From patchwork Mon Oct 28 01:37:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 15999 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 CF4AC44A9EC for ; Mon, 28 Oct 2019 03:45:27 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A3FEC68AC51; Mon, 28 Oct 2019 03:45:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 24B2368A435 for ; Mon, 28 Oct 2019 03:45:21 +0200 (EET) Received: by mail-qk1-f193.google.com with SMTP id c25so860474qkk.1 for ; Sun, 27 Oct 2019 18:45:21 -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=qR7KgTClwyJaetfRtCqS1y63ACoV3LMDg1asjVX1SsE=; b=tfLzmBXxPmG3XYDYqBbS43Ocqar+UORXJI2o8NoYnx+hoViyCB4AGs+unjMK4YcXpp LX0H0wsWcWu8uRKjBDrTd08gXNG0cnR+oPjJk2osc/Jb/yt+jYJw+t67ZNtZwMAugeuU V1S8fx2Gs+EBN/eoGHR/eeYjVWiLWXVreXyZS2IXmS3gkCYG80BKfIE2l9pVVN66N/BO sONsOvrXOkFAG3YFmyVBUOgBRdNhOSBCpxxbQS6Y8kiRnPsOdHEG0VwB+y4fkqhJlb3A +IGiHC0qx9fMLXpyvZTXh87zBXYCiiZchK82+81J+cIjuX15CILiBbu/H29OWv+ECsd1 3reg== 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=qR7KgTClwyJaetfRtCqS1y63ACoV3LMDg1asjVX1SsE=; b=VEaF8mCIyXcTVU00U4mBlwh1cy7WxPnlj6k5THZqYve9b/DOp6gYDuiARa7HPxMA9q aN3IfDZIEW9Kh+vz6g1OKenjlFbPR1lFG7sw27Neo12OuJNVibYquP733InS5Rl+6rSH jqieisQMeEPZCoBhyPP00F00UX5GuLY81Km7QfOsywclNy7Iy+D8mvnpuBqS0mHMUX+Q +VDE1GChsELO43xGjEQgGs6WWwOsczeG/rIRB/Q9pxxEc/ufW1eu8poRZgtcwraY5PZi Ec5VyO9fYf0UTzErwIHW+dvZW78LpWOauYBxP1KURfG6YxD5Bpqg0v3whc4Qv6aSo6en cTcg== X-Gm-Message-State: APjAAAXM9CJYNcramejtPIRPlHgj7TWT2t4hGrhSUUerYZt8kdnj23TA RNexlY9nb046yHcfrGIrXmGvWAKMRHg= X-Google-Smtp-Source: APXvYqwmsUIY/c5Z667eF8sfp9sinDCi6pDXgTUDGeKi2hc7LrxmQOUctlFGndSU59a6pzbqnriB9w== X-Received: by 2002:a37:7603:: with SMTP id r3mr13192968qkc.116.1572226660524; Sun, 27 Oct 2019 18:37:40 -0700 (PDT) Received: from localhost.localdomain ([194.59.251.37]) by smtp.gmail.com with ESMTPSA id c15sm5212556qkc.101.2019.10.27.18.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2019 18:37:39 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Sun, 27 Oct 2019 20:37:28 -0500 Message-Id: <2f2aae0741c15e2b580e255302c72c993c1fecf8.1572226177.git.cyrozap@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: <20191020095533.15016-1-cyrozap@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/5] libdc1394: Enable specifying a camera by GUID[:unit] 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" Signed-off-by: Forest Crossman --- doc/indevs.texi | 3 ++ libavdevice/libdc1394.c | 70 ++++++++++++++++++++++++++++------------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 14595774f3..757fac91de 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -1068,6 +1068,9 @@ IIDC1394 input device, based on libdc1394 and libraw1394. Requires the configure option @code{--enable-libdc1394}. +Specify the FireWire device GUID to be used as the input file, or "auto" +to choose the first device detected. + @subsection Options @table @option diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index 7be1d7b8dd..90252f7c4a 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -171,6 +171,8 @@ static int dc1394_read_header(AVFormatContext *c) dc1394_data* dc1394 = c->priv_data; dc1394camera_list_t *list; int res, i; + uint64_t guid; + uint16_t unit; const struct dc1394_frame_format *fmt = NULL; const struct dc1394_frame_rate *fps = NULL; const struct dc1394_frame_format *tmp_fmt; @@ -186,33 +188,57 @@ static int dc1394_read_header(AVFormatContext *c) /* Now let us prep the hardware. */ dc1394->d = dc1394_new(); - if (dc1394_camera_enumerate(dc1394->d, &list) != DC1394_SUCCESS || !list) { - av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera.\n"); - goto out; - } - if (list->num == 0) { - av_log(c, AV_LOG_ERROR, "No cameras found.\n"); - dc1394_camera_free_list(list); - goto out; - } + /* Parse URL */ + if (sscanf(c->url, "0x%"SCNx64":%"SCNu16, &guid, &unit) == 2) { + /* If both the GUID and unit are set, open the device based on + * those values exactly. */ + dc1394->camera = dc1394_camera_new_unit(dc1394->d, guid, unit); + if (!dc1394->camera) { + av_log(c, AV_LOG_ERROR, "Unable to open camera 0x%016"PRIx64":%"PRIu16"\n", + guid, unit); + goto out; + } + } else if (sscanf(c->url, "0x%"SCNx64, &guid) == 1) { + /* If the GUID is set, but not the unit, grab the device using + * the first unit found. */ + dc1394->camera = dc1394_camera_new(dc1394->d, guid); + if (!dc1394->camera) { + av_log(c, AV_LOG_ERROR, "Unable to open camera 0x%016"PRIx64"\n", + guid); + goto out; + } + } else { + /* If no GUID is set, or is set to "auto", use the first camera + * found. */ + if (dc1394_camera_enumerate(dc1394->d, &list) != DC1394_SUCCESS || !list) { + av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera.\n"); + goto out; + } - /* FIXME: To select a specific camera I need to search in list its guid */ - dc1394->camera = dc1394_camera_new (dc1394->d, list->ids[0].guid); + if (list->num == 0) { + av_log(c, AV_LOG_ERROR, "No cameras found.\n"); + dc1394_camera_free_list(list); + goto out; + } - if (!dc1394->camera) { - av_log(c, AV_LOG_ERROR, "Unable to open camera with guid 0x%"PRIx64"\n", - list->ids[0].guid); - dc1394_camera_free_list(list); - goto out; - } + if (list->num > 1) { + av_log(c, AV_LOG_INFO, "Multiple cameras detected, using the first camera found.\n"); + } - if (list->num > 1) { - av_log(c, AV_LOG_INFO, "Working with the first camera found\n"); - } + guid = list->ids[0].guid; + unit = list->ids[0].unit; + dc1394->camera = dc1394_camera_new_unit(dc1394->d, guid, unit); - /* Freeing list of cameras */ - dc1394_camera_free_list (list); + /* Freeing list of cameras */ + dc1394_camera_free_list (list); + + if (!dc1394->camera) { + av_log(c, AV_LOG_ERROR, "Unable to open camera 0x%016"PRIx64":%"PRIu16"\n", + guid, unit); + goto out; + } + } /* Select MAX Speed possible from the cam */ if (dc1394->camera->bmode_capable>0) {