From d4d1b5fbde09593d56ee491f50eac6f29909ee4b Mon Sep 17 00:00:00 2001
From: "Ronald S. Bultje" <rsbultje@gmail.com>
Date: Thu, 8 Nov 2007 15:14:37 +0000
Subject: [PATCH] Isolate caching of audio frames in its own function. Patch by
 Ronald S. Bultje: rsbultje gmail com Original thread: Re: [FFmpeg-devel]
 [PATCH 3/6] rmdec.c: ff_rm_retrieve_cache() Date: 11/05/2007 09:25 PM

Originally committed as revision 10963 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavformat/rmdec.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 2f64a9427a2..533a1a59b00 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -632,6 +632,27 @@ ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len, AVPacket *pkt,
     return 0;
 }
 
+static void
+ff_rm_retrieve_cache (AVFormatContext *s, AVStream *st, AVPacket *pkt)
+{
+    ByteIOContext *pb = &s->pb;
+    RMContext *rm = s->priv_data;
+
+    assert (rm->audio_pkt_cnt > 0);
+
+    if (st->codec->codec_id == CODEC_ID_AAC)
+        av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]);
+    else {
+        av_new_packet(pkt, st->codec->block_align);
+        memcpy(pkt->data, rm->audiobuf + st->codec->block_align *
+               (rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
+               st->codec->block_align);
+    }
+    rm->audio_pkt_cnt--;
+    pkt->flags = 0;
+    pkt->stream_index = st->index;
+}
+
 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     RMContext *rm = s->priv_data;
@@ -645,17 +666,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (rm->audio_pkt_cnt) {
         // If there are queued audio packet return them first
         st = s->streams[rm->audio_stream_num];
-        if (st->codec->codec_id == CODEC_ID_AAC)
-            av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]);
-        else {
-        av_new_packet(pkt, st->codec->block_align);
-        memcpy(pkt->data, rm->audiobuf + st->codec->block_align *
-               (rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
-               st->codec->block_align);
-        }
-        rm->audio_pkt_cnt--;
-        pkt->flags = 0;
-        pkt->stream_index = st->index;
+        ff_rm_retrieve_cache(s, st, pkt);
     } else if (rm->old_format) {
         st = s->streams[0];
         if (st->codec->codec_id == CODEC_ID_RA_288) {
-- 
GitLab