From patchwork Thu Oct 15 21:30:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 22977 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 850C744B9BF for ; Fri, 16 Oct 2020 00:38:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5CD5A68B8C1; Fri, 16 Oct 2020 00:38:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1096B68B8A3 for ; Fri, 16 Oct 2020 00:38:24 +0300 (EEST) Received: by mail-yb1-f196.google.com with SMTP id l15so222570ybp.2 for ; Thu, 15 Oct 2020 14:38:23 -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=PR+rKbGlNjj5CQ4I7rmbRUlaRK0ju5cZtDuddgdOuiA=; b=c2Ybu8ePU0lgFmDs+CShwqtpgoe35Uah+SUjV6m+Sv5qAF8NHfno9UQs8oAW20i3RN IranLkC6JIaf+w9gjeS9cJBvqK5UonSPmPKBnJofeHOAwEG1LMghL6ml5ClfQb0hMwIl QJ80j19vftdwACXrahpzvNVVo0IYw5KfBkJhjlRyHN+KaUtDWn7ynvBRrewgW00imqgo wooDrMzQL75jAgQkaix8JWkHDegnxVZZI3L5kj377hypjpdRxnahFmo/1YOVq+wguKin wtbZu2mKjVmOeh2yFjMb2IOeI6mNVZDxDEDVT0ZVPxjXtySNQFXrOynqbVk1a5o3UyhN bnDA== 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=PR+rKbGlNjj5CQ4I7rmbRUlaRK0ju5cZtDuddgdOuiA=; b=RP5LFw0k7caoQ12tcz4F09/YdMbEBu6F04hkmGGdFAh4fq7Y/ceYmUy39RXGIORs01 y6moec5ZsaUXntx7jZHGyBwTFQSXYx1nVxFbNQXZC92HYIivSspylu9uTzk7nnB+JZJz rM4YbnovLKFZSdW9HMbbHDMWHrRFS0ne5TxfQIc316CyKRLFcLS32AaRLrJ++/AWRQ41 troJ2wEAMQHJhp8bwu+kA5w0nLEu7t3ji/VFC45Q9hZU0AqBgjC/QMPH5m6ECGcGMsAQ 5p7Bj6q2p4QL/GufAyiQhQXcAmBpSo+FP/Cy3b60OLBVX6FfUaAsiNPYvy7J8mAvFTri o2hA== X-Gm-Message-State: AOAM530YmK/da6MRvarLZAIgNGRWlf53iIUFMiW7uHzqnwAm5gsY3C8y 6r75TCMKvskV60YbuZmasazJ8j/Pv3Y= X-Google-Smtp-Source: ABdhPJwJTh9pAppEgbycFpO8sf0InvhWg7/79QOG9OnTLVnu97CoyubIJTdEbVNKEPGoNo+rDMNzdQ== X-Received: by 2002:a9d:6acc:: with SMTP id m12mr314159otq.95.1602797454198; Thu, 15 Oct 2020 14:30:54 -0700 (PDT) Received: from localhost.localdomain ([170.130.31.90]) by smtp.gmail.com with ESMTPSA id 15sm233248ooy.36.2020.10.15.14.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 14:30:53 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Oct 2020 16:30:36 -0500 Message-Id: <20201015213039.1019624-3-cyrozap@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201015213039.1019624-1-cyrozap@gmail.com> References: <20191020095533.15016-1-cyrozap@gmail.com> <20201015213039.1019624-1-cyrozap@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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, the camera can 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;