2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "hwcontext.h"
24 #include "hwcontext_internal.h"
31 static const HWContextType * const hw_table[] = {
33 &ff_hwcontext_type_cuda,
36 &ff_hwcontext_type_d3d11va,
39 &ff_hwcontext_type_drm,
42 &ff_hwcontext_type_dxva2,
45 &ff_hwcontext_type_opencl,
48 &ff_hwcontext_type_qsv,
51 &ff_hwcontext_type_vaapi,
54 &ff_hwcontext_type_vdpau,
56 #if CONFIG_VIDEOTOOLBOX
57 &ff_hwcontext_type_videotoolbox,
60 &ff_hwcontext_type_mediacodec,
63 &ff_hwcontext_type_vulkan,
68 static const char *const hw_type_names[] = {
69 [AV_HWDEVICE_TYPE_CUDA] = "cuda",
70 [AV_HWDEVICE_TYPE_DRM] = "drm",
71 [AV_HWDEVICE_TYPE_DXVA2] = "dxva2",
72 [AV_HWDEVICE_TYPE_D3D11VA] = "d3d11va",
73 [AV_HWDEVICE_TYPE_OPENCL] = "opencl",
74 [AV_HWDEVICE_TYPE_QSV] = "qsv",
75 [AV_HWDEVICE_TYPE_VAAPI] = "vaapi",
76 [AV_HWDEVICE_TYPE_VDPAU] = "vdpau",
77 [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
78 [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec",
79 [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
82 enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
85 for (type = 0; type < FF_ARRAY_ELEMS(hw_type_names); type++) {
86 if (hw_type_names[type] && !strcmp(hw_type_names[type], name))
89 return AV_HWDEVICE_TYPE_NONE;
92 const char *av_hwdevice_get_type_name(enum AVHWDeviceType type)
94 if (type > AV_HWDEVICE_TYPE_NONE &&
95 type < FF_ARRAY_ELEMS(hw_type_names))
96 return hw_type_names[type];
101 enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
103 enum AVHWDeviceType next;
105 for (i = 0; hw_table[i]; i++) {
106 if (prev != AV_HWDEVICE_TYPE_NONE && hw_table[i]->type <= prev)
108 if (!set || hw_table[i]->type < next) {
109 next = hw_table[i]->type;
113 return set ? next : AV_HWDEVICE_TYPE_NONE;
116 static const AVClass hwdevice_ctx_class = {
117 .class_name = "AVHWDeviceContext",
118 .item_name = av_default_item_name,
119 .version = LIBAVUTIL_VERSION_INT,
122 static void hwdevice_ctx_free(void *opaque, uint8_t *data)
124 AVHWDeviceContext *ctx = (AVHWDeviceContext*)data;
126 /* uninit might still want access the hw context and the user
127 * free() callback might destroy it, so uninit has to be called first */
128 if (ctx->internal->hw_type->device_uninit)
129 ctx->internal->hw_type->device_uninit(ctx);
134 av_buffer_unref(&ctx->internal->source_device);
136 av_freep(&ctx->hwctx);
137 av_freep(&ctx->internal->priv);
138 av_freep(&ctx->internal);
142 AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
144 AVHWDeviceContext *ctx;
146 const HWContextType *hw_type = NULL;
149 for (i = 0; hw_table[i]; i++) {
150 if (hw_table[i]->type == type) {
151 hw_type = hw_table[i];
158 ctx = av_mallocz(sizeof(*ctx));
162 ctx->internal = av_mallocz(sizeof(*ctx->internal));
166 if (hw_type->device_priv_size) {
167 ctx->internal->priv = av_mallocz(hw_type->device_priv_size);
168 if (!ctx->internal->priv)
172 if (hw_type->device_hwctx_size) {
173 ctx->hwctx = av_mallocz(hw_type->device_hwctx_size);
178 buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx),
179 hwdevice_ctx_free, NULL,
180 AV_BUFFER_FLAG_READONLY);
185 ctx->av_class = &hwdevice_ctx_class;
187 ctx->internal->hw_type = hw_type;
193 av_freep(&ctx->internal->priv);
194 av_freep(&ctx->internal);
195 av_freep(&ctx->hwctx);
200 int av_hwdevice_ctx_init(AVBufferRef *ref)
202 AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
205 if (ctx->internal->hw_type->device_init) {
206 ret = ctx->internal->hw_type->device_init(ctx);
213 if (ctx->internal->hw_type->device_uninit)
214 ctx->internal->hw_type->device_uninit(ctx);
218 static const AVClass hwframe_ctx_class = {
219 .class_name = "AVHWFramesContext",
220 .item_name = av_default_item_name,
221 .version = LIBAVUTIL_VERSION_INT,
224 static void hwframe_ctx_free(void *opaque, uint8_t *data)
226 AVHWFramesContext *ctx = (AVHWFramesContext*)data;
228 if (ctx->internal->pool_internal)
229 av_buffer_pool_uninit(&ctx->internal->pool_internal);
231 if (ctx->internal->hw_type->frames_uninit)
232 ctx->internal->hw_type->frames_uninit(ctx);
237 av_buffer_unref(&ctx->internal->source_frames);
239 av_buffer_unref(&ctx->device_ref);
241 av_freep(&ctx->hwctx);
242 av_freep(&ctx->internal->priv);
243 av_freep(&ctx->internal);
247 AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
249 AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)device_ref_in->data;
250 const HWContextType *hw_type = device_ctx->internal->hw_type;
251 AVHWFramesContext *ctx;
252 AVBufferRef *buf, *device_ref = NULL;
254 ctx = av_mallocz(sizeof(*ctx));
258 ctx->internal = av_mallocz(sizeof(*ctx->internal));
262 if (hw_type->frames_priv_size) {
263 ctx->internal->priv = av_mallocz(hw_type->frames_priv_size);
264 if (!ctx->internal->priv)
268 if (hw_type->frames_hwctx_size) {
269 ctx->hwctx = av_mallocz(hw_type->frames_hwctx_size);
274 device_ref = av_buffer_ref(device_ref_in);
278 buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx),
279 hwframe_ctx_free, NULL,
280 AV_BUFFER_FLAG_READONLY);
284 ctx->av_class = &hwframe_ctx_class;
285 ctx->device_ref = device_ref;
286 ctx->device_ctx = device_ctx;
287 ctx->format = AV_PIX_FMT_NONE;
288 ctx->sw_format = AV_PIX_FMT_NONE;
290 ctx->internal->hw_type = hw_type;
296 av_buffer_unref(&device_ref);
298 av_freep(&ctx->internal->priv);
299 av_freep(&ctx->internal);
300 av_freep(&ctx->hwctx);
305 static int hwframe_pool_prealloc(AVBufferRef *ref)
307 AVHWFramesContext *ctx = (AVHWFramesContext*)ref->data;
311 frames = av_mallocz_array(ctx->initial_pool_size, sizeof(*frames));
313 return AVERROR(ENOMEM);
315 for (i = 0; i < ctx->initial_pool_size; i++) {
316 frames[i] = av_frame_alloc();
320 ret = av_hwframe_get_buffer(ref, frames[i], 0);
326 for (i = 0; i < ctx->initial_pool_size; i++)
327 av_frame_free(&frames[i]);
333 int av_hwframe_ctx_init(AVBufferRef *ref)
335 AVHWFramesContext *ctx = (AVHWFramesContext*)ref->data;
336 const enum AVPixelFormat *pix_fmt;
339 if (ctx->internal->source_frames) {
340 /* A derived frame context is already initialised. */
344 /* validate the pixel format */
345 for (pix_fmt = ctx->internal->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) {
346 if (*pix_fmt == ctx->format)
349 if (*pix_fmt == AV_PIX_FMT_NONE) {
350 av_log(ctx, AV_LOG_ERROR,
351 "The hardware pixel format '%s' is not supported by the device type '%s'\n",
352 av_get_pix_fmt_name(ctx->format), ctx->internal->hw_type->name);
353 return AVERROR(ENOSYS);
356 /* validate the dimensions */
357 ret = av_image_check_size(ctx->width, ctx->height, 0, ctx);
361 /* format-specific init */
362 if (ctx->internal->hw_type->frames_init) {
363 ret = ctx->internal->hw_type->frames_init(ctx);
368 if (ctx->internal->pool_internal && !ctx->pool)
369 ctx->pool = ctx->internal->pool_internal;
371 /* preallocate the frames in the pool, if requested */
372 if (ctx->initial_pool_size > 0) {
373 ret = hwframe_pool_prealloc(ref);
380 if (ctx->internal->hw_type->frames_uninit)
381 ctx->internal->hw_type->frames_uninit(ctx);
385 int av_hwframe_transfer_get_formats(AVBufferRef *hwframe_ref,
386 enum AVHWFrameTransferDirection dir,
387 enum AVPixelFormat **formats, int flags)
389 AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
391 if (!ctx->internal->hw_type->transfer_get_formats)
392 return AVERROR(ENOSYS);
394 return ctx->internal->hw_type->transfer_get_formats(ctx, dir, formats);
397 static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
399 AVHWFramesContext *ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;
403 frame_tmp = av_frame_alloc();
405 return AVERROR(ENOMEM);
407 /* if the format is set, use that
408 * otherwise pick the first supported one */
409 if (dst->format >= 0) {
410 frame_tmp->format = dst->format;
412 enum AVPixelFormat *formats;
414 ret = av_hwframe_transfer_get_formats(src->hw_frames_ctx,
415 AV_HWFRAME_TRANSFER_DIRECTION_FROM,
419 frame_tmp->format = formats[0];
422 frame_tmp->width = ctx->width;
423 frame_tmp->height = ctx->height;
425 ret = av_frame_get_buffer(frame_tmp, 0);
429 ret = av_hwframe_transfer_data(frame_tmp, src, flags);
433 frame_tmp->width = src->width;
434 frame_tmp->height = src->height;
436 av_frame_move_ref(dst, frame_tmp);
439 av_frame_free(&frame_tmp);
443 int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
445 AVHWFramesContext *ctx;
449 return transfer_data_alloc(dst, src, flags);
452 * Hardware -> Hardware Transfer.
453 * Unlike Software -> Hardware or Hardware -> Software, the transfer
454 * function could be provided by either the src or dst, depending on
455 * the specific combination of hardware.
457 if (src->hw_frames_ctx && dst->hw_frames_ctx) {
458 AVHWFramesContext *src_ctx =
459 (AVHWFramesContext*)src->hw_frames_ctx->data;
460 AVHWFramesContext *dst_ctx =
461 (AVHWFramesContext*)dst->hw_frames_ctx->data;
463 if (src_ctx->internal->source_frames) {
464 av_log(src_ctx, AV_LOG_ERROR,
465 "A device with a derived frame context cannot be used as "
466 "the source of a HW -> HW transfer.");
467 return AVERROR(ENOSYS);
470 if (dst_ctx->internal->source_frames) {
471 av_log(src_ctx, AV_LOG_ERROR,
472 "A device with a derived frame context cannot be used as "
473 "the destination of a HW -> HW transfer.");
474 return AVERROR(ENOSYS);
477 ret = src_ctx->internal->hw_type->transfer_data_from(src_ctx, dst, src);
478 if (ret == AVERROR(ENOSYS))
479 ret = dst_ctx->internal->hw_type->transfer_data_to(dst_ctx, dst, src);
483 if (src->hw_frames_ctx) {
484 ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;
486 ret = ctx->internal->hw_type->transfer_data_from(ctx, dst, src);
489 } else if (dst->hw_frames_ctx) {
490 ctx = (AVHWFramesContext*)dst->hw_frames_ctx->data;
492 ret = ctx->internal->hw_type->transfer_data_to(ctx, dst, src);
496 return AVERROR(ENOSYS);
502 int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
504 AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
507 if (ctx->internal->source_frames) {
508 // This is a derived frame context, so we allocate in the source
509 // and map the frame immediately.
512 frame->format = ctx->format;
513 frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
514 if (!frame->hw_frames_ctx)
515 return AVERROR(ENOMEM);
517 src_frame = av_frame_alloc();
519 return AVERROR(ENOMEM);
521 ret = av_hwframe_get_buffer(ctx->internal->source_frames,
524 av_frame_free(&src_frame);
528 ret = av_hwframe_map(frame, src_frame,
529 ctx->internal->source_allocation_map_flags);
531 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
532 "frame context: %d.\n", ret);
533 av_frame_free(&src_frame);
537 // Free the source frame immediately - the mapped frame still
538 // contains a reference to it.
539 av_frame_free(&src_frame);
544 if (!ctx->internal->hw_type->frames_get_buffer)
545 return AVERROR(ENOSYS);
548 return AVERROR(EINVAL);
550 frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
551 if (!frame->hw_frames_ctx)
552 return AVERROR(ENOMEM);
554 ret = ctx->internal->hw_type->frames_get_buffer(ctx, frame);
556 av_buffer_unref(&frame->hw_frames_ctx);
560 frame->extended_data = frame->data;
565 void *av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
567 AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
568 const HWContextType *hw_type = ctx->internal->hw_type;
570 if (hw_type->device_hwconfig_size == 0)
573 return av_mallocz(hw_type->device_hwconfig_size);
576 AVHWFramesConstraints *av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
577 const void *hwconfig)
579 AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
580 const HWContextType *hw_type = ctx->internal->hw_type;
581 AVHWFramesConstraints *constraints;
583 if (!hw_type->frames_get_constraints)
586 constraints = av_mallocz(sizeof(*constraints));
590 constraints->min_width = constraints->min_height = 0;
591 constraints->max_width = constraints->max_height = INT_MAX;
593 if (hw_type->frames_get_constraints(ctx, hwconfig, constraints) >= 0) {
596 av_hwframe_constraints_free(&constraints);
601 void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
604 av_freep(&(*constraints)->valid_hw_formats);
605 av_freep(&(*constraints)->valid_sw_formats);
607 av_freep(constraints);
610 int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type,
611 const char *device, AVDictionary *opts, int flags)
613 AVBufferRef *device_ref = NULL;
614 AVHWDeviceContext *device_ctx;
617 device_ref = av_hwdevice_ctx_alloc(type);
619 ret = AVERROR(ENOMEM);
622 device_ctx = (AVHWDeviceContext*)device_ref->data;
624 if (!device_ctx->internal->hw_type->device_create) {
625 ret = AVERROR(ENOSYS);
629 ret = device_ctx->internal->hw_type->device_create(device_ctx, device,
634 ret = av_hwdevice_ctx_init(device_ref);
638 *pdevice_ref = device_ref;
641 av_buffer_unref(&device_ref);
646 int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
647 enum AVHWDeviceType type,
648 AVBufferRef *src_ref,
649 AVDictionary *options, int flags)
651 AVBufferRef *dst_ref = NULL, *tmp_ref;
652 AVHWDeviceContext *dst_ctx, *tmp_ctx;
657 tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
658 if (tmp_ctx->type == type) {
659 dst_ref = av_buffer_ref(tmp_ref);
661 ret = AVERROR(ENOMEM);
666 tmp_ref = tmp_ctx->internal->source_device;
669 dst_ref = av_hwdevice_ctx_alloc(type);
671 ret = AVERROR(ENOMEM);
674 dst_ctx = (AVHWDeviceContext*)dst_ref->data;
678 tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
679 if (dst_ctx->internal->hw_type->device_derive) {
680 ret = dst_ctx->internal->hw_type->device_derive(dst_ctx,
685 dst_ctx->internal->source_device = av_buffer_ref(src_ref);
686 if (!dst_ctx->internal->source_device) {
687 ret = AVERROR(ENOMEM);
690 ret = av_hwdevice_ctx_init(dst_ref);
695 if (ret != AVERROR(ENOSYS))
698 tmp_ref = tmp_ctx->internal->source_device;
701 ret = AVERROR(ENOSYS);
705 *dst_ref_ptr = dst_ref;
709 av_buffer_unref(&dst_ref);
714 int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
715 enum AVHWDeviceType type,
716 AVBufferRef *src_ref, int flags)
718 return av_hwdevice_ctx_create_derived_opts(dst_ref_ptr, type, src_ref,
722 static void ff_hwframe_unmap(void *opaque, uint8_t *data)
724 HWMapDescriptor *hwmap = (HWMapDescriptor*)data;
725 AVHWFramesContext *ctx = opaque;
728 hwmap->unmap(ctx, hwmap);
730 av_frame_free(&hwmap->source);
732 av_buffer_unref(&hwmap->hw_frames_ctx);
737 int ff_hwframe_map_create(AVBufferRef *hwframe_ref,
738 AVFrame *dst, const AVFrame *src,
739 void (*unmap)(AVHWFramesContext *ctx,
740 HWMapDescriptor *hwmap),
743 AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
744 HWMapDescriptor *hwmap;
747 hwmap = av_mallocz(sizeof(*hwmap));
749 ret = AVERROR(ENOMEM);
753 hwmap->source = av_frame_alloc();
754 if (!hwmap->source) {
755 ret = AVERROR(ENOMEM);
758 ret = av_frame_ref(hwmap->source, src);
762 hwmap->hw_frames_ctx = av_buffer_ref(hwframe_ref);
763 if (!hwmap->hw_frames_ctx) {
764 ret = AVERROR(ENOMEM);
768 hwmap->unmap = unmap;
771 dst->buf[0] = av_buffer_create((uint8_t*)hwmap, sizeof(*hwmap),
772 &ff_hwframe_unmap, ctx, 0);
774 ret = AVERROR(ENOMEM);
782 av_buffer_unref(&hwmap->hw_frames_ctx);
783 av_frame_free(&hwmap->source);
789 int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
791 AVHWFramesContext *src_frames, *dst_frames;
792 HWMapDescriptor *hwmap;
795 if (src->hw_frames_ctx && dst->hw_frames_ctx) {
796 src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data;
797 dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data;
799 if ((src_frames == dst_frames &&
800 src->format == dst_frames->sw_format &&
801 dst->format == dst_frames->format) ||
802 (src_frames->internal->source_frames &&
803 src_frames->internal->source_frames->data ==
804 (uint8_t*)dst_frames)) {
805 // This is an unmap operation. We don't need to directly
806 // do anything here other than fill in the original frame,
807 // because the real unmap will be invoked when the last
808 // reference to the mapped frame disappears.
810 av_log(src_frames, AV_LOG_ERROR, "Invalid mapping "
811 "found when attempting unmap.\n");
812 return AVERROR(EINVAL);
814 hwmap = (HWMapDescriptor*)src->buf[0]->data;
816 return av_frame_ref(dst, hwmap->source);
820 if (src->hw_frames_ctx) {
821 src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data;
823 if (src_frames->format == src->format &&
824 src_frames->internal->hw_type->map_from) {
825 ret = src_frames->internal->hw_type->map_from(src_frames,
827 if (ret != AVERROR(ENOSYS))
832 if (dst->hw_frames_ctx) {
833 dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data;
835 if (dst_frames->format == dst->format &&
836 dst_frames->internal->hw_type->map_to) {
837 ret = dst_frames->internal->hw_type->map_to(dst_frames,
839 if (ret != AVERROR(ENOSYS))
844 return AVERROR(ENOSYS);
847 int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
848 enum AVPixelFormat format,
849 AVBufferRef *derived_device_ctx,
850 AVBufferRef *source_frame_ctx,
853 AVBufferRef *dst_ref = NULL;
854 AVHWFramesContext *dst = NULL;
855 AVHWFramesContext *src = (AVHWFramesContext*)source_frame_ctx->data;
858 if (src->internal->source_frames) {
859 AVHWFramesContext *src_src =
860 (AVHWFramesContext*)src->internal->source_frames->data;
861 AVHWDeviceContext *dst_dev =
862 (AVHWDeviceContext*)derived_device_ctx->data;
864 if (src_src->device_ctx == dst_dev) {
865 // This is actually an unmapping, so we just return a
866 // reference to the source frame context.
868 av_buffer_ref(src->internal->source_frames);
869 if (!*derived_frame_ctx) {
870 ret = AVERROR(ENOMEM);
877 dst_ref = av_hwframe_ctx_alloc(derived_device_ctx);
879 ret = AVERROR(ENOMEM);
883 dst = (AVHWFramesContext*)dst_ref->data;
885 dst->format = format;
886 dst->sw_format = src->sw_format;
887 dst->width = src->width;
888 dst->height = src->height;
890 dst->internal->source_frames = av_buffer_ref(source_frame_ctx);
891 if (!dst->internal->source_frames) {
892 ret = AVERROR(ENOMEM);
896 dst->internal->source_allocation_map_flags =
897 flags & (AV_HWFRAME_MAP_READ |
898 AV_HWFRAME_MAP_WRITE |
899 AV_HWFRAME_MAP_OVERWRITE |
900 AV_HWFRAME_MAP_DIRECT);
902 ret = AVERROR(ENOSYS);
903 if (src->internal->hw_type->frames_derive_from)
904 ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
905 if (ret == AVERROR(ENOSYS) &&
906 dst->internal->hw_type->frames_derive_to)
907 ret = dst->internal->hw_type->frames_derive_to(dst, src, flags);
908 if (ret == AVERROR(ENOSYS))
913 *derived_frame_ctx = dst_ref;
918 av_buffer_unref(&dst->internal->source_frames);
919 av_buffer_unref(&dst_ref);
923 int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src)
925 HWMapDescriptor *hwmap = (HWMapDescriptor*)dst->buf[0]->data;
926 av_frame_unref(hwmap->source);
927 return av_frame_ref(hwmap->source, src);