From patchwork Tue Oct 27 14:18:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23247 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 4461844BDB0 for ; Tue, 27 Oct 2020 16:19:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 28B4868ACD0; Tue, 27 Oct 2020 16:19:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD0CF68AB96 for ; Tue, 27 Oct 2020 16:19:42 +0200 (EET) Received: by mail-qt1-f172.google.com with SMTP id m9so1057001qth.7 for ; Tue, 27 Oct 2020 07:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+jUusQv32sRKHJ7tU+IZOTuiNg+P7uRq2XmsFPBjOOU=; b=tkbVrHidIMCNqdCYmMnv77wWqKhItCGk+2M5QGGFdDPBV+Q35nb2p+AzvqjP7zPbJ+ yi21LWST8KcO/xGjbMJktxkfzeWM2JIJOh5IP4N8F/+TvBN0cTmr/4dG3bcawG4vSCEe cFMC9bSiKjrtmPFK5Tm/i8EYc9yBQSc4VH95eB0VigaP+MUAX7ZPAT9OP2rToddhRmZw 6CJBr3OLwHPyh4b+KxjFjtlw8Mp5PylTPLCITfQ5mcW661jS5wy05OJATV7eKu8yATvX Geiq0v6/9vFmMff21jQ1XRbDRBm2LZEb08t2lRnDy/KP5kGJmW7FHRNrsjs2dsMzXE6U 5qfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+jUusQv32sRKHJ7tU+IZOTuiNg+P7uRq2XmsFPBjOOU=; b=s1kJQhMDcUXzqJFuqOedzNDX1Jw0Ctqqmp1PStUwQtnWAlBZwdAsXEqWPak/5qj9Up RNV3IMUO3Aku4BF6EDph7NJ+vjJF34LpokYUzskxyAKUCYKwTnqbHcnVkCoYp1iAjOgs U1oRPA7HaxNXpxeln1vfYshoPdK/iQQaAclDYqnGNvlYKn3t25zzYpvA+urtVC6orGd4 Lmze2Dii9f2E4tUPNbbBq2wjdy6ZuvW/wMGu8Rhw4yN0S2kxHC3Z4jbop6heloZ34Z3q VBXuZ+4+ibXY59OO0ijSeEjvD/5d34wEc/b/iUofP8/OsTDSTvKLFZQK1mZBYZx6Q/31 Kv6Q== X-Gm-Message-State: AOAM532fprDS85p8QgP1B4YxVEpWu0ZdYmfvATniLmDoNkX1BFfZtQ4a tW2Z7scD0W1iFNGuC7oZI6FOTbEm8RU= X-Google-Smtp-Source: ABdhPJwUXr0GgwpoBUmLB/7vZPIXtd6H4vdTDAKLqCgpzC3tyKxjxfMUYilMwQJ9D0urBFly85Pc1w== X-Received: by 2002:ac8:71d5:: with SMTP id i21mr2354285qtp.365.1603808381248; Tue, 27 Oct 2020 07:19:41 -0700 (PDT) Received: from localhost.localdomain ([181.23.86.134]) by smtp.gmail.com with ESMTPSA id u16sm890865qth.42.2020.10.27.07.19.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 07:19:40 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Oct 2020 11:18:59 -0300 Message-Id: <20201027141859.1346-3-jamrial@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027141859.1346-1-jamrial@gmail.com> References: <20201027141859.1346-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/codec2utils: move the remaining avpriv functions to lavf 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" They are only used by the codec2 demuxers. The symbols are kept around until the next major bump. Signed-off-by: James Almer --- libavcodec/codec2utils.c | 2 ++ libavcodec/codec2utils.h | 4 +++ libavformat/codec2.c | 66 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/libavcodec/codec2utils.c b/libavcodec/codec2utils.c index f1b6e56526..a942662403 100644 --- a/libavcodec/codec2utils.c +++ b/libavcodec/codec2utils.c @@ -23,6 +23,7 @@ #include "internal.h" #include "libavcodec/codec2utils.h" +#if LIBAVCODEC_VERSION_MAJOR < 59 int avpriv_codec2_mode_bit_rate(void *logctx, int mode) { int frame_size = avpriv_codec2_mode_frame_size(logctx, mode); @@ -78,3 +79,4 @@ int avpriv_codec2_mode_block_align(void *logctx, int mode) return block_align_table[mode]; } } +#endif diff --git a/libavcodec/codec2utils.h b/libavcodec/codec2utils.h index 2ee7a592a1..37f0693dc7 100644 --- a/libavcodec/codec2utils.h +++ b/libavcodec/codec2utils.h @@ -24,6 +24,8 @@ #include +#include "version.h" + //Highest mode we're willing to use. //Don't want to let users accidentally produce files that can't be decoded in the future. //CODEC2_MODE_WB (9) is experimental/unstable as of 2017-11-23. @@ -45,6 +47,7 @@ { "700B", "700B", 0, AV_OPT_TYPE_CONST, {.i64 = 7}, .flags=option_flags, .unit="codec2_mode"},\ { "700C", "700C", 0, AV_OPT_TYPE_CONST, {.i64 = 8}, .flags=option_flags, .unit="codec2_mode"} +#if LIBAVCODEC_VERSION_MAJOR < 59 //The three following functions are here to avoid needing libavformat/codec2.c to depend on libcodec2 //Computes bitrate from mode, with frames rounded up to the nearest octet. @@ -58,6 +61,7 @@ int avpriv_codec2_mode_frame_size(void *logctx, int mode); //Mimics (codec2_bits_per_frame()+7)/8 int avpriv_codec2_mode_block_align(void *logctx, int mode); +#endif #define CODEC2_EXTRADATA_SIZE 4 diff --git a/libavformat/codec2.c b/libavformat/codec2.c index edd450716f..a64160283c 100644 --- a/libavformat/codec2.c +++ b/libavformat/codec2.c @@ -61,6 +61,66 @@ static int codec2_probe(const AVProbeData *p) return AVPROBE_SCORE_EXTENSION + 1; } +//Mimics codec2_samples_per_frame() +static int codec2_mode_frame_size(AVFormatContext *s, int mode) +{ + int frame_size_table[CODEC2_MODE_MAX+1] = { + 160, // 3200 + 160, // 2400 + 320, // 1600 + 320, // 1400 + 320, // 1300 + 320, // 1200 + 320, // 700 + 320, // 700B + 320, // 700C + }; + + if (mode < 0 || mode > CODEC2_MODE_MAX) { + av_log(s, AV_LOG_ERROR, "unknown codec2 mode %i, can't find frame_size\n", mode); + return 0; + } else { + return frame_size_table[mode]; + } +} + +//Mimics (codec2_bits_per_frame()+7)/8 +static int codec2_mode_block_align(AVFormatContext *s, int mode) +{ + int block_align_table[CODEC2_MODE_MAX+1] = { + 8, // 3200 + 6, // 2400 + 8, // 1600 + 7, // 1400 + 7, // 1300 + 6, // 1200 + 4, // 700 + 4, // 700B + 4, // 700C + }; + + if (mode < 0 || mode > CODEC2_MODE_MAX) { + av_log(s, AV_LOG_ERROR, "unknown codec2 mode %i, can't find block_align\n", mode); + return 0; + } else { + return block_align_table[mode]; + } +} + +//Computes bitrate from mode, with frames rounded up to the nearest octet. +//So 700 bit/s (28 bits/frame) becomes 800 bits/s (32 bits/frame). +static int codec2_mode_bit_rate(AVFormatContext *s, int mode) +{ + int frame_size = codec2_mode_frame_size(s, mode); + int block_align = codec2_mode_block_align(s, mode); + + if (frame_size <= 0 || block_align <= 0) { + return 0; + } + + return 8 * 8000 * block_align / frame_size; +} + static int codec2_read_header_common(AVFormatContext *s, AVStream *st) { int mode = codec2_mode_from_extradata(st->codecpar->extradata); @@ -71,9 +131,9 @@ static int codec2_read_header_common(AVFormatContext *s, AVStream *st) st->codecpar->channels = 1; st->codecpar->format = AV_SAMPLE_FMT_S16; st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; - st->codecpar->bit_rate = avpriv_codec2_mode_bit_rate(s, mode); - st->codecpar->frame_size = avpriv_codec2_mode_frame_size(s, mode); - st->codecpar->block_align = avpriv_codec2_mode_block_align(s, mode); + st->codecpar->bit_rate = codec2_mode_bit_rate(s, mode); + st->codecpar->frame_size = codec2_mode_frame_size(s, mode); + st->codecpar->block_align = codec2_mode_block_align(s, mode); if (st->codecpar->bit_rate <= 0 || st->codecpar->frame_size <= 0 ||