From patchwork Sun Oct 20 09:55:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 15861 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B68DF4492AF for ; Sun, 20 Oct 2019 13:03:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8D5C068AF1B; Sun, 20 Oct 2019 13:03:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A29C68A2B9 for ; Sun, 20 Oct 2019 13:03:26 +0300 (EEST) Received: by mail-oi1-f193.google.com with SMTP id k20so8720392oih.3 for ; Sun, 20 Oct 2019 03:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pJthOla+Fc65oEuu3+gP1WYL6/qKwPONI3nBB94BhbY=; b=j2/Sg0qAx+JBnmNNFJ7La7VdOCkgC+HqNKiZhkn9WVX0cLXNkxhMLiOzKFf9SiSUPr kIOZtuW7lM36JNjdsZJC7+OTge+cm02C3cfCpyuIw4B7PQQvkhsaDUx8hToDiCUWxT9D 5LupQGu7JOnQEvWHphbf56aj1NHzn2LDppKicVQZ4NuFi82r+IuVYsDnCh1gyie0Q0NG aLBoRP6eKOQlnRZYojlRb8GlhTU30FXOKCwTsLhBzXTmCXaPQIl4VmZ5Bh1PyfC14P+v DLfEWV/F5fVLHhsjDKSyMjdY/vMX9fh80ZJR+73lp8Lo0DY9H2M+HazT6jHD0gMuoqL6 CrRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pJthOla+Fc65oEuu3+gP1WYL6/qKwPONI3nBB94BhbY=; b=gaVd13vaDmR6jv84F1qZvI0U4Hx2WrTXCF93BHvsZsnzCEbTIjk3ZBLg7dIRiKUIxP cbJ2MX/gss3CSpcQTxoGA9zGwomzQY8SRFAp6Nv1rQnerojFL/tK+/Il57S2b9XWhzhY Ccm405l0GCrDTSKwDxtN25fmY5Dth7qFP53H4c0PT3WiQGNvVzYFq7+1LqAAsgE4hhky 1AODdtsapoYBbVDK2x1UdL/TUucisX5ozmUmAQMO9li1lF+oz5Wd2aJSOfy4/k6EisXL mdPr7RcTOZ151bLl5nGmJUHnFZxmPu2bxqWiaLr0LKBAtG4+XSawJWUR7AB++JA0VW/N lQTw== X-Gm-Message-State: APjAAAWxK7QiY647RG3OQ6d0jXwkc6E1pUT7Iv2PQzXJD967lXESGGaT TiOaO7xNl4JkGULJcRIdXgmcros9 X-Google-Smtp-Source: APXvYqzUJWPsVpTk7Y8mXSygF//QZPShCIqm0WzG/hfraZcMthT/VzCSBL2PQr5XmBsYrj65oZY8LA== X-Received: by 2002:a54:4402:: with SMTP id k2mr14069000oiw.66.1571565352890; Sun, 20 Oct 2019 02:55:52 -0700 (PDT) Received: from localhost.localdomain (ip-137-232-239-173.texas.us.northamericancoax.com. [173.239.232.137]) by smtp.gmail.com with ESMTPSA id 60sm3247187oto.27.2019.10.20.02.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2019 02:55:52 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2019 04:55:30 -0500 Message-Id: <20191020095533.15016-3-cyrozap@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191020095533.15016-1-cyrozap@gmail.com> References: <20191020095533.15016-1-cyrozap@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] libdc1394: Verify the camera supports the selected mode and framerate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Forest Crossman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Without this, if a mode or framerate is selected that the camera doesn't support, it's possible that the camera will enter a state where it won't respond until it's power-cycled. Tested with an Apple iSight. Signed-off-by: Forest Crossman --- libavdevice/libdc1394.c | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index ec74cea87a..7be1d7b8dd 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -173,6 +173,13 @@ static int dc1394_read_header(AVFormatContext *c) int res, i; const struct dc1394_frame_format *fmt = NULL; const struct dc1394_frame_rate *fps = NULL; + const struct dc1394_frame_format *tmp_fmt; + const struct dc1394_frame_rate *tmp_fps; + dc1394video_modes_t supported_modes; + dc1394framerates_t supported_framerates; + int requested_mode_supported = 0; + int requested_framerate_supported = 0; + int mode_found; if (dc1394_read_common(c, &fmt, &fps) != 0) return -1; @@ -223,11 +230,60 @@ static int dc1394_read_header(AVFormatContext *c) goto out_camera; } + if (dc1394_video_get_supported_modes(dc1394->camera, &supported_modes) != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Couldn't get supported video formats\n"); + goto out_camera; + } + + for (i = 0; i < supported_modes.num; i++) { + mode_found = 0; + if (fmt->frame_size_id == supported_modes.modes[i]) + requested_mode_supported = 1; + for (tmp_fmt = dc1394_frame_formats; tmp_fmt->width; tmp_fmt++) + if (tmp_fmt->frame_size_id == supported_modes.modes[i]) { + av_log(c, AV_LOG_VERBOSE, "Supported format: %dx%d, %s\n", + tmp_fmt->width, tmp_fmt->height, av_get_pix_fmt_name(tmp_fmt->pix_fmt)); + mode_found = 1; + break; + } + if (!mode_found) + av_log(c, AV_LOG_VERBOSE, "Supported format (unsupported by libavdevice): %d\n", + supported_modes.modes[i]); + } + + if (!requested_mode_supported) { + av_log(c, AV_LOG_ERROR, "Camera doesn't support video format: %dx%d, %s\n", + fmt->width, fmt->height, av_get_pix_fmt_name(fmt->pix_fmt)); + goto out_camera; + } + if (dc1394_video_set_mode(dc1394->camera, fmt->frame_size_id) != DC1394_SUCCESS) { av_log(c, AV_LOG_ERROR, "Couldn't set video format\n"); goto out_camera; } + if (dc1394_video_get_supported_framerates(dc1394->camera, fmt->frame_size_id, &supported_framerates) != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Couldn't get supported framerates\n"); + goto out_camera; + } + + for (i = 0; i < supported_framerates.num; i++) { + if (fps->frame_rate_id == supported_framerates.framerates[i]) + requested_framerate_supported = 1; + for (tmp_fps = dc1394_frame_rates; tmp_fps->frame_rate; tmp_fps++) + if (tmp_fps->frame_rate_id == supported_framerates.framerates[i]) { + av_log(c, AV_LOG_VERBOSE, "Supported framerate for mode %dx%d, %s: %d:1000\n", + fmt->width, fmt->height, av_get_pix_fmt_name(fmt->pix_fmt), tmp_fps->frame_rate); + break; + } + } + + if (!requested_framerate_supported) { + av_log(c, AV_LOG_ERROR, "Camera doesn't support framerate for mode %dx%d, %s: %d:1000\n", + fmt->width, fmt->height, av_get_pix_fmt_name(fmt->pix_fmt), fps->frame_rate); + goto out_camera; + } + if (dc1394_video_set_framerate(dc1394->camera,fps->frame_rate_id) != DC1394_SUCCESS) { av_log(c, AV_LOG_ERROR, "Couldn't set framerate %d \n",fps->frame_rate); goto out_camera;