diff mbox

[FFmpeg-devel,3/3] avcodec/mpeg4video: Detect reference studio streams as studio streams

Message ID 20180429215616.17303-3-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer April 29, 2018, 9:56 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/mpeg4video.h    |  2 ++
 libavcodec/mpeg4videodec.c | 25 ++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

Comments

Kieran Kunhya April 29, 2018, 11:21 p.m. UTC | #1
On Sun, 29 Apr 2018 at 22:57 Michael Niedermayer <michael@niedermayer.cc>
wrote:

> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/mpeg4video.h    |  2 ++
>  libavcodec/mpeg4videodec.c | 25 ++++++++++++++++---------
>  2 files changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
> index f974792887..dd0a59038d 100644
> --- a/libavcodec/mpeg4video.h
> +++ b/libavcodec/mpeg4video.h
> @@ -41,6 +41,8 @@
>  #define NBIT_VO_TYPE             5
>  #define ARTS_VO_TYPE            10
>  #define ACE_VO_TYPE             12
> +#define SIMPLE_STUDIO_VO_TYPE   14
> +#define CORE_STUDIO_VO_TYPE     15
>  #define ADV_SIMPLE_VO_TYPE      17
>
>  #define VOT_VIDEO_ID 1
> diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> index ada5cdc6fa..d2b5e90331 100644
> --- a/libavcodec/mpeg4videodec.c
> +++ b/libavcodec/mpeg4videodec.c
> @@ -46,6 +46,8 @@
>  #define MB_TYPE_B_VLC_BITS 4
>  #define STUDIO_INTRA_BITS 9
>
> +static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext
> *gb);
> +
>  static VLC dc_lum, dc_chrom;
>  static VLC sprite_trajectory;
>  static VLC mb_type_b_vlc;
> @@ -2049,6 +2051,18 @@ static int decode_vol_header(Mpeg4DecContext *ctx,
> GetBitContext *gb)
>      /* vol header */
>      skip_bits(gb, 1);                   /* random access */
>      s->vo_type = get_bits(gb, 8);
> +
> +    if (s->vo_type == CORE_STUDIO_VO_TYPE ||
> +        s->vo_type == SIMPLE_STUDIO_VO_TYPE) {
> +        if (s->avctx->profile != FF_PROFILE_UNKNOWN && s->avctx->profile
> != FF_PROFILE_MPEG4_SIMPLE_STUDIO)
> +            return AVERROR_INVALIDDATA;
> +        s->studio_profile = 1;
> +        s->avctx->profile = FF_PROFILE_MPEG4_SIMPLE_STUDIO;
> +        return decode_studio_vol_header(ctx, gb);
> +    } else if (s->studio_profile) {
> +        return AVERROR_PATCHWELCOME;
> +    }
> +
>      if (get_bits1(gb) != 0) {           /* is_ol_id */
>          vo_ver_id = get_bits(gb, 4);    /* vo_ver_id */
>          skip_bits(gb, 3);               /* vo_priority */
> @@ -3001,8 +3015,6 @@ static int decode_studio_vol_header(Mpeg4DecContext
> *ctx, GetBitContext *gb)
>      int width, height;
>      int bits_per_raw_sample;
>
> -            skip_bits1(gb); /* random_accessible_vol */
> -            skip_bits(gb, 8); /* video_object_type_indication */
>              skip_bits(gb, 4); /* video_object_layer_verid */
>

Please add a comment explaining what you've done here, someone might look
at this code in 10 years time (exactly like I did) and not understand why
you are mixing normal vol header and studio vol header.

Kieran
Michael Niedermayer May 16, 2018, 9:03 p.m. UTC | #2
On Sun, Apr 29, 2018 at 11:21:58PM +0000, Kieran Kunhya wrote:
> On Sun, 29 Apr 2018 at 22:57 Michael Niedermayer <michael@niedermayer.cc>
> wrote:
> 
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/mpeg4video.h    |  2 ++
> >  libavcodec/mpeg4videodec.c | 25 ++++++++++++++++---------
> >  2 files changed, 18 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
> > index f974792887..dd0a59038d 100644
> > --- a/libavcodec/mpeg4video.h
> > +++ b/libavcodec/mpeg4video.h
> > @@ -41,6 +41,8 @@
> >  #define NBIT_VO_TYPE             5
> >  #define ARTS_VO_TYPE            10
> >  #define ACE_VO_TYPE             12
> > +#define SIMPLE_STUDIO_VO_TYPE   14
> > +#define CORE_STUDIO_VO_TYPE     15
> >  #define ADV_SIMPLE_VO_TYPE      17
> >
> >  #define VOT_VIDEO_ID 1
> > diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> > index ada5cdc6fa..d2b5e90331 100644
> > --- a/libavcodec/mpeg4videodec.c
> > +++ b/libavcodec/mpeg4videodec.c
> > @@ -46,6 +46,8 @@
> >  #define MB_TYPE_B_VLC_BITS 4
> >  #define STUDIO_INTRA_BITS 9
> >
> > +static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext
> > *gb);
> > +
> >  static VLC dc_lum, dc_chrom;
> >  static VLC sprite_trajectory;
> >  static VLC mb_type_b_vlc;
> > @@ -2049,6 +2051,18 @@ static int decode_vol_header(Mpeg4DecContext *ctx,
> > GetBitContext *gb)
> >      /* vol header */
> >      skip_bits(gb, 1);                   /* random access */
> >      s->vo_type = get_bits(gb, 8);
> > +
> > +    if (s->vo_type == CORE_STUDIO_VO_TYPE ||
> > +        s->vo_type == SIMPLE_STUDIO_VO_TYPE) {
> > +        if (s->avctx->profile != FF_PROFILE_UNKNOWN && s->avctx->profile
> > != FF_PROFILE_MPEG4_SIMPLE_STUDIO)
> > +            return AVERROR_INVALIDDATA;
> > +        s->studio_profile = 1;
> > +        s->avctx->profile = FF_PROFILE_MPEG4_SIMPLE_STUDIO;
> > +        return decode_studio_vol_header(ctx, gb);
> > +    } else if (s->studio_profile) {
> > +        return AVERROR_PATCHWELCOME;
> > +    }
> > +
> >      if (get_bits1(gb) != 0) {           /* is_ol_id */
> >          vo_ver_id = get_bits(gb, 4);    /* vo_ver_id */
> >          skip_bits(gb, 3);               /* vo_priority */
> > @@ -3001,8 +3015,6 @@ static int decode_studio_vol_header(Mpeg4DecContext
> > *ctx, GetBitContext *gb)
> >      int width, height;
> >      int bits_per_raw_sample;
> >
> > -            skip_bits1(gb); /* random_accessible_vol */
> > -            skip_bits(gb, 8); /* video_object_type_indication */
> >              skip_bits(gb, 4); /* video_object_layer_verid */
> >
> 
> Please add a comment explaining what you've done here, someone might look
> at this code in 10 years time (exactly like I did) and not understand why
> you are mixing normal vol header and studio vol header.

yes, this is a good idea
Ill add some comments and apply

thx


[...]
diff mbox

Patch

diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index f974792887..dd0a59038d 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -41,6 +41,8 @@ 
 #define NBIT_VO_TYPE             5
 #define ARTS_VO_TYPE            10
 #define ACE_VO_TYPE             12
+#define SIMPLE_STUDIO_VO_TYPE   14
+#define CORE_STUDIO_VO_TYPE     15
 #define ADV_SIMPLE_VO_TYPE      17
 
 #define VOT_VIDEO_ID 1
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index ada5cdc6fa..d2b5e90331 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -46,6 +46,8 @@ 
 #define MB_TYPE_B_VLC_BITS 4
 #define STUDIO_INTRA_BITS 9
 
+static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb);
+
 static VLC dc_lum, dc_chrom;
 static VLC sprite_trajectory;
 static VLC mb_type_b_vlc;
