Browse code

Fix an issue uncovered by commit 20623:

The init functions of mpc7 and mpc8 check whether the vlc has been
initialized already and return early if this is the case (eg by calling
init a second time).
But avctx->sample_fmt and channel_layout is set after the vlc initialization,
causing it not to be set on the second call of init.

Move all manipulations of avctx before the initialization of the vlc,
so that it is always set.

Originally committed as revision 20668 to svn://svn.ffmpeg.org/ffmpeg/trunk

Attila Kinali authored on 2009/11/30 19:25:20
Showing 2 changed files
... ...
@@ -85,6 +85,9 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
85 85
             c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands);
86 86
     c->frames_to_skip = 0;
87 87
 
88
+    avctx->sample_fmt = SAMPLE_FMT_S16;
89
+    avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
90
+
88 91
     if(vlc_initialized) return 0;
89 92
     av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
90 93
     scfi_vlc.table = scfi_table;
... ...
@@ -124,8 +127,6 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
124 124
         }
125 125
     }
126 126
     vlc_initialized = 1;
127
-    avctx->sample_fmt = SAMPLE_FMT_S16;
128
-    avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
129 127
     return 0;
130 128
 }
131 129
 
... ...
@@ -129,6 +129,9 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
129 129
     c->MSS = get_bits1(&gb);
130 130
     c->frames = 1 << (get_bits(&gb, 3) * 2);
131 131
 
132
+    avctx->sample_fmt = SAMPLE_FMT_S16;
133
+    avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
134
+
132 135
     if(vlc_initialized) return 0;
133 136
     av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
134 137
 
... ...
@@ -219,8 +222,6 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
219 219
                  &mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
220 220
     }
221 221
     vlc_initialized = 1;
222
-    avctx->sample_fmt = SAMPLE_FMT_S16;
223
-    avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
224 222
     return 0;
225 223
 }
226 224