diff mbox

[FFmpeg-devel] h264_ps: validate chroma sample location

Message ID 76824ab4-271d-ca78-23ce-bcec85877b7d@googlemail.com
State Superseded
Headers show

Commit Message

Andreas Cadhalpun Jan. 6, 2017, 8:44 p.m. UTC
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
---
 libavcodec/h264_ps.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Kieran Kunhya Jan. 6, 2017, 9:47 p.m. UTC | #1
On Fri, 6 Jan 2017 at 20:44 Andreas Cadhalpun <
andreas.cadhalpun@googlemail.com> wrote:

> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> ---
>  libavcodec/h264_ps.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
> index 8218e3a010..089bfc650a 100644
> --- a/libavcodec/h264_ps.c
> +++ b/libavcodec/h264_ps.c
> @@ -181,6 +181,10 @@ static inline int decode_vui_parameters(GetBitContext
> *gb, AVCodecContext *avctx
>      if (get_bits1(gb)) {
>          /* chroma_sample_location_type_top_field */
>          avctx->chroma_sample_location = get_ue_golomb(gb) + 1;
> +        if (!av_chroma_location_name(avctx->chroma_sample_location)) {
> +            av_log(avctx, AV_LOG_WARNING, "Invalid chroma sample location
> %d, setting to unspecified\n", avctx->chroma_sample_location);
> +            avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
> +        }
>
>
Is there a way to long only once, this seems like it could spam the user
full of these warnings.

Kieran
Andreas Cadhalpun Jan. 6, 2017, 10:33 p.m. UTC | #2
On 06.01.2017 22:47, Kieran Kunhya wrote:
> On Fri, 6 Jan 2017 at 20:44 Andreas Cadhalpun <
> andreas.cadhalpun@googlemail.com> wrote:
> 
>> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
>> ---
>>  libavcodec/h264_ps.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
>> index 8218e3a010..089bfc650a 100644
>> --- a/libavcodec/h264_ps.c
>> +++ b/libavcodec/h264_ps.c
>> @@ -181,6 +181,10 @@ static inline int decode_vui_parameters(GetBitContext
>> *gb, AVCodecContext *avctx
>>      if (get_bits1(gb)) {
>>          /* chroma_sample_location_type_top_field */
>>          avctx->chroma_sample_location = get_ue_golomb(gb) + 1;
>> +        if (!av_chroma_location_name(avctx->chroma_sample_location)) {
>> +            av_log(avctx, AV_LOG_WARNING, "Invalid chroma sample location
>> %d, setting to unspecified\n", avctx->chroma_sample_location);
>> +            avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
>> +        }
>>
>>
> Is there a way to long only once, this seems like it could spam the user
> full of these warnings.

One could add a field like shown_chroma_loc_warning to SPS, but I think
that would be a bit too much overhead for this.
Alternatively, one could drop the log message entirely. (Wrong color
primaries etc. aren't logged either...)

Best regards,
Andreas
Michael Niedermayer Jan. 7, 2017, 12:41 a.m. UTC | #3
On Fri, Jan 06, 2017 at 11:33:13PM +0100, Andreas Cadhalpun wrote:
> On 06.01.2017 22:47, Kieran Kunhya wrote:
> > On Fri, 6 Jan 2017 at 20:44 Andreas Cadhalpun <
> > andreas.cadhalpun@googlemail.com> wrote:
> > 
> >> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> >> ---
> >>  libavcodec/h264_ps.c | 4 ++++
> >>  1 file changed, 4 insertions(+)
> >>
> >> diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
> >> index 8218e3a010..089bfc650a 100644
> >> --- a/libavcodec/h264_ps.c
> >> +++ b/libavcodec/h264_ps.c
> >> @@ -181,6 +181,10 @@ static inline int decode_vui_parameters(GetBitContext
> >> *gb, AVCodecContext *avctx
> >>      if (get_bits1(gb)) {
> >>          /* chroma_sample_location_type_top_field */
> >>          avctx->chroma_sample_location = get_ue_golomb(gb) + 1;
> >> +        if (!av_chroma_location_name(avctx->chroma_sample_location)) {
> >> +            av_log(avctx, AV_LOG_WARNING, "Invalid chroma sample location
> >> %d, setting to unspecified\n", avctx->chroma_sample_location);
> >> +            avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
> >> +        }
> >>
> >>
> > Is there a way to long only once, this seems like it could spam the user
> > full of these warnings.
> 
> One could add a field like shown_chroma_loc_warning to SPS, but I think
> that would be a bit too much overhead for this.
> Alternatively, one could drop the log message entirely. (Wrong color
> primaries etc. aren't logged either...)

I think making it a "normally not displayed" log level would be a
better choice than removing it entirely

also a generic solution is possible, like a

av_log_once(context, &context->my_message_state, ...)
such function would also allow simplifying a bit of code

[...]
diff mbox

Patch

diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index 8218e3a010..089bfc650a 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -181,6 +181,10 @@  static inline int decode_vui_parameters(GetBitContext *gb, AVCodecContext *avctx
     if (get_bits1(gb)) {
         /* chroma_sample_location_type_top_field */
         avctx->chroma_sample_location = get_ue_golomb(gb) + 1;
+        if (!av_chroma_location_name(avctx->chroma_sample_location)) {
+            av_log(avctx, AV_LOG_WARNING, "Invalid chroma sample location %d, setting to unspecified\n", avctx->chroma_sample_location);
+            avctx->chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
+        }
         get_ue_golomb(gb);  /* chroma_sample_location_type_bottom_field */
     }