[FFmpeg-devel] [PATCH] rmdec.c: remove cache access duplication
Ronald S. Bultje
rsbultje
Wed Mar 11 05:59:36 CET 2009
Hi,
as suggested by Kostya, attached patch removes the duplicate code in
ff_rm_parse_packet() to read cache data while we could just as well
recurse and let the parent function do that. Attached patch does the
correct thing.
Ronald
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rdt.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rdt.c 2009-03-11 00:13:10.000000000 -0400
+++ ffmpeg-svn/libavformat/rdt.c 2009-03-11 00:14:38.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-11 00:13:41.000000000 -0400
+++ ffmpeg-svn/libavformat/rmdec.c 2009-03-11 00:14:58.000000000 -0400
@@ -629,16 +629,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;
@@ -646,11 +639,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);
@@ -697,6 +689,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;
@@ -749,7 +745,7 @@
(old_flags & 2 || res == 0)))
av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
- if (res < 0)
+ if (res)
continue;
}
Index: ffmpeg-svn/libavformat/rm.h
===================================================================
--- ffmpeg-svn.orig/libavformat/rm.h 2009-03-11 00:12:50.000000000 -0400
+++ ffmpeg-svn/libavformat/rm.h 2009-03-11 00:14:38.000000000 -0400
@@ -68,9 +68,9 @@
* @param flags pointer to an integer containing the packet flags, may be
updated
* @param ts pointer to timestamp, may be updated
- * @return >=0 on success (where >0 indicates there are cached samples that
- * can be retrieved with subsequent calls to ff_rm_retrieve_cache()),
- * errno codes on error
+ * @return <0 on error, 0 if a packet was placed in the \p pkt pointer. A
+ * value >0 means that no data was placed in \p pkt, but that cached
+ * data is available by calling ff_rm_retrieve_cache().
*/
int ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
AVStream *st, RMStream *rst, int len,
More information about the ffmpeg-devel
mailing list