Re: [FFmpeg-devel] [PATCH 1/2] lavfi/opencl: Use filter device if no input device is available

2018-01-03 Thread Jun Zhao


On 2018/1/3 18:25, Mark Thompson wrote:
> On 03/01/18 06:57, Jun Zhao wrote:
>> On 2018/1/3 7:12, Mark Thompson wrote:
>>> This allows implementing sources as well as filters.
>>> ---
>>>  libavfilter/opencl.c | 39 +--
>>>  1 file changed, 33 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/libavfilter/opencl.c b/libavfilter/opencl.c
>>> index 005ad089e2..37afc41f8b 100644
>>> --- a/libavfilter/opencl.c
>>> +++ b/libavfilter/opencl.c
>>> @@ -42,11 +42,29 @@ int ff_opencl_filter_query_formats(AVFilterContext 
>>> *avctx)
>>>  return ff_set_common_formats(avctx, formats);
>>>  }
>>>  
>>> +static int opencl_filter_set_device(AVFilterContext *avctx,
>>> +AVBufferRef *device)
>>> +{
>>> +OpenCLFilterContext *ctx = avctx->priv;
>>> +
>>> +av_buffer_unref(>device_ref);
>>> +
>>> +ctx->device_ref = av_buffer_ref(device);
>>> +if (!ctx->device_ref)
>>> +return AVERROR(ENOMEM);
>>> +
>>> +ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
>>> +ctx->hwctx  = ctx->device->hwctx;
>>> +
>>> +return 0;
>>> +}
>>> +
>>>  int ff_opencl_filter_config_input(AVFilterLink *inlink)
>>>  {
>>>  AVFilterContext   *avctx = inlink->dst;
>>>  OpenCLFilterContext *ctx = avctx->priv;
>>>  AVHWFramesContext *input_frames;
>>> +int err;
>>>  
>>>  if (!inlink->hw_frames_ctx) {
>>>  av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires a "
>>> @@ -59,15 +77,12 @@ int ff_opencl_filter_config_input(AVFilterLink *inlink)
>>>  return 0;
>>>  
>>>  input_frames = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
>>> -
>>>  if (input_frames->format != AV_PIX_FMT_OPENCL)
>>>  return AVERROR(EINVAL);
>>>  
>>> -ctx->device_ref = av_buffer_ref(input_frames->device_ref);
>>> -if (!ctx->device_ref)
>>> -return AVERROR(ENOMEM);
>>> -ctx->device = input_frames->device_ctx;
>>> -ctx->hwctx  = ctx->device->hwctx;
>>> +err = opencl_filter_set_device(avctx, input_frames->device_ref);
>>> +if (err < 0)
>>> +return err;
>>>  
>>>  // Default output parameters match input parameters.
>>>  if (ctx->output_format == AV_PIX_FMT_NONE)
>>> @@ -90,6 +105,18 @@ int ff_opencl_filter_config_output(AVFilterLink 
>>> *outlink)
>>>  
>>>  av_buffer_unref(>hw_frames_ctx);
>>>  
>>> +if (!ctx->device_ref) {
>> I  think AVFilter framework call ff_opencl_filter_config_input first, is
>> it need to check !ctx->device_ref?
> If you have a filter then config_input is indeed called first and the device 
> from the first input is used, but if you have a source rather than a filter 
> (no inputs) then you need this test to get the device from the filter setup.  
> See how openclsrc works in patch 1/2.
Got it, thanks.
>>> +if (!avctx->hw_device_ctx) {
>>> +av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires an "
>>> +   "OpenCL device.\n");
>>> +return AVERROR(EINVAL);
>>> +}
>>> +
>>> +err = opencl_filter_set_device(avctx, avctx->hw_device_ctx);
>>> +if (err < 0)
>>> +return err;
>>> +}
>>> +
>>>  output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
>>>  if (!output_frames_ref) {
>>>  err = AVERROR(ENOMEM);
> 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] [PATCH 1/2] lavfi/opencl: Use filter device if no input device is available

2018-01-03 Thread Mark Thompson
On 03/01/18 06:57, Jun Zhao wrote:
> On 2018/1/3 7:12, Mark Thompson wrote:
>> This allows implementing sources as well as filters.
>> ---
>>  libavfilter/opencl.c | 39 +--
>>  1 file changed, 33 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavfilter/opencl.c b/libavfilter/opencl.c
>> index 005ad089e2..37afc41f8b 100644
>> --- a/libavfilter/opencl.c
>> +++ b/libavfilter/opencl.c
>> @@ -42,11 +42,29 @@ int ff_opencl_filter_query_formats(AVFilterContext 
>> *avctx)
>>  return ff_set_common_formats(avctx, formats);
>>  }
>>  
>> +static int opencl_filter_set_device(AVFilterContext *avctx,
>> +AVBufferRef *device)
>> +{
>> +OpenCLFilterContext *ctx = avctx->priv;
>> +
>> +av_buffer_unref(>device_ref);
>> +
>> +ctx->device_ref = av_buffer_ref(device);
>> +if (!ctx->device_ref)
>> +return AVERROR(ENOMEM);
>> +
>> +ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
>> +ctx->hwctx  = ctx->device->hwctx;
>> +
>> +return 0;
>> +}
>> +
>>  int ff_opencl_filter_config_input(AVFilterLink *inlink)
>>  {
>>  AVFilterContext   *avctx = inlink->dst;
>>  OpenCLFilterContext *ctx = avctx->priv;
>>  AVHWFramesContext *input_frames;
>> +int err;
>>  
>>  if (!inlink->hw_frames_ctx) {
>>  av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires a "
>> @@ -59,15 +77,12 @@ int ff_opencl_filter_config_input(AVFilterLink *inlink)
>>  return 0;
>>  
>>  input_frames = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
>> -
>>  if (input_frames->format != AV_PIX_FMT_OPENCL)
>>  return AVERROR(EINVAL);
>>  
>> -ctx->device_ref = av_buffer_ref(input_frames->device_ref);
>> -if (!ctx->device_ref)
>> -return AVERROR(ENOMEM);
>> -ctx->device = input_frames->device_ctx;
>> -ctx->hwctx  = ctx->device->hwctx;
>> +err = opencl_filter_set_device(avctx, input_frames->device_ref);
>> +if (err < 0)
>> +return err;
>>  
>>  // Default output parameters match input parameters.
>>  if (ctx->output_format == AV_PIX_FMT_NONE)
>> @@ -90,6 +105,18 @@ int ff_opencl_filter_config_output(AVFilterLink *outlink)
>>  
>>  av_buffer_unref(>hw_frames_ctx);
>>  
>> +if (!ctx->device_ref) {
> I  think AVFilter framework call ff_opencl_filter_config_input first, is
> it need to check !ctx->device_ref?

If you have a filter then config_input is indeed called first and the device 
from the first input is used, but if you have a source rather than a filter (no 
inputs) then you need this test to get the device from the filter setup.  See 
how openclsrc works in patch 1/2.

>> +if (!avctx->hw_device_ctx) {
>> +av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires an "
>> +   "OpenCL device.\n");
>> +return AVERROR(EINVAL);
>> +}
>> +
>> +err = opencl_filter_set_device(avctx, avctx->hw_device_ctx);
>> +if (err < 0)
>> +return err;
>> +}
>> +
>>  output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
>>  if (!output_frames_ref) {
>>  err = AVERROR(ENOMEM);
> 

Thanks,

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


Re: [FFmpeg-devel] [PATCH 1/2] lavfi/opencl: Use filter device if no input device is available

2018-01-02 Thread Jun Zhao


On 2018/1/3 7:12, Mark Thompson wrote:
> This allows implementing sources as well as filters.
> ---
>  libavfilter/opencl.c | 39 +--
>  1 file changed, 33 insertions(+), 6 deletions(-)
>
> diff --git a/libavfilter/opencl.c b/libavfilter/opencl.c
> index 005ad089e2..37afc41f8b 100644
> --- a/libavfilter/opencl.c
> +++ b/libavfilter/opencl.c
> @@ -42,11 +42,29 @@ int ff_opencl_filter_query_formats(AVFilterContext *avctx)
>  return ff_set_common_formats(avctx, formats);
>  }
>  
> +static int opencl_filter_set_device(AVFilterContext *avctx,
> +AVBufferRef *device)
> +{
> +OpenCLFilterContext *ctx = avctx->priv;
> +
> +av_buffer_unref(>device_ref);
> +
> +ctx->device_ref = av_buffer_ref(device);
> +if (!ctx->device_ref)
> +return AVERROR(ENOMEM);
> +
> +ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
> +ctx->hwctx  = ctx->device->hwctx;
> +
> +return 0;
> +}
> +
>  int ff_opencl_filter_config_input(AVFilterLink *inlink)
>  {
>  AVFilterContext   *avctx = inlink->dst;
>  OpenCLFilterContext *ctx = avctx->priv;
>  AVHWFramesContext *input_frames;
> +int err;
>  
>  if (!inlink->hw_frames_ctx) {
>  av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires a "
> @@ -59,15 +77,12 @@ int ff_opencl_filter_config_input(AVFilterLink *inlink)
>  return 0;
>  
>  input_frames = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
> -
>  if (input_frames->format != AV_PIX_FMT_OPENCL)
>  return AVERROR(EINVAL);
>  
> -ctx->device_ref = av_buffer_ref(input_frames->device_ref);
> -if (!ctx->device_ref)
> -return AVERROR(ENOMEM);
> -ctx->device = input_frames->device_ctx;
> -ctx->hwctx  = ctx->device->hwctx;
> +err = opencl_filter_set_device(avctx, input_frames->device_ref);
> +if (err < 0)
> +return err;
>  
>  // Default output parameters match input parameters.
>  if (ctx->output_format == AV_PIX_FMT_NONE)
> @@ -90,6 +105,18 @@ int ff_opencl_filter_config_output(AVFilterLink *outlink)
>  
>  av_buffer_unref(>hw_frames_ctx);
>  
> +if (!ctx->device_ref) {
I  think AVFilter framework call ff_opencl_filter_config_input first, is
it need to check !ctx->device_ref?
> +if (!avctx->hw_device_ctx) {
> +av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires an "
> +   "OpenCL device.\n");
> +return AVERROR(EINVAL);
> +}
> +
> +err = opencl_filter_set_device(avctx, avctx->hw_device_ctx);
> +if (err < 0)
> +return err;
> +}
> +
>  output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
>  if (!output_frames_ref) {
>  err = AVERROR(ENOMEM);

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


[FFmpeg-devel] [PATCH 1/2] lavfi/opencl: Use filter device if no input device is available

2018-01-02 Thread Mark Thompson
This allows implementing sources as well as filters.
---
 libavfilter/opencl.c | 39 +--
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/libavfilter/opencl.c b/libavfilter/opencl.c
index 005ad089e2..37afc41f8b 100644
--- a/libavfilter/opencl.c
+++ b/libavfilter/opencl.c
@@ -42,11 +42,29 @@ int ff_opencl_filter_query_formats(AVFilterContext *avctx)
 return ff_set_common_formats(avctx, formats);
 }
 
+static int opencl_filter_set_device(AVFilterContext *avctx,
+AVBufferRef *device)
+{
+OpenCLFilterContext *ctx = avctx->priv;
+
+av_buffer_unref(>device_ref);
+
+ctx->device_ref = av_buffer_ref(device);
+if (!ctx->device_ref)
+return AVERROR(ENOMEM);
+
+ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
+ctx->hwctx  = ctx->device->hwctx;
+
+return 0;
+}
+
 int ff_opencl_filter_config_input(AVFilterLink *inlink)
 {
 AVFilterContext   *avctx = inlink->dst;
 OpenCLFilterContext *ctx = avctx->priv;
 AVHWFramesContext *input_frames;
+int err;
 
 if (!inlink->hw_frames_ctx) {
 av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires a "
@@ -59,15 +77,12 @@ int ff_opencl_filter_config_input(AVFilterLink *inlink)
 return 0;
 
 input_frames = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
-
 if (input_frames->format != AV_PIX_FMT_OPENCL)
 return AVERROR(EINVAL);
 
-ctx->device_ref = av_buffer_ref(input_frames->device_ref);
-if (!ctx->device_ref)
-return AVERROR(ENOMEM);
-ctx->device = input_frames->device_ctx;
-ctx->hwctx  = ctx->device->hwctx;
+err = opencl_filter_set_device(avctx, input_frames->device_ref);
+if (err < 0)
+return err;
 
 // Default output parameters match input parameters.
 if (ctx->output_format == AV_PIX_FMT_NONE)
@@ -90,6 +105,18 @@ int ff_opencl_filter_config_output(AVFilterLink *outlink)
 
 av_buffer_unref(>hw_frames_ctx);
 
+if (!ctx->device_ref) {
+if (!avctx->hw_device_ctx) {
+av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires an "
+   "OpenCL device.\n");
+return AVERROR(EINVAL);
+}
+
+err = opencl_filter_set_device(avctx, avctx->hw_device_ctx);
+if (err < 0)
+return err;
+}
+
 output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
 if (!output_frames_ref) {
 err = AVERROR(ENOMEM);
-- 
2.11.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel