diff mbox

[FFmpeg-devel,1/2] avcodec/vaapi: slice_vertical_position starts from zero for the second field

Message ID dd48f849-d8b8-2040-6de2-7ebe9a2995ac@carpalis.nl
State Accepted
Commit 3d028b7b72a071df7ec2b5a2ccdbf767eec60505
Headers show

Commit Message

Jerome Borsboom May 9, 2018, 5:50 a.m. UTC
Contrary to VC-1 spec, VAAPI expects the row address of the first
macroblock row in the first slice to start from zero for the second
field in a field interlaced picture.

Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
---
This patch set adds support for hardware decoding multi-slice field interlaced
pictures. With this patch set, the SA10180 test file decodes correctly with
VAAPI hardware acceleration. This was succesfully tested on Intel Haswell platform.

 libavcodec/vaapi_vc1.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Xiang, Haihao May 9, 2018, 8:54 a.m. UTC | #1
On Wed, 2018-05-09 at 07:50 +0200, Jerome Borsboom wrote:
> Contrary to VC-1 spec, VAAPI expects the row address of the first

> macroblock row in the first slice to start from zero for the second

> field in a field interlaced picture.

> 

> Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>

> ---

> This patch set adds support for hardware decoding multi-slice field interlaced

> pictures. With this patch set, the SA10180 test file decodes correctly with

> VAAPI hardware acceleration. This was succesfully tested on Intel Haswell

> platform.

> 


I still see lots of artifacts for a multi-slice field interfaced VC-1 video on
Coffee Lake, maybe we should fix it in the driver 

Thanks
Haihao


>  libavcodec/vaapi_vc1.c | 8 +++++++-

>  1 file changed, 7 insertions(+), 1 deletion(-)

> 

> diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c

> index bdb5e24cc5..921ca6391b 100644

> --- a/libavcodec/vaapi_vc1.c

> +++ b/libavcodec/vaapi_vc1.c

> @@ -467,6 +467,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx,

> const uint8_t *buffer,

>      const MpegEncContext *s = &v->s;

>      VAAPIDecodePicture *pic = s->current_picture_ptr-

> >hwaccel_picture_private;

>      VASliceParameterBufferVC1 slice_param;

> +    int mb_height;

>      int err;

>  

>      /* Current bit buffer is beyond any marker for VC-1, so skip it */

> @@ -475,12 +476,17 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx,

> const uint8_t *buffer,

>          size -= 4;

>      }

>  

> +    if (v->fcm == ILACE_FIELD)

> +        mb_height = avctx->coded_height + 31 >> 5;

> +    else

> +        mb_height = avctx->coded_height + 15 >> 4;

> +

>      slice_param = (VASliceParameterBufferVC1) {

>          .slice_data_size         = size,

>          .slice_data_offset       = 0,

>          .slice_data_flag         = VA_SLICE_DATA_FLAG_ALL,

>          .macroblock_offset       = get_bits_count(&s->gb),

> -        .slice_vertical_position = s->mb_y,

> +        .slice_vertical_position = s->mb_y % mb_height,

>      };

>  

>      err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
Jerome Borsboom May 9, 2018, noon UTC | #2
>> Contrary to VC-1 spec, VAAPI expects the row address of the first
>> macroblock row in the first slice to start from zero for the second
>> field in a field interlaced picture.
>> 
>> Signed-off-by: Jerome Borsboom <jerome.borsboom at carpalis.nl>
>> ---
>> This patch set adds support for hardware decoding multi-slice field interlaced
>> pictures. With this patch set, the SA10180 test file decodes correctly with
>> VAAPI hardware acceleration. This was succesfully tested on Intel Haswell
>> platform.
>> 
> 
> I still see lots of artifacts for a multi-slice field interfaced VC-1 video on
> Coffee Lake, maybe we should fix it in the driver 
> 
> Thanks
> Haihao

