#10732: avcodec_flush_buffers() not resetting E-AC-3 decoder
-------------------------------------+-------------------------------------
             Reporter:  Peter        |                    Owner:  (none)
  Krefting                           |
                 Type:  defect       |                   Status:  new
             Priority:  minor        |                Component:
                                     |  undetermined
              Version:  6.1          |               Resolution:
             Keywords:  eac3         |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
Comment (by James):

 Does the following work for you?
 There may have been a reason the ac3 decoder did not include a flush()
 method, but perhaps it was simply forgotten.

 {{{
 diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
 index 3cc20f32a9..3490e02c89 100644
 --- a/libavcodec/ac3dec.c
 +++ b/libavcodec/ac3dec.c
 @@ -252,6 +252,17 @@ 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 + offsetof(AC3DecodeContext, 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 d94070bc0c..60d3472ca6 100644
 --- a/libavcodec/ac3dec_float.c
 +++ b/libavcodec/ac3dec_float.c
 @@ -87,6 +87,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 |
 }}}
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/10732#comment:5>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
_______________________________________________
FFmpeg-trac mailing list
FFmpeg-trac@avcodec.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-trac

To unsubscribe, visit link above, or email
ffmpeg-trac-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to