--- zapit.cpp-1.375 2005-10-03 10:41:33.000000000 +0200 +++ zapit.cpp 2005-10-21 16:50:20.000000000 +0200 @@ -44,6 +44,10 @@ #include #endif +// AudioPIDs per channel are saved here between sessions. +// define to /dev/null to disable +#define AUDIO_CONFIG_FILE "/var/tuxbox/config/zapit/audioPIDs.data" + /* tuxbox headers */ #include #include @@ -92,6 +96,12 @@ CDemux *teletextDemux = NULL; CDemux *videoDemux = NULL; +// This associative array holds the last selected AudioPid for each channel +map audio_map; + +// True if we save AudioPIDs between sessions +bool save_audioPIDs = false; + /* current zapit mode */ enum { TV_MODE = 0x01, @@ -173,6 +183,20 @@ if (config.getModifiedFlag()) config.saveConfig(CONFIGFILE); + if (save_audioPIDs) { + FILE *audio_config_file = fopen(AUDIO_CONFIG_FILE, "w"); + if (audio_config_file) { + for (map::iterator audio_map_it = audio_map.begin(); + audio_map_it != audio_map.end(); + audio_map_it++) { + fwrite(&(audio_map_it->first), sizeof(t_channel_id), 1, + audio_config_file); + fwrite(&(audio_map_it->second), sizeof(unsigned short), 1, + audio_config_file); + } + fclose(audio_config_file); + } + } } } @@ -207,12 +231,28 @@ static int pmt_update_fd = -1; static bool update_pmt = false; +void +remember_selected_audio() +{ + if (save_audioPIDs && channel) { + if (channel->getAudioChannelCount() > 1) { + audio_map[channel->getServiceId()] = channel->getAudioPid(); + DBG("*** Remembering apid = %d for channel (service-id) = %d", channel->getAudioPid(), channel->getServiceId()); + } else { + audio_map.erase(channel->getServiceId()); + DBG("*** Not Remembering apid = %d for channel (service-id) = %d", channel->getAudioPid(), channel->getServiceId()); + } + } +} + int zapit(const t_channel_id channel_id, bool in_nvod, transponder_id_t transponder_id) { bool transponder_change; tallchans_iterator cit; transponder_id_t current_transponder_id; + remember_selected_audio(); + #ifndef SKIP_CA_STATUS eventServer->sendEvent(CZapitClient::EVT_ZAP_CA_CLEAR, CEventServer::INITID_ZAPIT); // INFO("Event: CA_CLEAR send"); @@ -363,7 +403,7 @@ failed = true; } - thisChannel->setAudioChannel(audioChannel); + thisChannel->setAudioChannel(audioChannel); if ((!failed) && (thisChannel->getAudioPid() == NONE) && (thisChannel->getVideoPid() == NONE)) { WARN("neither audio nor video pid found"); @@ -383,6 +423,23 @@ else thisChannel->getCaPmt()->ca_pmt_list_management = 0x04; + if (save_audioPIDs) { + DBG("***Now trying to get audio right: %d\t%d\t%d", + thisChannel->getAudioChannelCount(), + thisChannel->getAudioChannel(0)->pid, + thisChannel->getServiceId()); + if (audio_map.find(thisChannel->getServiceId()) != audio_map.end()) { + DBG("*************** Searching *** %d **** %d ******\n", thisChannel->getServiceId(), audio_map[thisChannel->getServiceId()]); + for (int i = 0; i < thisChannel->getAudioChannelCount(); i++) { + if (thisChannel->getAudioChannel(i)->pid == audio_map[thisChannel->getServiceId()]) { + //printf("[zapit-audiopids]: Restoring previous audiopid to %d\n", thisChannel->getAudioChannel(i)->pid); + thisChannel->setAudioChannel(i); + } + } + } //else + //printf("[zapit-audiopids]: No previous audiopid for this channel stored\n"); + } + startPlayBack(thisChannel); cam->setCaPmt(thisChannel->getCaPmt()); saveSettings(false); @@ -432,6 +489,7 @@ /* update current channel */ channel->setAudioChannel(index); + remember_selected_audio(); /* set bypass mode */ CZapitAudioChannel *currentAudioChannel = channel->getAudioChannel(); @@ -1849,6 +1907,7 @@ "motorRotationSpeed" ", " "traceNukes" ", " "ChannelNamesFromBouquet" ", " + "saveAudioPIDs" ", " "lnb0_OffsetLow" ", ..., " "lnb63_OffsetLow" ", " "lnb0_OffsetHigh" ", ..., " "lnb63_OffsetHigh" "." "\n", argv[0]); @@ -1908,6 +1967,23 @@ return 0; } + save_audioPIDs = config.getBool("saveAudioPIDs", true); + if (save_audioPIDs) { + FILE *audio_config_file = fopen(AUDIO_CONFIG_FILE, "r"); + if (audio_config_file) { + t_channel_id chan; + unsigned short apid; + while (! feof(audio_config_file)) { + fread(&chan, sizeof(t_channel_id), 1, audio_config_file); + fread(&apid, sizeof(unsigned short), 1, audio_config_file); + DBG("**** Old channelinfo: %d %d\n", (int) chan, (int) apid); + audio_map[chan] = apid; + } + fclose(audio_config_file); + } + } + + // create eventServer eventServer = new CEventServer;