Re: [FFmpeg-devel] [PATCH] MAINTAINERS: Add Haihao Xiang for vaapi

2021-12-14 Thread Xu, Guangxin



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Michael Niedermayer
> Sent: Wednesday, December 15, 2021 5:40 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] MAINTAINERS: Add Haihao Xiang for
> vaapi
> 
> On Tue, Dec 14, 2021 at 12:16:16PM -0800, Philip Langdale wrote:
> > On Tue, 14 Dec 2021 16:39:40 +
> > "Eoff, Ullysses A"  wrote:
> >
> > > I have not seen any objections.
> > > I just added Mark to CC using their email found on this ML.
> > > Unfortunately, we don't have current email contact for Gwenole (whom
> > > has not worked on ffmpeg for ~6 years).
> > > Who else can make the approval, aside from the inactive people
> > > previously listed?
> >
> > Are people reluctant to approve?
> 
> I dont think so, iam just extra carefull as someone on IRC noticed that
> "everyone and their grandmother who's worked for intel's got push access"

Lynne may have misunderstanding, as I know, the author he mentioned in IRC is 
not from Intel. 

> 
> There where also some complaints about code quality/cleanlyness toward
> intels contributions So i just wanted to make sure there are no objections
> (iam not conciously aware of any objections to these MAINTAINER additions
> ATM)

We care about the code quality, every patch sent to upstream will pass our 
internal review and ci test firstly. We defined an upstream process here 
https://github.com/intel-media-ci/cartwheel-ffmpeg#upstream-process.
If we missed something in the internal review, please give review comments 
during the public review. We will try our best to fix all issues. Push code 
only when it's no objections. 

We know the current code quality is not so good.  This is why we send many 
patches to improve it. But most of the patches are not merged since original 
maintainers are not so active. Having an active maintainer will help this. 
Haihao is a good candidate for the vaapi/qsv maintainer. He is the libva api 
maintainer for 10+ years. He will review and monitor all patches related to 
Intel. Hope this will address your code quality concerns.

> 
> 
> > I'll give it my approval to have on
> > the record. If the old maintainers want to emerge from the woodwork and
> > object after the fact, they are welcome to do so, but we can't just sit
> > around indefinitely. The contributions here are clear, and I can't see
> > either of them objecting, given my past interactions.
> 
> I suggest you apply these if noone raises any objections in the next
> 2-3 days, in fact people had a really long time already ...

Thank you Michael, Philip, Softworkz, U.Arite,  and all help on this.

> 
> thx
> 
> [...]
> --
> Michael GnuPG fingerprint:
> 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Freedom in capitalist society always remains about the same as it was in
> ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/4] avcodec: vaapi_decode, do not set initial_pool_size if driver supports frame pool resizing

2021-11-17 Thread Xu Guangxin
Two benifites of this commit:
1. Save memory. If we play an 8k hevc, previous code we allocate 50M * 20(1 + 
16 + 3) = 1G memory. 4 may enough for most of playback usecases. 16 is a waste.
2. Allow downstream cache more frames. A downstream lookahead encoder will 
cache some frames. 20 may not enough for it.

This commit will fix the following command
ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i 100frames.264  -vf 
reverse -an -f null -
---
 libavcodec/vaapi_decode.c | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 665af370ed..177949c36d 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -572,22 +572,24 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 if (err < 0)
 goto fail;
 
-frames->initial_pool_size = 1;
-// Add per-codec number of surfaces used for storing reference frames.
-switch (avctx->codec_id) {
-case AV_CODEC_ID_H264:
-case AV_CODEC_ID_HEVC:
-case AV_CODEC_ID_AV1:
-frames->initial_pool_size += 16;
-break;
-case AV_CODEC_ID_VP9:
-frames->initial_pool_size += 8;
-break;
-case AV_CODEC_ID_VP8:
-frames->initial_pool_size += 3;
-break;
-default:
-frames->initial_pool_size += 2;
+if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING) {
+frames->initial_pool_size = 1;
+// Add per-codec number of surfaces used for storing reference 
frames.
+switch (avctx->codec_id) {
+case AV_CODEC_ID_H264:
+case AV_CODEC_ID_HEVC:
+case AV_CODEC_ID_AV1:
+frames->initial_pool_size += 16;
+break;
+case AV_CODEC_ID_VP9:
+frames->initial_pool_size += 8;
+break;
+case AV_CODEC_ID_VP8:
+frames->initial_pool_size += 3;
+break;
+default:
+frames->initial_pool_size += 2;
+}
 }
 }
 
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/4] avutil: hwcontext_vaapi, mark i965, VDPAU and ubit driver as AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING

2021-11-17 Thread Xu Guangxin
Legacy drivers can't support decode output frame pool resize.
---
 libavutil/hwcontext_vaapi.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 14a2df38c6..c13c395da2 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -331,23 +331,26 @@ static const struct {
 const char *match_string;
 unsigned int quirks;
 } vaapi_driver_quirks_table[] = {
-#if !VA_CHECK_VERSION(1, 0, 0)
-// The i965 driver did not conform before version 2.0.
+// The i965 driver did not conform RENDER_PARAM_BUFFERS before version 2.0.
 {
 "Intel i965 (Quick Sync)",
 "i965",
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
-},
+#if !VA_CHECK_VERSION(1, 0, 0)
+AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS | 
AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
+#else
+AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
 #endif
+},
+
 {
 "Intel iHD",
 "ubit",
-AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE,
+AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE | 
AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
 },
 {
 "VDPAU wrapper",
 "Splitted-Desktop Systems VDPAU backend for VA-API",
-AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
+AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES | 
AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING,
 },
 };
 
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/4] avutil: hwcontext_vaapi, add AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING

