Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma
@ 2022-10-03 22:32 Andreas Rheinhardt
  2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window Andreas Rheinhardt
                   ` (9 more replies)
  0 siblings, 10 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:32 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

GCC 4.0 not only added a visibility attribute, but also
a pragma to set it for a whole region of code.*
This commit exposes this via macros.

*: See https://gcc.gnu.org/gcc-4.0/changes.html

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/attributes_internal.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavutil/attributes_internal.h b/libavutil/attributes_internal.h
index 9d3d10b63e..c81e9b8204 100644
--- a/libavutil/attributes_internal.h
+++ b/libavutil/attributes_internal.h
@@ -23,8 +23,12 @@
 
 #if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) || defined(__MACH__))
 #    define attribute_visibility_hidden __attribute__((visibility("hidden")))
+#    define FF_VISIBILITY_PUSH_HIDDEN   _Pragma("GCC visibility push(hidden)")
+#    define FF_VISIBILITY_POP_HIDDEN    _Pragma("GCC visibility pop")
 #else
 #    define attribute_visibility_hidden
+#    define FF_VISIBILITY_START_HIDDEN
+#    define FF_VISIBILITY_END_HIDDEN
 #endif
 
 #endif /* AVUTIL_ATTRIBUTES_INTERNAL_H */
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
@ 2022-10-03 22:44 ` Andreas Rheinhardt
  2022-10-04 12:14   ` Michael Niedermayer
  2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 3/9] avcodec/opus: Move OpusStreamContext to its only user Andreas Rheinhardt
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:44 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Currently, it is accessed via a pointer (ff_celt_window)
exported from opustab.h which points inside a static array
(ff_celt_window_padded) in opustab.h. Instead export
ff_celt_window_padded directly and make opustab.h
a static const pointer pointing inside ff_celt_window_padded.
Also mark all the declarations in opustab.h as hidden,
so that the compiler knows that ff_celt_window has a fixed
offset from the code even when compiling position-independent
code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opusenc.c | 4 ++--
 libavcodec/opustab.c | 4 +---
 libavcodec/opustab.h | 8 +++++++-
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
index 58e3f5fa38..06f71876eb 100644
--- a/libavcodec/opusenc.c
+++ b/libavcodec/opusenc.c
@@ -203,7 +203,7 @@ static void celt_frame_mdct(OpusEncContext *s, CeltFrame *f)
                 float *src2 = &b->samples[CELT_OVERLAP*t];
                 s->dsp->vector_fmul(win, src1, ff_celt_window, 128);
                 s->dsp->vector_fmul_reverse(&win[CELT_OVERLAP], src2,
-                                            ff_celt_window - 8, 128);
+                                            ff_celt_window_padded, 128);
                 src1 = src2;
                 s->tx_fn[0](s->tx[0], b->coeffs + t, win, sizeof(float)*f->blocks);
             }
@@ -224,7 +224,7 @@ static void celt_frame_mdct(OpusEncContext *s, CeltFrame *f)
 
             /* Samples, windowed */
             s->dsp->vector_fmul_reverse(temp, b->samples + rwin,
-                                        ff_celt_window - 8, 128);
+                                        ff_celt_window_padded, 128);
             memcpy(win + lap_dst + blk_len, temp, CELT_OVERLAP*sizeof(float));
 
             s->tx_fn[f->size](s->tx[f->size], b->coeffs, win, sizeof(float));
diff --git a/libavcodec/opustab.c b/libavcodec/opustab.c
index b23ca4feac..2a57511177 100644
--- a/libavcodec/opustab.c
+++ b/libavcodec/opustab.c
@@ -1101,7 +1101,7 @@ const float ff_celt_postfilter_taps[3][3] = {
     { 0.7998046875f, 0.1000976562f, 0.0           }
 };
 
-DECLARE_ALIGNED(32, static const float, ff_celt_window_padded)[136] = {
+DECLARE_ALIGNED(32, const float, ff_celt_window_padded)[136] = {
     0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f,
     0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f,
     6.7286966e-05f, 0.00060551348f, 0.0016815970f, 0.0032947962f, 0.0054439943f,
@@ -1132,8 +1132,6 @@ DECLARE_ALIGNED(32, static const float, ff_celt_window_padded)[136] = {
     1.00000000f, 1.00000000f, 1.00000000f,
 };
 
-const float *const ff_celt_window = &ff_celt_window_padded[8];
-
 /* square of the window, used for the postfilter */
 const float ff_celt_window2[120] = {
     4.5275357e-09f, 3.66647e-07f, 2.82777e-06f, 1.08557e-05f, 2.96371e-05f, 6.60594e-05f,
diff --git a/libavcodec/opustab.h b/libavcodec/opustab.h
index 16011db758..9c9f1b9d98 100644
--- a/libavcodec/opustab.h
+++ b/libavcodec/opustab.h
@@ -25,6 +25,9 @@
 
 #include <stdint.h>
 
+#include "libavutil/attributes_internal.h"
+
+FF_VISIBILITY_PUSH_HIDDEN
 extern const uint8_t  ff_celt_band_end[];
 
 extern const uint8_t  ff_opus_default_coupled_streams[];
@@ -154,8 +157,11 @@ extern const uint16_t ff_celt_qn_exp2[];
 extern const float    ff_celt_postfilter_taps[3][3];
 
 extern const float    ff_celt_window2[120];
-extern const float *const ff_celt_window;
+
+extern const float    ff_celt_window_padded[];
+static const float *const ff_celt_window = &ff_celt_window_padded[8];
 
 extern const uint32_t * const ff_celt_pvq_u_row[15];
+FF_VISIBILITY_POP_HIDDEN
 
 #endif /* AVCODEC_OPUSTAB_H */
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 3/9] avcodec/opus: Move OpusStreamContext to its only user
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
  2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window Andreas Rheinhardt
@ 2022-10-03 22:44 ` Andreas Rheinhardt
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 4/9] avcodec/opus: Move stuff shared by decoder and parser to a new file Andreas Rheinhardt
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:44 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Namely opusdec.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opus.h    | 52 +-------------------------------------------
 libavcodec/opusdec.c | 47 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 51 deletions(-)

diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index b73949a811..264128f09e 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -25,12 +25,7 @@
 
 #include <stdint.h>
 
-#include "libavutil/audio_fifo.h"
 #include "libavutil/float_dsp.h"
-#include "libavutil/frame.h"
-#include "libavutil/mem_internal.h"
-
-#include "libswresample/swresample.h"
 
 #include "avcodec.h"
 #include "opus_rc.h"
@@ -98,51 +93,6 @@ typedef struct OpusPacket {
     enum OpusBandwidth bandwidth;   /**< bandwidth */
 } OpusPacket;
 
-typedef struct OpusStreamContext {
-    AVCodecContext *avctx;
-    int output_channels;
-
-    /* number of decoded samples for this stream */
-    int decoded_samples;
-    /* current output buffers for this stream */
-    float *out[2];
-    int out_size;
-    /* Buffer with samples from this stream for synchronizing
-     * the streams when they have different resampling delays */
-    AVAudioFifo *sync_buffer;
-
-    OpusRangeCoder rc;
-    OpusRangeCoder redundancy_rc;
-    SilkContext *silk;
-    CeltFrame *celt;
-    AVFloatDSPContext *fdsp;
-
-    float silk_buf[2][960];
-    float *silk_output[2];
-    DECLARE_ALIGNED(32, float, celt_buf)[2][960];
-    float *celt_output[2];
-
-    DECLARE_ALIGNED(32, float, redundancy_buf)[2][960];
-    float *redundancy_output[2];
-
-    /* buffers for the next samples to be decoded */
-    float *cur_out[2];
-    int remaining_out_size;
-
-    float *out_dummy;
-    int    out_dummy_allocated_size;
-
-    SwrContext *swr;
-    AVAudioFifo *celt_delay;
-    int silk_samplerate;
-    /* number of samples we still want to get from the resampler */
-    int delayed_samples;
-
-    OpusPacket packet;
-
-    int redundancy_idx;
-} OpusStreamContext;
-
 // a mapping between an opus stream and an output channel
 typedef struct ChannelMap {
     int stream_idx;
@@ -161,7 +111,7 @@ typedef struct ChannelMap {
 
 typedef struct OpusContext {
     AVClass *av_class;
-    OpusStreamContext *streams;
+    struct OpusStreamContext *streams;
     int apply_phase_inv;
 
     int             nb_streams;
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index d255486d06..87a86b6b47 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -38,6 +38,8 @@
 #include "libavutil/attributes.h"
 #include "libavutil/audio_fifo.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/frame.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 
 #include "libswresample/swresample.h"
@@ -63,6 +65,51 @@ static const int silk_resample_delay[] = {
     4, 8, 11, 11, 11
 };
 
+typedef struct OpusStreamContext {
+    AVCodecContext *avctx;
+    int output_channels;
+
+    /* number of decoded samples for this stream */
+    int decoded_samples;
+    /* current output buffers for this stream */
+    float *out[2];
+    int out_size;
+    /* Buffer with samples from this stream for synchronizing
+     * the streams when they have different resampling delays */
+    AVAudioFifo *sync_buffer;
+
+    OpusRangeCoder rc;
+    OpusRangeCoder redundancy_rc;
+    SilkContext *silk;
+    CeltFrame *celt;
+    AVFloatDSPContext *fdsp;
+
+    float silk_buf[2][960];
+    float *silk_output[2];
+    DECLARE_ALIGNED(32, float, celt_buf)[2][960];
+    float *celt_output[2];
+
+    DECLARE_ALIGNED(32, float, redundancy_buf)[2][960];
+    float *redundancy_output[2];
+
+    /* buffers for the next samples to be decoded */
+    float *cur_out[2];
+    int remaining_out_size;
+
+    float *out_dummy;
+    int    out_dummy_allocated_size;
+
+    SwrContext *swr;
+    AVAudioFifo *celt_delay;
+    int silk_samplerate;
+    /* number of samples we still want to get from the resampler */
+    int delayed_samples;
+
+    OpusPacket packet;
+
+    int redundancy_idx;
+} OpusStreamContext;
+
 static int get_silk_samplerate(int config)
 {
     if (config < 4)
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 4/9] avcodec/opus: Move stuff shared by decoder and parser to a new file
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
  2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window Andreas Rheinhardt
  2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 3/9] avcodec/opus: Move OpusStreamContext to its only user Andreas Rheinhardt
@ 2022-10-03 22:45 ` Andreas Rheinhardt
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 5/9] avcodec/opus_celt: Break cyclic inlusion of opus_celt.h<->opus_pvq.h Andreas Rheinhardt
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:45 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

opus.h (which is used by all the Opus code) currently includes
several structures only used by the parser and the decoder;
several elements of OpusContext are even only used by the decoder.

This commit therefore moves the part of OpusContext that is shared
between these two components (and used by ff_opus_parse_extradata())
out into a new structure and moves all the other accompanying
structures and functions to a new header, opus_parse.h; the
functions itself are also moved to a new file, opus_parse.c.
(This also allows to remove several spurious dependencies
of the Opus parser and encoder.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/Makefile      |   8 +-
 libavcodec/opus.c        | 442 ------------------------------------
 libavcodec/opus.h        |  54 -----
 libavcodec/opus_parse.c  | 469 +++++++++++++++++++++++++++++++++++++++
 libavcodec/opus_parse.h  |  77 +++++++
 libavcodec/opus_parser.c |  13 +-
 libavcodec/opusdec.c     |  59 +++--
 7 files changed, 594 insertions(+), 528 deletions(-)
 create mode 100644 libavcodec/opus_parse.c
 create mode 100644 libavcodec/opus_parse.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1946930c20..10a9c47ea3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -556,9 +556,9 @@ OBJS-$(CONFIG_NUV_DECODER)             += nuv.o rtjpeg.o
 OBJS-$(CONFIG_ON2AVC_DECODER)          += on2avc.o on2avcdata.o
 OBJS-$(CONFIG_OPUS_DECODER)            += opusdec.o opus.o opus_celt.o opus_rc.o \
                                           opus_pvq.o opus_silk.o opustab.o vorbis_data.o \
-                                          opusdsp.o
+                                          opusdsp.o opus_parse.o
 OBJS-$(CONFIG_OPUS_ENCODER)            += opusenc.o opus.o opus_rc.o opustab.o opus_pvq.o \
-                                          opusenc_psy.o vorbis_data.o
+                                          opusenc_psy.o
 OBJS-$(CONFIG_PAF_AUDIO_DECODER)       += pafaudio.o
 OBJS-$(CONFIG_PAF_VIDEO_DECODER)       += pafvideo.o
 OBJS-$(CONFIG_PAM_DECODER)             += pnmdec.o pnm.o
@@ -1156,8 +1156,8 @@ OBJS-$(CONFIG_MPEG4VIDEO_PARSER)       += mpeg4video_parser.o h263.o \
 OBJS-$(CONFIG_MPEGAUDIO_PARSER)        += mpegaudio_parser.o
 OBJS-$(CONFIG_MPEGVIDEO_PARSER)        += mpegvideo_parser.o    \
                                           mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_OPUS_PARSER)             += opus_parser.o opus.o opustab.o \
-                                          opus_rc.o vorbis_data.o
+OBJS-$(CONFIG_OPUS_PARSER)             += opus_parser.o opus_parse.o \
+                                          vorbis_data.o
 OBJS-$(CONFIG_PNG_PARSER)              += png_parser.o
 OBJS-$(CONFIG_PNM_PARSER)              += pnm_parser.o pnm.o
 OBJS-$(CONFIG_QOI_PARSER)              += qoi_parser.o
diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index b91f57dec3..791e25c488 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -19,452 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/**
- * @file
- * Opus decoder/parser shared code
- */
-
 #include <stdint.h>
 
-#include "libavutil/channel_layout.h"
-#include "libavutil/error.h"
-#include "libavutil/ffmath.h"
-
 #include "opus_celt.h"
 #include "opustab.h"
-#include "internal.h"
-#include "vorbis_data.h"
-
-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
- */
-static inline int xiph_lacing_16bit(const uint8_t **ptr, const uint8_t *end)
-{
-    int val;
-
-    if (*ptr >= end)
-        return AVERROR_INVALIDDATA;
-    val = *(*ptr)++;
-    if (val >= 252) {
-        if (*ptr >= end)
-            return AVERROR_INVALIDDATA;
-        val += 4 * *(*ptr)++;
-    }
-    return val;
-}
-
-/**
- * Read a multi-byte length (used for code 3 packet padding size)
- */
-static inline int xiph_lacing_full(const uint8_t **ptr, const uint8_t *end)
-{
-    int val = 0;
-    int next;
-
-    while (1) {
-        if (*ptr >= end || val > INT_MAX - 254)
-            return AVERROR_INVALIDDATA;
-        next = *(*ptr)++;
-        val += next;
-        if (next < 255)
-            break;
-        else
-            val--;
-    }
-    return val;
-}
-
-/**
- * Parse Opus packet info from raw packet data
- */
-int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size,
-                         int self_delimiting)
-{
-    const uint8_t *ptr = buf;
-    const uint8_t *end = buf + buf_size;
-    int padding = 0;
-    int frame_bytes, i;
-
-    if (buf_size < 1)
-        goto fail;
-
-    /* TOC byte */
-    i = *ptr++;
-    pkt->code   = (i     ) & 0x3;
-    pkt->stereo = (i >> 2) & 0x1;
-    pkt->config = (i >> 3) & 0x1F;
-
-    /* code 2 and code 3 packets have at least 1 byte after the TOC */
-    if (pkt->code >= 2 && buf_size < 2)
-        goto fail;
-
-    switch (pkt->code) {
-    case 0:
-        /* 1 frame */
-        pkt->frame_count = 1;
-        pkt->vbr         = 0;
-
-        if (self_delimiting) {
-            int len = xiph_lacing_16bit(&ptr, end);
-            if (len < 0 || len > end - ptr)
-                goto fail;
-            end      = ptr + len;
-            buf_size = end - buf;
-        }
-
-        frame_bytes = end - ptr;
-        if (frame_bytes > MAX_FRAME_SIZE)
-            goto fail;
-        pkt->frame_offset[0] = ptr - buf;
-        pkt->frame_size[0]   = frame_bytes;
-        break;
-    case 1:
-        /* 2 frames, equal size */
-        pkt->frame_count = 2;
-        pkt->vbr         = 0;
-
-        if (self_delimiting) {
-            int len = xiph_lacing_16bit(&ptr, end);
-            if (len < 0 || 2 * len > end - ptr)
-                goto fail;
-            end      = ptr + 2 * len;
-            buf_size = end - buf;
-        }
-
-        frame_bytes = end - ptr;
-        if (frame_bytes & 1 || frame_bytes >> 1 > MAX_FRAME_SIZE)
-            goto fail;
-        pkt->frame_offset[0] = ptr - buf;
-        pkt->frame_size[0]   = frame_bytes >> 1;
-        pkt->frame_offset[1] = pkt->frame_offset[0] + pkt->frame_size[0];
-        pkt->frame_size[1]   = frame_bytes >> 1;
-        break;
-    case 2:
-        /* 2 frames, different sizes */
-        pkt->frame_count = 2;
-        pkt->vbr         = 1;
-
-        /* read 1st frame size */
-        frame_bytes = xiph_lacing_16bit(&ptr, end);
-        if (frame_bytes < 0)
-            goto fail;
-
-        if (self_delimiting) {
-            int len = xiph_lacing_16bit(&ptr, end);
-            if (len < 0 || len + frame_bytes > end - ptr)
-                goto fail;
-            end      = ptr + frame_bytes + len;
-            buf_size = end - buf;
-        }
-
-        pkt->frame_offset[0] = ptr - buf;
-        pkt->frame_size[0]   = frame_bytes;
-
-        /* calculate 2nd frame size */
-        frame_bytes = end - ptr - pkt->frame_size[0];
-        if (frame_bytes < 0 || frame_bytes > MAX_FRAME_SIZE)
-            goto fail;
-        pkt->frame_offset[1] = pkt->frame_offset[0] + pkt->frame_size[0];
-        pkt->frame_size[1]   = frame_bytes;
-        break;
-    case 3:
-        /* 1 to 48 frames, can be different sizes */
-        i = *ptr++;
-        pkt->frame_count = (i     ) & 0x3F;
-        padding          = (i >> 6) & 0x01;
-        pkt->vbr         = (i >> 7) & 0x01;
-
-        if (pkt->frame_count == 0 || pkt->frame_count > MAX_FRAMES)
-            goto fail;
-
-        /* read padding size */
-        if (padding) {
-            padding = xiph_lacing_full(&ptr, end);
-            if (padding < 0)
-                goto fail;
-        }
-
-        /* read frame sizes */
-        if (pkt->vbr) {
-            /* for VBR, all frames except the final one have their size coded
-               in the bitstream. the last frame size is implicit. */
-            int total_bytes = 0;
-            for (i = 0; i < pkt->frame_count - 1; i++) {
-                frame_bytes = xiph_lacing_16bit(&ptr, end);
-                if (frame_bytes < 0)
-                    goto fail;
-                pkt->frame_size[i] = frame_bytes;
-                total_bytes += frame_bytes;
-            }
-
-            if (self_delimiting) {
-                int len = xiph_lacing_16bit(&ptr, end);
-                if (len < 0 || len + total_bytes + padding > end - ptr)
-                    goto fail;
-                end      = ptr + total_bytes + len + padding;
-                buf_size = end - buf;
-            }
-
-            frame_bytes = end - ptr - padding;
-            if (total_bytes > frame_bytes)
-                goto fail;
-            pkt->frame_offset[0] = ptr - buf;
-            for (i = 1; i < pkt->frame_count; i++)
-                pkt->frame_offset[i] = pkt->frame_offset[i-1] + pkt->frame_size[i-1];
-            pkt->frame_size[pkt->frame_count-1] = frame_bytes - total_bytes;
-        } else {
-            /* for CBR, the remaining packet bytes are divided evenly between
-               the frames */
-            if (self_delimiting) {
-                frame_bytes = xiph_lacing_16bit(&ptr, end);
-                if (frame_bytes < 0 || pkt->frame_count * frame_bytes + padding > end - ptr)
-                    goto fail;
-                end      = ptr + pkt->frame_count * frame_bytes + padding;
-                buf_size = end - buf;
-            } else {
-                frame_bytes = end - ptr - padding;
-                if (frame_bytes % pkt->frame_count ||
-                    frame_bytes / pkt->frame_count > MAX_FRAME_SIZE)
-                    goto fail;
-                frame_bytes /= pkt->frame_count;
-            }
-
-            pkt->frame_offset[0] = ptr - buf;
-            pkt->frame_size[0]   = frame_bytes;
-            for (i = 1; i < pkt->frame_count; i++) {
-                pkt->frame_offset[i] = pkt->frame_offset[i-1] + pkt->frame_size[i-1];
-                pkt->frame_size[i]   = frame_bytes;
-            }
-        }
-    }
-
-    pkt->packet_size = 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];
-    if (pkt->frame_duration * pkt->frame_count > MAX_PACKET_DUR)
-        goto fail;
-
-    /* set mode and bandwidth */
-    if (pkt->config < 12) {
-        pkt->mode = OPUS_MODE_SILK;
-        pkt->bandwidth = pkt->config >> 2;
-    } else if (pkt->config < 16) {
-        pkt->mode = OPUS_MODE_HYBRID;
-        pkt->bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND + (pkt->config >= 14);
-    } else {
-        pkt->mode = OPUS_MODE_CELT;
-        pkt->bandwidth = (pkt->config - 16) >> 2;
-        /* skip medium band */
-        if (pkt->bandwidth)
-            pkt->bandwidth++;
-    }
-
-    return 0;
-
-fail:
-    memset(pkt, 0, sizeof(*pkt));
-    return AVERROR_INVALIDDATA;
-}
-
-static int channel_reorder_vorbis(int nb_channels, int channel_idx)
-{
-    return ff_vorbis_channel_layout_offsets[nb_channels - 1][channel_idx];
-}
-
-static int channel_reorder_unknown(int nb_channels, int channel_idx)
-{
-    return channel_idx;
-}
-
-av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
-                                    OpusContext *s)
-{
-    static const uint8_t default_channel_map[2] = { 0, 1 };
-
-    int (*channel_reorder)(int, int) = channel_reorder_unknown;
-    int channels = avctx->ch_layout.nb_channels;
-
-    const uint8_t *extradata, *channel_map;
-    int extradata_size;
-    int version, map_type, streams, stereo_streams, i, j, ret;
-    AVChannelLayout layout = { 0 };
-
-    if (!avctx->extradata) {
-        if (channels > 2) {
-            av_log(avctx, AV_LOG_ERROR,
-                   "Multichannel configuration without extradata.\n");
-            return AVERROR(EINVAL);
-        }
-        extradata      = opus_default_extradata;
-        extradata_size = sizeof(opus_default_extradata);
-    } else {
-        extradata = avctx->extradata;
-        extradata_size = avctx->extradata_size;
-    }
-
-    if (extradata_size < 19) {
-        av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
-               extradata_size);
-        return AVERROR_INVALIDDATA;
-    }
-
-    version = extradata[8];
-    if (version > 15) {
-        avpriv_request_sample(avctx, "Extradata version %d", version);
-        return AVERROR_PATCHWELCOME;
-    }
-
-    avctx->delay = AV_RL16(extradata + 10);
-    if (avctx->internal)
-        avctx->internal->skip_samples = avctx->delay;
-
-    channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2;
-    if (!channels) {
-        av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the extradata\n");
-        return AVERROR_INVALIDDATA;
-    }
-
-    s->gain_i = AV_RL16(extradata + 16);
-    if (s->gain_i)
-        s->gain = ff_exp10(s->gain_i / (20.0 * 256));
-
-    map_type = extradata[18];
-    if (!map_type) {
-        if (channels > 2) {
-            av_log(avctx, AV_LOG_ERROR,
-                   "Channel mapping 0 is only specified for up to 2 channels\n");
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
-        layout         = (channels == 1) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
-                                           (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
-        streams        = 1;
-        stereo_streams = channels - 1;
-        channel_map    = default_channel_map;
-    } else if (map_type == 1 || map_type == 2 || map_type == 255) {
-        if (extradata_size < 21 + channels) {
-            av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
-                   extradata_size);
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
-
-        streams        = extradata[19];
-        stereo_streams = extradata[20];
-        if (!streams || stereo_streams > streams ||
-            streams + stereo_streams > 255) {
-            av_log(avctx, AV_LOG_ERROR,
-                   "Invalid stream/stereo stream count: %d/%d\n", streams, stereo_streams);
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
-
-        if (map_type == 1) {
-            if (channels > 8) {
-                av_log(avctx, AV_LOG_ERROR,
-                       "Channel mapping 1 is only specified for up to 8 channels\n");
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
-            }
-            av_channel_layout_copy(&layout, &ff_vorbis_ch_layouts[channels - 1]);
-            channel_reorder = channel_reorder_vorbis;
-        } else if (map_type == 2) {
-            int ambisonic_order = ff_sqrt(channels) - 1;
-            if (channels != ((ambisonic_order + 1) * (ambisonic_order + 1)) &&
-                channels != ((ambisonic_order + 1) * (ambisonic_order + 1) + 2)) {
-                av_log(avctx, AV_LOG_ERROR,
-                       "Channel mapping 2 is only specified for channel counts"
-                       " which can be written as (n + 1)^2 or (n + 1)^2 + 2"
-                       " for nonnegative integer n\n");
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
-            }
-            if (channels > 227) {
-                av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
-            }
-
-            layout.order = AV_CHANNEL_ORDER_AMBISONIC;
-            layout.nb_channels = channels;
-            if (channels != ((ambisonic_order + 1) * (ambisonic_order + 1)))
-                layout.u.mask = AV_CH_LAYOUT_STEREO;
-        } else {
-            layout.order       = AV_CHANNEL_ORDER_UNSPEC;
-            layout.nb_channels = channels;
-        }
-
-        channel_map = extradata + 21;
-    } else {
-        avpriv_request_sample(avctx, "Mapping type %d", map_type);
-        return AVERROR_PATCHWELCOME;
-    }
-
-    s->channel_maps = av_calloc(channels, sizeof(*s->channel_maps));
-    if (!s->channel_maps) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
-
-    for (i = 0; i < channels; i++) {
-        ChannelMap *map = &s->channel_maps[i];
-        uint8_t     idx = channel_map[channel_reorder(channels, i)];
-
-        if (idx == 255) {
-            map->silence = 1;
-            continue;
-        } else if (idx >= streams + stereo_streams) {
-            av_log(avctx, AV_LOG_ERROR,
-                   "Invalid channel map for output channel %d: %d\n", i, idx);
-            av_freep(&s->channel_maps);
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
-
-        /* check that we did not see this index yet */
-        map->copy = 0;
-        for (j = 0; j < i; j++)
-            if (channel_map[channel_reorder(channels, j)] == idx) {
-                map->copy     = 1;
-                map->copy_idx = j;
-                break;
-            }
-
-        if (idx < 2 * stereo_streams) {
-            map->stream_idx  = idx / 2;
-            map->channel_idx = idx & 1;
-        } else {
-            map->stream_idx  = idx - stereo_streams;
-            map->channel_idx = 0;
-        }
-    }
-
-    ret = av_channel_layout_copy(&avctx->ch_layout, &layout);
-    if (ret < 0)
-        goto fail;
-
-    s->nb_streams         = streams;
-    s->nb_stereo_streams  = stereo_streams;
-
-    return 0;
-fail:
-    av_channel_layout_uninit(&layout);
-    return ret;
-}
 
 void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc)
 {
diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 264128f09e..c88bb89dde 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -25,8 +25,6 @@
 
 #include <stdint.h>
 
-#include "libavutil/float_dsp.h"
-
 #include "avcodec.h"
 #include "opus_rc.h"
 
@@ -77,58 +75,6 @@ typedef struct SilkContext SilkContext;
 
 typedef struct CeltFrame CeltFrame;
 
-typedef struct OpusPacket {
-    int packet_size;                /**< packet size */
-    int data_size;                  /**< size of the useful data -- packet size - padding */
-    int code;                       /**< packet code: specifies the frame layout */
-    int stereo;                     /**< whether this packet is mono or stereo */
-    int vbr;                        /**< vbr flag */
-    int config;                     /**< configuration: tells the audio mode,
-                                     **                bandwidth, and frame duration */
-    int frame_count;                /**< frame count */
-    int frame_offset[MAX_FRAMES];   /**< frame offsets */
-    int frame_size[MAX_FRAMES];     /**< frame sizes */
-    int frame_duration;             /**< frame duration, in samples @ 48kHz */
-    enum OpusMode mode;             /**< mode */
-    enum OpusBandwidth bandwidth;   /**< bandwidth */
-} OpusPacket;
-
-// a mapping between an opus stream and an output channel
-typedef struct ChannelMap {
-    int stream_idx;
-    int channel_idx;
-
-    // when a single decoded channel is mapped to multiple output channels, we
-    // write to the first output directly and copy from it to the others
-    // this field is set to 1 for those copied output channels
-    int copy;
-    // this is the index of the output channel to copy from
-    int copy_idx;
-
-    // this channel is silent
-    int silence;
-} ChannelMap;
-
-typedef struct OpusContext {
-    AVClass *av_class;
-    struct OpusStreamContext *streams;
-    int apply_phase_inv;
-
-    int             nb_streams;
-    int      nb_stereo_streams;
-
-    AVFloatDSPContext *fdsp;
-    int16_t gain_i;
-    float   gain;
-
-    ChannelMap *channel_maps;
-} OpusContext;
-
-int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size,
-                         int self_delimited);
-
-int ff_opus_parse_extradata(AVCodecContext *avctx, OpusContext *s);
-
 int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels);
 void ff_silk_free(SilkContext **ps);
 void ff_silk_flush(SilkContext *s);
diff --git a/libavcodec/opus_parse.c b/libavcodec/opus_parse.c
new file mode 100644
index 0000000000..39765c5b79
--- /dev/null
+++ b/libavcodec/opus_parse.c
@@ -0,0 +1,469 @@
+/*
+ * Copyright (c) 2012 Andrew D'Addesio
+ * Copyright (c) 2013-2014 Mozilla Corporation
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Opus decoder/parser shared code
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/error.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
+
+#include "avcodec.h"
+#include "internal.h"
+#include "mathops.h"
+#include "opus.h"
+#include "opus_parse.h"
+#include "vorbis_data.h"
+
+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
+ */
+static inline int xiph_lacing_16bit(const uint8_t **ptr, const uint8_t *end)
+{
+    int val;
+
+    if (*ptr >= end)
+        return AVERROR_INVALIDDATA;
+    val = *(*ptr)++;
+    if (val >= 252) {
+        if (*ptr >= end)
+            return AVERROR_INVALIDDATA;
+        val += 4 * *(*ptr)++;
+    }
+    return val;
+}
+
+/**
+ * Read a multi-byte length (used for code 3 packet padding size)
+ */
+static inline int xiph_lacing_full(const uint8_t **ptr, const uint8_t *end)
+{
+    int val = 0;
+    int next;
+
+    while (1) {
+        if (*ptr >= end || val > INT_MAX - 254)
+            return AVERROR_INVALIDDATA;
+        next = *(*ptr)++;
+        val += next;
+        if (next < 255)
+            break;
+        else
+            val--;
+    }
+    return val;
+}
+
+/**
+ * Parse Opus packet info from raw packet data
+ */
+int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size,
+                         int self_delimiting)
+{
+    const uint8_t *ptr = buf;
+    const uint8_t *end = buf + buf_size;
+    int padding = 0;
+    int frame_bytes, i;
+
+    if (buf_size < 1)
+        goto fail;
+
+    /* TOC byte */
+    i = *ptr++;
+    pkt->code   = (i     ) & 0x3;
+    pkt->stereo = (i >> 2) & 0x1;
+    pkt->config = (i >> 3) & 0x1F;
+
+    /* code 2 and code 3 packets have at least 1 byte after the TOC */
+    if (pkt->code >= 2 && buf_size < 2)
+        goto fail;
+
+    switch (pkt->code) {
+    case 0:
+        /* 1 frame */
+        pkt->frame_count = 1;
+        pkt->vbr         = 0;
+
+        if (self_delimiting) {
+            int len = xiph_lacing_16bit(&ptr, end);
+            if (len < 0 || len > end - ptr)
+                goto fail;
+            end      = ptr + len;
+            buf_size = end - buf;
+        }
+
+        frame_bytes = end - ptr;
+        if (frame_bytes > MAX_FRAME_SIZE)
+            goto fail;
+        pkt->frame_offset[0] = ptr - buf;
+        pkt->frame_size[0]   = frame_bytes;
+        break;
+    case 1:
+        /* 2 frames, equal size */
+        pkt->frame_count = 2;
+        pkt->vbr         = 0;
+
+        if (self_delimiting) {
+            int len = xiph_lacing_16bit(&ptr, end);
+            if (len < 0 || 2 * len > end - ptr)
+                goto fail;
+            end      = ptr + 2 * len;
+            buf_size = end - buf;
+        }
+
+        frame_bytes = end - ptr;
+        if (frame_bytes & 1 || frame_bytes >> 1 > MAX_FRAME_SIZE)
+            goto fail;
+        pkt->frame_offset[0] = ptr - buf;
+        pkt->frame_size[0]   = frame_bytes >> 1;
+        pkt->frame_offset[1] = pkt->frame_offset[0] + pkt->frame_size[0];
+        pkt->frame_size[1]   = frame_bytes >> 1;
+        break;
+    case 2:
+        /* 2 frames, different sizes */
+        pkt->frame_count = 2;
+        pkt->vbr         = 1;
+
+        /* read 1st frame size */
+        frame_bytes = xiph_lacing_16bit(&ptr, end);
+        if (frame_bytes < 0)
+            goto fail;
+
+        if (self_delimiting) {
+            int len = xiph_lacing_16bit(&ptr, end);
+            if (len < 0 || len + frame_bytes > end - ptr)
+                goto fail;
+            end      = ptr + frame_bytes + len;
+            buf_size = end - buf;
+        }
+
+        pkt->frame_offset[0] = ptr - buf;
+        pkt->frame_size[0]   = frame_bytes;
+
+        /* calculate 2nd frame size */
+        frame_bytes = end - ptr - pkt->frame_size[0];
+        if (frame_bytes < 0 || frame_bytes > MAX_FRAME_SIZE)
+            goto fail;
+        pkt->frame_offset[1] = pkt->frame_offset[0] + pkt->frame_size[0];
+        pkt->frame_size[1]   = frame_bytes;
+        break;
+    case 3:
+        /* 1 to 48 frames, can be different sizes */
+        i = *ptr++;
+        pkt->frame_count = (i     ) & 0x3F;
+        padding          = (i >> 6) & 0x01;
+        pkt->vbr         = (i >> 7) & 0x01;
+
+        if (pkt->frame_count == 0 || pkt->frame_count > MAX_FRAMES)
+            goto fail;
+
+        /* read padding size */
+        if (padding) {
+            padding = xiph_lacing_full(&ptr, end);
+            if (padding < 0)
+                goto fail;
+        }
+
+        /* read frame sizes */
+        if (pkt->vbr) {
+            /* for VBR, all frames except the final one have their size coded
+               in the bitstream. the last frame size is implicit. */
+            int total_bytes = 0;
+            for (i = 0; i < pkt->frame_count - 1; i++) {
+                frame_bytes = xiph_lacing_16bit(&ptr, end);
+                if (frame_bytes < 0)
+                    goto fail;
+                pkt->frame_size[i] = frame_bytes;
+                total_bytes += frame_bytes;
+            }
+
+            if (self_delimiting) {
+                int len = xiph_lacing_16bit(&ptr, end);
+                if (len < 0 || len + total_bytes + padding > end - ptr)
+                    goto fail;
+                end      = ptr + total_bytes + len + padding;
+                buf_size = end - buf;
+            }
+
+            frame_bytes = end - ptr - padding;
+            if (total_bytes > frame_bytes)
+                goto fail;
+            pkt->frame_offset[0] = ptr - buf;
+            for (i = 1; i < pkt->frame_count; i++)
+                pkt->frame_offset[i] = pkt->frame_offset[i-1] + pkt->frame_size[i-1];
+            pkt->frame_size[pkt->frame_count-1] = frame_bytes - total_bytes;
+        } else {
+            /* for CBR, the remaining packet bytes are divided evenly between
+               the frames */
+            if (self_delimiting) {
+                frame_bytes = xiph_lacing_16bit(&ptr, end);
+                if (frame_bytes < 0 || pkt->frame_count * frame_bytes + padding > end - ptr)
+                    goto fail;
+                end      = ptr + pkt->frame_count * frame_bytes + padding;
+                buf_size = end - buf;
+            } else {
+                frame_bytes = end - ptr - padding;
+                if (frame_bytes % pkt->frame_count ||
+                    frame_bytes / pkt->frame_count > MAX_FRAME_SIZE)
+                    goto fail;
+                frame_bytes /= pkt->frame_count;
+            }
+
+            pkt->frame_offset[0] = ptr - buf;
+            pkt->frame_size[0]   = frame_bytes;
+            for (i = 1; i < pkt->frame_count; i++) {
+                pkt->frame_offset[i] = pkt->frame_offset[i-1] + pkt->frame_size[i-1];
+                pkt->frame_size[i]   = frame_bytes;
+            }
+        }
+    }
+
+    pkt->packet_size = 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];
+    if (pkt->frame_duration * pkt->frame_count > MAX_PACKET_DUR)
+        goto fail;
+
+    /* set mode and bandwidth */
+    if (pkt->config < 12) {
+        pkt->mode = OPUS_MODE_SILK;
+        pkt->bandwidth = pkt->config >> 2;
+    } else if (pkt->config < 16) {
+        pkt->mode = OPUS_MODE_HYBRID;
+        pkt->bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND + (pkt->config >= 14);
+    } else {
+        pkt->mode = OPUS_MODE_CELT;
+        pkt->bandwidth = (pkt->config - 16) >> 2;
+        /* skip medium band */
+        if (pkt->bandwidth)
+            pkt->bandwidth++;
+    }
+
+    return 0;
+
+fail:
+    memset(pkt, 0, sizeof(*pkt));
+    return AVERROR_INVALIDDATA;
+}
+
+static int channel_reorder_vorbis(int nb_channels, int channel_idx)
+{
+    return ff_vorbis_channel_layout_offsets[nb_channels - 1][channel_idx];
+}
+
+static int channel_reorder_unknown(int nb_channels, int channel_idx)
+{
+    return channel_idx;
+}
+
+av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
+                                    OpusParseContext *s)
+{
+    static const uint8_t default_channel_map[2] = { 0, 1 };
+
+    int (*channel_reorder)(int, int) = channel_reorder_unknown;
+    int channels = avctx->ch_layout.nb_channels;
+
+    const uint8_t *extradata, *channel_map;
+    int extradata_size;
+    int version, map_type, streams, stereo_streams, i, j, ret;
+    AVChannelLayout layout = { 0 };
+
+    if (!avctx->extradata) {
+        if (channels > 2) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Multichannel configuration without extradata.\n");
+            return AVERROR(EINVAL);
+        }
+        extradata      = opus_default_extradata;
+        extradata_size = sizeof(opus_default_extradata);
+    } else {
+        extradata = avctx->extradata;
+        extradata_size = avctx->extradata_size;
+    }
+
+    if (extradata_size < 19) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
+               extradata_size);
+        return AVERROR_INVALIDDATA;
+    }
+
+    version = extradata[8];
+    if (version > 15) {
+        avpriv_request_sample(avctx, "Extradata version %d", version);
+        return AVERROR_PATCHWELCOME;
+    }
+
+    avctx->delay = AV_RL16(extradata + 10);
+    if (avctx->internal)
+        avctx->internal->skip_samples = avctx->delay;
+
+    channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2;
+    if (!channels) {
+        av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the extradata\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    s->gain_i = AV_RL16(extradata + 16);
+
+    map_type = extradata[18];
+    if (!map_type) {
+        if (channels > 2) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Channel mapping 0 is only specified for up to 2 channels\n");
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
+        }
+        layout         = (channels == 1) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
+                                           (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+        streams        = 1;
+        stereo_streams = channels - 1;
+        channel_map    = default_channel_map;
+    } else if (map_type == 1 || map_type == 2 || map_type == 255) {
+        if (extradata_size < 21 + channels) {
+            av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
+                   extradata_size);
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
+        }
+
+        streams        = extradata[19];
+        stereo_streams = extradata[20];
+        if (!streams || stereo_streams > streams ||
+            streams + stereo_streams > 255) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Invalid stream/stereo stream count: %d/%d\n", streams, stereo_streams);
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
+        }
+
+        if (map_type == 1) {
+            if (channels > 8) {
+                av_log(avctx, AV_LOG_ERROR,
+                       "Channel mapping 1 is only specified for up to 8 channels\n");
+                ret = AVERROR_INVALIDDATA;
+                goto fail;
+            }
+            av_channel_layout_copy(&layout, &ff_vorbis_ch_layouts[channels - 1]);
+            channel_reorder = channel_reorder_vorbis;
+        } else if (map_type == 2) {
+            int ambisonic_order = ff_sqrt(channels) - 1;
+            if (channels != ((ambisonic_order + 1) * (ambisonic_order + 1)) &&
+                channels != ((ambisonic_order + 1) * (ambisonic_order + 1) + 2)) {
+                av_log(avctx, AV_LOG_ERROR,
+                       "Channel mapping 2 is only specified for channel counts"
+                       " which can be written as (n + 1)^2 or (n + 1)^2 + 2"
+                       " for nonnegative integer n\n");
+                ret = AVERROR_INVALIDDATA;
+                goto fail;
+            }
+            if (channels > 227) {
+                av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
+                ret = AVERROR_INVALIDDATA;
+                goto fail;
+            }
+
+            layout.order = AV_CHANNEL_ORDER_AMBISONIC;
+            layout.nb_channels = channels;
+            if (channels != ((ambisonic_order + 1) * (ambisonic_order + 1)))
+                layout.u.mask = AV_CH_LAYOUT_STEREO;
+        } else {
+            layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            layout.nb_channels = channels;
+        }
+
+        channel_map = extradata + 21;
+    } else {
+        avpriv_request_sample(avctx, "Mapping type %d", map_type);
+        return AVERROR_PATCHWELCOME;
+    }
+
+    s->channel_maps = av_calloc(channels, sizeof(*s->channel_maps));
+    if (!s->channel_maps) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    for (i = 0; i < channels; i++) {
+        ChannelMap *map = &s->channel_maps[i];
+        uint8_t     idx = channel_map[channel_reorder(channels, i)];
+
+        if (idx == 255) {
+            map->silence = 1;
+            continue;
+        } else if (idx >= streams + stereo_streams) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Invalid channel map for output channel %d: %d\n", i, idx);
+            av_freep(&s->channel_maps);
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
+        }
+
+        /* check that we did not see this index yet */
+        map->copy = 0;
+        for (j = 0; j < i; j++)
+            if (channel_map[channel_reorder(channels, j)] == idx) {
+                map->copy     = 1;
+                map->copy_idx = j;
+                break;
+            }
+
+        if (idx < 2 * stereo_streams) {
+            map->stream_idx  = idx / 2;
+            map->channel_idx = idx & 1;
+        } else {
+            map->stream_idx  = idx - stereo_streams;
+            map->channel_idx = 0;
+        }
+    }
+
+    ret = av_channel_layout_copy(&avctx->ch_layout, &layout);
+    if (ret < 0)
+        goto fail;
+
+    s->nb_streams         = streams;
+    s->nb_stereo_streams  = stereo_streams;
+
+    return 0;
+fail:
+    av_channel_layout_uninit(&layout);
+    return ret;
+}
+
diff --git a/libavcodec/opus_parse.h b/libavcodec/opus_parse.h
new file mode 100644
index 0000000000..8e5c6a880c
--- /dev/null
+++ b/libavcodec/opus_parse.h
@@ -0,0 +1,77 @@
+/*
+ * Opus decoder/parser common functions and structures
+ * Copyright (c) 2012 Andrew D'Addesio
+ * Copyright (c) 2013-2014 Mozilla Corporation
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_OPUS_PARSE_H
+#define AVCODEC_OPUS_PARSE_H
+
+#include <stdint.h>
+
+#include "avcodec.h"
+#include "opus.h"
+
+typedef struct OpusPacket {
+    int packet_size;                /**< packet size */
+    int data_size;                  /**< size of the useful data -- packet size - padding */
+    int code;                       /**< packet code: specifies the frame layout */
+    int stereo;                     /**< whether this packet is mono or stereo */
+    int vbr;                        /**< vbr flag */
+    int config;                     /**< configuration: tells the audio mode,
+                                     **                bandwidth, and frame duration */
+    int frame_count;                /**< frame count */
+    int frame_offset[MAX_FRAMES];   /**< frame offsets */
+    int frame_size[MAX_FRAMES];     /**< frame sizes */
+    int frame_duration;             /**< frame duration, in samples @ 48kHz */
+    enum OpusMode mode;             /**< mode */
+    enum OpusBandwidth bandwidth;   /**< bandwidth */
+} OpusPacket;
+
+// a mapping between an opus stream and an output channel
+typedef struct ChannelMap {
+    int stream_idx;
+    int channel_idx;
+
+    // when a single decoded channel is mapped to multiple output channels, we
+    // write to the first output directly and copy from it to the others
+    // this field is set to 1 for those copied output channels
+    int copy;
+    // this is the index of the output channel to copy from
+    int copy_idx;
+
+    // this channel is silent
+    int silence;
+} ChannelMap;
+
+typedef struct OpusParseContext {
+    int             nb_streams;
+    int      nb_stereo_streams;
+
+    int16_t gain_i;
+
+    ChannelMap *channel_maps;
+} OpusParseContext;
+
+int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size,
+                         int self_delimited);
+
+int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s);
+
+#endif /* AVCODEC_OPUS_PARSE_H */
diff --git a/libavcodec/opus_parser.c b/libavcodec/opus_parser.c
index 726c010f67..e6df34abab 100644
--- a/libavcodec/opus_parser.c
+++ b/libavcodec/opus_parser.c
@@ -28,15 +28,16 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "opus.h"
+#include "opus_parse.h"
 #include "parser.h"
 
-typedef struct OpusParseContext {
+typedef struct OpusParserContext {
     ParseContext pc;
-    OpusContext ctx;
+    OpusParseContext ctx;
     OpusPacket pkt;
     int extradata_parsed;
     int ts_framing;
-} OpusParseContext;
+} OpusParserContext;
 
 static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_len, int buf_len)
 {
@@ -83,7 +84,7 @@ static const uint8_t *parse_opus_ts_header(const uint8_t *start, int *payload_le
 static int opus_find_frame_end(AVCodecParserContext *ctx, AVCodecContext *avctx,
                                const uint8_t *buf, int buf_size, int *header_len)
 {
-    OpusParseContext *s = ctx->priv_data;
+    OpusParserContext *s = ctx->priv_data;
     ParseContext *pc    = &s->pc;
     int ret, start_found, i = 0, payload_len = 0;
     const uint8_t *payload;
@@ -166,7 +167,7 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx,
                        const uint8_t **poutbuf, int *poutbuf_size,
                        const uint8_t *buf, int buf_size)
 {
-    OpusParseContext *s = ctx->priv_data;
+    OpusParserContext *s = ctx->priv_data;
     ParseContext *pc    = &s->pc;
     int next, header_len;
 
@@ -192,7 +193,7 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx,
 
 const AVCodecParser ff_opus_parser = {
     .codec_ids      = { AV_CODEC_ID_OPUS },
-    .priv_data_size = sizeof(OpusParseContext),
+    .priv_data_size = sizeof(OpusParserContext),
     .parser_parse   = opus_parse,
     .parser_close   = ff_parse_close
 };
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index 87a86b6b47..e26ca0b2c3 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -38,6 +38,8 @@
 #include "libavutil/attributes.h"
 #include "libavutil/audio_fifo.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/ffmath.h"
+#include "libavutil/float_dsp.h"
 #include "libavutil/frame.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
@@ -50,6 +52,7 @@
 #include "opus.h"
 #include "opustab.h"
 #include "opus_celt.h"
+#include "opus_parse.h"
 
 static const uint16_t silk_frame_duration_ms[16] = {
     10, 20, 40, 60,
@@ -110,6 +113,18 @@ typedef struct OpusStreamContext {
     int redundancy_idx;
 } OpusStreamContext;
 
+typedef struct OpusContext {
+    AVClass *av_class;
+
+    struct OpusStreamContext *streams;
+    int apply_phase_inv;
+
+    AVFloatDSPContext *fdsp;
+    float   gain;
+
+    OpusParseContext p;
+} OpusContext;
+
 static int get_silk_samplerate(int config)
 {
     if (config < 4)
@@ -469,7 +484,7 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
     int i, ret;
 
     /* calculate the number of delayed samples */
-    for (i = 0; i < c->nb_streams; i++) {
+    for (int i = 0; i < c->p.nb_streams; i++) {
         OpusStreamContext *s = &c->streams[i];
         s->out[0] =
         s->out[1] = NULL;
@@ -480,7 +495,7 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
     /* decode the header of the first sub-packet to find out the sample count */
     if (buf) {
         OpusPacket *pkt = &c->streams[0].packet;
-        ret = ff_opus_parse_packet(pkt, buf, buf_size, c->nb_streams > 1);
+        ret = ff_opus_parse_packet(pkt, buf, buf_size, c->p.nb_streams > 1);
         if (ret < 0) {
             av_log(avctx, AV_LOG_ERROR, "Error parsing the packet header.\n");
             return ret;
@@ -504,13 +519,13 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
     frame->nb_samples = 0;
 
     for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
-        ChannelMap *map = &c->channel_maps[i];
+        ChannelMap *map = &c->p.channel_maps[i];
         if (!map->copy)
             c->streams[map->stream_idx].out[map->channel_idx] = (float*)frame->extended_data[i];
     }
 
     /* read the data from the sync buffers */
-    for (i = 0; i < c->nb_streams; i++) {
+    for (int i = 0; i < c->p.nb_streams; i++) {
         OpusStreamContext *s = &c->streams[i];
         float          **out = s->out;
         int sync_size = av_audio_fifo_size(s->sync_buffer);
@@ -542,11 +557,11 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
     }
 
     /* decode each sub-packet */
-    for (i = 0; i < c->nb_streams; i++) {
+    for (int i = 0; i < c->p.nb_streams; i++) {
         OpusStreamContext *s = &c->streams[i];
 
         if (i && buf) {
-            ret = ff_opus_parse_packet(&s->packet, buf, buf_size, i != c->nb_streams - 1);
+            ret = ff_opus_parse_packet(&s->packet, buf, buf_size, i != c->p.nb_streams - 1);
             if (ret < 0) {
                 av_log(avctx, AV_LOG_ERROR, "Error parsing the packet header.\n");
                 return ret;
@@ -572,7 +587,7 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
     }
 
     /* buffer the extra samples */
-    for (i = 0; i < c->nb_streams; i++) {
+    for (int i = 0; i < c->p.nb_streams; i++) {
         OpusStreamContext *s = &c->streams[i];
         int   buffer_samples = s->decoded_samples - decoded_samples;
         if (buffer_samples) {
@@ -587,7 +602,7 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
     }
 
     for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
-        ChannelMap *map = &c->channel_maps[i];
+        ChannelMap *map = &c->p.channel_maps[i];
 
         /* handle copied channels */
         if (map->copy) {
@@ -598,7 +613,7 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
             memset(frame->extended_data[i], 0, frame->linesize[0]);
         }
 
-        if (c->gain_i && decoded_samples > 0) {
+        if (c->p.gain_i && decoded_samples > 0) {
             c->fdsp->vector_fmul_scalar((float*)frame->extended_data[i],
                                        (float*)frame->extended_data[i],
                                        c->gain, FFALIGN(decoded_samples, 8));
@@ -614,9 +629,8 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
 static av_cold void opus_decode_flush(AVCodecContext *ctx)
 {
     OpusContext *c = ctx->priv_data;
-    int i;
 
-    for (i = 0; i < c->nb_streams; i++) {
+    for (int i = 0; i < c->p.nb_streams; i++) {
         OpusStreamContext *s = &c->streams[i];
 
         memset(&s->packet, 0, sizeof(s->packet));
@@ -635,9 +649,8 @@ static av_cold void opus_decode_flush(AVCodecContext *ctx)
 static av_cold int opus_decode_close(AVCodecContext *avctx)
 {
     OpusContext *c = avctx->priv_data;
-    int i;
 
-    for (i = 0; i < c->nb_streams; i++) {
+    for (int i = 0; i < c->p.nb_streams; i++) {
         OpusStreamContext *s = &c->streams[i];
 
         ff_silk_free(&s->silk);
@@ -653,9 +666,9 @@ static av_cold int opus_decode_close(AVCodecContext *avctx)
 
     av_freep(&c->streams);
 
-    c->nb_streams = 0;
+    c->p.nb_streams = 0;
 
-    av_freep(&c->channel_maps);
+    av_freep(&c->p.channel_maps);
     av_freep(&c->fdsp);
 
     return 0;
@@ -664,7 +677,7 @@ static av_cold int opus_decode_close(AVCodecContext *avctx)
 static av_cold int opus_decode_init(AVCodecContext *avctx)
 {
     OpusContext *c = avctx->priv_data;
-    int ret, i, j;
+    int ret;
 
     avctx->sample_fmt  = AV_SAMPLE_FMT_FLTP;
     avctx->sample_rate = 48000;
@@ -674,26 +687,28 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
 
     /* find out the channel configuration */
-    ret = ff_opus_parse_extradata(avctx, c);
+    ret = ff_opus_parse_extradata(avctx, &c->p);
     if (ret < 0)
         return ret;
+    if (c->p.gain_i)
+        c->gain = ff_exp10(c->p.gain_i / (20.0 * 256));
 
     /* allocate and init each independent decoder */
-    c->streams = av_calloc(c->nb_streams, sizeof(*c->streams));
+    c->streams = av_calloc(c->p.nb_streams, sizeof(*c->streams));
     if (!c->streams) {
-        c->nb_streams = 0;
+        c->p.nb_streams = 0;
         return AVERROR(ENOMEM);
     }
 
-    for (i = 0; i < c->nb_streams; i++) {
+    for (int i = 0; i < c->p.nb_streams; i++) {
         OpusStreamContext *s = &c->streams[i];
         AVChannelLayout layout;
 
-        s->output_channels = (i < c->nb_stereo_streams) ? 2 : 1;
+        s->output_channels = (i < c->p.nb_stereo_streams) ? 2 : 1;
 
         s->avctx = avctx;
 
-        for (j = 0; j < s->output_channels; j++) {
+        for (int j = 0; j < s->output_channels; j++) {
             s->silk_output[j]       = s->silk_buf[j];
             s->celt_output[j]       = s->celt_buf[j];
             s->redundancy_output[j] = s->redundancy_buf[j];
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 5/9] avcodec/opus_celt: Break cyclic inlusion of opus_celt.h<->opus_pvq.h
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
                   ` (2 preceding siblings ...)
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 4/9] avcodec/opus: Move stuff shared by decoder and parser to a new file Andreas Rheinhardt
@ 2022-10-03 22:45 ` Andreas Rheinhardt
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 6/9] avcodec/opus_celt, opus_pvq: Move CeltPVQ typedef to opus_pvq.h Andreas Rheinhardt
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:45 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Simply don't include opus_pvq.h in opus_celt.h: The latter only
uses pointers to CeltPVQ.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opus.c      | 1 +
 libavcodec/opus_celt.h | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index 791e25c488..a24c38be52 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -22,6 +22,7 @@
 #include <stdint.h>
 
 #include "opus_celt.h"
+#include "opus_pvq.h"
 #include "opustab.h"
 
 void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc)
diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
index 291a544298..19cf617652 100644
--- a/libavcodec/opus_celt.h
+++ b/libavcodec/opus_celt.h
@@ -27,7 +27,6 @@
 #include <float.h>
 
 #include "opus.h"
-#include "opus_pvq.h"
 #include "opusdsp.h"
 
 #include "libavutil/float_dsp.h"
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 6/9] avcodec/opus_celt, opus_pvq: Move CeltPVQ typedef to opus_pvq.h
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
                   ` (3 preceding siblings ...)
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 5/9] avcodec/opus_celt: Break cyclic inlusion of opus_celt.h<->opus_pvq.h Andreas Rheinhardt
@ 2022-10-03 22:45 ` Andreas Rheinhardt
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 7/9] avcodec/opus: Move remaining celt declarations to opus_celt.h Andreas Rheinhardt
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:45 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

It is more natural that way.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opus_celt.h | 4 +---
 libavcodec/opus_pvq.h  | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
index 19cf617652..c812b6645c 100644
--- a/libavcodec/opus_celt.h
+++ b/libavcodec/opus_celt.h
@@ -44,8 +44,6 @@
 #define CELT_POSTFILTER_MINPERIOD    15
 #define CELT_ENERGY_SILENCE          (-28.0f)
 
-typedef struct CeltPVQ CeltPVQ;
-
 enum CeltSpread {
     CELT_SPREAD_NONE,
     CELT_SPREAD_LIGHT,
@@ -96,7 +94,7 @@ struct CeltFrame {
     av_tx_fn            tx_fn[4];
     AVFloatDSPContext   *dsp;
     CeltBlock           block[2];
-    CeltPVQ             *pvq;
+    struct CeltPVQ      *pvq;
     OpusDSP             opusdsp;
     int channels;
     int output_channels;
diff --git a/libavcodec/opus_pvq.h b/libavcodec/opus_pvq.h
index b30407f5ab..b71bc49034 100644
--- a/libavcodec/opus_pvq.h
+++ b/libavcodec/opus_pvq.h
@@ -34,13 +34,13 @@
                                        float *lowband_out, int level, float gain,    \
                                        float *lowband_scratch, int fill)
 
-struct CeltPVQ {
+typedef struct CeltPVQ {
     DECLARE_ALIGNED(32, int,   qcoeff      )[256];
     DECLARE_ALIGNED(32, float, hadamard_tmp)[256];
 
     float (*pvq_search)(float *X, int *y, int K, int N);
     QUANT_FN(*quant_band);
-};
+} CeltPVQ;
 
 void ff_celt_pvq_init_x86(struct CeltPVQ *s);
 
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 7/9] avcodec/opus: Move remaining celt declarations to opus_celt.h
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
                   ` (4 preceding siblings ...)
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 6/9] avcodec/opus_celt, opus_pvq: Move CeltPVQ typedef to opus_pvq.h Andreas Rheinhardt
@ 2022-10-03 22:45 ` Andreas Rheinhardt
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 8/9] avcodec/opus: Move defines to better places Andreas Rheinhardt
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:45 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opus.h      |  8 --------
 libavcodec/opus_celt.h | 11 +++++++++--
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index c88bb89dde..023bc9daa1 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -73,8 +73,6 @@ enum OpusBandwidth {
 
 typedef struct SilkContext SilkContext;
 
-typedef struct CeltFrame CeltFrame;
-
 int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels);
 void ff_silk_free(SilkContext **ps);
 void ff_silk_flush(SilkContext *s);
@@ -88,10 +86,4 @@ int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc,
                               enum OpusBandwidth bandwidth, int coded_channels,
                               int duration_ms);
 
-/* Encode or decode CELT bands */
-void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc);
-
-/* Encode or decode CELT bitallocation */
-void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode);
-
 #endif /* AVCODEC_OPUS_H */
diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
index c812b6645c..8d92b86b07 100644
--- a/libavcodec/opus_celt.h
+++ b/libavcodec/opus_celt.h
@@ -28,6 +28,7 @@
 
 #include "opus.h"
 #include "opusdsp.h"
+#include "opus_rc.h"
 
 #include "libavutil/float_dsp.h"
 #include "libavutil/libm.h"
@@ -87,7 +88,7 @@ typedef struct CeltBlock {
     float emph_coeff;
 } CeltBlock;
 
-struct CeltFrame {
+typedef struct CeltFrame {
     // constant values that do not change during context lifetime
     AVCodecContext      *avctx;
     AVTXContext        *tx[4];
@@ -136,7 +137,7 @@ struct CeltFrame {
     int fine_priority[CELT_MAX_BANDS];
     int pulses       [CELT_MAX_BANDS];
     int tf_change    [CELT_MAX_BANDS];
-};
+} CeltFrame;
 
 /* LCG for noise generation */
 static av_always_inline uint32_t celt_rng(CeltFrame *f)
@@ -167,4 +168,10 @@ void ff_celt_flush(CeltFrame *f);
 int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output,
                          int coded_channels, int frame_size, int startband, int endband);
 
+/* Encode or decode CELT bands */
+void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc);
+
+/* Encode or decode CELT bitallocation */
+void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode);
+
 #endif /* AVCODEC_OPUS_CELT_H */
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 8/9] avcodec/opus: Move defines to better places
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
                   ` (5 preceding siblings ...)
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 7/9] avcodec/opus: Move remaining celt declarations to opus_celt.h Andreas Rheinhardt
@ 2022-10-03 22:45 ` Andreas Rheinhardt
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 9/9] avcodec/opus: Move Silk declarations to a new header, opus_silk.h Andreas Rheinhardt
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:45 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Move ROUND_MUL* macros to their only users and the Celt
macros to opus_celt.h. Also improve the other headers
a bit while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opus.h        |  9 ---------
 libavcodec/opus_celt.c   |  2 ++
 libavcodec/opus_celt.h   | 10 ++++++++--
 libavcodec/opus_pvq.c    |  5 +++++
 libavcodec/opus_silk.c   |  3 +++
 libavcodec/opusenc.c     |  2 ++
 libavcodec/opusenc.h     |  3 ++-
 libavcodec/opusenc_psy.c |  5 ++++-
 libavcodec/opusenc_psy.h |  2 +-
 9 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 023bc9daa1..283d9d9f7a 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -32,18 +32,9 @@
 #define MAX_FRAMES                   48
 #define MAX_PACKET_DUR               5760
 
-#define CELT_SHORT_BLOCKSIZE         120
-#define CELT_OVERLAP                 CELT_SHORT_BLOCKSIZE
-#define CELT_MAX_LOG_BLOCKS          3
-#define CELT_MAX_FRAME_SIZE          (CELT_SHORT_BLOCKSIZE * (1 << CELT_MAX_LOG_BLOCKS))
-#define CELT_MAX_BANDS               21
-
 #define SILK_HISTORY                 322
 #define SILK_MAX_LPC                 16
 
-#define ROUND_MULL(a,b,s) (((MUL64(a, b) >> ((s) - 1)) + 1) >> 1)
-#define ROUND_MUL16(a,b)  ((MUL16(a, b) + 16384) >> 15)
-
 #define OPUS_TS_HEADER     0x7FE0        // 0x3ff (11 bits)
 #define OPUS_TS_MASK       0xFFE0        // top 11 bits
 
diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c
index f1fb88a56d..c2904cc9e0 100644
--- a/libavcodec/opus_celt.c
+++ b/libavcodec/opus_celt.c
@@ -25,6 +25,8 @@
  * Opus CELT decoder
  */
 
+#include <float.h>
+
 #include "opus_celt.h"
 #include "opustab.h"
 #include "opus_pvq.h"
diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
index 8d92b86b07..3aa96244e1 100644
--- a/libavcodec/opus_celt.h
+++ b/libavcodec/opus_celt.h
@@ -24,9 +24,9 @@
 #ifndef AVCODEC_OPUS_CELT_H
 #define AVCODEC_OPUS_CELT_H
 
-#include <float.h>
+#include <stdint.h>
 
-#include "opus.h"
+#include "avcodec.h"
 #include "opusdsp.h"
 #include "opus_rc.h"
 
@@ -35,6 +35,12 @@
 #include "libavutil/mem_internal.h"
 #include "libavutil/tx.h"
 
+#define CELT_SHORT_BLOCKSIZE         120
+#define CELT_OVERLAP                 CELT_SHORT_BLOCKSIZE
+#define CELT_MAX_LOG_BLOCKS          3
+#define CELT_MAX_FRAME_SIZE          (CELT_SHORT_BLOCKSIZE * (1 << CELT_MAX_LOG_BLOCKS))
+#define CELT_MAX_BANDS               21
+
 #define CELT_VECTORS                 11
 #define CELT_ALLOC_STEPS             6
 #define CELT_FINE_OFFSET             21
diff --git a/libavcodec/opus_pvq.c b/libavcodec/opus_pvq.c
index a4e44b7a14..79101847af 100644
--- a/libavcodec/opus_pvq.c
+++ b/libavcodec/opus_pvq.c
@@ -23,11 +23,16 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <float.h>
+
 #include "config_components.h"
 
+#include "mathops.h"
 #include "opustab.h"
 #include "opus_pvq.h"
 
+#define ROUND_MUL16(a,b)  ((MUL16(a, b) + 16384) >> 15)
+
 #define CELT_PVQ_U(n, k) (ff_celt_pvq_u_row[FFMIN(n, k)][FFMAX(n, k)])
 #define CELT_PVQ_V(n, k) (CELT_PVQ_U(n, k) + CELT_PVQ_U(n, (k) + 1))
 
diff --git a/libavcodec/opus_silk.c b/libavcodec/opus_silk.c
index f9d67f4fb3..fd1e83659c 100644
--- a/libavcodec/opus_silk.c
+++ b/libavcodec/opus_silk.c
@@ -26,9 +26,12 @@
 
 #include <stdint.h>
 
+#include "mathops.h"
 #include "opus.h"
 #include "opustab.h"
 
+#define ROUND_MULL(a,b,s) (((MUL64(a, b) >> ((s) - 1)) + 1) >> 1)
+
 typedef struct SilkFrame {
     int coded;
     int log_gain;
diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
index 06f71876eb..d082b86056 100644
--- a/libavcodec/opusenc.c
+++ b/libavcodec/opusenc.c
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <float.h>
+
 #include "encode.h"
 #include "opusenc.h"
 #include "opus_pvq.h"
diff --git a/libavcodec/opusenc.h b/libavcodec/opusenc.h
index 32d23deead..4d691d6a7d 100644
--- a/libavcodec/opusenc.h
+++ b/libavcodec/opusenc.h
@@ -22,7 +22,8 @@
 #ifndef AVCODEC_OPUSENC_H
 #define AVCODEC_OPUSENC_H
 
-#include "opus_celt.h"
+#include "libavutil/intmath.h"
+#include "opus.h"
 
 /* Determines the maximum delay the psychoacoustic system will use for lookahead */
 #define FF_BUFQUEUE_SIZE 145
diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c
index 3bff57d347..9b11651dbe 100644
--- a/libavcodec/opusenc_psy.c
+++ b/libavcodec/opusenc_psy.c
@@ -19,10 +19,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <float.h>
+
 #include "opusenc_psy.h"
+#include "opus_celt.h"
 #include "opus_pvq.h"
 #include "opustab.h"
-#include "libavutil/qsort.h"
+#include "libavfilter/window_func.h"
 
 static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int band,
                            float *bits, float lambda)
diff --git a/libavcodec/opusenc_psy.h b/libavcodec/opusenc_psy.h
index 0a7cdb6f2c..67e96b2fa5 100644
--- a/libavcodec/opusenc_psy.h
+++ b/libavcodec/opusenc_psy.h
@@ -26,8 +26,8 @@
 #include "libavutil/mem_internal.h"
 
 #include "opusenc.h"
+#include "opus_celt.h"
 #include "opusenc_utils.h"
-#include "libavfilter/window_func.h"
 
 /* Each step is 2.5ms */
 typedef struct OpusPsyStep {
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 9/9] avcodec/opus: Move Silk declarations to a new header, opus_silk.h
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
                   ` (6 preceding siblings ...)
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 8/9] avcodec/opus: Move defines to better places Andreas Rheinhardt
@ 2022-10-03 22:45 ` Andreas Rheinhardt
  2022-10-04 11:09 ` [FFmpeg-devel] [PATCH 10/10] avcodec/opus, opus_celt: Fix header descriptions Andreas Rheinhardt
  2022-10-04 18:30 ` [FFmpeg-devel] [PATCH v2] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
  9 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-03 22:45 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opus.h          | 21 -----------------
 libavcodec/opus_silk.c     |  2 ++
 libavcodec/opus_silk.h     | 48 ++++++++++++++++++++++++++++++++++++++
 libavcodec/opusdec.c       |  2 ++
 libavcodec/opusenc_utils.h |  3 +++
 5 files changed, 55 insertions(+), 21 deletions(-)
 create mode 100644 libavcodec/opus_silk.h

diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 283d9d9f7a..80d685d47c 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -25,16 +25,10 @@
 
 #include <stdint.h>
 
-#include "avcodec.h"
-#include "opus_rc.h"
-
 #define MAX_FRAME_SIZE               1275
 #define MAX_FRAMES                   48
 #define MAX_PACKET_DUR               5760
 
-#define SILK_HISTORY                 322
-#define SILK_MAX_LPC                 16
-
 #define OPUS_TS_HEADER     0x7FE0        // 0x3ff (11 bits)
 #define OPUS_TS_MASK       0xFFE0        // top 11 bits
 
@@ -62,19 +56,4 @@ enum OpusBandwidth {
     OPUS_BANDWITH_NB
 };
 
-typedef struct SilkContext SilkContext;
-
-int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels);
-void ff_silk_free(SilkContext **ps);
-void ff_silk_flush(SilkContext *s);
-
-/**
- * Decode the LP layer of one Opus frame (which may correspond to several SILK
- * frames).
- */
-int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc,
-                              float *output[2],
-                              enum OpusBandwidth bandwidth, int coded_channels,
-                              int duration_ms);
-
 #endif /* AVCODEC_OPUS_H */
diff --git a/libavcodec/opus_silk.c b/libavcodec/opus_silk.c
index fd1e83659c..cf8b16acff 100644
--- a/libavcodec/opus_silk.c
+++ b/libavcodec/opus_silk.c
@@ -28,6 +28,8 @@
 
 #include "mathops.h"
 #include "opus.h"
+#include "opus_rc.h"
+#include "opus_silk.h"
 #include "opustab.h"
 
 #define ROUND_MULL(a,b,s) (((MUL64(a, b) >> ((s) - 1)) + 1) >> 1)
diff --git a/libavcodec/opus_silk.h b/libavcodec/opus_silk.h
new file mode 100644
index 0000000000..6552c166a4
--- /dev/null
+++ b/libavcodec/opus_silk.h
@@ -0,0 +1,48 @@
+/*
+ * Opus Silk functions/definitions
+ * Copyright (c) 2012 Andrew D'Addesio
+ * Copyright (c) 2013-2014 Mozilla Corporation
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_OPUS_SILK_H
+#define AVCODEC_OPUS_SILK_H
+
+#include "avcodec.h"
+#include "opus.h"
+#include "opus_rc.h"
+
+#define SILK_HISTORY                 322
+#define SILK_MAX_LPC                 16
+
+typedef struct SilkContext SilkContext;
+
+int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels);
+void ff_silk_free(SilkContext **ps);
+void ff_silk_flush(SilkContext *s);
+
+/**
+ * Decode the LP layer of one Opus frame (which may correspond to several SILK
+ * frames).
+ */
+int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc,
+                              float *output[2],
+                              enum OpusBandwidth bandwidth, int coded_channels,
+                              int duration_ms);
+
+#endif /* AVCODEC_OPUS_SILK_H */
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index e26ca0b2c3..c5f06e0600 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -53,6 +53,8 @@
 #include "opustab.h"
 #include "opus_celt.h"
 #include "opus_parse.h"
+#include "opus_rc.h"
+#include "opus_silk.h"
 
 static const uint16_t silk_frame_duration_ms[16] = {
     10, 20, 40, 60,
diff --git a/libavcodec/opusenc_utils.h b/libavcodec/opusenc_utils.h
index be82e13767..c76295979a 100644
--- a/libavcodec/opusenc_utils.h
+++ b/libavcodec/opusenc_utils.h
@@ -22,6 +22,9 @@
 #ifndef AVCODEC_OPUSENC_UTILS_H
 #define AVCODEC_OPUSENC_UTILS_H
 
+#include <math.h>
+#include <string.h>
+
 #include "opus.h"
 
 typedef struct FFBesselFilter {
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH 10/10] avcodec/opus, opus_celt: Fix header descriptions
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
                   ` (7 preceding siblings ...)
  2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 9/9] avcodec/opus: Move Silk declarations to a new header, opus_silk.h Andreas Rheinhardt
