diff mbox

[FFmpeg-devel,2/3,v1.2] avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding

Message ID bacec69d-d034-3588-c59a-c715f56263b6@carpalis.nl
State Accepted
Commit 883bdc5fb7c4f579eba1c10e01487b08601ec0be
Headers show

Commit Message

Jerome Borsboom March 1, 2018, 8:07 a.m. UTC
v1.1->v1.2: Changed ifdefs around vc1_get_INTCOMPFIELD, vc1_get_LUMSCALE2,
and vc1_get_LUMSHIFT2 to av_unused.

avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding

Pass necessary bitstream elements to the VAAPI VC-1 decoder in order
to start doing interlaced decoding in hardware.

Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
---
 libavcodec/vaapi_vc1.c | 163 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 134 insertions(+), 29 deletions(-)

Comments

Moritz Barsnick March 1, 2018, 5:15 p.m. UTC | #1
On Thu, Mar 01, 2018 at 09:07:17 +0100, Jerome Borsboom wrote:
> v1.1->v1.2: Changed ifdefs around vc1_get_INTCOMPFIELD, vc1_get_LUMSCALE2,
> and vc1_get_LUMSHIFT2 to av_unused.

When emailing like this, you need to place the additional (manually
edited?) comments below the patch's '---' line. Otherwise they will
become part of the commit message when pushing. (Changes between
reviews and comments like "Please ignore the previous patch" are
obviously not meant for the commit message.)

> avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding
> 
> Pass necessary bitstream elements to the VAAPI VC-1 decoder in order
> to start doing interlaced decoding in hardware.
> 
> Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
> ---

Down here.

>  libavcodec/vaapi_vc1.c | 163 ++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 134 insertions(+), 29 deletions(-)
> 
> diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
[...]

Cheers,
Moritz
Mark Thompson March 1, 2018, 10:43 p.m. UTC | #2
On 01/03/18 08:07, Jerome Borsboom wrote:
> v1.1->v1.2: Changed ifdefs around vc1_get_INTCOMPFIELD, vc1_get_LUMSCALE2,
> and vc1_get_LUMSHIFT2 to av_unused.
> 
> avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding
> 
> Pass necessary bitstream elements to the VAAPI VC-1 decoder in order
> to start doing interlaced decoding in hardware.
> 
> Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
> ---
>  libavcodec/vaapi_vc1.c | 163 ++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 134 insertions(+), 29 deletions(-)

Wrt hashes, here is fate/vc1/ilaced_twomv.vc1 from a few different decoders:

libavcodec software decoder:

0,          0,          0,        1,  3110400, 0x764f8856
0,          2,          2,        1,  3110400, 0x3b615b79
0,          3,          3,        1,  3110400, 0x4fbb6f84
0,          4,          4,        1,  3110400, 0xc1ca8532
0,          5,          5,        1,  3110400, 0xb6e7d363
0,          6,          6,        1,  3110400, 0x1beb5c34
0,          7,          7,        1,  3110400, 0xcb8cb061
0,          8,          8,        1,  3110400, 0x13ddbd61
0,          9,          9,        1,  3110400, 0xde8f052f
0,         10,         10,        1,  3110400, 0x4d4072db
0,         11,         11,        1,  3110400, 0x4e5d29e3
0,         12,         12,        1,  3110400, 0x75300531
0,         13,         13,        1,  3110400, 0x1114285a

VAAPI, "Intel i965 driver for Intel(R) Coffee Lake - 2.1.1.pre1 (2.0.0-140-gff23e69)":

0,          0,          0,        1,  3110400, 0xc95e8861
0,          2,          2,        1,  3110400, 0xf58b5cbf
0,          3,          3,        1,  3110400, 0x2f866f33
0,          4,          4,        1,  3110400, 0x05c18415
0,          5,          5,        1,  3110400, 0x94dff199
0,          6,          6,        1,  3110400, 0xf31fda77
0,          7,          7,        1,  3110400, 0x60b1b2da
0,          8,          8,        1,  3110400, 0x748993f5
0,          9,          9,        1,  3110400, 0x750fdf14
0,         10,         10,        1,  3110400, 0x0879792c
0,         11,         11,        1,  3110400, 0x7e0e60fa
0,         12,         12,        1,  3110400, 0xda5bd837
0,         13,         13,        1,  3110400, 0xb6346ccf

VAAPI, "Mesa Gallium driver 18.1.0-devel for AMD Radeon (TM) RX 460 Graphics (POLARIS11 / DRM 3.23.0 / 4.15.7, LLVM 4.0.1)":

0,          0,          0,        1,  3110400, 0xc95e8861
0,          2,          2,        1,  3110400, 0xafefc967
0,          3,          3,        1,  3110400, 0x1d736d3b
0,          4,          4,        1,  3110400, 0x4f0fe807
0,          5,          5,        1,  3110400, 0x758c6e9b
0,          6,          6,        1,  3110400, 0x56a5c92a
0,          7,          7,        1,  3110400, 0xa60fcf66
0,          8,          8,        1,  3110400, 0x0c638017
0,          9,          9,        1,  3110400, 0x3fe3310c
0,         10,         10,        1,  3110400, 0x3d2ea8de
0,         11,         11,        1,  3110400, 0xe2f8de62
0,         12,         12,        1,  3110400, 0xa309cd68
0,         13,         13,        1,  3110400, 0x8602abb1

