[FFmpeg-cvslog] lavc: deprecate AVCodecContext.sub_id.

Anton Khirnov git at videolan.org
Mon Mar 5 00:28:57 CET 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Feb 27 18:52:13 2012 +0100| [02beb9826b29166b5d7c9b306ac1648abb449be0] | committer: Anton Khirnov

lavc: deprecate AVCodecContext.sub_id.

In most places where it's used, it's as a pointless write-only field.

Only rv10 decoder actually reads from it, but it stores some internal
version info in it. There is no reason for it to be in a public field.

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

 libavcodec/avcodec.h            |   11 ++++-------
 libavcodec/mpeg12.c             |    4 ----
 libavcodec/mpegaudiodec.c       |    2 --
 libavcodec/mpegaudiodecheader.c |    1 -
 libavcodec/mpegvideo_parser.c   |    2 --
 libavcodec/options.c            |    2 ++
 libavcodec/pthread.c            |    1 -
 libavcodec/rv10.c               |   38 +++++++++++++++++++++++---------------
 libavcodec/version.h            |    3 +++
 9 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3598aaa..491fb16 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1228,15 +1228,12 @@ typedef struct AVCodecContext {
      */
     unsigned int stream_codec_tag;
 
+#if FF_API_SUB_ID
     /**
-     * Some codecs need additional format info. It is stored here.
-     * If any muxer uses this then ALL demuxers/parsers AND encoders for the
-     * specific codec MUST set it correctly otherwise stream copy breaks.
-     * In general use of this field by muxers is not recommended.
-     * - encoding: Set by libavcodec.
-     * - decoding: Set by libavcodec. (FIXME: Is this OK?)
+     * @deprecated this field is unused
      */
-    int sub_id;
+    attribute_deprecated int sub_id;
+#endif
 
     void *priv_data;
 
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index a5dafbd..c49343f 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1237,7 +1237,6 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
          * that behave like P-frames. */
         avctx->has_b_frames = !s->low_delay;
 
-        assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO));
         if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) {
             //MPEG-1 fps
             avctx->time_base.den = avpriv_frame_rate_tab[s->frame_rate_index].num;
@@ -1382,7 +1381,6 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
 
     av_dlog(s->avctx, "sequence extension\n");
     s->codec_id      = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
-    s->avctx->sub_id = 2; /* indicates MPEG-2 found */
 
     if (s->avctx->debug & FF_DEBUG_PICT_INFO)
         av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
@@ -2000,7 +1998,6 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
     s->frame_pred_frame_dct = 1;
     s->chroma_format        = 1;
     s->codec_id             = s->avctx->codec_id = CODEC_ID_MPEG1VIDEO;
-    avctx->sub_id           = 1; /* indicates MPEG-1 */
     s->out_format           = FMT_MPEG1;
     s->swap_uv              = 0; // AFAIK VCR2 does not have SEQ_HEADER
     if (s->flags & CODEC_FLAG_LOW_DELAY)
@@ -2060,7 +2057,6 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
     s->frame_pred_frame_dct  = 1;
     s->chroma_format         = 1;
     s->codec_id              = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
-    avctx->sub_id            = 2; /* indicates MPEG-2 */
     s1->save_width           = s->width;
     s1->save_height          = s->height;
     s1->save_progressive_seq = s->progressive_sequence;
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index d6a09c8..dd43beb 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -1660,7 +1660,6 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
     avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
     if (!avctx->bit_rate)
         avctx->bit_rate = s->bit_rate;
-    avctx->sub_id = s->layer;
 
     if (s->frame_size <= 0 || s->frame_size > buf_size) {
         av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
@@ -1733,7 +1732,6 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
     avctx->channels    = s->nb_channels;
     if (!avctx->bit_rate)
         avctx->bit_rate = s->bit_rate;
-    avctx->sub_id = s->layer;
 
     s->frame_size = len;
 
diff --git a/libavcodec/mpegaudiodecheader.c b/libavcodec/mpegaudiodecheader.c
index dbd67ff..428137d 100644
--- a/libavcodec/mpegaudiodecheader.c
+++ b/libavcodec/mpegaudiodecheader.c
@@ -142,6 +142,5 @@ int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_r
     *sample_rate = s->sample_rate;
     *channels = s->nb_channels;
     *bit_rate = s->bit_rate;
-    avctx->sub_id = s->layer;
     return s->frame_size;
 }
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index f0b3b20..af4b6e4 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -69,7 +69,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
                 pc->frame_rate.num = avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_index].den;
                 avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400;
                 avctx->codec_id = CODEC_ID_MPEG1VIDEO;