2021-11-17 Thread Xu Guangxin
---
 libavutil/hwcontext_vaapi.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 0b2e071cb3..e4c7707861 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -58,6 +58,12 @@ enum {
  * and the results of the vaQuerySurfaceAttributes() call will be faked.
  */
 AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
+
+/**
+ * The driver does not support dynamically frame pool resizing.
+ * We need to provide all va surfaces at vaCreateContext
+ */
+AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING = (1 << 4),
 };
 
 /**
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/4] avutils: hwcontext_vaapi, print error if allocated surfaces > pool size

2021-11-17 Thread Xu Guangxin
---
 libavutil/hwcontext_vaapi.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 83e542876d..14a2df38c6 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -475,8 +475,11 @@ static AVBufferRef *vaapi_pool_alloc(void *opaque, size_t 
size)
 AVBufferRef *ref;
 
 if (hwfc->initial_pool_size > 0 &&
-avfc->nb_surfaces >= hwfc->initial_pool_size)
+avfc->nb_surfaces >= hwfc->initial_pool_size) {
+av_log(hwfc, AV_LOG_ERROR, "allocated surfaces count(%d) > 
pool_size(%d)\n",
+   avfc->nb_surfaces,  hwfc->initial_pool_size);
 return NULL;
+}
 
 vas = vaCreateSurfaces(hwctx->display, ctx->rt_format,
hwfc->width, hwfc->height,
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avutils/hwcontext_qsv: set the source device in qsv_device_create

2021-03-13 Thread Xu, Guangxin
> You are hacking it to lie to the hwcontext implementation around how the
> device was derived, so the test fails because it finds a different derivation
> structure to what it created?  That seems correct?
> 
> Your command-line was:
> 
> $ ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -init_hw_device
> opencl=ocl@intel -hwaccel qsv -c:v h264_qsv -hwaccel_output_format qsv -i
> $input -filter_hw_device ocl -vf
> 'hwmap=derive_device=opencl,format=opencl,unsharp_opencl,hwmap=der
> ive_device=qsv:reverse=1:extra_hw_frames=32'  -c:v hevc_qsv  -y test.h265
> 
> So that's trying to make five device references in turn:
> 
> 1. Make a VAAPI device explicitly.
> 2. Derive an OpenCL device from the VAAPI device 1.
> 3. Make a libmfx device implicitly (because a libmfx decoder was requested).
> 4. Derive a new OpenCL device from the libmfx device 3 (you told the filter
> graph about device 2, but then didn't use it anywhere).
> 5. Derive a libmfx device from the OpenCL device 4, which should return
> libmfx device 3.
> 
> What's going wrong?  Step 4 fails to create an OpenCL device because
> devices 1/2 and device 3 aren't actually connected together at all.
> 
> How to solve that?  Either we can fix the connection, or we could just use the
> device we already have in step 4 rather than trying to create a new one.
> 
> To fix the connection, derive device 3 from device 1.  This doesn't work in 
> the
> ffmpeg utility because the hacky support in ffmpeg_qsv.c doesn't support
> the normal device stuff.  It would work in your own program.
> 
> Using the existing device (by using device 2 rather than deriving a new on at
> step 4) looks like it should work:
> 
> $ ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -init_hw_device
> opencl=ocl@intel -hwaccel qsv -c:v h264_qsv -hwaccel_output_format qsv -i
> $input -filter_hw_device ocl -vf
> 'hwmap,format=opencl,unsharp_opencl,hwmap=derive_device=qsv:revers
> e=1:extra_hw_frames=32'  -c:v hevc_qsv  -y test.h265
> 
> Unfortunately it doesn't, and for the same reason that the first approach
> didn't - devices 1 and 3 aren't connected, so the OpenCL mapping is being
> given frames in the wrong device context and therefore fails (in fact the 
> Intel
> ICD crashes with an abort, which is about the best you can hope for with this
> sort of undefined behaviour).
> 
> 
> So, how can we make this work?  Well, the weird libmfx hacks are causing the
> problem, so let's just duck that by dumping the pointless wrapper decoder
> and using the normal decoder directly:
Hi Mark,
Thanks for the detailed explaining. I will try the vaapi path.

thanks
> 
> $ ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -hwaccel vaapi -
> hwaccel_output_format vaapi -i $input -vf
> 'hwmap=derive_device=opencl,format=opencl,unsharp_opencl,hwmap=der
> ive_device=qsv:reverse=1:extra_hw_frames=32'  -c:v hevc_qsv  -y test.h265
> 
> If you want to make it work with the libmfx wrapper decoder, then I think
> the most sensible way is to implement
> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX in that decoder so it
> works like the others and the ffmpeg_qsv.c hacks can be removed entirely.
> 
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avutils/hwcontext_qsv: set the source device in qsv_device_create

2021-03-11 Thread Xu, Guangxin
> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Guangxin Xu
> Sent: Friday, March 5, 2021 9:46 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avutils/hwcontext_qsv: set the source
> device in qsv_device_create
> 
> On Tue, Feb 23, 2021 at 9:34 AM Guangxin Xu  wrote:
> 
> >
> >
> > On Mon, Feb 22, 2021 at 5:17 PM Soft Works 
> wrote:
> >
> >>
> >>
> >> > -Original Message-
> >> > From: ffmpeg-devel  On Behalf
> Of
> >> > Xu Guangxin
> >> > Sent: Monday, February 22, 2021 9:45 AM
> >> > To: ffmpeg-devel@ffmpeg.org
> >> > Cc: Xu Guangxin 
> >> > Subject: [FFmpeg-devel] [PATCH] avutils/hwcontext_qsv: set the
> >> > source device in qsv_device_create
> >> >
> >> > opencl_device_derive only handles AV_HWDEVICE_TYPE_VAAPI.
> >> > We need a source device for qsv.
> >> >
> >> > this will fix following pipeline:
> >> > ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128
> >> > -init_hw_device opencl=ocl@intel -hwaccel qsv -c:v h264_qsv
> >> > -hwaccel_output_format qsv
> >> -i
> >> > $input -filter_hw_device ocl -vf
> >> >
> 'hwmap=derive_device=opencl,format=opencl,unsharp_opencl,hwmap=der
> >> > ive_device=qsv:reverse=1:extra_hw_frames=32'  -c:v hevc_qsv  -y
> >> test.h265
> >> > ---
> >> >  libavutil/hwcontext_qsv.c | 8 +++-
> >> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> >> > index 35a944f8f8..af3ee32cac 100644
> >> > --- a/libavutil/hwcontext_qsv.c
> >> > +++ b/libavutil/hwcontext_qsv.c
> >> > @@ -1269,7 +1269,13 @@ static int
> >> > qsv_device_create(AVHWDeviceContext
> >> > *ctx, const char *device,
> >> >
> >> >  impl = choose_implementation(device);
> >> >
> >> > -return qsv_device_derive_from_child(ctx, impl, child_device, 0);
> >> > +ret = qsv_device_derive_from_child(ctx, impl, child_device, 0);
> >> > +if (ret == 0) {
> >> > +ctx->internal->source_device =
> >> av_buffer_ref(priv->child_device_ctx);
> >> > +if (!ctx->internal->source_device)
> >> > +ret = AVERROR(ENOMEM);
> >> > +}
> >> > +return ret;
> >> >  }
> >>
> >> That's funny, I made almost the same change only two days ago:
> >>
> >> impl = choose_implementation(device);
> >> ret = qsv_device_derive_from_child(ctx, impl, child_device, 0);
> >> if (ret >= 0)
> >> ctx->internal->source_device =
> >> av_buffer_ref(priv->child_device_ctx);
> >>
> >> return ret;
> >>
> >>
> >> From my POV, this change is correct and required.
> >>
> > Glad to hear this. Thanks for the endorsement  :)
> >
> Hi softworkz,
> Could you help merge this?
> thanks
> 
Hmm, this patch will failed for "make fate-hwdevice V=2"
It because Qsv's internal->source_device is vaapi.  
When we derivation qsv to vaapi, and derivation back again, it will create a 
new qsv device.

Hi Mark,
Can we remove this test for qsv and vaapi? Or could you suggest a better way 
for me?
https://github.com/FFmpeg/FFmpeg/blob/069d2b4a50a6eb2f925f36884e6b9bd9a1e54670/libavutil/tests/hwdevice.c#L75

thanks

...
Successfully tested derivation vaapi -> qsv.
Test passed for vaapi with device :0.
Device type qsv successfully created.
Derivation qsv to vaapi succeeded, but derivation back again did not return the 
original device.
Test failed for qsv with default options.
Attempted to test 2 device types: 1 passed, 1 failed, 0 skipped.
make: *** [tests/Makefile:256: fate-hwdevice] Error 1
> 
> >> softworkz
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> >
> >
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/h264_slice: don't copy frame data during error concealment

2021-03-10 Thread Xu, Guangxin
> -Original Message-
> From: ffmpeg-devel  On Behalf Of Xu,
> Guangxin
> Sent: Tuesday, March 9, 2021 5:13 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_slice: don't copy frame
> data during error concealment
> 
> We will test vaapi for this patch.
> 
> But I am more curious about the software decoder behaviors.
> This approach just ref the yuv. Not the intermedia data(like mv,  macroblock
> type) Will it have problem if missed frame selected as colPic (Figure 8-2 in
> spec).
> 
It's no regression for from ffmpeg vaapi. 
And it will fix following frame gap clips for vaapi
MR3_TANDBERG_B 
MR4_TANDBERG_C
MR5_TANDBERG_C
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/h264_slice: don't copy frame data during error concealment

2021-03-09 Thread Xu, Guangxin
We will test vaapi for this patch.
 
But I am more curious about the software decoder behaviors.
This approach just ref the yuv. Not the intermedia data(like mv,  macroblock 
type)
Will it have problem if missed frame selected as colPic (Figure 8-2 in spec).

> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Hendrik Leppkes
> Sent: Tuesday, March 9, 2021 3:44 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_slice: don't copy frame
> data during error concealment
> 
> On Tue, Mar 9, 2021 at 3:39 AM James Almer  wrote:
> >
> > In addition to the fact that av_image_copy() cannot handle hardware
> > pixel formats, h->short_ref[0]->f may not even be writable at this point.
> >
> > Based on a patch by Hendrik Leppkes.
> >
> > Signed-off-by: James Almer 
> > ---
> > This is an alternative to "avcodec/h264_slice: properly handle missing
> > reference frames with hwaccel", given that I noticed that the target
> > frame is not writable for example when running fate-h264-missing-frame.
> >
> > To keep the current behavior of copying the frame data instead of
> > making a reference, I also tried to do ff_thread_release_buffer() ->
> > ff_thread_get_buffer() -> av_frame_copy(), which worked with software
> > decoding, but when using the d3d11va hwaccel the av_frame_copy() call
> would fail.
> >
> > There is a warning above this code that makes it sound like making
> > references is not ideal, but considering h->short_ref[0] is not
> > writable here it feels like it could be an outdated comment that someone
> forgot to remove.
> >
> 
> Looks more thorough then my original change. I was worried about the
> comment also, but I think it may have been from before the days of ref-
> counting, frame threading, and all that (the comment appeared with the
> original code in e2983d6eac7b0bb563886c6f97c4ce0385b2018d, 2010)
> 
> Perhaps the comment should be removed if we are going to reference now
> anyway?
> 
> - Hendrik
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avutils/hwcontext_qsv: set the source device in qsv_device_create

2021-02-22 Thread Xu Guangxin
opencl_device_derive only handles AV_HWDEVICE_TYPE_VAAPI.
We need a source device for qsv.

this will fix following pipeline:
ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -init_hw_device 
opencl=ocl@intel -hwaccel qsv -c:v h264_qsv -hwaccel_output_format qsv -i 
$input -filter_hw_device ocl -vf 
'hwmap=derive_device=opencl,format=opencl,unsharp_opencl,hwmap=derive_device=qsv:reverse=1:extra_hw_frames=32'
  -c:v hevc_qsv  -y test.h265
---
 libavutil/hwcontext_qsv.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 35a944f8f8..af3ee32cac 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1269,7 +1269,13 @@ static int qsv_device_create(AVHWDeviceContext *ctx, 
const char *device,
 
 impl = choose_implementation(device);
 
-return qsv_device_derive_from_child(ctx, impl, child_device, 0);
+ret = qsv_device_derive_from_child(ctx, impl, child_device, 0);
+if (ret == 0) {
+ctx->internal->source_device = av_buffer_ref(priv->child_device_ctx);
+if (!ctx->internal->source_device)
+ret = AVERROR(ENOMEM);
+}
+return ret;
 }
 
 const HWContextType ff_hwcontext_type_qsv = {
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avutils/vulkan: hwmap, respect src frame resolution

2021-01-21 Thread Xu, Guangxin


> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Lynne
> Sent: Friday, January 22, 2021 11:37 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avutils/vulkan: hwmap, respect src
> frame resolution
> 
> Jan 21, 2021, 05:35 by guangxin...@intel.com:
> 
> > fixes http://trac.ffmpeg.org/ticket/9055
> >
> > The hw decoder may allocate a large frame from AVHWFramesContext,
> and adjust width and height based on bitstream.
> > We need to use resolution from src frame instead of AVHWFramesContext.
> >
> > test command:
> > ffmpeg -loglevel debug -hide_banner -hwaccel vaapi -init_hw_device
> > vaapi=va:/dev/dri/renderD128 -hwaccel_device va -
> hwaccel_output_format
> > vaapi -init_hw_device vulkan=vulk -filter_hw_device vulk -i
> > 1920x1080.264 -c:v libx264 -r:v 30 -profile:v high -preset veryfast
> > -vf "hwmap,chromaber_vulkan=0:0,hwdownload,format=nv12" -map 0 -y
> > vaapiouts.mkv
> >
> > expected:
> > No green bar at bottom.
> > ---
> >  libavutil/hwcontext_vulkan.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavutil/hwcontext_vulkan.c
> > b/libavutil/hwcontext_vulkan.c index d4ff4ae307..f6d0cae8ae 100644
> > --- a/libavutil/hwcontext_vulkan.c
> > +++ b/libavutil/hwcontext_vulkan.c
> > @@ -2009,7 +2009,7 @@ static inline VkFormat
> > drm_to_vulkan_fmt(uint32_t drm_fourcc)  }
> >
> >  static int vulkan_map_from_drm_frame_desc(AVHWFramesContext
> *hwfc, AVVkFrame **frame,
> > -  AVDRMFrameDescriptor *desc)
> > +  const AVFrame *src,
> > + AVDRMFrameDescriptor *desc)
> >  {
> >  int err = 0;
> >  VkResult ret;
> > @@ -2085,7 +2085,7 @@ static int
> > vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc,
> AVVkFrame **f
> > };
> >
> >  get_plane_wh(&create_info.extent.width, &create_info.extent.height,
> > - hwfc->sw_format, hwfc->width, hwfc->height, i);
> > + hwfc->sw_format, src->width, src->height, i);
> >
> >  for (int j = 0; j < planes; j++) {
> >  plane_data[j].offset = desc->layers[i].planes[j].offset;
> > @@ -2246,7 +2246,7 @@ static int
> vulkan_map_from_drm(AVHWFramesContext
> > *hwfc, AVFrame *dst,  AVVkFrame *f;  VulkanMapping *map = NULL;
> >
> > -err = vulkan_map_from_drm_frame_desc(hwfc, &f,
> > +err = vulkan_map_from_drm_frame_desc(hwfc, &f, src,
> >  (AVDRMFrameDescriptor *)src->data[0]);  if (err)  return err;
> >
> 
> Thanks, pushed with a small style nit.
Great! thanks.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avutils/vulkan: hwmap, respect src frame resolution

2021-01-20 Thread Xu Guangxin
fixes http://trac.ffmpeg.org/ticket/9055

The hw decoder may allocate a large frame from AVHWFramesContext, and adjust 
width and height based on bitstream.
We need to use resolution from src frame instead of AVHWFramesContext.

test command:
ffmpeg -loglevel debug -hide_banner -hwaccel vaapi -init_hw_device 
vaapi=va:/dev/dri/renderD128 -hwaccel_device va -hwaccel_output_format vaapi 
-init_hw_device vulkan=vulk -filter_hw_device vulk -i 1920x1080.264 -c:v 
libx264 -r:v 30 -profile:v high -preset veryfast -vf 
"hwmap,chromaber_vulkan=0:0,hwdownload,format=nv12" -map 0 -y vaapiouts.mkv

expected:
No green bar at bottom.
---
 libavutil/hwcontext_vulkan.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index d4ff4ae307..f6d0cae8ae 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2009,7 +2009,7 @@ static inline VkFormat drm_to_vulkan_fmt(uint32_t 
drm_fourcc)
 }
 
 static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame 
**frame,
-  AVDRMFrameDescriptor *desc)
+  const AVFrame *src, 
AVDRMFrameDescriptor *desc)
 {
 int err = 0;
 VkResult ret;
@@ -2085,7 +2085,7 @@ static int 
vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
 };
 
 get_plane_wh(&create_info.extent.width, &create_info.extent.height,
- hwfc->sw_format, hwfc->width, hwfc->height, i);
+ hwfc->sw_format, src->width, src->height, i);
 
 for (int j = 0; j < planes; j++) {
 plane_data[j].offset = desc->layers[i].planes[j].offset;
@@ -2246,7 +2246,7 @@ static int vulkan_map_from_drm(AVHWFramesContext *hwfc, 
AVFrame *dst,
 AVVkFrame *f;
 VulkanMapping *map = NULL;
 
-err = vulkan_map_from_drm_frame_desc(hwfc, &f,
+err = vulkan_map_from_drm_frame_desc(hwfc, &f, src,
  (AVDRMFrameDescriptor *)src->data[0]);
 if (err)
 return err;
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/qsv_enc: do not reuse enc_ctrl from previous frames

2021-01-05 Thread Xu Guangxin
fixes #8857

If we do not clear the enc_ctrl, we will reuse previous frames' data like 
FrameType.
---
 libavcodec/qsvenc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2bd2a56227..94473c4eab 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1249,6 +1249,8 @@ static void clear_unused_frames(QSVEncContext *q)
 while (cur) {
 if (cur->used && !cur->surface.Data.Locked) {
 free_encoder_ctrl_payloads(&cur->enc_ctrl);
+//do not reuse enc_ctrl from previous frame
+memset(&cur->enc_ctrl, 0, sizeof(cur->enc_ctrl));
 if (cur->frame->format == AV_PIX_FMT_QSV) {
 av_frame_unref(cur->frame);
 }
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 6/6] avcodec/qsvdec: refact, remove duplicate code for plugin loading

2021-01-04 Thread Xu Guangxin
---
 libavcodec/qsvdec.c | 29 +++--
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 3ca16dafae..d10f90a0db 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -682,21 +682,12 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 {
 QSVDecContext *s = avctx->priv_data;
 int ret;
+const char *uid = NULL;
 
 if (avctx->codec_id == AV_CODEC_ID_VP8) {
-static const char *uid_vp8dec_hw = "f622394d8d87452f878c51f2fc9b4131";
-
-av_freep(&s->qsv.load_plugins);
-s->qsv.load_plugins = av_strdup(uid_vp8dec_hw);
-if (!s->qsv.load_plugins)
-return AVERROR(ENOMEM);
+uid = "f622394d8d87452f878c51f2fc9b4131";
 } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
-static const char *uid_vp9dec_hw = "a922394d8d87452f878c51f2fc9b4131";
-
-av_freep(&s->qsv.load_plugins);
-s->qsv.load_plugins = av_strdup(uid_vp9dec_hw);
-if (!s->qsv.load_plugins)
-return AVERROR(ENOMEM);
+uid = "a922394d8d87452f878c51f2fc9b4131";
 }
 else if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != 
LOAD_PLUGIN_NONE) {
 static const char * const uid_hevcdec_sw = 
"15dd936825ad475ea34e35f3f54217a6";
@@ -707,16 +698,18 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
"load_plugins is not empty, but load_plugin is not set to 
'none'."
"The load_plugin value will be ignored.\n");
 } else {
-av_freep(&s->qsv.load_plugins);
-
 if (s->load_plugin == LOAD_PLUGIN_HEVC_SW)
-s->qsv.load_plugins = av_strdup(uid_hevcdec_sw);
+uid = uid_hevcdec_sw;
 else
-s->qsv.load_plugins = av_strdup(uid_hevcdec_hw);
-if (!s->qsv.load_plugins)
-return AVERROR(ENOMEM);
+uid = uid_hevcdec_hw;
 }
 }
+if (uid) {
+av_freep(&s->qsv.load_plugins);
+s->qsv.load_plugins = av_strdup(uid);
+if (!s->qsv.load_plugins)
+return AVERROR(ENOMEM);
+}
 
 s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
 s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 5/6] avcodec/qsvdec: refact, move qsvdec_other.c to qsvdec.c

2021-01-04 Thread Xu Guangxin
---
 libavcodec/Makefile   |  14 +--
 libavcodec/qsvdec.c   |  41 ++-
 libavcodec/qsvdec_other.c | 242 --
 3 files changed, 47 insertions(+), 250 deletions(-)
 delete mode 100644 libavcodec/qsvdec_other.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 87b9396681..cd6d8c89b1 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -449,7 +449,7 @@ OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o 
metasound_data.o \
 OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o
-OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec_other.o
+OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec.o
 OBJS-$(CONFIG_MJPEG_ENCODER)   += mjpegenc.o mjpegenc_common.o \
   mjpegenc_huffman.o
 OBJS-$(CONFIG_MJPEGB_DECODER)  += mjpegbdec.o
@@ -486,7 +486,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)  += mpeg12enc.o 
mpeg12.o
 OBJS-$(CONFIG_MPEG1_CUVID_DECODER) += cuviddec.o
 OBJS-$(CONFIG_MPEG1_V4L2M2M_DECODER)   += v4l2_m2m_dec.o
 OBJS-$(CONFIG_MPEG2_MMAL_DECODER)  += mmaldec.o
-OBJS-$(CONFIG_MPEG2_QSV_DECODER)   += qsvdec_other.o
+OBJS-$(CONFIG_MPEG2_QSV_DECODER)   += qsvdec.o
 OBJS-$(CONFIG_MPEG2_QSV_ENCODER)   += qsvenc_mpeg2.o
 OBJS-$(CONFIG_MPEG2VIDEO_DECODER)  += mpeg12dec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)  += mpeg12enc.o mpeg12.o
@@ -688,7 +688,7 @@ OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o 
vc1_block.o vc1_loopfilter.o
   wmv2dsp.o wmv2data.o
 OBJS-$(CONFIG_VC1_CUVID_DECODER)   += cuviddec.o
 OBJS-$(CONFIG_VC1_MMAL_DECODER)+= mmaldec.o
-OBJS-$(CONFIG_VC1_QSV_DECODER) += qsvdec_other.o
+OBJS-$(CONFIG_VC1_QSV_DECODER) += qsvdec.o
 OBJS-$(CONFIG_VC1_V4L2M2M_DECODER) += v4l2_m2m_dec.o
 OBJS-$(CONFIG_VC2_ENCODER) += vc2enc.o vc2enc_dwt.o diractab.o
 OBJS-$(CONFIG_VCR1_DECODER)+= vcr1.o
@@ -707,7 +707,7 @@ OBJS-$(CONFIG_VP7_DECODER) += vp8.o vp56rac.o
 OBJS-$(CONFIG_VP8_DECODER) += vp8.o vp56rac.o
 OBJS-$(CONFIG_VP8_CUVID_DECODER)   += cuviddec.o
 OBJS-$(CONFIG_VP8_MEDIACODEC_DECODER)  += mediacodecdec.o
-OBJS-$(CONFIG_VP8_QSV_DECODER) += qsvdec_other.o
+OBJS-$(CONFIG_VP8_QSV_DECODER) += qsvdec.o
 OBJS-$(CONFIG_VP8_RKMPP_DECODER)   += rkmppdec.o
 OBJS-$(CONFIG_VP8_VAAPI_ENCODER)   += vaapi_encode_vp8.o
 OBJS-$(CONFIG_VP8_V4L2M2M_DECODER) += v4l2_m2m_dec.o
@@ -942,7 +942,7 @@ OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL) += 
mpegvideo_xvmc.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
-OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec_other.o
+OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
 OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)+= vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
@@ -954,7 +954,7 @@ OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
-OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec_other.o
+OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
 OBJS-$(CONFIG_VC1_VDPAU_HWACCEL)  += vdpau_vc1.o
 OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
@@ -964,7 +964,7 @@ OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
-OBJS-$(CONFIG_VP8_QSV_HWACCEL)+= qsvdec_other.o
+OBJS-$(CONFIG_VP8_QSV_HWACCEL)+= qsvdec.o
 
 # libavformat dependencies
 OBJS-$(CONFIG_ISO_MEDIA)   += mpeg4audio.o mpegaudiodata.o
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 18ae288b70..3ca16dafae 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -683,7 +683,22 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 QSVDecContext *s = avctx->priv_data;
 int ret;
 
-if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != 
LOAD_PLUGIN_NONE) {
+if (avctx->codec_id == AV_CODEC_ID_VP8) {
+static const char *uid_vp8dec_hw = "f622394d8d87452f878c51f2fc9b4131";
+
+av_freep(&s->qsv.load_plugins);
+s->qsv.load_plugins = av_strdup(uid_vp8dec_hw);
+if (!s->qsv.load_plugins)
+return AVERROR(ENOMEM);
+} else if (avctx->codec_id == AV_CODEC_ID_VP9) {
+static const char *uid_vp9dec_hw = "a922394d8d87452f878c51f2fc9b4131";
+
+   

[FFmpeg-devel] [PATCH v2 4/6] avcodec/qsvdec: refact, move qsvdec_h2645.c to qsvdec.c

2021-01-04 Thread Xu Guangxin
---
 libavcodec/Makefile   |   8 +-
 libavcodec/qsvdec.c   | 217 -
 libavcodec/qsvdec_h2645.c | 250 --
 3 files changed, 219 insertions(+), 256 deletions(-)
 delete mode 100644 libavcodec/qsvdec_h2645.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fea37ef3c9..87b9396681 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -375,7 +375,7 @@ OBJS-$(CONFIG_H264_NVENC_ENCODER)  += nvenc_h264.o
 OBJS-$(CONFIG_NVENC_ENCODER)   += nvenc_h264.o
 OBJS-$(CONFIG_NVENC_H264_ENCODER)  += nvenc_h264.o
 OBJS-$(CONFIG_H264_OMX_ENCODER)+= omx.o
-OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
+OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec.o
 OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
 OBJS-$(CONFIG_H264_RKMPP_DECODER)  += rkmppdec.o
 OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o h264_levels.o
@@ -395,7 +395,7 @@ OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_HEVC_MF_ENCODER) += mfenc.o mf_utils.o
 OBJS-$(CONFIG_HEVC_NVENC_ENCODER)  += nvenc_hevc.o
 OBJS-$(CONFIG_NVENC_HEVC_ENCODER)  += nvenc_hevc.o
-OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec_h2645.o
+OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec.o
 OBJS-$(CONFIG_HEVC_QSV_ENCODER)+= qsvenc_hevc.o hevc_ps_enc.o   \
   hevc_data.o
 OBJS-$(CONFIG_HEVC_RKMPP_DECODER)  += rkmppdec.o
@@ -923,14 +923,14 @@ OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_D3D11VA_HWACCEL)   += dxva2_h264.o
 OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
 OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o
-OBJS-$(CONFIG_H264_QSV_HWACCEL)   += qsvdec_h2645.o
+OBJS-$(CONFIG_H264_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
 OBJS-$(CONFIG_H264_VDPAU_HWACCEL) += vdpau_h264.o
 OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += videotoolbox.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
-OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec_h2645.o
+OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
 OBJS-$(CONFIG_HEVC_VDPAU_HWACCEL) += vdpau_hevc.o h265_profile_level.o
 OBJS-$(CONFIG_MJPEG_NVDEC_HWACCEL)+= nvdec_mjpeg.o
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c666aaeb52..18ae288b70 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -31,6 +31,7 @@
 #include "libavutil/hwcontext_qsv.h"
 #include "libavutil/mem.h"
 #include "libavutil/log.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/time.h"
@@ -228,7 +229,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 return 0;
  }
 
-static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxVideoParam 
*param)
+static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, 
mfxVideoParam *param)
 {
 int ret;
 
@@ -615,7 +616,7 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 }
 
 if (!q->initialized) {
-ret = qsv_decode_init(avctx, q, ¶m);
+ret = qsv_decode_init_context(avctx, q, ¶m);
 if (ret < 0)
 goto reinit_fail;
 q->initialized = 1;
@@ -633,3 +634,215 @@ void ff_qsv_decode_flush(AVCodecContext *avctx, 
QSVContext *q)
 q->orig_pix_fmt = AV_PIX_FMT_NONE;
 q->initialized = 0;
 }
+
+enum LoadPlugin {
+LOAD_PLUGIN_NONE,
+LOAD_PLUGIN_HEVC_SW,
+LOAD_PLUGIN_HEVC_HW,
+};
+
+typedef struct QSVDecContext {
+AVClass *class;
+QSVContext qsv;
+
+int load_plugin;
+
+AVFifoBuffer *packet_fifo;
+
+AVPacket buffer_pkt;
+} QSVDecContext;
+
+static void qsv_clear_buffers(QSVDecContext *s)
+{
+AVPacket pkt;
+while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
+av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
+av_packet_unref(&pkt);
+}
+
+av_packet_unref(&s->buffer_pkt);
+}
+
+static av_cold int qsv_decode_close(AVCodecContext *avctx)
+{
+QSVDecContext *s = avctx->priv_data;
+
+av_freep(&s->qsv.load_plugins);
+
+ff_qsv_decode_close(&s->qsv);
+
+qsv_clear_buffers(s);
+
+av_fifo_free(s->packet_fifo);
+
+return 0;
+}
+
+static av_cold int qsv_decode_init(AVCodecContext *avctx)
+{
+QSVDecContext *s = avctx->priv_data;
+int ret;
+
+if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != 
LOAD_PLUGIN_NONE) {
+static const char * const uid_hevcdec_sw = 
"15dd936825ad475ea34e35f3f54217a6";
+static const char * const uid_hevcdec_hw = 
"33a61c0b4c27454ca8d85dde757c6f8e";
+
+if (s->qsv.load_plugins[0]) {
+ 

[FFmpeg-devel] [PATCH v2 3/6] avcodec/qsvdec_h2645: refact, use DEFINE_QSV_DECODER to remove duplicate code

2021-01-04 Thread Xu Guangxin
---
 libavcodec/qsvdec_h2645.c | 89 +++
 1 file changed, 33 insertions(+), 56 deletions(-)

diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index 3d6e85230f..974c1b6034 100644
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -184,6 +184,36 @@ static void qsv_decode_flush(AVCodecContext *avctx)
 #define OFFSET(x) offsetof(QSVH2645Context, x)
 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
+#define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt) \
+static const AVClass x##_qsv_class = { \
+.class_name = #x "_qsv", \
+.item_name  = av_default_item_name, \
+.option = opt, \
+.version= LIBAVUTIL_VERSION_INT, \
+}; \
+AVCodec ff_##x##_qsv_decoder = { \
+.name   = #x "_qsv", \
+.long_name  = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video 
acceleration)"), \
+.priv_data_size = sizeof(QSVH2645Context), \
+.type   = AVMEDIA_TYPE_VIDEO, \
+.id = AV_CODEC_ID_##X, \
+.init   = qsv_decode_init, \
+.decode = qsv_decode_frame, \
+.flush  = qsv_decode_flush, \
+.close  = qsv_decode_close, \
+.bsfs   = bsf_name, \
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
+.priv_class = &x##_qsv_class, \
+.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
+AV_PIX_FMT_P010, \
+AV_PIX_FMT_QSV, \
+AV_PIX_FMT_NONE }, \
+.hw_configs = ff_qsv_hw_configs, \
+.wrapper_name   = "qsv", \
+}; \
+
+#define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x, 
X, bsf_name, options)
+
 #if CONFIG_HEVC_QSV_DECODER
 static const AVOption hevc_options[] = {
 { "async_depth", "Internal parallelization depth, the higher the value the 
higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 
ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
@@ -202,37 +232,9 @@ static const AVOption hevc_options[] = {
 { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF },   
  0, 0, VD, "gpu_copy"},
 { NULL },
 };
-
-static const AVClass hevc_class = {
-.class_name = "hevc_qsv",
-.item_name  = av_default_item_name,
-.option = hevc_options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_hevc_qsv_decoder = {
-.name   = "hevc_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("HEVC (Intel Quick Sync Video 
acceleration)"),
-.priv_data_size = sizeof(QSVH2645Context),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_HEVC,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &hevc_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_P010,
-AV_PIX_FMT_QSV,
-AV_PIX_FMT_NONE },
-.hw_configs = ff_qsv_hw_configs,
-.bsfs   = "hevc_mp4toannexb",
-.wrapper_name   = "qsv",
-};
+DEFINE_QSV_DECODER_WITH_OPTION(hevc, HEVC, "hevc_mp4toannexb", hevc_options)
 #endif
 
-#if CONFIG_H264_QSV_DECODER
 static const AVOption options[] = {
 { "async_depth", "Internal parallelization depth, the higher the value the 
higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 
ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
 
@@ -243,31 +245,6 @@ static const AVOption options[] = {
 { NULL },
 };
 
-static const AVClass class = {
-.class_name = "h264_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_h264_qsv_decoder = {
-.name   = "h264_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 
part 10 (Intel Quick Sync Video acceleration)"),
-.priv_data_size = sizeof(QSVH2645Context),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_H264,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_P010,
-AV_PIX_FMT_QSV,
- 

[FFmpeg-devel] [PATCH v2 2/6] avcodec/qsvdec_other: refact, use DEFINE_QSV_DECODER to remove duplicate code

2021-01-04 Thread Xu Guangxin
---
 libavcodec/qsvdec_other.c | 188 --
 1 file changed, 36 insertions(+), 152 deletions(-)

diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
index 2775e07955..266ac9f2e5 100644
--- a/libavcodec/qsvdec_other.c
+++ b/libavcodec/qsvdec_other.c
@@ -189,170 +189,54 @@ static const AVOption options[] = {
 { NULL },
 };
 
-#if CONFIG_MPEG2_QSV_DECODER
-static const AVClass mpeg2_qsv_class = {
-.class_name = "mpeg2_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
+#define DEFINE_QSV_DECODER(x, X, bsf_name) \
+static const AVClass x##_qsv_class = { \
+.class_name = #x "_qsv", \
+.item_name  = av_default_item_name, \
+.option = options, \
+.version= LIBAVUTIL_VERSION_INT, \
+}; \
+AVCodec ff_##x##_qsv_decoder = { \
+.name   = #x "_qsv", \
+.long_name  = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video 
acceleration)"), \
+.priv_data_size = sizeof(QSVOtherContext), \
+.type   = AVMEDIA_TYPE_VIDEO, \
+.id = AV_CODEC_ID_##X, \
+.init   = qsv_decode_init, \
+.decode = qsv_decode_frame, \
+.flush  = qsv_decode_flush, \
+.close  = qsv_decode_close, \
+.bsfs   = bsf_name, \
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
+.priv_class = &x##_qsv_class, \
+.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
+AV_PIX_FMT_P010, \
+AV_PIX_FMT_QSV, \
+AV_PIX_FMT_NONE }, \
+.hw_configs = ff_qsv_hw_configs, \
+.wrapper_name   = "qsv", \
+}; \
 
-AVCodec ff_mpeg2_qsv_decoder = {
-.name   = "mpeg2_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("MPEG-2 video (Intel Quick Sync 
Video acceleration)"),
-.priv_data_size = sizeof(QSVOtherContext),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_MPEG2VIDEO,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &mpeg2_qsv_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_QSV,
-AV_PIX_FMT_NONE },
-.hw_configs = ff_qsv_hw_configs,
-.wrapper_name   = "qsv",
-};
+#if CONFIG_MPEG2_QSV_DECODER
+DEFINE_QSV_DECODER(mpeg2, MPEG2VIDEO, NULL)
 #endif
 
 #if CONFIG_VC1_QSV_DECODER
-static const AVClass vc1_qsv_class = {
-.class_name = "vc1_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_vc1_qsv_decoder = {
-.name   = "vc1_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("VC-1 video (Intel Quick Sync Video 
acceleration)"),
-.priv_data_size = sizeof(QSVOtherContext),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_VC1,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &vc1_qsv_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_QSV,
-AV_PIX_FMT_NONE },
-.hw_configs = ff_qsv_hw_configs,
-.wrapper_name   = "qsv",
-};
-#endif
-
-#if CONFIG_VP8_QSV_DECODER
-static const AVClass vp8_qsv_class = {
-.class_name = "vp8_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_vp8_qsv_decoder = {
-.name   = "vp8_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("VP8 video (Intel Quick Sync Video 
acceleration)"),
-.priv_data_size = sizeof(QSVOtherContext),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_VP8,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &vp8_qsv_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_QSV,
-   

[FFmpeg-devel] [PATCH v2 1/6] avcodec/qsv_h2645: fix memory leak for plugin load

2021-01-04 Thread Xu Guangxin
---
 libavcodec/qsvdec_h2645.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index 02c41883b6..3d6e85230f 100644
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -69,6 +69,8 @@ static av_cold int qsv_decode_close(AVCodecContext *avctx)
 {
 QSVH2645Context *s = avctx->priv_data;
 
+av_freep(&s->qsv.load_plugins);
+
 ff_qsv_decode_close(&s->qsv);
 
 qsv_clear_buffers(s);
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 5/5] avcodec/qsvdec: refact, remove duplicate code for plugin loading

2020-11-26 Thread Xu Guangxin
---
 libavcodec/qsvdec.c | 29 +++--
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index ed40e2f4c2..8da367079a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -681,21 +681,12 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 {
 QSVDecContext *s = avctx->priv_data;
 int ret;
+const char *uid = NULL;
 
 if (avctx->codec_id == AV_CODEC_ID_VP8) {
-static const char *uid_vp8dec_hw = "f622394d8d87452f878c51f2fc9b4131";
-
-av_freep(&s->qsv.load_plugins);
-s->qsv.load_plugins = av_strdup(uid_vp8dec_hw);
-if (!s->qsv.load_plugins)
-return AVERROR(ENOMEM);
+uid = "f622394d8d87452f878c51f2fc9b4131";
 } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
-static const char *uid_vp9dec_hw = "a922394d8d87452f878c51f2fc9b4131";
-
-av_freep(&s->qsv.load_plugins);
-s->qsv.load_plugins = av_strdup(uid_vp9dec_hw);
-if (!s->qsv.load_plugins)
-return AVERROR(ENOMEM);
+uid = "a922394d8d87452f878c51f2fc9b4131";
 }
 else if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != 
LOAD_PLUGIN_NONE) {
 static const char * const uid_hevcdec_sw = 
"15dd936825ad475ea34e35f3f54217a6";
@@ -706,16 +697,18 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
"load_plugins is not empty, but load_plugin is not set to 
'none'."
"The load_plugin value will be ignored.\n");
 } else {
-av_freep(&s->qsv.load_plugins);
-
 if (s->load_plugin == LOAD_PLUGIN_HEVC_SW)
-s->qsv.load_plugins = av_strdup(uid_hevcdec_sw);
+uid = uid_hevcdec_sw;
 else
-s->qsv.load_plugins = av_strdup(uid_hevcdec_hw);
-if (!s->qsv.load_plugins)
-return AVERROR(ENOMEM);
+uid = uid_hevcdec_hw;
 }
 }
+if (uid) {
+av_freep(&s->qsv.load_plugins);
+s->qsv.load_plugins = av_strdup(uid);
+if (!s->qsv.load_plugins)
+return AVERROR(ENOMEM);
+}
 
 s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
 s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 4/5] avcodec/qsvdec: refact, move qsvdec_other.c to qsvdec.c

2020-11-26 Thread Xu Guangxin
---
 libavcodec/Makefile   |  14 +--
 libavcodec/qsvdec.c   |  42 ++-
 libavcodec/qsvdec_other.c | 242 --
 3 files changed, 48 insertions(+), 250 deletions(-)
 delete mode 100644 libavcodec/qsvdec_other.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3ee8aa7f86..d7dac52e15 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -448,7 +448,7 @@ OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o 
metasound_data.o \
 OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o
-OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec_other.o
+OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec.o
 OBJS-$(CONFIG_MJPEG_ENCODER)   += mjpegenc.o mjpegenc_common.o \
   mjpegenc_huffman.o
 OBJS-$(CONFIG_MJPEGB_DECODER)  += mjpegbdec.o
@@ -485,7 +485,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)  += mpeg12enc.o 
mpeg12.o
 OBJS-$(CONFIG_MPEG1_CUVID_DECODER) += cuviddec.o
 OBJS-$(CONFIG_MPEG1_V4L2M2M_DECODER)   += v4l2_m2m_dec.o
 OBJS-$(CONFIG_MPEG2_MMAL_DECODER)  += mmaldec.o
-OBJS-$(CONFIG_MPEG2_QSV_DECODER)   += qsvdec_other.o
+OBJS-$(CONFIG_MPEG2_QSV_DECODER)   += qsvdec.o
 OBJS-$(CONFIG_MPEG2_QSV_ENCODER)   += qsvenc_mpeg2.o
 OBJS-$(CONFIG_MPEG2VIDEO_DECODER)  += mpeg12dec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)  += mpeg12enc.o mpeg12.o
@@ -687,7 +687,7 @@ OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o 
vc1_block.o vc1_loopfilter.o
   wmv2dsp.o wmv2data.o
 OBJS-$(CONFIG_VC1_CUVID_DECODER)   += cuviddec.o
 OBJS-$(CONFIG_VC1_MMAL_DECODER)+= mmaldec.o
-OBJS-$(CONFIG_VC1_QSV_DECODER) += qsvdec_other.o
+OBJS-$(CONFIG_VC1_QSV_DECODER) += qsvdec.o
 OBJS-$(CONFIG_VC1_V4L2M2M_DECODER) += v4l2_m2m_dec.o
 OBJS-$(CONFIG_VC2_ENCODER) += vc2enc.o vc2enc_dwt.o diractab.o
 OBJS-$(CONFIG_VCR1_DECODER)+= vcr1.o
@@ -706,7 +706,7 @@ OBJS-$(CONFIG_VP7_DECODER) += vp8.o vp56rac.o
 OBJS-$(CONFIG_VP8_DECODER) += vp8.o vp56rac.o
 OBJS-$(CONFIG_VP8_CUVID_DECODER)   += cuviddec.o
 OBJS-$(CONFIG_VP8_MEDIACODEC_DECODER)  += mediacodecdec.o
-OBJS-$(CONFIG_VP8_QSV_DECODER) += qsvdec_other.o
+OBJS-$(CONFIG_VP8_QSV_DECODER) += qsvdec.o
 OBJS-$(CONFIG_VP8_RKMPP_DECODER)   += rkmppdec.o
 OBJS-$(CONFIG_VP8_VAAPI_ENCODER)   += vaapi_encode_vp8.o
 OBJS-$(CONFIG_VP8_V4L2M2M_DECODER) += v4l2_m2m_dec.o
@@ -941,7 +941,7 @@ OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL) += 
mpegvideo_xvmc.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
-OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec_other.o
+OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
 OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)+= vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
@@ -953,7 +953,7 @@ OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
-OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec_other.o
+OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
 OBJS-$(CONFIG_VC1_VDPAU_HWACCEL)  += vdpau_vc1.o
 OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
@@ -963,7 +963,7 @@ OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
-OBJS-$(CONFIG_VP8_QSV_HWACCEL)+= qsvdec_other.o
+OBJS-$(CONFIG_VP8_QSV_HWACCEL)+= qsvdec.o
 
 # libavformat dependencies
 OBJS-$(CONFIG_ISO_MEDIA)   += mpeg4audio.o mpegaudiodata.o
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 0a79d00eac..ed40e2f4c2 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -667,6 +667,7 @@ static av_cold int qsv_decode_close(AVCodecContext *avctx)
 {
 QSVDecContext *s = avctx->priv_data;
 
+av_freep(&s->qsv.load_plugins);
 ff_qsv_decode_close(&s->qsv);
 
 qsv_clear_buffers(s);
@@ -681,7 +682,22 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 QSVDecContext *s = avctx->priv_data;
 int ret;
 
-if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != 
LOAD_PLUGIN_NONE) {
+if (avctx->codec_id == AV_CODEC_ID_VP8) {
+static const char *uid_vp8dec_hw = "f622394d8d87452f878c51f2fc9b4131";
+
+av_freep(&s->qsv.load_plugins);
+s->qsv.load_plugins = av_strdup(u

[FFmpeg-devel] [PATCH 3/5] avcodec/qsvdec: refact, move qsvdec_h2645.c to qsvdec.c

2020-11-26 Thread Xu Guangxin
---
 libavcodec/Makefile   |   8 +-
 libavcodec/qsvdec.c   | 215 -
 libavcodec/qsvdec_h2645.c | 248 --
 3 files changed, 217 insertions(+), 254 deletions(-)
 delete mode 100644 libavcodec/qsvdec_h2645.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a6435c9e85..3ee8aa7f86 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -374,7 +374,7 @@ OBJS-$(CONFIG_H264_NVENC_ENCODER)  += nvenc_h264.o
 OBJS-$(CONFIG_NVENC_ENCODER)   += nvenc_h264.o
 OBJS-$(CONFIG_NVENC_H264_ENCODER)  += nvenc_h264.o
 OBJS-$(CONFIG_H264_OMX_ENCODER)+= omx.o
-OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
+OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec.o
 OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
 OBJS-$(CONFIG_H264_RKMPP_DECODER)  += rkmppdec.o
 OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o h264_levels.o
@@ -394,7 +394,7 @@ OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_HEVC_MF_ENCODER) += mfenc.o mf_utils.o
 OBJS-$(CONFIG_HEVC_NVENC_ENCODER)  += nvenc_hevc.o
 OBJS-$(CONFIG_NVENC_HEVC_ENCODER)  += nvenc_hevc.o
-OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec_h2645.o
+OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec.o
 OBJS-$(CONFIG_HEVC_QSV_ENCODER)+= qsvenc_hevc.o hevc_ps_enc.o   \
   hevc_data.o
 OBJS-$(CONFIG_HEVC_RKMPP_DECODER)  += rkmppdec.o
@@ -922,14 +922,14 @@ OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_D3D11VA_HWACCEL)   += dxva2_h264.o
 OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
 OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o
-OBJS-$(CONFIG_H264_QSV_HWACCEL)   += qsvdec_h2645.o
+OBJS-$(CONFIG_H264_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
 OBJS-$(CONFIG_H264_VDPAU_HWACCEL) += vdpau_h264.o
 OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += videotoolbox.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
-OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec_h2645.o
+OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
 OBJS-$(CONFIG_HEVC_VDPAU_HWACCEL) += vdpau_hevc.o h265_profile_level.o
 OBJS-$(CONFIG_MJPEG_NVDEC_HWACCEL)+= nvdec_mjpeg.o
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c666aaeb52..0a79d00eac 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -31,6 +31,7 @@
 #include "libavutil/hwcontext_qsv.h"
 #include "libavutil/mem.h"
 #include "libavutil/log.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/time.h"
@@ -228,7 +229,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 return 0;
  }
 
-static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxVideoParam 
*param)
+static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, 
mfxVideoParam *param)
 {
 int ret;
 
@@ -615,7 +616,7 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 }
 
 if (!q->initialized) {
-ret = qsv_decode_init(avctx, q, ¶m);
+ret = qsv_decode_init_context(avctx, q, ¶m);
 if (ret < 0)
 goto reinit_fail;
 q->initialized = 1;
@@ -633,3 +634,213 @@ void ff_qsv_decode_flush(AVCodecContext *avctx, 
QSVContext *q)
 q->orig_pix_fmt = AV_PIX_FMT_NONE;
 q->initialized = 0;
 }
+
+enum LoadPlugin {
+LOAD_PLUGIN_NONE,
+LOAD_PLUGIN_HEVC_SW,
+LOAD_PLUGIN_HEVC_HW,
+};
+
+typedef struct QSVDecContext {
+AVClass *class;
+QSVContext qsv;
+
+int load_plugin;
+
+AVFifoBuffer *packet_fifo;
+
+AVPacket buffer_pkt;
+} QSVDecContext;
+
+static void qsv_clear_buffers(QSVDecContext *s)
+{
+AVPacket pkt;
+while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
+av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
+av_packet_unref(&pkt);
+}
+
+av_packet_unref(&s->buffer_pkt);
+}
+
+static av_cold int qsv_decode_close(AVCodecContext *avctx)
+{
+QSVDecContext *s = avctx->priv_data;
+
+ff_qsv_decode_close(&s->qsv);
+
+qsv_clear_buffers(s);
+
+av_fifo_free(s->packet_fifo);
+
+return 0;
+}
+
+static av_cold int qsv_decode_init(AVCodecContext *avctx)
+{
+QSVDecContext *s = avctx->priv_data;
+int ret;
+
+if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != 
LOAD_PLUGIN_NONE) {
+static const char * const uid_hevcdec_sw = 
"15dd936825ad475ea34e35f3f54217a6";
+static const char * const uid_hevcdec_hw = 
"33a61c0b4c27454ca8d85dde757c6f8e";
+
+if (s->qsv.load_plugins[0]) {
+av_log(avctx, AV_LOG_WARNING

[FFmpeg-devel] [PATCH 2/5] avcodec/qsvdec_h2645: refact, use DEFINE_QSV_DECODER to remove duplicate code

2020-11-26 Thread Xu Guangxin
---
 libavcodec/qsvdec_h2645.c | 89 +++
 1 file changed, 33 insertions(+), 56 deletions(-)

diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index 02c41883b6..b0ab23a922 100644
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -182,6 +182,36 @@ static void qsv_decode_flush(AVCodecContext *avctx)
 #define OFFSET(x) offsetof(QSVH2645Context, x)
 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
+#define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt) \
+static const AVClass x##_qsv_class = { \
+.class_name = #x "_qsv", \
+.item_name  = av_default_item_name, \
+.option = opt, \
+.version= LIBAVUTIL_VERSION_INT, \
+}; \
+AVCodec ff_##x##_qsv_decoder = { \
+.name   = #x "_qsv", \
+.long_name  = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video 
acceleration)"), \
+.priv_data_size = sizeof(QSVH2645Context), \
+.type   = AVMEDIA_TYPE_VIDEO, \
+.id = AV_CODEC_ID_##X, \
+.init   = qsv_decode_init, \
+.decode = qsv_decode_frame, \
+.flush  = qsv_decode_flush, \
+.close  = qsv_decode_close, \
+.bsfs   = bsf_name, \
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
+.priv_class = &x##_qsv_class, \
+.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
+AV_PIX_FMT_P010, \
+AV_PIX_FMT_QSV, \
+AV_PIX_FMT_NONE }, \
+.hw_configs = ff_qsv_hw_configs, \
+.wrapper_name   = "qsv", \
+}; \
+
+#define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x, 
X, bsf_name, options)
+
 #if CONFIG_HEVC_QSV_DECODER
 static const AVOption hevc_options[] = {
 { "async_depth", "Internal parallelization depth, the higher the value the 
higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 
ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
@@ -200,37 +230,9 @@ static const AVOption hevc_options[] = {
 { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF },   
  0, 0, VD, "gpu_copy"},
 { NULL },
 };
-
-static const AVClass hevc_class = {
-.class_name = "hevc_qsv",
-.item_name  = av_default_item_name,
-.option = hevc_options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_hevc_qsv_decoder = {
-.name   = "hevc_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("HEVC (Intel Quick Sync Video 
acceleration)"),
-.priv_data_size = sizeof(QSVH2645Context),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_HEVC,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &hevc_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_P010,
-AV_PIX_FMT_QSV,
-AV_PIX_FMT_NONE },
-.hw_configs = ff_qsv_hw_configs,
-.bsfs   = "hevc_mp4toannexb",
-.wrapper_name   = "qsv",
-};
+DEFINE_QSV_DECODER_WITH_OPTION(hevc, HEVC, "hevc_mp4toannexb", hevc_options)
 #endif
 
-#if CONFIG_H264_QSV_DECODER
 static const AVOption options[] = {
 { "async_depth", "Internal parallelization depth, the higher the value the 
higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 
ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
 
@@ -241,31 +243,6 @@ static const AVOption options[] = {
 { NULL },
 };
 
-static const AVClass class = {
-.class_name = "h264_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_h264_qsv_decoder = {
-.name   = "h264_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 
part 10 (Intel Quick Sync Video acceleration)"),
-.priv_data_size = sizeof(QSVH2645Context),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_H264,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_P010,
-AV_PIX_FMT_QSV,
- 

[FFmpeg-devel] [PATCH 1/5] avcodec/qsvdec_other: refact, use DEFINE_QSV_DECODER to remove duplicate code

2020-11-26 Thread Xu Guangxin
---
 libavcodec/qsvdec_other.c | 188 --
 1 file changed, 36 insertions(+), 152 deletions(-)

diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
index 2775e07955..266ac9f2e5 100644
--- a/libavcodec/qsvdec_other.c
+++ b/libavcodec/qsvdec_other.c
@@ -189,170 +189,54 @@ static const AVOption options[] = {
 { NULL },
 };
 
-#if CONFIG_MPEG2_QSV_DECODER
-static const AVClass mpeg2_qsv_class = {
-.class_name = "mpeg2_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
+#define DEFINE_QSV_DECODER(x, X, bsf_name) \
+static const AVClass x##_qsv_class = { \
+.class_name = #x "_qsv", \
+.item_name  = av_default_item_name, \
+.option = options, \
+.version= LIBAVUTIL_VERSION_INT, \
+}; \
+AVCodec ff_##x##_qsv_decoder = { \
+.name   = #x "_qsv", \
+.long_name  = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video 
acceleration)"), \
+.priv_data_size = sizeof(QSVOtherContext), \
+.type   = AVMEDIA_TYPE_VIDEO, \
+.id = AV_CODEC_ID_##X, \
+.init   = qsv_decode_init, \
+.decode = qsv_decode_frame, \
+.flush  = qsv_decode_flush, \
+.close  = qsv_decode_close, \
+.bsfs   = bsf_name, \
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
+.priv_class = &x##_qsv_class, \
+.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
+AV_PIX_FMT_P010, \
+AV_PIX_FMT_QSV, \
+AV_PIX_FMT_NONE }, \
+.hw_configs = ff_qsv_hw_configs, \
+.wrapper_name   = "qsv", \
+}; \
 
-AVCodec ff_mpeg2_qsv_decoder = {
-.name   = "mpeg2_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("MPEG-2 video (Intel Quick Sync 
Video acceleration)"),
-.priv_data_size = sizeof(QSVOtherContext),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_MPEG2VIDEO,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &mpeg2_qsv_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_QSV,
-AV_PIX_FMT_NONE },
-.hw_configs = ff_qsv_hw_configs,
-.wrapper_name   = "qsv",
-};
+#if CONFIG_MPEG2_QSV_DECODER
+DEFINE_QSV_DECODER(mpeg2, MPEG2VIDEO, NULL)
 #endif
 
 #if CONFIG_VC1_QSV_DECODER
-static const AVClass vc1_qsv_class = {
-.class_name = "vc1_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_vc1_qsv_decoder = {
-.name   = "vc1_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("VC-1 video (Intel Quick Sync Video 
acceleration)"),
-.priv_data_size = sizeof(QSVOtherContext),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_VC1,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &vc1_qsv_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_QSV,
-AV_PIX_FMT_NONE },
-.hw_configs = ff_qsv_hw_configs,
-.wrapper_name   = "qsv",
-};
-#endif
-
-#if CONFIG_VP8_QSV_DECODER
-static const AVClass vp8_qsv_class = {
-.class_name = "vp8_qsv",
-.item_name  = av_default_item_name,
-.option = options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-
-AVCodec ff_vp8_qsv_decoder = {
-.name   = "vp8_qsv",
-.long_name  = NULL_IF_CONFIG_SMALL("VP8 video (Intel Quick Sync Video 
acceleration)"),
-.priv_data_size = sizeof(QSVOtherContext),
-.type   = AVMEDIA_TYPE_VIDEO,
-.id = AV_CODEC_ID_VP8,
-.init   = qsv_decode_init,
-.decode = qsv_decode_frame,
-.flush  = qsv_decode_flush,
-.close  = qsv_decode_close,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
-.priv_class = &vp8_qsv_class,
-.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
-AV_PIX_FMT_QSV,
-   

[FFmpeg-devel] [PATCH v2] fate/hevc-conformance: add clip for persistent_rice_adaptation_enabled_flag

2020-11-14 Thread Xu Guangxin
you can download it from:
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/RExt/WPP_HIGH_TP_444_8BIT_RExt_Apple_2.zip

Signed-off-by: Xu Guangxin 
---
 tests/fate/hevc.mak   | 1 +
 .../hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2| 8 
 2 files changed, 9 insertions(+)
 create mode 100644 
tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2

diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak
index 9a32a7d74c..97edb49781 100644
--- a/tests/fate/hevc.mak
+++ b/tests/fate/hevc.mak
@@ -141,6 +141,7 @@ HEVC_SAMPLES =  \
 WPP_D_ericsson_MAIN_2   \
 WPP_E_ericsson_MAIN_2   \
 WPP_F_ericsson_MAIN_2   \
+WPP_HIGH_TP_444_8BIT_RExt_Apple_2 \
 
 HEVC_SAMPLES_10BIT =\
 DBLK_A_MAIN10_VIXS_3\
diff --git a/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2 
b/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2
new file mode 100644
index 00..fcb1d2894a
--- /dev/null
+++ b/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2
@@ -0,0 +1,8 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1024x768
+#sar 0: 0/1
+0,  0,  0,1,  1179648, 0x78e55a69
+0,  1,  1,1,  1179648, 0x5babb3cb
+0,  2,  2,1,  1179648, 0x65935648
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] fate/hevc-conformance: add clip for persistent_rice_adaptation_enabled_flag

2020-11-14 Thread Xu Guangxin
you can download it from:
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/RExt/WPP_HIGH_TP_444_8BIT_RExt_Apple_2.zip

Signed-off-by: Xu Guangxin 
---
 tests/fate/hevc.mak   | 1 +
 .../hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2| 8 
 2 files changed, 9 insertions(+)
 create mode 100644 
tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2

diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak
index 9a32a7d74c..97edb49781 100644
--- a/tests/fate/hevc.mak
+++ b/tests/fate/hevc.mak
@@ -141,6 +141,7 @@ HEVC_SAMPLES =  \
 WPP_D_ericsson_MAIN_2   \
 WPP_E_ericsson_MAIN_2   \
 WPP_F_ericsson_MAIN_2   \
+WPP_HIGH_TP_444_8BIT_RExt_Apple_2 \
 
 HEVC_SAMPLES_10BIT =\
 DBLK_A_MAIN10_VIXS_3\
diff --git a/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2 
b/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2
new file mode 100644
index 00..fcb1d2894a
--- /dev/null
+++ b/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2
@@ -0,0 +1,8 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1024x768
+#sar 0: 0/1
+0,  0,  0,1,  1179648, 0x78e55a69
+0,  1,  1,1,  1179648, 0x5babb3cb
+0,  2,  2,1,  1179648, 0x65935648
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] avcodec/hevcdec: fix stat_coeff save/load for persistent_rice_adaptation_enabled_flag

2020-11-14 Thread Xu Guangxin
It's required by the 9.3.1 TableStatCoeff* section.

Following clips have this feature:
WPP_HIGH_TP_444_8BIT_RExt_Apple_2.bit
Bitdepth_A_RExt_Sony_1.bin
Bitdepth_B_RExt_Sony_1.bin
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_10BIT_RExt_Sony_1.bit
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_12BIT_RExt_Sony_1.bit
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_8BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_10BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_12BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_8BIT_RExt_Sony_1.bit
WPP_AND_TILE_10Bit422Test_HIGH_TP_444_10BIT_RExt_Apple_2.bit
WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_0_HIGH_TP_444_14BIT_RExt_Apple_2.bit
WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_1_HIGH_TP_444_14BIT_RExt_Apple_2.bit
WPP_AND_TILE_HIGH_TP_444_8BIT_RExt_Apple_2.bit

you can download them from:
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/RExt/

Signed-off-by: Xu Guangxin 
---
 libavcodec/hevc_cabac.c | 15 +++
 libavcodec/hevcdec.c|  4 ++--
 libavcodec/hevcdec.h|  6 --
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 3dc0987dad..93fc1ec795 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -454,12 +454,19 @@ void ff_hevc_save_states(HEVCContext *s, int ctb_addr_ts)
  (s->ps.sps->ctb_width == 2 &&
   ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
 memcpy(s->cabac_state, s->HEVClc->cabac_state, HEVC_CONTEXTS);
+if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
+memcpy(s->stat_coeff, s->HEVClc->stat_coeff, HEVC_STAT_COEFFS);
+}
 }
 }
 
-static void load_states(HEVCContext *s)
+static void load_states(HEVCContext *s, int thread)
 {
 memcpy(s->HEVClc->cabac_state, s->cabac_state, HEVC_CONTEXTS);
+if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
+const HEVCContext *prev = s->sList[(thread + s->threads_number - 1) % 
s->threads_number];
+memcpy(s->HEVClc->stat_coeff, prev->stat_coeff, HEVC_STAT_COEFFS);
+}
 }
 
 static int cabac_reinit(HEVCLocalContext *lc)
@@ -501,7 +508,7 @@ static void cabac_init_state(HEVCContext *s)
 s->HEVClc->stat_coeff[i] = 0;
 }
 
-int ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts)
+int ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts, int thread)
 {
 if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
 int ret = cabac_init_decoder(s);
@@ -518,7 +525,7 @@ int ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts)
 if (s->ps.sps->ctb_width == 1)
 cabac_init_state(s);
 else if (s->sh.dependent_slice_segment_flag == 1)
-load_states(s);
+load_states(s, thread);
 }
 }
 } else {
@@ -549,7 +556,7 @@ int ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts)
 if (s->ps.sps->ctb_width == 1)
 cabac_init_state(s);
 else
-load_states(s);
+load_states(s, thread);
 }
 }
 }
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 699c13bbcc..7191fcf542 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2473,7 +2473,7 @@ static int hls_decode_entry(AVCodecContext *avctxt, void 
*isFilterThread)
 y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> 
s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
 hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts);
 
-ret = ff_hevc_cabac_init(s, ctb_addr_ts);
+ret = ff_hevc_cabac_init(s, ctb_addr_ts, 0);
 if (ret < 0) {
 s->tab_slice_address[ctb_addr_rs] = -1;
 return ret;
@@ -2551,7 +2551,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, 
void *input_ctb_row, int
 return 0;
 }
 
-ret = ff_hevc_cabac_init(s, ctb_addr_ts);
+ret = ff_hevc_cabac_init(s, ctb_addr_ts, thread);
 if (ret < 0)
 goto error;
 hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> 
s->ps.sps->log2_ctb_size);
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 39c5c7f89f..5b49384aea 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -53,6 +53,7 @@
 #define DEFAULT_INTRA_TC_OFFSET 2
 
 #define HEVC_CONTEXTS 199
+#define HEVC_STAT_COEFFS 4
 
 #define MRG_MAX_NUM_CANDS 5
 
@@ -424,7 +425,7 @@ typedef struct HEVCFrame {
 typedef struct HEVCLocalContext {
 uint8_t cabac_state[HEVC_CONTEXTS];
 
-uint8_t stat_coeff[4];
+uint8_t stat_coeff[HEVC_STAT_COEFFS];
 
 uint8_t first_qp_group;
 
@@ -480,6 +481,7 @@ typedef struct HEVCContext {
 int height;
 
 uint8_t *cabac_state;
+uint8_t stat_coe

[FFmpeg-devel] [PATCH] avcodec/hevcdec: constrained intra predict, do not check top left IS_INTRA if it's not available

2020-10-16 Thread Xu Guangxin
fix ticket: 8932

For poc 2, we have tile boundary at x = 640.
When we predict cu(640,912),the top left pixel is not avaliable to the cu.
So, we can not check it's intra or not. We need set top[-1] = top[0] directly.
see 8.4.4.2.1 for details
---
 libavcodec/hevcpred_template.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevcpred_template.c b/libavcodec/hevcpred_template.c
index 6fe33546b1..e550707874 100644
--- a/libavcodec/hevcpred_template.c
+++ b/libavcodec/hevcpred_template.c
@@ -213,7 +213,7 @@ do {  \
 while (j < size_max_x && !IS_INTRA(j, -1))
 j++;
 if (j > 0)
-if (x0 > 0) {
+if (cand_up_left) {
 EXTEND_LEFT_CIP(top, j, j + 1);
 } else {
 EXTEND_LEFT_CIP(top, j, j);
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/2] fate/hevc-conformance: add clip for persistent_rice_adaptation_enabled_flag

2020-08-28 Thread Xu Guangxin
you can download it from:
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/RExt/WPP_HIGH_TP_444_8BIT_RExt_Apple_2.bit

Signed-off-by: Xu Guangxin 
---
 tests/fate/hevc.mak   | 1 +
 .../hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2| 8 
 2 files changed, 9 insertions(+)
 create mode 100644 
tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2

diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak
index 65c5a262e9..f81a065e80 100644
--- a/tests/fate/hevc.mak
+++ b/tests/fate/hevc.mak
@@ -141,6 +141,7 @@ HEVC_SAMPLES =  \
 WPP_D_ericsson_MAIN_2   \
 WPP_E_ericsson_MAIN_2   \
 WPP_F_ericsson_MAIN_2   \
+WPP_HIGH_TP_444_8BIT_RExt_Apple_2 \
 
 HEVC_SAMPLES_10BIT =\
 DBLK_A_MAIN10_VIXS_3\
diff --git a/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2 
b/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2
new file mode 100644
index 00..fcb1d2894a
--- /dev/null
+++ b/tests/ref/fate/hevc-conformance-WPP_HIGH_TP_444_8BIT_RExt_Apple_2
@@ -0,0 +1,8 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1024x768
+#sar 0: 0/1
+0,  0,  0,1,  1179648, 0x78e55a69
+0,  1,  1,1,  1179648, 0x5babb3cb
+0,  2,  2,1,  1179648, 0x65935648
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] avcodec/hevcdec: fix stat_coeff save/load for persistent_rice_adaptation_enabled_flag

2020-08-28 Thread Xu Guangxin
It's required by 9.3.1. following clips have this feature:

WPP_HIGH_TP_444_8BIT_RExt_Apple_2.bit
Bitdepth_A_RExt_Sony_1.bin
Bitdepth_B_RExt_Sony_1.bin
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_10BIT_RExt_Sony_1.bit
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_12BIT_RExt_Sony_1.bit
EXTPREC_HIGHTHROUGHPUT_444_16_INTRA_8BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_10BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_12BIT_RExt_Sony_1.bit
EXTPREC_MAIN_444_16_INTRA_8BIT_RExt_Sony_1.bit
WPP_AND_TILE_10Bit422Test_HIGH_TP_444_10BIT_RExt_Apple_2.bit
WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_0_HIGH_TP_444_14BIT_RExt_Apple_2.bit
WPP_AND_TILE_AND_CABAC_BYPASS_ALIGN_1_HIGH_TP_444_14BIT_RExt_Apple_2.bit
WPP_AND_TILE_HIGH_TP_444_8BIT_RExt_Apple_2.bit

you can download them from:
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/RExt/

Signed-off-by: Xu Guangxin 
---
 libavcodec/hevc_cabac.c | 6 ++
 libavcodec/hevcdec.h| 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 3dc0987dad..635b4edef3 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -454,12 +454,18 @@ void ff_hevc_save_states(HEVCContext *s, int ctb_addr_ts)
  (s->ps.sps->ctb_width == 2 &&
   ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
 memcpy(s->cabac_state, s->HEVClc->cabac_state, HEVC_CONTEXTS);
+if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
+memcpy(s->stat_coeff, s->HEVClc->stat_coeff, HEVC_STAT_COEFFS);
+}
 }
 }
 
 static void load_states(HEVCContext *s)
 {
 memcpy(s->HEVClc->cabac_state, s->cabac_state, HEVC_CONTEXTS);
+if (s->ps.sps->persistent_rice_adaptation_enabled_flag) {
+memcpy(s->HEVClc->stat_coeff, s->stat_coeff, HEVC_STAT_COEFFS);
+}
 }
 
 static int cabac_reinit(HEVCLocalContext *lc)
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 39c5c7f89f..d41aed4556 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -53,6 +53,7 @@
 #define DEFAULT_INTRA_TC_OFFSET 2
 
 #define HEVC_CONTEXTS 199
+#define HEVC_STAT_COEFFS 4
 
 #define MRG_MAX_NUM_CANDS 5
 
@@ -424,7 +425,7 @@ typedef struct HEVCFrame {
 typedef struct HEVCLocalContext {
 uint8_t cabac_state[HEVC_CONTEXTS];
 
-uint8_t stat_coeff[4];
+uint8_t stat_coeff[HEVC_STAT_COEFFS];
 
 uint8_t first_qp_group;
 
@@ -480,6 +481,7 @@ typedef struct HEVCContext {
 int height;
 
 uint8_t *cabac_state;
+uint8_t stat_coeff[HEVC_STAT_COEFFS];
 
 /** 1 if the independent slice segment header was successfully parsed */
 uint8_t slice_initialized;
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/ff_mpv_encode_end: fix a crash for null s->avctx

