r3d: do not create the audio stream until we know the sample rate
[ffmpeg.git] / libavcodec / opusdec.c
index acae6e1..92e651c 100644 (file)
@@ -567,8 +567,8 @@ static int opus_decode_packet(AVCodecContext *avctx, void *data,
         if (buffer_samples) {
             float *buf[2] = { c->out[2 * i + 0] ? c->out[2 * i + 0] : (float*)frame->extended_data[0],
                               c->out[2 * i + 1] ? c->out[2 * i + 1] : (float*)frame->extended_data[0] };
-            buf[0] += buffer_samples;
-            buf[1] += buffer_samples;
+            buf[0] += decoded_samples;
+            buf[1] += decoded_samples;
             ret = av_audio_fifo_write(c->sync_buffers[i], (void**)buf, buffer_samples);
             if (ret < 0)
                 return ret;
@@ -587,7 +587,7 @@ static int opus_decode_packet(AVCodecContext *avctx, void *data,
             memset(frame->extended_data[i], 0, frame->linesize[0]);
         }
 
-        if (c->gain_i) {
+        if (c->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));