I suppose you also applied the second part of this patch and still see
artifacts. I cannot check for Coffee Lake, but there may be issues with
the VAAPI driver for CL platform. The patches are just a copy of the
multi-slice support for frame interlaced images, so nothing special there.

Could you share (part of) the video you used to check on Coffee Lake so
that I can see how Haswell performs?


Regards,
Jerome
Xiang, Haihao May 10, 2018, 7:03 a.m. UTC | #3
On Wed, 2018-05-09 at 14:00 +0200, Jerome Borsboom wrote:
> > > Contrary to VC-1 spec, VAAPI expects the row address of the first

> > > macroblock row in the first slice to start from zero for the second

> > > field in a field interlaced picture.

> > > 

> > > Signed-off-by: Jerome Borsboom <jerome.borsboom at carpalis.nl>

> > > ---

> > > This patch set adds support for hardware decoding multi-slice field

> > > interlaced

> > > pictures. With this patch set, the SA10180 test file decodes correctly

> > > with

> > > VAAPI hardware acceleration. This was succesfully tested on Intel Haswell

> > > platform.

> > > 

> > 

> > I still see lots of artifacts for a multi-slice field interfaced VC-1 video

> > on

> > Coffee Lake, maybe we should fix it in the driver 

> > 

> > Thanks

> > Haihao

> 

> I suppose you also applied the second part of this patch and still see

> artifacts. I cannot check for Coffee Lake, but there may be issues with

> the VAAPI driver for CL platform. The patches are just a copy of the

> multi-slice support for frame interlaced images, so nothing special there.

> 

> Could you share (part of) the video you used to check on Coffee Lake so

> that I can see how Haswell performs?

> 


I apologize that I used a video with Luma/Chroma scaling set which is not
supported by the driver. I confirmed your patchset works for me with other
multi-slice field interfaced VC-1 video.

Thanks
Haihao


> 

> Regards,

> Jerome

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Jerome Borsboom June 8, 2018, 9:09 a.m. UTC | #4
If there are no more issues or remarks with these two patches, could
someone please commit them?

Thanks!


Regards,
Jerome
Michael Niedermayer June 15, 2018, 12:35 a.m. UTC | #5
On Wed, May 09, 2018 at 07:50:23AM +0200, Jerome Borsboom wrote:
> Contrary to VC-1 spec, VAAPI expects the row address of the first
> macroblock row in the first slice to start from zero for the second
> field in a field interlaced picture.
> 
> Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
> ---
> This patch set adds support for hardware decoding multi-slice field interlaced
> pictures. With this patch set, the SA10180 test file decodes correctly with
> VAAPI hardware acceleration. This was succesfully tested on Intel Haswell platform.

are these 2 patches enough or something else ?
It feels like iam missing something but

i tried
./ffmpeg -hwaccel vaapi -i SA10180.vc1 -pix_fmt yuv420p -f framecrc crcpatch12

but ffmpeg spews errors at me:

ibva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
Stream mapping:
  Stream #0:0 -> #0:0 (vc1 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, framecrc, to 'crcpatch12':
  Metadata:
    encoder         : Lavf58.17.100
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x480 [SAR 1:1 DAR 3:2], q=2-31, 103680 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.20.102 rawvideo
[vc1 @ 0x3d430c0] Failed to end picture decode issue: 23 (unknown libva error / description missing).
Error while decoding stream #0:0: Input/output error


[...]
Jerome Borsboom June 15, 2018, 5:29 a.m. UTC | #6
Is your VAAPI library and VAAPI driver new enough? You need at least
libva-2.1.0 (VA-API version 1.1.0) and intel-vaapi-driver-2.1.0 for
interlaced VC-1 decoding. From the output, I think you are using an
older version and the error is just the libva library bailing out for
not supporting interlaced VC-1.


Regards,
Jerome