2020-08-25 Thread Xu Guangxin
Steps to reproduce:
1. ./configure --enable-debug=3 --disable-libx264 && make install
2. ffmpeg -i input.mp4 -profile:v baseline output.mp4 -y

you will see a crash like this:
[mpeg4 @ 0x575854c0] [Eval @ 0x7fffbf80] Undefined constant or missing 
'(' in 'baseline'
[mpeg4 @ 0x575854c0] Unable to parse option value "baseline"
[mpeg4 @ 0x575854c0] Error setting option profile to value baseline.
Thread 1 "ffmpeg" received signal SIGSEGV, Segmentation fault.

root cause:
If the codec has FF_CODEC_CAP_INIT_CLEANUP flag, and avcodec_open2 got an error 
before avctx->codec->init,
the ff_mpv_encode_end will face a null s->avctx.
---
 libavcodec/mpegvideo_enc.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 09697d89c8..a79309d1b9 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1078,9 +1078,10 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
 av_frame_free(&s->tmp_frames[i]);
 
 ff_free_picture_tables(&s->new_picture);
-ff_mpeg_unref_picture(s->avctx, &s->new_picture);
-
-av_freep(&s->avctx->stats_out);
+if (s->avctx) {
+ff_mpeg_unref_picture(s->avctx, &s->new_picture);
+av_freep(&s->avctx->stats_out);
+}
 av_freep(&s->ac_stats);
 
 if(s->q_chroma_intra_matrix   != s->q_intra_matrix  ) 
