* [FFmpeg-devel] [PATCH] avcodec/ac3dec: add a flush callback for the eac3 decoder
@ 2025-02-06 16:05 James Almer
2025-02-06 19:17 ` [FFmpeg-devel] [PATCH v2] avcodec/ac3dec: add a flush callback for the ac3 and eac3 decoders James Almer
0 siblings, 1 reply; 2+ messages in thread
From: James Almer @ 2025-02-06 16:05 UTC (permalink / raw)
To: ffmpeg-devel
Fixes ticket #10732
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/ac3dec.c | 10 ++++++++++
libavcodec/ac3dec.h | 38 ++++++++++++++++++++++----------------
libavcodec/ac3dec_fixed.c | 1 +
libavcodec/ac3dec_float.c | 1 +
4 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index ff8cbfb0b4..2cf82abc19 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -252,6 +252,16 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
return 0;
}
+static av_cold void ac3_decode_flush(AVCodecContext *avctx)
+{
+ AC3DecodeContext *s = avctx->priv_data;
+
+ memset(&s->frame_type, 0, sizeof(*s) - offsetof(AC3DecodeContext, frame_type));
+
+ AC3_RENAME(ff_kbd_window_init)(s->window, 5.0, 256);
+ av_lfg_init(&s->dith_state, 0);
+}
+
/**
* Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream.
* GetBitContext within AC3DecodeContext must point to
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index 98de7b5abf..cfaad446ab 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -75,8 +75,29 @@ typedef struct AC3DecodeContext {
AVCodecContext *avctx; ///< parent context
GetBitContext gbc; ///< bitstream reader
+ AVTXContext *tx_128, *tx_256;
+ av_tx_fn tx_fn_128, tx_fn_256;
+
+///@name Optimization
+ BswapDSPContext bdsp;
+#if USE_FIXED
+ AVFixedDSPContext *fdsp;
+#else
+ AVFloatDSPContext *fdsp;
+#endif
+ AC3DSPContext ac3dsp;
+ FmtConvertContext fmt_conv; ///< optimized conversion functions
+///@}
+
+ INTFLOAT *xcfptr[AC3_MAX_CHANNELS];
+ INTFLOAT *dlyptr[AC3_MAX_CHANNELS];
+
+ AVChannelLayout downmix_layout;
+
+// Start of flushable fields
///@name Bit stream information
///@{
+ // frame_type must be first
int frame_type; ///< frame type (strmtyp)
int substreamid; ///< substream identification
int superframe_size; ///< current superframe size, in bytes
@@ -222,24 +243,9 @@ typedef struct AC3DecodeContext {
///@name IMDCT
int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags (blksw)
- AVTXContext *tx_128, *tx_256;
- av_tx_fn tx_fn_128, tx_fn_256;
-///@}
-
-///@name Optimization
- BswapDSPContext bdsp;
-#if USE_FIXED
- AVFixedDSPContext *fdsp;
-#else
- AVFloatDSPContext *fdsp;
-#endif
- AC3DSPContext ac3dsp;
- FmtConvertContext fmt_conv; ///< optimized conversion functions
///@}
SHORTFLOAT *outptr[AC3_MAX_CHANNELS];
- INTFLOAT *xcfptr[AC3_MAX_CHANNELS];
- INTFLOAT *dlyptr[AC3_MAX_CHANNELS];
///@name Aligned arrays
DECLARE_ALIGNED(16, int, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< fixed-point transform coefficients
@@ -252,7 +258,7 @@ typedef struct AC3DecodeContext {
DECLARE_ALIGNED(32, SHORTFLOAT, output_buffer)[EAC3_MAX_CHANNELS][AC3_BLOCK_SIZE * 6]; ///< final output buffer
///@}
- AVChannelLayout downmix_layout;
+// End of flushable fields
} AC3DecodeContext;
/**
diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c
index e0db9b2260..e284140e74 100644
--- a/libavcodec/ac3dec_fixed.c
+++ b/libavcodec/ac3dec_fixed.c
@@ -181,6 +181,7 @@ const FFCodec ff_ac3_fixed_decoder = {
.p.priv_class = &ac3_decoder_class,
.priv_data_size = sizeof (AC3DecodeContext),
.init = ac3_decode_init,
+ .flush = ac3_decode_flush,
.close = ac3_decode_end,
FF_CODEC_DECODE_CB(ac3_decode_frame),
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c
index 53d9d472c4..aed34ec2e9 100644
--- a/libavcodec/ac3dec_float.c
+++ b/libavcodec/ac3dec_float.c
@@ -88,6 +88,7 @@ const FFCodec ff_eac3_decoder = {
.p.id = AV_CODEC_ID_EAC3,
.priv_data_size = sizeof (AC3DecodeContext),
.init = ac3_decode_init,
+ .flush = ac3_decode_flush,
.close = ac3_decode_end,
FF_CODEC_DECODE_CB(ac3_decode_frame),
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
--
2.48.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] 2+ messages in thread
* [FFmpeg-devel] [PATCH v2] avcodec/ac3dec: add a flush callback for the ac3 and eac3 decoders
2025-02-06 16:05 [FFmpeg-devel] [PATCH] avcodec/ac3dec: add a flush callback for the eac3 decoder James Almer
@ 2025-02-06 19:17 ` James Almer
0 siblings, 0 replies; 2+ messages in thread
From: James Almer @ 2025-02-06 19:17 UTC (permalink / raw)
To: ffmpeg-devel
Fixes ticket #10732
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/ac3dec.c | 10 ++++++++++
libavcodec/ac3dec.h | 40 ++++++++++++++++++++++-----------------
libavcodec/ac3dec_fixed.c | 1 +
libavcodec/ac3dec_float.c | 2 ++
4 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index ff8cbfb0b4..2cf82abc19 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -252,6 +252,16 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
return 0;
}
+static av_cold void ac3_decode_flush(AVCodecContext *avctx)
+{
+ AC3DecodeContext *s = avctx->priv_data;
+
+ memset(&s->frame_type, 0, sizeof(*s) - offsetof(AC3DecodeContext, frame_type));
+
+ AC3_RENAME(ff_kbd_window_init)(s->window, 5.0, 256);
+ av_lfg_init(&s->dith_state, 0);
+}
+
/**
* Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream.
* GetBitContext within AC3DecodeContext must point to
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index 98de7b5abf..cc6d1a118e 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -75,8 +75,30 @@ typedef struct AC3DecodeContext {
AVCodecContext *avctx; ///< parent context
GetBitContext gbc; ///< bitstream reader
+ AVTXContext *tx_128, *tx_256;
+ av_tx_fn tx_fn_128, tx_fn_256;
+
+///@name Optimization
+ BswapDSPContext bdsp;
+#if USE_FIXED
+ AVFixedDSPContext *fdsp;
+#else
+ AVFloatDSPContext *fdsp;
+#endif
+ AC3DSPContext ac3dsp;
+ FmtConvertContext fmt_conv; ///< optimized conversion functions
+///@}
+
+ INTFLOAT *xcfptr[AC3_MAX_CHANNELS];
+ INTFLOAT *dlyptr[AC3_MAX_CHANNELS];
+
+ AVChannelLayout downmix_layout;
+ SHORTFLOAT *downmix_coeffs[2]; ///< stereo downmix coefficients
+
+// Start of flushable fields
///@name Bit stream information
///@{
+ // frame_type must be first
int frame_type; ///< frame type (strmtyp)
int substreamid; ///< substream identification
int superframe_size; ///< current superframe size, in bytes
@@ -164,7 +186,6 @@ typedef struct AC3DecodeContext {
int fbw_channels; ///< number of full-bandwidth channels
int channels; ///< number of total channels
int lfe_ch; ///< index of LFE channel
- SHORTFLOAT *downmix_coeffs[2]; ///< stereo downmix coefficients
int downmixed; ///< indicates if coeffs are currently downmixed
int output_mode; ///< output channel configuration
int prev_output_mode; ///< output channel configuration for previous frame
@@ -222,24 +243,9 @@ typedef struct AC3DecodeContext {
///@name IMDCT
int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags (blksw)
- AVTXContext *tx_128, *tx_256;
- av_tx_fn tx_fn_128, tx_fn_256;
-///@}
-
-///@name Optimization
- BswapDSPContext bdsp;
-#if USE_FIXED
- AVFixedDSPContext *fdsp;
-#else
- AVFloatDSPContext *fdsp;
-#endif
- AC3DSPContext ac3dsp;
- FmtConvertContext fmt_conv; ///< optimized conversion functions
///@}
SHORTFLOAT *outptr[AC3_MAX_CHANNELS];
- INTFLOAT *xcfptr[AC3_MAX_CHANNELS];
- INTFLOAT *dlyptr[AC3_MAX_CHANNELS];
///@name Aligned arrays
DECLARE_ALIGNED(16, int, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< fixed-point transform coefficients
@@ -252,7 +258,7 @@ typedef struct AC3DecodeContext {
DECLARE_ALIGNED(32, SHORTFLOAT, output_buffer)[EAC3_MAX_CHANNELS][AC3_BLOCK_SIZE * 6]; ///< final output buffer
///@}
- AVChannelLayout downmix_layout;
+// End of flushable fields
} AC3DecodeContext;
/**
diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c
index e0db9b2260..e284140e74 100644
--- a/libavcodec/ac3dec_fixed.c
+++ b/libavcodec/ac3dec_fixed.c
@@ -181,6 +181,7 @@ const FFCodec ff_ac3_fixed_decoder = {
.p.priv_class = &ac3_decoder_class,
.priv_data_size = sizeof (AC3DecodeContext),
.init = ac3_decode_init,
+ .flush = ac3_decode_flush,
.close = ac3_decode_end,
FF_CODEC_DECODE_CB(ac3_decode_frame),
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c
index 53d9d472c4..31f5590729 100644
--- a/libavcodec/ac3dec_float.c
+++ b/libavcodec/ac3dec_float.c
@@ -70,6 +70,7 @@ const FFCodec ff_ac3_decoder = {
.p.id = AV_CODEC_ID_AC3,
.priv_data_size = sizeof (AC3DecodeContext),
.init = ac3_decode_init,
+ .flush = ac3_decode_flush,
.close = ac3_decode_end,
FF_CODEC_DECODE_CB(ac3_decode_frame),
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
@@ -88,6 +89,7 @@ const FFCodec ff_eac3_decoder = {
.p.id = AV_CODEC_ID_EAC3,
.priv_data_size = sizeof (AC3DecodeContext),
.init = ac3_decode_init,
+ .flush = ac3_decode_flush,
.close = ac3_decode_end,
FF_CODEC_DECODE_CB(ac3_decode_frame),
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
--
2.48.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] 2+ messages in thread
end of thread, other threads:[~2025-02-06 19:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-06 16:05 [FFmpeg-devel] [PATCH] avcodec/ac3dec: add a flush callback for the eac3 decoder James Almer
2025-02-06 19:17 ` [FFmpeg-devel] [PATCH v2] avcodec/ac3dec: add a flush callback for the ac3 and eac3 decoders James Almer
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