[FFmpeg-cvslog] lavf: make read_from_packet_buffer() more flexible.

Anton Khirnov git at videolan.org
Tue Mar 6 06:15:56 CET 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Mar  3 16:28:32 2012 +0100| [dcee811505b9f95edad73526d94cabc99331b659] | committer: Anton Khirnov

lavf: make read_from_packet_buffer() more flexible.

Make packet buffer a parameter, don't hardcode it to be
AVFormatContext.packet_buffer.

Also move the function higher in the file, since it will be called from
read_frame_internal().

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dcee811505b9f95edad73526d94cabc99331b659
---

 libavformat/utils.c |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7661e98..a3f8d4e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1011,6 +1011,21 @@ static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_en
     *pkt_buf_end = NULL;
 }
 
+static int read_from_packet_buffer(AVPacketList **pkt_buffer,
+                                   AVPacketList **pkt_buffer_end,
+                                   AVPacket      *pkt)
+{
+    AVPacketList *pktl;
+    av_assert0(*pkt_buffer);
+    pktl = *pkt_buffer;
+    *pkt = pktl->pkt;
+    *pkt_buffer = pktl->next;
+    if (!pktl->next)
+        *pkt_buffer_end = NULL;
+    av_freep(&pktl);
+    return 0;
+}
+
 
 static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
 {
@@ -1171,23 +1186,15 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
-static int read_from_packet_buffer(AVFormatContext *s, AVPacket *pkt)
-{
-    AVPacketList *pktl = s->packet_buffer;
-    av_assert0(pktl);
-    *pkt = pktl->pkt;
-    s->packet_buffer = pktl->next;
-    av_freep(&pktl);
-    return 0;
-}
-
 int av_read_frame(AVFormatContext *s, AVPacket *pkt)
 {
     const int genpts = s->flags & AVFMT_FLAG_GENPTS;
     int          eof = 0;
 
     if (!genpts)
-        return s->packet_buffer ? read_from_packet_buffer(s, pkt) :
+        return s->packet_buffer ? read_from_packet_buffer(&s->packet_buffer,
+                                                          &s->packet_buffer_end,
+                                                          pkt) :
                                   read_frame_internal(s, pkt);
 
     for (;;) {
@@ -1213,7 +1220,8 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
             /* read packet from packet buffer, if there is data */
             if (!(next_pkt->pts == AV_NOPTS_VALUE &&
                   next_pkt->dts != AV_NOPTS_VALUE && !eof))
-                return read_from_packet_buffer(s, pkt);
+                return read_from_packet_buffer(&s->packet_buffer,
+                                               &s->packet_buffer_end, pkt);
         }
 
         ret = read_frame_internal(s, pkt);



More information about the ffmpeg-cvslog mailing list