@ 2022-10-04 11:09 ` Andreas Rheinhardt
  2022-10-04 21:40   ` Lynne
  2022-10-04 18:30 ` [FFmpeg-devel] [PATCH v2] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
  9 siblings, 1 reply; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-04 11:09 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/opus.h      | 2 +-
 libavcodec/opus_celt.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 80d685d47c..4d061cf5f8 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -1,5 +1,5 @@
 /*
- * Opus decoder/demuxer common functions
+ * Opus common header
  * Copyright (c) 2012 Andrew D'Addesio
  * Copyright (c) 2013-2014 Mozilla Corporation
  *
diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
index 3aa96244e1..2dbb79be6c 100644
--- a/libavcodec/opus_celt.h
+++ b/libavcodec/opus_celt.h
@@ -1,5 +1,5 @@
 /*
- * Opus decoder/demuxer common functions
+ * Opus decoder/encoder CELT functions
  * Copyright (c) 2012 Andrew D'Addesio
  * Copyright (c) 2013-2014 Mozilla Corporation
  * Copyright (c) 2016 Rostislav Pehlivanov <atomnuker@gmail.com>
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window
  2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window Andreas Rheinhardt
@ 2022-10-04 12:14   ` Michael Niedermayer
  2022-10-04 12:18     ` Andreas Rheinhardt
  0 siblings, 1 reply; 16+ messages in thread
From: Michael Niedermayer @ 2022-10-04 12:14 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 2330 bytes --]

On Tue, Oct 04, 2022 at 12:44:58AM +0200, Andreas Rheinhardt wrote:
> Currently, it is accessed via a pointer (ff_celt_window)
> exported from opustab.h which points inside a static array
> (ff_celt_window_padded) in opustab.h. Instead export
> ff_celt_window_padded directly and make opustab.h
> a static const pointer pointing inside ff_celt_window_padded.
> Also mark all the declarations in opustab.h as hidden,
> so that the compiler knows that ff_celt_window has a fixed
> offset from the code even when compiling position-independent
> code.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/opusenc.c | 4 ++--
>  libavcodec/opustab.c | 4 +---
>  libavcodec/opustab.h | 8 +++++++-
>  3 files changed, 10 insertions(+), 6 deletions(-)
[...]
> diff --git a/libavcodec/opustab.h b/libavcodec/opustab.h
> index 16011db758..9c9f1b9d98 100644
> --- a/libavcodec/opustab.h
> +++ b/libavcodec/opustab.h
> @@ -25,6 +25,9 @@
>  
>  #include <stdint.h>
>  
> +#include "libavutil/attributes_internal.h"
> +
> +FF_VISIBILITY_PUSH_HIDDEN
>  extern const uint8_t  ff_celt_band_end[];
>  
>  extern const uint8_t  ff_opus_default_coupled_streams[];

didnt investigate but this breaks mingw64 here

CC	libavcodec/opus.o
In file included from src/libavcodec/opus.c:34:0:
src/libavcodec/opustab.h:31:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
 extern const uint8_t  ff_celt_band_end[];
 ^~~~~~
In file included from src/libavcodec/opus.c:35:0:
src/libavcodec/internal.h:52:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’
 typedef struct AVCodecInternal {
 ^~~~~~~
src/libavcodec/opus.c: In function ‘ff_opus_parse_extradata’:
src/libavcodec/opus.c:333:24: error: ‘struct AVCodecInternal’ has no member named ‘skip_samples’
         avctx->internal->skip_samples = avctx->delay;
                        ^~
src/ffbuild/common.mak:81: recipe for target 'libavcodec/opus.o' failed
make: *** [libavcodec/opus.o] Error 1



[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window
  2022-10-04 12:14   ` Michael Niedermayer
