Re: Fix problem with EAC3 audio

Petri Hintukainen <[email protected]> Wed, 15 Aug 2012 23:04:56 +0300
Newsgroups gmane.comp.video.xine.devel
Message-ID <1345061096.20782.8.camel@ph-NF310>
On ke, 2012-08-15 at 01:04 -0700, Chris Rankin wrote:
> ----- Original Message -----
> > If yes, maybe this could be fixed by re-opening audio output when parameters change ?
> 
> 
> I should mention that xine does indeed play the stream correctly if I start playback *after* the 
> point where the number of audio channels increases from 2 to 6. However, I haven't yet found any 
> *programmatic* way of getting FFMPEG to inform me that the audio config has changed. Without that, 
> how could I possibly know when I would need to reopen the audio output?

I was thinking something like this (completely untested).


- Petri

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
xine-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xine-devel
ffmpeg_codec_params_check.diff (text/x-patch, 1.8 KB)
diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c
--- a/src/combined/ffmpeg/ff_audio_decoder.c
+++ b/src/combined/ffmpeg/ff_audio_decoder.c
@@ -342,6 +347,13 @@ static void ff_audio_reset_parser(ff_aud
   }
 }
 
+static void output_close(ff_audio_decoder_t *this)
+{
+  if (this->output_open)
+    this->stream->audio_out->close (this->stream->audio_out, this->stream);
+  this->output_open = 0;
+}
+
 static int ff_audio_decode(xine_t *xine,
                            AVCodecContext *ctx,
                            AVCodecParserContext *parser_ctx,
@@ -467,6 +479,19 @@ static void ff_audio_decode_data (audio_
           return;
         }
 
+        if (this->output_open) {
+          if (this->audio_bits        != this->context->bits_per_sample ||
+              this->audio_sample_rate != this->context->sample_rate ||
+              this->audio_channels    != this->context->channels) {
+	     xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+                    _("ffmpeg_audio_dec: codec parameters changed\n"));
+            output_close(this);
+            this->audio_bits = this->context->bits_per_sample;
+            this->audio_sample_rate = this->context->sample_rate;
+            this->audio_channels = this->context->channels;
+          }
+        }
+
 	if (!this->output_open) {
 	  if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) {
 	    this->audio_bits = this->context->bits_per_sample;
@@ -605,9 +630,7 @@ static void ff_audio_dispose (audio_deco
     pthread_mutex_unlock (&ffmpeg_lock);
   }
 
-  if (this->output_open)
-    this->stream->audio_out->close (this->stream->audio_out, this->stream);
-  this->output_open = 0;
+  output_close(this);
 
   free16 (this->buf);
   free16 (this->decode_buffer);