Microsoft decoder (thanks to Hendrik for these):

0,          0,          0,        1,  3110400, 0xc95e8861
0,          2,          2,        1,  3110400, 0xf58b5cbf
0,          3,          3,        1,  3110400, 0x2f866f33
0,          4,          4,        1,  3110400, 0x05c18415
0,          5,          5,        1,  3110400, 0x4077ca93
0,          6,          6,        1,  3110400, 0x44d105fc
0,          7,          7,        1,  3110400, 0xa0608374
0,          8,          8,        1,  3110400, 0x407689dc
0,          9,          9,        1,  3110400, 0x4707d00a
0,         10,         10,        1,  3110400, 0x74986831
0,         11,         11,        1,  3110400, 0xa5912619
0,         12,         12,        1,  3110400, 0x44aa5565
0,         13,         13,        1,  3110400, 0xb9752774

The VAAPI hardware implementations agree with the Microsoft decoder for the initial four (Intel) or one (AMD) frames, while the software decoder doesn't agree at all.  Unfortunately the AMD output is completely broken after the first frame, but the Intel output does look sensible through the whole sequence.  So, while this could probably be improved in drivers just as it could in the software decoder, the FATE test is not relevant here so this discussion shouldn't block anything.

As such, I'm happy to apply all of this as it is now.  Does anyone have any further comments, especially about the VC-1 parts of this change?  If not, I'll apply the whole set this weekend.

Thanks,

