From patchwork Sun Oct 20 09:55:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 15858 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 90AD14489DD for ; Sun, 20 Oct 2019 12:56:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7B73A68AF19; Sun, 20 Oct 2019 12:56:04 +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 C9BB368AEE8 for ; Sun, 20 Oct 2019 12:55:57 +0300 (EEST) Received: by mail-oi1-f193.google.com with SMTP id i185so8689722oif.9 for ; Sun, 20 Oct 2019 02:55:57 -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=Zvm3VvHRzUSGaYjmE6nHhLNn2o7ihZ9ZVOx/9MPAwIgYjq+NXh+DfT4+pSUBLIdXAI 4ic19gBWa9ayXkLkV/vYCh7lY6s3HqBBxJ9iEC3zeab6e7LPaQWEt5TmpHKEryFOsate BSBDsbYqfzsx66BDscvgjJRD2+2qDVK2NZaiLvgldkNYDozUJDNpvIsXqsoohGGrIm2H pnWZWpAj/p5/tw/aDNuMW1/PwsQy9zVqEY1Jyg1bG4AFXu25prmK1t4ifSlSxiHHJZ+S Yg5p+GEt++UvpPkyFkne5Vxo0bCiR2mmAX8IKX9FRXfGwZFVjK0HxzACM89sXBNvhDrS HvBw== 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=baaWL/rstiVZiOyequ8PYsy2PNNNuFK80AwG+vbSu3jakBPFs+SJME6VoOuxhJfSr0 tEhPkPhf4t8k6SbrAehGlSnl35i9a8ZREspG7oOlgjJ9m86cEhn4ouxA85CoXYsMinG/ CSPBMpqcHCYFR4CTDGQhpmy5cvugbeEFYKmOojVt7VvcENL0jaE43kPzli8QY26s6iPq 47Jz4K0XZZ4XWV12EXb3i21EOYTxOHHQpeBGmUForabbE5HwoylGyCq3x2M4hcXsE3gZ YY2qInu9PoHMjz2uhxbfgIVBTcsHcw7DvfrEvvtCB7utMlzBWJfe9Kj40zXOx3T/6owN cUFg== X-Gm-Message-State: APjAAAUE99KgfHSF+MtbHpSkjY969169kSS7acVrhXeUMpya0dajwN8V cHWAKslXA02+TdzJu4uJ1Y5nOG8b X-Google-Smtp-Source: APXvYqyQQzIIQXHU+0vCGEvURs0PB6NpmFDx0hp/mC18tjUTAHyVRLBYQjY8sOEL7PdccZCuZpxT/A== X-Received: by 2002:aca:ab86:: with SMTP id u128mr15054021oie.29.1571565356175; Sun, 20 Oct 2019 02:55:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2019 02:55:55 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2019 04:55:31 -0500 Message-Id: <20191020095533.15016-4-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 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) {