From patchwork Fri Mar 23 20:48:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 8127 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp862646jad; Fri, 23 Mar 2018 13:49:19 -0700 (PDT) X-Google-Smtp-Source: AG47ELupZWEVB2PhpWTq1IvhaHrPFy0OHukvrYhM5IvovQgxTf79wPKjbFGGaNozTAsUFymQsK+0 X-Received: by 10.223.162.10 with SMTP id p10mr23927334wra.93.1521838159165; Fri, 23 Mar 2018 13:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521838159; cv=none; d=google.com; s=arc-20160816; b=AYHvbFVivu565Jt5uy2yIK/2OtlXQVnkMEvq9bzOTLYps5FuaUOvNjJRMfRfisUkci jWo4wrfGP0LZU7xD3d7DYd0/2iPhiwCurKA0FewxZrZ9bCNOB7ZVHdjuWDNBS5Ondtrj siQpm4/HDH/WdySWj9QWV2/zkt7xhOmt6Kp9BhBZ/+DPR41E3ar/D3AK7EFfLUZTPvIS gZUOZnkMqTSwSjdtoUrZ3RitUdrmTRhL7MMpAaCTgO+kjpKJG+L+0dglCL8IxH09r3Gv lVL9mwPtJxjUrBgJjOIhm1bPPXqcNqrh8Dlk3lAXw2QWBiDGSVOiB9G+O+liED7bNzrE XqJA== 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=ac7PGwi8vJkHbaisDzUZGpy2L2OKMtBI+5PV24EHG4A=; b=Ili3pV8mVbpP0V5WaLjDxZP51wdKHeLkIBI9YtCJsIeApPqZ4wHsf95hWOKtJbiWLk ixjZcFMlwghQpfyTD1pUR+3blLjyP9+r77J6PadWoWZnDcwAp71CqT6pRyMSVigVkTbv 4DgAl8F/mJZAsvweQNyWCtG0Vh3x5ybFmT3RsKQCIme2YjhTXURux4xTqSIpZAWCFVwQ /FWNNeauvQT9BHL3bYckQ5EZ5zUwZag3g8KdCuGmww+wsi7EUCYhfEFr2pLkMQR1n5fC o439jII+pIROcgw92IzbCmGgSDGzRT1umZjkgjZAenS1u03vMv2k+tck97qpcpZ/y+7x 4oig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@itanimul.li header.s=fm1 header.b=x3tkNUJJ; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm2 header.b=iRmFbiQx; 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 t200si6537870wmd.195.2018.03.23.13.49.18; Fri, 23 Mar 2018 13:49:19 -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=x3tkNUJJ; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm2 header.b=iRmFbiQx; 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 06431689A81; Fri, 23 Mar 2018 22:48:27 +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 0E5FF689982 for ; Fri, 23 Mar 2018 22:48:18 +0200 (EET) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 323A021091 for ; Fri, 23 Mar 2018 16:48:33 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Fri, 23 Mar 2018 16:48:33 -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=EtikYScOXZwvSsRFH l3C/QPUPqSZK2E1PDN6DoFM4T4=; b=x3tkNUJJRtLCwZskV/FZToVXs1GMFVSIz U6s0KACKypNF6ZexYuegUp2hY5zIS2/C/z0rb4Cuyod+iZhjEGX6wtDGM7MUX6oo ZwwJ8BhSwZI+23WGqBEZEO0JP5iPsYepmxYPnmOZ/n8V7A5FkXaZ07Q7o5sLiz+J 91WZlwiHTxk/b+WCJOxBXsORtVNE09VNYNf3r8s+5Z+FhvwmbcUgjCrIu4vRIiKf VAS3qmVTmbVCYplSR6/CKGM4qvbRBtQdUv0cbKpIF3AnYMdEJKprcat2maf6Bdwd 5mlqKZtW32YE/Isf8uE/VZe3CCuiX3B5lzS4oabHcdf2ljeflkY8g== 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=EtikYScOXZwvSsRFHl3C/QPUPqSZK2E1PDN6DoFM4T4=; b=iRmFbiQx fOq2ipQFQ6YxLMQvH7K7thq+qgG+wYwLqZMTzpdHzl8DAyR4O6LnnIfupuF+bioZ 9Yi/pqV8qhIqsNvMS/ofIRtTJmx3/e6RvhLwS+FnalAwTlszxrvmVMM30lsYy8na rwdSmT+gHwmDG0T+K7+y53ZLs8wTT40KkEHAz+p28ESZVsOMV3WOz3pOdaJkB+qt a6mfBQPvoTpPJ5o8qtP4hzi+GGxszbVWrGgUAVe3AujKkFXxj4JlUEdfG6EpXJbU SNt2bP09dTmOZ7hMRCa6Wh9t9LjSz1ZqErYX9nLZop7Ee87vIZFFzGM3Rcw3Haj7 5e7UEKz+t1wGpw== 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 B0EC5240DC for ; Fri, 23 Mar 2018 16:48:32 -0400 (EDT) From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Mar 2018 20:48:18 +0000 Message-Id: <20180323204819.86159-5-josh@itanimul.li> X-Mailer: git-send-email 2.14.3 (Apple Git-98) In-Reply-To: <20180323204819.86159-1-josh@itanimul.li> References: <20180323204819.86159-1-josh@itanimul.li> Subject: [FFmpeg-devel] [PATCH 4/5] lavd: remove linked lists 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" --- configure | 23 +++++++------ libavdevice/alldevices.c | 87 ++++++++++++++++++++++-------------------------- libavformat/allformats.c | 78 +++++++++++++++++++++++++++++++++++++------ libavformat/avformat.h | 2 ++ 4 files changed, 120 insertions(+), 70 deletions(-) diff --git a/configure b/configure index 0bb789cae4..3a99f46c87 100755 --- a/configure +++ b/configure @@ -3561,21 +3561,12 @@ for v in "$@"; do FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}" done -find_things(){ - thing=$1 - pattern=$2 - file=$source_path/$3 - sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" "$file" -} - -OUTDEV_LIST=$(find_things outdev OUTDEV libavdevice/alldevices.c) -INDEV_LIST=$(find_things indev _IN libavdevice/alldevices.c) - find_things_extern(){ thing=$1 pattern=$2 file=$source_path/$3 - sed -n "s/^[^#]*extern.*$pattern *ff_\([^ ]*\)_$thing;/\1_$thing/p" "$file" + out=${4:-$thing} + sed -n "s/^[^#]*extern.*$pattern *ff_\([^ ]*\)_$thing;/\1_$out/p" "$file" } find_filters_extern(){ @@ -3585,6 +3576,8 @@ find_filters_extern(){ } FILTER_LIST=$(find_filters_extern libavfilter/allfilters.c) +OUTDEV_LIST=$(find_things_extern muxer AVOutputFormat libavdevice/alldevices.c outdev) +INDEV_LIST=$(find_things_extern demuxer AVInputFormat libavdevice/alldevices.c indev) MUXER_LIST=$(find_things_extern muxer AVOutputFormat libavformat/allformats.c) DEMUXER_LIST=$(find_things_extern demuxer AVInputFormat libavformat/allformats.c) ENCODER_LIST=$(find_things_extern encoder AVCodec libavcodec/allcodecs.c) @@ -7110,6 +7103,12 @@ print_enabled_components(){ filter_list) c=$(full_filter_name $(remove_suffix _filter $c)) ;; + indev_list) + c=$(add_suffix _demuxer $(remove_suffix _indev $c)) + ;; + outdev_list) + c=$(add_suffix _muxer $(remove_suffix _outdev $c)) + ;; esac printf " &ff_%s,\n" $c >> $TMPH fi @@ -7124,6 +7123,8 @@ print_enabled_components libavcodec/parser_list.c AVCodecParser parser_list $PAR print_enabled_components libavcodec/bsf_list.c AVBitStreamFilter bitstream_filters $BSF_LIST print_enabled_components libavformat/demuxer_list.c AVInputFormat demuxer_list $DEMUXER_LIST print_enabled_components libavformat/muxer_list.c AVOutputFormat muxer_list $MUXER_LIST +print_enabled_components libavdevice/indev_list.c AVInputFormat indev_list $INDEV_LIST +print_enabled_components libavdevice/outdev_list.c AVOutputFormat outdev_list $OUTDEV_LIST print_enabled_components libavformat/protocol_list.c URLProtocol url_protocols $PROTOCOL_LIST # Settings for pkg-config files diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c index b767b6a718..ebf95f8a81 100644 --- a/libavdevice/alldevices.c +++ b/libavdevice/alldevices.c @@ -22,57 +22,48 @@ #include "libavutil/thread.h" #include "avdevice.h" -#define REGISTER_OUTDEV(X, x) \ - { \ - extern AVOutputFormat ff_##x##_muxer; \ - if (CONFIG_##X##_OUTDEV) \ - av_register_output_format(&ff_##x##_muxer); \ - } +/* devices */ +extern AVInputFormat ff_alsa_demuxer; +extern AVOutputFormat ff_alsa_muxer; +extern AVInputFormat ff_android_camera_demuxer; +extern AVInputFormat ff_avfoundation_demuxer; +extern AVInputFormat ff_bktr_demuxer; +extern AVOutputFormat ff_caca_muxer; +extern AVInputFormat ff_decklink_demuxer; +extern AVOutputFormat ff_decklink_muxer; +extern AVInputFormat ff_libndi_newtek_demuxer; +extern AVOutputFormat ff_libndi_newtek_muxer; +extern AVInputFormat ff_dshow_demuxer; +extern AVInputFormat ff_fbdev_demuxer; +extern AVOutputFormat ff_fbdev_muxer; +extern AVInputFormat ff_gdigrab_demuxer; +extern AVInputFormat ff_iec61883_demuxer; +extern AVInputFormat ff_jack_demuxer; +extern AVInputFormat ff_kmsgrab_demuxer; +extern AVInputFormat ff_lavfi_demuxer; +extern AVInputFormat ff_openal_demuxer; +extern AVOutputFormat ff_opengl_muxer; +extern AVInputFormat ff_oss_demuxer; +extern AVOutputFormat ff_oss_muxer; +extern AVInputFormat ff_pulse_demuxer; +extern AVOutputFormat ff_pulse_muxer; +extern AVOutputFormat ff_sdl2_muxer; +extern AVInputFormat ff_sndio_demuxer; +extern AVOutputFormat ff_sndio_muxer; +extern AVInputFormat ff_v4l2_demuxer; +extern AVOutputFormat ff_v4l2_muxer; +extern AVInputFormat ff_vfwcap_demuxer; +extern AVInputFormat ff_xcbgrab_demuxer; +extern AVOutputFormat ff_xv_muxer; -#define REGISTER_INDEV(X, x) \ - { \ - extern AVInputFormat ff_##x##_demuxer; \ - if (CONFIG_##X##_INDEV) \ - av_register_input_format(&ff_##x##_demuxer); \ - } +/* external libraries */ +extern AVInputFormat ff_libcdio_demuxer; +extern AVInputFormat ff_libdc1394_demuxer; -#define REGISTER_INOUTDEV(X, x) REGISTER_OUTDEV(X, x); REGISTER_INDEV(X, x) - -static void register_all(void) -{ - /* devices */ - REGISTER_INOUTDEV(ALSA, alsa); - REGISTER_INDEV (AVFOUNDATION, avfoundation); - REGISTER_INDEV (BKTR, bktr); - REGISTER_OUTDEV (CACA, caca); - REGISTER_INOUTDEV(DECKLINK, decklink); - REGISTER_INOUTDEV(LIBNDI_NEWTEK, libndi_newtek); - REGISTER_INDEV (DSHOW, dshow); - REGISTER_INOUTDEV(FBDEV, fbdev); - REGISTER_INDEV (GDIGRAB, gdigrab); - REGISTER_INDEV (IEC61883, iec61883); - REGISTER_INDEV (JACK, jack); - REGISTER_INDEV (KMSGRAB, kmsgrab); - REGISTER_INDEV (LAVFI, lavfi); - REGISTER_INDEV (OPENAL, openal); - REGISTER_OUTDEV (OPENGL, opengl); - REGISTER_INOUTDEV(OSS, oss); - REGISTER_INOUTDEV(PULSE, pulse); - REGISTER_OUTDEV (SDL2, sdl2); - REGISTER_INOUTDEV(SNDIO, sndio); - REGISTER_INOUTDEV(V4L2, v4l2); - REGISTER_INDEV (VFWCAP, vfwcap); - REGISTER_INDEV (XCBGRAB, xcbgrab); - REGISTER_OUTDEV (XV, xv); - - /* external libraries */ - REGISTER_INDEV (LIBCDIO, libcdio); - REGISTER_INDEV (LIBDC1394, libdc1394); -} +#include "libavdevice/outdev_list.c" +#include "libavdevice/indev_list.c" void avdevice_register_all(void) { - static AVOnce control = AV_ONCE_INIT; - - ff_thread_once(&control, register_all); + avpriv_register_devices(outdev_list, indev_list); } diff --git a/libavformat/allformats.c b/libavformat/allformats.c index e748faf4e6..2a20548c95 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -484,24 +484,45 @@ extern AVInputFormat ff_libopenmpt_demuxer; #include "libavformat/muxer_list.c" #include "libavformat/demuxer_list.c" +static const AVInputFormat * const *indev_list = NULL; +static const AVOutputFormat * const *outdev_list = NULL; + const AVOutputFormat *av_muxer_iterate(void **opaque) { + static const uintptr_t size = sizeof(muxer_list)/sizeof(muxer_list[0]) - 1; uintptr_t i = (uintptr_t)*opaque; - const AVOutputFormat *f = muxer_list[i]; + const AVOutputFormat *f = NULL; + + if (i < size - 1) { + f = muxer_list[i]; + } else if (indev_list) { + f = outdev_list[i - size]; + } + if (f) *opaque = (void*)(i + 1); return f; } -const AVInputFormat *av_demuxer_iterate(void **opaque){ +const AVInputFormat *av_demuxer_iterate(void **opaque) +{ + static const uintptr_t size = sizeof(demuxer_list)/sizeof(demuxer_list[0]) - 1; uintptr_t i = (uintptr_t)*opaque; - const AVInputFormat *f = demuxer_list[i]; + const AVInputFormat *f = NULL; + + if (i < size) { + f = demuxer_list[i]; + } else if (outdev_list) { + f = indev_list[i - size]; + } if (f) *opaque = (void*)(i + 1); return f; } +static AVMutex avpriv_register_devices_mutex = AV_MUTEX_INITIALIZER; + #if FF_API_NEXT FF_DISABLE_DEPRECATION_WARNINGS static AVOnce av_format_next_init = AV_ONCE_INIT; @@ -510,38 +531,62 @@ static void av_format_init_next(void) { AVOutputFormat *prevout = NULL, *out; AVInputFormat *previn = NULL, *in; - void *i = 0; - while ((out = (AVOutputFormat*)av_muxer_iterate(&i))) { + ff_mutex_lock(&avpriv_register_devices_mutex); + + for (int i = 0; (out = (AVOutputFormat*)muxer_list[i]); i++) { if (prevout) prevout->next = out; prevout = out; } - i = 0; - while ((in = (AVInputFormat*)av_demuxer_iterate(&i))) { + if (outdev_list) { + for (int i = 0; (out = (AVOutputFormat*)outdev_list[i]); i++) { + if (prevout) + prevout->next = out; + prevout = out; + } + } + + for (int i = 0; (in = (AVInputFormat*)demuxer_list[i]); i++) { if (previn) previn->next = in; previn = in; } + + if (indev_list) { + for (int i = 0; (in = (AVInputFormat*)indev_list[i]); i++) { + if (previn) + previn->next = in; + previn = in; + } + } + + ff_mutex_unlock(&avpriv_register_devices_mutex); } AVInputFormat *av_iformat_next(const AVInputFormat *f) { ff_thread_once(&av_format_next_init, av_format_init_next); + if (f) return f->next; - else - return demuxer_list[0]; + else { + void *opaque = NULL; + return (AVInputFormat *)av_demuxer_iterate(&opaque); + } } AVOutputFormat *av_oformat_next(const AVOutputFormat *f) { ff_thread_once(&av_format_next_init, av_format_init_next); + if (f) return f->next; - else - return muxer_list[0]; + else { + void *opaque = NULL; + return (AVOutputFormat *)av_muxer_iterate(&opaque); + } } void av_register_all(void) @@ -560,3 +605,14 @@ void av_register_output_format(AVOutputFormat *format) } FF_ENABLE_DEPRECATION_WARNINGS #endif + +void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputFormat * const i[]) +{ + ff_mutex_lock(&avpriv_register_devices_mutex); + outdev_list = o; + indev_list = i; + ff_mutex_unlock(&avpriv_register_devices_mutex); +#if FF_API_NEXT + av_format_init_next(); +#endif +} diff --git a/libavformat/avformat.h b/libavformat/avformat.h index a2fe7c6bb2..ec4e5f45f5 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -3060,6 +3060,8 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, */ AVRational av_stream_get_codec_timebase(const AVStream *st); + +void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputFormat * const i[]); /** * @} */