- Mark
Jun Zhao March 2, 2018, 1:23 a.m. UTC | #3
On 2018/3/2 6:43, Mark Thompson wrote:
> On 01/03/18 08:07, Jerome Borsboom wrote:
>> v1.1->v1.2: Changed ifdefs around vc1_get_INTCOMPFIELD, vc1_get_LUMSCALE2,
>> and vc1_get_LUMSHIFT2 to av_unused.
>>
>> avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding
>>
>> Pass necessary bitstream elements to the VAAPI VC-1 decoder in order
>> to start doing interlaced decoding in hardware.
>>
>> Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
>> ---
>>  libavcodec/vaapi_vc1.c | 163 ++++++++++++++++++++++++++++++++++++++++---------
>>  1 file changed, 134 insertions(+), 29 deletions(-)
> Wrt hashes, here is fate/vc1/ilaced_twomv.vc1 from a few different decoders:
>
> libavcodec software decoder:
>
> 0,          0,          0,        1,  3110400, 0x764f8856
> 0,          2,          2,        1,  3110400, 0x3b615b79
> 0,          3,          3,        1,  3110400, 0x4fbb6f84
> 0,          4,          4,        1,  3110400, 0xc1ca8532
> 0,          5,          5,        1,  3110400, 0xb6e7d363
> 0,          6,          6,        1,  3110400, 0x1beb5c34
> 0,          7,          7,        1,  3110400, 0xcb8cb061
> 0,          8,          8,        1,  3110400, 0x13ddbd61
> 0,          9,          9,        1,  3110400, 0xde8f052f
> 0,         10,         10,        1,  3110400, 0x4d4072db
> 0,         11,         11,        1,  3110400, 0x4e5d29e3
> 0,         12,         12,        1,  3110400, 0x75300531
> 0,         13,         13,        1,  3110400, 0x1114285a
>
> VAAPI, "Intel i965 driver for Intel(R) Coffee Lake - 2.1.1.pre1 (2.0.0-140-gff23e69)":
>
> 0,          0,          0,        1,  3110400, 0xc95e8861
> 0,          2,          2,        1,  3110400, 0xf58b5cbf
> 0,          3,          3,        1,  3110400, 0x2f866f33
> 0,          4,          4,        1,  3110400, 0x05c18415
> 0,          5,          5,        1,  3110400, 0x94dff199
> 0,          6,          6,        1,  3110400, 0xf31fda77
> 0,          7,          7,        1,  3110400, 0x60b1b2da
> 0,          8,          8,        1,  3110400, 0x748993f5
> 0,          9,          9,        1,  3110400, 0x750fdf14
> 0,         10,         10,        1,  3110400, 0x0879792c
> 0,         11,         11,        1,  3110400, 0x7e0e60fa
> 0,         12,         12,        1,  3110400, 0xda5bd837
> 0,         13,         13,        1,  3110400, 0xb6346ccf
>
> VAAPI, "Mesa Gallium driver 18.1.0-devel for AMD Radeon (TM) RX 460 Graphics (POLARIS11 / DRM 3.23.0 / 4.15.7, LLVM 4.0.1)":
>
> 0,          0,          0,        1,  3110400, 0xc95e8861
> 0,          2,          2,        1,  3110400, 0xafefc967
> 0,          3,          3,        1,  3110400, 0x1d736d3b
> 0,          4,          4,        1,  3110400, 0x4f0fe807
> 0,          5,          5,        1,  3110400, 0x758c6e9b
> 0,          6,          6,        1,  3110400, 0x56a5c92a
> 0,          7,          7,        1,  3110400, 0xa60fcf66
> 0,          8,          8,        1,  3110400, 0x0c638017
> 0,          9,          9,        1,  3110400, 0x3fe3310c
> 0,         10,         10,        1,  3110400, 0x3d2ea8de
> 0,         11,         11,        1,  3110400, 0xe2f8de62
> 0,         12,         12,        1,  3110400, 0xa309cd68
> 0,         13,         13,        1,  3110400, 0x8602abb1
>
> Microsoft decoder (thanks to Hendrik for these):
>
> 0,          0,          0,        1,  3110400, 0xc95e8861
> 0,          2,          2,        1,  3110400, 0xf58b5cbf
> 0,          3,          3,        1,  3110400, 0x2f866f33
> 0,          4,          4,        1,  3110400, 0x05c18415
> 0,          5,          5,        1,  3110400, 0x4077ca93
> 0,          6,          6,        1,  3110400, 0x44d105fc
> 0,          7,          7,        1,  3110400, 0xa0608374
> 0,          8,          8,        1,  3110400, 0x407689dc
> 0,          9,          9,        1,  3110400, 0x4707d00a
> 0,         10,         10,        1,  3110400, 0x74986831
> 0,         11,         11,        1,  3110400, 0xa5912619
> 0,         12,         12,        1,  3110400, 0x44aa5565
> 0,         13,         13,        1,  3110400, 0xb9752774
>
> The VAAPI hardware implementations agree with the Microsoft decoder for the initial four (Intel) or one (AMD) frames, while the software decoder doesn't agree at all.  Unfortunately the AMD output is completely broken after the first frame, but the Intel output does look sensible through the whole sequence.  So, while this could probably be improved in drivers just as it could in the software decoder, the FATE test is not relevant here so this discussion shouldn't block anything.
>
> As such, I'm happy to apply all of this as it is now.  Does anyone have any further comments, especially about the VC-1 parts of this change?  If not, I'll apply the whole set this weekend.
>
> Thanks,
>
> - Mark
I am OK to merge this part, in fact, I have a similar patches
(https://github.com/mypopydev/FFmpeg/commit/da0e142cfc6302790bba08704d4cc0b507a78f70),
but I think Jerome Borsboom did better job than me, so I didn't submit
the patch.

For VC1 interlaced decoding can't bit match (bit-exact) for Windows
Decoder/FFmpeg SW Decoder/VA-API HWAccel Decoder, I guess the root cause
is the DCT/iDCT precision.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Hendrik Leppkes March 2, 2018, 10:22 a.m. UTC | #4
On Fri, Mar 2, 2018 at 2:23 AM, Jun Zhao <mypopydev@gmail.com> wrote:
>
>
> On 2018/3/2 6:43, Mark Thompson wrote:
>> On 01/03/18 08:07, Jerome Borsboom wrote:
>>> v1.1->v1.2: Changed ifdefs around vc1_get_INTCOMPFIELD, vc1_get_LUMSCALE2,
>>> and vc1_get_LUMSHIFT2 to av_unused.
>>>
>>> avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding
>>>
>>> Pass necessary bitstream elements to the VAAPI VC-1 decoder in order
>>> to start doing interlaced decoding in hardware.
>>>
>>> Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
>>> ---
>>>  libavcodec/vaapi_vc1.c | 163 ++++++++++++++++++++++++++++++++++++++++---------
>>>  1 file changed, 134 insertions(+), 29 deletions(-)
>> Wrt hashes, here is fate/vc1/ilaced_twomv.vc1 from a few different decoders:
>>
>> libavcodec software decoder:
>>
>> 0,          0,          0,        1,  3110400, 0x764f8856
>> 0,          2,          2,        1,  3110400, 0x3b615b79
>> 0,          3,          3,        1,  3110400, 0x4fbb6f84
>> 0,          4,          4,        1,  3110400, 0xc1ca8532
>> 0,          5,          5,        1,  3110400, 0xb6e7d363
>> 0,          6,          6,        1,  3110400, 0x1beb5c34
>> 0,          7,          7,        1,  3110400, 0xcb8cb061
>> 0,          8,          8,        1,  3110400, 0x13ddbd61
>> 0,          9,          9,        1,  3110400, 0xde8f052f
>> 0,         10,         10,        1,  3110400, 0x4d4072db
>> 0,         11,         11,        1,  3110400, 0x4e5d29e3
>> 0,         12,         12,        1,  3110400, 0x75300531
>> 0,         13,         13,        1,  3110400, 0x1114285a
>>
>> VAAPI, "Intel i965 driver for Intel(R) Coffee Lake - 2.1.1.pre1 (2.0.0-140-gff23e69)":
>>
>> 0,          0,          0,        1,  3110400, 0xc95e8861
>> 0,          2,          2,        1,  3110400, 0xf58b5cbf
>> 0,          3,          3,        1,  3110400, 0x2f866f33
>> 0,          4,          4,        1,  3110400, 0x05c18415
>> 0,          5,          5,        1,  3110400, 0x94dff199
>> 0,          6,          6,        1,  3110400, 0xf31fda77
>> 0,          7,          7,        1,  3110400, 0x60b1b2da
>> 0,          8,          8,        1,  3110400, 0x748993f5
>> 0,          9,          9,        1,  3110400, 0x750fdf14
>> 0,         10,         10,        1,  3110400, 0x0879792c
>> 0,         11,         11,        1,  3110400, 0x7e0e60fa
>> 0,         12,         12,        1,  3110400, 0xda5bd837
>> 0,         13,         13,        1,  3110400, 0xb6346ccf
>>
>> VAAPI, "Mesa Gallium driver 18.1.0-devel for AMD Radeon (TM) RX 460 Graphics (POLARIS11 / DRM 3.23.0 / 4.15.7, LLVM 4.0.1)":
>>
>> 0,          0,          0,        1,  3110400, 0xc95e8861
>> 0,          2,          2,        1,  3110400, 0xafefc967
>> 0,          3,          3,        1,  3110400, 0x1d736d3b
>> 0,          4,          4,        1,  3110400, 0x4f0fe807
>> 0,          5,          5,        1,  3110400, 0x758c6e9b
>> 0,          6,          6,        1,  3110400, 0x56a5c92a
>> 0,          7,          7,        1,  3110400, 0xa60fcf66
>> 0,          8,          8,        1,  3110400, 0x0c638017
>> 0,          9,          9,        1,  3110400, 0x3fe3310c
>> 0,         10,         10,        1,  3110400, 0x3d2ea8de
>> 0,         11,         11,        1,  3110400, 0xe2f8de62
>> 0,         12,         12,        1,  3110400, 0xa309cd68
>> 0,         13,         13,        1,  3110400, 0x8602abb1
>>
>> Microsoft decoder (thanks to Hendrik for these):
>>
>> 0,          0,          0,        1,  3110400, 0xc95e8861
>> 0,          2,          2,        1,  3110400, 0xf58b5cbf
>> 0,          3,          3,        1,  3110400, 0x2f866f33
>> 0,          4,          4,        1,  3110400, 0x05c18415
>> 0,          5,          5,        1,  3110400, 0x4077ca93
>> 0,          6,          6,        1,  3110400, 0x44d105fc
>> 0,          7,          7,        1,  3110400, 0xa0608374
>> 0,          8,          8,        1,  3110400, 0x407689dc
>> 0,          9,          9,        1,  3110400, 0x4707d00a
>> 0,         10,         10,        1,  3110400, 0x74986831
>> 0,         11,         11,        1,  3110400, 0xa5912619
>> 0,         12,         12,        1,  3110400, 0x44aa5565
>> 0,         13,         13,        1,  3110400, 0xb9752774
>>
>> The VAAPI hardware implementations agree with the Microsoft decoder for the initial four (Intel) or one (AMD) frames, while the software decoder doesn't agree at all.  Unfortunately the AMD output is completely broken after the first frame, but the Intel output does look sensible through the whole sequence.  So, while this could probably be improved in drivers just as it could in the software decoder, the FATE test is not relevant here so this discussion shouldn't block anything.
>>
>> As such, I'm happy to apply all of this as it is now.  Does anyone have any further comments, especially about the VC-1 parts of this change?  If not, I'll apply the whole set this weekend.
>>
>> Thanks,
>>
>> - Mark
> I am OK to merge this part, in fact, I have a similar patches
> (https://github.com/mypopydev/FFmpeg/commit/da0e142cfc6302790bba08704d4cc0b507a78f70),
> but I think Jerome Borsboom did better job than me, so I didn't submit
> the patch.
>
> For VC1 interlaced decoding can't bit match (bit-exact) for Windows
> Decoder/FFmpeg SW Decoder/VA-API HWAccel Decoder, I guess the root cause
> is the DCT/iDCT precision.

For the record, DXVA2/D3D11 on my Intel Haswell GPU also matches the
Intel VAAPI results, so it seems to be up to the hardware/driver.
NVIDIA DXVA2/D3D11 matches the Microsoft software decoder, FWIW.

Is VC-1 even specified strong enough to result in bit-exact output
from every possible decoder?

- Hendrik
Mark Thompson March 4, 2018, 10:45 p.m. UTC | #5
On 01/03/18 22:43, Mark Thompson wrote:
> On 01/03/18 08:07, Jerome Borsboom wrote:
>> v1.1->v1.2: Changed ifdefs around vc1_get_INTCOMPFIELD, vc1_get_LUMSCALE2,
>> and vc1_get_LUMSHIFT2 to av_unused.
>>
>> avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding
>>
>> Pass necessary bitstream elements to the VAAPI VC-1 decoder in order
>> to start doing interlaced decoding in hardware.
>>
>> Signed-off-by: Jerome Borsboom <jerome.borsboom@carpalis.nl>
>> ---
>>  libavcodec/vaapi_vc1.c | 163 ++++++++++++++++++++++++++++++++++++++++---------
>>  1 file changed, 134 insertions(+), 29 deletions(-)
> 
> ...
> 
> As such, I'm happy to apply all of this as it is now.  Does anyone have any further comments, especially about the VC-1 parts of this change?  If not, I'll apply the whole set this weekend.

And applied.

Thank you for the patches!

- Mark
Xiang, Haihao March 6, 2018, 4:37 a.m. UTC | #6
On Fri, 2018-03-02 at 09:23 +0800, Jun Zhao wrote:
> 

> On 2018/3/2 6:43, Mark Thompson wrote:

> > On 01/03/18 08:07, Jerome Borsboom wrote:

> > > v1.1->v1.2: Changed ifdefs around vc1_get_INTCOMPFIELD, vc1_get_LUMSCALE2,

> > > and vc1_get_LUMSHIFT2 to av_unused.

> > > 

> > > avcodec/vaapi: add fields for VAAPI VC-1 interlaced decoding

> > > 

> > > Pass necessary bitstream elements to the VAAPI VC-1 decoder in order

> > > to start doing interlaced decoding in hardware.

> > > 

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

> > > ---

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

> > > -------

> > >  1 file changed, 134 insertions(+), 29 deletions(-)

> > 

> > Wrt hashes, here is fate/vc1/ilaced_twomv.vc1 from a few different decoders:

> > 

> > libavcodec software decoder:

> > 

> > 0,          0,          0,        1,  3110400, 0x764f8856

> > 0,          2,          2,        1,  3110400, 0x3b615b79

> > 0,          3,          3,        1,  3110400, 0x4fbb6f84

> > 0,          4,          4,        1,  3110400, 0xc1ca8532

> > 0,          5,          5,        1,  3110400, 0xb6e7d363

> > 0,          6,          6,        1,  3110400, 0x1beb5c34

> > 0,          7,          7,        1,  3110400, 0xcb8cb061

> > 0,          8,          8,        1,  3110400, 0x13ddbd61

> > 0,          9,          9,        1,  3110400, 0xde8f052f

> > 0,         10,         10,        1,  3110400, 0x4d4072db

> > 0,         11,         11,        1,  3110400, 0x4e5d29e3

> > 0,         12,         12,        1,  3110400, 0x75300531

> > 0,         13,         13,        1,  3110400, 0x1114285a

> > 

> > VAAPI, "Intel i965 driver for Intel(R) Coffee Lake - 2.1.1.pre1 (2.0.0-140-

> > gff23e69)":

> > 

> > 0,          0,          0,        1,  3110400, 0xc95e8861

> > 0,          2,          2,        1,  3110400, 0xf58b5cbf

> > 0,          3,          3,        1,  3110400, 0x2f866f33

> > 0,          4,          4,        1,  3110400, 0x05c18415

> > 0,          5,          5,        1,  3110400, 0x94dff199

> > 0,          6,          6,        1,  3110400, 0xf31fda77

> > 0,          7,          7,        1,  3110400, 0x60b1b2da

> > 0,          8,          8,        1,  3110400, 0x748993f5

> > 0,          9,          9,        1,  3110400, 0x750fdf14

> > 0,         10,         10,        1,  3110400, 0x0879792c

> > 0,         11,         11,        1,  3110400, 0x7e0e60fa

> > 0,         12,         12,        1,  3110400, 0xda5bd837

> > 0,         13,         13,        1,  3110400, 0xb6346ccf

> > 

> > VAAPI, "Mesa Gallium driver 18.1.0-devel for AMD Radeon (TM) RX 460 Graphics

> > (POLARIS11 / DRM 3.23.0 / 4.15.7, LLVM 4.0.1)":

> > 

> > 0,          0,          0,        1,  3110400, 0xc95e8861

> > 0,          2,          2,        1,  3110400, 0xafefc967

> > 0,          3,          3,        1,  3110400, 0x1d736d3b

> > 0,          4,          4,        1,  3110400, 0x4f0fe807

> > 0,          5,          5,        1,  3110400, 0x758c6e9b

> > 0,          6,          6,        1,  3110400, 0x56a5c92a

> > 0,          7,          7,        1,  3110400, 0xa60fcf66

> > 0,          8,          8,        1,  3110400, 0x0c638017

> > 0,          9,          9,        1,  3110400, 0x3fe3310c

> > 0,         10,         10,        1,  3110400, 0x3d2ea8de

> > 0,         11,         11,        1,  3110400, 0xe2f8de62

> > 0,         12,         12,        1,  3110400, 0xa309cd68

> > 0,         13,         13,        1,  3110400, 0x8602abb1

> > 

> > Microsoft decoder (thanks to Hendrik for these):

> > 

> > 0,          0,          0,        1,  3110400, 0xc95e8861

> > 0,          2,          2,        1,  3110400, 0xf58b5cbf

> > 0,          3,          3,        1,  3110400, 0x2f866f33

> > 0,          4,          4,        1,  3110400, 0x05c18415

> > 0,          5,          5,        1,  3110400, 0x4077ca93

> > 0,          6,          6,        1,  3110400, 0x44d105fc

> > 0,          7,          7,        1,  3110400, 0xa0608374

> > 0,          8,          8,        1,  3110400, 0x407689dc

> > 0,          9,          9,        1,  3110400, 0x4707d00a

> > 0,         10,         10,        1,  3110400, 0x74986831

> > 0,         11,         11,        1,  3110400, 0xa5912619

> > 0,         12,         12,        1,  3110400, 0x44aa5565

> > 0,         13,         13,        1,  3110400, 0xb9752774

> > 

> > The VAAPI hardware implementations agree with the Microsoft decoder for the

> > initial four (Intel) or one (AMD) frames, while the software decoder doesn't

> > agree at all.  Unfortunately the AMD output is completely broken after the

> > first frame, but the Intel output does look sensible through the whole

> > sequence.  So, while this could probably be improved in drivers just as it

> > could in the software decoder, the FATE test is not relevant here so this

> > discussion shouldn't block anything.

> > 

> > As such, I'm happy to apply all of this as it is now.  Does anyone have any

> > further comments, especially about the VC-1 parts of this change?  If not,

> > I'll apply the whole set this weekend.

> > 

> > Thanks,

> > 

> > - Mark

> 

> I am OK to merge this part, in fact, I have a similar patches

> (https://github.com/mypopydev/FFmpeg/commit/da0e142cfc6302790bba08704d4cc0b507

> a78f70),

> but I think Jerome Borsboom did better job than me, so I didn't submit

> the patch.

> 

> For VC1 interlaced decoding can't bit match (bit-exact) for Windows

> Decoder/FFmpeg SW Decoder/VA-API HWAccel Decoder, I guess the root cause

> is the DCT/iDCT precision.


Yes, it is caused by the precision, so it is reasonable the hardware decoder
doesn't bit-match the software result for VC1.

Thanks
Haihao






> > _______________________________________________

> > ffmpeg-devel mailing list

> > ffmpeg-devel@ffmpeg.org

> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

> 

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index 525376790e..97b23917f6 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -44,7 +44,8 @@  static inline int vc1_has_MVTYPEMB_bitplane(const VC1Context *v)
 {
     if (v->mv_type_is_raw)
         return 0;
-    return v->s.pict_type == AV_PICTURE_TYPE_P &&
+    return v->fcm == PROGRESSIVE &&
+           (v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) &&
            (v->mv_mode == MV_PMODE_MIXED_MV ||
             (v->mv_mode == MV_PMODE_INTENSITY_COMP &&
              v->mv_mode2 == MV_PMODE_MIXED_MV));
@@ -55,8 +56,9 @@  static inline int vc1_has_SKIPMB_bitplane(const VC1Context *v)
 {
     if (v->skip_is_raw)
         return 0;
-    return v->s.pict_type == AV_PICTURE_TYPE_P ||
-           (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type);
+    return (v->fcm == PROGRESSIVE || v->fcm == ILACE_FRAME) &&
+           ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) ||
+            (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type));
 }
 
 /** Check whether the DIRECTMB bitplane is present */
@@ -64,7 +66,8 @@  static inline int vc1_has_DIRECTMB_bitplane(const VC1Context *v)
 {
     if (v->dmb_is_raw)
         return 0;
-    return v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type;
+    return (v->fcm == PROGRESSIVE || v->fcm == ILACE_FRAME) &&
+           (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type);
 }
 
 /** Check whether the ACPRED bitplane is present */
@@ -89,6 +92,25 @@  static inline int vc1_has_OVERFLAGS_bitplane(const VC1Context *v)
            v->condover == CONDOVER_SELECT;
 }
 
+/** Check whether the FIELDTX bitplane is present */
+static inline int vc1_has_FIELDTX_bitplane(const VC1Context *v)
+{
+    if (v->fieldtx_is_raw)
+        return 0;
+    return v->fcm == ILACE_FRAME &&
+           (v->s.pict_type == AV_PICTURE_TYPE_I ||
+            (v->s.pict_type == AV_PICTURE_TYPE_B && v->bi_type));
+}
+
+/** Check whether the FORWARDMB bitplane is present */
+static inline int vc1_has_FORWARDMB_bitplane(const VC1Context *v)
+{
+    if (v->fmb_is_raw)
+        return 0;
+    return v->fcm == ILACE_FIELD &&
+           (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type);
+}
+
 /** Reconstruct bitstream PTYPE (7.1.1.4, index into Table-35) */
 static int vc1_get_PTYPE(const VC1Context *v)
 {
@@ -101,10 +123,22 @@  static int vc1_get_PTYPE(const VC1Context *v)
     return 0;
 }
 