@ 2022-10-04 12:18     ` Andreas Rheinhardt
  0 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-04 12:18 UTC (permalink / raw)
  To: ffmpeg-devel

Michael Niedermayer:
> On Tue, Oct 04, 2022 at 12:44:58AM +0200, Andreas Rheinhardt wrote:
>> Currently, it is accessed via a pointer (ff_celt_window)
>> exported from opustab.h which points inside a static array
>> (ff_celt_window_padded) in opustab.h. Instead export
>> ff_celt_window_padded directly and make opustab.h
>> a static const pointer pointing inside ff_celt_window_padded.
>> Also mark all the declarations in opustab.h as hidden,
>> so that the compiler knows that ff_celt_window has a fixed
>> offset from the code even when compiling position-independent
>> code.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/opusenc.c | 4 ++--
>>  libavcodec/opustab.c | 4 +---
>>  libavcodec/opustab.h | 8 +++++++-
>>  3 files changed, 10 insertions(+), 6 deletions(-)
> [...]
>> diff --git a/libavcodec/opustab.h b/libavcodec/opustab.h
>> index 16011db758..9c9f1b9d98 100644
>> --- a/libavcodec/opustab.h
>> +++ b/libavcodec/opustab.h
>> @@ -25,6 +25,9 @@
>>  
>>  #include <stdint.h>
>>  
>> +#include "libavutil/attributes_internal.h"
>> +
>> +FF_VISIBILITY_PUSH_HIDDEN
>>  extern const uint8_t  ff_celt_band_end[];
>>  
>>  extern const uint8_t  ff_opus_default_coupled_streams[];
> 
> didnt investigate but this breaks mingw64 here
> 
> CC	libavcodec/opus.o
> In file included from src/libavcodec/opus.c:34:0:
> src/libavcodec/opustab.h:31:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
>  extern const uint8_t  ff_celt_band_end[];
>  ^~~~~~
> In file included from src/libavcodec/opus.c:35:0:
> src/libavcodec/internal.h:52:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’
>  typedef struct AVCodecInternal {
>  ^~~~~~~
> src/libavcodec/opus.c: In function ‘ff_opus_parse_extradata’:
> src/libavcodec/opus.c:333:24: error: ‘struct AVCodecInternal’ has no member named ‘skip_samples’
>          avctx->internal->skip_samples = avctx->delay;
>                         ^~
> src/ffbuild/common.mak:81: recipe for target 'libavcodec/opus.o' failed
> make: *** [libavcodec/opus.o] Error 1
> 
> 

I already see the problem: An earlier version used
FF_VISIBILITY_START/END_HIDDEN, then I decided to switch to
FF_VISIBILITY_PUSH/POP_HIDDEN, but I only modified the part where hidden
is supported; in the other case, FF_VISIBILITY_START/END_HIDDEN is still
defined.
Thanks for testing.

- Andreas

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [FFmpeg-devel] [PATCH v2] avutil/attributes_internal: Add visibility pragma
  2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
                   ` (8 preceding siblings ...)
  2022-10-04 11:09 ` [FFmpeg-devel] [PATCH 10/10] avcodec/opus, opus_celt: Fix header descriptions Andreas Rheinhardt
@ 2022-10-04 18:30 ` Andreas Rheinhardt
  2022-10-09 16:03   ` Andreas Rheinhardt
  9 siblings, 1 reply; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-04 18:30 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

GCC 4.0 not only added a visibility attribute, but also
a pragma to set it for a whole region of code.*
This commit exposes this via macros.

*: See https://gcc.gnu.org/gcc-4.0/changes.html

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/attributes_internal.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavutil/attributes_internal.h b/libavutil/attributes_internal.h
index 9d3d10b63e..3df1ee6af3 100644
--- a/libavutil/attributes_internal.h
+++ b/libavutil/attributes_internal.h
@@ -23,8 +23,12 @@
 
 #if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) || defined(__MACH__))
 #    define attribute_visibility_hidden __attribute__((visibility("hidden")))
+#    define FF_VISIBILITY_PUSH_HIDDEN   _Pragma("GCC visibility push(hidden)")
+#    define FF_VISIBILITY_POP_HIDDEN    _Pragma("GCC visibility pop")
 #else
 #    define attribute_visibility_hidden
+#    define FF_VISIBILITY_PUSH_HIDDEN
+#    define FF_VISIBILITY_POP_HIDDEN
 #endif
 
 #endif /* AVUTIL_ATTRIBUTES_INTERNAL_H */
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [FFmpeg-devel] [PATCH 10/10] avcodec/opus, opus_celt: Fix header descriptions
  2022-10-04 11:09 ` [FFmpeg-devel] [PATCH 10/10] avcodec/opus, opus_celt: Fix header descriptions Andreas Rheinhardt
