Merge code for packet reading in "old" (.ra, audio-only) Realmedia files and
the newer (.rm, audio/video) files. See "[PATCH] rmdec.c: merge old/new packet reading code" thread on mailinglist. Originally committed as revision 18005 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
@@ -704,71 +704,48 @@ ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb,
|
|||||||
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
|
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
RMDemuxContext *rm = s->priv_data;
|
RMDemuxContext *rm = s->priv_data;
|
||||||
ByteIOContext *pb = s->pb;
|
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
int i, len, res;
|
int i, len, res, seq = 1;
|
||||||
int64_t timestamp, pos;
|
int64_t timestamp, pos;
|
||||||
int old_flags, flags;
|
int old_flags, flags;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
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
|
||||||
st = s->streams[rm->audio_stream_num];
|
st = s->streams[rm->audio_stream_num];
|
||||||
ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
|
ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
|
||||||
} else if (rm->old_format) {
|
} else {
|
||||||
|
if (rm->old_format) {
|
||||||
RMStream *ast;
|
RMStream *ast;
|
||||||
|
|
||||||
st = s->streams[0];
|
st = s->streams[0];
|
||||||
ast = st->priv_data;
|
ast = st->priv_data;
|
||||||
if (st->codec->codec_id == CODEC_ID_RA_288) {
|
timestamp = AV_NOPTS_VALUE;
|
||||||
int x, y;
|
len = !ast->audio_framesize ? RAW_PACKET_SIZE :
|
||||||
|
ast->coded_framesize * ast->sub_packet_h / 2;
|
||||||
for (y = 0; y < ast->sub_packet_h; y++)
|
flags = (seq++ == 1) ? 2 : 0;
|
||||||
for (x = 0; x < ast->sub_packet_h/2; x++)
|
|
||||||
if (get_buffer(pb, ast->pkt.data+x*2*ast->audio_framesize+y*ast->coded_framesize, ast->coded_framesize) <= 0)
|
|
||||||
return AVERROR(EIO);
|
|
||||||
rm->audio_stream_num = 0;
|
|
||||||
rm->audio_pkt_cnt = ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - 1;
|
|
||||||
// Release first audio packet
|
|
||||||
av_new_packet(pkt, st->codec->block_align);
|
|
||||||
memcpy(pkt->data, ast->pkt.data, st->codec->block_align); //FIXME avoid this
|
|
||||||
pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
|
|
||||||
pkt->stream_index = 0;
|
|
||||||
} else {
|
} else {
|
||||||
/* just read raw bytes */
|
|
||||||
len = RAW_PACKET_SIZE;
|
|
||||||
len= av_get_packet(pb, pkt, len);
|
|
||||||
pkt->stream_index = 0;
|
|
||||||
if (len <= 0) {
|
|
||||||
return AVERROR(EIO);
|
|
||||||
}
|
|
||||||
pkt->size = len;
|
|
||||||
}
|
|
||||||
rm_ac3_swap_bytes(st, pkt);
|
|
||||||
} else {
|
|
||||||
int seq=1;
|
|
||||||
resync:
|
|
||||||
len=sync(s, ×tamp, &flags, &i, &pos);
|
len=sync(s, ×tamp, &flags, &i, &pos);
|
||||||
if(len<0)
|
|
||||||
return AVERROR(EIO);
|
|
||||||
st = s->streams[i];
|
st = s->streams[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(len<0 || url_feof(s->pb))
|
||||||
|
return AVERROR(EIO);
|
||||||
|
|
||||||
old_flags = flags;
|
old_flags = flags;
|
||||||
res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
|
res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
|
||||||
&seq, &flags, ×tamp);
|
&seq, &flags, ×tamp);
|
||||||
if((old_flags&2) && (seq&0x7F) == 1)
|
if((old_flags&2) && (seq&0x7F) == 1)
|
||||||
av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
|
av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
|
||||||
if (res < 0)
|
if (res)
|
||||||
goto resync;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
|
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
|
||||||
|| st->discard >= AVDISCARD_ALL){
|
|| st->discard >= AVDISCARD_ALL){
|
||||||
av_free_packet(pkt);
|
av_free_packet(pkt);
|
||||||
while (rm->audio_pkt_cnt > 0) {
|
} else
|
||||||
ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
|
break;
|
||||||
av_free_packet(pkt);
|
|
||||||
}
|
|
||||||
goto resync;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user