+/** Reconstruct bitstream FPTYPE (9.1.1.42, index into Table-105) */
+static int vc1_get_FPTYPE(const VC1Context *v)
+{
+    const MpegEncContext *s = &v->s;
+    switch (s->pict_type) {
+    case AV_PICTURE_TYPE_I: return 0;
+    case AV_PICTURE_TYPE_P: return 3;
+    case AV_PICTURE_TYPE_B: return v->bi_type ? 7 : 4;
+    }
+    return 0;
+}
+
 /** Reconstruct bitstream MVMODE (7.1.1.32) */
 static inline VAMvModeVC1 vc1_get_MVMODE(const VC1Context *v)
 {
-    if (v->s.pict_type == AV_PICTURE_TYPE_P ||
+    if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) ||
         (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type))
         return get_VAMvModeVC1(v->mv_mode);
     return 0;
@@ -113,11 +147,77 @@  static inline VAMvModeVC1 vc1_get_MVMODE(const VC1Context *v)
 /** Reconstruct bitstream MVMODE2 (7.1.1.33) */
 static inline VAMvModeVC1 vc1_get_MVMODE2(const VC1Context *v)
 {
-    if (v->s.pict_type == AV_PICTURE_TYPE_P && v->mv_mode == MV_PMODE_INTENSITY_COMP)
+    if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) &&
+        v->mv_mode == MV_PMODE_INTENSITY_COMP)
         return get_VAMvModeVC1(v->mv_mode2);
     return 0;
 }
 
