]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/hwcontext_vaapi.c
avutil/buffer: Switch AVBuffer API to size_t
[ffmpeg] / libavutil / hwcontext_vaapi.c
index 5c4f5de04ec6fafe1222641f2efe4f4e0da8fcda..83e542876d883cf0344cc2e5de501f9d0c7442ff 100644 (file)
@@ -136,6 +136,9 @@ static const VAAPIFormatDescriptor vaapi_format_map[] = {
 #endif
     MAP(ARGB, RGB32,   ARGB, 0),
     MAP(XRGB, RGB32,   0RGB, 0),
+#ifdef VA_FOURCC_X2R10G10B10
+    MAP(X2R10G10B10, RGB32_10, X2RGB10, 0),
+#endif
 };
 #undef MAP
 
@@ -265,14 +268,24 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev,
             }
 
             for (i = j = 0; i < attr_count; i++) {
+                int k;
+
                 if (attr_list[i].type != VASurfaceAttribPixelFormat)
                     continue;
                 fourcc = attr_list[i].value.value.i;
                 pix_fmt = vaapi_pix_fmt_from_fourcc(fourcc);
-                if (pix_fmt != AV_PIX_FMT_NONE)
+
+                if (pix_fmt == AV_PIX_FMT_NONE)
+                    continue;
+
+                for (k = 0; k < j; k++) {
+                    if (constraints->valid_sw_formats[k] == pix_fmt)
+                        break;
+                }
+
+                if (k == j)
                     constraints->valid_sw_formats[j++] = pix_fmt;
             }
-            av_assert0(j == pix_fmt_count);
             constraints->valid_sw_formats[j] = AV_PIX_FMT_NONE;
         }
     } else {
@@ -284,9 +297,19 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev,
             err = AVERROR(ENOMEM);
             goto fail;
         }
-        for (i = 0; i < ctx->nb_formats; i++)
-            constraints->valid_sw_formats[i] = ctx->formats[i].pix_fmt;
-        constraints->valid_sw_formats[i] = AV_PIX_FMT_NONE;
+        for (i = j = 0; i < ctx->nb_formats; i++) {
+            int k;
+
+            for (k = 0; k < j; k++) {
+                if (constraints->valid_sw_formats[k] == ctx->formats[i].pix_fmt)
+                    break;
+            }
+
+            if (k == j)
+                constraints->valid_sw_formats[j++] = ctx->formats[i].pix_fmt;
+        }
+
+        constraints->valid_sw_formats[j] = AV_PIX_FMT_NONE;
     }
 
     constraints->valid_hw_formats = av_malloc_array(2, sizeof(pix_fmt));
@@ -441,7 +464,7 @@ static void vaapi_buffer_free(void *opaque, uint8_t *data)
     }
 }
 
-static AVBufferRef *vaapi_pool_alloc(void *opaque, int size)
+static AVBufferRef *vaapi_pool_alloc(void *opaque, size_t size)
 {
     AVHWFramesContext     *hwfc = opaque;
     VAAPIFramesContext     *ctx = hwfc->internal->priv;
@@ -1654,20 +1677,24 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
             } else {
                 render_node = drmGetRenderDeviceNameFromFd(src_hwctx->fd);
                 if (!render_node) {
-                    av_log(ctx, AV_LOG_ERROR, "Failed to find a render node "
-                           "matching the DRM device.\n");
-                    return AVERROR(ENODEV);
-                }
-                fd = open(render_node, O_RDWR);
-                if (fd < 0) {
-                    av_log(ctx, AV_LOG_ERROR, "Failed to open render node %s"
-                           "matching the DRM device.\n", render_node);
+                    av_log(ctx, AV_LOG_VERBOSE, "Using non-render node "
+                           "because the device does not have an "
+                           "associated render node.\n");
+                    fd = src_hwctx->fd;
+                } else {
+                    fd = open(render_node, O_RDWR);
+                    if (fd < 0) {
+                        av_log(ctx, AV_LOG_VERBOSE, "Using non-render node "
+                               "because the associated render node "
+                               "could not be opened.\n");
+                        fd = src_hwctx->fd;
+                    } else {
+                        av_log(ctx, AV_LOG_VERBOSE, "Using render node %s "
+                               "in place of non-render DRM device.\n",
+                               render_node);
+                    }
                     free(render_node);
-                    return AVERROR(errno);
                 }
-                av_log(ctx, AV_LOG_VERBOSE, "Using render node %s in place "
-                       "of non-render DRM device.\n", render_node);
-                free(render_node);
             }
         }
 #else
@@ -1675,8 +1702,13 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
 #endif
 
         priv = av_mallocz(sizeof(*priv));
-        if (!priv)
+        if (!priv) {
+            if (fd != src_hwctx->fd) {
+                // The fd was opened in this function.
+                close(fd);
+            }
             return AVERROR(ENOMEM);
+        }
 
         if (fd == src_hwctx->fd) {
             // The fd is inherited from the source context and we are holding