mirror of https://git.ffmpeg.org/ffmpeg.git
Fix index generation in the way that it was supposed to be used. See the
discussion in the ML thread "[PATCH] rmdec.c: merge old/new packet reading code". Over time, this code broke somewhat, e.g. seq was never actually written into (and was thus always 1, therefore the seq condition was always true), whereas it was supposed to be set to the sequence number of the video slice in case the video frame is divided over multiple RM packets (slices). The problem of this is that packets other than those containing the beginning of a video frame would be indexed as well. Secondly, flags&2 is supposed to be true for video keyframes and for these audio packets containing the start of a block. For some codecs (e.g. AAC), that is every single packet, whereas for others (e.g. cook), that is the packet containing the first of a series of scrambled packets that are to be descrambled together. Indexing any of the following would lead to incomplete and thus useless frames. Problem here is that flags would be reset to 2 to indicate that the first packet is ready to be returned, and in addition if no data was left to be returned (which is always true for the first packet), then we wouldn't actually write the index entry anyway. All in all, the idea was good and it probably worked at some point, but that is long ago. This patch should at the very least make it likely for this code to be executed again at the right times, i.e. the way it was originally intended to be used. Originally committed as revision 17993 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
b217024706
commit
7a160bca83
|
@ -492,7 +492,7 @@ skip:
|
||||||
|
|
||||||
static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,
|
static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,
|
||||||
RMDemuxContext *rm, RMStream *vst,
|
RMDemuxContext *rm, RMStream *vst,
|
||||||
AVPacket *pkt, int len)
|
AVPacket *pkt, int len, int *pseq)
|
||||||
{
|
{
|
||||||
int hdr, seq, pic_num, len2, pos;
|
int hdr, seq, pic_num, len2, pos;
|
||||||
int type;
|
int type;
|
||||||
|
@ -527,6 +527,7 @@ static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,
|
||||||
}
|
}
|
||||||
//now we have to deal with single slice
|
//now we have to deal with single slice
|
||||||
|
|
||||||
|
*pseq = seq;
|
||||||
if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){
|
if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){
|
||||||
vst->slices = ((hdr & 0x3F) << 1) + 1;
|
vst->slices = ((hdr & 0x3F) << 1) + 1;
|
||||||
vst->videobufsize = len2 + 8*vst->slices + 1;
|
vst->videobufsize = len2 + 8*vst->slices + 1;
|
||||||
|
@ -593,7 +594,7 @@ ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
|
||||||
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
|
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
|
||||||
rm->current_stream= st->id;
|
rm->current_stream= st->id;
|
||||||
if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len))
|
if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq))
|
||||||
return -1; //got partial frame
|
return -1; //got partial frame
|
||||||
} else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
|
} else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
|
||||||
if ((st->codec->codec_id == CODEC_ID_RA_288) ||
|
if ((st->codec->codec_id == CODEC_ID_RA_288) ||
|
||||||
|
@ -705,9 +706,9 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
RMDemuxContext *rm = s->priv_data;
|
RMDemuxContext *rm = s->priv_data;
|
||||||
ByteIOContext *pb = s->pb;
|
ByteIOContext *pb = s->pb;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
int i, len;
|
int i, len, res;
|
||||||
int64_t timestamp, pos;
|
int64_t timestamp, pos;
|
||||||
int flags;
|
int old_flags, flags;
|
||||||
|
|
||||||
if (rm->audio_pkt_cnt) {
|
if (rm->audio_pkt_cnt) {
|
||||||
// If there are queued audio packet return them first
|
// If there are queued audio packet return them first
|
||||||
|
@ -751,8 +752,12 @@ resync:
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
st = s->streams[i];
|
st = s->streams[i];
|
||||||
|
|
||||||
if (ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
|
old_flags = flags;
|
||||||
&seq, &flags, ×tamp) < 0)
|
res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
|
||||||
|
&seq, &flags, ×tamp);
|
||||||
|
if((old_flags&2) && (seq&0x7F) == 1)
|
||||||
|
av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
|
||||||
|
if (res < 0)
|
||||||
goto resync;
|
goto resync;
|
||||||
|
|
||||||
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
|
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
|
||||||
|
@ -764,9 +769,6 @@ resync:
|
||||||
}
|
}
|
||||||
goto resync;
|
goto resync;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((flags&2) && (seq&0x7F) == 1)
|
|
||||||
av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue