On 21/02/17 07:28, wm4 wrote:
> On Mon, 20 Feb 2017 21:54:03 +0000
> Mark Thompson <[email protected]> wrote:
> 
>> On 20/02/17 05:37, wm4 wrote:
>>> On Sun, 19 Feb 2017 18:46:23 +0000
>>> Mark Thompson <[email protected]> wrote:
>>>   
>>>> Creates a new device context from another of a different type which
>>>> refers to the same underlying hardware.
>>>> ---
>>>>  libavutil/hwcontext.c          | 78 
>>>> ++++++++++++++++++++++++++++++++++++++++++
>>>>  libavutil/hwcontext.h          | 16 +++++++++
>>>>  libavutil/hwcontext_internal.h |  8 +++++
>>>>  3 files changed, 102 insertions(+)
>>>>
>>>> diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
>>>> index 608da6872..1f9442622 100644
>>>> --- a/libavutil/hwcontext.c
>>>> +++ b/libavutil/hwcontext.c
>>>> @@ -65,6 +65,8 @@ static void hwdevice_ctx_free(void *opaque, uint8_t 
>>>> *data)
>>>>      if (ctx->free)
>>>>          ctx->free(ctx);
>>>>  
>>>> +    av_buffer_unref(&ctx->internal->source_device);
>>>> +
>>>>      av_freep(&ctx->hwctx);
>>>>      av_freep(&ctx->internal->priv);
>>>>      av_freep(&ctx->internal);
>>>> @@ -535,6 +537,82 @@ fail:
>>>>      return ret;
>>>>  }
>>>>  
>>>> +int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
>>>> +                                   enum AVHWDeviceType type,
>>>> +                                   AVBufferRef *src_ref, int flags)
>>>> +{
>>>> +    AVBufferRef *dst_ref = NULL, *tmp_ref;
>>>> +    AVHWDeviceContext *dst_ctx, *src_ctx, *tmp_ctx;
>>>> +    int ret = 0;
>>>> +
>>>> +    src_ctx = (AVHWDeviceContext*)src_ref->data;
>>>> +    if (src_ctx->type == type) {
>>>> +        // Currently disallowed.  It is possible that deriving a device of
>>>> +        // the same type could do something useful (device partitioning?),
>>>> +        // but for now just don't support it.
>>>> +        return AVERROR(EINVAL);  
>>>
>>> It could just be a no-nop (basically creating an alias). Whether that'd
>>> be useful, who knows.  
>>
>> If you can come up with any case where that is useful, then sure.  I 
>> couldn't think of one, so making it always fail rather than doing something 
>> unhelpful seemed reasonable.
>>
> 
> It looks to me like this would be quite orthogonal. The user could call
> this function simply to create a new reference to a desired device
> type, without having to check whether src_ref is already the desired
> type (and having to call av_buffer_ref instead in this case).

Ok, I'm convinced: I'll change it to remove this check and make the loop below 
start at the source device rather than its immediate parent.

>>>> +    }
>>>> +
>>>> +    // If the source device was originally derived from a device of the
>>>> +    // target type (possibly through more intermediates), then return a
>>>> +    // new reference to the original device.
>>>> +    tmp_ref = src_ctx->internal->source_device;
>>>> +    while (tmp_ref) {
>>>> +        tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
>>>> +        if (tmp_ctx->type == type) {
>>>> +            dst_ref = av_buffer_ref(tmp_ref);
>>>> +            if (!dst_ref) {
>>>> +                ret = AVERROR(ENOMEM);
>>>> +                goto fail;
>>>> +            }
>>>> +            goto done;  

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to