[mythtv] Reinitialze Audio Output Device on LiveTV Channel Change

Lyall mythtv at modified.cc
Fri Dec 2 01:03:44 EST 2005


Daniel,

Thanks for the advice - I found that method last night after some futher 
digging.  Attached is an ugly hack which does the job I needed it to do.

Also thanks to Martin and Simon who replied off-thread.

To go further the following would need to be done:

1. Create a new entry in the audio setting screen for "secondary audio 
device" (does this need a new database entry or is adding a new class to 
globalsettings sufficient ?)
2. Wrap the code in if statements so it is only called if necessary
3. Maybe add some error code if the output device is not available on 
ReinitAudio()
4. Redo the patch against the current development branch (currently 
against 0.18.2 stable)

If this could prove to be useful to others I'll give it ago.

Regards,
Lyall

Daniel Kristjansson wrote:
> On Mon, 2005-11-28 at 21:59 +1100, Lyall wrote:
> 
>>Hi All,
>>However, when changing channels in livetv the audio channel is not 
>>re-opened, the new stream is simply passed down the original channel, 
>>resulting in a decoding error on the amplifier.
>>Can anyone offer some advice on how I might get the audio channel to 
>>re-initialize on a channel change ?
> 
> I can't really offer any advice, but I just wanted to encourage your
> efforts. The lack of audio reinit on channel change causes problems
> with AC3<->MP3 changes as well. There is a ReinitAudio() method in the
> NVP, you might start by checking that it is being called, and if so
> check whether the things it does are sufficient.
> 
> -- Daniel
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

-------------- next part --------------
diff -rupN mythtv/libs/libmythtv/NuppelVideoPlayer.cpp mythtv.patched/libs/libmythtv/NuppelVideoPlayer.cpp
--- mythtv/libs/libmythtv/NuppelVideoPlayer.cpp	2005-11-30 19:44:15.000000000 +1100
+++ mythtv.patched/libs/libmythtv/NuppelVideoPlayer.cpp	2005-11-30 19:44:24.000000000 +1100
@@ -479,7 +479,23 @@ void NuppelVideoPlayer::ReinitAudio(void
 {
     if (audioOutput)
     {
-        audioOutput->Reconfigure(audio_bits, audio_channels, audio_samplerate);
+	delete audioOutput;
+
+	bool setVolume = gContext->GetNumSetting("MythControlsVolume", 1);
+	VERBOSE(VB_PLAYBACK, QString("ReInit Audio"));
+	if ( gContext->GetSetting("Use_AC3") == "yes")
+	{
+		audiodevice = "ALSA:plug:iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2}";
+	}
+	else
+	{
+		audiodevice = "ALSA:default";
+	}
+
+        audioOutput = AudioOutput::OpenAudio(audiodevice, audio_bits,
+                      audio_channels, audio_samplerate,
+                      AUDIOOUTPUT_VIDEO, setVolume);
+
         audioOutput->SetStretchFactor(audio_stretchfactor);
     }
 }
@@ -1754,6 +1770,19 @@ void NuppelVideoPlayer::StartPlaying(voi
                           !gContext->GetNumSetting("PVR350InternalAudioOnly")))
     {
         bool setVolume = gContext->GetNumSetting("MythControlsVolume", 1);
+	VERBOSE(VB_AUDIO,
+			                QString("Opening audioOutput - NuppelVideoPlayer"));
+
+	VERBOSE(VB_PLAYBACK, QString("Opening Audio"));
+	if ( gContext->GetSetting("Use_AC3") == "yes")
+	{
+		audiodevice = "ALSA:plug:iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2}";
+	}
+	else
+	{
+		audiodevice = "ALSA:default";
+	}
+
         audioOutput = AudioOutput::OpenAudio(audiodevice, audio_bits,
                                              audio_channels, audio_samplerate, 
                                              AUDIOOUTPUT_VIDEO,
diff -rupN mythtv/libs/libmythtv/avformatdecoder.cpp mythtv.patched/libs/libmythtv/avformatdecoder.cpp
--- mythtv/libs/libmythtv/avformatdecoder.cpp	2005-11-30 19:44:15.000000000 +1100
+++ mythtv.patched/libs/libmythtv/avformatdecoder.cpp	2005-11-30 19:44:24.000000000 +1100
@@ -1251,7 +1251,7 @@ bool AvFormatDecoder::autoSelectAudioTra
 
     int selectedTrack = -1;
     int selectedChannels = -1;
-    
+
     while ((selectedTrack == -1) && (minChannels >= 0))
     {
         for (track = 0; track <= maxTracks; track++)
@@ -1298,12 +1298,14 @@ bool AvFormatDecoder::autoSelectAudioTra
     AVCodecContext *e = &ic->streams[wantedAudioStream]->codec;
     if (e->codec_id == CODEC_ID_AC3)
     {
+	gContext->SetSetting("Use_AC3", "yes");
         VERBOSE(VB_AUDIO, 
                 QString("Auto-selecting AC3 audio track (stream #%2).")
                 .arg(wantedAudioStream)); 
     }
     else
     {
+	gContext->SetSetting("Use_AC3", "no");
         VERBOSE(VB_AUDIO, 
                 QString("Auto-selecting audio track #%1 (stream #%2).")
                 .arg(selectedTrack + 1).arg(wantedAudioStream));


More information about the mythtv-dev mailing list