bool CPVRClients::OpenStream(const CPVRChannelPtr &channel, bool bIsSwitchingChannel) { assert(channel.get()); bool bReturn(false); CloseStream(); /* try to open the stream on the client */ PVR_CLIENT client; if (GetConnectedClient(channel->ClientID(), client) && client->OpenStream(channel, bIsSwitchingChannel)) { CSingleLock lock(m_critSection); m_playingClientId = channel->ClientID(); m_bIsPlayingLiveTV = true; if (client.get()) m_strPlayingClientName = client->GetFriendlyName(); else m_strPlayingClientName = g_localizeStrings.Get(13205); bReturn = true; } return bReturn; }
bool CPVRManager::OpenLiveStream(const CFileItem &channel) { bool bReturn(false); if (!channel.HasPVRChannelInfoTag()) return bReturn; CLog::Log(LOGDEBUG,"PVRManager - %s - opening live stream on channel '%s'", __FUNCTION__, channel.GetPVRChannelInfoTag()->ChannelName().c_str()); // check if we're allowed to play this file if (IsParentalLocked(*channel.GetPVRChannelInfoTag())) return bReturn; if ((bReturn = m_addons->OpenStream(*channel.GetPVRChannelInfoTag(), false)) != false) { CSingleLock lock(m_critSection); if(m_currentFile) delete m_currentFile; m_currentFile = new CFileItem(channel); // set channel as selected item if (channel.HasPVRChannelInfoTag()) CGUIWindowPVRBase::SetSelectedItemPath(channel.GetPVRChannelInfoTag()->IsRadio(), channel.GetPVRChannelInfoTag()->Path()); CPVRChannelPtr playingChannel; if (m_addons->GetPlayingChannel(playingChannel)) UpdateLastWatched(*playingChannel.get()); } return bReturn; }
bool CPVRChannel::UpdateFromClient(const CPVRChannelPtr &channel) { assert(channel.get()); SetClientID(channel->ClientID()); SetStreamURL(channel->StreamURL()); CSingleLock lock(m_critSection); if (m_iClientChannelNumber.channel != channel->ClientChannelNumber() || m_iClientChannelNumber.subchannel != channel->ClientSubChannelNumber() || m_strInputFormat != channel->InputFormat() || m_iClientEncryptionSystem != channel->EncryptionSystem() || m_strClientChannelName != channel->ClientChannelName()) { m_iClientChannelNumber.channel = channel->ClientChannelNumber(); m_iClientChannelNumber.subchannel = channel->ClientSubChannelNumber(); m_strInputFormat = channel->InputFormat(); m_iClientEncryptionSystem = channel->EncryptionSystem(); m_strClientChannelName = channel->ClientChannelName(); UpdateEncryptionName(); SetChanged(); } // only update the channel name and icon if the user hasn't changed them manually if (m_strChannelName.empty() || !IsUserSetName()) SetChannelName(channel->ClientChannelName()); if (m_strIconPath.empty() || !IsUserSetIcon()) SetIconPath(channel->IconPath()); return m_bChanged; }
bool CPVRClients::SwitchChannel(const CPVRChannel &channel) { { 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; } bool bSwitchSuccessful(false); CPVRChannelPtr currentChannel; if (// no channel is currently playing !GetPlayingChannel(currentChannel) || // different backend currentChannel->ClientID() != channel.ClientID() || // different type currentChannel->IsRadio() != channel.IsRadio() || // stream URL should always be opened as a new file !channel.StreamURL().IsEmpty() || !currentChannel->StreamURL().IsEmpty()) { if (channel.StreamURL().IsEmpty()) { CloseStream(); bSwitchSuccessful = OpenStream(channel, true); } else { CFileItem m_currentFile(channel); CApplicationMessenger::Get().PlayFile(m_currentFile, false); bSwitchSuccessful = true; } } // same channel else if (currentChannel.get() && *currentChannel == channel) { bSwitchSuccessful = true; } else { PVR_CLIENT client; if (GetConnectedClient(channel.ClientID(), client)) bSwitchSuccessful = client->SwitchChannel(channel); } { CSingleLock lock(m_critSection); m_bIsSwitchingChannels = false; if (bSwitchSuccessful) m_bIsValidChannelSettings = false; } if (!bSwitchSuccessful) CLog::Log(LOGERROR, "PVR - %s - cannot switch to channel '%s' on client '%d'",__FUNCTION__, channel.ChannelName().c_str(), channel.ClientID()); return bSwitchSuccessful; }
bool CPVRClient::CanPlayChannel(const CPVRChannelPtr &channel) const { assert(channel.get()); return (m_bReadyToUse && ((m_addonCapabilities.bSupportsTV && !channel->IsRadio()) || (m_addonCapabilities.bSupportsRadio && channel->IsRadio()))); }
bool CPVRClients::SwitchChannel(const CPVRChannelPtr &channel) { assert(channel.get()); { 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; } bool bSwitchSuccessful(false); CPVRChannelPtr currentChannel(GetPlayingChannel()); if (// no channel is currently playing !currentChannel || // different backend currentChannel->ClientID() != channel->ClientID() || // stream URL should always be opened as a new file !channel->StreamURL().empty() || !currentChannel->StreamURL().empty()) { if (channel->StreamURL().empty()) { CloseStream(); bSwitchSuccessful = OpenStream(channel, true); } else { CApplicationMessenger::GetInstance().PostMsg(TMSG_MEDIA_PLAY, 0, 0, static_cast<void*>(new CFileItem(channel))); bSwitchSuccessful = true; } } // same channel else if (currentChannel && currentChannel == channel) { bSwitchSuccessful = true; } else { PVR_CLIENT client; if (GetConnectedClient(channel->ClientID(), client)) bSwitchSuccessful = client->SwitchChannel(channel); } { CSingleLock lock(m_critSection); m_bIsSwitchingChannels = false; } if (!bSwitchSuccessful) CLog::Log(LOGERROR, "PVR - %s - cannot switch to channel '%s' on client '%d'",__FUNCTION__, channel->ChannelName().c_str(), channel->ClientID()); return bSwitchSuccessful; }
void CGUIWindowPVRGuide::UpdateViewChannel() { CPVRChannelPtr currentChannel; bool bGotCurrentChannel = g_PVRManager.GetCurrentChannel(currentChannel); if (bGotCurrentChannel && currentChannel.get()) SET_CONTROL_LABEL(CONTROL_LABEL_HEADER1, currentChannel->ChannelName().c_str()); SET_CONTROL_LABEL(CONTROL_LABEL_HEADER2, GetGroup()->GroupName()); m_vecItems->Clear(); if ((!bGotCurrentChannel || g_PVRManager.GetCurrentEpg(*m_vecItems) == 0) && currentChannel.get()) { CFileItemPtr item; item.reset(new CFileItem("pvr://guide/" + currentChannel->ChannelName() + "/empty.epg", false)); item->SetLabel(g_localizeStrings.Get(19028)); item->SetLabelPreformated(true); m_vecItems->Add(item); } m_viewControl.SetItems(*m_vecItems); }
std::string CPVRClients::GetStreamURL(const CPVRChannelPtr &channel) { assert(channel.get()); std::string strReturn; PVR_CLIENT client; if (GetConnectedClient(channel->ClientID(), client)) strReturn = client->GetLiveStreamURL(channel); else CLog::Log(LOGERROR, "PVR - %s - cannot find client %d",__FUNCTION__, channel->ClientID()); return strReturn; }
PVR_ERROR CPVRClients::GetEPGForChannel(const CPVRChannelPtr &channel, CEpg *epg, time_t start, time_t end) { assert(channel.get()); PVR_ERROR error(PVR_ERROR_UNKNOWN); PVR_CLIENT client; if (GetConnectedClient(channel->ClientID(), client)) error = client->GetEPGForChannel(channel, epg, start, end); if (error != PVR_ERROR_NO_ERROR) CLog::Log(LOGERROR, "PVR - %s - cannot get EPG for channel '%s' from client '%d': %s",__FUNCTION__, channel->ChannelName().c_str(), channel->ClientID(), CPVRClient::ToString(error)); return error; }
bool CPVRTimers::InstantTimer(const CPVRChannelPtr &channel) { assert(channel.get()); if (!g_PVRManager.CheckParentalLock(channel)) return false; CEpgInfoTagPtr epgTag(channel->GetEPGNow()); CPVRTimerInfoTagPtr newTimer; if (epgTag) newTimer = CPVRTimerInfoTag::CreateFromEpg(epgTag); if (!newTimer) { newTimer.reset(new CPVRTimerInfoTag); /* set the timer data */ newTimer->m_iClientIndex = -1; newTimer->m_strTitle = channel->ChannelName(); newTimer->m_strSummary = g_localizeStrings.Get(19056); newTimer->m_iChannelNumber = channel->ChannelNumber(); newTimer->m_iClientChannelUid = channel->UniqueID(); newTimer->m_iClientId = channel->ClientID(); newTimer->m_bIsRadio = channel->IsRadio(); /* generate summary string */ newTimer->m_strSummary = StringUtils::Format("%s %s %s %s %s", newTimer->StartAsLocalTime().GetAsLocalizedDate().c_str(), g_localizeStrings.Get(19159).c_str(), newTimer->StartAsLocalTime().GetAsLocalizedTime("", false).c_str(), g_localizeStrings.Get(19160).c_str(), newTimer->EndAsLocalTime().GetAsLocalizedTime("", false).c_str()); } CDateTime startTime(0); newTimer->SetStartFromUTC(startTime); newTimer->m_iMarginStart = 0; /* set the start margin to 0 for instant timers */ int iDuration = CSettings::GetInstance().GetInt(CSettings::SETTING_PVRRECORD_INSTANTRECORDTIME); CDateTime endTime = CDateTime::GetUTCDateTime() + CDateTimeSpan(0, 0, iDuration ? iDuration : 120, 0); newTimer->SetEndFromUTC(endTime); /* unused only for reference */ newTimer->m_strFileNameAndPath = CPVRTimersPath::PATH_NEW; bool bReturn = newTimer->AddToClient(); if (!bReturn) CLog::Log(LOGERROR, "PVRTimers - %s - unable to add an instant timer on the client", __FUNCTION__); return bReturn; }
void CPVRManager::CloseStream(void) { CSingleLock lock(m_critSection); CPVRChannelPtr channel; if (m_addons->GetPlayingChannel(channel)) { UpdateLastWatched(*channel.get()); // store channel settings g_application.SaveFileState(); } m_addons->CloseStream(); SAFE_DELETE(m_currentFile); }
void CPVRManager::UpdateLastWatched(const CPVRChannelPtr &channel) { assert(channel.get()); time_t tNow; CDateTime::GetCurrentDateTime().GetAsTime(tNow); channel->SetLastWatched(tNow); // update last watched timestamp for group CPVRChannelGroupPtr group(GetPlayingGroup(channel->IsRadio())); group->SetLastWatched(tNow); /* update last played group */ m_channelGroups->SetLastPlayedGroup(group); }
bool CDVDInputStreamPVRManager::SelectChannel(const CPVRChannelPtr &channel) { assert(channel.get()); PVR_CLIENT client; if (IsOtherStreamHack()) { CFileItem item(channel); return CloseAndOpen(item.GetPath().c_str()); } else if (m_pLiveTV) { return m_pLiveTV->SelectChannelById(channel->ChannelID()); } return false; }
bool CDVDInputStreamPVRManager::SelectChannel(const CPVRChannelPtr &channel) { assert(channel.get()); PVR_CLIENT client; if (IsOtherStreamHack()) { CFileItem item(channel); return CloseAndOpen(item.GetPath()); } else if (!m_isRecording) { return g_PVRManager.ChannelSwitchById(channel->ChannelID()); } return false; }
/*! * @brief Copy over channel info from xbmcChannel to addonClient. * @param xbmcChannel The channel on XBMC's side. * @param addonChannel The channel on the addon's side. */ void CPVRClient::WriteClientChannelInfo(const CPVRChannelPtr &xbmcChannel, PVR_CHANNEL &addonChannel) { assert(xbmcChannel.get()); memset(&addonChannel, 0, sizeof(addonChannel)); addonChannel.iUniqueId = xbmcChannel->UniqueID(); addonChannel.iChannelNumber = xbmcChannel->ClientChannelNumber(); addonChannel.iSubChannelNumber = xbmcChannel->ClientSubChannelNumber(); strncpy(addonChannel.strChannelName, xbmcChannel->ClientChannelName().c_str(), sizeof(addonChannel.strChannelName) - 1); strncpy(addonChannel.strIconPath, xbmcChannel->IconPath().c_str(), sizeof(addonChannel.strIconPath) - 1); addonChannel.iEncryptionSystem = xbmcChannel->EncryptionSystem(); addonChannel.bIsRadio = xbmcChannel->IsRadio(); addonChannel.bIsHidden = xbmcChannel->IsHidden(); strncpy(addonChannel.strInputFormat, xbmcChannel->InputFormat().c_str(), sizeof(addonChannel.strInputFormat) - 1); strncpy(addonChannel.strStreamURL, xbmcChannel->StreamURL().c_str(), sizeof(addonChannel.strStreamURL) - 1); }
bool CDVDInputStreamPVRManager::SelectChannel(const CPVRChannelPtr &channel) { assert(channel.get()); PVR_CLIENT client; if (!SupportsChannelSwitch()) { CFileItem item(channel); return CloseAndOpen(item.GetPath().c_str()); } else if (m_pLiveTV) { return m_pLiveTV->SelectChannel(channel->ChannelNumber()); } return false; }
bool CPVRTimers::InstantTimer(const CPVRChannelPtr &channel) { assert(channel.get()); if (!g_PVRManager.CheckParentalLock(channel)) return false; CPVRTimerInfoTagPtr newTimer(CPVRTimerInfoTag::CreateInstantTimerTag(channel)); bool bReturn(false); if (newTimer) bReturn = newTimer->AddToClient(); if (!bReturn) CLog::Log(LOGERROR, "PVRTimers - %s - unable to add an instant timer on the client", __FUNCTION__); return bReturn; }
CFileItemPtr CPVRChannelGroup::GetLastPlayedChannel(unsigned int iCurrentChannel /* = -1 */) const { CSingleLock lock(m_critSection); time_t tCurrentLastWatched(0), tMaxLastWatched(0); if (iCurrentChannel > 0) { CPVRChannelPtr channel = GetByChannelID(iCurrentChannel); if (channel.get()) { CDateTime::GetCurrentDateTime().GetAsTime(tMaxLastWatched); channel->SetLastWatched(tMaxLastWatched); channel->Persist(); } } CPVRChannelPtr returnChannel; for (unsigned int iChannelPtr = 0; iChannelPtr < m_members.size(); iChannelPtr++) { PVRChannelGroupMember groupMember = m_members.at(iChannelPtr); if (g_PVRClients->IsConnectedClient(groupMember.channel->ClientID()) && groupMember.channel->LastWatched() > 0 && (tMaxLastWatched == 0 || groupMember.channel->LastWatched() < tMaxLastWatched) && (tCurrentLastWatched == 0 || groupMember.channel->LastWatched() > tCurrentLastWatched)) { returnChannel = groupMember.channel; tCurrentLastWatched = returnChannel->LastWatched(); } } if (returnChannel) { CFileItemPtr retVal = CFileItemPtr(new CFileItem(*returnChannel)); return retVal; } CFileItemPtr retVal = CFileItemPtr(new CFileItem); return retVal; }
void CGUIWindowPVRGuide::UpdateViewChannel(bool bUpdateSelectedFile) { CPVRChannelPtr CurrentChannel; bool bGotCurrentChannel = g_PVRManager.GetCurrentChannel(CurrentChannel); m_parent->m_guideGrid = NULL; m_parent->m_viewControl.SetCurrentView(CONTROL_LIST_GUIDE_CHANNEL); m_parent->SetLabel(m_iControlButton, g_localizeStrings.Get(19222) + ": " + g_localizeStrings.Get(19029)); if (bGotCurrentChannel && CurrentChannel.get()) m_parent->SetLabel(CONTROL_LABELGROUP, CurrentChannel->ChannelName().c_str()); if ((!bGotCurrentChannel || g_PVRManager.GetCurrentEpg(*m_parent->m_vecItems) == 0) && CurrentChannel.get()) { CFileItemPtr item; item.reset(new CFileItem("pvr://guide/" + CurrentChannel->ChannelName() + "/empty.epg", false)); item->SetLabel(g_localizeStrings.Get(19028)); item->SetLabelPreformated(true); m_parent->m_vecItems->Add(item); } m_parent->m_viewControl.SetItems(*m_parent->m_vecItems); }
CPVRChannelPtr CPVRChannelGroupInternal::UpdateFromClient(const CPVRChannelPtr &channel, unsigned int iChannelNumber /* = 0 */) { assert(channel.get()); CSingleLock lock(m_critSection); const PVRChannelGroupMember& realChannel(GetByUniqueID(channel->StorageId())); if (realChannel.channel) { realChannel.channel->UpdateFromClient(channel); return realChannel.channel; } else { PVRChannelGroupMember newMember = { channel, iChannelNumber > 0l ? iChannelNumber : (int)m_sortedMembers.size() + 1 }; channel->UpdatePath(this); m_sortedMembers.push_back(newMember); m_members.insert(std::make_pair(channel->StorageId(), newMember)); m_bChanged = true; SortAndRenumber(); } return channel; }
bool CPVRChannelGroupInternal::RemoveFromGroup(const CPVRChannelPtr &channel) { CSingleLock lock(m_critSection); assert(channel.get()); if (!IsGroupMember(channel)) return false; /* check if this channel is currently playing if we are hiding it */ CPVRChannelPtr currentChannel(g_PVRManager.GetCurrentChannel()); if (currentChannel && currentChannel == channel) { CGUIDialogOK::ShowAndGetInput(CVariant{19098}, CVariant{19102}); return false; } /* switch the hidden flag */ if (!channel->IsHidden()) { channel->SetHidden(true); ++m_iHiddenChannels; } else { channel->SetHidden(false); if (m_iHiddenChannels > 0) --m_iHiddenChannels; } /* renumber this list */ SortAndRenumber(); /* and persist */ return channel->Persist() && Persist(); }
bool CPVRManager::PerformChannelSwitch(const CPVRChannelPtr &channel, bool bPreview) { assert(channel.get()); // 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 CFileItemPtr previousFile; { 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; } if (bPreview) { if (!g_infoManager.GetShowInfo() && m_settings.GetIntValue(CSettings::SETTING_PVRPLAYBACK_CHANNELENTRYTIMEOUT) == 0) { // no need to do anything return true; } m_currentFile.reset(new CFileItem(channel)); if (IsPlayingChannel(channel)) m_isChannelPreview = false; else m_isChannelPreview = true; return true; } m_bIsSwitchingChannels = true; CLog::Log(LOGDEBUG, "PVRManager - %s - switching to channel '%s'", __FUNCTION__, channel->ChannelName().c_str()); previousFile = std::move(m_currentFile); } 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); // set channel as selected item CGUIWindowPVRBase::SetSelectedItemPath(channel->IsRadio(), channel->Path()); UpdateLastWatched(channel); CSingleLock lock(m_critSection); m_currentFile.reset(new CFileItem(channel)); m_bIsSwitchingChannels = false; CLog::Log(LOGNOTICE, "PVRManager - %s - switched to channel '%s'", __FUNCTION__, channel->ChannelName().c_str()); } // announce OnStop if (previousFile) { CVariant data(CVariant::VariantTypeObject); data["end"] = true; ANNOUNCEMENT::CAnnouncementManager::GetInstance().Announce(ANNOUNCEMENT::Player, "xbmc", "OnStop", previousFile, data); } // announce OnPlay if (m_currentFile) { CVariant param; param["player"]["speed"] = 1; param["player"]["playerid"] = CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist(); ANNOUNCEMENT::CAnnouncementManager::GetInstance().Announce(ANNOUNCEMENT::Player, "xbmc", "OnPlay", m_currentFile, param); } return bSwitched; }
JSONRPC_STATUS CPlayerOperations::GetItem(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { PlayerType player = GetPlayer(parameterObject["playerid"]); CFileItemPtr fileItem; switch (player) { case Video: case Audio: { fileItem = CFileItemPtr(new CFileItem(g_application.CurrentFileItem())); if (fileItem->GetLabel().empty()) { if (IsPVRChannel()) { CPVRChannelPtr currentChannel; if (g_PVRManager.GetCurrentChannel(currentChannel) && currentChannel.get() != NULL) fileItem = CFileItemPtr(new CFileItem(*currentChannel.get())); } else if (player == Video) { if (!CVideoLibrary::FillFileItem(g_application.CurrentFile(), fileItem, parameterObject)) { const CVideoInfoTag *currentVideoTag = g_infoManager.GetCurrentMovieTag(); if (currentVideoTag != NULL) fileItem = CFileItemPtr(new CFileItem(*currentVideoTag)); fileItem->SetPath(g_application.CurrentFileItem().GetPath()); } } else { if (!CAudioLibrary::FillFileItem(g_application.CurrentFile(), fileItem, parameterObject)) { const MUSIC_INFO::CMusicInfoTag *currentMusicTag = g_infoManager.GetCurrentSongTag(); if (currentMusicTag != NULL) fileItem = CFileItemPtr(new CFileItem(*currentMusicTag)); fileItem->SetPath(g_application.CurrentFileItem().GetPath()); } } } if (IsPVRChannel()) break; if (player == Video) { bool additionalInfo = false; bool streamdetails = false; for (CVariant::const_iterator_array itr = parameterObject["properties"].begin_array(); itr != parameterObject["properties"].end_array(); itr++) { CStdString fieldValue = itr->asString(); if (fieldValue == "cast" || fieldValue == "set" || fieldValue == "setid" || fieldValue == "showlink" || fieldValue == "resume" || (fieldValue == "streamdetails" && !fileItem->GetVideoInfoTag()->m_streamDetails.HasItems())) additionalInfo = true; } CVideoDatabase videodatabase; if ((additionalInfo) && videodatabase.Open()) { if (additionalInfo) { switch (fileItem->GetVideoContentType()) { case VIDEODB_CONTENT_MOVIES: videodatabase.GetMovieInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_MUSICVIDEOS: videodatabase.GetMusicVideoInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_EPISODES: videodatabase.GetEpisodeInfo("", *(fileItem->GetVideoInfoTag()), fileItem->GetVideoInfoTag()->m_iDbId); break; case VIDEODB_CONTENT_TVSHOWS: case VIDEODB_CONTENT_MOVIE_SETS: default: break; } } videodatabase.Close(); } } else if (player == Audio) { if (fileItem->IsMusicDb()) { CMusicDatabase musicdb; CFileItemList items; items.Add(fileItem); CAudioLibrary::GetAdditionalSongDetails(parameterObject, items, musicdb); } } break; } case Picture: { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; CFileItemList slides; slideshow->GetSlideShowContents(slides); fileItem = slides[slideshow->CurrentSlide() - 1]; break; } case None: default: return FailedToExecute; } HandleFileItem("id", !IsPVRChannel(), "item", fileItem, parameterObject, parameterObject["properties"], result, false); return OK; }
JSONRPC_STATUS CPlayerOperations::Open(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CVariant optionShuffled = parameterObject["options"]["shuffled"]; CVariant optionRepeat = parameterObject["options"]["repeat"]; CVariant optionResume = parameterObject["options"]["resume"]; if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid")) { int playlistid = (int)parameterObject["item"]["playlistid"].asInteger(); if (playlistid < PLAYLIST_PICTURE) { // Apply the "shuffled" option if available if (optionShuffled.isBoolean()) g_playlistPlayer.SetShuffle(playlistid, optionShuffled.asBoolean(), false); // Apply the "repeat" option if available if (!optionRepeat.isNull()) g_playlistPlayer.SetRepeat(playlistid, (REPEAT_STATE)ParseRepeatState(optionRepeat), false); } switch (playlistid) { case PLAYLIST_MUSIC: case PLAYLIST_VIDEO: CApplicationMessenger::Get().MediaPlay(playlistid, (int)parameterObject["item"]["position"].asInteger()); OnPlaylistChanged(); break; case PLAYLIST_PICTURE: return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean()); break; } return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("path")) { bool random = (optionShuffled.isBoolean() && optionShuffled.asBoolean()) || (!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean()); return StartSlideshow(parameterObject["item"]["path"].asString(), parameterObject["item"]["recursive"].asBoolean(), random); } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("partymode")) { if (g_partyModeManager.IsEnabled()) g_partyModeManager.Disable(); CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + parameterObject["item"]["partymode"].asString() + "))"); return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("channelid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRChannelGroupsContainer *channelGroupContainer = g_PVRChannelGroups; if (channelGroupContainer == NULL) return FailedToExecute; CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["item"]["channelid"].asInteger()); if (channel == NULL) return InvalidParams; CApplicationMessenger::Get().MediaPlay(CFileItem(*channel.get())); return ACK; } else { CFileItemList list; if (FillFileItemList(parameterObject["item"], list) && list.Size() > 0) { bool slideshow = true; for (int index = 0; index < list.Size(); index++) { if (!list[index]->IsPicture()) { slideshow = false; break; } } if (slideshow) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; SendSlideshowAction(ACTION_STOP); slideshow->Reset(); for (int index = 0; index < list.Size(); index++) slideshow->Add(list[index].get()); return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean()); } else { // Handle "shuffled" option if (optionShuffled.isBoolean()) list.SetProperty("shuffled", optionShuffled); // Handle "repeat" option if (!optionRepeat.isNull()) list.SetProperty("repeat", ParseRepeatState(optionRepeat)); // Handle "resume" option if (list.Size() == 1) { if (optionResume.isBoolean() && optionResume.asBoolean()) list[0]->m_lStartOffset = STARTOFFSET_RESUME; else if (optionResume.isDouble()) list[0]->SetProperty("StartPercent", optionResume); else if (optionResume.isObject()) list[0]->m_lStartOffset = (int)(ParseTimeInSeconds(optionResume) * 75.0); } CApplicationMessenger::Get().MediaPlay(list); } return ACK; } else return InvalidParams; } return InvalidParams; }
bool CPVRManager::PerformChannelSwitch(const CPVRChannelPtr &channel, bool bPreview) { assert(channel.get()); // 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); // 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; }
JSONRPC_STATUS CPlayerOperations::Open(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CVariant options = parameterObject["options"]; CVariant optionShuffled = options["shuffled"]; CVariant optionRepeat = options["repeat"]; CVariant optionResume = options["resume"]; CVariant optionPlayer = options["playercoreid"]; if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid")) { int playlistid = (int)parameterObject["item"]["playlistid"].asInteger(); if (playlistid < PLAYLIST_PICTURE) { // Apply the "shuffled" option if available if (optionShuffled.isBoolean()) g_playlistPlayer.SetShuffle(playlistid, optionShuffled.asBoolean(), false); // Apply the "repeat" option if available if (!optionRepeat.isNull()) g_playlistPlayer.SetRepeat(playlistid, (REPEAT_STATE)ParseRepeatState(optionRepeat), false); } int playlistStartPosition = (int)parameterObject["item"]["position"].asInteger(); switch (playlistid) { case PLAYLIST_MUSIC: case PLAYLIST_VIDEO: CApplicationMessenger::Get().MediaPlay(playlistid, playlistStartPosition); OnPlaylistChanged(); break; case PLAYLIST_PICTURE: { std::string firstPicturePath; if (playlistStartPosition > 0) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (slideshow != NULL) { CFileItemList list; slideshow->GetSlideShowContents(list); if (playlistStartPosition < list.Size()) firstPicturePath = list.Get(playlistStartPosition)->GetPath(); } } return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean(), firstPicturePath); break; } } return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("path")) { bool random = (optionShuffled.isBoolean() && optionShuffled.asBoolean()) || (!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean()); return StartSlideshow(parameterObject["item"]["path"].asString(), parameterObject["item"]["recursive"].asBoolean(), random); } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("partymode")) { if (g_partyModeManager.IsEnabled()) g_partyModeManager.Disable(); CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + parameterObject["item"]["partymode"].asString() + "))"); return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("channelid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRChannelGroupsContainer *channelGroupContainer = g_PVRChannelGroups; if (channelGroupContainer == NULL) return FailedToExecute; CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["item"]["channelid"].asInteger()); if (channel == NULL) return InvalidParams; if ((g_PVRManager.IsPlayingRadio() && channel.get()->IsRadio()) || (g_PVRManager.IsPlayingTV() && !channel.get()->IsRadio())) g_application.m_pPlayer->SwitchChannel(*channel.get()); else CApplicationMessenger::Get().MediaPlay(CFileItem(*channel.get())); return ACK; } else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("recordingid")) { if (!g_PVRManager.IsStarted()) return FailedToExecute; CPVRRecordings *recordingsContainer = g_PVRRecordings; if (recordingsContainer == NULL) return FailedToExecute; CFileItemPtr fileItem = recordingsContainer->GetById((int)parameterObject["item"]["recordingid"].asInteger()); if (fileItem == NULL) return InvalidParams; CApplicationMessenger::Get().MediaPlay(*fileItem); return ACK; } else { CFileItemList list; if (FillFileItemList(parameterObject["item"], list) && list.Size() > 0) { bool slideshow = true; for (int index = 0; index < list.Size(); index++) { if (!list[index]->IsPicture()) { slideshow = false; break; } } if (slideshow) { CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW); if (!slideshow) return FailedToExecute; SendSlideshowAction(ACTION_STOP); slideshow->Reset(); for (int index = 0; index < list.Size(); index++) slideshow->Add(list[index].get()); return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean()); } else { // Handle the "playerid" option if (!optionPlayer.isNull()) { PLAYERCOREID playerId = EPC_NONE; if (optionPlayer.isInteger()) { playerId = (PLAYERCOREID)optionPlayer.asInteger(); // check if the there's actually a player with the given player ID if (CPlayerCoreFactory::Get().GetPlayerConfig(playerId) == NULL) return InvalidParams; // check if the player can handle at least the first item in the list VECPLAYERCORES possiblePlayers; CPlayerCoreFactory::Get().GetPlayers(*list.Get(0).get(), possiblePlayers); VECPLAYERCORES::const_iterator matchingPlayer = std::find(possiblePlayers.begin(), possiblePlayers.end(), playerId); if (matchingPlayer == possiblePlayers.end()) return InvalidParams; } else if (!optionPlayer.isString() || optionPlayer.asString().compare("default") != 0) return InvalidParams; // set the next player to be used g_application.m_eForcedNextPlayer = playerId; } // Handle "shuffled" option if (optionShuffled.isBoolean()) list.SetProperty("shuffled", optionShuffled); // Handle "repeat" option if (!optionRepeat.isNull()) list.SetProperty("repeat", ParseRepeatState(optionRepeat)); // Handle "resume" option if (list.Size() == 1) { if (optionResume.isBoolean() && optionResume.asBoolean()) list[0]->m_lStartOffset = STARTOFFSET_RESUME; else if (optionResume.isDouble()) list[0]->SetProperty("StartPercent", optionResume); else if (optionResume.isObject()) list[0]->m_lStartOffset = (int)(ParseTimeInSeconds(optionResume) * 75.0); } CApplicationMessenger::Get().MediaPlay(list); } return ACK; } else return InvalidParams; } return InvalidParams; }