av_freep(&s->q_chroma_intra_matrix);
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/3] avcodec/cbs_av1: infer frame_type when parsing a show_existing_frame frame

2020-08-24 Thread Xu, Guangxin
May not related to this patch.
When we have show_existing_frame and the frame_type is key frame, do we need do 
"Reference frame update"?

> -Original Message-
> From: ffmpeg-devel  On Behalf Of James
> Almer
> Sent: Monday, August 24, 2020 3:24 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/cbs_av1: infer frame_type when
> parsing a show_existing_frame frame
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/cbs_av1_syntax_template.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/cbs_av1_syntax_template.c
> b/libavcodec/cbs_av1_syntax_template.c
> index dedd549572..28d9ab9817 100644
> --- a/libavcodec/cbs_av1_syntax_template.c
> +++ b/libavcodec/cbs_av1_syntax_template.c
> @@ -1299,6 +1299,7 @@ static int
> FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
>  else
>  infer(refresh_frame_flags, 0);
> 
> +infer(frame_type,frame->frame_type);
>  infer(frame_width_minus_1,   frame->upscaled_width - 1);
>  infer(frame_height_minus_1,  frame->frame_height - 1);
>  infer(render_width_minus_1,  frame->render_width - 1);
> --
> 2.27.0
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse options in openvino backend

