From patchwork Mon Sep 7 00:41:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 22135 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 212CA44BB74 for ; Mon, 7 Sep 2020 03:41:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EEC3D680812; Mon, 7 Sep 2020 03:41:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 50009680154 for ; Mon, 7 Sep 2020 03:41:23 +0300 (EEST) Received: from w3.tutanota.de (unknown [192.168.1.164]) by w4.tutanota.de (Postfix) with ESMTP id DF92110602DB for ; Mon, 7 Sep 2020 00:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1599439279; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=L4jMWZCaEbpQtGu0ud1yqfkpfyYnHnduAOYJ86oZUfQ=; b=LeD5EuF5MZiPaNix1YicaDWilOR3XIpEOkap8JAtPPoCWqJupN4iNcckkBcXnrmv UsM7Z36JvrbHp6xGCqnyfbxvlWlKpTXp3n4TMvYEzZu0CE+XWVmo6/tB6UC6DpglpPo sVNJrOcWH2YYGt0xSFmCMBjErz++uIpWbXUnfUaJLLi9UCTSNlLcIzbeeaBfPiDnwkn JogaSUJxIdt19SghTiLO9MEliTfudAKG799YzdLF30uRQa1z01DfO+vVQien2pk+7Rm mTBr0okoxPIigwUdYlRPRoaFRLL9R9VL1UesSv+0Rf+fFoIXwylBgoqM1OpDJy+nynV A3vm76fGEQ== Date: Mon, 7 Sep 2020 02:41:19 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libwavpackenc: remove libwavpackenc wrapper 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The manual states "there is virtually no reason to use that encoder.". It supports less sample formats than the native encoder, is less efficient than the native encoder and is also slower and pretty much remains untested. libwavpack also isn't being fuzzed, which given that we plug the parameters without any sanitizing them looks concerning. Patch attached. Subject: [PATCH] libwavpackenc: remove libwavpackenc wrapper The manual states "there is virtually no reason to use that encoder.". It supports less sample formats than the native encoder, is less efficient than the native encoder and is also slower and pretty much remains untested. libwavpack also isn't being fuzzed, which given that we plug the parameters without any sanitizing them looks concerning. --- configure | 11 +-- doc/encoders.texi | 53 +--------- doc/general.texi | 8 -- libavcodec/Makefile | 1 - libavcodec/allcodecs.c | 1 - libavcodec/libwavpackenc.c | 195 ------------------------------------- 6 files changed, 4 insertions(+), 265 deletions(-) delete mode 100644 libavcodec/libwavpackenc.c diff --git a/configure b/configure index 9ff246b07f..6b5b3d512c 100755 --- a/configure +++ b/configure @@ -190,9 +190,9 @@ External library support: Using any of the following switches will allow FFmpeg to link to the corresponding external library. All the components depending on that library will become enabled, if all their other dependencies are met and they are not - explicitly disabled. E.g. --enable-libwavpack will enable linking to - libwavpack and allow the libwavpack encoder to be built, unless it is - specifically disabled with --disable-encoder=libwavpack. + explicitly disabled. E.g. --enable-libopus will enable linking to + libopus and allow the libopus encoder to be built, unless it is + specifically disabled with --disable-encoder=libopus. Note that only the system libraries are auto-detected. All the other external libraries must be explicitly enabled. @@ -284,7 +284,6 @@ External library support: --enable-libvorbis enable Vorbis en/decoding via libvorbis, native implementation exists [no] --enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no] - --enable-libwavpack enable wavpack encoding via libwavpack [no] --enable-libwebp enable WebP encoding via libwebp [no] --enable-libx264 enable H.264 encoding via x264 [no] --enable-libx265 enable HEVC encoding via x265 [no] @@ -1815,7 +1814,6 @@ EXTERNAL_LIBRARY_LIST=" libvmaf libvorbis libvpx - libwavpack libwebp libxml2 libzimg @@ -3262,8 +3260,6 @@ libvpx_vp8_decoder_deps="libvpx" libvpx_vp8_encoder_deps="libvpx" libvpx_vp9_decoder_deps="libvpx" libvpx_vp9_encoder_deps="libvpx" -libwavpack_encoder_deps="libwavpack" -libwavpack_encoder_select="audio_frame_queue" libwebp_encoder_deps="libwebp" libwebp_anim_encoder_deps="libwebp" libx262_encoder_deps="libx262" @@ -6446,7 +6442,6 @@ enabled libvpx && { fi } -enabled libwavpack && require libwavpack wavpack/wavpack.h WavpackOpenFileOutput -lwavpack enabled libwebp && { enabled libwebp_encoder && require_pkg_config libwebp "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; } diff --git a/doc/encoders.texi b/doc/encoders.texi index 69bf742c2d..6517da88a2 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1180,53 +1180,6 @@ transient response is a higher bitrate. @end table -@anchor{libwavpack} -@section libwavpack - -A wrapper providing WavPack encoding through libwavpack. - -Only lossless mode using 32-bit integer samples is supported currently. - -Requires the presence of the libwavpack headers and library during -configuration. You need to explicitly configure the build with -@code{--enable-libwavpack}. - -Note that a libavcodec-native encoder for the WavPack codec exists so users can -encode audios with this codec without using this encoder. See @ref{wavpackenc}. - -@subsection Options - -@command{wavpack} command line utility's corresponding options are listed in -parentheses, if any. - -@table @option -@item frame_size (@emph{--blocksize}) -Default is 32768. - -@item compression_level -Set speed vs. compression tradeoff. Acceptable arguments are listed below: - -@table @samp -@item 0 (@emph{-f}) -Fast mode. - -@item 1 -Normal (default) settings. - -@item 2 (@emph{-h}) -High quality. - -@item 3 (@emph{-hh}) -Very high quality. - -@item 4-8 (@emph{-hh -x}@var{EXTRAPROC}) -Same as @samp{3}, but with extra processing enabled. - -@samp{4} is the same as @option{-x2} and @samp{8} is the same as @option{-x6}. - -@end table -@end table - @anchor{mjpegenc} @section mjpeg @@ -1253,10 +1206,7 @@ Compute and use optimal huffman tables. WavPack lossless audio encoder. -This is a libavcodec-native WavPack encoder. There is also an encoder based on -libwavpack, but there is virtually no reason to use that encoder. - -See also @ref{libwavpack}. +This is a libavcodec-native WavPack encoder. @subsection Options @@ -1278,7 +1228,6 @@ For the complete formula of calculating default, see @file{libavcodec/wavpackenc.c}. @item compression_level (@emph{-f}, @emph{-h}, @emph{-hh}, and @emph{-x}) -This option's syntax is consistent with @ref{libwavpack}'s. @end table @subsubsection Private options diff --git a/doc/general.texi b/doc/general.texi index d618565347..5e32413976 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -290,14 +290,6 @@ Due to security concerns, Vapoursynth scripts will not be autodetected so the input format has to be forced. For ff* CLI tools, add @code{-f vapoursynth} before the input @code{-i yourscript.vpy}. -@section WavPack - -FFmpeg can make use of the libwavpack library for WavPack encoding. - -Go to @url{http://www.wavpack.com/} and follow the instructions for -installing the library. Then pass @code{--enable-libwavpack} to configure to -enable it. - @section x264 FFmpeg can make use of the x264 library for H.264 encoding. diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 98f31e246b..e72aa2428e 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1045,7 +1045,6 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o -OBJS-$(CONFIG_LIBWAVPACK_ENCODER) += libwavpackenc.o OBJS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.o libwebpenc.o OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER) += libwebpenc_common.o libwebpenc_animencoder.o OBJS-$(CONFIG_LIBX262_ENCODER) += libx264.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index f3572a47e3..5201ef12c6 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -744,7 +744,6 @@ extern AVCodec ff_libvpx_vp8_encoder; extern AVCodec ff_libvpx_vp8_decoder; extern AVCodec ff_libvpx_vp9_encoder; extern AVCodec ff_libvpx_vp9_decoder; -extern AVCodec ff_libwavpack_encoder; /* preferred over libwebp */ extern AVCodec ff_libwebp_anim_encoder; extern AVCodec ff_libwebp_encoder; diff --git a/libavcodec/libwavpackenc.c b/libavcodec/libwavpackenc.c deleted file mode 100644 index e84b074893..0000000000 --- a/libavcodec/libwavpackenc.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 -#include - -#include "libavutil/attributes.h" -#include "libavutil/opt.h" -#include "libavutil/samplefmt.h" - -#include "audio_frame_queue.h" -#include "avcodec.h" -#include "internal.h" - -#define WV_DEFAULT_BLOCK_SIZE 32768 - -typedef struct LibWavpackContext { - const AVClass *class; - WavpackContext *wv; - AudioFrameQueue afq; - - AVPacket *pkt; - int user_size; - - int got_output; -} LibWavpackContext; - -static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *pkt, - const AVFrame *frame, int *got_output) -{ - LibWavpackContext *s = avctx->priv_data; - int ret; - - s->got_output = 0; - s->pkt = pkt; - s->user_size = pkt->size; - - if (frame) { - ret = ff_af_queue_add(&s->afq, frame); - if (ret < 0) - return ret; - - ret = WavpackPackSamples(s->wv, (int32_t*)frame->data[0], frame->nb_samples); - if (!ret) { - av_log(avctx, AV_LOG_ERROR, "Error encoding a frame: %s\n", - WavpackGetErrorMessage(s->wv)); - return AVERROR_UNKNOWN; - } - } - - if (!s->got_output && - (!frame || frame->nb_samples < avctx->frame_size)) { - ret = WavpackFlushSamples(s->wv); - if (!ret) { - av_log(avctx, AV_LOG_ERROR, "Error flushing the encoder: %s\n", - WavpackGetErrorMessage(s->wv)); - return AVERROR_UNKNOWN; - } - } - - if (s->got_output) { - ff_af_queue_remove(&s->afq, avctx->frame_size, &pkt->pts, &pkt->duration); - *got_output = 1; - } - - return 0; -} - -static int encode_callback(void *id, void *data, int32_t count) -{ - AVCodecContext *avctx = id; - LibWavpackContext *s = avctx->priv_data; - int ret, offset = s->pkt->size; - - if (s->user_size) { - if (s->user_size - count < s->pkt->size) { - av_log(avctx, AV_LOG_ERROR, "Provided packet too small.\n"); - return 0; - } - s->pkt->size += count; - } else { - ret = av_grow_packet(s->pkt, count); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Error allocating output packet.\n"); - return 0; - } - } - - memcpy(s->pkt->data + offset, data, count); - - s->got_output = 1; - - return 1; -} - -static av_cold int wavpack_encode_init(AVCodecContext *avctx) -{ - LibWavpackContext *s = avctx->priv_data; - WavpackConfig config = { 0 }; - int ret; - - s->wv = WavpackOpenFileOutput(encode_callback, avctx, NULL); - if (!s->wv) { - av_log(avctx, AV_LOG_ERROR, "Error allocating the encoder.\n"); - return AVERROR(ENOMEM); - } - - if (!avctx->frame_size) - avctx->frame_size = WV_DEFAULT_BLOCK_SIZE; - - config.bytes_per_sample = 4; - config.bits_per_sample = 32; - config.block_samples = avctx->frame_size; - config.channel_mask = avctx->channel_layout; - config.num_channels = avctx->channels; - config.sample_rate = avctx->sample_rate; - - if (avctx->compression_level != FF_COMPRESSION_DEFAULT) { - if (avctx->compression_level >= 3) { - config.flags |= CONFIG_VERY_HIGH_FLAG; - - if (avctx->compression_level >= 8) - config.xmode = 6; - else if (avctx->compression_level >= 7) - config.xmode = 5; - else if (avctx->compression_level >= 6) - config.xmode = 4; - else if (avctx->compression_level >= 5) - config.xmode = 3; - else if (avctx->compression_level >= 4) - config.xmode = 2; - } else if (avctx->compression_level >= 2) - config.flags |= CONFIG_HIGH_FLAG; - else if (avctx->compression_level < 1) - config.flags |= CONFIG_FAST_FLAG; - } - - ret = WavpackSetConfiguration(s->wv, &config, -1); - if (!ret) - goto fail; - - ret = WavpackPackInit(s->wv); - if (!ret) - goto fail; - - ff_af_queue_init(avctx, &s->afq); - - return 0; - -fail: - av_log(avctx, AV_LOG_ERROR, "Error configuring the encoder: %s.\n", - WavpackGetErrorMessage(s->wv)); - WavpackCloseFile(s->wv); - return AVERROR_UNKNOWN; -} - -static av_cold int wavpack_encode_close(AVCodecContext *avctx) -{ - LibWavpackContext *s = avctx->priv_data; - - WavpackCloseFile(s->wv); - - ff_af_queue_close(&s->afq); - - return 0; -} - -AVCodec ff_libwavpack_encoder = { - .name = "libwavpack", - .type = AVMEDIA_TYPE_AUDIO, - .id = AV_CODEC_ID_WAVPACK, - .priv_data_size = sizeof(LibWavpackContext), - .init = wavpack_encode_init, - .encode2 = wavpack_encode_frame, - .close = wavpack_encode_close, - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SMALL_LAST_FRAME, - .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32, - AV_SAMPLE_FMT_NONE }, - .wrapper_name = "libwavpack", -};