From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8CA9D42C31 for ; Mon, 1 Aug 2022 09:12:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4239168BAA9; Mon, 1 Aug 2022 12:12:37 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A795968BA43 for ; Mon, 1 Aug 2022 12:12:30 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9AA99240179; Mon, 1 Aug 2022 11:12:29 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id pVaoMHpf8A6O; Mon, 1 Aug 2022 11:12:28 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id D4E932400F5; Mon, 1 Aug 2022 11:12:28 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id 7607F1601B2; Mon, 1 Aug 2022 11:12:27 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <20220725043051.9692-2-haihao.xiang@intel.com> References: <20220725043051.9692-1-haihao.xiang@intel.com> <20220725043051.9692-2-haihao.xiang@intel.com> Mail-Followup-To: FFmpeg development discussions and patches , Haihao Xiang Date: Mon, 01 Aug 2022 11:12:27 +0200 Message-ID: <165934514745.15471.3243258857472976626@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] ffmpeg_opt: consider HW acceleration method when selecting decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Haihao Xiang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Hi, the concept is generally ok, but I have a few comments on the implementation. Quoting Xiang, Haihao (2022-07-25 06:30:51) > +static const AVCodec *choose_decoder2(InputStream *ist, OptionsContext *o, AVFormatContext *s, AVStream *st) > +{ > + char *codec_name = NULL; > + > + MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st); > + if (codec_name) { > + const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); > + st->codecpar->codec_id = codec->id; > + if (recast_media && st->codecpar->codec_type != codec->type) > + st->codecpar->codec_type = codec->type; > + return codec; > + } else { > + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && > + ist->hwaccel_id == HWACCEL_GENERIC && > + ist->hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) { > + const AVCodec *p; 'p' is a rather weird name for an AVCodec instance, I'd expect 'c' or 'codec' or something like that > + void *i = 0; NULL, it's a pointer > + > + while ((p = av_codec_iterate(&i))) { > + int j; > + > + if (p->id != st->codecpar->codec_id || > + !av_codec_is_decoder(p) || > + !avcodec_get_hw_config(p, 0)) > + continue; > + > + for (j = 0; ;j++) { for (int j = 0; config = avcodec_get_hw_config(p, j); j++) gets rid of the explicit check in the loop and also avcodec_get_hw_config() in the condition above > + const AVCodecHWConfig *config = avcodec_get_hw_config(p, j); > + > + if (!config) > + break; > + > + if (config->device_type == ist->hwaccel_device_type) > + return p; > + } > + } > + } > + > + return avcodec_find_decoder(st->codecpar->codec_id); > + } > +} > + > /* Add all the streams from the given input file to the global > * list of input streams. */ > static void add_input_streams(OptionsContext *o, AVFormatContext *ic) > @@ -973,7 +1015,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) > ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE; > } > > - ist->dec = choose_decoder(o, ic, st); > + ist->dec = choose_decoder2(ist, o, ic, st); I don't like adding a new function that partially duplicates choose_decoder() and has a non-descriptive name. Just extend choose_decoder() by passing hwaccel_id and hwaccel_device_type to it. -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".