+av_unused static inline int vc1_get_INTCOMPFIELD(const VC1Context *v)
+{
+    if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) &&
+        v->fcm == ILACE_FIELD &&
+        v->mv_mode == MV_PMODE_INTENSITY_COMP)
+        switch (v->intcompfield) {
+        case 1: return 1;
+        case 2: return 2;
+        case 3: return 0;
+        }
+    return 0;
+}
+
+static inline int vc1_get_LUMSCALE(const VC1Context *v)
+{
+    if (v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) {
+        if ((v->fcm == PROGRESSIVE && v->mv_mode == MV_PMODE_INTENSITY_COMP) ||
+            (v->fcm == ILACE_FRAME && v->intcomp))
+            return v->lumscale;
+        else if (v->fcm == ILACE_FIELD && v->mv_mode == MV_PMODE_INTENSITY_COMP)
+            switch (v->intcompfield) {
+            case 1: return v->lumscale;
+            case 2: return v->lumscale2;
+            case 3: return v->lumscale;
+        }
+    }
+    return 0;
+}
+
+static inline int vc1_get_LUMSHIFT(const VC1Context *v)
+{
+    if (v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) {
+        if ((v->fcm == PROGRESSIVE && v->mv_mode == MV_PMODE_INTENSITY_COMP) ||
+            (v->fcm == ILACE_FRAME && v->intcomp))
+            return v->lumshift;
+        else if (v->fcm == ILACE_FIELD && v->mv_mode == MV_PMODE_INTENSITY_COMP)
+            switch (v->intcompfield) {
+            case 1: return v->lumshift;
+            case 2: return v->lumshift2;
+            case 3: return v->lumshift;
+        }
+    }
+    return 0;
+}
+
+av_unused static inline int vc1_get_LUMSCALE2(const VC1Context *v)
+{
+    if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) &&
+        v->fcm == ILACE_FIELD &&
+        v->mv_mode == MV_PMODE_INTENSITY_COMP &&
+        v->intcompfield == 3)
+        return v->lumscale2;
+    return 0;
+}
+
+av_unused static inline int vc1_get_LUMSHIFT2(const VC1Context *v)
+{
+    if ((v->s.pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) &&
+        v->fcm == ILACE_FIELD &&
+        v->mv_mode == MV_PMODE_INTENSITY_COMP &&
+        v->intcompfield == 3)
+        return v->lumshift2;
+    return 0;
+}
+
 /** Reconstruct bitstream TTFRM (7.1.1.41, Table-53) */
 static inline int vc1_get_TTFRM(const VC1Context *v)
 {
@@ -189,27 +289,32 @@  static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t
             .chroma                        = v->range_mapuv,
         },
         .b_picture_fraction                = v->bfraction_lut_index,