> are these 2 patches enough or something else ?
> It feels like iam missing something but
> 
> i tried
> ./ffmpeg -hwaccel vaapi -i SA10180.vc1 -pix_fmt yuv420p -f framecrc crcpatch12
> 
> but ffmpeg spews errors at me:
> 
> ibva info: VA-API version 0.39.0
> libva info: va_getDriverName() returns 0
> libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
> libva info: Found init function __vaDriverInit_0_39
> libva info: va_openDriver() returns 0
> Stream mapping:
>   Stream #0:0 -> #0:0 (vc1 (native) -> rawvideo (native))
> Press [q] to stop, [?] for help
> Output #0, framecrc, to 'crcpatch12':
>   Metadata:
>     encoder         : Lavf58.17.100
>     Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x480 [SAR 1:1 DAR 3:2], q=2-31, 103680 kb/s, 25 fps, 25 tbn, 25 tbc
>     Metadata:
>       encoder         : Lavc58.20.102 rawvideo
> [vc1 @ 0x3d430c0] Failed to end picture decode issue: 23 (unknown libva error / description missing).
> Error while decoding stream #0:0: Input/output error
Xiang, Haihao June 15, 2018, 5:44 a.m. UTC | #7
I may confirm that the error is returned from the old version of libva and vaapi
driver w/wo this patch, the command below works well for me if using the new
version of libva and vaapi driver.  

Thanks
Haihao


> Is your VAAPI library and VAAPI driver new enough? You need at least

> libva-2.1.0 (VA-API version 1.1.0) and intel-vaapi-driver-2.1.0 for

> interlaced VC-1 decoding. From the output, I think you are using an

> older version and the error is just the libva library bailing out for

> not supporting interlaced VC-1.

> 

> 

> Regards,

> Jerome

> 

> > are these 2 patches enough or something else ?

> > It feels like iam missing something but

> > 

> > i tried

> > ./ffmpeg -hwaccel vaapi -i SA10180.vc1 -pix_fmt yuv420p -f framecrc

> > crcpatch12

> > 

> > but ffmpeg spews errors at me:

> > 

> > ibva info: VA-API version 0.39.0

> > libva info: va_getDriverName() returns 0

> > libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so

> > libva info: Found init function __vaDriverInit_0_39

> > libva info: va_openDriver() returns 0

> > Stream mapping:

> >   Stream #0:0 -> #0:0 (vc1 (native) -> rawvideo (native))

> > Press [q] to stop, [?] for help

> > Output #0, framecrc, to 'crcpatch12':

> >   Metadata:

> >     encoder         : Lavf58.17.100

> >     Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x480 [SAR

> > 1:1 DAR 3:2], q=2-31, 103680 kb/s, 25 fps, 25 tbn, 25 tbc

> >     Metadata:

> >       encoder         : Lavc58.20.102 rawvideo

> > [vc1 @ 0x3d430c0] Failed to end picture decode issue: 23 (unknown libva

> > error / description missing).

> > Error while decoding stream #0:0: Input/output error

> 

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Michael Niedermayer June 15, 2018, 10:06 a.m. UTC | #8
On Fri, Jun 15, 2018 at 07:29:31AM +0200, Jerome Borsboom wrote:
> Is your VAAPI library and VAAPI driver new enough? You need at least
> libva-2.1.0 (VA-API version 1.1.0) and intel-vaapi-driver-2.1.0 for
> interlaced VC-1 decoding. From the output, I think you are using an
> older version and the error is just the libva library bailing out for
> not supporting interlaced VC-1.

yes, it seems its 1.7.0, thats whats in ubuntu 16.04

[...]
Carl Eugen Hoyos June 16, 2018, 5:57 p.m. UTC | #9
2018-06-08 11:09 GMT+02:00, Jerome Borsboom <jerome.borsboom@carpalis.nl>:
> If there are no more issues or remarks with these two patches, could
> someone please commit them?

I cannot test, sorry!

Perhaps you could send your public git key to Michael and push yourself?

