From patchwork Mon Mar 19 19:35:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 8044 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp3021158jad; Mon, 19 Mar 2018 12:36:53 -0700 (PDT) X-Google-Smtp-Source: AG47ELvF6bcS9Htk0hRBzYnsjBLuvbeUlk0iRtETbYUec0l4hrdAo+owTF91RZkqBbLVzpp8i7O4 X-Received: by 10.223.199.10 with SMTP id k10mr10220787wrg.186.1521488213565; Mon, 19 Mar 2018 12:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521488213; cv=none; d=google.com; s=arc-20160816; b=Nbddx0ku5YBzxBbLjklonf129rOAL9IFjQi/rOIGzpkwkNEICCrzEkZvdAcABDSUwx hwY4YcUjJZVgvj9v2BdApYDfT6Ig8lEkXH+5XSX2EfLefvxWO78hdxuIr0Htqo9HmcR3 rtAjs9YZHtZc+sbN45VbONSQsS2Pi0Jz7cEAVAtT5BX1FEdWNhzfNS9TjDttPO83fc3y ajnJbLRwy+Kp8oZjpbFnoyVgHS+Mc/88g7boM6i5e0faytNy3kzLEHyr7Q9pa8mDDxu1 Z6TyeMZbK3N1xfQVq1yAzM5mpRw2zS/UEHzgHMQVNbeLjs8gMvn+fAlrioPvYWqwBZZ2 febQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-signature:delivered-to :arc-authentication-results; bh=bqfLELs0wAGfHEC3bo53TEUr//6BPXNsE9Zqbtv1bog=; b=S6NSy46gi/fDzlmX9+8a+JCae8owIOZ6xVQ8t0Me2bVTn6jIPLsQjMKTqYRfNHWm0+ YesCJu6NkUScpQXbKtBPaxnLkrlqEzhYWhTmocO8v+Pc/0Bz6/Z0zA36Vq7xrwFai9kj lWlr97jxAhgnQ6JR1rua0nArdf47uGzwZAFhkMg4oWsTtzBIi4vkZD/TCyYHAu72IqDj ump2cTMLgmQd1MKhebxa3gghw6w1Mll9Hz4+m6NSZIgYhfvfL4MBUjFzt0BxpoutQcJv AOzPBNsRZO8Aewg01PUI1CyIBOpoh8IENZVeuLpKezQp3lLr2482//gdlacxYkG223F6 17bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@itanimul.li header.s=fm1 header.b=t9L91Ftk; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm2 header.b=DF15WVG/; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v101si514104wrb.396.2018.03.19.12.36.53; Mon, 19 Mar 2018 12:36:53 -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=@itanimul.li header.s=fm1 header.b=t9L91Ftk; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm2 header.b=DF15WVG/; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CFD7689E88; Mon, 19 Mar 2018 21:35:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E6E52689E43 for ; Mon, 19 Mar 2018 21:35:42 +0200 (EET) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4DAD320F9E for ; Mon, 19 Mar 2018 15:35:53 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Mon, 19 Mar 2018 15:35:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itanimul.li; h= date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=t6aJDVKNaPenmRrD8 69UDE193Y5jmpjmbF4wB5wil+I=; b=t9L91FtkXCBHVzYdXyyAs+z9162yQNg8N RO4gYXJo2aqQ8Agf4A8nxJJ9bKqD39b++StU8q4XKHY+TF0zL+V5dlbd7UmjZ/mj ghJTu+UCDWadOLNKlsNYXYBTIxjamSjlsSOlCvx1B6iEgeqWT3YlkTsEwrPZkkiM jBDS5kdxKgcTsm9D+/YmBYFDydRjCbPz9KQPh+5ULtvAkq9irl/wyiu/MopLVlmF UHQLwnAAqOLTnMgKMnQXJQHlfFtcGZ+vgmNQrAU3LXmNIfeBG2WJKTsxgFqrRpQg 9DkgfLgRfNXLBoaoO6klW2v5Ofh9xcPz5sO9TRUXOsOcKgfnkhe7g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=t6aJDVKNaPenmRrD869UDE193Y5jmpjmbF4wB5wil+I=; b=DF15WVG/ ZTkd8ImVzCUDgOrQfvbuTWgGE4lEhcV7yLFv4wY3HCLcidaLpmkhR6M5r1h1yOyg UWtRKCIZZtqUHgjF8ql9q8tzQ4HVj2FnLliFctQDm0W2e+0YJwHMOW/X1aolStL6 gvhqara4hg6c90/CUQgEaxjiF12VhxNdjnljlzq0BG1bu2wvEZLmLDK20biPgVLq qUTqz+TcLVHPJczA21+rz4ioqalPKGwHiao31j4OV1SVU8vNyEbAzvoj5kG/NQk4 YmhiwTIni4c43NnWw6D9A2Dwz+yzSOJedUK8jD9luMEC0AJEadDbmVi9LnQfDYce 2kZcYLkBHr8xWQ== X-ME-Sender: Received: from localhost.localdomain (cpc75394-sotn16-2-0-cust168.15-1.cable.virginm.net [82.22.8.169]) by mail.messagingengine.com (Postfix) with ESMTPA id BB95F7E13B for ; Mon, 19 Mar 2018 15:35:52 -0400 (EDT) From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Mar 2018 19:35:39 +0000 Message-Id: <20180319193541.2977-6-josh@itanimul.li> X-Mailer: git-send-email 2.14.3 (Apple Git-98) In-Reply-To: <20180319193541.2977-1-josh@itanimul.li> References: <4d3ccc63-c2f9-37bb-a33a-88cd0538faa8@itanimul.li> <20180319193541.2977-1-josh@itanimul.li> Subject: [FFmpeg-devel] [PATCH v3 5/7] lavf, lavd: add AVClass for lavd & use iterate API 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add an AVClass for AVDevice as the .child_class_next member for lavf's AVClass will no longer find devices. --- fftools/cmdutils.c | 10 +++++ fftools/ffmpeg_opt.c | 2 +- libavdevice/Makefile | 1 + libavdevice/avdevice.h | 1 + libavdevice/options.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ libavformat/options.c | 46 +++++++++++--------- 6 files changed, 154 insertions(+), 21 deletions(-) create mode 100644 libavdevice/options.c diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 2da313cc0a..88ff3ec87a 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -549,6 +549,9 @@ int opt_default(void *optctx, const char *opt, const char *arg) char opt_stripped[128]; const char *p; const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(); +#if CONFIG_AVDEVICE + const AVClass *dc = avdevice_get_class(); +#endif #if CONFIG_AVRESAMPLE const AVClass *rc = avresample_get_class(); #endif @@ -580,6 +583,13 @@ int opt_default(void *optctx, const char *opt, const char *arg) av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt); consumed = 1; } +#if CONFIG_AVDEVICE + if ((o = opt_find(&dc, opt, NULL, 0, + AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { + av_dict_set(&format_opts, opt, arg, FLAGS); + consumed = 1; + } +#endif #if CONFIG_SWSCALE if (!consumed && (o = opt_find(&sc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 45c26c391e..82944c903a 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -967,7 +967,7 @@ static int open_input_file(OptionsContext *o, const char *filename) { InputFile *f; AVFormatContext *ic; - const AVInputFormat *file_iformat = NULL; + AVInputFormat *file_iformat = NULL; int err, i, ret; int64_t timestamp; AVDictionary *unused_opts = NULL; diff --git a/libavdevice/Makefile b/libavdevice/Makefile index f11a6f2a86..65f7c2971d 100644 --- a/libavdevice/Makefile +++ b/libavdevice/Makefile @@ -7,6 +7,7 @@ HEADERS = avdevice.h \ OBJS = alldevices.o \ avdevice.o \ utils.o \ + options.o OBJS-$(HAVE_LIBC_MSVCRT) += file_open.o OBJS-$(CONFIG_SHARED) += reverse.o diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index dd6ad9365e..bacc2c3aad 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -535,6 +535,7 @@ int avdevice_list_input_sources(struct AVInputFormat *device, const char *device int avdevice_list_output_sinks(struct AVOutputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list); +const AVClass *avdevice_get_class(void); /** * @} */ diff --git a/libavdevice/options.c b/libavdevice/options.c new file mode 100644 index 0000000000..e9d79d7481 --- /dev/null +++ b/libavdevice/options.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "libavformat/avformat.h" + +#include "libavdevice/avdevice.h" + +#include "libavutil/internal.h" +#include "libavutil/opt.h" + +/** + * @file + * Options definition for AVFormatContext. + */ + +FF_DISABLE_DEPRECATION_WARNINGS +//#include "options_table.h" +static const AVOption avdevice_options[] = { +{ NULL }, +}; +FF_ENABLE_DEPRECATION_WARNINGS + +static const char* device_to_name(void* ptr) +{ + AVFormatContext* fc = (AVFormatContext*) ptr; + if(fc->iformat) return fc->iformat->name; + else if(fc->oformat) return fc->oformat->name; + else return "NULL"; +} + +static void *device_child_next(void *obj, void *prev) +{ + AVFormatContext *s = obj; + if (!prev && s->priv_data && + ((s->iformat && s->iformat->priv_class) || + s->oformat && s->oformat->priv_class)) + return s->priv_data; + if (s->pb && s->pb->av_class && prev != s->pb) + return s->pb; + return NULL; +} + +static const AVClass *device_child_class_next(const AVClass *prev) +{ + void *opaque = NULL; + const AVInputFormat *ifmt = NULL; + const AVOutputFormat *ofmt = NULL; + + while ((ifmt = av_indev_iterate(&opaque))) { + if (prev && ifmt->priv_class == prev) + goto next_demuxer; + } + opaque = NULL; + + while ((ofmt = av_outdev_iterate(&opaque))) { + if (prev && ofmt->priv_class == prev) + goto next_muxer; + } + opaque = NULL; + +next_demuxer: + while (ifmt = av_indev_iterate(&opaque)) { + if (ifmt->priv_class) + return ifmt->priv_class; + } + opaque = NULL; + +next_muxer: + while (ofmt = av_outdev_iterate(&opaque)) { + if (ofmt->priv_class) + return ofmt->priv_class; + } + + return NULL; +} + +static AVClassCategory get_category(void *ptr) +{ + AVFormatContext* s = ptr; + if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER; + else return AV_CLASS_CATEGORY_MUXER; +} + +static const AVClass av_device_context_class = { + .class_name = "AVDeviceContext", + .item_name = device_to_name, + .option = avdevice_options, + .version = LIBAVUTIL_VERSION_INT, + .child_next = device_child_next, + .child_class_next = device_child_class_next, + .category = AV_CLASS_CATEGORY_MUXER, + .get_category = get_category, +}; + + +const AVClass *avdevice_get_class(void) +{ + return &av_device_context_class; +} diff --git a/libavformat/options.c b/libavformat/options.c index c188c23506..f6a2fabe6e 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -55,28 +55,34 @@ static void *format_child_next(void *obj, void *prev) static const AVClass *format_child_class_next(const AVClass *prev) { - AVInputFormat *ifmt = NULL; - AVOutputFormat *ofmt = NULL; - - if (!prev) - return &ff_avio_class; - - while ((ifmt = av_iformat_next(ifmt))) - if (ifmt->priv_class == prev) - break; - - if (!ifmt) - while ((ofmt = av_oformat_next(ofmt))) - if (ofmt->priv_class == prev) - break; - if (!ofmt) - while (ifmt = av_iformat_next(ifmt)) - if (ifmt->priv_class) - return ifmt->priv_class; - - while (ofmt = av_oformat_next(ofmt)) + void *opaque = NULL; + const AVInputFormat *ifmt = NULL; + const AVOutputFormat *ofmt = NULL; + + while ((ifmt = av_demuxer_iterate(&opaque))) { + if (prev && ifmt->priv_class == prev) + goto next_demuxer; + } + opaque = NULL; + + while ((ofmt = av_muxer_iterate(&opaque))) { + if (prev && ofmt->priv_class == prev) + goto next_muxer; + } + opaque = NULL; + +next_demuxer: + while (ifmt = av_demuxer_iterate(&opaque)) { + if (ifmt->priv_class) + return ifmt->priv_class; + } + opaque = NULL; + +next_muxer: + while (ofmt = av_muxer_iterate(&opaque)) { if (ofmt->priv_class) return ofmt->priv_class; + } return NULL; }