Merge commit '14e558024642638085ae2bbeffc6087612e6a3f9'
authorHendrik Leppkes <h.leppkes@gmail.com>
Sun, 2 Aug 2015 10:40:53 +0000 (12:40 +0200)
committerHendrik Leppkes <h.leppkes@gmail.com>
Sun, 2 Aug 2015 10:40:53 +0000 (12:40 +0200)
* commit '14e558024642638085ae2bbeffc6087612e6a3f9':
  opusdec: properly handle mismatching configurations in multichannel streams

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavcodec/opus.h
libavcodec/opusdec.c

Simple merge
@@@ -370,11 -374,15 +371,15 @@@ static int opus_decode_subpacket(OpusSt
      int flush_needed   = 0;
      int i, j, ret;
  
+     s->out[0]   = out[0];
+     s->out[1]   = out[1];
+     s->out_size = out_size;
      /* check if we need to flush the resampler */
 -    if (avresample_is_open(s->avr)) {
 +    if (swr_is_initialized(s->swr)) {
          if (buf) {
              int64_t cur_samplerate;
 -            av_opt_get_int(s->avr, "in_sample_rate", 0, &cur_samplerate);
 +            av_opt_get_int(s->swr, "in_sample_rate", 0, &cur_samplerate);
              flush_needed = (s->packet.mode == OPUS_MODE_CELT) || (cur_samplerate != s->silk_samplerate);
          } else {
              flush_needed = !!s->delayed_samples;
@@@ -447,15 -455,14 +452,17 @@@ static int opus_decode_packet(AVCodecCo
      const uint8_t *buf  = avpkt->data;
      int buf_size        = avpkt->size;
      int coded_samples   = 0;
-     int decoded_samples = 0;
-     int i, ret;
+     int decoded_samples = INT_MAX;
      int delayed_samples = 0;
+     int i, ret;
  
+     /* calculate the number of delayed samples */
      for (i = 0; i < c->nb_streams; i++) {
-         delayed_samples = FFMAX(delayed_samples, s->delayed_samples);
 +        OpusStreamContext *s = &c->streams[i];
 +        s->out[0] =
 +        s->out[1] = NULL;
 -                                c->streams[i].delayed_samples + av_audio_fifo_size(c->sync_buffers[i]));
+         delayed_samples = FFMAX(delayed_samples,
++                                s->delayed_samples + av_audio_fifo_size(c->sync_buffers[i]));
      }
  
      /* decode the header of the first sub-packet to find out the sample count */
  
      /* setup the data buffers */
      ret = ff_get_buffer(avctx, frame, 0);
 -    if (ret < 0) {
 -        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 +    if (ret < 0)
          return ret;
 -    }
      frame->nb_samples = 0;
  
+     memset(c->out, 0, c->nb_streams * 2 * sizeof(*c->out));
      for (i = 0; i < avctx->channels; i++) {
          ChannelMap *map = &c->channel_maps[i];
          if (!map->copy)
@@@ -564,8 -613,10 +611,10 @@@ static av_cold void opus_decode_flush(A
  
          if (s->celt_delay)
              av_audio_fifo_drain(s->celt_delay, av_audio_fifo_size(s->celt_delay));
 -        avresample_close(s->avr);
 +        swr_close(s->swr);
  
+         av_audio_fifo_drain(c->sync_buffers[i], av_audio_fifo_size(c->sync_buffers[i]));
          ff_silk_flush(s->silk);
          ff_celt_flush(s->celt);
      }