2020-08-14 Thread Xu, Guangxin


> -Original Message-
> From: ffmpeg-devel  On Behalf Of Guo,
> Yejun
> Sent: Friday, August 14, 2020 9:50 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH V2] dnn_backend_openvino.c: parse options
> in openvino backend
> 
> Signed-off-by: Guo, Yejun 
> ---
>  libavfilter/dnn/dnn_backend_openvino.c | 37
> +-
>  1 file changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_openvino.c
> b/libavfilter/dnn/dnn_backend_openvino.c
> index d343bf2..478e151 100644
> --- a/libavfilter/dnn/dnn_backend_openvino.c
> +++ b/libavfilter/dnn/dnn_backend_openvino.c
> @@ -26,8 +26,14 @@
>  #include "dnn_backend_openvino.h"
>  #include "libavformat/avio.h"
>  #include "libavutil/avassert.h"
> +#include "libavutil/avstring.h"
>  #include 
> 
> +typedef struct OVOptions{
> +uint32_t batch_size;
> +uint32_t req_num;
> +} OVOptions;
> +
>  typedef struct OVModel{
>  ie_core_t *core;
>  ie_network_t *network;
> @@ -36,6 +42,7 @@ typedef struct OVModel{
>  ie_blob_t *input_blob;
>  ie_blob_t **output_blobs;
>  uint32_t nb_output;
> +OVOptions options;
>  } OVModel;
> 
>  static DNNDataType precision_to_datatype(precision_e precision) @@ -50,6
> +57,32 @@ static DNNDataType precision_to_datatype(precision_e precision)
>  }
>  }
> 
> +static int parse_options_ov(OVOptions *to, const char *from) {
> +AVDictionary *dict = NULL;
> +AVDictionaryEntry *opt = NULL;
> +int err = av_dict_parse_string(&dict, from, "=", "&", 0);
> +if (err < 0) {
> +av_dict_free(&dict);
This may not needed.

> +return err;
> +}
> +
> +opt = av_dict_get(dict, "nireq", opt, AV_DICT_MATCH_CASE);
> +if (opt != NULL)
> +to->req_num = atoi(opt->value);
> +else
> +to->req_num = 1;
> +
> +opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE);
> +if (opt != NULL)
> +to->batch_size = atoi(opt->value);
> +else
> +to->batch_size = 1;
How about a function like this.
Int dict_get_int(const AVDictionary *m, const char *key, int default_value)

> +
> +av_dict_free(&dict);
> +return 0;
> +}
> +
>  static DNNReturnType get_input_ov(void *model, DNNData *input, const char
> *input_name)  {
>  OVModel *ov_model = (OVModel *)model; @@ -171,6 +204,9 @@
> DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char
> *options)
>  if (!ov_model)
>  goto err;
> 
> +model->options = options;
> +parse_options_ov(&ov_model->options, model->options);
Check error?

> +
>  status = ie_core_create("", &ov_model->core);
>  if (status != OK)
>  goto err;
> @@ -186,7 +222,6 @@ DNNModel *ff_dnn_load_model_ov(const char
> *model_filename, const char *options)
>  model->model = (void *)ov_model;
>  model->set_input_output = &set_input_output_ov;
>  model->get_input = &get_input_ov;
> -model->options = options;
> 
>  return model;
> 
> --
> 2.7.4
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] dnn_backend_native_layer_mathbinary: add floormod support

2020-08-14 Thread Xu, Guangxin


> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Mingyu Yin
> Sent: Friday, August 14, 2020 6:11 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH] dnn_backend_native_layer_mathbinary: add
> floormod support
> 
> Signed-off-by: Mingyu Yin 
> ---
>  .../dnn/dnn_backend_native_layer_mathbinary.c   | 17 +
>  .../dnn/dnn_backend_native_layer_mathbinary.h   |  1 +
>  tests/dnn/dnn-layer-mathbinary-test.c   |  5 +
>  tools/python/convert_from_tensorflow.py |  2 +-
>  tools/python/convert_header.py  |  2 +-
>  5 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> index dd42c329a9..6876aaf2c6 100644
> --- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> +++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
> @@ -175,6 +175,23 @@ int dnn_execute_layer_math_binary(DnnOperand
> *operands, const int32_t *input_ope
>  }
>  }
>  return 0;
> +case DMBO_FLOORMOD:
> +if (params->input0_broadcast) {
> +for (int i = 0; i < dims_count; ++i) {
> +dst[i] = (int)(params->v) % (int)(src[i]);
> +}
> +} else if (params->input1_broadcast) {
> +for (int i = 0; i < dims_count; ++i) {
> +dst[i] = (int)(src[i]) % (int)(params->v);
> +}
> +} else {
> +const DnnOperand *input1 = &operands[input_operand_indexes[1]];
> +const float *src1 = input1->data;
> +for (int i = 0; i < dims_count; ++i) {
> +dst[i] = (int)(src[i]) % (int)(src1[i]);
> +}
> +}
Nearly same code as DMBO_SUB.
Only the op is different, how about define a function pass op as a inline 
function.

> +return 0;
>  default:
>  return -1;
>  }
> diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h
> b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h
> index 0acf3b0ea0..9525685afa 100644
> --- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h
> +++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.h
> @@ -36,6 +36,7 @@ typedef enum {
>  DMBO_MUL = 2,
>  DMBO_REALDIV = 3,
>  DMBO_MINIMUM = 4,
> +DMBO_FLOORMOD = 5,
>  DMBO_COUNT
>  } DNNMathBinaryOperation;
> 
> diff --git a/tests/dnn/dnn-layer-mathbinary-test.c b/tests/dnn/dnn-layer-
> mathbinary-test.c
> index e7f8f8557c..e5f6a12939 100644
> --- a/tests/dnn/dnn-layer-mathbinary-test.c
> +++ b/tests/dnn/dnn-layer-mathbinary-test.c
> @@ -40,6 +40,8 @@ static float get_expected(float f1, float f2,
> DNNMathBinaryOperation op)
>  return f1 / f2;
>  case DMBO_MINIMUM:
>  return (f1 < f2) ? f1 : f2;
> +case DMBO_FLOORMOD:
> +return (int)(f1) % (int)(f2);
>  default:
>  av_assert0(!"not supported yet");
>  return 0.f;
> @@ -205,5 +207,8 @@ int main(int argc, char **argv)
>  if (test(DMBO_MINIMUM))
>  return 1;
> 
> +if (test(DMBO_FLOORMOD))
> +return 1;
> +
>  return 0;
>  }
> diff --git a/tools/python/convert_from_tensorflow.py
> b/tools/python/convert_from_tensorflow.py
> index 65fdbc5d43..2ed0f66829 100644
> --- a/tools/python/convert_from_tensorflow.py
> +++ b/tools/python/convert_from_tensorflow.py
> @@ -71,7 +71,7 @@ class TFConverter:
>  self.conv2d_scope_names = set()
>  self.conv2d_scopename_inputname_dict = {}
>  self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3, 
> 'Maximum':4,
> 'MathBinary':5, 'MathUnary':6}
> -self.mathbin2code = {'Sub':0, 'Add':1, 'Mul':2, 'RealDiv':3, 
> 'Minimum':4}
> +self.mathbin2code = {'Sub':0, 'Add':1, 'Mul':2, 'RealDiv':3,
> + 'Minimum':4, 'FloorMod':5}
>  self.mathun2code  = {'Abs':0, 'Sin':1, 'Cos':2, 'Tan':3, 'Asin':4,
>  'Acos':5, 'Atan':6, 'Sinh':7, 'Cosh':8, 'Tanh':9, 'Asinh':10,
>  'Acosh':11, 'Atanh':12, 'Ceil':13, 'Floor':14, 'Round':15} 
> diff --git
> a/tools/python/convert_header.py b/tools/python/convert_header.py index
> 747c8776eb..782a6341f9 100644
> --- a/tools/python/convert_header.py
> +++ b/tools/python/convert_header.py
> @@ -23,4 +23,4 @@ str = 'FFMPEGDNNNATIVE'
>  major = 1
> 
>  # increase minor when we don't have to re-convert the model file -minor = 21
> +minor = 22
> --
> 2.17.1
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v3] fate: av1dec, add test clip for low overhead obu

2020-08-13 Thread Xu Guangxin
v3 changelist: add missed tests/ref/fate/av1-low-overhead-demux

---
 tests/fate/demux.mak  |  3 +++
 tests/ref/fate/av1-low-overhead-demux | 16 
 2 files changed, 19 insertions(+)
 create mode 100644 tests/ref/fate/av1-low-overhead-demux

diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index 9f3a6be276..763452a533 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -13,6 +13,9 @@ fate-aea-demux: CMD = crc -i $(TARGET_SAMPLES)/aea/chirp.aea 
-c:a copy
 FATE_SAMPLES_DEMUX-$(CONFIG_AV1_DEMUXER) += fate-av1-annexb-demux
 fate-av1-annexb-demux: CMD = framecrc -i $(TARGET_SAMPLES)/av1/annexb.obu -c:v 
copy
 
+FATE_SAMPLES_DEMUX-$(CONFIG_AV1_DEMUXER) += fate-av1-low-overhead-demux
+fate-av1-low-overhead-demux: CMD = framecrc -i 
$(TARGET_SAMPLES)/av1/low_overhead.obu -c:v copy
+
 FATE_SAMPLES_DEMUX-$(CONFIG_AST_DEMUXER) += fate-ast
 fate-ast: CMD = crc -i $(TARGET_SAMPLES)/ast/demo11_02_partial.ast -c copy
 
diff --git a/tests/ref/fate/av1-low-overhead-demux 
b/tests/ref/fate/av1-low-overhead-demux
new file mode 100644
index 00..62635bba89
--- /dev/null
+++ b/tests/ref/fate/av1-low-overhead-demux
@@ -0,0 +1,16 @@
+#extradata 0:   13, 0x12ed043e
+#tb 0: 1/120
+#media_type 0: video
+#codec_id 0: av1
+#dimensions 0: 176x144
+#sar 0: 0/1
+0,  0,  0,48000, 9106, 0x09d4b5fe
+0,  48000,  48000,48000,10218, 0xafe5dad1, F=0x0
+0,  96000,  96000,48000,5, 0x016200e5, F=0x0
+0, 144000, 144000,48000,  697, 0x96cb5a52, F=0x0
+0, 192000, 192000,48000,5, 0x015200d5, F=0x0
+0, 24, 24,48000, 2000, 0x34b2ea8e, F=0x0
+0, 288000, 288000,48000,5, 0x01920115, F=0x0
+0, 336000, 336000,48000,  836, 0x8a1b9294, F=0x0
+0, 384000, 384000,48000,  761, 0x407a72d4, F=0x0
+0, 432000, 432000,48000,   27, 0x4bde0706, F=0x0
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3 2/3] avormat/av1dec: add low-overhead bitstream format

2020-08-13 Thread Xu, Guangxin
Hi Martin, 
Thanks for your detailed explaining. 
It's a good education to me. 

thanks

> -Original Message-
> From: ffmpeg-devel  On Behalf Of Martin
> Storsjö
> Sent: Friday, August 14, 2020 3:25 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v3 2/3] avormat/av1dec: add low-
> overhead bitstream format
> 
> On Thu, 13 Aug 2020, James Almer wrote:
> 
> > On 8/13/2020 3:51 AM, Xu Guangxin wrote:
> 
> >> +
> >> +ret = obu_prefetch(s, header, MAX_OBU_HEADER_SIZE);
> >> +if (!ret)
> >> +return AVERROR(EOF);
> >
> > We use AVERROR_EOF rather than AVERROR(EOF) (Afair, it was done
> > because EOF is not portable, but don't quote me on it).
> 
> Actually, it's a more severe thing than that.
> 
> AVERROR() is used for mapping an errno style error code, EINVAL etc, which can
> be either positive or negative numbers depending on platforms, to the AVERROR
> range (which is negative numbers).
> 
> So AVERROR() actually is shorthand for ERRNO_CODE_TO_AVERROR(). On
> platforms where errno codes are positive (most common modern platforms
> except BeOS/Haiku, iirc), it's essentially defined as (-(x)).
> 
> Now EOF isn't an errno error code, and is defined to be a negative value 
> (often -
> 1). So if you do AVERROR(EOF) on a system where errno codes are positive,
> AVERROR(EOF) evalues to +1, which most caller would identify as not an error
> at all.
> 
> TL;DR: AVERROR(EOF) is never correct.
> 
> // Martin
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3 2/3] avormat/av1dec: add low-overhead bitstream format

2020-08-13 Thread Xu, Guangxin
> Should be good with those trivial changes, so i can implement them and push if
> you don't want to send another revision.
>
Great! thanks for you kindly help on this and previous review.
Really appreciate it.

