[FFmpeg-devel] [PATCH] Make RM demuxer behave better with -an option
Ronald S. Bultje
rsbultje
Sun Mar 8 17:58:59 CET 2009
Hi,
On Mon, Mar 2, 2009 at 11:15 AM, Ronald S. Bultje <rsbultje at gmail.com> wrote:
> On Mon, Mar 2, 2009 at 10:07 AM, Kostya <kostya.shishkov at gmail.com> wrote:
>> oh, and I think returning
>> first subpacket from reassembled audio frame is not needed too (cache will
>> handle it).
>
> I'll implement this in a bit.
Attached is a patch doing this. It removes code duplication in
ff_rm_parse_packet() vs. ff_rm_retrieve_cache(). rdt.c needed a small
update to continue working in the same way as it did before. Let me
know if you think the goto-thing is sloppy and I'll get rid of that.
Ronald
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rdt.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rdt.c 2009-03-08 12:51:49.000000000 -0400
+++ ffmpeg-svn/libavformat/rdt.c 2009-03-08 12:55:41.000000000 -0400
@@ -312,14 +312,16 @@
pos = url_ftell(&pb);
if (res < 0)
return res;
- rdt->audio_pkt_cnt = res;
- if (rdt->audio_pkt_cnt > 0 &&
- st->codec->codec_id == CODEC_ID_AAC) {
+ if (res > 0) {
+ if (st->codec->codec_id == CODEC_ID_AAC) {
memcpy (rdt->buffer, buf + pos, len - pos);
rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0,
NULL, NULL, NULL, NULL);
+ }
+ goto get_cache;
}
} else {
+get_cache:
rdt->audio_pkt_cnt =
ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb,
st, rdt->rmst[st->index], pkt);
Index: ffmpeg-svn/libavformat/rmdec.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rmdec.c 2009-03-08 12:52:05.000000000 -0400
+++ ffmpeg-svn/libavformat/rmdec.c 2009-03-08 12:55:49.000000000 -0400
@@ -614,16 +614,9 @@
if (++(ast->sub_packet_cnt) < h)
return -1;
- else {
ast->sub_packet_cnt = 0;
rm->audio_stream_num = st->index;
- rm->audio_pkt_cnt = h * w / 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
- *timestamp = ast->audiotimestamp;
- *flags = 2; // Mark first packet as keyframe
- }
+ rm->audio_pkt_cnt = h * w / st->codec->block_align;
} else if (st->codec->codec_id == CODEC_ID_AAC) {
int x;
rm->audio_stream_num = st->index;
@@ -631,11 +624,10 @@
if (ast->sub_packet_cnt) {
for (x = 0; x < ast->sub_packet_cnt; x++)
ast->sub_packet_lengths[x] = get_be16(pb);
- // Release first audio packet
- rm->audio_pkt_cnt = ast->sub_packet_cnt - 1;
- av_get_packet(pb, pkt, ast->sub_packet_lengths[0]);
- *flags = 2; // Mark first packet as keyframe
- }
+ rm->audio_pkt_cnt = ast->sub_packet_cnt;
+ ast->audiotimestamp = *timestamp;
+ } else
+ return -1;
} else {
av_get_packet(pb, pkt, len);
rm_ac3_swap_bytes(st, pkt);
@@ -682,6 +674,10 @@
st->codec->block_align);
}
rm->audio_pkt_cnt--;
+ if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) {
+ ast->audiotimestamp = AV_NOPTS_VALUE;
+ pkt->flags = PKT_FLAG_KEY;
+ } else
pkt->flags = 0;
pkt->stream_index = st->index;
@@ -692,17 +688,18 @@
{
RMDemuxContext *rm = s->priv_data;
AVStream *st;
- int i, len, seq = 1;
+ int res, i, len, seq = 1;
int64_t timestamp, pos;
int flags;
if (rm->audio_pkt_cnt) {
+get_cache:
// If there are queued audio packet return them first
st = s->streams[rm->audio_stream_num];
ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
} else if (rm->old_format) {
RMStream *ast = s->streams[0]->priv_data;
- int res, y, h = ast->audio_framesize ? ast->sub_packet_h : 1;
+ int y, h = ast->audio_framesize ? ast->sub_packet_h : 1;
timestamp = AV_NOPTS_VALUE;
len = ast->audio_framesize ? ast->coded_framesize * h / 2 : RAW_PACKET_SIZE;
@@ -713,6 +710,8 @@
}
if (res < 0)
return res;
+ if (res > 0)
+ goto get_cache;
} else {
resync:
len=sync(s, ×tamp, &flags, &i, &pos);
@@ -720,9 +719,11 @@
return AVERROR(EIO);
st = s->streams[i];
- if (ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
- &seq, &flags, ×tamp) < 0)
+ if ((res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
+ &seq, &flags, ×tamp)) < 0)
goto resync;
+ if (res > 0)
+ goto get_cache;
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
|| st->discard >= AVDISCARD_ALL){
More information about the ffmpeg-devel
mailing list