[FFmpeg-cvslog] h264: move parser-only variables to their own context

Anton Khirnov git at videolan.org
Tue Jan 27 15:15:45 CET 2015


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Jan 17 17:30:46 2015 +0100| [9404a47a2d1df418946a338938eb6cdb3afed474] | committer: Anton Khirnov

h264: move parser-only variables to their own context

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

 libavcodec/h264.c        |    7 -------
 libavcodec/h264.h        |    2 --
 libavcodec/h264_parser.c |   40 ++++++++++++++++++++++++++--------------
 3 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index f966751..593a23d 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1084,13 +1084,6 @@ static void flush_dpb(AVCodecContext *avctx)
 
     h->mb_x = h->mb_y = 0;
 
-    h->parse_context.state             = -1;
-    h->parse_context.frame_start_found = 0;
-    h->parse_context.overread          = 0;
-    h->parse_context.overread_index    = 0;
-    h->parse_context.index             = 0;
-    h->parse_context.last_index        = 0;
-
     ff_h264_free_tables(h, 1);
     h->context_initialized = 0;
 }
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index fa6e19e..ad36549 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -305,7 +305,6 @@ typedef struct H264Context {
     H264DSPContext h264dsp;
     H264ChromaContext h264chroma;
     H264QpelContext h264qpel;
-    ParseContext parse_context;
     GetBitContext gb;
     ERContext er;
 
@@ -522,7 +521,6 @@ typedef struct H264Context {
      */
     int is_avc;           ///< this flag is != 0 if codec is avc1
     int nal_length_size;  ///< Number of bytes used for nal length (1, 2 or 4)
-    int got_first;        ///< this flag is != 0 if we've parsed a frame
 
     int bit_depth_luma;         ///< luma bit depth from sps to detect changes
     int chroma_format_idc;      ///< chroma format from sps to detect changes
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 2ed3dd0..a0308b0 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -34,13 +34,20 @@
 
 #include <assert.h>
 
+typedef struct H264ParseContext {
+    H264Context h;
+    ParseContext pc;
+    int got_first;
+} H264ParseContext;
 
-static int h264_find_frame_end(H264Context *h, const uint8_t *buf,
+
+static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,
                                int buf_size)
 {
+    H264Context *h = &p->h;
     int i;
     uint32_t state;
-    ParseContext *pc = &h->parse_context;
+    ParseContext *pc = &p->pc;
 //    mb_addr= pc->mb_addr - 1;
     state = pc->state;
     if (state > 13)
@@ -92,7 +99,8 @@ found:
 
 static int scan_mmco_reset(AVCodecParserContext *s)
 {
-    H264Context *h = s->priv_data;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
 
     h->slice_type_nos = s->pict_type & 3;
 
@@ -172,7 +180,8 @@ static inline int parse_nal_units(AVCodecParserContext *s,
                                   AVCodecContext *avctx,
                                   const uint8_t *buf, int buf_size)
 {
-    H264Context *h         = s->priv_data;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
     const uint8_t *buf_end = buf + buf_size;
     unsigned int pps_id;
     unsigned int slice_type;
@@ -401,12 +410,13 @@ static int h264_parse(AVCodecParserContext *s,
                       const uint8_t **poutbuf, int *poutbuf_size,
                       const uint8_t *buf, int buf_size)
 {
-    H264Context *h   = s->priv_data;
-    ParseContext *pc = &h->parse_context;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
+    ParseContext *pc = &p->pc;
     int next;
 
-    if (!h->got_first) {
-        h->got_first = 1;
+    if (!p->got_first) {
+        p->got_first = 1;
         if (avctx->extradata_size) {
             h->avctx = avctx;
             // must be done like in the decoder.
@@ -423,7 +433,7 @@ static int h264_parse(AVCodecParserContext *s,
     if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
         next = buf_size;
     } else {
-        next = h264_find_frame_end(h, buf, buf_size);
+        next = h264_find_frame_end(p, buf, buf_size);
 
         if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
             *poutbuf      = NULL;
@@ -433,7 +443,7 @@ static int h264_parse(AVCodecParserContext *s,
 
         if (next < 0 && next != END_NOT_FOUND) {
             assert(pc->last_index + next >= 0);
-            h264_find_frame_end(h, &pc->buffer[pc->last_index + next], -next); // update state
+            h264_find_frame_end(p, &pc->buffer[pc->last_index + next], -next); // update state
         }
     }
 
@@ -491,8 +501,9 @@ static int h264_split(AVCodecContext *avctx,
 
 static void close(AVCodecParserContext *s)
 {
-    H264Context *h   = s->priv_data;
-    ParseContext *pc = &h->parse_context;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
+    ParseContext *pc = &p->pc;
 
     av_free(pc->buffer);
     ff_h264_free_context(h);
@@ -500,7 +511,8 @@ static void close(AVCodecParserContext *s)
 
 static av_cold int init(AVCodecParserContext *s)
 {
-    H264Context *h = s->priv_data;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
     h->thread_context[0]   = h;
     h->slice_context_count = 1;
     ff_h264dsp_init(&h->h264dsp, 8, 1);
@@ -509,7 +521,7 @@ static av_cold int init(AVCodecParserContext *s)
 
 AVCodecParser ff_h264_parser = {
     .codec_ids      = { AV_CODEC_ID_H264 },
-    .priv_data_size = sizeof(H264Context),
+    .priv_data_size = sizeof(H264ParseContext),
     .parser_init    = init,
     .parser_parse   = h264_parse,
     .parser_close   = close,



More information about the ffmpeg-cvslog mailing list