From patchwork Mon Dec 30 13:54:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 17065 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 F1D86449AE8 for ; Mon, 30 Dec 2019 15:54:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D758268AC26; Mon, 30 Dec 2019 15:54:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbg.qq.com (smtpbg508.qq.com [203.205.250.107]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3DD6768A702 for ; Mon, 30 Dec 2019 15:54:40 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1577714075; bh=i5eBy1DF+j426kaS57e64nrO/ciPpzZHLA48UTcXyag=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=IZPey5K4jt66j3g5146WsS9EnHwzGmVCuTso7P/UEgXiOCq20V2+V+YGATeTHuIhN 8ddNQq0yHngZtX0n6uFeAZvO5URCG54URhnew6i0pkDckCGnN3DSTNFwcLFF+Re9cQ u2fmWMODenbpsJyr4JDJFYrjHnyyzb3I7g5Y4WW8= X-QQ-mid: esmtp3t1577714073t5m31s2yk Received: from ZHILIZHAO-MB1.tencent.com (unknown [14.17.22.54]) by esmtp4.qq.com (ESMTP) with id ; Mon, 30 Dec 2019 21:54:32 +0800 (CST) X-QQ-SSF: 01000000000000N0WH4000000000002 X-QQ-FEAT: 83XBpSITAVYT1bmtyGyi4gvXqP++vLfH7ZL77yYF4tF+sTe88JMpF44lgFO+i oWnDODnryQbICz5OjkrhkRpp4YYNtIScQEyQrmip2S+HgeGb5c7UGtVmY58JcaJXHBxdnWE vAVI0fL5XQTgg/6W84T5QthHNOXH9D++a/wtSB3kw3meyhCYR7GrTQ513VkHj1yy+QvBIf9 YVHOOYdKzaPi+zTNLFo+OvSOFHD8o9nf44MwDuls6S4OpBGNaGYlMBwG9PKPGMUMB608i7K r7E8OnhGVKyj6SFt5SQwL0WOL+XwSkogtyDA== X-QQ-GoodBg: 0 From: quinkblack@foxmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Dec 2019 21:54:19 +0800 Message-Id: <20191230135419.56529-8-quinkblack@foxmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20191230135419.56529-1-quinkblack@foxmail.com> References: <20191230135419.56529-1-quinkblack@foxmail.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: esmtp:foxmail.com:bgweb:bgweb2 Subject: [FFmpeg-devel] [PATCH 8/8] avresample: remove access of AV_SAMPLE_FMT_NB 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: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Zhao Zhili --- libavresample/options.c | 6 +++--- libavresample/utils.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libavresample/options.c b/libavresample/options.c index 5f08cd7e52..cdab98c357 100644 --- a/libavresample/options.c +++ b/libavresample/options.c @@ -37,12 +37,12 @@ static const AVOption avresample_options[] = { { "in_channel_layout", "Input Channel Layout", OFFSET(in_channel_layout), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, PARAM }, - { "in_sample_fmt", "Input Sample Format", OFFSET(in_sample_fmt), AV_OPT_TYPE_INT, { .i64 = AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_NB-1, PARAM }, + { "in_sample_fmt", "Input Sample Format", OFFSET(in_sample_fmt), AV_OPT_TYPE_INT, { .i64 = AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, INT_MAX, PARAM }, { "in_sample_rate", "Input Sample Rate", OFFSET(in_sample_rate), AV_OPT_TYPE_INT, { .i64 = 48000 }, 1, INT_MAX, PARAM }, { "out_channel_layout", "Output Channel Layout", OFFSET(out_channel_layout), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, PARAM }, - { "out_sample_fmt", "Output Sample Format", OFFSET(out_sample_fmt), AV_OPT_TYPE_INT, { .i64 = AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_NB-1, PARAM }, + { "out_sample_fmt", "Output Sample Format", OFFSET(out_sample_fmt), AV_OPT_TYPE_INT, { .i64 = AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, INT_MAX, PARAM }, { "out_sample_rate", "Output Sample Rate", OFFSET(out_sample_rate), AV_OPT_TYPE_INT, { .i64 = 48000 }, 1, INT_MAX, PARAM }, - { "internal_sample_fmt", "Internal Sample Format", OFFSET(internal_sample_fmt), AV_OPT_TYPE_INT, { .i64 = AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, PARAM, "internal_sample_fmt" }, + { "internal_sample_fmt", "Internal Sample Format", OFFSET(internal_sample_fmt), AV_OPT_TYPE_INT, { .i64 = AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE, INT_MAX, PARAM, "internal_sample_fmt" }, {"u8" , "8-bit unsigned integer", 0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_U8 }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"}, {"s16", "16-bit signed integer", 0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_S16 }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"}, {"s32", "32-bit signed integer", 0, AV_OPT_TYPE_CONST, {.i64 = AV_SAMPLE_FMT_S32 }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"}, diff --git a/libavresample/utils.c b/libavresample/utils.c index b4fb906556..0fbb28641d 100644 --- a/libavresample/utils.c +++ b/libavresample/utils.c @@ -42,6 +42,19 @@ int avresample_open(AVAudioResampleContext *avr) return AVERROR(EINVAL); } +#define check_format(fmt, option_name) \ + if (!av_get_sample_fmt_name(fmt)) { \ + av_log(avr, AV_LOG_ERROR, "%s sample format %d not supported\n", \ + option_name, fmt); \ + return AVERROR(EINVAL); \ + } + + check_format(avr->in_sample_fmt, "Input") + check_format(avr->out_sample_fmt, "Out") + check_format(avr->internal_sample_fmt, "Internal") + +#undef check_format + /* set channel mixing parameters */ avr->in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout); if (avr->in_channels <= 0 || avr->in_channels > AVRESAMPLE_MAX_CHANNELS) {