> -Original Message-
> From: ffmpeg-devel  On Behalf Of James
> Almer
> Sent: Friday, August 14, 2020 3:11 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3 2/3] avormat/av1dec: add low-
> overhead bitstream format
> 
> On 8/13/2020 3:51 AM, Xu Guangxin wrote:
> > Hi James,
> > thanks for your feedback, please help review it again.
> >
> > Changelist for v3:
> >   use av_fifo_* instead of homebrewed fifo operations
> >   obu_probe(), add padding obu to alllow list
> >   read_header(), use "const AVRational* framerate" instead of "AVRational
> framerate"
> >
> >
> >
> > It's defined in Section 5.2, used by netflix.
> > see http://download.opencontent.netflix.com/?prefix=AV1/Chimera/
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/av1dec.c | 263 +++--
> --
> >  3 files changed, 242 insertions(+), 23 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 8de1afcb99..d4a1fea9ce 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3331,6 +3331,7 @@ mxf_d10_muxer_select="mxf_muxer"
> >  mxf_opatom_muxer_select="mxf_muxer"
> >  nut_muxer_select="riffenc"
> >  nuv_demuxer_select="riffdec"
> > +obu_demuxer_select="av1_frame_merge_bsf av1_parser"
> >  oga_muxer_select="ogg_muxer"
> >  ogg_demuxer_select="dirac_parse"
> >  ogv_muxer_select="ogg_muxer"
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c index
> > b7e59ae170..0aa9dd7198 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -293,6 +293,7 @@ extern AVOutputFormat ff_null_muxer;  extern
> > AVInputFormat  ff_nut_demuxer;  extern AVOutputFormat ff_nut_muxer;
> > extern AVInputFormat  ff_nuv_demuxer;
> > +extern AVInputFormat  ff_obu_demuxer;
> >  extern AVOutputFormat ff_oga_muxer;
> >  extern AVInputFormat  ff_ogg_demuxer;  extern AVOutputFormat
> > ff_ogg_muxer; diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
> > index 1be2fac1c1..62cf5c31ea 100644
> > --- a/libavformat/av1dec.c
> > +++ b/libavformat/av1dec.c
> > @@ -22,6 +22,7 @@
> >  #include "config.h"
> >
> >  #include "libavutil/common.h"
> > +#include "libavutil/fifo.h"
> >  #include "libavutil/opt.h"
> >  #include "libavcodec/av1_parse.h"
> >  #include "avformat.h"
> > @@ -70,6 +71,25 @@ static int read_obu(const uint8_t *buf, int size, int64_t
> *obu_size, int *type)
> >  return 0;
> >  }
> >
> > +//return < 0 if we need more data
> > +static int get_score(int type, int *seq) {
> > +switch (type) {
> > +case AV1_OBU_SEQUENCE_HEADER:
> > +*seq = 1;
> > +return -1;
> > +case AV1_OBU_FRAME:
> > +case AV1_OBU_FRAME_HEADER:
> > +return *seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
> > +case AV1_OBU_METADATA:
> > +case AV1_OBU_PADDING:
> > +return -1;
> > +default:
> > +break;
> > +}
> > +return 0;
> > +}
> > +
> >  static int annexb_probe(const AVProbeData *p)  {
> >  AVIOContext pb;
> > @@ -123,19 +143,9 @@ static int annexb_probe(const AVProbeData *p)
> >  return 0;
> >  cnt += obu_unit_size;
> >
> > -switch (type) {
> > -case AV1_OBU_SEQUENCE_HEADER:
> > -seq = 1;
> > -break;
> > -case AV1_OBU_FRAME:
> > -case AV1_OBU_FRAME_HEADER:
> > -return seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
> > -case AV1_OBU_TILE_GROUP:
> > -case AV1_OBU_TEMPORAL_DELIMITER:
> > -return 0;
> > -default:
> > -break;
> > -}
> > +ret = get_score(type, &seq);
> > +if (ret >= 0)
> > +return ret;
> >
> >  temporal_unit_size -= obu_unit_size + ret;
> >  frame_unit_size -= obu_unit_size + ret; @@ -144,15 +154,14 @@
> > static int annexb_probe(const AVProbeData *p)
> >  return 0;
> >  }
> >
> > -static int annexb_read_header(AVFormatContext 

[FFmpeg-devel] [PATCH v3 2/3] avormat/av1dec: add low-overhead bitstream format

2020-08-12 Thread Xu Guangxin
Hi James,
thanks for your feedback, please help review it again.

Changelist for v3:
  use av_fifo_* instead of homebrewed fifo operations
  obu_probe(), add padding obu to alllow list
  read_header(), use "const AVRational* framerate" instead of "AVRational 
framerate"

  

It's defined in Section 5.2, used by netflix.
see http://download.opencontent.netflix.com/?prefix=AV1/Chimera/
---
 configure|   1 +
 libavformat/allformats.c |   1 +
 libavformat/av1dec.c | 263 +++
 3 files changed, 242 insertions(+), 23 deletions(-)

diff --git a/configure b/configure
index 8de1afcb99..d4a1fea9ce 100755
--- a/configure
+++ b/configure
@@ -3331,6 +3331,7 @@ mxf_d10_muxer_select="mxf_muxer"
 mxf_opatom_muxer_select="mxf_muxer"
 nut_muxer_select="riffenc"
 nuv_demuxer_select="riffdec"
+obu_demuxer_select="av1_frame_merge_bsf av1_parser"
 oga_muxer_select="ogg_muxer"
 ogg_demuxer_select="dirac_parse"
 ogv_muxer_select="ogg_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index b7e59ae170..0aa9dd7198 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -293,6 +293,7 @@ extern AVOutputFormat ff_null_muxer;
 extern AVInputFormat  ff_nut_demuxer;
 extern AVOutputFormat ff_nut_muxer;
 extern AVInputFormat  ff_nuv_demuxer;
+extern AVInputFormat  ff_obu_demuxer;
 extern AVOutputFormat ff_oga_muxer;
 extern AVInputFormat  ff_ogg_demuxer;
 extern AVOutputFormat ff_ogg_muxer;
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 1be2fac1c1..62cf5c31ea 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -22,6 +22,7 @@
 #include "config.h"
 
 #include "libavutil/common.h"
+#include "libavutil/fifo.h"
 #include "libavutil/opt.h"
 #include "libavcodec/av1_parse.h"
 #include "avformat.h"
@@ -70,6 +71,25 @@ static int read_obu(const uint8_t *buf, int size, int64_t 
*obu_size, int *type)
 return 0;
 }
 
+//return < 0 if we need more data
+static int get_score(int type, int *seq)
+{
+switch (type) {
+case AV1_OBU_SEQUENCE_HEADER:
+*seq = 1;
+return -1;
+case AV1_OBU_FRAME:
+case AV1_OBU_FRAME_HEADER:
+return *seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
+case AV1_OBU_METADATA:
+case AV1_OBU_PADDING:
+return -1;
+default:
+break;
+}
+return 0;
+}
+
 static int annexb_probe(const AVProbeData *p)
 {
 AVIOContext pb;
@@ -123,19 +143,9 @@ static int annexb_probe(const AVProbeData *p)
 return 0;
 cnt += obu_unit_size;
 
-switch (type) {
-case AV1_OBU_SEQUENCE_HEADER:
-seq = 1;
-break;
-case AV1_OBU_FRAME:
-case AV1_OBU_FRAME_HEADER:
-return seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
-case AV1_OBU_TILE_GROUP:
-case AV1_OBU_TEMPORAL_DELIMITER:
-return 0;
-default:
-break;
-}
+ret = get_score(type, &seq);
+if (ret >= 0)
+return ret;
 
 temporal_unit_size -= obu_unit_size + ret;
 frame_unit_size -= obu_unit_size + ret;
@@ -144,15 +154,14 @@ static int annexb_probe(const AVProbeData *p)
 return 0;
 }
 
-static int annexb_read_header(AVFormatContext *s)
+static int read_header(AVFormatContext *s, const AVRational *framerate, 
AVBSFContext **bsf, void *logctx)
 {
-AnnexBContext *c = s->priv_data;
 const AVBitStreamFilter *filter = av_bsf_get_by_name("av1_frame_merge");
 AVStream *st;
 int ret;
 
 if (!filter) {
-av_log(c, AV_LOG_ERROR, "av1_frame_merge bitstream filter "
+av_log(logctx, AV_LOG_ERROR, "av1_frame_merge bitstream filter "
"not found. This is a bug, please report it.\n");
 return AVERROR_BUG;
 }
@@ -165,25 +174,32 @@ static int annexb_read_header(AVFormatContext *s)
 st->codecpar->codec_id = AV_CODEC_ID_AV1;
 st->need_parsing = AVSTREAM_PARSE_HEADERS;
 
-st->internal->avctx->framerate = c->framerate;
+st->internal->avctx->framerate = *framerate;
 // taken from rawvideo demuxers
 avpriv_set_pts_info(st, 64, 1, 120);
 
-ret = av_bsf_alloc(filter, &c->bsf);
+ret = av_bsf_alloc(filter, bsf);
 if (ret < 0)
 return ret;
 
-ret = avcodec_parameters_copy(c->bsf->par_in, st->codecpar);
+ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
 if (ret < 0) {
-av_bsf_free(&c->bsf);
+av_bsf_free(bsf);
 return ret;
 }
 
-ret = av_bsf_init(c->bsf);
+ret = av_bsf_init(*bsf);
 if (ret < 0)
-av_bsf_free(&c->bsf);
+av_bsf_free(bsf);
 
 return ret;
+
+}
+
+static int annexb_read_header(AVFormatContext *s)
+{
+AnnexBContext *c = s->priv_data;
+return read_header(s, &c->framerate, &c->bsf, c);
 }
 
 static int annexb_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -251,12 +267,193 @@ static int annexb_read_close(AVFormatContext *s)
 return 0;
 }
 
-#define OFFSET(x) offsetof(AnnexBC

Re: [FFmpeg-devel] [PATCH V2 2/3] avormat/av1dec: add low-overhead bitstream format

2020-08-12 Thread Xu, Guangxin

Hi James, 
Thanks for the review.
Comment in line.

> -Original Message-
> From: ffmpeg-devel  On Behalf Of James
> Almer
> Sent: Wednesday, August 12, 2020 9:06 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH V2 2/3] avormat/av1dec: add low-
> overhead bitstream format
> 
> On 8/10/2020 6:34 AM, Xu Guangxin wrote:
> > It's defined in Section 5.2, used by netflix.
> > see http://download.opencontent.netflix.com/?prefix=AV1/Chimera/
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/av1dec.c | 266 +++--
> --
> >  3 files changed, 245 insertions(+), 23 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 8de1afcb99..d4a1fea9ce 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3331,6 +3331,7 @@ mxf_d10_muxer_select="mxf_muxer"
> >  mxf_opatom_muxer_select="mxf_muxer"
> >  nut_muxer_select="riffenc"
> >  nuv_demuxer_select="riffdec"
> > +obu_demuxer_select="av1_frame_merge_bsf av1_parser"
> >  oga_muxer_select="ogg_muxer"
> >  ogg_demuxer_select="dirac_parse"
> >  ogv_muxer_select="ogg_muxer"
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c index
> > b7e59ae170..0aa9dd7198 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -293,6 +293,7 @@ extern AVOutputFormat ff_null_muxer;  extern
> > AVInputFormat  ff_nut_demuxer;  extern AVOutputFormat ff_nut_muxer;
> > extern AVInputFormat  ff_nuv_demuxer;
> > +extern AVInputFormat  ff_obu_demuxer;
> >  extern AVOutputFormat ff_oga_muxer;
> >  extern AVInputFormat  ff_ogg_demuxer;  extern AVOutputFormat
> > ff_ogg_muxer; diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
> > index 1be2fac1c1..14efb8f1d4 100644
> > --- a/libavformat/av1dec.c
> > +++ b/libavformat/av1dec.c
> > @@ -70,6 +70,24 @@ static int read_obu(const uint8_t *buf, int size, int64_t
> *obu_size, int *type)
> >  return 0;
> >  }
> >
> > +//return < 0 if we need more data
> > +static int get_score(int type, int *seq) {
> > +switch (type) {
> > +case AV1_OBU_SEQUENCE_HEADER:
> > +*seq = 1;
> > +return -1;
> > +case AV1_OBU_FRAME:
> > +case AV1_OBU_FRAME_HEADER:
> > +return *seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
> > +case AV1_OBU_METADATA:
> > +return -1;
> > +default:
> > +break;
> 
> Padding OBU should be ignored/skipped, same as Metadata. This function
> should make the caller abort only for OBUs that are not meant to appear before
> a Frame/Frame Header (Tile list, Tile Group, Redundant Frame Header, another
> Temporal Delimiter).
Sure, I will add padding to allow list.

> 
> > +}
> > +return 0;
> > +}
> > +
> >  static int annexb_probe(const AVProbeData *p)  {
> >  AVIOContext pb;
> > @@ -123,19 +141,9 @@ static int annexb_probe(const AVProbeData *p)
> >  return 0;
> >  cnt += obu_unit_size;
> >
> > -switch (type) {
> > -case AV1_OBU_SEQUENCE_HEADER:
> > -seq = 1;
> > -break;
> > -case AV1_OBU_FRAME:
> > -case AV1_OBU_FRAME_HEADER:
> > -return seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
> > -case AV1_OBU_TILE_GROUP:
> > -case AV1_OBU_TEMPORAL_DELIMITER:
> > -return 0;
> > -default:
> > -break;
> > -}
> > +ret = get_score(type, &seq);
> > +if (ret >= 0)
> > +return ret;
> >
> >  temporal_unit_size -= obu_unit_size + ret;
> >  frame_unit_size -= obu_unit_size + ret; @@ -144,15 +152,14 @@
> > static int annexb_probe(const AVProbeData *p)
> >  return 0;
> >  }
> >
> > -static int annexb_read_header(AVFormatContext *s)
> > +static int read_header(AVFormatContext *s, AVRational framerate,
> > +AVBSFContext **bsf, void *logctx)
> 
> Nit: Maybe a pointer to framerate instead.
I will change to 
const AVRational* framerate

