Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-19 Thread Alexander Kravchenko


> -Original Message-
> From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of Luca 
> Barbato
> Sent: Monday, April 16, 2018 5:33 AM
> To: libav-devel@libav.org
> Subject: Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D 
> frames used as input during the encoding process
> 
> On 13/04/2018 00:41, Alexander Kravchenko wrote:
> > This fixes frame corruption issue when decoder started reusing frames
> > while they are still in use of encoding process
> >
> > Issue with frame corruption  was reproduced using:
> > avconv.exe -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i
> > input.h264 -an -c:v h264_amf output.mkv
> >
> > it is recommended to use -extra_hw_frames 16 option in case if hw
> > frames number in pool is not enough
> >
> 
> Seems good enough, I do not have the hardware at hand to see if would be 
> possible to make it simpler than that.
> 
> I'll merge in 8 hours or such.
> 
> lu
> 

Hi Luca,
A soft reminder about merging the patch :)

Thanks
Alexander

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

Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-15 Thread Luca Barbato
On 13/04/2018 00:41, Alexander Kravchenko wrote:
> This fixes frame corruption issue when decoder started reusing frames while 
> they are still in use of encoding process
> 
> Issue with frame corruption  was reproduced using:
> avconv.exe -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.h264 -an 
> -c:v h264_amf output.mkv
> 
> it is recommended to use -extra_hw_frames 16 option in case if hw frames 
> number in pool is not enough
> 

Seems good enough, I do not have the hardware at hand to see if would be
possible to make it simpler than that.

I'll merge in 8 hours or such.

lu

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

Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-15 Thread Alexander Kravchenko
Hi Guys,
Did you have a chance to review the patch? Is it ok?

Thanks,
Alexander

> -Original Message-
> From: Alexander Kravchenko [mailto:akravchenko...@gmail.com]
> Sent: Thursday, April 12, 2018 6:42 PM
> To: libav-devel@libav.org
> Cc: Alexander Kravchenko 
> Subject: [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input 
> during the encoding process
> 
> This fixes frame corruption issue when decoder started reusing frames while 
> they are still in use of encoding process
> 
> Issue with frame corruption  was reproduced using:
> avconv.exe -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.h264 -an 
> -c:v h264_amf output.mkv
> 
> it is recommended to use -extra_hw_frames 16 option in case if hw frames 
> number in pool is not enough
> 
> 
> ---
>  libavcodec/amfenc.c | 95 
> -
>  libavcodec/amfenc.h |  3 ++
>  2 files changed, 97 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 
> 74b020b4d..9a60050bc 100644
> --- a/libavcodec/amfenc.c
> +++ b/libavcodec/amfenc.c
> @@ -162,6 +162,9 @@ static int amf_init_context(AVCodecContext *avctx)
>  AmfContext *ctx = avctx->priv_data;
>  AMF_RESULT  res = AMF_OK;
> 
> +ctx->hwsurfaces_in_queue = 0;
> +ctx->hwsurfaces_in_queue_max = 16;
> +
>  // configure AMF logger
>  // the return of these functions indicates old state and do not affect 
> behaviour
>  ctx->trace->pVtbl->EnableWriter(ctx->trace, 
> AMF_TRACE_WRITER_DEBUG_OUTPUT, ctx->log_to_dbg != 0 ); @@ -192,6 +195,8
> @@ static int amf_init_context(AVCodecContext *avctx)
>  if (!ctx->hw_frames_ctx) {
>  return AVERROR(ENOMEM);
>  }
> +if (device_ctx->initial_pool_size > 0)
> +ctx->hwsurfaces_in_queue_max =
> + device_ctx->initial_pool_size - 1;
>  } else {
>  if(res == AMF_NOT_SUPPORTED)
>  av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
> has D3D11 device which doesn't have D3D11VA interface,
> switching to default\n"); @@ -447,6 +452,75 @@ int 
> ff_amf_encode_init(AVCodecContext *avctx)
>  return ret;
>  }
> 
> +static AMF_RESULT amf_set_property_buffer(AMFSurface *object, const
> +wchar_t *name, AMFBuffer *val) {
> +AMF_RESULT res;
> +AMFVariantStruct var;
> +res = AMFVariantInit();
> +if (res == AMF_OK) {
> +AMFGuid guid_AMFInterface = IID_AMFInterface();
> +AMFInterface *amf_interface;
> +res = val->pVtbl->QueryInterface(val, _AMFInterface,
> +(void**)_interface);
> +
> +if (res == AMF_OK) {
> +res = AMFVariantAssignInterface(, amf_interface);
> +amf_interface->pVtbl->Release(amf_interface);
> +}
> +if (res == AMF_OK) {
> +res = object->pVtbl->SetProperty(object, name, var);
> +}
> +AMFVariantClear();
> +}
> +return res;
> +}
> +
> +static AMF_RESULT amf_get_property_buffer(AMFData *object, const
> +wchar_t *name, AMFBuffer **val) {
> +AMF_RESULT res;
> +AMFVariantStruct var;
> +res = AMFVariantInit();
> +if (res == AMF_OK) {
> +res = object->pVtbl->GetProperty(object, name, );
> +if (res == AMF_OK) {
> +if (var.type == AMF_VARIANT_INTERFACE) {
> +AMFGuid guid_AMFBuffer = IID_AMFBuffer();
> +AMFInterface *amf_interface = AMFVariantInterface();
> +res = amf_interface->pVtbl->QueryInterface(amf_interface, 
> _AMFBuffer, (void**)val);
> +} else {
> +res = AMF_INVALID_DATA_TYPE;
> +}
> +}
> +AMFVariantClear();
> +}
> +return res;
> +}
> +
> +static AMFBuffer *amf_create_buffer_with_frame_ref(const AVFrame
> +*frame, AMFContext *context) {
> +AVFrame *frame_ref;
> +AMFBuffer *frame_ref_storage_buffer = NULL;
> +AMF_RESULT res;
> +
> +res = context->pVtbl->AllocBuffer(context, AMF_MEMORY_HOST, 
> sizeof(frame_ref), _ref_storage_buffer);
> +if (res == AMF_OK) {
> +frame_ref = av_frame_clone(frame);
> +if (frame_ref) {
> +
> memcpy(frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
> _ref, sizeof(frame_ref));
> +} else {
> +
> frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
> +frame_ref_storage_buffer = NULL;
> +}
> +}
> +return frame_ref_storage_buffer;
> +}
> +
> +static void amf_release_buffer_with_frame_ref(AMFBuffer
> +*frame_ref_storage_buffer) {
> +AVFrame *av_frame_ref;
> +memcpy(_frame_ref, 
> frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
> sizeof(av_frame_ref));
> +av_frame_free(_frame_ref);
> +

Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-12 Thread Alexander Kravchenko
Hi guys,
thanks for your advice.
I have sent one more time using git send-email

чт, 12 апр. 2018 г. в 17:56, Diego Biurrun :

> On Wed, Apr 11, 2018 at 07:31:19PM +0300, Alexander Kravchenko wrote:
> > >
> > > Your mailer mangled the patch, could you please resend it attached?
> >
> > It would be nice if you recommend some good simple mailer or to do
>
> I use git-send-email, works fine here.
>
> Diego
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-12 Thread Diego Biurrun
On Wed, Apr 11, 2018 at 07:31:19PM +0300, Alexander Kravchenko wrote:
> > 
> > Your mailer mangled the patch, could you please resend it attached?
> 
> It would be nice if you recommend some good simple mailer or to do

I use git-send-email, works fine here.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-12 Thread Luca Barbato
On 12/04/2018 01:31, Alexander Kravchenko wrote:
>>
>> Your mailer mangled the patch, could you please resend it attached?
>>
>> Diego
> 
> Hi Diego,
> Sending plain text mail format (probably I switched from Rich text to plain 
> after paste patch test)
> Hopefully it is ok.
> Last time I tried to send attached mail in outlook. It was rejected as binary.
> It would be nice if you recommend some good simple mailer or to do
> 

http://trojita.flaska.net/download.html with git-format-patch might work
fine.

Otherwise you could configure git-send-email to use directly gmail as
the end of the man page suggests but it can be relatively annoying IMHO.

lu

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

Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-11 Thread Alexander Kravchenko
> 
> Your mailer mangled the patch, could you please resend it attached?
> 
> Diego

Hi Diego,
Sending plain text mail format (probably I switched from Rich text to plain 
after paste patch test)
Hopefully it is ok.
Last time I tried to send attached mail in outlook. It was rejected as binary.
It would be nice if you recommend some good simple mailer or to do

Thanks,
Alexander


---
 libavcodec/amfenc.c | 95 -
 libavcodec/amfenc.h |  3 ++
 2 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 74b020b4d..9a60050bc 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -162,6 +162,9 @@ static int amf_init_context(AVCodecContext *avctx)
 AmfContext *ctx = avctx->priv_data;
 AMF_RESULT  res = AMF_OK;
 
+ctx->hwsurfaces_in_queue = 0;
+ctx->hwsurfaces_in_queue_max = 16;
+
 // configure AMF logger
 // the return of these functions indicates old state and do not affect 
behaviour
 ctx->trace->pVtbl->EnableWriter(ctx->trace, AMF_TRACE_WRITER_DEBUG_OUTPUT, 
ctx->log_to_dbg != 0 );
@@ -192,6 +195,8 @@ static int amf_init_context(AVCodecContext *avctx)
 if (!ctx->hw_frames_ctx) {
 return AVERROR(ENOMEM);
 }
+if (device_ctx->initial_pool_size > 0)
+ctx->hwsurfaces_in_queue_max = 
device_ctx->initial_pool_size - 1;
 } else {
 if(res == AMF_NOT_SUPPORTED)
 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
has D3D11 device which doesn't have D3D11VA interface, switching to default\n");
@@ -447,6 +452,75 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 return ret;
 }
 
+static AMF_RESULT amf_set_property_buffer(AMFSurface *object, const wchar_t 
*name, AMFBuffer *val)
+{
+AMF_RESULT res;
+AMFVariantStruct var;
+res = AMFVariantInit();
+if (res == AMF_OK) {
+AMFGuid guid_AMFInterface = IID_AMFInterface();
+AMFInterface *amf_interface;
+res = val->pVtbl->QueryInterface(val, _AMFInterface, 
(void**)_interface);
+
+if (res == AMF_OK) {
+res = AMFVariantAssignInterface(, amf_interface);
+amf_interface->pVtbl->Release(amf_interface);
+}
+if (res == AMF_OK) {
+res = object->pVtbl->SetProperty(object, name, var);
+}
+AMFVariantClear();
+}
+return res;
+}
+
+static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t 
*name, AMFBuffer **val)
+{
+AMF_RESULT res;
+AMFVariantStruct var;
+res = AMFVariantInit();
+if (res == AMF_OK) {
+res = object->pVtbl->GetProperty(object, name, );
+if (res == AMF_OK) {
+if (var.type == AMF_VARIANT_INTERFACE) {
+AMFGuid guid_AMFBuffer = IID_AMFBuffer();
+AMFInterface *amf_interface = AMFVariantInterface();
+res = amf_interface->pVtbl->QueryInterface(amf_interface, 
_AMFBuffer, (void**)val);
+} else {
+res = AMF_INVALID_DATA_TYPE;
+}
+}
+AMFVariantClear();
+}
+return res;
+}
+
+static AMFBuffer *amf_create_buffer_with_frame_ref(const AVFrame *frame, 
AMFContext *context)
+{
+AVFrame *frame_ref;
+AMFBuffer *frame_ref_storage_buffer = NULL;
+AMF_RESULT res;
+
+res = context->pVtbl->AllocBuffer(context, AMF_MEMORY_HOST, 
sizeof(frame_ref), _ref_storage_buffer);
+if (res == AMF_OK) {
+frame_ref = av_frame_clone(frame);
+if (frame_ref) {
+
memcpy(frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
_ref, sizeof(frame_ref));
+} else {
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+frame_ref_storage_buffer = NULL;
+}
+}
+return frame_ref_storage_buffer;
+}
+
+static void amf_release_buffer_with_frame_ref(AMFBuffer 
*frame_ref_storage_buffer)
+{
+AVFrame *av_frame_ref;
+memcpy(_frame_ref, 
frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
sizeof(av_frame_ref));
+av_frame_free(_frame_ref);
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+}
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -488,6 +562,8 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 (ctx->hw_device_ctx && 
((AVHWFramesContext*)frame->hw_frames_ctx->data)->device_ctx ==
 (AVHWDeviceContext*)ctx->hw_device_ctx->data)
 )) {
+AMFBuffer *frame_ref_storage_buffer;
+
 #if CONFIG_D3D11VA
 static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 0xe7c3, 
0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
 ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; // 
actual texture

Re: [libav-devel] [PATCH] lavc/amfenc: Retain a reference to D3D frames used as input during the encoding process

2018-04-11 Thread Diego Biurrun
On Wed, Apr 11, 2018 at 06:02:32PM +0300, Alexander Kravchenko wrote:
> This fixes frame corruption issue when decoder started reusing frames while
> they are still in use of encoding process
> 
> Issue with frame corruption  was reproduced using:
> avconv.exe -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.h264
> -an -c:v h264_amf output.mkv
> 
> it is recommended to use -extra_hw_frames 16 option in case if hw frames
> number in pool is not enough
> 
> ---
>  libavcodec/amfenc.c | 95
> -
>  libavcodec/amfenc.h |  3 ++
>  2 files changed, 97 insertions(+), 1 deletion(-)

Your mailer mangled the patch, could you please resend it attached?

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel