[FFmpeg-devel] [PATCH] MAINTAINERS: add myself to the AMF section

2019-07-02 Thread Alexander Kravchenko



0001-MAINTAINERS-add-myself-to-the-AMF-section.patch
Description: Binary data
___
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] MAINTAINERS: add myself to the AMF section

2019-07-02 Thread Alexander Kravchenko




0001-MAINTAINERS-add-myself-to-the-AMF-section.patch
Description: Binary data
___
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] MAINTAINERS: add myself to the AMF section

2019-07-03 Thread Alexander Kravchenko
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 88b0109f22..a66e4fc338 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -138,6 +138,7 @@ Codecs:
   aacenc*, aaccoder.c   Rostislav Pehlivanov
   alacenc.c Jaikrishnan Menon
   alsdec.c  Thilo Borgmann, Umair Khan
+  amf*  Alexander Kravchenko
   aptx.cAurelien Jacobs
   ass*  Aurelien Jacobs
   asv*  Michael Niedermayer
-- 
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] MAINTAINERS: add myself to the AMF section

2019-07-04 Thread Alexander Kravchenko
Hi everybody.
Let me explain reasons here.

About AMF:
1) AMF is a light-weight, portable multimedia framework that provides access to 
AMD hardware accelerated encoder, decoder, converters/filters.
2) AMF abstracts away most of the platform and API-specific details and allows 
for easy implementation of multimedia applications using a variety of 
technologies, such as DirectX 11, OpenGL, and OpenCL, Vulkan and facilitates an 
efficient interop between them.
3) It is very useful to use AMF as part of FFmpeg framework together with 
numerous FFmpeg features
 
About myself
1) I was one of originators/architects of AMF and implemented core modules
2) I fixed few issues in amfenc integration in FFmpeg
3) I implemented integrations of AMF decoder, converter/scaler to FFmpeg. 
Unfortunately they were not applied yet.
4) I appreciate feedback, open for discussions, and ready to follow the rules 
of community

Proposed plan about AMF here
1) Add Linux support (via Vulkan)
2) Add AMD decoder, scaler, converter
3) Connect continuous integration server to execute tests and keep it stable

Thanks,
Alexander


___
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 1/2] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-10-29 Thread Alexander Kravchenko
Hi, Mark.
Thanks for review.
Could you please check the following comments/questions?

> +
> > +static const AVClass amflib_class = {
> > +.class_name = "amf",
> > +.item_name = av_default_item_name,
> > +.version = LIBAVUTIL_VERSION_INT,
> > +};
>
> This class shouldn't be needed - the right class to use is the one in the
> AVHWDeviceContext, you should be able to pass it to the right place via
> your AMFDeviceContextPrivate structure.
>
> > +
> > +typedef struct AMFLibraryContext {
> > +const AVClass  *avclass;
> > +} AMFLibraryContext;
> > +
> > +static AMFLibraryContext amflib_context =
> > +{
> > +.avclass = &amflib_class,
> > +};
>
> This structure is just a dummy for the class?  Use the AVHWDeviceContext.
>
> > +
> > +typedef struct AmfTraceWriter {
> > +const AMFTraceWriterVtbl*vtbl;
> > +void*avcl;
> > +} AmfTraceWriter;
> > +
> > +static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
>
> It would be sensible to take the opportunity to fix the function name to
> conform to ffmpeg style.
>
> > +const wchar_t *scope, const wchar_t *message)
> > +{
> > +AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
> > +av_log(tracer->avcl, AV_LOG_DEBUG, "%ls: %ls", scope, message);
> > +}
> > +
> > +static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
> > +{
> > +}
> > +
> > +static const AMFTraceWriterVtbl tracer_vtbl =
> > +{
> > +.Write = AMFTraceWriter_Write,
> > +.Flush = AMFTraceWriter_Flush,
>
> Is this function really required to exist, given that it doesn't do
> anything?
>
> > +};
> > +
> > +static const AmfTraceWriter amf_trace_writer =
> > +{
> > +.vtbl = &tracer_vtbl,
> > +.avcl = &amflib_context,
> > +};
>
> This should probably be inside the AMFDeviceContextPrivate, so that it can
> point to the right context structure.
>
> This is the question.
AMF Library has global Trace settings, not per AMFContext object.
My intension was to create global AMF lib class and Tracer object which
refers to it as class parameter in av_log call.
It is required in scenario when multiple hwcontext_amf are created during
application lifecycle.
if this way is ok, should I add comments to code describes this? or is
there another way to have global object to handle this?

AMFTraceWriterVtbl.Flush - I am not sure that it can be set as null
pointer, I could double check with AMD developers.




> >  #include 
> >  #include 
>
> Kindof unrelated, but is there any reason why both of these are in the
> header rather than in the per-codec files?
>
>
Component management code is the same for all encoder components.
The only encoder id defines is used for component creation here.



>
> The log_to_dbg option is orphaned by this change.  Is it worth keeping?
> (If you want to keep it then maybe it could be a named option to
> av_hwdevice_ctx_create() -> amf_device_create().)
>
> log_to_dbg is removed from here, because this setting is global for AMF
library, not per component(encoder) or per AMFContext(hwcontext_amf object)

Probably I could implement some global AMF lib options which configures
tracer more precisely in general

Thanks,
Alexander
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-10-29 Thread Alexander Kravchenko
Hi Mark,
see my comments bellow.

вт, 30 окт. 2018 г. в 0:23, Mark Thompson :

> On 29/10/18 11:45, Alexander Kravchenko wrote:
> > Hi, Mark.
> > Thanks for review.
> > Could you please check the following comments/questions?
> >
> >> +
> >>> +static const AVClass amflib_class = {
> >>> +.class_name = "amf",
> >>> +.item_name = av_default_item_name,
> >>> +.version = LIBAVUTIL_VERSION_INT,
> >>> +};
> >>
> >> This class shouldn't be needed - the right class to use is the one in
> the
> >> AVHWDeviceContext, you should be able to pass it to the right place via
> >> your AMFDeviceContextPrivate structure.
> >>
> >>> +
> >>> +typedef struct AMFLibraryContext {
> >>> +const AVClass  *avclass;
> >>> +} AMFLibraryContext;
> >>> +
> >>> +static AMFLibraryContext amflib_context =
> >>> +{
> >>> +.avclass = &amflib_class,
> >>> +};
> >>
> >> This structure is just a dummy for the class?  Use the
> AVHWDeviceContext.
> >>
> >>> +
> >>> +typedef struct AmfTraceWriter {
> >>> +const AMFTraceWriterVtbl*vtbl;
> >>> +void*avcl;
> >>> +} AmfTraceWriter;
> >>> +
> >>> +static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
> >>
> >> It would be sensible to take the opportunity to fix the function name to
> >> conform to ffmpeg style.
> >>
> >>> +const wchar_t *scope, const wchar_t *message)
> >>> +{
> >>> +AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
> >>> +av_log(tracer->avcl, AV_LOG_DEBUG, "%ls: %ls", scope, message);
> >>> +}
> >>> +
> >>> +static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
> >>> +{
> >>> +}
> >>> +
> >>> +static const AMFTraceWriterVtbl tracer_vtbl =
> >>> +{
> >>> +.Write = AMFTraceWriter_Write,
> >>> +.Flush = AMFTraceWriter_Flush,
> >>
> >> Is this function really required to exist, given that it doesn't do
> >> anything?
> >>
> >>> +};
> >>> +
> >>> +static const AmfTraceWriter amf_trace_writer =
> >>> +{
> >>> +.vtbl = &tracer_vtbl,
> >>> +.avcl = &amflib_context,
> >>> +};
> >>
> >> This should probably be inside the AMFDeviceContextPrivate, so that it
> can
> >> point to the right context structure.
> >>
> >> This is the question.
> > AMF Library has global Trace settings, not per AMFContext object.
>
> So that global state is inside the AMF library?
>
> How does that interact with the fact that you reload it and reconfigure it
> every time it gets loaded - if one thread calls amf_device_create() while
> another one is inside the encoder and generating log output (say), what
> happens?
>

One of my first proposed patch had singleton amf_library, which was
refcounted. main goal of it was init library (set Trace options) when the
first reference is requested and clean when it was finally released (last
hwcontext_amf is destroyed).
I was told that global state is not good (global amf_lib object keeper) and
I removed it and now Tracer options are updated each time amf_device_create
is called.

Now there is no global state in avutils/hwcontext_amf : all globals here
are const static objects. The only global state in AMF Library itself
(configuring tracer is thread-safe in AMF).


> (I also note that it presumably means the current AMF encoder code will
> crash if you have two encoders with nested lifetimes - the second encoder
> will overwrite the global state, and once it finishes and gets freed the
> global trace output from the first encoder will have an invalid class
> pointer.)
>

Yes, I aware the issue since I started to support amfenc and this is the
first reason to move amf lib code to hwcontext_amf.



> > My intension was to create global AMF lib class and Tracer object which
> > refers to it as class parameter in av_log call.
> > It is required in scenario when multiple hwcontext_amf are created during
> > application lifecycle.
> > if this way is ok, should I add comments to code describes this? or is
> > there another way to have global object to handle this?
> Global state in libraries really isn't ok.  I think in response to that I
> would force it to be completely off by default, maybe switch it o

Re: [FFmpeg-devel] [PATCH] amfenc: Add support for pict_type field

2019-02-01 Thread Alexander Kravchenko
Hi guys,

I could take manteinership and one person from my team, hopefully it could help 
to move pending patches which are required to be applied and have been waiting 
for a long time

 

Thanks

Alexander

 

 

От: ffmpeg-devel  от имени Carl Eugen Hoyos 

Обратный адрес: FFmpeg development discussions and patches 

Дата: пятница, 1 февраля 2019 г., 21:31
Кому: FFmpeg development discussions and patches 
Тема: Re: [FFmpeg-devel] [PATCH] amfenc: Add support for pict_type field

 

2019-02-01 19:25 GMT+01:00, Michael Dirks :

On 15.01.2019 23:41, Michael Dirks wrote:

On 15.01.2019 23:05, michael.di...@xaymar.com wrote:

From: Michael Fabian 'Xaymar' Dirks 

 

Adds support for the pict_type field in AVFrame to amf_h264 and

amf_h265 simultaneously. This field is needed in cases where the

application wishes to override the frame type with another one, such

as forcefully inserting a key frame for chapter markers or similar.

 

Additionally this abuses AV_PICTURE_TYPE_S for marking Skip frames, a

special type of frame in AVC, SVC and HEVC which is a flag for the

decoder to repeat the last frame.

This patch has been tested with the small tool I wrote here:

https://github.com/Xaymar/ffmpeg-test. It works in both H264 and H265

and produces the correct sequence of IDR, I, P and Skip frames -

including the visual corruption that AMD's Skip frames have.

 

As there currently seems to be no active maintainer for amfenc files

 

(I don't find this surprising given the history of the AMD patch.)

 

Could you take over mantainership?

 

Carl Eugen

___

ffmpeg-devel mailing list

ffmpeg-devel@ffmpeg.org

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

 

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


[FFmpeg-devel] amf: maintainership of amf components

2019-02-01 Thread Alexander Kravchenko
Hello guys, 

could you add me as maintainer of AMF components: encoder (+ coming scaler, 
decoder, vulkan)

 

There are lots of my pending patches and it look like nobody else have time to 
process/review them

I know AMF architecture and I already have experience in FFmpeg development.

 

Thanks,

Alexander Kravchenko

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


Re: [FFmpeg-devel] [PATCH] amfenc: Add support for pict_type field

2019-02-01 Thread Alexander Kravchenko
Hello Carl

Ok, I’m going to test and coming back.

 

Thanks,

Alexander

 

От: ffmpeg-devel  от имени Carl Eugen Hoyos 

Обратный адрес: FFmpeg development discussions and patches 

Дата: пятница, 1 февраля 2019 г., 21:51
Кому: FFmpeg development discussions and patches 
Тема: Re: [FFmpeg-devel] [PATCH] amfenc: Add support for pict_type field

 

2019-02-01 19:39 GMT+01:00, Alexander Kravchenko :

 

I could take manteinership and one person from my team, hopefully

it could help to move pending patches which are required to be

applied and have been waiting for a long time

 

A good start would be to review this patch an stop top-posting.

 

Carl Eugen

___

ffmpeg-devel mailing list

ffmpeg-devel@ffmpeg.org

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

 

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


[FFmpeg-devel] [PATCH] lavc/amfenc: Reference to input AVFrame (hwaccel) is retained during the encoding process

2018-03-26 Thread Alexander Kravchenko
Hello,
I have fixed issues listed in previous patch.


> Say what the change is in the title.  Something like "amfenc: Retain a 
> reference to D3D11 frames used as input during the encoding
> process", maybe?
Sure, but I am preparing next patch adding DX9 support, so probably better to 
write D3D instead D3D11

> 
> How many frames can end up queued inside the encoder here?
16

> 
> Is there always an exact 1->1 correspondence between input frames and output 
> packets?  That is, is it guaranteed that no frames are
> ever dropped, even in the low-latency modes?
yes

> Put the * in the right place - it's part of the declarator, not the 
> declaration-specifiers.
> "if (", and in all places below too.
I have fixed these issues in whole file (Hopefully you don’t mind if it put to 
same commit. There aren't many pf them)


From: Alexander Kravchenko 
---
 libavcodec/amfenc.c | 89 -
 1 file changed, 81 insertions(+), 8 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 89a10ff253..f532a32b7b 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -188,7 +188,7 @@ static int amf_init_context(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 }
 } else {
-if(res == AMF_NOT_SUPPORTED)
+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");
 else
 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
has non-AMD device, switching to default\n");
@@ -298,7 +298,7 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 }
 
 static int amf_copy_surface(AVCodecContext *avctx, const AVFrame *frame,
-AMFSurface* surface)
+AMFSurface *surface)
 {
 AVFrame*sw_frame = NULL;
 AMFPlane   *plane = NULL;
@@ -371,7 +371,7 @@ static int amf_copy_buffer(AVCodecContext *avctx, AVPacket 
*pkt, AMFBuffer *buff
 switch (avctx->codec->id) {
 case AV_CODEC_ID_H264:
 buffer->pVtbl->GetProperty(buffer, 
AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE, &var);
-if(var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_IDR) {
+if (var.int64Value == AMF_VIDEO_ENCODER_OUTPUT_DATA_TYPE_IDR) {
 pkt->flags = AV_PKT_FLAG_KEY;
 }
 break;
@@ -443,6 +443,48 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 return ret;
 }
 
+#define AMF_AV_QUERY_INTERFACE(res, from, InterfaceTypeTo, to) \
+{ \
+AMFGuid guid_##InterfaceTypeTo = IID_##InterfaceTypeTo(); \
+res = from->pVtbl->QueryInterface(from, &guid_##InterfaceTypeTo, 
(void**)&to); \
+}
+
+#define AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, pThis, name, val) \
+{ \
+AMFInterface *amf_interface; \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+if (res == AMF_OK) { \
+AMF_AV_QUERY_INTERFACE(res, val, AMFInterface, amf_interface)\
+} \
+if (res == AMF_OK) { \
+res = AMFVariantAssignInterface(&var, amf_interface); \
+amf_interface->pVtbl->Release(amf_interface); \
+} \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->SetProperty(pThis, name, var); \
+} \
+res = AMFVariantClear(&var); \
+}
+
+#define AMF_AV_GET_PROPERTY_INTERFACE(res, pThis, name, TargetType, val) \
+{ \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+res = pThis->pVtbl->GetProperty(pThis, name, &var); \
+if (res == AMF_OK) { \
+if (var.type == AMF_VARIANT_INTERFACE && 
AMFVariantInterface(&var)) { \
+AMF_AV_QUERY_INTERFACE(res, AMFVariantInterface(&var), 
TargetType, val); \
+} else { \
+res = AMF_INVALID_DATA_TYPE; \
+} \
+} \
+AMFVariantClear(&var); \
+}
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -458,7 +500,7 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 if (!ctx->eof) { // submit drain one time only
 if (ctx->delayed_surface != NULL) {
 ctx->delayed_drain = 1; // input queue is full: resubmit 
Drain() in ff_amf_receive_packet
-} else if(!ctx->delayed_drain) {
+} else if (!ctx->delayed_drain) {
 res = ctx->encoder->pVtbl->Drain(ctx->encoder);
 if (res == AMF_INPUT_FULL) {
  

[FFmpeg-devel] [PATCH] lavc/amfenc: Reference to input AVFrame (hwaccel) is retained during the encoding process

2018-03-26 Thread Alexander Kravchenko
Fixed issues of previous patch

---
 libavcodec/amfenc.c | 82 ++---
 1 file changed, 78 insertions(+), 4 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 89a10ff253..5f3440a9f3 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -443,6 +443,48 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 return ret;
 }
 
+#define AMF_AV_QUERY_INTERFACE(res, from, InterfaceTypeTo, to) \
+{ \
+AMFGuid guid_##InterfaceTypeTo = IID_##InterfaceTypeTo(); \
+res = from->pVtbl->QueryInterface(from, &guid_##InterfaceTypeTo, 
(void**)&to); \
+}
+
+#define AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, pThis, name, val) \
+{ \
+AMFInterface *amf_interface; \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+if (res == AMF_OK) { \
+AMF_AV_QUERY_INTERFACE(res, val, AMFInterface, amf_interface)\
+} \
+if (res == AMF_OK) { \
+res = AMFVariantAssignInterface(&var, amf_interface); \
+amf_interface->pVtbl->Release(amf_interface); \
+} \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->SetProperty(pThis, name, var); \
+} \
+res = AMFVariantClear(&var); \
+}
+
+#define AMF_AV_GET_PROPERTY_INTERFACE(res, pThis, name, TargetType, val) \
+{ \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+res = pThis->pVtbl->GetProperty(pThis, name, &var); \
+if (res == AMF_OK) { \
+if (var.type == AMF_VARIANT_INTERFACE && 
AMFVariantInterface(&var)) { \
+AMF_AV_QUERY_INTERFACE(res, AMFVariantInterface(&var), 
TargetType, val); \
+} else { \
+res = AMF_INVALID_DATA_TYPE; \
+} \
+} \
+AMFVariantClear(&var); \
+}
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -484,6 +526,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)
 )) {
+AVFrame *frame_ref;
+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
@@ -496,6 +540,21 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 // input HW surfaces can be vertically aligned by 16; tell AMF the 
real size
 surface->pVtbl->SetCrop(surface, 0, 0, frame->width, 
frame->height);
 #endif
+res = ctx->context->pVtbl->AllocBuffer(ctx->context, 
AMF_MEMORY_HOST, sizeof(frame_ref), &frame_ref_storage_buffer);
+AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
"AllocBuffer() failed  with error %d\n", res);
+frame_ref = av_frame_clone(frame);
+AMF_RETURN_IF_FALSE(ctx, frame_ref != NULL, AVERROR(ENOMEM), 
"av_frame_clone() returned NULL\n");
+
memcpy(frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
&frame_ref, sizeof(frame_ref));
+AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, surface, L"av_frame_ref", 
frame_ref_storage_buffer);
+if (res != AMF_OK)
+{
+av_frame_free(&frame_ref);
+surface->pVtbl->Release(surface);
+av_log(avctx, AV_LOG_WARNING, "failed to attach av_frame_ref 
to surface\n");
+return AVERROR(ENOMEM);
+}
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
"SetProperty failed for \"frame_ref\" with error %d\n", res);
 } else {
 res = ctx->context->pVtbl->AllocSurface(ctx->context, 
AMF_MEMORY_HOST, ctx->format, avctx->width, avctx->height, &surface);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
"AllocSurface() failed  with error %d\n", res);
@@ -554,12 +613,27 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 res_query = ctx->encoder->pVtbl->QueryOutput(ctx->encoder, &data);
 if (data) {
 // copy data to packet
-AMFBuffer* buffer;
-AMFGuid guid = IID_AMFBuffer();
-data->pVtbl->QueryInterface(data, &guid, (void**)&buffer); // 
query for buffer interface
+AMFBuffer *buffer;
+AMF_AV_QUERY_INTERFACE(res, data, AMFBuffer, buffer);
+AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "Invalid 
data type from encoder->QueryOutput, should be AMFBuffer, error %d\n", res);
 

[FFmpeg-devel] [PATCH] lavc/amfenc: Reference to input AVFrame (hwaccel) is retained during the encoding process

2018-03-28 Thread Alexander Kravchenko
Hello.
I fixed couple of issues in previous patch.
So if it is possible to use newer one, could you please review the following 
patch.


Subject: amfenc: Retain a reference to D3D frames used as input during the 
encoding process
---
libavcodec/amfenc.c | 91 +
 1 file changed, 91 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 89a10ff253..4a8385f9e2 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -443,6 +443,75 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 return ret;
 }
 
+#define AMF_AV_QUERY_INTERFACE(res, from, InterfaceTypeTo, to) \
+{ \
+AMFGuid guid_##InterfaceTypeTo = IID_##InterfaceTypeTo(); \
+res = from->pVtbl->QueryInterface(from, &guid_##InterfaceTypeTo, 
(void**)&to); \
+}
+
+#define AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, pThis, name, val) \
+{ \
+AMFInterface *amf_interface; \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+if (res == AMF_OK) { \
+AMF_AV_QUERY_INTERFACE(res, val, AMFInterface, amf_interface)\
+} \
+if (res == AMF_OK) { \
+res = AMFVariantAssignInterface(&var, amf_interface); \
+amf_interface->pVtbl->Release(amf_interface); \
+} \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->SetProperty(pThis, name, var); \
+} \
+AMFVariantClear(&var); \
+}
+
+#define AMF_AV_GET_PROPERTY_INTERFACE(res, pThis, name, TargetType, val) \
+{ \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res != AMF_OK) \
+return res; \
+res = pThis->pVtbl->GetProperty(pThis, name, &var); \
+if (res == AMF_OK) { \
+if (var.type == AMF_VARIANT_INTERFACE && 
AMFVariantInterface(&var)) { \
+AMF_AV_QUERY_INTERFACE(res, AMFVariantInterface(&var), 
TargetType, val); \
+} else { \
+res = AMF_INVALID_DATA_TYPE; \
+} \
+} \
+AMFVariantClear(&var); \
+}
+
+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), &frame_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), 
&frame_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(&av_frame_ref, 
frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
sizeof(av_frame_ref));
+av_frame_free(&av_frame_ref);
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+} 
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -484,6 +553,7 @@ 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
@@ -496,6 +566,16 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 // input HW surfaces can be vertically aligned by 16; tell AMF the 
real size
 surface->pVtbl->SetCrop(surface, 0, 0, frame->width, 
frame->height);
 #endif
+
+frame_ref_storage_buffer = amf_create_buffer_with_frame_ref(frame, 
ctx->context);
+AMF_RETURN_IF_FALSE(ctx, frame_ref_storage_buffer != NULL, 
AVERROR(ENOMEM), "create_buffer_with_frame_ref() returned NULL\n");
+
+AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, surface, L"av_frame_ref", 
frame_ref_storage_buffer);
+if (res != AMF_OK) {
+surface->pVtbl->Release(surface);
+}
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
"SetProperty failed for \"av_frame_ref\" with error %d\n", res);
 } else {
 res = ctx->context->pVtbl->AllocSurface(ctx->context, 
AMF_MEMORY_HOST, ctx->format, avctx->width, avctx->height, &surface);
 AMF_RETURN_IF_FAL

[FFmpeg-devel] [PATCH] lavc/amfenc: Reference to input AVFrame (hwaccel) is retained during the encoding process

2018-04-02 Thread Alexander Kravchenko
Hello, Mark,
Did you have a chance to review the latest version patch?

Thanks,
Alexander

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


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

2018-04-05 Thread Alexander Kravchenko

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:
ffmpeg.exe -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.h264  -an 
-c:v h264_amf output.mkv

Previous questions and answers
> How many frames can end up queued inside the encoder here?
16

> Is there always an exact 1->1 correspondence between input frames and output 
> packets?  That is, is it guaranteed that no frames
are
> ever dropped, even in the low-latency modes?
yes

> These look even more like they should be functions rather than macros now?  
> In particular, the returns in them interact badly with
the code below.
Macroses were used because they works with different types. I have removed 
returns from them (sorry, I missed this comment).

---
 libavcodec/amfenc.c | 89 +
 1 file changed, 89 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 89a10ff253..084b06e56d 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -443,6 +443,73 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 return ret;
 }
 
+#define AMF_AV_QUERY_INTERFACE(res, from, InterfaceTypeTo, to) \
+{ \
+AMFGuid guid_##InterfaceTypeTo = IID_##InterfaceTypeTo(); \
+res = from->pVtbl->QueryInterface(from, &guid_##InterfaceTypeTo, 
(void**)&to); \
+}
+
+#define AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, pThis, name, val) \
+{ \
+AMFInterface *amf_interface; \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res == AMF_OK) { \
+AMF_AV_QUERY_INTERFACE(res, val, AMFInterface, amf_interface)\
+if (res == AMF_OK) { \
+res = AMFVariantAssignInterface(&var, amf_interface); \
+amf_interface->pVtbl->Release(amf_interface); \
+} \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->SetProperty(pThis, name, var); \
+} \
+AMFVariantClear(&var); \
+}\
+}
+
+#define AMF_AV_GET_PROPERTY_INTERFACE(res, pThis, name, TargetType, val) \
+{ \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->GetProperty(pThis, name, &var); \
+if (res == AMF_OK) { \
+if (var.type == AMF_VARIANT_INTERFACE && 
AMFVariantInterface(&var)) { \
+AMF_AV_QUERY_INTERFACE(res, AMFVariantInterface(&var), 
TargetType, val); \
+} else { \
+res = AMF_INVALID_DATA_TYPE; \
+} \
+} \
+AMFVariantClear(&var); \
+}\
+}
+
+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), &frame_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), 
&frame_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(&av_frame_ref, 
frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
sizeof(av_frame_ref));
+av_frame_free(&av_frame_ref);
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+} 
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -484,6 +551,7 @@ 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
@@ -496,6 +564,16 @@ int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame 
*frame)
 // input HW surfaces can be vertically aligned by 16; tell AMF the 
real size
 surface->pVtbl->SetCrop(surface, 0, 0, frame->width, 
frame->height);
 #endif
+
+frame_ref_storage_buffer = amf_create_buffer_with_frame_ref(frame, 
ctx->context);
+AMF_RETURN_IF_FALSE(ctx, frame_ref_storage_buffer != NULL, 
AVERROR(ENOMEM), "create_buffer_with_frame_ref() returned
NULL\n");
+

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

2018-04-05 Thread Alexander Kravchenko
> 
> This breaks the testcase described in
> https://trac.ffmpeg.org/ticket/6990 which is basically the same as the
> one you described in this patch.
> 
> I get the following spammed repeatedly:
> 
> [AVHWFramesContext @ 0502d340] Static surface pool size exceeded.
> [mpeg2video @ 02f8d400] get_buffer() failed
> [mpeg2video @ 02f8d400] thread_get_buffer() failed
> [mpeg2video @ 02f8d400] get_buffer() failed (-12 )
> Error while decoding stream #0:1: Operation not permitted

Hi,
I have checked the test, it causes such error because dxva decoder allocates 
small pool size for input of AV_CODEC_ID_MPEG2VIDEO

Option  "-extra_hw_frames 16" solves this problem.

I have checked test using the following command line. Result video looks ok 
comparing to original video.
./ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -extra_hw_frames 12 -i 
matrixbench_mpeg2.mpg -an -c:v h264_amf out.mkv

I have found the logic in dxva.c which sets initial pool size
/* add surfaces based on number of possible refs */
if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == 
AV_CODEC_ID_HEVC)
num_surfaces += 16;
else if (avctx->codec_id == AV_CODEC_ID_VP9)
num_surfaces += 8;
else
num_surfaces += 2;
...
frames_ctx->initial_pool_size = num_surfaces;

There is alternative way to solve this problem, such as using copy surface 
before submitting to encoder, but this scenario will spend additional resources.

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


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

2018-04-06 Thread Alexander Kravchenko
> 
> This breaks the testcase described in
> https://trac.ffmpeg.org/ticket/6990 which is basically the same as the
> one you described in this patch.
> 
> I get the following spammed repeatedly:
> 
> [AVHWFramesContext @ 0502d340] Static surface pool size exceeded.
> [mpeg2video @ 02f8d400] get_buffer() failed
> [mpeg2video @ 02f8d400] thread_get_buffer() failed
> [mpeg2video @ 02f8d400] get_buffer() failed (-12 )
> Error while decoding stream #0:1: Operation not permitted

Hi, could you please review the following updated patch
I added queue limit according initial pool size of incoming frame context.
This solves the problem running this pipeline without -extra_hw_frames 16 
option, but -extra_hw_frames option can be used to have bigger queue for 
encoder.


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

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 89a10ff253..eb7b20c252 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -157,6 +157,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 );
@@ -187,6 +190,7 @@ static int amf_init_context(AVCodecContext *avctx)
 if (!ctx->hw_frames_ctx) {
 return AVERROR(ENOMEM);
 }
+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");
@@ -443,6 +447,73 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 return ret;
 }
 
+#define AMF_AV_QUERY_INTERFACE(res, from, InterfaceTypeTo, to) \
+{ \
+AMFGuid guid_##InterfaceTypeTo = IID_##InterfaceTypeTo(); \
+res = from->pVtbl->QueryInterface(from, &guid_##InterfaceTypeTo, 
(void**)&to); \
+}
+
+#define AMF_AV_ASSIGN_PROPERTY_INTERFACE(res, pThis, name, val) \
+{ \
+AMFInterface *amf_interface; \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res == AMF_OK) { \
+AMF_AV_QUERY_INTERFACE(res, val, AMFInterface, amf_interface)\
+if (res == AMF_OK) { \
+res = AMFVariantAssignInterface(&var, amf_interface); \
+amf_interface->pVtbl->Release(amf_interface); \
+} \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->SetProperty(pThis, name, var); \
+} \
+AMFVariantClear(&var); \
+}\
+}
+
+#define AMF_AV_GET_PROPERTY_INTERFACE(res, pThis, name, TargetType, val) \
+{ \
+AMFVariantStruct var; \
+res = AMFVariantInit(&var); \
+if (res == AMF_OK) { \
+res = pThis->pVtbl->GetProperty(pThis, name, &var); \
+if (res == AMF_OK) { \
+if (var.type == AMF_VARIANT_INTERFACE && 
AMFVariantInterface(&var)) { \
+AMF_AV_QUERY_INTERFACE(res, AMFVariantInterface(&var), 
TargetType, val); \
+} else { \
+res = AMF_INVALID_DATA_TYPE; \
+} \
+} \
+AMFVariantClear(&var); \
+}\
+}
+
+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), &frame_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), 
&frame_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(&av_frame_ref, 
frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
sizeof(av_frame_ref));
+av_frame_free(&av_frame_ref);
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+} 
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -484,6 +555,7 @@ int ff_amf_send_frame(AVCodecContext *a

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

2018-04-06 Thread Alexander Kravchenko

> >> This breaks the testcase described in
> >> https://trac.ffmpeg.org/ticket/6990 which is basically the same as the
> >> one you described in this patch.
> >>
> >> I get the following spammed repeatedly:
> >>
> >> [AVHWFramesContext @ 0502d340] Static surface pool size exceeded.
> >> [mpeg2video @ 02f8d400] get_buffer() failed
> >> [mpeg2video @ 02f8d400] thread_get_buffer() failed
> >> [mpeg2video @ 02f8d400] get_buffer() failed (-12 )
> >> Error while decoding stream #0:1: Operation not permitted
> >
> > Hi, could you please review the following updated patch
> > I added queue limit according initial pool size of incoming frame context.
> > This solves the problem running this pipeline without -extra_hw_frames 16 
> > option, but -extra_hw_frames option can be used to
> have bigger queue for encoder.
> 
> Yes, this solves it, and the output does indeed look good now. Thanks.
> 
> I'll leave reviewing this patch to someone more familiar with hw encoding.
Thanks, James.

I think the following approaches could help to solve issues with pool size more 
flexible way
1) communication between decoder and the following frame consumer component 
(filter or encoder) about extra frames requirement in hw frame pool.
2) add function like av_buffer_pool_test(AVBufferPool *pool); which returns 
current status of pool (used/free frames count). 

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


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

2018-04-08 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Mark Thompson
> Sent: Sunday, April 8, 2018 8:25 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: Retain a reference to D3D
> frames used as input during the encoding process
> 
> On 06/04/18 11:25, Alexander Kravchenko wrote:
> >>
> >> This breaks the testcase described in
> >> https://trac.ffmpeg.org/ticket/6990 which is basically the same as
> >> the one you described in this patch.
> >>
> >> I get the following spammed repeatedly:
> >>
> >> [AVHWFramesContext @ 0502d340] Static surface pool size
> exceeded.
> >> [mpeg2video @ 02f8d400] get_buffer() failed [mpeg2video @
> >> 02f8d400] thread_get_buffer() failed [mpeg2video @
> >> 02f8d400] get_buffer() failed (-12 ) Error
> >> while decoding stream #0:1: Operation not permitted
> >
> > Hi, could you please review the following updated patch I added queue
> > limit according initial pool size of incoming frame context.
> > This solves the problem running this pipeline without -extra_hw_frames 16
> option, but -extra_hw_frames option can be used to have bigger queue for
> encoder.
> 
> I think you've misunderstood /why/ the decoder has the pool size allocation
> that it does.  The decoder expects to use all of the surfaces it has 
> allocated in
> the worst case - the difference between MPEG-2 and H.264 is that MPEG-2
> can store at most two reference frames (the forward and backward
> references for B-frames), while H.264 can store up to sixteen.  Most H.264
> streams don't use all sixteen references, but in theory they could (excepting
> level restrictions, but they are generally quite iffy) so the decoder 
> allocates
> space for all of those references even if they aren't used.
> 
> I can believe that this patch happens to work if you have a simple stream
> with limited references (streams rarely use more than two or three), but it
> will certainly fail exactly as before for complex streams.
> 
> If you want to hold onto more than one frame in the encoder then currently
> you need to use the -extra_hw_frames option on the source (whether
> decoder or filter) - that is exactly what it's there for.  Some sort of 
> automatic
> negotiation is suggested (there was some discussion on libav-devel a while
> ago), but the requirement that it works through libavfilter is a difficult one
> with the current structure so nothing concrete is yet proposed.  (That was
> mostly considering libmfx, where it's even more of a problem because the
> lookahead options can make the encoder queue over a hundred frames
> internally.)
> 
> > ---
> >  libavcodec/amfenc.c | 97
> > -
> >  libavcodec/amfenc.h |  3 ++
> >  2 files changed, 99 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index
> > 89a10ff253..eb7b20c252 100644
> > --- a/libavcodec/amfenc.c
> > +++ b/libavcodec/amfenc.c
> > @@ -157,6 +157,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 ); @@ -187,6
> +190,7 @@ static int amf_init_context(AVCodecContext *avctx)
> >  if (!ctx->hw_frames_ctx) {
> >  return AVERROR(ENOMEM);
> >  }
> > +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"); @@ -443,6 +447,73 @@ int
> ff_amf_encode_init(AVCodecContext *avctx)
> >  return ret;
> >  }
> >
> > +#define AMF_AV_QUERY_INTERFACE(res, from, InterfaceTypeTo, to) \
> > +{ \
> > +AMFGuid guid_##InterfaceTypeTo = IID_##InterfaceTypeTo(); \
> > +res = from->pVtbl->QueryInte

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

2018-04-09 Thread Alexander Kravchenko
Hi, could you please review updated patch?

Fixes according on Mark's review:
* Macroses changed to functions
* error level of AMF_RETURN_IF_FALSE changed to fatal (all cases it returns are 
fatal according on fatal error level description)
* used AMF_RETURN_IF_FALSE for case if a frame reference has been completely 
lost (was just warning before)

Hopefully this patch is ok enough to be applied :).
FYI, near time I am going to send the following patches 
* cosmetic fixes
* hwcontext_amf (to be reused in encoder and color space converter)
* AMF colors space converter (input memory types: opencl, dx9, dx11, host; 
output memory types: opencl, dx9, dx11)


---
 libavcodec/amfenc.c | 94 -
 libavcodec/amfenc.h |  5 ++-
 2 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 89a10ff253..ea2c5acbbf 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -157,6 +157,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 );
@@ -187,6 +190,7 @@ static int amf_init_context(AVCodecContext *avctx)
 if (!ctx->hw_frames_ctx) {
 return AVERROR(ENOMEM);
 }
+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");
@@ -443,6 +447,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(&var);
+if (res == AMF_OK) {
+AMFGuid guid_AMFInterface = IID_AMFInterface();
+AMFInterface *amf_interface;
+res = val->pVtbl->QueryInterface(val, &guid_AMFInterface, 
(void**)&amf_interface);
+
+if (res == AMF_OK) {
+res = AMFVariantAssignInterface(&var, amf_interface);
+amf_interface->pVtbl->Release(amf_interface);
+}
+if (res == AMF_OK) {
+res = object->pVtbl->SetProperty(object, name, var);
+}
+AMFVariantClear(&var);
+}
+return res;
+}
+
+static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t 
*name, AMFBuffer **val)
+{
+AMF_RESULT res;
+AMFVariantStruct var;
+res = AMFVariantInit(&var);
+if (res == AMF_OK) {
+res = object->pVtbl->GetProperty(object, name, &var);
+if (res == AMF_OK) {
+if (var.type == AMF_VARIANT_INTERFACE) {
+AMFGuid guid_AMFBuffer = IID_AMFBuffer();
+AMFInterface *amf_interface = AMFVariantInterface(&var);
+res = amf_interface->pVtbl->QueryInterface(amf_interface, 
&guid_AMFBuffer, (void**)val);
+} else {
+res = AMF_INVALID_DATA_TYPE;
+}
+}
+AMFVariantClear(&var);
+}
+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), &frame_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), 
&frame_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(&av_frame_ref, 
frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
sizeof(av_frame_ref));
+av_frame_free(&av_frame_ref);
+frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+} 
 
 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
@@ -484,6 +557,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

[FFmpeg-devel] [PATCH] lavc/amfenc: device type AV_HWDEVICE_TYPE_DXVA2 support

2018-04-11 Thread Alexander Kravchenko

---
 libavcodec/amfenc.c | 123
+++-
 1 file changed, 102 insertions(+), 21 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index b9418b6791..c1f65f909d 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -24,6 +24,9 @@
 #if CONFIG_D3D11VA
 #include "libavutil/hwcontext_d3d11va.h"
 #endif
+#if CONFIG_DXVA2
+#include "libavutil/hwcontext_dxva2.h"
+#endif
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -50,6 +53,9 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_YUV420P,
 #if CONFIG_D3D11VA
 AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
 #endif
 AV_PIX_FMT_NONE
 };
@@ -69,6 +75,7 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
 { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
 { AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_DXVA2_VLD,  AMF_SURFACE_NV12 },
 };
 
 
@@ -152,6 +159,23 @@ static int amf_load_library(AVCodecContext *avctx)
 return 0;
 }
 
+static void get_dx9_device_from_devmgr(IDirect3DDeviceManager9 *devmgr,
IDirect3DDevice9 **device, void *avcl)
+{
+HRESULT hr;
+HANDLE device_handle;
+
+if (SUCCEEDED(devmgr->lpVtbl->OpenDeviceHandle(devmgr,
&device_handle))) {
+if (SUCCEEDED(devmgr->lpVtbl->LockDevice(devmgr, device_handle,
device, FALSE))) {
+devmgr->lpVtbl->UnlockDevice(devmgr, device_handle, FALSE);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to lock device handle for
Direct3D9 device: %lx.\n", (unsigned long)hr);
+}
+devmgr->lpVtbl->CloseDeviceHandle(devmgr, device_handle);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to open device handle for
Direct3D9 device: %lx.\n", (unsigned long)hr);
+}
+}
+
 static int amf_init_context(AVCodecContext *avctx)
 {
 AmfContext *ctx = avctx->priv_data;
@@ -177,34 +201,58 @@ static int amf_init_context(AVCodecContext *avctx)
 res = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN,
"CreateContext() failed with error %d\n", res);
 // try to reuse existing DX device
-#if CONFIG_D3D11VA
 if (avctx->hw_frames_ctx) {
-AVHWFramesContext *device_ctx =
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
-if (device_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
-if (amf_av_to_amf_format(device_ctx->sw_format) !=
AMF_SURFACE_UNKNOWN) {
-if (device_ctx->device_ctx->hwctx) {
-AVD3D11VADeviceContext *device_d3d11 =
(AVD3D11VADeviceContext *)device_ctx->device_ctx->hwctx;
+AVHWFramesContext *frames_ctx =
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
+if (amf_av_to_amf_format(frames_ctx->sw_format) !=
AMF_SURFACE_UNKNOWN) {
+if (frames_ctx->device_ctx->hwctx) {
+#if CONFIG_D3D11VA
+if (frames_ctx->device_ctx->type ==
AV_HWDEVICE_TYPE_D3D11VA) {
+AVD3D11VADeviceContext *device_d3d11 =
(AVD3D11VADeviceContext *)frames_ctx->device_ctx->hwctx;
 res = ctx->context->pVtbl->InitDX11(ctx->context,
device_d3d11->device, AMF_DX11_1);
 if (res == AMF_OK) {
 ctx->hw_frames_ctx =
av_buffer_ref(avctx->hw_frames_ctx);
 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;
+if (frames_ctx->initial_pool_size > 0)
+ctx->hwsurfaces_in_queue_max =
frames_ctx->initial_pool_size - 1;
 } else {
-if(res == AMF_NOT_SUPPORTED)
+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");
 else
 av_log(avctx, AV_LOG_INFO,
"avctx->hw_frames_ctx has non-AMD device, switching to default\n");
 }
 }
-} else {
-av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has format
not uspported by AMF, switching to default\n");
+#endif
+#if CONFIG_DXVA2
+if (frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_DXVA2)
{
+AVDXVA2DeviceContext *device_dxva2 =
(AVDXVA2DeviceContext *)frames_ctx->device_ctx->hwctx;
+IDirect3DDevice9 *device_dx9 = NULL;
+get_dx9_device_from_devmgr(device_dxva2->devmgr,
&device_dx9, avctx);
+res = ctx->context->pVtbl->InitDX9(ctx->context,
device_dx9);
+device_dx9->lpVtbl->Rele

Re: [FFmpeg-devel] [PATCH] lavc/amfenc: device type AV_HWDEVICE_TYPE_DXVA2 support

2018-04-11 Thread Alexander Kravchenko
Resending patch (mailer mangled the patch)

---
 libavcodec/amfenc.c | 123 +++-
 1 file changed, 102 insertions(+), 21 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index b9418b6791..c1f65f909d 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -24,6 +24,9 @@
 #if CONFIG_D3D11VA
 #include "libavutil/hwcontext_d3d11va.h"
 #endif
+#if CONFIG_DXVA2
+#include "libavutil/hwcontext_dxva2.h"
+#endif
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -50,6 +53,9 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_YUV420P,
 #if CONFIG_D3D11VA
 AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
 #endif
 AV_PIX_FMT_NONE
 };
@@ -69,6 +75,7 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
 { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
 { AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_DXVA2_VLD,  AMF_SURFACE_NV12 },
 };
 
 
@@ -152,6 +159,23 @@ static int amf_load_library(AVCodecContext *avctx)
 return 0;
 }
 
+static void get_dx9_device_from_devmgr(IDirect3DDeviceManager9 *devmgr, 
IDirect3DDevice9 **device, void *avcl)
+{
+HRESULT hr;
+HANDLE device_handle;
+
+if (SUCCEEDED(devmgr->lpVtbl->OpenDeviceHandle(devmgr, &device_handle))) {
+if (SUCCEEDED(devmgr->lpVtbl->LockDevice(devmgr, device_handle, 
device, FALSE))) {
+devmgr->lpVtbl->UnlockDevice(devmgr, device_handle, FALSE);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to lock device handle for 
Direct3D9 device: %lx.\n", (unsigned long)hr);
+}
+devmgr->lpVtbl->CloseDeviceHandle(devmgr, device_handle);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to open device handle for Direct3D9 
device: %lx.\n", (unsigned long)hr);
+}
+}
+
 static int amf_init_context(AVCodecContext *avctx)
 {
 AmfContext *ctx = avctx->priv_data;
@@ -177,34 +201,58 @@ static int amf_init_context(AVCodecContext *avctx)
 res = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext() 
failed with error %d\n", res);
 // try to reuse existing DX device
-#if CONFIG_D3D11VA
 if (avctx->hw_frames_ctx) {
-AVHWFramesContext *device_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
-if (device_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
-if (amf_av_to_amf_format(device_ctx->sw_format) != 
AMF_SURFACE_UNKNOWN) {
-if (device_ctx->device_ctx->hwctx) {
-AVD3D11VADeviceContext *device_d3d11 = 
(AVD3D11VADeviceContext *)device_ctx->device_ctx->hwctx;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
+if (amf_av_to_amf_format(frames_ctx->sw_format) != 
AMF_SURFACE_UNKNOWN) {
+if (frames_ctx->device_ctx->hwctx) {
+#if CONFIG_D3D11VA
+if (frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
+AVD3D11VADeviceContext *device_d3d11 = 
(AVD3D11VADeviceContext *)frames_ctx->device_ctx->hwctx;
 res = ctx->context->pVtbl->InitDX11(ctx->context, 
device_d3d11->device, AMF_DX11_1);
 if (res == AMF_OK) {
 ctx->hw_frames_ctx = 
av_buffer_ref(avctx->hw_frames_ctx);
 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;
+if (frames_ctx->initial_pool_size > 0)
+ctx->hwsurfaces_in_queue_max = 
frames_ctx->initial_pool_size - 1;
 } else {
-if(res == AMF_NOT_SUPPORTED)
+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");
 else
 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
has non-AMD device, switching to default\n");
 }
 }
-} else {
-av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has format 
not uspported by AMF, switching to default\n");
+#endif
+#if CONFIG_DXVA2
+if (frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) {
+AVDXVA2DeviceContext *device_dxva2 = (AVDXVA2DeviceContext 
*)frames_ctx->device_ctx->hwctx;
+IDirect3DDevice9 *device_dx9 = NULL;
+get_dx9_device_from_devmgr(device_dxva2->devmgr, 
&device_dx9, avctx);
+res = ctx->context->pVtbl->InitDX9(ctx->cont

Re: [FFmpeg-devel] [PATCH] lavc/amfenc: device type AV_HWDEVICE_TYPE_DXVA2 support

2018-04-11 Thread Alexander Kravchenko
I am sorry, sending patch one more time. Outlook was wrapping text.
Sending patch in message body and in attachment

---
 libavcodec/amfenc.c | 123 +++-
 1 file changed, 102 insertions(+), 21 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index b9418b6791..c1f65f909d 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -24,6 +24,9 @@
 #if CONFIG_D3D11VA
 #include "libavutil/hwcontext_d3d11va.h"
 #endif
+#if CONFIG_DXVA2
+#include "libavutil/hwcontext_dxva2.h"
+#endif
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -50,6 +53,9 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_YUV420P,
 #if CONFIG_D3D11VA
 AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
 #endif
 AV_PIX_FMT_NONE
 };
@@ -69,6 +75,7 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
 { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
 { AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_DXVA2_VLD,  AMF_SURFACE_NV12 },
 };
 
 
@@ -152,6 +159,23 @@ static int amf_load_library(AVCodecContext *avctx)
 return 0;
 }
 
+static void get_dx9_device_from_devmgr(IDirect3DDeviceManager9 *devmgr, 
IDirect3DDevice9 **device, void *avcl)
+{
+HRESULT hr;
+HANDLE device_handle;
+
+if (SUCCEEDED(devmgr->lpVtbl->OpenDeviceHandle(devmgr, &device_handle))) {
+if (SUCCEEDED(devmgr->lpVtbl->LockDevice(devmgr, device_handle, 
device, FALSE))) {
+devmgr->lpVtbl->UnlockDevice(devmgr, device_handle, FALSE);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to lock device handle for 
Direct3D9 device: %lx.\n", (unsigned long)hr);
+}
+devmgr->lpVtbl->CloseDeviceHandle(devmgr, device_handle);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to open device handle for Direct3D9 
device: %lx.\n", (unsigned long)hr);
+}
+}
+
 static int amf_init_context(AVCodecContext *avctx)
 {
 AmfContext *ctx = avctx->priv_data;
@@ -177,34 +201,58 @@ static int amf_init_context(AVCodecContext *avctx)
 res = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext() 
failed with error %d\n", res);
 // try to reuse existing DX device
-#if CONFIG_D3D11VA
 if (avctx->hw_frames_ctx) {
-AVHWFramesContext *device_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
-if (device_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
-if (amf_av_to_amf_format(device_ctx->sw_format) != 
AMF_SURFACE_UNKNOWN) {
-if (device_ctx->device_ctx->hwctx) {
-AVD3D11VADeviceContext *device_d3d11 = 
(AVD3D11VADeviceContext *)device_ctx->device_ctx->hwctx;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
+if (amf_av_to_amf_format(frames_ctx->sw_format) != 
AMF_SURFACE_UNKNOWN) {
+if (frames_ctx->device_ctx->hwctx) {
+#if CONFIG_D3D11VA
+if (frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
+AVD3D11VADeviceContext *device_d3d11 = 
(AVD3D11VADeviceContext *)frames_ctx->device_ctx->hwctx;
 res = ctx->context->pVtbl->InitDX11(ctx->context, 
device_d3d11->device, AMF_DX11_1);
 if (res == AMF_OK) {
 ctx->hw_frames_ctx = 
av_buffer_ref(avctx->hw_frames_ctx);
 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;
+if (frames_ctx->initial_pool_size > 0)
+ctx->hwsurfaces_in_queue_max = 
frames_ctx->initial_pool_size - 1;
 } else {
-if(res == AMF_NOT_SUPPORTED)
+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");
 else
 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
has non-AMD device, switching to default\n");
 }
 }
-} else {
-av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has format 
not uspported by AMF, switching to default\n");
+#endif
+#if CONFIG_DXVA2
+if (frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) {
+AVDXVA2DeviceContext *device_dxva2 = (AVDXVA2DeviceContext 
*)frames_ctx->device_ctx->hwctx;
+IDirect3DDevice9 *device_dx9 = NULL;
+get_dx9_device_from_devmgr(device_dxva2->devmgr, 
&device_dx9, 

[FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-12 Thread Alexander Kravchenko

This patch contains DXVA2 textures support implementation by AMF encoder (in 
addition of D3D11 textures)

Samples of usage:
DXVA2 decoder -> dxva2_vld texture -> AMF Encoder:
ffmpeg -hwaccel dxva2 -hwaccel_output_format dxva2_vld -extra_hw_frames 16 -i 
input.mp4 -an -c:v h264_amf out.mkv

D3D11va decoder -> d3d11 texture -> AMF Encoder:
ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -extra_hw_frames 16 -i 
input.mp4 -an -c:v h264_amf out.mkv


---
 libavcodec/amfenc.c | 123 +++-
 1 file changed, 102 insertions(+), 21 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index b9418b6791..c1f65f909d 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -24,6 +24,9 @@
 #if CONFIG_D3D11VA
 #include "libavutil/hwcontext_d3d11va.h"
 #endif
+#if CONFIG_DXVA2
+#include "libavutil/hwcontext_dxva2.h"
+#endif
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -50,6 +53,9 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_YUV420P,
 #if CONFIG_D3D11VA
 AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
 #endif
 AV_PIX_FMT_NONE
 };
@@ -69,6 +75,7 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
 { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
 { AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_DXVA2_VLD,  AMF_SURFACE_NV12 },
 };
 
 
@@ -152,6 +159,23 @@ static int amf_load_library(AVCodecContext *avctx)
 return 0;
 }
 
+static void get_dx9_device_from_devmgr(IDirect3DDeviceManager9 *devmgr, 
IDirect3DDevice9 **device, void *avcl)
+{
+HRESULT hr;
+HANDLE device_handle;
+
+if (SUCCEEDED(devmgr->lpVtbl->OpenDeviceHandle(devmgr, &device_handle))) {
+if (SUCCEEDED(devmgr->lpVtbl->LockDevice(devmgr, device_handle, 
device, FALSE))) {
+devmgr->lpVtbl->UnlockDevice(devmgr, device_handle, FALSE);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to lock device handle for 
Direct3D9 device: %lx.\n", (unsigned long)hr);
+}
+devmgr->lpVtbl->CloseDeviceHandle(devmgr, device_handle);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to open device handle for Direct3D9 
device: %lx.\n", (unsigned long)hr);
+}
+}
+
 static int amf_init_context(AVCodecContext *avctx)
 {
 AmfContext *ctx = avctx->priv_data;
@@ -177,34 +201,58 @@ static int amf_init_context(AVCodecContext *avctx)
 res = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext() 
failed with error %d\n", res);
 // try to reuse existing DX device
-#if CONFIG_D3D11VA
 if (avctx->hw_frames_ctx) {
-AVHWFramesContext *device_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
-if (device_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
-if (amf_av_to_amf_format(device_ctx->sw_format) != 
AMF_SURFACE_UNKNOWN) {
-if (device_ctx->device_ctx->hwctx) {
-AVD3D11VADeviceContext *device_d3d11 = 
(AVD3D11VADeviceContext *)device_ctx->device_ctx->hwctx;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
+if (amf_av_to_amf_format(frames_ctx->sw_format) != 
AMF_SURFACE_UNKNOWN) {
+if (frames_ctx->device_ctx->hwctx) {
+#if CONFIG_D3D11VA
+if (frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
+AVD3D11VADeviceContext *device_d3d11 = 
(AVD3D11VADeviceContext *)frames_ctx->device_ctx->hwctx;
 res = ctx->context->pVtbl->InitDX11(ctx->context, 
device_d3d11->device, AMF_DX11_1);
 if (res == AMF_OK) {
 ctx->hw_frames_ctx = 
av_buffer_ref(avctx->hw_frames_ctx);
 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;
+if (frames_ctx->initial_pool_size > 0)
+ctx->hwsurfaces_in_queue_max = 
frames_ctx->initial_pool_size - 1;
 } else {
-if(res == AMF_NOT_SUPPORTED)
+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");
 else
 av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx 
has non-AMD device, switching to default\n");
 }
 }
-} else {
-av_log(avctx, AV_LOG_INFO, "avctx->hw_frames_ctx has format 
not uspported by AMF, switching to default\n");
+#endif
+#if CONFIG_D

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

2018-04-12 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Wednesday, April 11, 2018 2:13 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: Retain a reference to D3D 
> frames used as input during the encoding process
> 

> 
> Two minor points below, not enough to merit another cycle so I fixed them and 
> pushed.
> 

Hi Mark,
Thanks for your help reviewing, fixing, and pushing patch

I have send one more patch with subject: [PATCH] lavc/amfenc: DXVA2 textures 
support implementation by AMF encoder
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-April/228186.html

Could you please review it?

FYI, my next steps are:
* hwcontext_amf + apply using one in amfenc.
* vf_scale_amf
* code cleanup

Thanks,
Alexander

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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-12 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Carl 
> Eugen Hoyos
> Sent: Friday, April 13, 2018 12:48 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
> implementation by AMF encoder
> 
> 2018-04-12 23:42 GMT+02:00, Alexander Kravchenko :
> >
> > This patch contains DXVA2 textures support implementation by AMF
> > encoder (in addition of D3D11 textures)
> 
> > +if (frames_ctx->device_ctx->hwctx) { #if CONFIG_D3D11VA
> > +if (frames_ctx->device_ctx->type ==
> > AV_HWDEVICE_TYPE_D3D11VA) {
> 
> if (CONFIG_D3D11VA && frames_ctx->device_ctx->type ==...
> 
> same below.
> 

Hi Carl, thanks for your feedback

Could you explain the reason replacing
if (frames_ctx->device_ctx->type ==
to
if (CONFIG_D3D11VA && frames_ctx->device_ctx->type ==
in code like:

#if CONFIG_DXVA2
#include "libavutil/hwcontext_dxva2.h"
#endif
//...
#if CONFIG_D3D11VA
if (frames_ctx->device_ctx->type ==...
//code required include libavutil/hwcontext_dxva2.h"
#endif


Thanks,
Alexander

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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: device type AV_HWDEVICE_TYPE_DXVA2 support

2018-04-12 Thread Alexander Kravchenko
Thread was moved to
[FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by 
AMF encoder


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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: device type AV_HWDEVICE_TYPE_DXVA2 support

2018-04-12 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Friday, April 13, 2018 1:27 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: device type 
> AV_HWDEVICE_TYPE_DXVA2 support
> 
> 
> Tested on Windows 7, works well.  Unlike with D3D11 the OpenCL interop works 
> properly as well, so e.g. -vf
> 'hwmap=derive_device=opencl,convolution_opencl=0 1 0 1 -4 1 0 1 
> 0,hwmap=derive_device=dxva2:reverse=1:extra_hw_frames=16'
> as encoder input works too.
> 
> Thanks,
> 
> - Mark


Hi Mark, 
sorry if I confused you
I have moved the thread to
 [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by 
AMF encoder
With the same code patch, but with different subject and with sample of usage.

I will fix code according your feedback and send the new patch there if you 
don’t mind

Thanks,
Alexander

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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-12 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Carl 
> Eugen Hoyos
> Sent: Friday, April 13, 2018 1:24 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
> implementation by AMF encoder
> 
> 
> The code gets more readable / less ugly.
> 

Hi Carl,
Is this the common practice? Any recommendations somewhere?

IMHO it does not help reading code, but may confuse and make code researcher to 
spend time trying to figure out why the macro is in condition
Also it makes condition longer

Thanks,
Alexander



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


[FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-13 Thread Alexander Kravchenko

This patch contains DXVA2 textures support implementation by AMF encoder (in 
addition of D3D11 textures)

Samples of usage:
DXVA2 decoder -> dxva2_vld texture -> AMF Encoder:
ffmpeg -hwaccel dxva2 -hwaccel_output_format dxva2_vld -extra_hw_frames 16 -i 
input.mp4 -an -c:v h264_amf out.mkv

D3D11va decoder -> d3d11 texture -> AMF Encoder:
ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -extra_hw_frames 16 -i 
input.mp4 -an -c:v h264_amf out.mkv

---
Sending updated patch (Fixes according Mark's review):
> > ---
>^
> (When adding commentary which isn't part of the commit message to an email 
> please place it after this line so that it doesn't end up in the commit 
> message.)
Done here, hopefully correctly

> >  { AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
> > +{ AV_PIX_FMT_DXVA2_VLD,  AMF_SURFACE_NV12 },
> 
> As with D3D11, this isn't necessarily true.  This was ignored before, but do 
> you have any plan for how P010 (and others?) will be handled here?
removed HW types from format map, and added logic reading pixel format from 
avctx->sw_pix_fmt in case if avctx->pix_fmt is HWACCEL type

> +static void get_dx9_device_from_devmgr(IDirect3DDeviceManager9 *devmgr, 
> IDirect3DDevice9 **device, void *avcl) {
> ...
> Might be cleaner using an error return rather than the null device?
Fixed

> Everything using D3D9 types needs to be inside CONFIG_DXVA2
Fixed

> Passing NULL here will make this case succeed in cases where it shouldn't, I 
> think?
Agree, fixed

> Tbh I don't think this fallback case should exist at all, it should just fail.
> Is there any use-case for having it?  The user passed a DXVA2 frames context 
> on a 
> non-AMD device and expects it to work with that hardware input, this fallback 
> makes 
> it kindof work with at least two copies in a way which is likely to be very 
> slow.  
> Even if the user does want to do that, it would be better for them to do it 
> explicitly 
> to ensure that they aware of the problem.  (We don't automatically do this in 
> any other case.)
Agree, fixed

> Spurious whitespace.
Fixed in changed blocks/functions

> Tested on Windows 7, works well.  
> Unlike with D3D11 the OpenCL interop works properly as well, 
> so e.g. -vf 'hwmap=derive_device=opencl,convolution_opencl=0 1 0 1 -4 1 0 1 
> 0,hwmap=derive_device=dxva2:reverse=1:extra_hw_frames=16' as encoder input 
> works too.
Could you send the samples (or link if they are published, I will add to my 
tests and will check OpenCL interop with D3D11)



 libavcodec/amfenc.c | 158 +---
 1 file changed, 126 insertions(+), 32 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index b9418b6791..7cdf17a972 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -24,6 +24,9 @@
 #if CONFIG_D3D11VA
 #include "libavutil/hwcontext_d3d11va.h"
 #endif
+#if CONFIG_DXVA2
+#include "libavutil/hwcontext_dxva2.h"
+#endif
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -50,6 +53,9 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_YUV420P,
 #if CONFIG_D3D11VA
 AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
 #endif
 AV_PIX_FMT_NONE
 };
@@ -68,7 +74,6 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
 { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
 { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
-{ AV_PIX_FMT_D3D11,  AMF_SURFACE_NV12 },
 };
 
 
@@ -152,6 +157,26 @@ static int amf_load_library(AVCodecContext *avctx)
 return 0;
 }
 
+#if CONFIG_DXVA2
+static HRESULT get_dx9_device_from_devmgr(IDirect3DDeviceManager9 *devmgr, 
IDirect3DDevice9 **device, void *avcl)
+{
+HRESULT hr;
+HANDLE device_handle;
+
+if (SUCCEEDED(hr = devmgr->lpVtbl->OpenDeviceHandle(devmgr, 
&device_handle))) {
+if (SUCCEEDED(hr = devmgr->lpVtbl->LockDevice(devmgr, device_handle, 
device, FALSE))) {
+devmgr->lpVtbl->UnlockDevice(devmgr, device_handle, FALSE);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to lock device handle for 
Direct3D9 device: %lx.\n", (unsigned long)hr);
+}
+devmgr->lpVtbl->CloseDeviceHandle(devmgr, device_handle);
+} else {
+av_log(avcl, AV_LOG_INFO, "Failed to open device handle for Direct3D9 
device: %lx.\n", (unsigned long)hr);
+}
+return hr;
+}
+#endif
+
 static int amf_init_context(AVCodecContext *avctx)
 {
 AmfContext *ctx = avctx->priv_data;
@@ -177,34 +202,61 @@ static int amf_init_context(AVCodecContext *avctx)
 res = ctx->factory->pVtbl->CreateContext(ctx->factory, &ctx->context);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext() 
failed with error %d\n", res);
 // try to reuse existing DX device
-#if CONFIG_D3D11VA
 if (avctx->hw_frames_ctx) {
-AVHWFramesContext *device_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
-if (device

Re: [FFmpeg-devel] [PATCH] lavc/amfenc: device type AV_HWDEVICE_TYPE_DXVA2 support

2018-04-13 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Friday, April 13, 2018 1:27 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: device type 
> AV_HWDEVICE_TYPE_DXVA2 support
> 

Hi Mark,
I have sent updated patch with my fixes and my comments according on your 
review in the following subject and link, 
could you please review?

Subject : [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
implementation by AMF encoder
Archive link: http://ffmpeg.org/pipermail/ffmpeg-devel/2018-April/228214.html

Thanks,
Alexander

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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-14 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Saturday, April 14, 2018 7:15 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
> implementation by AMF encoder
> 
> 
> I've sent a new set containing this patch as 3 and 4 (I split out the format 
> check part, since that doesn't have anything to do with
> DXVA2), which hopefully makes the initialisation and surface mapping setup 
> cleaner.  Would you like to look at that and comment?
> Quite a bit of stuff got moved around in the merge.
> 


Hi Mark,
I briefly read the patches, they look good
But I tried to apply them locally
The first one failed
1) I cloned ffmpeg
2) pasted patch text to file p1.patch
3) git apply p1.patch

error: patch failed: libavcodec/amfenc.c:152
error: libavcodec/amfenc.c: patch does not apply

it look like patch expexts "amf_load_library(AVCodecContext *avctx)" at line 152
@@ -152,10 +152,30 @@ static int amf_load_library(AVCodecContext *avctx)

In github
https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/amfenc.c
it is on line 155

did I miss something?

Thanks,
Alexander
 

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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-14 Thread Alexander Kravchenko


> -Original Message-
> From: Alexander Kravchenko [mailto:akravchenko...@gmail.com]
> Sent: Sunday, April 15, 2018 12:02 AM
> To: 'FFmpeg development discussions and patches' 
> Subject: RE: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
> implementation by AMF encoder
> 
> 
> 
> > -Original Message-
> > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> > Of Mark Thompson
> > Sent: Saturday, April 14, 2018 7:15 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures
> > support implementation by AMF encoder
> >
> >
> > I've sent a new set containing this patch as 3 and 4 (I split out the
> > format check part, since that doesn't have anything to do with DXVA2), 
> > which hopefully makes the initialisation and surface mapping
> setup cleaner.  Would you like to look at that and comment?
> > Quite a bit of stuff got moved around in the merge.
> >
> 
> 
> Hi Mark,
> I briefly read the patches, they look good But I tried to apply them locally 
> The first one failed
> 1) I cloned ffmpeg
> 2) pasted patch text to file p1.patch
> 3) git apply p1.patch
> 
> error: patch failed: libavcodec/amfenc.c:152
> error: libavcodec/amfenc.c: patch does not apply
> 
> it look like patch expexts "amf_load_library(AVCodecContext *avctx)" at line 
> 152 @@ -152,10 +152,30 @@ static int
> amf_load_library(AVCodecContext *avctx)
> 
> In github
> https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/amfenc.c
> it is on line 155
> 
> did I miss something?
> 
> Thanks,
> Alexander
> 

I managed to apply patch, patch was broken by Far Manager Editor.
Pasting patch text to nano solved the applying problem.

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


Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious initialisations

2018-04-14 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Saturday, April 14, 2018 6:54 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious initialisations
> 

Hi Mark,
I reviewed and tested all 5 patches in set all together.
Now the code looks cleaner.
My local tests passed for dx9 and dx11 with and without -hwaccel_output_format.

I am waiting patches to be applied to propose new patch with hwcontext_amf in 
libavutil.

Thanks,
Alexander

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


Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious initialisations

2018-04-15 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Sunday, April 15, 2018 7:31 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious 
> initialisations
> 
> 
> > I am waiting patches to be applied to propose new patch with hwcontext_amf 
> > in libavutil.
> 
> Can you explain what you're intending to use that for?  It's not clear to me 
> how an extra wrapper around the D3D(9|11) surfaces is
> going to help, given that the support for them with AMF is already pretty 
> good.  (Compare the Intel libmfx stuff (the misleadingly-
> named "qsv") where the extra wrapping does help for some cases because the 
> underlying library has weird constraints, but overall
> adds a lot of complexity (and failure modes) for rather unclear benefit.  
> It's also inconvenient in that it promotes the existence of
> antifeatures like the "_qsv" decoders which are inferior to the builtin 
> hwaccels in pretty much every respect.)
> 

Hi Mark,
I am intending to create amf common helpers(tools) in libavutil. 
They will be used in amfenc and vf_scaleamf. (vf_scaleamf is hw-accelerated 
color-space converter and scaler)

amf helpers should provide:
* amf_library: functions to load/unload amf dll based on reference count 
mechanism
* amf_context: functions to create AMFContext derived from DXVA2, D3D11, opencl 
and Vulcan in future
* av_frame <-> AMFSurface map functions (move from amfenc.c)

amfav_context can be implemented like hwdevice_ctx (AVAMFDeviceContext) and can 
be managed by av_hwdevice_ctx_create_derived (in case of incoming hw frames) 
and av_hwdevice_ctx_create or it can be implemented not using of 
av_hwdevice_ctx* mechanism

I think don’t need AVAMFFrameContext, and amf components will send/receive 
hwframes based on existing framecontexts (dxva/opencl...)

Could you recommend the best way how to do this fit in current architecture?

Thanks,
Alexander

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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support implementation by AMF encoder

2018-04-24 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Sunday, April 22, 2018 6:49 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: DXVA2 textures support 
> implementation by AMF encoder
> 
> On 19/04/18 03:18, Song, Ruiling wrote:
> >> Note that OpenCL <-> D3D11 won't work on AMD for normal video
> >> surfaces
> >> (NV12) because there is no support for multiple-plane textures, so
> >> it's only going to work with DXVA2 currently.  Intel has an extension
> >> ("cl_intel_d3d11_nv12_media_sharing") which adds a simple hack
> >> overloading the subresource index and therefore it is usable on Intel
> >> GPUs, but other vendors don't have that.
> >
> > For OpenCL NV12 support, I think we can use two separate images as
> > arguments, one image for Y plane, and another image for UV plane.
> > I think AMD OpenCL should support (CL_RG + CL_UNORM_INT8), right?
> > So, we can get same behavior across different OpenCL vendors.
> 
> This is exactly what it does already, in a standard way with both DXVA2 and 
> VAAPI - NV12 as R/UNORM_INT8 + RG/UNORM_INT8 is
> indeed usable for AMD on Windows with DXVA2 interop and via direct upload.
> 
> The problematic case is D3D11, because the standard cl_khr_d3d11_sharing 
> extension does not support multiple-plane formats.  I
> would prefer that AMD has an OpenCL-only extension to do it like Intel does, 
> but an alternative route using AMF to do the mapping
> isn't horrible (though it would be quite confusing if it isn't transparent to 
> the user).

The AMD OpenCL only extension is requested to be published. Hopefully it is 
coming soon.

Now it is possible to convert DX11-NV12 surface to OpenCL-NV12 using AMF 
(AMFSurface->Convert(AMF_MEMORY_OPENCL)).
The private helper function can be implemented as temporary workaround. It can 
be deprecated when opencl-only extension is published by AMD

The helper function implementation requires hwcontext_amf which is going to be 
implemented soon (to be shared in amfenc and vf_scale_amf)

Thanks,
Alexander


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


Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious initialisations

2018-04-24 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Sunday, April 22, 2018 6:37 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious 
> initialisations
> 
> On 15/04/18 20:45, Alexander Kravchenko wrote:
> >> -Original Message-
> >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> >> Of Mark Thompson
> >> Sent: Sunday, April 15, 2018 7:31 PM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious
> >> initialisations
> >>
> >>
> >>> I am waiting patches to be applied to propose new patch with 
> >>> hwcontext_amf in libavutil.
> >>
> >> Can you explain what you're intending to use that for?  It's not
> >> clear to me how an extra wrapper around the D3D(9|11) surfaces is
> >> going to help, given that the support for them with AMF is already
> >> pretty good.  (Compare the Intel libmfx stuff (the misleadingly-
> >> named "qsv") where the extra wrapping does help for some cases
> >> because the underlying library has weird constraints, but overall
> >> adds a lot of complexity (and failure modes) for rather unclear
> >> benefit.  It's also inconvenient in that it promotes the existence of
> >> antifeatures like the "_qsv" decoders which are inferior to the
> >> builtin hwaccels in pretty much every respect.)
> >>
> >
> > Hi Mark,
> > I am intending to create amf common helpers(tools) in libavutil.
> > They will be used in amfenc and vf_scaleamf. (vf_scaleamf is
> > hw-accelerated color-space converter and scaler)
> >
> > amf helpers should provide:
> > * amf_library: functions to load/unload amf dll based on reference
> > count mechanism
> > * amf_context: functions to create AMFContext derived from DXVA2,
> > D3D11, opencl and Vulcan in future
> > * av_frame <-> AMFSurface map functions (move from amfenc.c)
> >
> > amfav_context can be implemented like hwdevice_ctx
> > (AVAMFDeviceContext) and can be managed by
> > av_hwdevice_ctx_create_derived (in case of incoming hw frames) and
> > av_hwdevice_ctx_create or it can be implemented not using of
> > av_hwdevice_ctx* mechanism
> >
> > I think don’t need AVAMFFrameContext, and amf components will
> > send/receive hwframes based on existing framecontexts (dxva/opencl...)
> >
> > Could you recommend the best way how to do this fit in current architecture?
> 
> I agree that using a hwdevice context here makes sense, since it wraps all of 
> the right properties (in particular, derivation from other
> devices).
> 
> It's less clear to me what to do with the frames.  A hwframes context could 
> work just for derivation because you don't actually need to
> implement the allocation stuff (the existing DRM hwcontext does this, since 
> it's only for interop).  What other approach would you
> think of taking?  Adding special external API to use internally between 
> libraries is not nice and we try to avoid it quite strongly.
> 

Hi Mark,
I agree it is good to stay within current API (hwdevice and hwframes), but I am 
not sure it is always possible.

is it ok create hwcontext_amf_internal.h which can be placeholder for the API 
like the following, or probably some helper functions can be published as 
pointers in AVAMFDeviceContext structure:
amf_set_property_buffer
amf_get_property_buffer
amf_create_buffer_with_frame_ref
amf_release_buffer_with_frame_ref


Thanks,
Alexander









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


Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious initialisations

2018-04-25 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of 
> Rostislav Pehlivanov
> Sent: Tuesday, April 24, 2018 4:04 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious 
> initialisations
> 
> On 24 April 2018 at 12:29, Alexander Kravchenko 
> wrote:
> 
> >
> >
> > > -Original Message-
> > > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> > > Behalf
> > Of Mark Thompson
> > > Sent: Sunday, April 22, 2018 6:37 PM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious
> > initialisations
> > >
> > > On 15/04/18 20:45, Alexander Kravchenko wrote:
> > > >> -Original Message-
> > > >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> > > >> Behalf Of Mark Thompson
> > > >> Sent: Sunday, April 15, 2018 7:31 PM
> > > >> To: ffmpeg-devel@ffmpeg.org
> > > >> Subject: Re: [FFmpeg-devel] [PATCH 5/5] amfenc: Remove spurious
> > > >> initialisations
> > > >>
> > > >>
> > > >>> I am waiting patches to be applied to propose new patch with
> > hwcontext_amf in libavutil.
> > > >>
> > > >> Can you explain what you're intending to use that for?  It's not
> > > >> clear to me how an extra wrapper around the D3D(9|11) surfaces is
> > > >> going to help, given that the support for them with AMF is
> > > >> already pretty good.  (Compare the Intel libmfx stuff (the
> > > >> misleadingly- named "qsv") where the extra wrapping does help for
> > > >> some cases because the underlying library has weird constraints,
> > > >> but overall adds a lot of complexity (and failure modes) for
> > > >> rather unclear benefit.  It's also inconvenient in that it
> > > >> promotes the existence of antifeatures like the "_qsv" decoders
> > > >> which are inferior to the builtin hwaccels in pretty much every
> > > >> respect.)
> > > >>
> > > >
> > > > Hi Mark,
> > > > I am intending to create amf common helpers(tools) in libavutil.
> > > > They will be used in amfenc and vf_scaleamf. (vf_scaleamf is
> > > > hw-accelerated color-space converter and scaler)
> > > >
> > > > amf helpers should provide:
> > > > * amf_library: functions to load/unload amf dll based on reference
> > > > count mechanism
> > > > * amf_context: functions to create AMFContext derived from DXVA2,
> > > > D3D11, opencl and Vulcan in future
> > > > * av_frame <-> AMFSurface map functions (move from amfenc.c)
> > > >
> > > > amfav_context can be implemented like hwdevice_ctx
> > > > (AVAMFDeviceContext) and can be managed by
> > > > av_hwdevice_ctx_create_derived (in case of incoming hw frames) and
> > > > av_hwdevice_ctx_create or it can be implemented not using of
> > > > av_hwdevice_ctx* mechanism
> > > >
> > > > I think don’t need AVAMFFrameContext, and amf components will
> > > > send/receive hwframes based on existing framecontexts
> > > > (dxva/opencl...)
> > > >
> > > > Could you recommend the best way how to do this fit in current
> > architecture?
> > >
> > > I agree that using a hwdevice context here makes sense, since it
> > > wraps
> > all of the right properties (in particular, derivation from other
> > > devices).
> > >
> > > It's less clear to me what to do with the frames.  A hwframes
> > > context
> > could work just for derivation because you don't actually need to
> > > implement the allocation stuff (the existing DRM hwcontext does
> > > this,
> > since it's only for interop).  What other approach would you
> > > think of taking?  Adding special external API to use internally
> > > between
> > libraries is not nice and we try to avoid it quite strongly.
> > >
> >
> > Hi Mark,
> > I agree it is good to stay within current API (hwdevice and hwframes),
> > but I am not sure it is always possible.
> >
> > is it ok create hwcontext_amf_internal.h which can be placeholder for
> > the API like the following, or probably some helper functions can be
> > published as pointers in AVAMFDeviceContext structure:
> > amf_set_property_buffer
> > amf_get_property_buffer
> > amf_create_buffer_with_frame_ref
> > amf_release_buffer_with_frame_ref
> >
> 
> No, I think there should be no avpriv functions for hwcontexts, nor any 
> public API changes. Better duplicate that code in lavfi.

Ok, if avutil is not proper place to put shared code between libavcodec and 
libavfilter, may be there should be another place?
Duplicating code will increase cost of maintenance, which is not good. 
Probably there should be some other place to put shared code?
May be shared code can be just set of static functions and macroses are put in 
headers?

Thanks,
Alexander






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


[FFmpeg-devel] [PATCH] lavu, lavc/amf: hwcontext_amf phase 1. move AMF library and AMF device management from amfenc to hwcontext_amf

2018-04-26 Thread Alexander Kravchenko
This patch moves AMF library and AMF device management from amfenc to 
hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF library/context creation/destroying
Phase 2 probably will include frame interop/map functions using hwframe_ctx API

---
 libavcodec/amfenc.c| 250 ---
 libavcodec/amfenc.h|  27 +---
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 329 +
 libavutil/hwcontext_amf.h  |  43 ++
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 418 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..a8186c7b86 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,17 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+av_unused int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +98,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
-else
-av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on the given 
D3D11 device: %d.\n", res);
-return AVERROR(ENODEV);
-}
-
-return 0;
-}
-#endif
-
-#if CONFIG_DXVA2

Re: [FFmpeg-devel] [PATCH] lavu, lavc/amf: hwcontext_amf phase 1. move AMF library and AMF device management from amfenc to hwcontext_amf

2018-05-05 Thread Alexander Kravchenko


> -Original Message-
> From: Alexander Kravchenko [mailto:akravchenko...@gmail.com]
> Sent: Thursday, April 26, 2018 10:01 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Alexander Kravchenko 
> Subject: [PATCH] lavu,lavc/amf: hwcontext_amf phase 1. move AMF library and 
> AMF device management from amfenc to
> hwcontext_amf
> 
> This patch moves AMF library and AMF device management from amfenc to 
> hwcontext_amf.
> Now av_hwdevice_ctx API is used for AMF library/context creation/destroying 
> Phase 2 probably will include frame interop/map
> functions using hwframe_ctx API
> 

Hello, 
I am sending reminder to review the patch.

Hopefully you could review it soon.
I am waiting applying it to send patches with vf_scale_amf which is color-space 
converter/scaler using DX9, DX11, OpenCL.


Thanks,
Alexander

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


[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to

2018-05-08 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying
This patch does not change component behaviour, 
it contains only restructurization for further patches with new amf components

---
sending patch one more time in May, since April's one wasn't commented/pushed.
previous April's link:
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-April/229051.html



 libavcodec/amfenc.c| 250 ---
 libavcodec/amfenc.h|  27 +---
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 329 +
 libavutil/hwcontext_amf.h  |  43 ++
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 418 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..a8186c7b86 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,17 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+av_unused int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +98,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
-else
- 

[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-08 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying.
This patch does not change component behaviour.
it contains only restructurization for further patches with new amf components

---
sending patch one more time in May, since April's one wasn't commented/pushed.
previous April's link:
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-April/229051.html



 libavcodec/amfenc.c| 250 ---
 libavcodec/amfenc.h|  27 +---
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 329 +
 libavutil/hwcontext_amf.h  |  43 ++
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 418 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..a8186c7b86 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,17 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+av_unused int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +98,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
-else
- 

Re: [FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-11 Thread Alexander Kravchenko
Hi Mark, 
Thank you for your comments.
Could you see my comments and questions bellow

> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Thursday, May 10, 2018 11:43 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code 
> (library and context) to lavu/hwcontext_amf from
> amfenc to be reused in other amf components
> 

> > +static AVBufferRef *amf_library_ctx = NULL;
> 
> Global mutable state in libraries is strongly discouraged.  Just loading it 
> again should be fine?
> 

Yes, loading it again could be fine.
I wanted to prevent additional call of library loading and trace 
initializations every time amf_device context is created.
User can create many instances of encoder in one process. 
Storing amf_library_ctx allows to detect when cleanup functions can be called 
(UnregisterWriter...). Of course we can never call dclose and keep library 
loaded all time.
What is your opinion?

> > +
> > +#include "frame.h"
> > +#include "AMF/core/Context.h"
> > +#include "AMF/core/Factory.h"
> > +
> > +
> > +/**
> > + * This struct is allocated as AVHWDeviceContext.hwctx  */ typedef
> > +struct AVAMFDeviceContext {
> > +AMFContext *context;
> > +AMFFactory *factory;
> 
> Do you actually need both of these?  It feels like you should be able to 
> derive the creating factory (/ library instance) from the context.
> 

AMFContext does not have pointer to AMFFactory. Now AMFFactory -> 
CreateComponent is used in encoder initialization.
May be AMFFactory is too wide interface on this level. Pointer to function like 
CreateComponent can be published in AVAMFDeviceContext instead of factory 
pointer.
or did you mean something different?

--
I have another question about publish amf library level options (Trace level, 
trace writers...). This could be in another patch if we decide this option is 
possible.
What is the best way to add such option? Can command line options be used to 
configure library? Or somehow publish this API?

Thanks,
Alexander



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


[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-12 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying.
This patch does not change component behaviour.
it contains only restructurization for further patches with new amf components

---
Sending updated patch based on Mark's review
1) simplificated library loading/unloading logic
2) minor fixes


 libavcodec/amfenc.c| 247 +---
 libavcodec/amfenc.h|  27 +
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 252 +
 libavutil/hwcontext_amf.h  |  43 +++
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 338 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..4c907ca3bc 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,18 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
-
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
 
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+AVAMFDeviceContext *amf_ctx;
+int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +99,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
-else
-av_log(avctx, AV_LOG

Re: [FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-14 Thread Alexander Kravchenko
Hi Mark, 
Thank you for your comments.
Could you see my comments bellow

> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Sunday, May 13, 2018 1:41 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code 
> (library and context) to lavu/hwcontext_amf from
> amfenc to be reused in other amf components
> 
> On 12/05/18 09:48, Alexander Kravchenko wrote:
> > This patch moves AMF common parts from amfenc to hwcontext_amf.
> > Now av_hwdevice_ctx API is used for AMF context creation/destroying.
> > This patch does not change component behaviour.
> > it contains only restructurization for further patches with new amf
> > components
> >
> > ---
> > Sending updated patch based on Mark's review
> > 1) simplificated library loading/unloading logic
> > 2) minor fixes
> >
> >
> >  libavcodec/amfenc.c| 247 
> > +---
> >  libavcodec/amfenc.h|  27 +
> >  libavutil/Makefile |   2 +
> >  libavutil/hwcontext.c  |   4 +
> >  libavutil/hwcontext.h  |   1 +
> >  libavutil/hwcontext_amf.c  | 252 
> > +
> >  libavutil/hwcontext_amf.h  |  43 +++
> >  libavutil/hwcontext_internal.h |   1 +
> >  8 files changed, 338 insertions(+), 239 deletions(-)  create mode
> > 100644 libavutil/hwcontext_amf.c  create mode 100644
> > libavutil/hwcontext_amf.h
> >
> > -
> > -static int amf_load_library(AVCodecContext *avctx)
> > +static int amf_init_context(AVCodecContext *avctx)
> >  {
> > -AmfContext*ctx = avctx->priv_data;
> > -AMFInit_Fn init_fun;
> > -AMFQueryVersion_Fn version_fun;
> > -AMF_RESULT res;
> > +AmfContext *ctx = avctx->priv_data;
> > +AVAMFDeviceContext *amf_ctx;
> > +int ret;
> >
> >  ctx->delayed_frame = av_frame_alloc();
> >  if (!ctx->delayed_frame) {
> >  return AVERROR(ENOMEM);
> >  }
> > +
> 
> Stray change?
> 

amf_load_library was moved to hwcontext; code which is unrelated to library 
moved to amf_init_context (delayed_frame object allocation)


> > +
> > +static void amf_device_uninit(AVHWDeviceContext *ctx) {
> > +AVAMFDeviceContext  *amf_ctx = ctx->hwctx;
> > +AMFDeviceContextPrivate *priv = ctx->internal->priv;
> > +if (amf_ctx->context) {
> > +amf_ctx->context->pVtbl->Terminate(amf_ctx->context);
> > +amf_ctx->context->pVtbl->Release(amf_ctx->context);
> > +amf_ctx->context = NULL;
> > +}
> > +if(priv->library) {
> > +dlclose(priv->library);
> > +}
> 
> This stuff shouldn't be in the uninit function, since this runs on all 
> devices rather than just those created internally.  You want to make
> a function to set as AVHWDeviceContext.free.
> 
OK, will be fixed in coming patch


> > +#include "frame.h"
> > +#include "AMF/core/Context.h"
> > +#include "AMF/core/Factory.h"
> > +
> > +
> > +/**
> > + * This struct is allocated as AVHWDeviceContext.hwctx  */ typedef
> > +struct AVAMFDeviceContext {
> > +AMFContext *context;
> > +AMFFactory *factory;
> 
> Might be nice to have a bit more documentation than that.
> 

I will add comments to header in coming patch


> > +} AVAMFDeviceContext;
> > +
> > +

Thanks,
Alexander

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


[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-14 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying.
This patch does not change component behaviour.
it contains only restructurization for further patches with new amf components

---
Sending updated patch based on Mark's review
1) moved device free code from amf_device_uninit to amf_device_free 
2) added comments for AVAMFDeviceContext structure


 libavcodec/amfenc.c| 247 +---
 libavcodec/amfenc.h|  27 +
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 253 +
 libavutil/hwcontext_amf.h  |  54 +
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 350 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..4c907ca3bc 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,18 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
-
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
 
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+AVAMFDeviceContext *amf_ctx;
+int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +99,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given de

[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-14 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying.
This patch does not change component behaviour.
it contains only restructurization for further patches with new amf components

---
Sending updated patch based on Mark's review
1) moved device free code from amf_device_uninit to amf_device_free 
2) added comments for AVAMFDeviceContext structure
3) Fixed trailing whitespace warnings


 libavcodec/amfenc.c| 247 +---
 libavcodec/amfenc.h|  27 +
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 253 +
 libavutil/hwcontext_amf.h  |  54 +
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 350 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..5a0fb90433 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,18 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+AVAMFDeviceContext *amf_ctx;
+int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +99,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11

Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop extension for NV12 and P010 textures - split planes

2018-05-27 Thread Alexander Kravchenko
Hi Mark.
This extension was implemented while ago, so it can be used now.

Thanks,
Alexander
сб, 26 мая 2018 г. в 19:45, Mark Thompson :

> On 24/05/18 15:26, Mironov, Mikhail wrote:
> > AMD has published OpenCL extension which allows split D3D11 texture
> interoped as a single 2D image into two 2D images representing Y and UV
> planes.
> >
> https://www.khronos.org/registry/OpenCL/extensions/amd/cl_amd_planar_yuv.txt
>
> Nice!  That looks like exactly what we want :)
>
> Is there any timeline for when this will be available in released drivers?
>
> Thanks,
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop extension for NV12 and P010 textures - split planes

2018-05-27 Thread Alexander Kravchenko


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Sunday, May 27, 2018 3:29 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop extension for 
> NV12 and P010 textures - split planes
> 
> On 27/05/18 07:57, Alexander Kravchenko wrote:
> > сб, 26 мая 2018 г. в 19:45, Mark Thompson :
> >
> >> On 24/05/18 15:26, Mironov, Mikhail wrote:
> >>> AMD has published OpenCL extension which allows split D3D11 texture
> >> interoped as a single 2D image into two 2D images representing Y and
> >> UV planes.
> >>>
> >> https://www.khronos.org/registry/OpenCL/extensions/amd/cl_amd_planar_
> >> yuv.txt
> >>
> >> Nice!  That looks like exactly what we want :)
> >>
> >> Is there any timeline for when this will be available in released drivers?
> >>
> > Hi Mark.
> > This extension was implemented while ago, so it can be used now.
> 
> I have what claims to be the most recent version of the Radeon drivers 
> (18.5.1, driver version 18.10.16, OpenCL version 24.20.11016.4
> - I don't know which of these is relevant), and it gives me:
> 
> Platform extensions:
> cl_khr_icd cl_khr_d3d10_sharing cl_khr_d3d11_sharing cl_khr_dx9_media_sharing 
> cl_amd_event_callback cl_amd_offline_devices
> 
> Device extensions:
> cl_khr_fp64 cl_amd_fp64 cl_khr_global_int32_base_atomics 
> cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics
> cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics 
> cl_khr_int64_extended_atomics cl_khr_3d_image_writes
> cl_khr_byte_addressable_store cl_khr_gl_sharing cl_khr_gl_depth_images 
> cl_amd_device_attribute_query cl_amd_vec3
> cl_amd_printf cl_amd_media_ops cl_amd_media_ops2 cl_amd_popcnt 
> cl_khr_d3d10_sharing cl_khr_d3d11_sharing
> cl_khr_dx9_media_sharing cl_khr_image2d_from_buffer cl_khr_spir 
> cl_khr_subgroups cl_khr_gl_event cl_khr_depth_images
> cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_amd_liquid_flash
> 
> which doesn't include this extension?
> 


Hi Mark,

It does include the extension. 
Extension was implemented while ago (years ago), but wasn't officially 
published till now. 

Probably the extension is still not enumerated in device/platform extensions 
list
Any way it can be used now.


Thanks,
Alexander

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


[FFmpeg-devel] [PATCH 2/2] lavf/vf_scale_amf: AMF scaler/colorspace converter filter implementation

2018-06-18 Thread Alexander Kravchenko
---
 configure  |   1 +
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_scale_amf.c | 620 +
 4 files changed, 623 insertions(+)
 create mode 100644 libavfilter/vf_scale_amf.c

diff --git a/configure b/configure
index 333e326a0a..eeb3a93810 100755
--- a/configure
+++ b/configure
@@ -3381,6 +3381,7 @@ rubberband_filter_deps="librubberband"
 sab_filter_deps="gpl swscale"
 scale2ref_filter_deps="swscale"
 scale_filter_deps="swscale"
+scale_amf_filter_deps="amf"
 scale_qsv_filter_deps="libmfx"
 select_filter_select="pixelutils"
 sharpness_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 5b4be4966c..8be008f6e3 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -311,6 +311,7 @@ OBJS-$(CONFIG_ROBERTS_FILTER)+= 
vf_convolution.o
 OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
 OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
 OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale.o
+OBJS-$(CONFIG_SCALE_AMF_FILTER)  += vf_scale_amf.o
 OBJS-$(CONFIG_SCALE_CUDA_FILTER) += vf_scale_cuda.o 
vf_scale_cuda.ptx.o
 OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
 OBJS-$(CONFIG_SCALE_QSV_FILTER)  += vf_scale_qsv.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index f2d27d2424..ab2a96a35c 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -300,6 +300,7 @@ extern AVFilter ff_vf_roberts;
 extern AVFilter ff_vf_rotate;
 extern AVFilter ff_vf_sab;
 extern AVFilter ff_vf_scale;
+extern AVFilter ff_vf_scale_amf;
 extern AVFilter ff_vf_scale_cuda;
 extern AVFilter ff_vf_scale_npp;
 extern AVFilter ff_vf_scale_qsv;
diff --git a/libavfilter/vf_scale_amf.c b/libavfilter/vf_scale_amf.c
new file mode 100644
index 00..25c0dc1ec3
--- /dev/null
+++ b/libavfilter/vf_scale_amf.c
@@ -0,0 +1,620 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * scale video filter - AMF
+ */
+
+#include 
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/time.h"
+
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_amf.h"
+
+#include "AMF/components/VideoConverter.h"
+
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+#include "scale.h"
+
+#if CONFIG_DXVA2
+#include 
+#endif
+
+#if CONFIG_D3D11VA
+#include 
+#endif
+
+#define AMFAV_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
+if (!(exp)) { \
+av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
+return ret_value; \
+}
+
+
+typedef struct FormatMap {
+enum AVPixelFormat   av_format;
+enum AMF_SURFACE_FORMAT  amf_format;
+} FormatMap;
+
+static const FormatMap format_map[] =
+{
+{ AV_PIX_FMT_NONE,   AMF_SURFACE_UNKNOWN },
+{ AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
+{ AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
+{ AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
+{ AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
+{ AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
+};
+
+static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum AVPixelFormat fmt)
+{
+int i;
+for (i = 0; i < amf_countof(format_map); i++) {
+if (format_map[i].av_format == fmt) {
+return format_map[i].amf_format;
+}
+}
+return AMF_SURFACE_UNKNOWN;
+}
+
+typedef struct AMFScaleContext {
+const AVClass *class;
+
+int width, height;
+enum AVPixelFormat format;
+
+char *w_expr;
+char *h_expr;
+char *format_str;
+
+int rect_left;
+int rect_right;
+int rect_top;
+int rect_bottom;
+
+int scale_type;
+int color_profile;
+
+int keep_aspect_ratio;
+int fill;
+uint8_t fill_color[4];
+
+AMFComponent*converter;
+AVBufferRef *amf_device_ref;
+
+AVBufferRef *hwframes_in_ref;
+AVBufferRef *hwframes_out_ref;
+AVBufferRef *hwdevice_ref;
+
+AMFContext  *con

[FFmpeg-devel] [PATCH 1/2] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-06-18 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying.
This patch does not change component behaviour.
it contains only restructurization for further patches with new amf components

---
 libavcodec/amfenc.c| 247 +
 libavcodec/amfenc.h|  27 +---
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 271 +
 libavutil/hwcontext_amf.h  |  54 
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 368 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..5a0fb90433 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,18 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+AVAMFDeviceContext *amf_ctx;
+int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +99,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
-else
-av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on the given 
D3D11 device: %d.\n", res);
-return AVERROR(ENODEV);
-}
-

Re: [FFmpeg-devel] [PATCH 2/2] lavf/vf_scale_amf: AMF scaler/colorspace converter filter implementation

2018-06-19 Thread Alexander Kravchenko
Hi Mark.
Thanks for your review and comments.
See my comments and question bellow

> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Tuesday, June 19, 2018 2:20 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavf/vf_scale_amf: AMF 
> scaler/colorspace converter filter implementation
> 

> 
> > +{ AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
> > +{ AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
> > +{ AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
> 
> What is happening to alpha here - should these be RGBA/BGRA?
> 
Alpha will be ignored in case RGB->NV12/YUV conversions
In case of conversion between RGBA variations channels will be reordered.
Probably RGBA/BGRA also should be also added as input formats


> > +int err;
> > +int i;
> > +static const enum AVPixelFormat input_pix_fmts[] = {
> > +AV_PIX_FMT_NV12,
> > +AV_PIX_FMT_0RGB,
> > +AV_PIX_FMT_BGR0,
> > +AV_PIX_FMT_RGB0,
> > +AV_PIX_FMT_GRAY8,
> > +AV_PIX_FMT_YUV420P,
> > +AV_PIX_FMT_YUYV422,
> > +AV_PIX_FMT_NONE,
> > +};
> > +static const enum AVPixelFormat output_pix_fmts_default[] = {
> > +AV_PIX_FMT_D3D11,
> > +AV_PIX_FMT_DXVA2_VLD,
> > +AV_PIX_FMT_NONE,
> > +};
> > +output_pix_fmts = output_pix_fmts_default;
> > +
> > +//in case if hw_device_ctx is set to DXVA2 we change order of pixel 
> > formats to set DXVA2 be choosen by default
> > +//The order is ignored if hw_frames_ctx is not NULL on the 
> > config_output stage
> > +if (avctx->hw_device_ctx) {
> > +device_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
> > +
> > +if (device_ctx->type == AV_HWDEVICE_TYPE_DXVA2){
> > +static const enum AVPixelFormat output_pix_fmts_dxva2[] = {
> > +AV_PIX_FMT_DXVA2_VLD,
> > +AV_PIX_FMT_D3D11,
> > +AV_PIX_FMT_NONE,
> > +};
> > +output_pix_fmts = output_pix_fmts_dxva2;
> 
> This feels dubious.  Can you explain exactly what you want to happen here?
> 
> I suspect you might be better exposing only the pixfmt associated with the 
> device if one is provided.  (E.g. if you have software input
> and a D3D11 device then you don't want to expose DXVA2 output at all.)
> 
We can have here two cases of initialization
1) from avctx->hw_device_ctx; available in 'query_output'. (input frame is in 
host memory, we use device from -filter_hw_device option). 
2) from avctx->inputs[0] ->hw_frames_ctx; not available in 'query_output'.  - 
(input frame is hw frame, we use device context from it) -  this is higher 
priority.

Frame context is higher priority but it is not set on this stage 
(query_formats).

So it can be the following scenario:
*) avctx->hw_device_ctx is set to DX9. This case we can set output format only 
DX9 in 'query_output'
*) avctx->inputs[0] ->hw_frames_ctx is set to DX11. But we know about this on 
configure_output function. And we cannot change output format to DX11.


> > +AMF_ASSIGN_PROPERTY_BOOL(res, ctx->converter, 
> > AMF_VIDEO_CONVERTER_KEEP_ASPECT_RATIO, ctx->keep_aspect_ratio);
> > +AMFAV_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR(ENOMEM),
> > + "AMFConverter-SetProperty() failed with error %d\n", res);
> 
> What effect with this have?  The w/h calculation already deals with aspect 
> ratio preservation (640:-1, etc.) in a common way across all
> scale filters.

this is required if you want to fit, for example, a square video into a 
rectangular video and fill the empty space with a color

> 
> > +
> > +AMF_ASSIGN_PROPERTY_BOOL(res, ctx->converter, 
> > AMF_VIDEO_CONVERTER_FILL, ctx->fill);
> > +AMFAV_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR(ENOMEM),
> > + "AMFConverter-SetProperty() failed with error %d\n", res);
> 
> Is it valid not to set this?  I'm guessing from the API, but it looks like if 
> this isn't set when you have an output rectangle then the rest of
> the surface will be left with undefined contents because it's a 
> newly-allocated surface.
> 

Option to fill or not fill empty space in case input stream does not fill 
output one.
This can happen if user set AMF_VIDEO_CONVERTER_KEEP_ASPECT_RATIO or/and set 
AMF_VIDEO_CONVERTER_OUTPUT_RECT


> > +
> > +if(ctx->color_profile != AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN) {
> > +AMF_ASSIGN_PROPERTY_INT64(res, ctx->converter,
> > + AMF_VIDEO_CONVERTER_COLOR_PROFILE, (amf_int32)ctx->color_profile);
> 
> What does this profile do?
This selects conversion matrix in RGB<->YUV conversions

> 
> The input properties should be set from the input AVFrame (see 
> color_range/color_primaries/color_trc/colorspace/chroma_location -
> you'll need all of those to support JPEG vs. normal video).
> 
> If it's setting the output properties then you will also need to set the 
> AVFrame fields correctly rather than copying them from th

[FFmpeg-devel] [PATCH 2/2] lavf/vf_scale_amf: AMF scaler/format converter filter implementation

2018-07-10 Thread Alexander Kravchenko
---
Sending updated patch based on Mark's review
1) added RGBA/BGRA
2) in case is device_ctx is set there is only the device hw format will be 
allowed as input and output
3) extended amf properties removed for now to have usual for ffmpeg 
scaler&format converter interface
4) input frame colorspace is set as color profile to select conversion matrix 
in case YUV->RGB, user setting removed.
5) misc bugs fixed


 configure  |   1 +
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_scale_amf.c | 623 +
 4 files changed, 626 insertions(+)
 create mode 100644 libavfilter/vf_scale_amf.c

diff --git a/configure b/configure
index b1a4dcfc42..321e9bdb70 100755
--- a/configure
+++ b/configure
@@ -3385,6 +3385,7 @@ rubberband_filter_deps="librubberband"
 sab_filter_deps="gpl swscale"
 scale2ref_filter_deps="swscale"
 scale_filter_deps="swscale"
+scale_amf_filter_deps="amf"
 scale_qsv_filter_deps="libmfx"
 select_filter_select="pixelutils"
 sharpness_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 7735c26529..1b35c9dd5e 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -317,6 +317,7 @@ OBJS-$(CONFIG_ROBERTS_OPENCL_FILTER) += 
vf_convolution_opencl.o opencl.o
 OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
 OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
 OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale.o
+OBJS-$(CONFIG_SCALE_AMF_FILTER)  += vf_scale_amf.o scale.o
 OBJS-$(CONFIG_SCALE_CUDA_FILTER) += vf_scale_cuda.o 
vf_scale_cuda.ptx.o
 OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
 OBJS-$(CONFIG_SCALE_QSV_FILTER)  += vf_scale_qsv.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 0ded83ede2..7c7eb1526a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -303,6 +303,7 @@ extern AVFilter ff_vf_roberts_opencl;
 extern AVFilter ff_vf_rotate;
 extern AVFilter ff_vf_sab;
 extern AVFilter ff_vf_scale;
+extern AVFilter ff_vf_scale_amf;
 extern AVFilter ff_vf_scale_cuda;
 extern AVFilter ff_vf_scale_npp;
 extern AVFilter ff_vf_scale_qsv;
diff --git a/libavfilter/vf_scale_amf.c b/libavfilter/vf_scale_amf.c
new file mode 100644
index 00..49250281e5
--- /dev/null
+++ b/libavfilter/vf_scale_amf.c
@@ -0,0 +1,623 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * scale video filter - AMF
+ */
+
+#include 
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/time.h"
+
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_amf.h"
+
+#include "AMF/components/VideoConverter.h"
+
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+#include "scale.h"
+
+#if CONFIG_DXVA2
+#include 
+#endif
+
+#if CONFIG_D3D11VA
+#include 
+#endif
+
+#define AMFAV_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
+if (!(exp)) { \
+av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
+return ret_value; \
+}
+
+#define AMFAV_GOTO_FAIL_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
+if (!(exp)) { \
+av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
+ret = ret_value; \
+goto fail; \
+}
+
+typedef struct FormatMap {
+enum AVPixelFormat   av_format;
+enum AMF_SURFACE_FORMAT  amf_format;
+} FormatMap;
+
+static const FormatMap format_map[] =
+{
+{ AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
+
+{ AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
+{ AV_PIX_FMT_BGRA,   AMF_SURFACE_BGRA },
+
+{ AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
+{ AV_PIX_FMT_RGBA,   AMF_SURFACE_RGBA },
+
+{ AV_PIX_FMT_0RGB,   AMF_SURFACE_ARGB },
+{ AV_PIX_FMT_ARGB,   AMF_SURFACE_ARGB },
+
+{ AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
+{ AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
+{ AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
+};
+
+static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum AVPixelFormat fmt)
+{
+int i;
+for (i = 0; i < amf_countof

[FFmpeg-devel] [PATCH 1/2] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-07-10 Thread Alexander Kravchenko
---
 libavcodec/amfenc.c| 247 +
 libavcodec/amfenc.h|  27 +---
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 271 +
 libavutil/hwcontext_amf.h  |  54 
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 368 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..5a0fb90433 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,18 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
 
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+AVAMFDeviceContext *amf_ctx;
+int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +99,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
-else
-av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on the given 
D3D11 device: %d.\n", res);
-return AVERROR(ENODEV);
-}
-
-return 0;
-}
-#endif
-
-#if CONFIG_DXVA2
-static int amf_init_from_dxva2_device(AVCodecContext *avctx, 
AVDXVA2DeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-HANDLE device_handle;
-IDirect3DDevice9 *device;
-HRESULT hr;
-   

Re: [FFmpeg-devel] [PATCH 1/2] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-07-26 Thread Alexander Kravchenko
Hello.
It is reminder.
Could you please review the patch? if it is ok, could you apply it?
It was published 2 weeks ago and it is required for further updates

Thanks,
Alexander






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


Re: [FFmpeg-devel] [PATCH 1/2] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-08-14 Thread Alexander Kravchenko
Hello.
It is reminder.
Could you please review the patch? if it is ok, could you please apply it?
It was published 1 month ago (10 July) and it is required for further updates

Thanks,
Alexander


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


Re: [FFmpeg-devel] [PATCH 2/2] lavf/vf_scale_amf: AMF scaler/format converter filter implementation

2018-08-14 Thread Alexander Kravchenko
Hi Mark, 
did you have a chance to review the patches?
I did send them 10 July, and no feedback from you
Could you please review it and send feedback to continue process?

Thanks,
Alexander 


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