From 1f677366c4c486eddce517d696d672acfd56db37 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 6 Feb 2005 11:33:13 +0100 Subject: [PATCH] Making sure the current audio track is actually one of the ones available in a recording --- device.c | 51 ++++++++++++++++++++++++++++++++------------------- device.h | 7 ++++++- menu.c | 3 ++- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/device.c b/device.c index 2a6e5b8b..88f41d27 100644 --- a/device.c +++ b/device.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: device.c 1.81 2005/01/30 14:41:57 kls Exp $ + * $Id: device.c 1.82 2005/02/06 11:32:05 kls Exp $ */ #include "device.h" @@ -137,6 +137,7 @@ cDevice::cDevice(void) pesAssembler = new cPesAssembler; ClrAvailableTracks(); currentAudioTrack = ttAudioFirst; + currentAudioTrackMissingCount = 0; for (int i = 0; i < MAXRECEIVERS; i++) receiver[i] = NULL; @@ -551,24 +552,7 @@ eSetChannelResult cDevice::SetChannel(const cChannel *Channel, bool LiveView) for (int i = 0; i < MAXDPIDS; i++) SetAvailableTrack(ttDolby, i, Channel->Dpid(i), Channel->Dlang(i)); } - // Select the preferred audio track: - eTrackType PreferredTrack = ttAudioFirst; - int LanguagePreference = -1; - int StartCheck = Setup.CurrentDolby ? ttDolbyFirst : ttAudioFirst; - int EndCheck = ttDolbyLast; - for (int i = StartCheck; i <= EndCheck; i++) { - const tTrackId *TrackId = GetTrack(eTrackType(i)); - if (TrackId && TrackId->id && I18nIsPreferredLanguage(Setup.AudioLanguages, I18nLanguageIndex(TrackId->language), LanguagePreference)) - PreferredTrack = eTrackType(i); - if (Setup.CurrentDolby && i == ttDolbyLast) { - i = ttAudioFirst - 1; - EndCheck = ttAudioLast; - } - } - // Make sure we're set to an available audio track: - const tTrackId *Track = GetTrack(GetCurrentAudioTrack()); - if (!Track || !Track->id || PreferredTrack != GetCurrentAudioTrack()) - SetCurrentAudioTrack(PreferredTrack); + EnsureAudioTrack(true); } cStatus::MsgChannelSwitch(this, Channel->Number()); // only report status if channel switch successfull } @@ -678,6 +662,10 @@ bool cDevice::SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const c availableTracks[t].flags = Flags; availableTracks[t].id = Id; // setting 'id' last to avoid the need for extensive locking } + if (t == currentAudioTrack) + currentAudioTrackMissingCount = 0; + else if (!availableTracks[currentAudioTrack].id && currentAudioTrackMissingCount++ > NumAudioTracks() * 10) + EnsureAudioTrack(); return true; } else @@ -717,6 +705,31 @@ bool cDevice::SetCurrentAudioTrack(eTrackType Type) return false; } +void cDevice::EnsureAudioTrack(bool Force) +{ + if (Force || !availableTracks[currentAudioTrack].id) { + eTrackType PreferredTrack = ttAudioFirst; + int LanguagePreference = -1; + int StartCheck = Setup.CurrentDolby ? ttDolbyFirst : ttAudioFirst; + int EndCheck = ttDolbyLast; + for (int i = StartCheck; i <= EndCheck; i++) { + const tTrackId *TrackId = GetTrack(eTrackType(i)); + if (TrackId && TrackId->id && I18nIsPreferredLanguage(Setup.AudioLanguages, I18nLanguageIndex(TrackId->language), LanguagePreference)) + PreferredTrack = eTrackType(i); + if (Setup.CurrentDolby && i == ttDolbyLast) { + i = ttAudioFirst - 1; + EndCheck = ttAudioLast; + } + } + // Make sure we're set to an available audio track: + const tTrackId *Track = GetTrack(GetCurrentAudioTrack()); + if (!Track || !Track->id || PreferredTrack != GetCurrentAudioTrack()) { + dsyslog("setting audio track to %d", PreferredTrack); + SetCurrentAudioTrack(PreferredTrack); + } + } +} + bool cDevice::CanReplay(void) const { return HasDecoder(); diff --git a/device.h b/device.h index 9ab15c9f..0ded7daf 100644 --- a/device.h +++ b/device.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: device.h 1.53 2005/01/22 14:58:07 kls Exp $ + * $Id: device.h 1.54 2005/02/06 11:25:37 kls Exp $ */ #ifndef __DEVICE_H @@ -315,6 +315,7 @@ public: private: tTrackId availableTracks[ttMaxTrackTypes]; eTrackType currentAudioTrack; + int currentAudioTrackMissingCount; bool pre_1_3_19_PrivateStream; protected: virtual void SetAudioTrackDevice(eTrackType Type); @@ -339,6 +340,10 @@ public: bool SetCurrentAudioTrack(eTrackType Type); ///< Sets the current audio track to the given Type. ///< \return Returns true if Type is a valid audio track, false otherwise. + void EnsureAudioTrack(bool Force = false); + ///< Makes sure an audio track is selected that is actually available. + ///< If Force is true, the language and Dolby Digital settings will + ///< be verified even if the current audio track is available. // Audio facilities diff --git a/menu.c b/menu.c index 4e00a999..a438b799 100644 --- a/menu.c +++ b/menu.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: menu.c 1.339 2005/02/05 11:35:23 kls Exp $ + * $Id: menu.c 1.340 2005/02/06 11:33:13 kls Exp $ */ #include "menu.h" @@ -2850,6 +2850,7 @@ cDisplayTracks *cDisplayTracks::currentDisplayTracks = NULL; cDisplayTracks::cDisplayTracks(void) :cOsdObject(true) { + cDevice::PrimaryDevice()->EnsureAudioTrack(); // Get the actual audio track descriptions from the EPG if we're not replaying: if (!cDevice::PrimaryDevice()->Replaying() || cTransferControl::ReceiverDevice()) SetTrackDescriptions();