[FFmpeg-devel] avcodec/h264dec: get field_order for typical frames

Submitted by Paul B Mahol on Dec. 5, 2018, 11:42 a.m.

Details

Message ID 20181205114239.32233-1-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol Dec. 5, 2018, 11:42 a.m.
This is normally set by parser but parsing is not always enabled.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/h264dec.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Michael Niedermayer Dec. 5, 2018, 7:11 p.m.
On Wed, Dec 05, 2018 at 12:42:39PM +0100, Paul B Mahol wrote:
> This is normally set by parser but parsing is not always enabled.
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavcodec/h264dec.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

breaks: fate-api-h264-slice
make: *** [fate-api-h264-slice] Error 139

[...]
Paul B Mahol Dec. 5, 2018, 7:38 p.m.
On 12/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Wed, Dec 05, 2018 at 12:42:39PM +0100, Paul B Mahol wrote:
>> This is normally set by parser but parsing is not always enabled.
>>
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  libavcodec/h264dec.c | 18 ++++++++++++++++++
>>  1 file changed, 18 insertions(+)
>
> breaks: fate-api-h264-slice
> make: *** [fate-api-h264-slice] Error 139

How so? Do you know why?

> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Breaking DRM is a little like attempting to break through a door even
> though the window is wide open and the only thing in the house is a bunch
> of things you dont want and which you would get tomorrow for free anyway
>
Michael Niedermayer Dec. 6, 2018, 9:35 p.m.
On Wed, Dec 05, 2018 at 08:38:41PM +0100, Paul B Mahol wrote:
> On 12/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > On Wed, Dec 05, 2018 at 12:42:39PM +0100, Paul B Mahol wrote:
> >> This is normally set by parser but parsing is not always enabled.
> >>
> >> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> >> ---
> >>  libavcodec/h264dec.c | 18 ++++++++++++++++++
> >>  1 file changed, 18 insertions(+)
> >
> > breaks: fate-api-h264-slice
> > make: *** [fate-api-h264-slice] Error 139
> 
> How so? Do you know why?

thats what valgrind says:

==16920== Invalid read of size 4
==16920==    at 0x51ED49: h264_decode_frame (h264dec.c:1022)
==16920==    by 0x473A1C: decode_simple_internal (decode.c:433)
==16920==    by 0x4746A3: decode_simple_receive_frame (decode.c:629)
==16920==    by 0x47476E: decode_receive_frame_internal (decode.c:647)
==16920==    by 0x4749C9: avcodec_send_packet (decode.c:705)
==16920==    by 0x408ACA: decode (api-h264-slice-test.c:57)
==16920==    by 0x409268: main (api-h264-slice-test.c:211)
==16920==  Address 0x488 is not stack'd, malloc'd or (recently) free'd
==16920== 
==16920== 
==16920== Process terminating with default action of signal 11 (SIGSEGV)
==16920==  Access not within mapped region at address 0x488
==16920==    at 0x51ED49: h264_decode_frame (h264dec.c:1022)
==16920==    by 0x473A1C: decode_simple_internal (decode.c:433)
==16920==    by 0x4746A3: decode_simple_receive_frame (decode.c:629)
==16920==    by 0x47476E: decode_receive_frame_internal (decode.c:647)
==16920==    by 0x4749C9: avcodec_send_packet (decode.c:705)
==16920==    by 0x408ACA: decode (api-h264-slice-test.c:57)
==16920==    by 0x409268: main (api-h264-slice-test.c:211)

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 00d922fbe9..39142da7af 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -1018,6 +1018,24 @@  static int h264_decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
+    if (h->picture_structure == PICT_FRAME) {
+        if (h->ps.sps->pic_struct_present_flag && h->sei.picture_timing.present) {
+            switch (h->sei.picture_timing.pic_struct) {
+            case H264_SEI_PIC_STRUCT_TOP_BOTTOM:
+            case H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
+                avctx->field_order = AV_FIELD_TT;
+                break;
+            case H264_SEI_PIC_STRUCT_BOTTOM_TOP:
+            case H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
+                avctx->field_order = AV_FIELD_BB;
+                break;
+            default:
+                avctx->field_order = AV_FIELD_PROGRESSIVE;
+                break;
+            }
+        }
+    }
+
     av_assert0(pict->buf[0] || !*got_frame);
 
     ff_h264_unref_picture(h, &h->last_pic_for_ec);