Thank you, Carl Eugen
Mark Thompson June 17, 2018, 3:34 p.m. UTC | #10
On 15/06/18 06:44, Xiang, Haihao wrote:
> 
> I may confirm that the error is returned from the old version of libva and vaapi
> driver w/wo this patch, the command below works well for me if using the new
> version of libva and vaapi driver.  

Trying others:

* The Mesa driver running on an AMD Polaris returns success but the output data is wrong for interlaced input.  I think it just isn't supported.

* The iHD driver running on Skylake GT3 always falls over when given an interlaced stream - the decode issue succeeds, but it returns "Failed to sync surface 0x5: 23 (internal decoding error)." when trying to get the result.

I tested on different machines with the current i965 driver and this looks good, so I will apply it.

However, since it only works on recent i965 I think that means something should be added to VAAPI indicate that support so that we can check it here.  The other cases (including old i965) all say they support the profile and therefore pass the point where we commit to hardware decode, but then they all fail later in different ways.  Maybe that should be a new config attribute, kindof like VAConfigAttribEncInterlaced for decode?

Thanks,

- Mark


>> Is your VAAPI library and VAAPI driver new enough? You need at least
>> libva-2.1.0 (VA-API version 1.1.0) and intel-vaapi-driver-2.1.0 for
>> interlaced VC-1 decoding. From the output, I think you are using an
>> older version and the error is just the libva library bailing out for
>> not supporting interlaced VC-1.
>>
>>
>> Regards,
>> Jerome
>>
>>> are these 2 patches enough or something else ?
>>> It feels like iam missing something but
>>>
>>> i tried
>>> ./ffmpeg -hwaccel vaapi -i SA10180.vc1 -pix_fmt yuv420p -f framecrc
>>> crcpatch12
>>>
>>> but ffmpeg spews errors at me:
>>>
>>> ibva info: VA-API version 0.39.0
>>> libva info: va_getDriverName() returns 0
>>> libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
>>> libva info: Found init function __vaDriverInit_0_39
>>> libva info: va_openDriver() returns 0
>>> Stream mapping:
>>>   Stream #0:0 -> #0:0 (vc1 (native) -> rawvideo (native))
>>> Press [q] to stop, [?] for help
>>> Output #0, framecrc, to 'crcpatch12':
>>>   Metadata:
>>>     encoder         : Lavf58.17.100
>>>     Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x480 [SAR
>>> 1:1 DAR 3:2], q=2-31, 103680 kb/s, 25 fps, 25 tbn, 25 tbc
>>>     Metadata:
>>>       encoder         : Lavc58.20.102 rawvideo
>>> [vc1 @ 0x3d430c0] Failed to end picture decode issue: 23 (unknown libva
>>> error / description missing).
>>> Error while decoding stream #0:0: Input/output error
>>
diff mbox

Patch

diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index bdb5e24cc5..921ca6391b 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -467,6 +467,7 @@  static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
     const MpegEncContext *s = &v->s;
     VAAPIDecodePicture *pic = s->current_picture_ptr->hwaccel_picture_private;
     VASliceParameterBufferVC1 slice_param;
+    int mb_height;
     int err;
 
     /* Current bit buffer is beyond any marker for VC-1, so skip it */
@@ -475,12 +476,17 @@  static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
         size -= 4;
     }
 
+    if (v->fcm == ILACE_FIELD)
+        mb_height = avctx->coded_height + 31 >> 5;
+    else
+        mb_height = avctx->coded_height + 15 >> 4;
+
     slice_param = (VASliceParameterBufferVC1) {
         .slice_data_size         = size,
         .slice_data_offset       = 0,
         .slice_data_flag         = VA_SLICE_DATA_FLAG_ALL,
         .macroblock_offset       = get_bits_count(&s->gb),
-        .slice_vertical_position = s->mb_y,
+        .slice_vertical_position = s->mb_y % mb_height,
     };
 
     err = ff_vaapi_decode_make_slice_buffer(avctx, pic,