@@ -2049,6 +2051,18 @@  static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
     /* vol header */
     skip_bits(gb, 1);                   /* random access */
     s->vo_type = get_bits(gb, 8);
+
+    if (s->vo_type == CORE_STUDIO_VO_TYPE ||
+        s->vo_type == SIMPLE_STUDIO_VO_TYPE) {
+        if (s->avctx->profile != FF_PROFILE_UNKNOWN && s->avctx->profile != FF_PROFILE_MPEG4_SIMPLE_STUDIO)
+            return AVERROR_INVALIDDATA;
+        s->studio_profile = 1;
+        s->avctx->profile = FF_PROFILE_MPEG4_SIMPLE_STUDIO;
+        return decode_studio_vol_header(ctx, gb);
+    } else if (s->studio_profile) {
+        return AVERROR_PATCHWELCOME;
+    }
+
     if (get_bits1(gb) != 0) {           /* is_ol_id */
         vo_ver_id = get_bits(gb, 4);    /* vo_ver_id */
         skip_bits(gb, 3);               /* vo_priority */
@@ -3001,8 +3015,6 @@  static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
     int width, height;
     int bits_per_raw_sample;
 
-            skip_bits1(gb); /* random_accessible_vol */
-            skip_bits(gb, 8); /* video_object_type_indication */
             skip_bits(gb, 4); /* video_object_layer_verid */
             ctx->shape = get_bits(gb, 2); /* video_object_layer_shape */
             skip_bits(gb, 4); /* video_object_layer_shape_extension */
@@ -3179,13 +3191,8 @@  int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb)
                 continue;
             }
             vol++;
-            if (s->studio_profile) {
-                if ((ret = decode_studio_vol_header(ctx, gb)) < 0)
-                    return ret;
-            } else {
-                if ((ret = decode_vol_header(ctx, gb)) < 0)
-                    return ret;
-            }
+            if ((ret = decode_vol_header(ctx, gb)) < 0)
+                return ret;
         } else if (startcode == USER_DATA_STARTCODE) {
             decode_user_data(ctx, gb);
         } else if (startcode == GOP_STARTCODE) {