From 853843d86f550ca73807263a71b613530fb60f45 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 6 Feb 2026 13:39:39 +0100 Subject: [PATCH] avcodec/opus/parse: Move frame_duration tab into a file of its own This is in preparation for duplicating it into libavformat. Signed-off-by: Andreas Rheinhardt --- libavcodec/opus/Makefile | 2 ++ libavcodec/opus/frame_duration_tab.c | 31 ++++++++++++++++++++++++++++ libavcodec/opus/parse.c | 15 ++------------ libavcodec/opus/tab.h | 2 ++ 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 libavcodec/opus/frame_duration_tab.c diff --git a/libavcodec/opus/Makefile b/libavcodec/opus/Makefile index 5a1aef0fd9..c23e684153 100644 --- a/libavcodec/opus/Makefile +++ b/libavcodec/opus/Makefile @@ -8,6 +8,7 @@ OBJS-$(CONFIG_OPUS_DECODER) += \ opus/dec.o \ opus/dec_celt.o \ opus/celt.o \ + opus/frame_duration_tab.o \ opus/pvq.o \ opus/silk.o \ opus/tab.o \ @@ -16,6 +17,7 @@ OBJS-$(CONFIG_OPUS_DECODER) += \ OBJS-$(CONFIG_OPUS_PARSER) += \ + opus/frame_duration_tab.o \ opus/parser.o \ diff --git a/libavcodec/opus/frame_duration_tab.c b/libavcodec/opus/frame_duration_tab.c new file mode 100644 index 0000000000..3e408d9788 --- /dev/null +++ b/libavcodec/opus/frame_duration_tab.c @@ -0,0 +1,31 @@ +/* + * 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 "tab.h" + +const uint16_t ff_opus_frame_duration[32] = { + 480, 960, 1920, 2880, + 480, 960, 1920, 2880, + 480, 960, 1920, 2880, + 480, 960, + 480, 960, + 120, 240, 480, 960, + 120, 240, 480, 960, + 120, 240, 480, 960, + 120, 240, 480, 960, +}; diff --git a/libavcodec/opus/parse.c b/libavcodec/opus/parse.c index 1949449b77..a927996e40 100644 --- a/libavcodec/opus/parse.c +++ b/libavcodec/opus/parse.c @@ -36,21 +36,10 @@ #include "mathops.h" #include "opus.h" #include "parse.h" +#include "tab.h" #include "vorbis_data.h" #if CONFIG_OPUSPARSE -static const uint16_t opus_frame_duration[32] = { - 480, 960, 1920, 2880, - 480, 960, 1920, 2880, - 480, 960, 1920, 2880, - 480, 960, - 480, 960, - 120, 240, 480, 960, - 120, 240, 480, 960, - 120, 240, 480, 960, - 120, 240, 480, 960, -}; - /** * Read a 1- or 2-byte frame length */ @@ -258,7 +247,7 @@ int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, pkt->data_size = pkt->packet_size - padding; /* total packet duration cannot be larger than 120ms */ - pkt->frame_duration = opus_frame_duration[pkt->config]; + pkt->frame_duration = ff_opus_frame_duration[pkt->config]; if (pkt->frame_duration * pkt->frame_count > OPUS_MAX_PACKET_DUR) goto fail; diff --git a/libavcodec/opus/tab.h b/libavcodec/opus/tab.h index ac140d5868..3903624278 100644 --- a/libavcodec/opus/tab.h +++ b/libavcodec/opus/tab.h @@ -28,6 +28,8 @@ #include "libavutil/attributes_internal.h" FF_VISIBILITY_PUSH_HIDDEN +extern const uint16_t ff_opus_frame_duration[32]; + extern const uint8_t ff_celt_band_end[]; extern const uint8_t ff_opus_default_coupled_streams[];