bool CPVRClients::SwitchChannel(const CPVRChannel &channel) { bool bSwitchSuccessful(false); bool bNewStreamOpened(false); { CSingleLock lock(m_critSection); if (m_bIsSwitchingChannels) { CLog::Log(LOGDEBUG, "PVRClients - %s - can't switch to channel '%s'. waiting for the previous switch to complete", __FUNCTION__, channel.ChannelName().c_str()); return false; } m_bIsSwitchingChannels = true; } CPVRChannel currentChannel; bool bGotPlayingChannel = GetPlayingChannel(currentChannel); if (bGotPlayingChannel) { if (currentChannel != channel) { /* different client add-on */ if (currentChannel.ClientID() != channel.ClientID() || /* switch from radio -> tv or tv -> radio */ currentChannel.IsRadio() != channel.IsRadio()) { CloseStream(); bSwitchSuccessful = OpenLiveStream(channel); } else if (!channel.StreamURL().IsEmpty() || !currentChannel.StreamURL().IsEmpty()) { // StreamURL should always be opened as a new file CFileItem m_currentFile(channel); g_application.getApplicationMessenger().PlayFile(m_currentFile, false); bSwitchSuccessful = true; bNewStreamOpened = true; } else { boost::shared_ptr<CPVRClient> client; if (GetConnectedClient(channel.ClientID(), client)) bSwitchSuccessful = client->SwitchChannel(channel); } } else { bSwitchSuccessful = true; } } { CSingleLock lock(m_critSection); m_bIsSwitchingChannels = false; if (bSwitchSuccessful && !bNewStreamOpened) { m_currentChannel = channel; m_bIsPlayingLiveTV = true; ResetQualityData(m_qualityInfo); m_bIsValidChannelSettings = false; } } if (!bSwitchSuccessful) CLog::Log(LOGERROR, "PVR - %s - cannot switch channel on client %d",__FUNCTION__, channel.ClientID()); return bSwitchSuccessful; }
bool CPVRDatabase::Persist(CPVRChannel &channel) { bool bReturn(false); /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVR - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return bReturn; } std::string strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = PrepareSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.EpgID()); } else { /* update channel */ strQuery = PrepareSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idChannel, idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ChannelID(), channel.EpgID()); } if (QueueInsertQuery(strQuery)) { /* update the channel ID for new channels */ if (channel.ChannelID() <= 0) channel.SetChannelID((int)m_pDS->lastinsertid()); bReturn = true; } return bReturn; }
bool CPVRManager::PerformChannelSwitch(const CPVRChannel &channel, bool bPreview) { // check parental lock state if (IsParentalLocked(channel)) return false; // invalid channel if (channel.ClientID() < 0) return false; // check whether we're waiting for a previous switch to complete { CSingleLock lock(m_critSection); if (m_bIsSwitchingChannels) { CLog::Log(LOGDEBUG, "PVRManager - %s - can't switch to channel '%s'. waiting for the previous switch to complete", __FUNCTION__, channel.ChannelName().c_str()); return false; } // no need to do anything except switching m_currentFile if (bPreview) { delete m_currentFile; m_currentFile = new CFileItem(channel); return true; } m_bIsSwitchingChannels = true; } CLog::Log(LOGDEBUG, "PVRManager - %s - switching to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); // store current time in iLastWatched CPVRChannelPtr currentChannel; if (m_addons->GetPlayingChannel(currentChannel)) { time_t tNow; CDateTime::GetCurrentDateTime().GetAsTime(tNow); currentChannel->SetLastWatched(tNow); } // store channel settings SaveCurrentChannelSettings(); // will be deleted by CPVRChannelSwitchJob::DoWork() CFileItem* previousFile = m_currentFile; m_currentFile = NULL; bool bSwitched(false); // switch channel if (!m_addons->SwitchChannel(channel)) { // switch failed CSingleLock lock(m_critSection); m_bIsSwitchingChannels = false; CLog::Log(LOGERROR, "PVRManager - %s - failed to switch to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); CStdString msg = StringUtils::Format(g_localizeStrings.Get(19035).c_str(), channel.ChannelName().c_str()); // CHANNELNAME could not be played. Check the log for details. CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), // PVR information msg); } else { // switch successful bSwitched = true; CSingleLock lock(m_critSection); m_currentFile = new CFileItem(channel); m_bIsSwitchingChannels = false; CLog::Log(LOGNOTICE, "PVRManager - %s - switched to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); } // announce OnStop and OnPlay. yes, this ain't pretty { CSingleLock lock(m_critSectionTriggers); m_pendingUpdates.push_back(new CPVRChannelSwitchJob(previousFile, m_currentFile)); } m_triggerEvent.Set(); return bSwitched; }
bool CPVRManager::PerformChannelSwitch(const CPVRChannel &channel, bool bPreview) { bool bSwitched(false); if (IsParentalLocked(channel)) return false; CSingleLock lock(m_critSection); if (m_bIsSwitchingChannels) { CLog::Log(LOGDEBUG, "PVRManager - %s - can't switch to channel '%s'. waiting for the previous switch to complete", __FUNCTION__, channel.ChannelName().c_str()); return bSwitched; } m_bIsSwitchingChannels = true; CLog::Log(LOGDEBUG, "PVRManager - %s - switching to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); /* make sure that channel settings are persisted */ if (!bPreview) { CPVRChannelPtr currentChannel; if (m_addons->GetPlayingChannel(currentChannel)) { /* store current time in iLastWatched */ time_t tNow; CDateTime::GetCurrentDateTime().GetAsTime(tNow); currentChannel->SetLastWatched(tNow); } SaveCurrentChannelSettings(); } SAFE_DELETE(m_currentFile); lock.Leave(); if (!bPreview && (channel.ClientID() < 0 || !m_addons->SwitchChannel(channel))) { lock.Enter(); m_bIsSwitchingChannels = false; lock.Leave(); CLog::Log(LOGERROR, "PVRManager - %s - failed to switch to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); } else { bSwitched = true; lock.Enter(); m_currentFile = new CFileItem(channel); if (!bPreview) CLog::Log(LOGNOTICE, "PVRManager - %s - switched to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); m_bIsSwitchingChannels = false; } if (!bSwitched) { CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), // PVR information g_localizeStrings.Get(19035)); // This channel cannot be played. Check the log for details. } return bSwitched; }
CPVRTimerInfoTag *CPVRTimerInfoTag::InstantTimer() { /* create a new timer */ CPVRTimerInfoTag *newTag = new CPVRTimerInfoTag(); if (!newTag) { CLog::Log(LOGERROR, "%s - couldn't create new timer", __FUNCTION__); return NULL; } CFileItem *curPlayingChannel = g_PVRManager.GetCurrentPlayingItem(); CPVRChannel *channel = (curPlayingChannel) ? curPlayingChannel->GetPVRChannelInfoTag(): NULL; if (!channel) { CLog::Log(LOGDEBUG, "%s - couldn't find current playing channel", __FUNCTION__); channel = PVRChannelsTV.GetByChannelNumber(1); if (!channel) { CLog::Log(LOGERROR, "%s - cannot find any channels", __FUNCTION__); } } int iDuration = g_guiSettings.GetInt("pvrrecord.instantrecordtime"); if (!iDuration) iDuration = 180; /* default to 180 minutes */ int iPriority = g_guiSettings.GetInt("pvrrecord.defaultpriority"); if (!iPriority) iPriority = 50; /* default to 50 */ int iLifetime = g_guiSettings.GetInt("pvrrecord.defaultlifetime"); if (!iLifetime) iLifetime = 30; /* default to 30 days */ /* set the timer data */ newTag->m_iClientIndex = -1; newTag->m_bIsActive = true; newTag->m_strTitle = g_localizeStrings.Get(19056); newTag->m_iChannelNumber = channel->ChannelNumber(); newTag->m_iClientNumber = channel->ClientChannelNumber(); newTag->m_iClientID = channel->ClientID(); newTag->m_bIsRadio = channel->IsRadio(); newTag->m_StartTime = CDateTime::GetCurrentDateTime(); newTag->SetDuration(iDuration); newTag->m_iPriority = iPriority; newTag->m_iLifetime = iLifetime; /* generate summary string */ newTag->m_strSummary.Format("%s %s %s %s %s", newTag->m_StartTime.GetAsLocalizedDate(), g_localizeStrings.Get(19159), newTag->m_StartTime.GetAsLocalizedTime("", false), g_localizeStrings.Get(19160), newTag->m_StopTime.GetAsLocalizedTime("", false)); /* unused only for reference */ newTag->m_strFileNameAndPath = "pvr://timers/new"; return newTag; }
bool CPVRDatabase::Persist(CPVRChannel &channel, bool bCommit) { bool bReturn(false); /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::LogF(LOGERROR, "Invalid channel uid: %d", channel.UniqueID()); return bReturn; } CSingleLock lock(m_critSection); // Note: Do not use channel.ChannelID value to check presence of channel in channels table. It might not yet be set correctly. std::string strQuery = PrepareSQL("iUniqueId = %u AND iClientId = %u", channel.UniqueID(), channel.ClientID()); const std::string strValue = GetSingleValue("channels", "idChannel", strQuery); if (strValue.empty()) { /* new channel */ strQuery = PrepareSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), static_cast<unsigned int>(channel.LastWatched()), channel.ClientID(), channel.EpgID()); } else { /* update channel */ strQuery = PrepareSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idChannel, idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %s, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), static_cast<unsigned int>(channel.LastWatched()), channel.ClientID(), strValue.c_str(), channel.EpgID()); } if (QueueInsertQuery(strQuery)) { bReturn = true; if (bCommit) bReturn = CommitInsertQueries(); } return bReturn; }
bool CPVRTimers::IsRecordingOnChannel(const CPVRChannel &channel) const { bool bReturn(false); CSingleLock lock(m_critSection); for (unsigned int ptr = 0; ptr < size(); ptr++) { CPVRTimerInfoTag *timer = at(ptr); if (timer->IsRecording() && timer->m_iClientChannelUid == channel.UniqueID() && timer->m_iClientId == channel.ClientID()) { bReturn = true; break; } } return bReturn; }
CPVRTimerInfoTag *CPVRTimerInfoTag::CreateFromEpg(const CEpgInfoTag &tag) { /* create a new timer */ CPVRTimerInfoTag *newTag = new CPVRTimerInfoTag(); if (!newTag) { CLog::Log(LOGERROR, "%s - couldn't create new timer", __FUNCTION__); return NULL; } /* check if a valid channel is set */ CPVRChannel *channel = (CPVRChannel *) tag.ChannelTag(); if (channel == NULL) { CLog::Log(LOGERROR, "%s - no channel set", __FUNCTION__); return NULL; } /* check if the epg end date is in the future */ if (tag.EndAsLocalTime() < CDateTime::GetCurrentDateTime()) { CLog::Log(LOGERROR, "%s - end time is in the past", __FUNCTION__); return NULL; } /* set the timer data */ CDateTime newStart = tag.StartAsUTC(); CDateTime newEnd = tag.EndAsUTC(); newTag->m_iClientIndex = -1; newTag->m_strTitle = tag.Title().IsEmpty() ? channel->ChannelName() : tag.Title(); newTag->m_iChannelNumber = channel->ChannelNumber(); newTag->m_iClientChannelUid = channel->UniqueID(); newTag->m_iClientId = channel->ClientID(); newTag->m_bIsRadio = channel->IsRadio(); newTag->m_iGenreType = tag.GenreType(); newTag->m_iGenreSubType = tag.GenreSubType(); newTag->SetStartFromUTC(newStart); newTag->SetEndFromUTC(newEnd); if (tag.Plot().IsEmpty()) { newTag->m_strSummary.Format("%s %s %s %s %s", newTag->StartAsLocalTime().GetAsLocalizedDate(), g_localizeStrings.Get(19159), newTag->StartAsLocalTime().GetAsLocalizedTime("", false), g_localizeStrings.Get(19160), newTag->EndAsLocalTime().GetAsLocalizedTime("", false)); } else { newTag->m_strSummary = tag.Plot(); } /* we might have a copy of the tag here, so get the real one from the pvrmanager */ const CEpg *epgTable = channel->GetEPG(); newTag->m_epgInfo = epgTable ? epgTable->GetTag(tag.UniqueBroadcastID(), tag.StartAsUTC()) : NULL; /* unused only for reference */ newTag->m_strFileNameAndPath = "pvr://timers/new"; return newTag; }
bool CPVRChannelGroup::AddToGroup(CPVRChannel &channel, int iChannelNumber /* = 0 */, bool bSortAndRenumber /* = true */) { CSingleLock lock(m_critSection); bool bReturn(false); if (!CPVRChannelGroup::IsGroupMember(channel)) { if (iChannelNumber <= 0 || iChannelNumber > (int) m_members.size() + 1) iChannelNumber = m_members.size() + 1; CPVRChannel *realChannel = (IsInternalGroup()) ? &channel : (CPVRChannel *) g_PVRChannelGroups->GetGroupAll(m_bRadio)->GetByClient(channel.UniqueID(), channel.ClientID()); if (realChannel) { PVRChannelGroupMember newMember = { realChannel, iChannelNumber }; m_members.push_back(newMember); m_bChanged = true; if (bSortAndRenumber) { if (m_bUsingBackendChannelOrder) SortByClientChannelNumber(); else SortByChannelNumber(); Renumber(); } // TODO notify observers bReturn = true; } } return bReturn; }
bool CPVRClient::OpenStream(const CPVRChannel &channel, bool bIsSwitchingChannel) { bool bReturn(false); CloseStream(); if(!CanPlayChannel(channel)) { CLog::Log(LOGDEBUG, "add-on '%s' can not play channel '%s'", GetFriendlyName().c_str(), channel.ChannelName().c_str()); } else if (!channel.StreamURL().IsEmpty()) { CLog::Log(LOGDEBUG, "opening live stream on url '%s'", channel.StreamURL().c_str()); bReturn = true; // the Njoy N7 sometimes doesn't switch channels, but opens a stream to the previous channel // when not waiting for a short period. // added in 1.1.0 AddonVersion checkVersion("1.1.0"); if (m_apiVersion >= checkVersion) { unsigned int iWaitTimeMs = m_pStruct->GetChannelSwitchDelay(); if (iWaitTimeMs > 0) XbmcThreads::ThreadSleep(iWaitTimeMs); } } else { CLog::Log(LOGDEBUG, "opening live stream for channel '%s'", channel.ChannelName().c_str()); PVR_CHANNEL tag; WriteClientChannelInfo(channel, tag); try { bReturn = m_pStruct->OpenLiveStream(tag); } catch (exception &e) { LogException(e, __FUNCTION__); } } if (bReturn) { CPVRChannelPtr currentChannel = g_PVRChannelGroups->GetByUniqueID(channel.UniqueID(), channel.ClientID()); CSingleLock lock(m_critSection); m_playingChannel = currentChannel; m_bIsPlayingTV = true; m_bIsPlayingRecording = false; } return bReturn; }
bool CPVRClient::SwitchChannel(const CPVRChannel &channel) { bool bSwitched(false); if (IsPlayingLiveStream() && CanPlayChannel(channel)) { PVR_CHANNEL tag; WriteClientChannelInfo(channel, tag); try { bSwitched = m_pStruct->SwitchChannel(tag); } catch (exception &e) { LogException(e, __FUNCTION__); } } if (bSwitched) { CPVRChannelPtr currentChannel = g_PVRChannelGroups->GetByUniqueID(channel.UniqueID(), channel.ClientID()); CSingleLock lock(m_critSection); ResetQualityData(m_qualityInfo); m_playingChannel = currentChannel; } return bSwitched; }
int CPVRDatabase::Persist(const CPVRChannel &channel, bool bQueueWrite /* = false */) { int iReturn = -1; /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVRDB - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return iReturn; } CStdString strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = FormatSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem) " "VALUES (%i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i);", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem()); } else { /* update channel */ strQuery = FormatSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idChannel) " "VALUES (%i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i);", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.ChannelID()); } if (bQueueWrite) { QueueInsertQuery(strQuery); iReturn = 0; } else if (ExecuteQuery(strQuery)) { iReturn = (channel.ChannelID() <= 0) ? (int) m_pDS->lastinsertid() : channel.ChannelID(); } return iReturn; }
bool CPVRManager::PerformChannelSwitch(CPVRChannel &channel, bool bPreview) { // check parental lock state if (IsParentalLocked(channel)) return false; // invalid channel if (channel.ClientID() < 0) return false; // check whether we're waiting for a previous switch to complete { CSingleLock lock(m_critSection); if (m_bIsSwitchingChannels) { CLog::Log(LOGDEBUG, "PVRManager - %s - can't switch to channel '%s'. waiting for the previous switch to complete", __FUNCTION__, channel.ChannelName().c_str()); return false; } // no need to do anything except switching m_currentFile if (bPreview) { delete m_currentFile; m_currentFile = new CFileItem(channel); return true; } m_bIsSwitchingChannels = true; } CLog::Log(LOGDEBUG, "PVRManager - %s - switching to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); // will be deleted by CPVRChannelSwitchJob::DoWork() CFileItem* previousFile = m_currentFile; m_currentFile = NULL; bool bSwitched(false); // switch channel if (!m_addons->SwitchChannel(channel)) { // switch failed CSingleLock lock(m_critSection); m_bIsSwitchingChannels = false; CLog::Log(LOGERROR, "PVRManager - %s - failed to switch to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); std::string msg = StringUtils::Format(g_localizeStrings.Get(19035).c_str(), channel.ChannelName().c_str()); // CHANNELNAME could not be played. Check the log for details. CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), // PVR information msg); } else { // switch successful bSwitched = true; // save previous and load new channel's settings (view mode is updated in // the player) g_application.SaveFileState(); g_application.LoadVideoSettings(channel.Path()); // set channel as selected item CGUIWindowPVRBase::SetSelectedItemPath(channel.IsRadio(), channel.Path()); UpdateLastWatched(channel); CSingleLock lock(m_critSection); m_currentFile = new CFileItem(channel); m_bIsSwitchingChannels = false; CLog::Log(LOGNOTICE, "PVRManager - %s - switched to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); } // announce OnStop and OnPlay. yes, this ain't pretty { CSingleLock lock(m_critSectionTriggers); m_pendingUpdates.push_back(new CPVRChannelSwitchJob(previousFile, m_currentFile)); } m_triggerEvent.Set(); return bSwitched; }
bool CPVRDatabase::Persist(CPVRChannel &channel, bool bQueueWrite /* = false */) { bool bReturn(false); /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVR - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return bReturn; } CStdString strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = FormatSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idEpg) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.EpgID()); } else { /* update channel */ strQuery = FormatSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idChannel, idEpg) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.ChannelID(), channel.EpgID()); } if (bQueueWrite) { QueueInsertQuery(strQuery); bReturn = true; } else if (ExecuteQuery(strQuery)) { CSingleLock lock(channel.m_critSection); if (channel.m_iChannelId <= 0) channel.m_iChannelId = (int)m_pDS->lastinsertid(); bReturn = true; } return bReturn; }
bool CPVRClients::CanRecordInstantly(void) { CPVRChannel currentChannel; return GetPlayingChannel(currentChannel) && HasRecordingsSupport(currentChannel.ClientID()); }
long CPVRDatabase::UpdateChannel(const CPVRChannel &channel, bool bQueueWrite /* = false */) { long iReturn = -1; /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVRDB - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return iReturn; } CStdString strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = FormatSQL("INSERT INTO Channels (" "UniqueId, ChannelNumber, GroupId, IsRadio, IsHidden, " "IconPath, ChannelName, IsVirtual, EPGEnabled, EPGScraper, ClientId, " "ClientChannelNumber, InputFormat, StreamURL, EncryptionSystem) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %i, %i, '%s', '%s', %i)\n", channel.UniqueID(), channel.ChannelNumber(), channel.GroupID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem()); } else { /* update channel */ strQuery = FormatSQL("REPLACE INTO Channels (" "UniqueId, ChannelNumber, GroupId, IsRadio, IsHidden, " "IconPath, ChannelName, IsVirtual, EPGEnabled, EPGScraper, ClientId, " "ClientChannelNumber, InputFormat, StreamURL, EncryptionSystem, ChannelId) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %i, %i, '%s', '%s', %i, %i)\n", channel.UniqueID(), channel.ChannelNumber(), channel.GroupID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.ChannelID()); } if (bQueueWrite) { QueueInsertQuery(strQuery); iReturn = 0; } else if (ExecuteQuery(strQuery)) { iReturn = (channel.ChannelID() <= 0) ? (long) m_pDS->lastinsertid() : channel.ChannelID(); } return iReturn; }
bool CPVRTimers::IsRecordingOnChannel(const CPVRChannel &channel) const { CSingleLock lock(m_critSection); for (map<CDateTime, vector<CPVRTimerInfoTag *>* >::const_iterator it = m_tags.begin(); it != m_tags.end(); it++) { for (unsigned int iTimerPtr = 0; iTimerPtr < it->second->size(); iTimerPtr++) { CPVRTimerInfoTag *timer = it->second->at(iTimerPtr); if (timer->IsRecording() && timer->m_iClientChannelUid == channel.UniqueID() && timer->m_iClientId == channel.ClientID()) return true; } } return false; }
bool CPVRChannelGroup::UpdateGroupEntries(const CPVRChannelGroup &channels) { bool bChanged(false); CSingleLock lock(m_critSection); int iCurSize = size(); CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if (!database || !database->Open()) return false; /* go through the channel list and check for updated or new channels */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { CPVRChannel *channel = channels.at(iChannelPtr).channel; int iChannelNumber = channels.at(iChannelPtr).iChannelNumber; if (!channel) continue; CPVRChannel *realChannel = (CPVRChannel *) CPVRManager::GetChannelGroups()->GetGroupAll(m_bRadio)->GetByClient(channel->UniqueID(), channel->ClientID()); if (!realChannel) continue; if (!IsGroupMember(realChannel)) { AddToGroup(realChannel, iChannelNumber, false); bChanged = true; m_bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroup - %s - added %s channel '%s' at position %d in group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", realChannel->ChannelName().c_str(), iChannelNumber, GroupName().c_str()); } } /* check for deleted channels */ unsigned int iSize = size(); for (unsigned int iChannelPtr = 0; iChannelPtr < iSize; iChannelPtr++) { CPVRChannel *channel = (CPVRChannel *) GetByIndex(iChannelPtr); if (!channel) continue; if (channels.GetByClient(channel->UniqueID(), channel->ClientID()) == NULL) { /* channel was not found */ CLog::Log(LOGINFO,"PVRChannelGroup - %s - deleted %s channel '%s' from group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str(), GroupName().c_str()); /* remove this channel from all non-system groups */ RemoveFromGroup(channel); m_bChanged = true; bChanged = true; iChannelPtr--; iSize--; } } if (bChanged) { /* sort by client channel number if this is the first time */ if (iCurSize == 0) SortByClientChannelNumber(); /* renumber to make sure all channels have a channel number. new channels were added at the back, so they'll get the highest numbers */ Renumber(); return Persist(); } return true; }