> 
> >  {
> > -AnnexBContext *c = s->priv_data;
> >  const AVBitStreamFilter *filter =
> av_bsf_get_by_name("av1_frame_merge");
> >  AVStream *st;
> >  int ret;
> >
> >  if (!filter) {
> > -av_log(c, AV_LOG_ERROR, "av1_frame_merge bitstream filter "
> > +av_

Re: [FFmpeg-devel] [PATCH V2 0/3] avformat/av1dec: add low overhead obu demux

2020-08-11 Thread Xu, Guangxin
Hi James,
All issues addressed. Could you help review it again?
Thanks for you great help on this.

> -Original Message-
> From: Xu, Guangxin 
> Sent: Monday, August 10, 2020 5:34 PM
> To: ffmpeg-devel@ffmpeg.org; jamr...@gmail.com
> Cc: Xu, Guangxin 
> Subject: [PATCH V2 0/3] avformat/av1dec: add low overhead obu demux
> 
> take following addvices from James:
>   Handle meta data before seq and frame in obu_probe
>   Use read_obu_with_size instead of change parse_obu_header
>   Use memmove instead of memcpy in obu_read_data
>   Add "av1_frame_merge_bsf av1_parser" as dependency to configure.
>   Change name from "av1" to "obu".
>   Change demux name to  ff_obu_demuxer
>   Use MAX_OBU_HEADER_SIZE instead MAX_HEADER_SIZE
>   Rename log context c to logctx.
> 
> Xu Guangxin (3):
>   av1_parse: refact, use macro for MAX_OBU_HEADER_SIZE
>   avormat/av1dec: add low-overhead bitstream format
>   fate: av1dec, add test clip for low overhead obu
> 
>  configure|   1 +
>  libavcodec/av1_parse.h   |   5 +-
>  libavformat/allformats.c |   1 +
>  libavformat/av1dec.c | 266 +++
>  tests/fate/demux.mak |   3 +
>  5 files changed, 252 insertions(+), 24 deletions(-)
> 
> --
> 2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH V2 2/3] avormat/av1dec: add low-overhead bitstream format

2020-08-10 Thread Xu Guangxin
It's defined in Section 5.2, used by netflix.
see http://download.opencontent.netflix.com/?prefix=AV1/Chimera/
---
 configure|   1 +
 libavformat/allformats.c |   1 +
 libavformat/av1dec.c | 266 +++
 3 files changed, 245 insertions(+), 23 deletions(-)

diff --git a/configure b/configure
index 8de1afcb99..d4a1fea9ce 100755
--- a/configure
+++ b/configure
@@ -3331,6 +3331,7 @@ mxf_d10_muxer_select="mxf_muxer"
 mxf_opatom_muxer_select="mxf_muxer"
 nut_muxer_select="riffenc"
 nuv_demuxer_select="riffdec"
+obu_demuxer_select="av1_frame_merge_bsf av1_parser"
 oga_muxer_select="ogg_muxer"
 ogg_demuxer_select="dirac_parse"
 ogv_muxer_select="ogg_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index b7e59ae170..0aa9dd7198 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -293,6 +293,7 @@ extern AVOutputFormat ff_null_muxer;
 extern AVInputFormat  ff_nut_demuxer;
 extern AVOutputFormat ff_nut_muxer;
 extern AVInputFormat  ff_nuv_demuxer;
+extern AVInputFormat  ff_obu_demuxer;
 extern AVOutputFormat ff_oga_muxer;
 extern AVInputFormat  ff_ogg_demuxer;
 extern AVOutputFormat ff_ogg_muxer;
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 1be2fac1c1..14efb8f1d4 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -70,6 +70,24 @@ static int read_obu(const uint8_t *buf, int size, int64_t 
*obu_size, int *type)
 return 0;
 }
 
+//return < 0 if we need more data
+static int get_score(int type, int *seq)
+{
+switch (type) {
+case AV1_OBU_SEQUENCE_HEADER:
+*seq = 1;
+return -1;
+case AV1_OBU_FRAME:
+case AV1_OBU_FRAME_HEADER:
+return *seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
+case AV1_OBU_METADATA:
+return -1;
+default:
+break;
+}
+return 0;
+}
+
 static int annexb_probe(const AVProbeData *p)
 {
 AVIOContext pb;
@@ -123,19 +141,9 @@ static int annexb_probe(const AVProbeData *p)
 return 0;
 cnt += obu_unit_size;
 
-switch (type) {
-case AV1_OBU_SEQUENCE_HEADER:
-seq = 1;
-break;
-case AV1_OBU_FRAME:
-case AV1_OBU_FRAME_HEADER:
-return seq ? AVPROBE_SCORE_EXTENSION + 1 : 0;
-case AV1_OBU_TILE_GROUP:
-case AV1_OBU_TEMPORAL_DELIMITER:
-return 0;
-default:
-break;
-}
+ret = get_score(type, &seq);
+if (ret >= 0)
+return ret;
 
 temporal_unit_size -= obu_unit_size + ret;
 frame_unit_size -= obu_unit_size + ret;
@@ -144,15 +152,14 @@ static int annexb_probe(const AVProbeData *p)
 return 0;
 }
 
-static int annexb_read_header(AVFormatContext *s)
+static int read_header(AVFormatContext *s, AVRational framerate, AVBSFContext 
**bsf, void *logctx)
 {
-AnnexBContext *c = s->priv_data;
 const AVBitStreamFilter *filter = av_bsf_get_by_name("av1_frame_merge");
 AVStream *st;
 int ret;
 
 if (!filter) {
-av_log(c, AV_LOG_ERROR, "av1_frame_merge bitstream filter "
+av_log(logctx, AV_LOG_ERROR, "av1_frame_merge bitstream filter "
"not found. This is a bug, please report it.\n");
 return AVERROR_BUG;
 }
@@ -165,25 +172,32 @@ static int annexb_read_header(AVFormatContext *s)
 st->codecpar->codec_id = AV_CODEC_ID_AV1;
 st->need_parsing = AVSTREAM_PARSE_HEADERS;
 
-st->internal->avctx->framerate = c->framerate;
+st->internal->avctx->framerate = framerate;
 // taken from rawvideo demuxers
 avpriv_set_pts_info(st, 64, 1, 120);
 
-ret = av_bsf_alloc(filter, &c->bsf);
+ret = av_bsf_alloc(filter, bsf);
 if (ret < 0)
 return ret;
 
-ret = avcodec_parameters_copy(c->bsf->par_in, st->codecpar);
+ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
 if (ret < 0) {
-av_bsf_free(&c->bsf);
+av_bsf_free(bsf);
 return ret;
 }
 
-ret = av_bsf_init(c->bsf);
+ret = av_bsf_init(*bsf);
 if (ret < 0)
-av_bsf_free(&c->bsf);
+av_bsf_free(bsf);
 
 return ret;
+
+}
+
+static int annexb_read_header(AVFormatContext *s)
+{
+AnnexBContext *c = s->priv_data;
+return read_header(s, c->framerate, &c->bsf, c);
 }
 
 static int annexb_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -251,12 +265,198 @@ static int annexb_read_close(AVFormatContext *s)
 return 0;
 }
 
-#define OFFSET(x) offsetof(AnnexBContext, x)
+typedef struct ObuContext {
+const AVClass *class;
+AVBSFContext *bsf;
+AVRational framerate;
+uint8_t prefetched[MAX_OBU_HEADER_SIZE];
+//prefetched len
+int len;
+} ObuContext;
+
+//For low overhead obu, we can't foresee the obu size before we parsed the 
header.
+//So, we can't use parse_obu_header here, since it will check size <= buf_size
+//see c27c7b49dc for more details
+static int read_obu_with_size(const uint8_t *buf, int buf_size, int64_t 
*obu_siz

[FFmpeg-devel] [PATCH V2 3/3] fate: av1dec, add test clip for low overhead obu

2020-08-10 Thread Xu Guangxin
---
 tests/fate/demux.mak | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index 9f3a6be276..763452a533 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -13,6 +13,9 @@ fate-aea-demux: CMD = crc -i $(TARGET_SAMPLES)/aea/chirp.aea 
-c:a copy
 FATE_SAMPLES_DEMUX-$(CONFIG_AV1_DEMUXER) += fate-av1-annexb-demux
 fate-av1-annexb-demux: CMD = framecrc -i $(TARGET_SAMPLES)/av1/annexb.obu -c:v 
copy
 
+FATE_SAMPLES_DEMUX-$(CONFIG_AV1_DEMUXER) += fate-av1-low-overhead-demux
+fate-av1-low-overhead-demux: CMD = framecrc -i 
$(TARGET_SAMPLES)/av1/low_overhead.obu -c:v copy
+
 FATE_SAMPLES_DEMUX-$(CONFIG_AST_DEMUXER) += fate-ast
 fate-ast: CMD = crc -i $(TARGET_SAMPLES)/ast/demo11_02_partial.ast -c copy
 
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH V2 1/3] av1_parse: refact, use macro for MAX_OBU_HEADER_SIZE

2020-08-10 Thread Xu Guangxin
---
 libavcodec/av1_parse.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index 01bcd646c2..ae0ebb5a18 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -27,6 +27,9 @@
 #include "avcodec.h"
 #include "get_bits.h"
 
+// OBU header fields + max leb128 length
+#define MAX_OBU_HEADER_SIZE (2 + 8)
+
 typedef struct AV1OBU {
 /** Size of payload */
 int size;
@@ -105,7 +108,7 @@ static inline int parse_obu_header(const uint8_t *buf, int 
buf_size,
 int ret, extension_flag, has_size_flag;
 int64_t size;
 
-ret = init_get_bits8(&gb, buf, FFMIN(buf_size, 2 + 8)); // OBU header 
fields + max leb128 length
+ret = init_get_bits8(&gb, buf, FFMIN(buf_size, MAX_OBU_HEADER_SIZE));
 if (ret < 0)
 return ret;
 
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH V2 0/3] avformat/av1dec: add low overhead obu demux

2020-08-10 Thread Xu Guangxin
take following addvices from James:
  Handle meta data before seq and frame in obu_probe
  Use read_obu_with_size instead of change parse_obu_header
  Use memmove instead of memcpy in obu_read_data
  Add "av1_frame_merge_bsf av1_parser" as dependency to configure.
  Change name from "av1" to "obu".
  Change demux name to  ff_obu_demuxer
  Use MAX_OBU_HEADER_SIZE instead MAX_HEADER_SIZE
  Rename log context c to logctx.

Xu Guangxin (3):
  av1_parse: refact, use macro for MAX_OBU_HEADER_SIZE
  avormat/av1dec: add low-overhead bitstream format
  fate: av1dec, add test clip for low overhead obu

 configure|   1 +
 libavcodec/av1_parse.h   |   5 +-
 libavformat/allformats.c |   1 +
 libavformat/av1dec.c | 266 +++
 tests/fate/demux.mak |   3 +
 5 files changed, 252 insertions(+), 24 deletions(-)

-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/5] av1_parser: do not check buf_size if we have size in obu header

2020-08-06 Thread Xu, Guangxin

> -Original Message-
> From: ffmpeg-devel  On Behalf Of James
> Almer
> Sent: Friday, August 7, 2020 1:38 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 2/5] av1_parser: do not check buf_size if
> we have size in obu header
> 
> On 8/6/2020 12:15 PM, Xu, Guangxin wrote:
> > Hi James,
> > Thanks for the review.
> > How about we add a new function in av1dec.c like this:
> >
> > static inline int read_obu_header_with_size_flag(const uint8_t *buf, int
> buf_size,
> >int64_t *obu_size, int *type); then
> > we can remove first two patches and check has_size_flag in the function.
> 
> You mean duplicating the implementation of parse_obu_header() in av1dec.c?

Yes. if we do not duplicate code. it's hard to fix the issue you mentioned.
Low overhead obu can not foresee the obu size. it need get size from the header.

> 
> >
> > I guess "out of array reads" will not happen in low overhead obu, since it
> always prepare enough data the obu.
> >
> >
> >> -Original Message-
> >> From: ffmpeg-devel  On Behalf Of
> >> James Almer
> >> Sent: Thursday, August 6, 2020 10:03 PM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [PATCH 2/5] av1_parser: do not check
> >> buf_size if we have size in obu header
> >>
> >> On 8/6/2020 5:04 AM, Xu Guangxin wrote:
> >>> for low overhead obu, we can't forsee the obu size. we can only get
> >>> it when we parsed the obu header.
> >>> ---
> >>>  libavcodec/av1_parse.h | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h index
> >>> a3b39f039c..823bdedd5e 100644
> >>> --- a/libavcodec/av1_parse.h
> >>> +++ b/libavcodec/av1_parse.h
> >>> @@ -135,7 +135,7 @@ static inline int parse_obu_header(const uint8_t
> >>> *buf, int buf_size,
> >>>
> >>>  size = *obu_size + *start_pos;
> >>>
> >>> -if (size > buf_size)
> >>> +if (!*has_size_flag && size > buf_size)
> >>
> >> This check was added in c27c7b49dc to fix out of array reads, so this
> >> change will surely reintroduce the issue.
> >>
> >> Also, when has_size_flag is 0, size will never be bigger than
> >> buf_size because it will be derived from it, meaning this change is
> >> the same as removing the check altogether.
> >>
> >>>  return AVERROR_INVALIDDATA;
> >>>
> >>>  return size;
> >>>
> >>
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> >
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 4/5] avormat/av1dec: add low-overhead bitstream format

2020-08-06 Thread Xu, Guangxin


> -Original Message-
> From: ffmpeg-devel  On Behalf Of James
> Almer
> Sent: Thursday, August 6, 2020 10:09 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 4/5] avormat/av1dec: add low-overhead
> bitstream format
> 
> On 8/6/2020 5:04 AM, Xu Guangxin wrote:
> > It's defined in Section 5.2, used by netflix.
> > see http://download.opencontent.netflix.com/?prefix=AV1/Chimera/
> > ---
> >  libavformat/allformats.c |   1 +
> >  libavformat/av1dec.c | 193
> +--
> >  2 files changed, 185 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c index
> > fd9e46e233..8eead5619d 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -75,6 +75,7 @@ extern AVOutputFormat ff_asf_stream_muxer;  extern
> > AVInputFormat  ff_au_demuxer;  extern AVOutputFormat ff_au_muxer;
> > extern AVInputFormat  ff_av1_demuxer;
> > +extern AVInputFormat  ff_av1_low_overhead_demuxer;
> 
> How about ff_obu_demuxer instead?
> 
> >  extern AVInputFormat  ff_avi_demuxer;  extern AVOutputFormat
> > ff_avi_muxer;  extern AVInputFormat  ff_avisynth_demuxer; diff --git
> > a/libavformat/av1dec.c b/libavformat/av1dec.c index
> > ec66152e03..0c5d172a0f 100644
> > --- a/libavformat/av1dec.c
> > +++ b/libavformat/av1dec.c
> > @@ -28,6 +28,9 @@
> >  #include "avio_internal.h"
> >  #include "internal.h"
> >
> > +//2 + max leb 128 size
> > +#define MAX_HEAD_SIZE 10
> 
> This value is also used in av1_parse.h, so you could put it there and reuse 
> it. But
> if you do, use a less generic name, like MAX_OBU_HEADER_SIZE.
> 
> > +
> >  typedef struct AnnexBContext {
> >  const AVClass *class;
> >  AVBSFContext *bsf;
> > @@ -139,9 +142,8 @@ static int annexb_probe(const AVProbeData *p)
> >  return 0;
> >  }
> >
> > -static int annexb_read_header(AVFormatContext *s)
> > +static int read_header(AVFormatContext *s, AVRational framerate,
> > +AVBSFContext **bsf, void *c)
> 
> Since c is now a log context, rename it to logctx.
> 
> >  {
> > -AnnexBContext *c = s->priv_data;
> >  const AVBitStreamFilter *filter =
> av_bsf_get_by_name("av1_frame_merge");
> >  AVStream *st;
> >  int ret;
> > @@ -160,25 +162,32 @@ static int annexb_read_header(AVFormatContext
> *s)
> >  st->codecpar->codec_id = AV_CODEC_ID_AV1;
> >  st->need_parsing = AVSTREAM_PARSE_HEADERS;
> >
> > -st->internal->avctx->framerate = c->framerate;
> > +st->internal->avctx->framerate = framerate;
> >  // taken from rawvideo demuxers
> >  avpriv_set_pts_info(st, 64, 1, 120);
> >
> > -ret = av_bsf_alloc(filter, &c->bsf);
> > +ret = av_bsf_alloc(filter, bsf);
> 
> If it requires this bsf, then it should be added as a depencency to configure.
Could you explain more about this.
The entire function is from original code, I just changed some signature.
thanks

> 
> >  if (ret < 0)
> >  return ret;
> >
> > -ret = avcodec_parameters_copy(c->bsf->par_in, st->codecpar);
> > +ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
> >  if (ret < 0) {
> > -av_bsf_free(&c->bsf);
> > +av_bsf_free(bsf);
> >  return ret;
> >  }
> >
> > -ret = av_bsf_init(c->bsf);
> > +ret = av_bsf_init(*bsf);
> >  if (ret < 0)
> > -av_bsf_free(&c->bsf);
> > +av_bsf_free(bsf);
> >
> >  return ret;
> > +
> > +}
> > +
> > +static int annexb_read_header(AVFormatContext *s) {
> > +AnnexBContext *c = s->priv_data;
> > +return read_header(s, c->framerate, &c->bsf, c);
> >  }
> >
> >  static int annexb_read_packet(AVFormatContext *s, AVPacket *pkt) @@
> > -246,12 +255,158 @@ static int annexb_read_close(AVFormatContext *s)
> >  return 0;
> >  }
> >
> > -#define OFFSET(x) offsetof(AnnexBContext, x)
> > +typedef struct LowOverheadContext {
> > +const AVClass *class;
> > +AVBSFContext *bsf;
> > +AVRational framerate;
> > +uint8_t prefetched[MAX_HEAD_SIZE];
> > +//prefetched len
> > +int len;
> > +} LowOverheadContext;
> > +
> > +static int low_overhead_probe(const AVProbeData *p) {
> > +AVIOContext pb;
> > +int64_t obu_siz

Re: [FFmpeg-devel] [PATCH 4/5] avormat/av1dec: add low-overhead bitstream format

2020-08-06 Thread Xu, Guangxin
Hi James,
Comment inline.

> -Original Message-
> From: ffmpeg-devel  On Behalf Of James
> Almer
> Sent: Thursday, August 6, 2020 10:09 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 4/5] avormat/av1dec: add low-overhead
> bitstream format
> 
> On 8/6/2020 5:04 AM, Xu Guangxin wrote:
> > It's defined in Section 5.2, used by netflix.
> > see http://download.opencontent.netflix.com/?prefix=AV1/Chimera/
> > ---
> >  libavformat/allformats.c |   1 +
> >  libavformat/av1dec.c | 193
> +--
> >  2 files changed, 185 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c index
> > fd9e46e233..8eead5619d 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -75,6 +75,7 @@ extern AVOutputFormat ff_asf_stream_muxer;  extern
> > AVInputFormat  ff_au_demuxer;  extern AVOutputFormat ff_au_muxer;
> > extern AVInputFormat  ff_av1_demuxer;
> > +extern AVInputFormat  ff_av1_low_overhead_demuxer;
> 
> How about ff_obu_demuxer instead?
You have a good taste:).
Yes the original name is ff_obu_demuxer, I change it to this before the I send 
to review.
I will change it back. I guess you also suggest I change all low_overhead 
things in av1dec.c to obu. Right?

> 
> >  extern AVInputFormat  ff_avi_demuxer;  extern AVOutputFormat
> > ff_avi_muxer;  extern AVInputFormat  ff_avisynth_demuxer; diff --git
> > a/libavformat/av1dec.c b/libavformat/av1dec.c index
> > ec66152e03..0c5d172a0f 100644
> > --- a/libavformat/av1dec.c
> > +++ b/libavformat/av1dec.c
> > @@ -28,6 +28,9 @@
> >  #include "avio_internal.h"
> >  #include "internal.h"
> >
> > +//2 + max leb 128 size
> > +#define MAX_HEAD_SIZE 10
> 
> This value is also used in av1_parse.h, so you could put it there and reuse 
> it. But
> if you do, use a less generic name, like MAX_OBU_HEADER_SIZE.
> 
Sure. 

> > +
> >  typedef struct AnnexBContext {
> >  const AVClass *class;
> >  AVBSFContext *bsf;
> > @@ -139,9 +142,8 @@ static int annexb_probe(const AVProbeData *p)
> >  return 0;
> >  }
> >
> > -static int annexb_read_header(AVFormatContext *s)
> > +static int read_header(AVFormatContext *s, AVRational framerate,
> > +AVBSFContext **bsf, void *c)
> 
> Since c is now a log context, rename it to logctx.
> 
Sure.


> >  {
> > -AnnexBContext *c = s->priv_data;
> >  const AVBitStreamFilter *filter =
> av_bsf_get_by_name("av1_frame_merge");
> >  AVStream *st;
> >  int ret;
> > @@ -160,25 +162,32 @@ static int annexb_read_header(AVFormatContext
> *s)
> >  st->codecpar->codec_id = AV_CODEC_ID_AV1;
> >  st->need_parsing = AVSTREAM_PARSE_HEADERS;
> >
> > -st->internal->avctx->framerate = c->framerate;
> > +st->internal->avctx->framerate = framerate;
> >  // taken from rawvideo demuxers
> >  avpriv_set_pts_info(st, 64, 1, 120);
> >
> > -ret = av_bsf_alloc(filter, &c->bsf);
> > +ret = av_bsf_alloc(filter, bsf);
> 
> If it requires this bsf, then it should be added as a depencency to configure.
> 
> >  if (ret < 0)
> >  return ret;
> >
> > -ret = avcodec_parameters_copy(c->bsf->par_in, st->codecpar);
> > +ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
> >  if (ret < 0) {
> > -av_bsf_free(&c->bsf);
> > +av_bsf_free(bsf);
> >  return ret;
> >  }
> >
> > -ret = av_bsf_init(c->bsf);
> > +ret = av_bsf_init(*bsf);
> >  if (ret < 0)
> > -av_bsf_free(&c->bsf);
> > +av_bsf_free(bsf);
> >
> >  return ret;
> > +
> > +}
> > +
> > +static int annexb_read_header(AVFormatContext *s) {
> > +AnnexBContext *c = s->priv_data;
> > +return read_header(s, c->framerate, &c->bsf, c);
> >  }
> >
> >  static int annexb_read_packet(AVFormatContext *s, AVPacket *pkt) @@
> > -246,12 +255,158 @@ static int annexb_read_close(AVFormatContext *s)
> >  return 0;
> >  }
> >
> > -#define OFFSET(x) offsetof(AnnexBContext, x)
> > +typedef struct LowOverheadContext {
> > +const AVClass *class;
> > +AVBSFContext *bsf;
> > +AVRational framerate;
> > +uint8_t prefetched[MAX_HEAD_SIZE];
> > +//prefetched len
> > +int len;
> > +} LowOverh

