On 31/03/17 20:14, Anton Khirnov wrote:
> Quoting Mark Thompson (2017-03-05 00:57:40)
>> Use the flags argument of av_hwframe_ctx_create_derived() to pass the
>> mapping flags which will be used on allocation.  Also, set the format
>> and hardware context on the allocated frame automatically - the user
>> should not be required to do this themselves.
>> ---
>>  libavutil/hwcontext.c          | 14 +++++++++++++-
>>  libavutil/hwcontext.h          |  4 +++-
>>  libavutil/hwcontext_internal.h |  5 +++++
>>  3 files changed, 21 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
>> index 4a47e258a..03cdd4701 100644
>> --- a/libavutil/hwcontext.c
>> +++ b/libavutil/hwcontext.c
>> @@ -459,6 +459,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, 
>> AVFrame *frame, int flags)
>>          // and map the frame immediately.
>>          AVFrame *src_frame;
>>  
>> +        frame->format = ctx->format;
>> +        frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
>> +        if (!frame->hw_frames_ctx)
>> +            return AVERROR(ENOMEM);
> 
> Shouldn't this be done in av_hwframe_map() below?

No?  hw_frames_ctx needs to be set on the destination frame for 
av_hwframe_map() to work.

>> +
>>          src_frame = av_frame_alloc();
>>          if (!src_frame)
>>              return AVERROR(ENOMEM);
>> @@ -468,7 +473,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, 
>> AVFrame *frame, int flags)
>>          if (ret < 0)
>>              return ret;
>>  
>> -        ret = av_hwframe_map(frame, src_frame, 0);
>> +        ret = av_hwframe_map(frame, src_frame,
>> +                             ctx->internal->source_allocation_map_flags);
>>          if (ret) {
>>              av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
>>                     "frame context: %d.\n", ret);
>> @@ -820,6 +826,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef 
>> **derived_frame_ctx,
>>          goto fail;
>>      }
>>  
>> +    dst->internal->source_allocation_map_flags =
>> +        flags & (AV_HWFRAME_MAP_READ      |
>> +                 AV_HWFRAME_MAP_WRITE     |
>> +                 AV_HWFRAME_MAP_OVERWRITE |
>> +                 AV_HWFRAME_MAP_DIRECT);
>> +
>>      ret = AVERROR(ENOSYS);
>>      if (src->internal->hw_type->map_frames_from)
>>          ret = src->internal->hw_type->map_frames_from(dst, src, flags);
>> diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
>> index cce7cdc7e..78162f598 100644
>> --- a/libavutil/hwcontext.h
>> +++ b/libavutil/hwcontext.h
>> @@ -564,7 +564,9 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int 
>> flags);
>>   *                           AVHWFramesContext on.
>>   * @param source_frame_ctx   A reference to an existing AVHWFramesContext
>>   *                           which will be mapped to the derived context.
>> - * @param flags  Currently unused; should be set to zero.
>> + * @param flags  Some combination of AV_HWFRAME_MAP_* flags, defining the
>> + *               mapping parameters to apply to frames which are allocated
>> + *               in the derived device.
>>   * @return       Zero on success, negative AVERROR code on failure.
> 
> This is strictly speaking an API change, so perhaps an APIchanges entry
> and a micro bump are appropriate.

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

Reply via email to