@ 2022-10-04 21:40   ` Lynne
  2022-10-04 22:39     ` Andreas Rheinhardt
  0 siblings, 1 reply; 16+ messages in thread
From: Lynne @ 2022-10-04 21:40 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Oct 4, 2022, 13:09 by andreas.rheinhardt@outlook.com:

> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/opus.h      | 2 +-
>  libavcodec/opus_celt.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/opus.h b/libavcodec/opus.h
> index 80d685d47c..4d061cf5f8 100644
> --- a/libavcodec/opus.h
> +++ b/libavcodec/opus.h
> @@ -1,5 +1,5 @@
>  /*
> - * Opus decoder/demuxer common functions
> + * Opus common header
>  * Copyright (c) 2012 Andrew D'Addesio
>  * Copyright (c) 2013-2014 Mozilla Corporation
>  *
> diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
> index 3aa96244e1..2dbb79be6c 100644
> --- a/libavcodec/opus_celt.h
> +++ b/libavcodec/opus_celt.h
> @@ -1,5 +1,5 @@
>  /*
> - * Opus decoder/demuxer common functions
> + * Opus decoder/encoder CELT functions
>  * Copyright (c) 2012 Andrew D'Addesio
>  * Copyright (c) 2013-2014 Mozilla Corporation
>  * Copyright (c) 2016 Rostislav Pehlivanov <> atomnuker@gmail.com> >
>

Could you merge this with patch 7/9?

Patchset looks good to me (as well as your more recent patch
for the visibility pragma).
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [FFmpeg-devel] [PATCH 10/10] avcodec/opus, opus_celt: Fix header descriptions
  2022-10-04 21:40   ` Lynne
@ 2022-10-04 22:39     ` Andreas Rheinhardt
  0 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-04 22:39 UTC (permalink / raw)
  To: ffmpeg-devel

Lynne:
> Oct 4, 2022, 13:09 by andreas.rheinhardt@outlook.com:
> 
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/opus.h      | 2 +-
>>  libavcodec/opus_celt.h | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/opus.h b/libavcodec/opus.h
>> index 80d685d47c..4d061cf5f8 100644
>> --- a/libavcodec/opus.h
>> +++ b/libavcodec/opus.h
>> @@ -1,5 +1,5 @@
>>  /*
>> - * Opus decoder/demuxer common functions
>> + * Opus common header
>>  * Copyright (c) 2012 Andrew D'Addesio
>>  * Copyright (c) 2013-2014 Mozilla Corporation
>>  *
>> diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
>> index 3aa96244e1..2dbb79be6c 100644
>> --- a/libavcodec/opus_celt.h
>> +++ b/libavcodec/opus_celt.h
>> @@ -1,5 +1,5 @@
>>  /*
>> - * Opus decoder/demuxer common functions
>> + * Opus decoder/encoder CELT functions
>>  * Copyright (c) 2012 Andrew D'Addesio
>>  * Copyright (c) 2013-2014 Mozilla Corporation
>>  * Copyright (c) 2016 Rostislav Pehlivanov <> atomnuker@gmail.com> >
>>
> 
> Could you merge this with patch 7/9?
> 
> Patchset looks good to me (as well as your more recent patch
> for the visibility pragma).

Will merge the opus.h change into 4/9 and the opus_celt.h patch into 7/9
and apply 3-9; but I will wait with the visibility patch a bit more to
give others more time to comment.

- Andreas

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] avutil/attributes_internal: Add visibility pragma
  2022-10-04 18:30 ` [FFmpeg-devel] [PATCH v2] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
@ 2022-10-09 16:03   ` Andreas Rheinhardt
  0 siblings, 0 replies; 16+ messages in thread
From: Andreas Rheinhardt @ 2022-10-09 16:03 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> GCC 4.0 not only added a visibility attribute, but also
> a pragma to set it for a whole region of code.*
> This commit exposes this via macros.
> 
> *: See https://gcc.gnu.org/gcc-4.0/changes.html
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavutil/attributes_internal.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavutil/attributes_internal.h b/libavutil/attributes_internal.h
> index 9d3d10b63e..3df1ee6af3 100644
> --- a/libavutil/attributes_internal.h
> +++ b/libavutil/attributes_internal.h
> @@ -23,8 +23,12 @@
>  
>  #if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) || defined(__MACH__))
>  #    define attribute_visibility_hidden __attribute__((visibility("hidden")))
> +#    define FF_VISIBILITY_PUSH_HIDDEN   _Pragma("GCC visibility push(hidden)")
> +#    define FF_VISIBILITY_POP_HIDDEN    _Pragma("GCC visibility pop")
>  #else
>  #    define attribute_visibility_hidden
> +#    define FF_VISIBILITY_PUSH_HIDDEN
> +#    define FF_VISIBILITY_POP_HIDDEN
>  #endif
>  
>  #endif /* AVUTIL_ATTRIBUTES_INTERNAL_H */

Will apply this patch and the opus patch dependening upon it tomorrow
unless there are objections.

- Andreas

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-10-09 16:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-03 22:32 [FFmpeg-devel] [PATCH 1/9] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 2/9] avcodec/opustab: Avoid indirection to access ff_celt_window Andreas Rheinhardt
2022-10-04 12:14   ` Michael Niedermayer
2022-10-04 12:18     ` Andreas Rheinhardt
2022-10-03 22:44 ` [FFmpeg-devel] [PATCH 3/9] avcodec/opus: Move OpusStreamContext to its only user Andreas Rheinhardt
2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 4/9] avcodec/opus: Move stuff shared by decoder and parser to a new file Andreas Rheinhardt
2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 5/9] avcodec/opus_celt: Break cyclic inlusion of opus_celt.h<->opus_pvq.h Andreas Rheinhardt
2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 6/9] avcodec/opus_celt, opus_pvq: Move CeltPVQ typedef to opus_pvq.h Andreas Rheinhardt
2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 7/9] avcodec/opus: Move remaining celt declarations to opus_celt.h Andreas Rheinhardt
2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 8/9] avcodec/opus: Move defines to better places Andreas Rheinhardt
2022-10-03 22:45 ` [FFmpeg-devel] [PATCH 9/9] avcodec/opus: Move Silk declarations to a new header, opus_silk.h Andreas Rheinhardt
2022-10-04 11:09 ` [FFmpeg-devel] [PATCH 10/10] avcodec/opus, opus_celt: Fix header descriptions Andreas Rheinhardt
2022-10-04 21:40   ` Lynne
2022-10-04 22:39     ` Andreas Rheinhardt
2022-10-04 18:30 ` [FFmpeg-devel] [PATCH v2] avutil/attributes_internal: Add visibility pragma Andreas Rheinhardt
2022-10-09 16:03   ` Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git