]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dca.c
Mask bits of reference indexes properly to avoid negative numbers entangling
[ffmpeg] / libavcodec / dca.c
index 14aa9816a3095130bfa6bf92b7f997c23c53696f..8cca01a020fef22edee64b533e46fee05cbb18d8 100644 (file)
@@ -178,7 +178,7 @@ typedef struct {
     DSPContext dsp;
 } DCAContext;
 
-static void dca_init_vlcs(void)
+static av_cold void dca_init_vlcs(void)
 {
     static int vlcs_initialized = 0;
     int i, j;
@@ -1173,7 +1173,14 @@ static int dca_decode_frame(AVCodecContext * avctx,
         s->output = DCA_STEREO;
     }
 
-    avctx->channels = channels;
+    /* There is nothing that prevents a dts frame to change channel configuration
+       but FFmpeg doesn't support that so only set the channels if it is previously
+       unset. Ideally during the first probe for channels the crc should be checked
+       and only set avctx->channels when the crc is ok. Right now the decoder could
+       set the channels based on a broken first frame.*/
+    if (!avctx->channels)
+        avctx->channels = channels;
+
     if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels)
         return -1;
     *data_size = 0;
@@ -1200,7 +1207,7 @@ static int dca_decode_frame(AVCodecContext * avctx,
  * @param s     pointer to the DCAContext
  */
 
-static void pre_calc_cosmod(DCAContext * s)
+static av_cold void pre_calc_cosmod(DCAContext * s)
 {
     int i, j, k;
     static int cosmod_initialized = 0;
@@ -1230,7 +1237,7 @@ static void pre_calc_cosmod(DCAContext * s)
  * @param avctx     pointer to the AVCodecContext
  */
 
-static int dca_decode_init(AVCodecContext * avctx)
+static av_cold int dca_decode_init(AVCodecContext * avctx)
 {
     DCAContext *s = avctx->priv_data;
 
@@ -1246,6 +1253,7 @@ static int dca_decode_init(AVCodecContext * avctx)
         avctx->channels = avctx->request_channels;
     }
 
+    avctx->sample_fmt = SAMPLE_FMT_S16;
     return 0;
 }
 
@@ -1257,4 +1265,5 @@ AVCodec dca_decoder = {
     .priv_data_size = sizeof(DCAContext),
     .init = dca_decode_init,
     .decode = dca_decode_frame,
+    .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
 };