-                avctx->sub_id = 1;
             }
             break;
         case EXT_START_CODE:
@@ -94,7 +93,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
                         avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1) * 2;
                         avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1);
                         avctx->codec_id = CODEC_ID_MPEG2VIDEO;
-                        avctx->sub_id = 2; /* forces MPEG2 */
                     }
                     break;
                 case 0x8: /* picture coding extension */
diff --git a/libavcodec/options.c b/libavcodec/options.c
index d25b64a..51187b8 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -109,7 +109,9 @@ static const AVOption options[]={
 #endif
 {"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},
 {"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"},
+#if FF_API_SUB_ID
 {"sub_id", NULL, OFFSET(sub_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+#endif
 {"me_method", "set motion estimation method", OFFSET(me_method), AV_OPT_TYPE_INT, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method"},
 {"zero", "zero motion estimation (fastest)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_ZERO }, INT_MIN, INT_MAX, V|E, "me_method" },
 {"full", "full motion estimation (slowest)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" },
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index f17f34e..4a02823 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -402,7 +402,6 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src,
     int err = 0;
 
     if (dst != src) {
-        dst->sub_id    = src->sub_id;
         dst->time_base = src->time_base;
         dst->width     = src->width;
         dst->height    = src->height;
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 2b1a09d..5775225 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -40,6 +40,11 @@
 
 #define DC_VLC_BITS 14 //FIXME find a better solution
 
+typedef struct RVDecContext {
+    MpegEncContext m;
+    int sub_id;
+} RVDecContext;
+
 static const uint16_t rv_lum_code[256] =
 {
  0x3e7f, 0x0f00, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05, 0x0f06,
@@ -293,8 +298,9 @@ static int rv10_decode_picture_header(MpegEncContext *s)
     return mb_count;
 }
 
-static int rv20_decode_picture_header(MpegEncContext *s)
+static int rv20_decode_picture_header(RVDecContext *rv)
 {
+    MpegEncContext *s = &rv->m;
     int seq, mb_pos, i;
     int rpr_bits;
 
@@ -325,10 +331,10 @@ static int rv20_decode_picture_header(MpegEncContext *s)
         return -1;
     }
 
-    if(RV_GET_MINOR_VER(s->avctx->sub_id) >= 2)
+    if(RV_GET_MINOR_VER(rv->sub_id) >= 2)
         s->loop_filter = get_bits1(&s->gb);
 
-    if(RV_GET_MINOR_VER(s->avctx->sub_id) <= 1)
+    if(RV_GET_MINOR_VER(rv->sub_id) <= 1)
         seq = get_bits(&s->gb, 8) << 7;
     else
         seq = get_bits(&s->gb, 13) << 2;
@@ -393,7 +399,7 @@ static int rv20_decode_picture_header(MpegEncContext *s)
 av_log(s->avctx, AV_LOG_DEBUG, "\n");*/
     s->no_rounding= get_bits1(&s->gb);
 
-    if(RV_GET_MINOR_VER(s->avctx->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
+    if(RV_GET_MINOR_VER(rv->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
         skip_bits(&s->gb, 5); // binary decoder reads 3+2 bits here but they don't seem to be used
 
     s->f_code = 1;
@@ -418,7 +424,8 @@ av_log(s->avctx, AV_LOG_DEBUG, "\n");*/
 
 static av_cold int rv10_decode_init(AVCodecContext *avctx)
 {
-    MpegEncContext *s = avctx->priv_data;
+    RVDecContext  *rv = avctx->priv_data;
+    MpegEncContext *s = &rv->m;
     static int done=0;
     int major_ver, minor_ver, micro_ver;
 
@@ -438,11 +445,11 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
     s->orig_height= s->height = avctx->coded_height;
 
     s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1;
-    avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4);
+    rv->sub_id = AV_RB32((uint8_t*)avctx->extradata + 4);
 
-    major_ver = RV_GET_MAJOR_VER(avctx->sub_id);
-    minor_ver = RV_GET_MINOR_VER(avctx->sub_id);
-    micro_ver = RV_GET_MICRO_VER(avctx->sub_id);
+    major_ver = RV_GET_MAJOR_VER(rv->sub_id);
+    minor_ver = RV_GET_MINOR_VER(rv->sub_id);
+    micro_ver = RV_GET_MICRO_VER(rv->sub_id);
 
     s->low_delay = 1;
     switch (major_ver) {
@@ -457,13 +464,13 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
         }
         break;
     default:
-        av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id);
+        av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", rv->sub_id);
         av_log_missing_feature(avctx, "RV1/2 version", 1);
         return AVERROR_PATCHWELCOME;
     }
 
     if(avctx->debug & FF_DEBUG_PICT_INFO){
-        av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", avctx->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1);
+        av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", rv->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1);
     }
 
     avctx->pix_fmt = PIX_FMT_YUV420P;
@@ -498,7 +505,8 @@ static av_cold int rv10_decode_end(AVCodecContext *avctx)
 static int rv10_decode_packet(AVCodecContext *avctx,
                              const uint8_t *buf, int buf_size, int buf_size2)
 {
-    MpegEncContext *s = avctx->priv_data;
+    RVDecContext  *rv = avctx->priv_data;
+    MpegEncContext *s = &rv->m;
     int mb_count, mb_pos, left, start_mb_x, active_bits_size;
 
     active_bits_size = buf_size * 8;
@@ -506,7 +514,7 @@ static int rv10_decode_packet(AVCodecContext *avctx,
     if(s->codec_id ==CODEC_ID_RV10)
         mb_count = rv10_decode_picture_header(s);
     else
-        mb_count = rv20_decode_picture_header(s);
+        mb_count = rv20_decode_picture_header(rv);
     if (mb_count < 0) {
         av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n");
         return -1;
@@ -714,7 +722,7 @@ AVCodec ff_rv10_decoder = {
     .name           = "rv10",
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = CODEC_ID_RV10,
-    .priv_data_size = sizeof(MpegEncContext),
+    .priv_data_size = sizeof(RVDecContext),
     .init           = rv10_decode_init,
     .close          = rv10_decode_end,
     .decode         = rv10_decode_frame,
@@ -728,7 +736,7 @@ AVCodec ff_rv20_decoder = {
     .name           = "rv20",
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = CODEC_ID_RV20,
-    .priv_data_size = sizeof(MpegEncContext),
+    .priv_data_size = sizeof(RVDecContext),
     .init           = rv10_decode_init,
     .close          = rv10_decode_end,
     .decode         = rv10_decode_frame,
diff --git a/libavcodec/version.h b/libavcodec/version.h
index f3b40ca..6fbe01c 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -59,5 +59,8 @@
 #ifndef FF_API_INTER_THRESHOLD
 #define FF_API_INTER_THRESHOLD  (LIBAVCODEC_VERSION_MAJOR < 55)
 #endif
+#ifndef FF_API_SUB_ID
+#define FF_API_SUB_ID           (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
 
 #endif /* AVCODEC_VERSION_H */



More information about the ffmpeg-cvslog mailing list