On 23/11/15 23:08, Alexandre Lision wrote:
> -list_formats
> -pixel_format
> -video_size
> -framerate
> ---
> libavdevice/avfoundation_dec.m | 203
> +++++++++++++++++++++++++++++++++++++----
> 1 file changed, 186 insertions(+), 17 deletions(-)
>
> diff --git a/libavdevice/avfoundation_dec.m b/libavdevice/avfoundation_dec.m
> index b4b6d78..b6dd25c 100644
> --- a/libavdevice/avfoundation_dec.m
> +++ b/libavdevice/avfoundation_dec.m
> @@ -30,6 +30,7 @@
> #include "libavformat/internal.h"
> #include "libavutil/time.h"
> #include "libavutil/mathematics.h"
> +#include "libavutil/parseutils.h"
>
> #include "avdevice.h"
>
> @@ -91,9 +92,15 @@ typedef struct AVFoundationCaptureContext {
> AVClass *class;
> /* AVOptions */
> int list_devices;
> - enum AVPixelFormat pixel_format;
> + int list_formats;
> + char* pixel_format;
> + char* video_size; /* String describing video size */
> + char* framerate; /* String describing the framerate */
> +
>
> int video_stream_index;
> + int width, height;
> + AVRational internal_framerate;
>
> int64_t first_pts;
> int frames_captured;
> @@ -118,6 +125,10 @@ static const AVOption options[] = {
> { "all", "Show all the supported devices",
> OFFSET(list_devices), AV_OPT_TYPE_CONST, {.i64 = ALL_DEVICES }, 0,
> INT_MAX, DEC, "list_devices" },
> { "audio", "Show only the audio devices",
> OFFSET(list_devices), AV_OPT_TYPE_CONST, {.i64 = AUDIO_DEVICES }, 0,
> INT_MAX, DEC, "list_devices" },
> { "video", "Show only the video devices",
> OFFSET(list_devices), AV_OPT_TYPE_CONST, {.i64 = VIDEO_DEVICES }, 0,
> INT_MAX, DEC, "list_devices" },
> + { "list_formats", "List available formats and exit",
> OFFSET(list_formats), AV_OPT_TYPE_INT, {.i64 = 0 }, 0,
> INT_MAX, DEC, "list_formats" },
> + { "pixel_format", "Preferred pixel format",
> OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0,
> DEC},
> + { "video_size", "A string describing frame size, such as 640x480 or
> hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
> + { "framerate", "A string representing desired framerate",
> OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
> { NULL },
> };
>
> @@ -152,6 +163,23 @@ static int
> avfoundation_list_capture_devices(AVFormatContext *s)
> return AVERROR_EXIT;
> }
>
> +static int list_formats(AVFormatContext *s)
> +{
> + av_log(s, AV_LOG_VERBOSE, "Supported pixel formats (first is more
> efficient):\n");
Move it below.
> + AVCaptureVideoDataOutput* out = [[AVCaptureVideoDataOutput alloc] init];
> +
> + for (NSNumber* cv_pixel_format in [out
> availableVideoCVPixelFormatTypes]) {
> + OSType cv_fmt = [cv_pixel_format intValue];
> + enum AVPixelFormat pix_fmt = core_video_to_pix_fmt(cv_fmt);
> + if (pix_fmt != AV_PIX_FMT_NONE) {
> + av_log(s, AV_LOG_VERBOSE, " %s: %d\n",
> + av_get_pix_fmt_name(pix_fmt),
> + cv_fmt);
> + }
> + }
> + return AVERROR_EXIT;
> +}
> +
> static void lock_frames(AVFoundationCaptureContext* ctx)
> {
> pthread_mutex_lock(&ctx->frame_lock);
> @@ -206,6 +234,99 @@ static void unlock_frames(AVFoundationCaptureContext*
> ctx)
>
> @end
>
> +/**
> + * Configure the video device.
> + */
> +static bool configure_video_device(AVFormatContext *s, AVCaptureDevice
> *video_device)
> +{
> + AVFoundationCaptureContext *ctx = s->priv_data;
> + AVCaptureDeviceFormat* selected_format = nil;
> + AVFrameRateRange* selected_range = nil;
> + double framerate = av_q2d(ctx->internal_framerate);
> + double epsilon = 0.00000001;
> +
> + for (AVCaptureDeviceFormat* format in [video_device formats]) {
> + CMFormatDescriptionRef formatDescription;
> + CMVideoDimensions dimensions;
> +
> + formatDescription = (CMFormatDescriptionRef)
> format.formatDescription;
> + dimensions =
> CMVideoFormatDescriptionGetDimensions(formatDescription);
> +
> + if ((ctx->width == 0 && ctx->height == 0) ||
> + (dimensions.width == ctx->width && dimensions.height ==
> ctx->height)) {
> +
> + av_log(s, AV_LOG_INFO, "Trying video size %dx%d\n",
> + dimensions.width, dimensions.height);
Mark it verbose.
I'll merge the two and feed the whole to [uncrustify][1] later.
[1] https://wiki.libav.org/CodingStyle/Uncrustify
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel