]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/hwcontext.c
avfilter/avf_showspectrum: improve axes drawing
[ffmpeg] / libavutil / hwcontext.c
index 7f8e22736c9c5fb1a7eb8300845589bb34b7b171..745016ed7e166cac03e47cea297ea5831e1bf877 100644 (file)
@@ -41,6 +41,9 @@ static const HWContextType * const hw_table[] = {
 #if CONFIG_DXVA2
     &ff_hwcontext_type_dxva2,
 #endif
+#if CONFIG_OPENCL
+    &ff_hwcontext_type_opencl,
+#endif
 #if CONFIG_QSV
     &ff_hwcontext_type_qsv,
 #endif
@@ -52,6 +55,9 @@ static const HWContextType * const hw_table[] = {
 #endif
 #if CONFIG_VIDEOTOOLBOX
     &ff_hwcontext_type_videotoolbox,
+#endif
+#if CONFIG_MEDIACODEC
+    &ff_hwcontext_type_mediacodec,
 #endif
     NULL,
 };
@@ -61,10 +67,12 @@ static const char *const hw_type_names[] = {
     [AV_HWDEVICE_TYPE_DRM]    = "drm",
     [AV_HWDEVICE_TYPE_DXVA2]  = "dxva2",
     [AV_HWDEVICE_TYPE_D3D11VA] = "d3d11va",
+    [AV_HWDEVICE_TYPE_OPENCL] = "opencl",
     [AV_HWDEVICE_TYPE_QSV]    = "qsv",
     [AV_HWDEVICE_TYPE_VAAPI]  = "vaapi",
     [AV_HWDEVICE_TYPE_VDPAU]  = "vdpau",
     [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
+    [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec",
 };
 
 enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
@@ -213,19 +221,16 @@ static void hwframe_ctx_free(void *opaque, uint8_t *data)
 {
     AVHWFramesContext *ctx = (AVHWFramesContext*)data;
 
-    if (ctx->internal->source_frames) {
-        av_buffer_unref(&ctx->internal->source_frames);
+    if (ctx->internal->pool_internal)
+        av_buffer_pool_uninit(&ctx->internal->pool_internal);
 
-    } else {
-        if (ctx->internal->pool_internal)
-            av_buffer_pool_uninit(&ctx->internal->pool_internal);
+    if (ctx->internal->hw_type->frames_uninit)
+        ctx->internal->hw_type->frames_uninit(ctx);
 
-        if (ctx->internal->hw_type->frames_uninit)
-            ctx->internal->hw_type->frames_uninit(ctx);
+    if (ctx->free)
+        ctx->free(ctx);
 
-        if (ctx->free)
-            ctx->free(ctx);
-    }
+    av_buffer_unref(&ctx->internal->source_frames);
 
     av_buffer_unref(&ctx->device_ref);
 
@@ -478,8 +483,10 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
 
         ret = av_hwframe_get_buffer(ctx->internal->source_frames,
                                     src_frame, 0);
-        if (ret < 0)
+        if (ret < 0) {
+            av_frame_free(&src_frame);
             return ret;
+        }
 
         ret = av_hwframe_map(frame, src_frame,
                              ctx->internal->source_allocation_map_flags);
@@ -639,6 +646,9 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
                     ret = AVERROR(ENOMEM);
                     goto fail;
                 }
+                ret = av_hwdevice_ctx_init(dst_ref);
+                if (ret < 0)
+                    goto fail;
                 goto done;
             }
             if (ret != AVERROR(ENOSYS))
@@ -651,10 +661,6 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
     goto fail;
 
 done:
-    ret = av_hwdevice_ctx_init(dst_ref);
-    if (ret < 0)
-        goto fail;
-
     *dst_ref_ptr = dst_ref;
     return 0;