Provides API to query device capabilities. Each device must implement callbacks to benefit from this API.
Unified · Split
| @@ -15,6 +15,10 @@ libavutil: 2012-10-22 · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | +2014-04-xx - xxxxxxx - lavd 55.12.100 - avdevice.h | |
| 19 | + Add avdevice_capabilities_create() function. | |
| 20 | + Add avdevice_capabilities_free() function. | |
| 21 | + | |
| 18 | 22 | 2014-04-xx - xxxxxxx - lavu 53.11.0 - pixfmt.h |
| 19 | 23 | Add AV_PIX_FMT_YVYU422 pixel format. |
| 20 | 24 | |
| @@ -17,9 +17,46 @@ · 16 unmodified lines | ||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | #include "libavutil/avassert.h" |
| 20 | +#include "libavutil/samplefmt.h" | |
| 21 | +#include "libavutil/pixfmt.h" | |
| 22 | +#include "libavcodec/avcodec.h" | |
| 20 | 23 | #include "avdevice.h" |
| 21 | 24 | #include "config.h" |
| 22 | 25 | |
| 26 | +#define E AV_OPT_FLAG_ENCODING_PARAM | |
| 27 | +#define D AV_OPT_FLAG_DECODING_PARAM | |
| 28 | +#define A AV_OPT_FLAG_AUDIO_PARAM | |
| 29 | +#define V AV_OPT_FLAG_VIDEO_PARAM | |
| 30 | +#define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x) | |
| 31 | + | |
| 32 | +const AVOption av_device_capabilities[] = { | |
| 33 | + { "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT, | |
| 34 | + {.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V }, | |
| 35 | + { "sample_format", "sample format", OFFSET(sample_format), AV_OPT_TYPE_INT, | |
| 36 | + {.i64 = AV_SAMPLE_FMT_NONE}, -1, INT_MAX, E|D|A }, | |
| 37 | + { "sample_rate", "sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, | |
| 38 | + {.i64 = -1}, -1, INT_MAX, E|D|A }, | |
| 39 | + { "channels", "channels", OFFSET(channels), AV_OPT_TYPE_INT, | |
| 40 | + {.i64 = -1}, -1, INT_MAX, E|D|A }, | |
| 41 | + { "channel_layout", "channel layout", OFFSET(channel_layout), AV_OPT_TYPE_INT64, | |
| 42 | + {.i64 = -1}, -1, INT_MAX, E|D|A }, | |
| 43 | + { "pixel_format", "pixel format", OFFSET(pixel_format), AV_OPT_TYPE_INT, | |
| 44 | + {.i64 = AV_PIX_FMT_NONE}, -1, INT_MAX, E|D|V }, | |
| 45 | + { "window_size", "window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, | |
| 46 | + {.str = NULL}, -1, INT_MAX, E|D|V }, | |
| 47 | + { "frame_size", "frame size", OFFSET(frame_width), AV_OPT_TYPE_IMAGE_SIZE, | |
| 48 | + {.str = NULL}, -1, INT_MAX, E|D|V }, | |
| 49 | + { "fps", "fps", OFFSET(fps), AV_OPT_TYPE_RATIONAL, | |
| 50 | + {.dbl = -1}, -1, INT_MAX, E|D|V }, | |
| 51 | + { NULL } | |
| 52 | +}; | |
| 53 | + | |
| 54 | +#undef E | |
| 55 | +#undef D | |
| 56 | +#undef A | |
| 57 | +#undef V | |
| 58 | +#undef OFFSET | |
| 59 | + | |
| 23 | 60 | unsigned avdevice_version(void) |
| 24 | 61 | { |
| 25 | 62 | av_assert0(LIBAVDEVICE_VERSION_MICRO >= 100); |
| @@ -99,6 +136,50 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToA · 73 unmodified lines | ||
| 99 | 136 | return s->control_message_cb(s, type, data, data_size); |
| 100 | 137 | } |
| 101 | 138 | |
| 139 | +int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, | |
| 140 | + AVDictionary **device_options) | |
| 141 | +{ | |
| 142 | + int ret; | |
| 143 | + av_assert0(s && caps); | |
| 144 | + av_assert0(s->iformat || s->oformat); | |
| 145 | + if ((s->oformat && !s->oformat->create_device_capabilities) || | |
| 146 | + (s->iformat && !s->iformat->create_device_capabilities)) | |
| 147 | + return AVERROR(ENOSYS); | |
| 148 | + *caps = av_mallocz(sizeof(**caps)); | |
| 149 | + if (!(*caps)) | |
| 150 | + return AVERROR(ENOMEM); | |
| 151 | + (*caps)->device_context = s; | |
| 152 | + if (((ret = av_opt_set_dict(s->priv_data, device_options)) < 0)) | |
| 153 | + goto fail; | |
| 154 | + if (s->iformat) { | |
| 155 | + if ((ret = s->iformat->create_device_capabilities(s, *caps)) < 0) | |
| 156 | + goto fail; | |
| 157 | + } else { | |
| 158 | + if ((ret = s->oformat->create_device_capabilities(s, *caps)) < 0) | |
| 159 | + goto fail; | |
| 160 | + } | |
| 161 | + av_opt_set_defaults(*caps); | |
| 162 | + return 0; | |
| 163 | + fail: | |
| 164 | + av_freep(caps); | |
| 165 | + return ret; | |
| 166 | +} | |
| 167 | + | |
| 168 | +void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s) | |
| 169 | +{ | |
| 170 | + if (!s || !caps || !(*caps)) | |
| 171 | + return; | |
| 172 | + av_assert0(s->iformat || s->oformat); | |
| 173 | + if (s->iformat) { | |
| 174 | + if (s->iformat->free_device_capabilities) | |
| 175 | + s->iformat->free_device_capabilities(s, *caps); | |
| 176 | + } else { | |
| 177 | + if (s->oformat->free_device_capabilities) | |
| 178 | + s->oformat->free_device_capabilities(s, *caps); | |
| 179 | + } | |
| 180 | + av_freep(caps); | |
| 181 | +} | |
| 182 | + | |
| 102 | 183 | int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list) |
| 103 | 184 | { |
| 104 | 185 | int ret; |
| @@ -43,6 +43,9 @@ · 42 unmodified lines | ||
| 43 | 43 | * @} |
| 44 | 44 | */ |
| 45 | 45 | |
| 46 | +#include "libavutil/log.h" | |
| 47 | +#include "libavutil/opt.h" | |
| 48 | +#include "libavutil/dict.h" | |
| 46 | 49 | #include "libavformat/avformat.h" |
| 47 | 50 | |
| 48 | 51 | /** |
| @@ -227,6 +230,131 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, · 178 unmodified lines | ||
| 227 | 230 | enum AVDevToAppMessageType type, |
| 228 | 231 | void *data, size_t data_size); |
| 229 | 232 | |
| 233 | +/** | |
| 234 | + * Following API allows user to probe device capabilities (supported codecs, | |
| 235 | + * pixel formats, sample formats, resolutions, channel counts, etc). | |
| 236 | + * It is build on top op AVOption API. | |
| 237 | + * Queried capabilities allows to set up converters of video or audio | |
| 238 | + * parameters that fit to the device. | |
| 239 | + * | |
| 240 | + * List of capablities that can be queried: | |
| 241 | + * - Capabilities valid for both audio and video devices: | |
| 242 | + * - codec: supported audio/video codecs. | |
| 243 | + * type: AV_OPT_TYPE_INT (AVCodecID value) | |
| 244 | + * - Capabilities valid for audio devices: | |
| 245 | + * - sample_format: supported sample formats. | |
| 246 | + * type: AV_OPT_TYPE_INT (AVSampleFormat value) | |
| 247 | + * - sample_rate: supported sample rates. | |
| 248 | + * type: AV_OPT_TYPE_INT | |
| 249 | + * - channels: supported number of channels. | |
| 250 | + * type: AV_OPT_TYPE_INT | |
| 251 | + * - channel_layout: supported channel layouts. | |
| 252 | + * type: AV_OPT_TYPE_INT64 | |
| 253 | + * - Capabilities valid for video devices: | |
| 254 | + * - pixel_format: supported pixel formats. | |
| 255 | + * type: AV_OPT_TYPE_INT (AVPixelFormat value) | |
| 256 | + * - window_size: supported window sizes (describes size of the window size presented to the user). | |
| 257 | + * type: AV_OPT_TYPE_IMAGE_SIZE | |
| 258 | + * - frame_size: supported frame sizes (describes size of provided video frames). | |
| 259 | + * type: AV_OPT_TYPE_IMAGE_SIZE | |
| 260 | + * - fps: supported fps values | |
| 261 | + * type: AV_OPT_TYPE_RATIONAL | |
| 262 | + * | |
| 263 | + * Value of the capability may be set by user using av_opt_set() function | |
| 264 | + * and AVDeviceCapabilitiesQuery object. Following queries will | |
| 265 | + * limit results to the values matching already set capabilities. | |
| 266 | + * For example, setting a codec may impact number of formats or fps values | |
| 267 | + * returned during next query. Setting invalid value may limit results to zero. | |
| 268 | + * | |
| 269 | + * Example of the usage basing on opengl output device: | |
| 270 | + * | |
| 271 | + * @code | |
| 272 | + * AVFormatContext *oc = NULL; | |
| 273 | + * AVDeviceCapabilitiesQuery *caps = NULL; | |
| 274 | + * AVOptionRanges *ranges; | |
| 275 | + * int ret; | |
| 276 | + * | |
| 277 | + * if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0) | |
| 278 | + * goto fail; | |
| 279 | + * if (avdevice_capabilities_create(&caps, oc, NULL) < 0) | |
| 280 | + * goto fail; | |
| 281 | + * | |
| 282 | + * //query codecs | |
| 283 | + * if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0) | |
| 284 | + * goto fail; | |
| 285 | + * //pick codec here and set it | |
| 286 | + * av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0); | |
| 287 | + * | |
| 288 | + * //query format | |
| 289 | + * if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0) | |
| 290 | + * goto fail; | |
| 291 | + * //pick format here and set it | |
| 292 | + * av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0); | |
| 293 | + * | |
| 294 | + * //query and set more capabilities | |
| 295 | + * | |
| 296 | + * fail: | |
| 297 | + * //clean up code | |
| 298 | + * avdevice_capabilities_free(&query, oc); | |
| 299 | + * avformat_free_context(oc); | |
| 300 | + * @endcode | |
| 301 | + */ | |
| 302 | + | |
| 303 | +/** | |
| 304 | + * Structure describes device capabilites. | |
| 305 | + * | |
| 306 | + * It is used by devices in conjuntion with av_device_capabilities AVOption table | |
| 307 | + * to implement capabilities probing API based on AVOption API. Should not be used directly. | |
| 308 | + */ | |
| 309 | +typedef struct AVDeviceCapabilitiesQuery { | |
| 310 | + const AVClass *class; | |
| 311 | + AVFormatContext *device_context; | |
| 312 | + enum AVCodecID codec; | |
| 313 | + enum AVSampleFormat sample_format; | |
| 314 | + enum AVPixelFormat pixel_format; | |
| 315 | + int sample_rate; | |
| 316 | + int channels; | |
| 317 | + int64_t channel_layout; | |
| 318 | + int window_width; | |
| 319 | + int window_height; | |
| 320 | + int frame_width; | |
| 321 | + int frame_height; | |
| 322 | + AVRational fps; | |
| 323 | +} AVDeviceCapabilitiesQuery; | |
| 324 | + | |
| 325 | +/** | |
| 326 | + * AVOption table used by devices to implement device capabilites API. Should not be used by a user. | |
| 327 | + */ | |
| 328 | +extern const AVOption av_device_capabilities[]; | |
| 329 | + | |
| 330 | +/** | |
| 331 | + * Initialize capabilities probing API based on AVOption API. | |
| 332 | + * | |
| 333 | + * avdevice_capabilities_free() must be called when query capabilities API is | |
| 334 | + * not used anymore. | |
| 335 | + * | |
| 336 | + * @param[out] caps Device capabilities data. Pointer to a NULL pointer must be passed. | |
| 337 | + * @param s Context of the device. | |
| 338 | + * @param device_options An AVDictionary filled with device-private options. | |
| 339 | + * On return this parameter will be destroyed and replaced with a dict | |
| 340 | + * containing options that were not found. May be NULL. | |
| 341 | + * The same options must be passed later to avformat_write_header() for output | |
| 342 | + * devices or avformat_open_input() for input devices, or at any other place | |
| 343 | + * that affects device-private options. | |
| 344 | + * | |
| 345 | + * @return >= 0 on success, negative otherwise. | |
| 346 | + */ | |
| 347 | +int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, | |
| 348 | + AVDictionary **device_options); | |
| 349 | + | |
| 350 | +/** | |
| 351 | + * Free resources created by avdevice_capabilities_create() | |
| 352 | + * | |
| 353 | + * @param caps Device capabilities data to be freed. | |
| 354 | + * @param s Context of the device. | |
| 355 | + */ | |
| 356 | +void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s); | |
| 357 | + | |
| 230 | 358 | /** |
| 231 | 359 | * Structure describes basic parameters of the device. |
| 232 | 360 | */ |
| @@ -28,7 +28,7 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "libavutil/version.h" |
| 29 | 29 | |
| 30 | 30 | #define LIBAVDEVICE_VERSION_MAJOR 55 |
| 31 | −#define LIBAVDEVICE_VERSION_MINOR 11 | |
| 31 | +#define LIBAVDEVICE_VERSION_MINOR 12 | |
| 32 | 32 | #define LIBAVDEVICE_VERSION_MICRO 100 |
| 33 | 33 | |
| 34 | 34 | #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ |
| @@ -262,6 +262,7 @@ · 261 unmodified lines | ||
| 262 | 262 | struct AVFormatContext; |
| 263 | 263 | |
| 264 | 264 | struct AVDeviceInfoList; |
| 265 | +struct AVDeviceCapabilitiesQuery; | |
| 265 | 266 | |
| 266 | 267 | /** |
| 267 | 268 | * @defgroup metadata_api Public Metadata API |
| @@ -531,6 +532,16 @@ typedef struct AVOutputFormat { · 263 unmodified lines | ||
| 531 | 532 | * @see avdevice_list_devices() for more details. |
| 532 | 533 | */ |
| 533 | 534 | int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); |
| 535 | + /** | |
| 536 | + * Initialize device capabilities submodule. | |
| 537 | + * @see avdevice_capabilities_create() for more details. | |
| 538 | + */ | |
| 539 | + int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); | |
| 540 | + /** | |
| 541 | + * Free device capabilities submodule. | |
| 542 | + * @see avdevice_capabilities_free() for more details. | |
| 543 | + */ | |
| 544 | + int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); | |
| 534 | 545 | } AVOutputFormat; |
| 535 | 546 | /** |
| 536 | 547 | * @} |
| @@ -665,6 +676,18 @@ typedef struct AVInputFormat { · 128 unmodified lines | ||
| 665 | 676 | * @see avdevice_list_devices() for more details. |
| 666 | 677 | */ |
| 667 | 678 | int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); |
| 679 | + | |
| 680 | + /** | |
| 681 | + * Initialize device capabilities submodule. | |
| 682 | + * @see avdevice_capabilities_create() for more details. | |
| 683 | + */ | |
| 684 | + int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); | |
| 685 | + | |
| 686 | + /** | |
| 687 | + * Free device capabilities submodule. | |
| 688 | + * @see avdevice_capabilities_free() for more details. | |
| 689 | + */ | |
| 690 | + int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); | |
| 668 | 691 | } AVInputFormat; |
| 669 | 692 | /** |
| 670 | 693 | * @} |
| @@ -30,8 +30,8 @@ · 29 unmodified lines | ||
| 30 | 30 | #include "libavutil/version.h" |
| 31 | 31 | |
| 32 | 32 | #define LIBAVFORMAT_VERSION_MAJOR 55 |
| 33 | −#define LIBAVFORMAT_VERSION_MINOR 36 | |
| 34 | −#define LIBAVFORMAT_VERSION_MICRO 103 | |
| 33 | +#define LIBAVFORMAT_VERSION_MINOR 37 | |
| 34 | +#define LIBAVFORMAT_VERSION_MICRO 100 | |
| 35 | 35 | |
| 36 | 36 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
| 37 | 37 | LIBAVFORMAT_VERSION_MINOR, \ |