Re: [FFmpeg-devel] [PATCH 2/5] av1_parser: do not check buf_size if we have size in obu header

2020-08-06 Thread Xu, Guangxin
Hi James,
Thanks for the review.
How about we add a new function in av1dec.c like this:

static inline int read_obu_header_with_size_flag(const uint8_t *buf, int 
buf_size,
   int64_t *obu_size, int *type);
then we can remove first two patches and check has_size_flag in the function. 

I guess "out of array reads" will not happen in low overhead obu, since it 
always prepare enough data the obu.


> -Original Message-
> From: ffmpeg-devel  On Behalf Of James
> Almer
> Sent: Thursday, August 6, 2020 10:03 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 2/5] av1_parser: do not check buf_size if
> we have size in obu header
> 
> On 8/6/2020 5:04 AM, Xu Guangxin wrote:
> > for low overhead obu, we can't forsee the obu size. we can only get it
> > when we parsed the obu header.
> > ---
> >  libavcodec/av1_parse.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h index
> > a3b39f039c..823bdedd5e 100644
> > --- a/libavcodec/av1_parse.h
> > +++ b/libavcodec/av1_parse.h
> > @@ -135,7 +135,7 @@ static inline int parse_obu_header(const uint8_t
> > *buf, int buf_size,
> >
> >  size = *obu_size + *start_pos;
> >
> > -if (size > buf_size)
> > +if (!*has_size_flag && size > buf_size)
> 
> This check was added in c27c7b49dc to fix out of array reads, so this change 
> will
> surely reintroduce the issue.
> 
> Also, when has_size_flag is 0, size will never be bigger than buf_size 
> because it
> will be derived from it, meaning this change is the same as removing the check
> altogether.
> 
> >  return AVERROR_INVALIDDATA;
> >
> >  return size;
> >
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org
> with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 5/5] fate: av1dec, add test clip for low overhead obu

2020-08-06 Thread Xu Guangxin
---
 tests/fate/demux.mak  |  3 +++
 tests/ref/fate/av1-low-overhead-demux | 16 
 2 files changed, 19 insertions(+)
 create mode 100644 tests/ref/fate/av1-low-overhead-demux

diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index 9f3a6be276..763452a533 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -13,6 +13,9 @@ fate-aea-demux: CMD = crc -i $(TARGET_SAMPLES)/aea/chirp.aea 
-c:a copy
 FATE_SAMPLES_DEMUX-$(CONFIG_AV1_DEMUXER) += fate-av1-annexb-demux
 fate-av1-annexb-demux: CMD = framecrc -i $(TARGET_SAMPLES)/av1/annexb.obu -c:v 
copy
 
+FATE_SAMPLES_DEMUX-$(CONFIG_AV1_DEMUXER) += fate-av1-low-overhead-demux
+fate-av1-low-overhead-demux: CMD = framecrc -i 
$(TARGET_SAMPLES)/av1/low_overhead.obu -c:v copy
+
 FATE_SAMPLES_DEMUX-$(CONFIG_AST_DEMUXER) += fate-ast
 fate-ast: CMD = crc -i $(TARGET_SAMPLES)/ast/demo11_02_partial.ast -c copy
 
diff --git a/tests/ref/fate/av1-low-overhead-demux 
b/tests/ref/fate/av1-low-overhead-demux
new file mode 100644
index 00..62635bba89
--- /dev/null
+++ b/tests/ref/fate/av1-low-overhead-demux
@@ -0,0 +1,16 @@
+#extradata 0:   13, 0x12ed043e
+#tb 0: 1/120
+#media_type 0: video
+#codec_id 0: av1
+#dimensions 0: 176x144
+#sar 0: 0/1
+0,  0,  0,48000, 9106, 0x09d4b5fe
+0,  48000,  48000,48000,10218, 0xafe5dad1, F=0x0
+0,  96000,  96000,48000,5, 0x016200e5, F=0x0
+0, 144000, 144000,48000,  697, 0x96cb5a52, F=0x0
+0, 192000, 192000,48000,5, 0x015200d5, F=0x0
+0, 24, 24,48000, 2000, 0x34b2ea8e, F=0x0
+0, 288000, 288000,48000,5, 0x01920115, F=0x0
+0, 336000, 336000,48000,  836, 0x8a1b9294, F=0x0
+0, 384000, 384000,48000,  761, 0x407a72d4, F=0x0
+0, 432000, 432000,48000,   27, 0x4bde0706, F=0x0
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 4/5] avormat/av1dec: add low-overhead bitstream format

2020-08-06 Thread Xu Guangxin
It's defined in Section 5.2, used by netflix.
see http://download.opencontent.netflix.com/?prefix=AV1/Chimera/
---
 libavformat/allformats.c |   1 +
 libavformat/av1dec.c | 193 +--
 2 files changed, 185 insertions(+), 9 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index fd9e46e233..8eead5619d 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -75,6 +75,7 @@ extern AVOutputFormat ff_asf_stream_muxer;
 extern AVInputFormat  ff_au_demuxer;
 extern AVOutputFormat ff_au_muxer;
 extern AVInputFormat  ff_av1_demuxer;
+extern AVInputFormat  ff_av1_low_overhead_demuxer;
 extern AVInputFormat  ff_avi_demuxer;
 extern AVOutputFormat ff_avi_muxer;
 extern AVInputFormat  ff_avisynth_demuxer;
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index ec66152e03..0c5d172a0f 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -28,6 +28,9 @@
 #include "avio_internal.h"
 #include "internal.h"
 
+//2 + max leb 128 size
+#define MAX_HEAD_SIZE 10
+
 typedef struct AnnexBContext {
 const AVClass *class;
 AVBSFContext *bsf;
@@ -139,9 +142,8 @@ static int annexb_probe(const AVProbeData *p)
 return 0;
 }
 
-static int annexb_read_header(AVFormatContext *s)
+static int read_header(AVFormatContext *s, AVRational framerate, AVBSFContext 
**bsf, void *c)
 {
-AnnexBContext *c = s->priv_data;
 const AVBitStreamFilter *filter = av_bsf_get_by_name("av1_frame_merge");
 AVStream *st;
 int ret;
@@ -160,25 +162,32 @@ static int annexb_read_header(AVFormatContext *s)
 st->codecpar->codec_id = AV_CODEC_ID_AV1;
 st->need_parsing = AVSTREAM_PARSE_HEADERS;
 
-st->internal->avctx->framerate = c->framerate;
+st->internal->avctx->framerate = framerate;
 // taken from rawvideo demuxers
 avpriv_set_pts_info(st, 64, 1, 120);
 
-ret = av_bsf_alloc(filter, &c->bsf);
+ret = av_bsf_alloc(filter, bsf);
 if (ret < 0)
 return ret;
 
-ret = avcodec_parameters_copy(c->bsf->par_in, st->codecpar);
+ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
 if (ret < 0) {
-av_bsf_free(&c->bsf);
+av_bsf_free(bsf);
 return ret;
 }
 
-ret = av_bsf_init(c->bsf);
+ret = av_bsf_init(*bsf);
 if (ret < 0)
-av_bsf_free(&c->bsf);
+av_bsf_free(bsf);
 
 return ret;
+
+}
+
+static int annexb_read_header(AVFormatContext *s)
+{
+AnnexBContext *c = s->priv_data;
+return read_header(s, c->framerate, &c->bsf, c);
 }
 
 static int annexb_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -246,12 +255,158 @@ static int annexb_read_close(AVFormatContext *s)
 return 0;
 }
 
-#define OFFSET(x) offsetof(AnnexBContext, x)
+typedef struct LowOverheadContext {
+const AVClass *class;
+AVBSFContext *bsf;
+AVRational framerate;
+uint8_t prefetched[MAX_HEAD_SIZE];
+//prefetched len
+int len;
+} LowOverheadContext;
+
+static int low_overhead_probe(const AVProbeData *p)
+{
+AVIOContext pb;
+int64_t obu_size;
+int ret, type, cnt = 0, has_size_flag;
+
+ffio_init_context(&pb, p->buf, p->buf_size, 0,
+  NULL, NULL, NULL, NULL);
+
+// Check that the first OBU is a Temporal Delimiter.
+ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, MAX_HEAD_SIZE), 
&obu_size, &type, &has_size_flag);
+if (ret < 0 || type != AV1_OBU_TEMPORAL_DELIMITER || obu_size != 0 || 
!has_size_flag)
+return 0;
+cnt += ret;
+
+ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, MAX_HEAD_SIZE), 
&obu_size, &type, &has_size_flag);
+if (ret < 0 || type != AV1_OBU_SEQUENCE_HEADER || !has_size_flag)
+return 0;
+cnt += ret;
+
+ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, MAX_HEAD_SIZE), 
&obu_size, &type, &has_size_flag);
+if (ret < 0 || (type != AV1_OBU_FRAME && type != AV1_OBU_FRAME_HEADER) || 
obu_size <= 0 || !has_size_flag)
+return 0;
+return AVPROBE_SCORE_EXTENSION + 1;
+}
+
+static int low_overhead_read_header(AVFormatContext *s)
+{
+LowOverheadContext *c = s->priv_data;
+return read_header(s, c->framerate, &c->bsf, c);
+}
+
+static int low_overhead_prefetch(AVFormatContext *s)
+{
+LowOverheadContext *c = s->priv_data;
+int ret;
+int size = MAX_HEAD_SIZE - c->len;
+if (size > 0 && !avio_feof(s->pb)) {
+ret = avio_read(s->pb, &c->prefetched[c->len], size);
+if (ret < 0)
+return ret;
+c->len += ret;
+}
+return c->len;
+}
+
+static int low_overhead_read_data(AVFormatContext *s, AVPacket *pkt, int size)
+{
+int left;
+LowOverheadContext *c = s->priv_data;
+int ret = av_new_packet(pkt, size);
+if (ret < 0) {
+av_log(c, AV_LOG_ERROR, "Failed to allocate packet for obu\n");
+return ret;
+}
+if (size <= c->len) {
+memcpy(pkt->data, c->prefetched, size);
+
+left = c->len - size;
+memcpy(c->prefetched, c->p

[FFmpeg-devel] [PATCH 3/5] avformat/av1dec: refact, do not overide return value in read_obu

2020-08-06 Thread Xu Guangxin
we need them later
---
 libavformat/av1dec.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 297e87cc52..ec66152e03 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -60,14 +60,9 @@ static int leb(AVIOContext *pb, uint32_t *len) {
 static int read_obu(const uint8_t *buf, int size, int64_t *obu_size, int 
*type, int *has_size_flag)
 {
 int start_pos, temporal_id, spatial_id;
-int len;
 
-len = parse_obu_header(buf, size, obu_size, &start_pos,
+return parse_obu_header(buf, size, obu_size, &start_pos,
type, &temporal_id, &spatial_id, has_size_flag);
-if (len < 0)
-return len;
-
-return 0;
 }
 
 static int annexb_probe(const AVProbeData *p)
@@ -137,8 +132,8 @@ static int annexb_probe(const AVProbeData *p)
 break;
 }
 
-temporal_unit_size -= obu_unit_size + ret;
-frame_unit_size -= obu_unit_size + ret;
+temporal_unit_size -= obu_unit_size;
+frame_unit_size -= obu_unit_size;
 } while (frame_unit_size);
 
 return 0;
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 2/5] av1_parser: do not check buf_size if we have size in obu header

2020-08-06 Thread Xu Guangxin
for low overhead obu, we can't forsee the obu size. we can only get it
when we parsed the obu header.
---
 libavcodec/av1_parse.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index a3b39f039c..823bdedd5e 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -135,7 +135,7 @@ static inline int parse_obu_header(const uint8_t *buf, int 
buf_size,
 
 size = *obu_size + *start_pos;
 
-if (size > buf_size)
+if (!*has_size_flag && size > buf_size)
 return AVERROR_INVALIDDATA;
 
 return size;
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 0/5] avformat/av1dec: add low overhead obu demux

2020-08-06 Thread Xu Guangxin

Xu Guangxin (5):
  av1_parser: parser_obu_header, return has_size_flag
  av1_parser: do not check buf_size if we have size in obu header
  avformat/av1dec: refact, do not overide return value in read_obu
  avormat/av1dec: add low-overhead bitstream format
  fate: av1dec, add test clip for low overhead obu

 libavcodec/av1_parse.c|   4 +-
 libavcodec/av1_parse.h|  10 +-
 libavformat/allformats.c  |   1 +
 libavformat/av1.c |  12 +-
 libavformat/av1dec.c  | 214 +++---
 tests/fate/demux.mak  |   3 +
 tests/ref/fate/av1-low-overhead-demux |  16 ++
 7 files changed, 225 insertions(+), 35 deletions(-)
 create mode 100644 tests/ref/fate/av1-low-overhead-demux

-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/5] av1_parser: parser_obu_header, return has_size_flag

2020-08-06 Thread Xu Guangxin
From: Xu Guangxin 

we need check has_size_flag for low overhead obu
---
 libavcodec/av1_parse.c |  4 ++--
 libavcodec/av1_parse.h |  8 
 libavformat/av1.c  | 12 ++--
 libavformat/av1dec.c   | 10 +-
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
index 59ea0bc6e7..b59b4e5e45 100644
--- a/libavcodec/av1_parse.c
+++ b/libavcodec/av1_parse.c
@@ -29,11 +29,11 @@
 int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void 
*logctx)
 {
 int64_t obu_size;
-int start_pos, type, temporal_id, spatial_id;
+int start_pos, type, temporal_id, spatial_id, has_size_flag;
 int len;
 
 len = parse_obu_header(buf, length, &obu_size, &start_pos,
-   &type, &temporal_id, &spatial_id);
+   &type, &temporal_id, &spatial_id, &has_size_flag);
 if (len < 0)
 return len;
 
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index 01bcd646c2..a3b39f039c 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -99,10 +99,10 @@ static inline int64_t leb128(GetBitContext *gb) {
 
 static inline int parse_obu_header(const uint8_t *buf, int buf_size,
int64_t *obu_size, int *start_pos, int 
*type,
-   int *temporal_id, int *spatial_id)
+   int *temporal_id, int *spatial_id, int 
*has_size_flag)
 {
 GetBitContext gb;
-int ret, extension_flag, has_size_flag;
+int ret, extension_flag;
 int64_t size;
 
 ret = init_get_bits8(&gb, buf, FFMIN(buf_size, 2 + 8)); // OBU header 
fields + max leb128 length
@@ -114,7 +114,7 @@ static inline int parse_obu_header(const uint8_t *buf, int 
buf_size,
 
 *type  = get_bits(&gb, 4);
 extension_flag = get_bits1(&gb);
-has_size_flag  = get_bits1(&gb);
+*has_size_flag  = get_bits1(&gb);
 skip_bits1(&gb); // obu_reserved_1bit
 
 if (extension_flag) {
@@ -125,7 +125,7 @@ static inline int parse_obu_header(const uint8_t *buf, int 
buf_size,
 *temporal_id = *spatial_id = 0;
 }
 
-*obu_size  = has_size_flag ? leb128(&gb)
+*obu_size  = *has_size_flag ? leb128(&gb)
: buf_size - 1 - extension_flag;
 
 if (get_bits_left(&gb) < 0)
diff --git a/libavformat/av1.c b/libavformat/av1.c
index 0cbffb1fd8..10d6815d1f 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -34,7 +34,7 @@ static int av1_filter_obus(AVIOContext *pb, const uint8_t 
*buf,
 {
 const uint8_t *start = buf, *end = buf + size;
 int64_t obu_size;
-int off, start_pos, type, temporal_id, spatial_id;
+int off, start_pos, type, temporal_id, spatial_id, has_size_flag;
 enum {
 START_NOT_FOUND,
 START_FOUND,
@@ -45,7 +45,7 @@ static int av1_filter_obus(AVIOContext *pb, const uint8_t 
*buf,
 off = size = 0;
 while (buf < end) {
 int len = parse_obu_header(buf, end - buf, &obu_size, &start_pos,
-   &type, &temporal_id, &spatial_id);
+   &type, &temporal_id, &spatial_id, 
&has_size_flag);
 if (len < 0)
 return len;
 
@@ -334,14 +334,14 @@ static int parse_sequence_header(AV1SequenceParameters 
*seq_params, const uint8_
 int ff_av1_parse_seq_header(AV1SequenceParameters *seq, const uint8_t *buf, 
int size)
 {
 int64_t obu_size;
-int start_pos, type, temporal_id, spatial_id;
+int start_pos, type, temporal_id, spatial_id, has_size_flag;
 
 if (size <= 0)
 return AVERROR_INVALIDDATA;
 
 while (size > 0) {
 int len = parse_obu_header(buf, size, &obu_size, &start_pos,
-   &type, &temporal_id, &spatial_id);
+   &type, &temporal_id, &spatial_id, 
&has_size_flag);
 if (len < 0)
 return len;
 
@@ -369,7 +369,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, 
int size)
 uint8_t header[4], *meta;
 const uint8_t *seq;
 int64_t obu_size;
-int start_pos, type, temporal_id, spatial_id;
+int start_pos, type, temporal_id, spatial_id, has_size_flag;
 int ret, nb_seq = 0, seq_size, meta_size;
 
 if (size <= 0)
@@ -381,7 +381,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, 
int size)
 
 while (size > 0) {
 int len = parse_obu_header(buf, size, &obu_size, &start_pos,
-   &type, &temporal_id, &spatial_id);
+   &type, &temporal_id, &spatial_id, 
&has_size_flag);
 if (len < 0) {
 ret = len;
 goto fail;
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
ind