From patchwork Thu Oct 15 21:30:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 22980 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 33BCD44ACD1 for ; Fri, 16 Oct 2020 01:28:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 113F868B91C; Fri, 16 Oct 2020 01:28:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f193.google.com (mail-yb1-f193.google.com [209.85.219.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7640A68ADBA for ; Fri, 16 Oct 2020 01:28:03 +0300 (EEST) Received: by mail-yb1-f193.google.com with SMTP id d15so275818ybl.10 for ; Thu, 15 Oct 2020 15:28:03 -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=iX3s51tKL4GCBfnvy5RoBAOzjf4W3zvdG/zuDrVQrdE=; b=snVsdo/7x5SPJjM2wRdS5w+OE4jKjoCCBKrdOVUzr/H4lVgMBZ9mIX7yJ794qXGKIz 5jFJxBSGqqNtfsqg8w2Cn/lwi2pd2wpdxbG07kWi0nF1pRzwOVcesAdsaYuBNzA7zKNN 8A/2k5n0iWDKI7fNPvgQIBl2E8cij43Qr11UZKWjzkQMFoLd1XENvx05oKEtlOqgGyRx m3fNyefQM/LCekW8kh4pDWl3ibqJdhiUEZBEVf3jaF5EUZSSRZTsBzN9yXrgU7HKzL2F HrDK9FweuBVcj1hiE3tOT+WInObtACKv2gyuidZZYUQ2xV4d+QLeQ4DlB2PiyRBk2GI+ KL9A== 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=iX3s51tKL4GCBfnvy5RoBAOzjf4W3zvdG/zuDrVQrdE=; b=ibyEB65Drw1BgDVMly08iZD6sypWr0uJCMV3wg3ymaJDehRkxzIero1iADSaJvvA8X ZyvShc/NJDxkVFSD3wHCorqWBD5wY9wF/OnGUmEPhoNC15dE0H0w2AbKi1gQPPJwpRrc TMUuPpCRVju9LoZTTFzMMKKeqhZ0YbVmO6F4tGoVrzDbsfCCvpz7j7goiLKbHieD7mVm 8b/qgvI45P++xSPoYzd/VpSCaNVDiwB3ry/vx8t4naU65giMOV8mC6PyNzPdvV+8h7cL m/pag+T1fZEiO2kIBplTzFLdsmpgCrhmf8OsWK7ITAX2pP2JbYylvUldhPFhCYiKoLkQ Djng== X-Gm-Message-State: AOAM530ZVozuSIoa2an6yk1GswLPRc9V6qJ4KLS/0NB2nEE5JQrA0UiX tZPUQi5TD3OAyOWKmfUO5M/7Xdu5Tuo= X-Google-Smtp-Source: ABdhPJxpvpmU4c2gt64pKdSUgusxWk27GbW+wdWijsSnOfn/BYbRPLrjOpncGmJkuAvP9oKF7LTZQA== X-Received: by 2002:a9d:5e90:: with SMTP id f16mr362397otl.266.1602797452246; Thu, 15 Oct 2020 14:30:52 -0700 (PDT) Received: from localhost.localdomain ([170.130.31.90]) by smtp.gmail.com with ESMTPSA id 15sm233248ooy.36.2020.10.15.14.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 14:30:51 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Oct 2020 16:30:35 -0500 Message-Id: <20201015213039.1019624-2-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 1/5] libdc1394: Enable listing sources 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" IIDC camera sources can now be listed by using the following command: ffmpeg -sources libdc1394 The basic structure of this function was borrowed from libavdevice/alsa.c:ff_alsa_get_device_list. Signed-off-by: Forest Crossman --- libavdevice/libdc1394.c | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index 003335fdd8..ec74cea87a 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -22,6 +22,8 @@ #include +#include "avdevice.h" + #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/log.h" @@ -288,6 +290,76 @@ static int dc1394_close(AVFormatContext * context) return 0; } +static int dc1394_get_device_list(AVFormatContext *c, AVDeviceInfoList *device_list) +{ + int ret = 0; + uint32_t i; + dc1394_t *d; + dc1394camera_t *camera; + dc1394camera_list_t *list; + AVDeviceInfo *new_device = NULL; + + d = dc1394_new(); + if (dc1394_camera_enumerate(d, &list) != DC1394_SUCCESS || !list) { + av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera.\n"); + ret = -1; + goto out; + } + + device_list->nb_devices = 0; + device_list->default_device = -1; + + if (list->num > 0) { + device_list->default_device = 0; + } + + for (i = 0; i < list->num; i++) { + new_device = av_mallocz(sizeof(AVDeviceInfo)); + if (!new_device) { + ret = AVERROR(ENOMEM); + break; + } + + camera = dc1394_camera_new_unit(d, list->ids[i].guid, list->ids[i].unit); + if (!camera) { + av_log(c, AV_LOG_ERROR, "Unable to open camera 0x%016"PRIx64":%"PRIu16"\n", + list->ids[i].guid, list->ids[i].unit); + ret = -1; + break; + } + + new_device->device_name = av_asprintf("0x%016"PRIx64":%"PRIu16, + list->ids[i].guid, list->ids[i].unit); + new_device->device_description = av_asprintf("%s %s", + camera->vendor, camera->model); + dc1394_camera_free(camera); + + if (!new_device->device_description || !new_device->device_name) { + ret = AVERROR(ENOMEM); + break; + } + + if ((ret = av_dynarray_add_nofree(&device_list->devices, + &device_list->nb_devices, new_device)) < 0) { + break; + } + + new_device = NULL; + } + if (new_device) { + av_free(new_device->device_description); + av_free(new_device->device_name); + av_free(new_device); + } + + /* Freeing list of cameras */ + dc1394_camera_free_list(list); + +out: + dc1394_free(d); + return ret; +} + AVInputFormat ff_libdc1394_demuxer = { .name = "libdc1394", .long_name = NULL_IF_CONFIG_SMALL("dc1394 v.2 A/V grab"), @@ -295,6 +367,7 @@ AVInputFormat ff_libdc1394_demuxer = { .read_header = dc1394_read_header, .read_packet = dc1394_read_packet, .read_close = dc1394_close, + .get_device_list = dc1394_get_device_list, .flags = AVFMT_NOFILE, .priv_class = &libdc1394_class, }; 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; From patchwork Thu Oct 15 21:30:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 22983 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:3414:0:0:0:0:0 with SMTP id b20csp784452yba; Thu, 15 Oct 2020 14:39:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR2XX/lD7BW03MttqyfIT79zIstGovoMPytFoyZRU//xYHD8nXvEDVtLG2ZEdqhZ59gwLC X-Received: by 2002:a05:6000:1084:: with SMTP id y4mr294354wrw.138.1602797945048; Thu, 15 Oct 2020 14:39:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602797945; cv=none; d=google.com; s=arc-20160816; b=RhogIgUjwvwfq/ZaX1JKqyDOSQpGDkOEXRISZQX3gEPLTUcyQokfKDuumirMB2dYIQ /6gCLIHqXXC1yr3wHr/uahO73DL1O/MW5IJMaXG3dqu/M2T5/d1oaOhqS1UbDE5yOBZ8 aMwPo0YQjqmR/f9BDFDDsuaqydqWN9WAEBpHjLVlRsDSIdLsgPfEocYfEL9Ywe368sPq 8ldAUOj08VM6RRCz4AYr9NoZI9jd+0uE7zyphdeClifrqY9TS5fTIGOC9ABSiWBnA95Y glN9Gsm4L29w64DSgO0yI50x5op+ZBfq1jFhH8P7A24aDIxV3B1K0Wa0LD/uW2NH6iS6 cLOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=rC763xqZW4bpcRn0vejaYohr6ybSN0YomH4pcI8B63Q=; b=RZXZ6Hs/91p5vl1pK/l5v4SKKe1vZG4NvfUbySctzyeMp90WFTNF5u0DP406EZydxz nln/+gx/ECnAWj98Jxm1JE+yfmG202206yKpu1TA27VC1uuGiN+IptUIA8ing8pHAL+W ECXMb2TTVvZSjz5zHyDe0061J2613a/6FaAOvEm5Iw9IVUPyAla5mS3XMmWbtZDl/FgO 0RI7bdVCM1Zt1DxOF3scTrfHFIEJ/SGqYEzwvDHZnHroDbw8Wj+5VWCLTKHPrXI2Dr6q X4wiVfKRlVQPqu0YDNgZz7pEM4GLMzNBaQU5yZcXhyMUcM57lN0bhscOvyCxTKoI1wsz 66wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Rtkq4n7s; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 72si296816wrc.120.2020.10.15.14.39.04; Thu, 15 Oct 2020 14:39:05 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Rtkq4n7s; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B426F68B972; Fri, 16 Oct 2020 00:39:03 +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 81D3D68B944 for ; Fri, 16 Oct 2020 00:38:52 +0300 (EEST) Received: by mail-yb1-f196.google.com with SMTP id l15so223388ybp.2 for ; Thu, 15 Oct 2020 14:38:52 -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=QbdLXWyoMNkpb2Dh5vTCa3okl/FVn85g3qf1B0lW7Nk=; b=Rtkq4n7sAP7JXdBoh0goyxs90OzXoZkMgO3bEJJ3Uv5xbaHTbNTdzwo1EkrIuT09O+ r9wtEwBEJHKfTCO5tRGRU1mz8ZUlMExWooTZ1yjCKueHRTcPqU/DGQxp2EGxGcDTlNH/ wIcmtXa0rd1arqXp2vyS1+z5TIitpYiJbM8wNqMdBMIPQQP575QmzwumvmXaUA3ZS5zU HOyyC2sxQGT792SapIY/USZDStUulwqLRnvWBx6vaiIhllgLvk6HzEOQ3GloI8o2KM37 I4F+5aB2GjxT1UmvEvLckT9RbBoXgXPUNjA7TnO5e0QpZW6HN3DBWeaKhO4ByKDK1dC5 b2Jg== 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=QbdLXWyoMNkpb2Dh5vTCa3okl/FVn85g3qf1B0lW7Nk=; b=ej7syPblM1Fh8HylqB36GoT7A1nUkn7mwy/YT6M3dEea9Vnaxa+8d7OMeXz1ieqflr 1qvOxjovbvVSGqu0hWT+flYyskt0bufdQfky0GG/kmZyH5SkwUue14p9Gf7M70AZjMPG gszShGeZVp30Izni5yYpvSp0uD/DJm2ePncZpjr+Z2NxTWwunpxb0/D16U3rtnoAcdl4 gR4U6FQs24dBeqIJuQqeIk0wzbKz0BDcO3o6z8l12OoIc6oSa0VL+ht2QlSh+lmEtUry ah2FYmH4PLHjuPPyKetie2OEcc7wJKQ7jChB2OFI1O8dF/6LSZl0sICfYgi2grP0iGVU xgrA== X-Gm-Message-State: AOAM5333PqzodQyJD1u9W1NdAlmUx9cl7GTva2ZO7wcgG2y15cBai4lB LQccq53bVXuqKdnSYvxTixC4IgwrYsk= X-Received: by 2002:a9d:d23:: with SMTP id 32mr392942oti.34.1602797455536; Thu, 15 Oct 2020 14:30:55 -0700 (PDT) Received: from localhost.localdomain ([170.130.31.90]) by smtp.gmail.com with ESMTPSA id 15sm233248ooy.36.2020.10.15.14.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 14:30:54 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Oct 2020 16:30:37 -0500 Message-Id: <20201015213039.1019624-4-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 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" X-TUID: cbM497dZunkV Content-Length: 6197 This enables a user to select a specific unit of a specific camera, instead of always selecting the first unit of the first camera that's found. 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 3d554bc8d8..46203833e9 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -1096,6 +1096,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) { From patchwork Thu Oct 15 21:30:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 22979 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 C6CE744BE50 for ; Fri, 16 Oct 2020 00:39:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AFD3E68B9D9; Fri, 16 Oct 2020 00:39:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f194.google.com (mail-yb1-f194.google.com [209.85.219.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 596D968B9C4 for ; Fri, 16 Oct 2020 00:39:01 +0300 (EEST) Received: by mail-yb1-f194.google.com with SMTP id s89so178394ybi.12 for ; Thu, 15 Oct 2020 14:39:01 -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=acNTLowLaIhRx05e+eq4nItcmN4cYOgVyxnoyLsFBRY=; b=asdScarzBOWSHnyoBSf6HhDwIRgoT5Q2xoNAxz0zFPEZVuTm9xxBmpocwGvz2Z9HNK Ir49Sv0ReGqNOdT7b8C1TsnSHfkqLxHilZF0ZhKB/fa5MMReoMmuxf8PyRytH/qomlLt QDDCfPMGRlNWHJhgMJ2THiS4SDn/+9xPLEKPNrrGMUbdSrj+uRwFGL46ILt6Fxl+6y+R emGcBSbw+Wg3JdeT74Ijl1zESsCDj18hHAtTb96wfxRVJA7gXg+VtWAXuezWGZi0Tpd0 GzAWxf3FuaM+XNrTzm4eQ+wUVkcuH/u9xYP4ceeGTzmLmUH6SW5/20fhTiwJIwRpV5V1 8mFA== 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=acNTLowLaIhRx05e+eq4nItcmN4cYOgVyxnoyLsFBRY=; b=oob9kTtJFHaG9YCFWJCXt1aVx1UNh0AkRdoOwhVDNaYPdoasyyFpgdT5STRSVMVREg LIh9it/+WqyyKTwSkRV/HAqadq6FFB3aA1bvGkyYjNlBaDt4Q6ZdJ4TfGqLOCUiVfc2u V+kqpOSnoYInWPCJoH0NSczD8lpc68Rstvqb3dA5n/2SrSzxleTZesA0RaFJ1v13r7ll a6kiIIy8gURAF/6Hf625m9nmCkajAQ3oSow+CnFmjhCTqlf8X1oI/RQ/dQpA+n6uphKK 1UNr/c3Gh0P4LLNL4UhL6huSd3FEJcmKcKPhP2Wg7x1xfn4aUD09AG9VfQjRfObyjtYc dIwQ== X-Gm-Message-State: AOAM531K4Bkfmu1W2geAGW6tcwSHQcug5kBi9ZA9BuTzMRSrJ1m7fLcS aBeRVd/lpiW88+aizrHxAd5Qm8tGas8= X-Google-Smtp-Source: ABdhPJyZt2vVG18wgPqsnZv14pgoYrkpZyCN8wlOgbh422nEnGNS6j35yz0yCIvdBXOBAVKefsYYdA== X-Received: by 2002:a9d:604e:: with SMTP id v14mr340740otj.234.1602797456863; Thu, 15 Oct 2020 14:30:56 -0700 (PDT) Received: from localhost.localdomain ([170.130.31.90]) by smtp.gmail.com with ESMTPSA id 15sm233248ooy.36.2020.10.15.14.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 14:30:56 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Oct 2020 16:30:38 -0500 Message-Id: <20201015213039.1019624-5-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 4/5] doc/indevs: Add examples for libdc1394 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 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/doc/indevs.texi b/doc/indevs.texi index 46203833e9..ca584f1d8e 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -1114,6 +1114,38 @@ Set the video size given as a string such as @code{640x480} or @code{hd720}. Default is @code{qvga}. @end table +@subsection Examples + +@itemize + +@item +List all the connected IIDC cameras. +@example +ffmpeg -sources libdc1394 +@end example + +@item +Grab and record the input of an Apple iSight. +@example +ffmpeg -f libdc1394 -pixel_format uyvy422 -video_size 320x240 -framerate 30 -i auto out.mkv +@end example + +@item +Grab and record the input of a specific Apple iSight, specified by its +GUID. +@example +ffmpeg -f libdc1394 -pixel_format uyvy422 -video_size 640x480 -framerate 15 -i 0x000a270004106ea3 out.mkv +@end example + +@item +Grab and record the second stream from a specific camera that has +multiple units. +@example +ffmpeg -f libdc1394 -pixel_format uyvy422 -video_size 640x480 -framerate 15 -i 0xfacade02bc394f15:1 out.mkv +@end example + +@end itemize + @section openal The OpenAL input device provides audio capture on all systems with a From patchwork Thu Oct 15 21:30:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 22976 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 8413944B8E7 for ; Fri, 16 Oct 2020 00:31:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61A9C68B886; Fri, 16 Oct 2020 00:31:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0B35468B6D4 for ; Fri, 16 Oct 2020 00:31:00 +0300 (EEST) Received: by mail-ot1-f53.google.com with SMTP id t15so603490otk.0 for ; Thu, 15 Oct 2020 14:30:59 -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=O5vHWZJhgP5ppDM37Ag3TnIxwxhvmHxuiHNoC8DOc7I=; b=foXzZVJxAhB1vMjIZc9jbLM3Fu8u1DJlpL22XJBUb0i9MJUwY19sfFvAcvUt6zND2y PKwHW3hfBafgiX+dA7VJUWUtrxBE/e6SsG/in/nV+7P/RjMaI2ItMFb5iVDgzh5s7w7M Fg4dYesAxuZqz5dWalFKUsFgFeJFyY0cvnlUCo2EhHrW7XmtAEIk99jhbB2cjhVI5haF ufFkweMh5YfLuDMGDUNm6/z66XS87boAgV5X+Rgh2xrGpI0XfrXR012vPiHr0W2h+R1R ewDHK7bicxBJfuGPwNy4U8sAYldH+g73en4LrjwKy9oRtY2X3i4r8WCooYzxP+K8AYvN DdTQ== 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=O5vHWZJhgP5ppDM37Ag3TnIxwxhvmHxuiHNoC8DOc7I=; b=oB5gdcBampfq4plaT0NG/Hn1cBTQA3LBzArzjsuv/Y93pO92aOUmjITpgmFE1lslGZ a9IuoXjxYdRk/4TOtynHGX+FIoWAZkDcK9BVpTyqx6ugKh+8MyJr5CjaYrI5iUWJiBTp vr8q/Im87fIDMxJZh5plgNvMNM/GI4GC6V1G7QkRN2BqpTuoJQEzd+ekIhUad6OlsJEa syvi2g7sw3SNEqZpMLv8AYq+8gLxWgYwxoWODEPKwmRH/MyGYz8Pgf+2ULCaHVmvaxmh z97CMgHEdPRjazMpgoVzNld050gYNxg9ViC5UrnqnFqEhC3ifR0Tcax0AIcRhyszI8SW EulA== X-Gm-Message-State: AOAM5305ew9/h9CbiW550mCyfjPIltZvLsxLIszPgTWhWGWDHCjbiQet ahXfd9iuve8Wk4Cv2IEWOxTeMLFkhqY= X-Google-Smtp-Source: ABdhPJwJftAnp4DEtm4JE3OqqUxw7pMIKUodPB4SsfcvPvCGGB0SiivlEycZFD92NflVC9SNUnw3uA== X-Received: by 2002:a05:6830:1f51:: with SMTP id u17mr311935oth.223.1602797458044; Thu, 15 Oct 2020 14:30:58 -0700 (PDT) Received: from localhost.localdomain ([170.130.31.90]) by smtp.gmail.com with ESMTPSA id 15sm233248ooy.36.2020.10.15.14.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 14:30:57 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Oct 2020 16:30:39 -0500 Message-Id: <20201015213039.1019624-6-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 5/5] libdc1394: Fix PTS wrapping 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, the timestamp will unexpectedly wrap around after approximately 2146 frames (on a 64-bit system, at least), which is about 19 minutes at the lowest framerate supported by the IIDC standard and about 9 seconds at the highest supported framerate. To fix this, we use av_rescale() to do the PTS calculation, then we change both the current_frame and frame_rate variables to int64_t (for consistency) and keep the PTS wraparound bits set to 64. For all intents and purposes, however, the PTS will never wrap around, because even at 240 fps--the highest framerate supported by the IIDC standard--it would take over 292 million years of continuous recording before an overflow would occur. Signed-off-by: Forest Crossman --- libavdevice/libdc1394.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index 90252f7c4a..1e138edac2 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -40,8 +40,8 @@ typedef struct dc1394_data { dc1394_t *d; dc1394camera_t *camera; dc1394video_frame_t *frame; - int current_frame; - int frame_rate; /**< frames per 1000 seconds (fps * 1000) */ + int64_t current_frame; + int64_t frame_rate; /**< frames per 1000 seconds (fps * 1000) */ char *video_size; /**< String describing video size, set by a private option. */ char *pixel_format; /**< Set by a private option. */ char *framerate; /**< Set by a private option. */ @@ -133,8 +133,8 @@ static inline int dc1394_read_common(AVFormatContext *c, break; if (!fps->frame_rate || !fmt->width) { - av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", av_get_pix_fmt_name(pix_fmt), - width, height, dc1394->frame_rate); + av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%"PRId64":1000fps\n", + av_get_pix_fmt_name(pix_fmt), width, height, dc1394->frame_rate); ret = AVERROR(EINVAL); goto out; } @@ -342,14 +342,14 @@ static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt) /* discard stale frame */ if (dc1394->current_frame++) { if (dc1394_capture_enqueue(dc1394->camera, dc1394->frame) != DC1394_SUCCESS) - av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame); + av_log(c, AV_LOG_ERROR, "failed to release %"PRId64" frame\n", dc1394->current_frame); } res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame); if (res == DC1394_SUCCESS) { pkt->data = (uint8_t *)dc1394->frame->image; pkt->size = dc1394->frame->image_bytes; - pkt->pts = dc1394->current_frame * 1000000 / dc1394->frame_rate; + pkt->pts = av_rescale(dc1394->current_frame, 1000000, dc1394->frame_rate); pkt->flags |= AV_PKT_FLAG_KEY; pkt->stream_index = dc1394->stream_index; } else {