Browse code

lavc: Add codec metadata to indicate hardware support

Mark Thompson authored on 2017/10/26 08:18:39
Showing 5 changed files
... ...
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
15 15
 
16 16
 API changes, most recent first:
17 17
 
18
+2017-11-xx - xxxxxxx - lavc 58.4.100 - avcodec.h
19
+  Add AVCodecHWConfig and avcodec_get_hw_config().
20
+
18 21
 2017-11-22 - 3650cb2dfa - lavu 55.3.100 - opencl.h
19 22
   Remove experimental OpenCL API (av_opencl_*).
20 23
 
... ...
@@ -36,6 +36,7 @@
36 36
 #include "libavutil/channel_layout.h"
37 37
 #include "libavutil/dict.h"
38 38
 #include "libavutil/frame.h"
39
+#include "libavutil/hwcontext.h"
39 40
 #include "libavutil/log.h"
40 41
 #include "libavutil/pixfmt.h"
41 42
 #include "libavutil/rational.h"
... ...
@@ -3279,6 +3280,61 @@ typedef struct AVProfile {
3279 3279
     const char *name; ///< short name for the profile
3280 3280
 } AVProfile;
3281 3281
 
3282
+enum {
3283
+    /**
3284
+     * The codec supports this format via the hw_device_ctx interface.
3285
+     *
3286
+     * When selecting this format, AVCodecContext.hw_device_ctx should
3287
+     * have been set to a device of the specified type before calling
3288
+     * avcodec_open2().
3289
+     */
3290
+    AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 0x01,
3291
+    /**
3292
+     * The codec supports this format via the hw_frames_ctx interface.
3293
+     *
3294
+     * When selecting this format for a decoder,
3295
+     * AVCodecContext.hw_frames_ctx should be set to a suitable frames
3296
+     * context inside the get_format() callback.  The frames context
3297
+     * must have been created on a device of the specified type.
3298
+     */
3299
+    AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 0x02,
3300
+    /**
3301
+     * The codec supports this format by some internal method.
3302
+     *
3303
+     * This format can be selected without any additional configuration -
3304
+     * no device or frames context is required.
3305
+     */
3306
+    AV_CODEC_HW_CONFIG_METHOD_INTERNAL      = 0x04,
3307
+    /**
3308
+     * The codec supports this format by some ad-hoc method.
3309
+     *
3310
+     * Additional settings and/or function calls are required.  See the
3311
+     * codec-specific documentation for details.  (Methods requiring
3312
+     * this sort of configuration are deprecated and others should be
3313
+     * used in preference.)
3314
+     */
3315
+    AV_CODEC_HW_CONFIG_METHOD_AD_HOC        = 0x08,
3316
+};
3317
+
3318
+typedef struct AVCodecHWConfig {
3319
+    /**
3320
+     * A hardware pixel format which the codec can use.
3321
+     */
3322
+    enum AVPixelFormat pix_fmt;
3323
+    /**
3324
+     * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
3325
+     * setup methods which can be used with this configuration.
3326
+     */
3327
+    int methods;
3328
+    /**
3329
+     * The device type associated with the configuration.
3330
+     *
3331
+     * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
3332
+     * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
3333
+     */
3334
+    enum AVHWDeviceType device_type;
3335
+} AVCodecHWConfig;
3336
+
3282 3337
 typedef struct AVCodecDefault AVCodecDefault;
3283 3338
 
3284 3339
 struct AVSubtitle;
... ...
@@ -3404,6 +3460,15 @@ typedef struct AVCodec {
3404 3404
      * packets before decoding.
3405 3405
      */
3406 3406
     const char *bsfs;
3407
+
3408
+    /**
3409
+     * Array of pointers to hardware configurations supported by the codec,
3410
+     * or NULL if no hardware supported.  The array is terminated by a NULL
3411
+     * pointer.
3412
+     *
3413
+     * The user can only access this field via avcodec_get_hw_config().
3414
+     */
3415
+    const struct AVCodecHWConfigInternal **hw_configs;
3407 3416
 } AVCodec;
3408 3417
 
3409 3418
 #if FF_API_CODEC_GET_SET
... ...
@@ -3414,6 +3479,15 @@ int av_codec_get_max_lowres(const AVCodec *codec);
3414 3414
 struct MpegEncContext;
3415 3415
 
3416 3416
 /**
3417
+ * Retrieve supported hardware configurations for a codec.
3418
+ *
3419
+ * Values of index from zero to some maximum return the indexed configuration
3420
+ * descriptor; all other values return NULL.  If the codec does not support
3421
+ * any hardware configurations then it will always return NULL.
3422
+ */
3423
+const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index);
3424
+
3425
+/**
3417 3426
  * @defgroup lavc_hwaccel AVHWAccel
3418 3427
  * @{
3419 3428
  */
... ...
@@ -19,6 +19,24 @@
19 19
 #ifndef AVCODEC_HWACCEL_H
20 20
 #define AVCODEC_HWACCEL_H
21 21
 
22
+#include "avcodec.h"
23
+
24
+
22 25
 #define HWACCEL_CAP_ASYNC_SAFE      (1 << 0)
23 26
 
27
+
28
+typedef struct AVCodecHWConfigInternal {
29
+    /**
30
+     * This is the structure which will be returned to the user by
31
+     * avcodec_get_hw_config().
32
+     */
33
+    AVCodecHWConfig public;
34
+    /**
35
+     * If this configuration uses a hwaccel, a pointer to it.
36
+     * If not, NULL.
37
+     */
38
+    const AVHWAccel *hwaccel;
39
+} AVCodecHWConfigInternal;
40
+
41
+
24 42
 #endif /* AVCODEC_HWACCEL_H */
... ...
@@ -45,6 +45,7 @@
45 45
 #include "libavutil/thread.h"
46 46
 #include "avcodec.h"
47 47
 #include "decode.h"
48
+#include "hwaccel.h"
48 49
 #include "libavutil/opt.h"
49 50
 #include "me_cmp.h"
50 51
 #include "mpegvideo.h"
... ...
@@ -1886,6 +1887,17 @@ int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
1886 1886
     return i;
1887 1887
 }
1888 1888
 
1889
+const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index)
1890
+{
1891
+    int i;
1892
+    if (!codec->hw_configs || index < 0)
1893
+        return NULL;
1894
+    for (i = 0; i <= index; i++)
1895
+        if (!codec->hw_configs[i])
1896
+            return NULL;
1897
+    return &codec->hw_configs[index]->public;
1898
+}
1899
+
1889 1900
 static AVHWAccel *first_hwaccel = NULL;
1890 1901
 static AVHWAccel **last_hwaccel = &first_hwaccel;
1891 1902
 
... ...
@@ -28,8 +28,8 @@
28 28
 #include "libavutil/version.h"
29 29
 
30 30
 #define LIBAVCODEC_VERSION_MAJOR  58
31
-#define LIBAVCODEC_VERSION_MINOR   3
32
-#define LIBAVCODEC_VERSION_MICRO 105
31
+#define LIBAVCODEC_VERSION_MINOR   4
32
+#define LIBAVCODEC_VERSION_MICRO 100
33 33
 
34 34
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
35 35
                                                LIBAVCODEC_VERSION_MINOR, \