-        .cbp_table                         = v->cbpcy_vlc ? v->cbpcy_vlc - ff_vc1_cbpcy_p_vlc : 0,
-        .mb_mode_table                     = 0, /* XXX: interlaced frame */
+        .cbp_table                         = (v->fcm == PROGRESSIVE ? v->cbptab : v->icbptab),
+        .mb_mode_table                     = v->mbmodetab,
         .range_reduction_frame             = v->rangeredfrm,
         .rounding_control                  = v->rnd,
         .post_processing                   = v->postproc,
         .picture_resolution_index          = v->respic,
-        .luma_scale                        = v->lumscale,
-        .luma_shift                        = v->lumshift,
         .picture_fields.bits = {
-            .picture_type                  = vc1_get_PTYPE(v),
+            .picture_type                  = (v->fcm == ILACE_FIELD ? vc1_get_FPTYPE(v) : vc1_get_PTYPE(v)),
             .frame_coding_mode             = v->fcm,
             .top_field_first               = v->tff,
-            .is_first_field                = v->fcm == 0, /* XXX: interlaced frame */
-            .intensity_compensation        = v->mv_mode == MV_PMODE_INTENSITY_COMP,
+            .is_first_field                = !v->second_field,
+            .intensity_compensation        = v->intcomp,
         },
+        .luma_scale                        = vc1_get_LUMSCALE(v),
+        .luma_shift                        = vc1_get_LUMSHIFT(v),
+#if VA_CHECK_VERSION(1, 1, 0)
+        .luma_scale2                       = vc1_get_LUMSCALE2(v),
+        .luma_shift2                       = vc1_get_LUMSHIFT2(v),
+        .intensity_compensation_field      = vc1_get_INTCOMPFIELD(v),
+#endif
         .raw_coding.flags = {
             .mv_type_mb                    = v->mv_type_is_raw,
             .direct_mb                     = v->dmb_is_raw,
             .skip_mb                       = v->skip_is_raw,
-            .field_tx                      = 0, /* XXX: interlaced frame */
-            .forward_mb                    = 0, /* XXX: interlaced frame */
+            .field_tx                      = v->fieldtx_is_raw,
+            .forward_mb                    = v->fmb_is_raw,
             .ac_pred                       = v->acpred_is_raw,
             .overflags                     = v->overflg_is_raw,
         },
@@ -217,28 +322,28 @@  static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t
             .bp_mv_type_mb                 = vc1_has_MVTYPEMB_bitplane(v),
             .bp_direct_mb                  = vc1_has_DIRECTMB_bitplane(v),
             .bp_skip_mb                    = vc1_has_SKIPMB_bitplane(v),
-            .bp_field_tx                   = 0, /* XXX: interlaced frame */
-            .bp_forward_mb                 = 0, /* XXX: interlaced frame */
+            .bp_field_tx                   = vc1_has_FIELDTX_bitplane(v),
+            .bp_forward_mb                 = vc1_has_FORWARDMB_bitplane(v),
             .bp_ac_pred                    = vc1_has_ACPRED_bitplane(v),
             .bp_overflags                  = vc1_has_OVERFLAGS_bitplane(v),
         },
         .reference_fields.bits = {
             .reference_distance_flag       = v->refdist_flag,
-            .reference_distance            = 0, /* XXX: interlaced frame */
-            .num_reference_pictures        = 0, /* XXX: interlaced frame */
-            .reference_field_pic_indicator = 0, /* XXX: interlaced frame */
+            .reference_distance            = v->refdist,
+            .num_reference_pictures        = v->numref,
+            .reference_field_pic_indicator = v->reffield,
         },
         .mv_fields.bits = {
             .mv_mode                       = vc1_get_MVMODE(v),
             .mv_mode2                      = vc1_get_MVMODE2(v),
-            .mv_table                      = s->mv_table_index,
-            .two_mv_block_pattern_table    = 0, /* XXX: interlaced frame */
-            .four_mv_switch                = 0, /* XXX: interlaced frame */
-            .four_mv_block_pattern_table   = 0, /* XXX: interlaced frame */
+            .mv_table                      = (v->fcm == PROGRESSIVE ? s->mv_table_index : v->imvtab),
+            .two_mv_block_pattern_table    = v->twomvbptab,
+            .four_mv_switch                = v->fourmvswitch,
+            .four_mv_block_pattern_table   = v->fourmvbptab,
             .extended_mv_flag              = v->extended_mv,
             .extended_mv_range             = v->mvrange,
             .extended_dmv_flag             = v->extended_dmv,
-            .extended_dmv_range            = 0, /* XXX: interlaced frame */
+            .extended_dmv_range            = v->dmvrange,
         },
         .pic_quantizer_fields.bits = {
             .dquant                        = v->dquant,
@@ -298,14 +403,14 @@  static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t
             break;
         case AV_PICTURE_TYPE_B:
             if (!v->bi_type) {
-                ff_bp[0] = pic_param.bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL;
-                ff_bp[1] = pic_param.bitplane_present.flags.bp_skip_mb   ? s->mbskip_table    : NULL;
-                ff_bp[2] = NULL; /* XXX: interlaced frame (FORWARD plane) */
+                ff_bp[0] = pic_param.bitplane_present.flags.bp_direct_mb  ? v->direct_mb_plane  : NULL;
+                ff_bp[1] = pic_param.bitplane_present.flags.bp_skip_mb    ? s->mbskip_table     : NULL;
+                ff_bp[2] = pic_param.bitplane_present.flags.bp_forward_mb ? v->forward_mb_plane : NULL;
                 break;
             }
             /* fall-through (BI-type) */
         case AV_PICTURE_TYPE_I:
-            ff_bp[0] = NULL; /* XXX: interlaced frame (FIELDTX plane) */
+            ff_bp[0] = pic_param.bitplane_present.flags.bp_field_tx   ? v->fieldtx_plane      : NULL;
             ff_bp[1] = pic_param.bitplane_present.flags.bp_ac_pred    ? v->acpred_plane       : NULL;
             ff_bp[2] = pic_param.bitplane_present.flags.bp_overflags  ? v->over_flags_plane   : NULL;
             break;