Esempio n. 1
0
void CPVRManager::CloseStream(void)
{
  CPVRChannelPtr channel;
  bool bPersistChannel(false);

  {
    CSingleLock lock(m_critSection);

    if (m_addons->GetPlayingChannel(channel))
    {
      /* store current time in iLastWatched */
      time_t tNow;
      CDateTime::GetCurrentDateTime().GetAsTime(tNow);
      channel->SetLastWatched(tNow);
      bPersistChannel = true;

      m_channelGroups->SetLastPlayedGroup(GetPlayingGroup(channel->IsRadio()));
    }

    m_addons->CloseStream();
    SAFE_DELETE(m_currentFile);
  }

  if (bPersistChannel)
    channel->Persist();
}
Esempio n. 2
0
void CPVRManager::UpdateLastWatched(const CPVRChannelPtr &channel)
{
  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);
}
Esempio n. 3
0
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;

  CPVRChannelPtr playingChannel;
  CPVRChannelGroupPtr group;
  bool bPersistChanges(false);
  if ((bReturn = m_addons->OpenStream(*channel.GetPVRChannelInfoTag(), false)) != false)
  {
    CSingleLock lock(m_critSection);
    if(m_currentFile)
      delete m_currentFile;
    m_currentFile = new CFileItem(channel);

    if (m_addons->GetPlayingChannel(playingChannel))
    {
      time_t tNow;
      CDateTime::GetCurrentDateTime().GetAsTime(tNow);

      /* update last watched timestamp for channel */
      playingChannel->SetLastWatched(tNow);

      /* update last watched timestamp for group */
      group = g_PVRManager.GetPlayingGroup(playingChannel->IsRadio());
      group->SetLastWatched(tNow);

      /* update last played group */
      m_channelGroups->SetLastPlayedGroup(group);

      bPersistChanges = true;
    }
  }

  if (bPersistChanges)
  {
    playingChannel->Persist();
    group->Persist();
  }

  return bReturn;
}
Esempio n. 4
0
void CPVRManager::UpdateLastWatched(const CPVRChannelPtr &channel, const CDateTime& time)
{
  time_t iTime;
  time.GetAsTime(iTime);

  channel->SetLastWatched(iTime);

  // update last watched timestamp for group
  CPVRChannelGroupPtr group(GetPlayingGroup(channel->IsRadio()));
  group->SetLastWatched(iTime);

  /* update last played group */
  m_channelGroups->SetLastPlayedGroup(group);
}
Esempio n. 5
0
void CPVRManager::UpdateLastWatched(CPVRChannel &channel)
{
  time_t tNow;
  CDateTime::GetCurrentDateTime().GetAsTime(tNow);

  // update last watched timestamp for channel
  // NOTE: method could be called with a fileitem copy as argument so we need to obtain the right channel instance
  CPVRChannelPtr channelPtr = m_channelGroups->GetChannelById(channel.ChannelID());
  channelPtr->SetLastWatched(tNow);
  channelPtr->Persist();

  // update last watched timestamp for group
  CPVRChannelGroupPtr group = GetPlayingGroup(channel.IsRadio());
  group->SetLastWatched(tNow);
  group->Persist();

  /* update last played group */
  m_channelGroups->SetLastPlayedGroup(group);
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
void CPVRManager::CloseStream(void)
{
  CPVRChannelPtr channel;
  CPVRChannelGroupPtr group;
  bool bPersistChanges(false);

  {
    CSingleLock lock(m_critSection);

    if (m_addons->GetPlayingChannel(channel))
    {
      time_t tNow;
      CDateTime::GetCurrentDateTime().GetAsTime(tNow);

      /* update last watched timestamp for channel */
      channel->SetLastWatched(tNow);

      /* update last watched timestamp for group */
      group = g_PVRManager.GetPlayingGroup(channel->IsRadio());
      group->SetLastWatched(tNow);

      /* update last played group */
      m_channelGroups->SetLastPlayedGroup(group);

      bPersistChanges = true;
      
      // store channel settings
      g_application.SaveFileState();
    }

    m_addons->CloseStream();
    SAFE_DELETE(m_currentFile);
  }

  if (bPersistChanges)
  {
    channel->Persist();
    group->Persist();
  }
}
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;

  CPVRChannelPtr playingChannel;
  bool bPersistChannel(false);
  if ((bReturn = m_addons->OpenStream(*channel.GetPVRChannelInfoTag(), false)) != false)
  {
    CSingleLock lock(m_critSection);
    if(m_currentFile)
      delete m_currentFile;
    m_currentFile = new CFileItem(channel);

    if (m_addons->GetPlayingChannel(playingChannel))
    {
      /* store current time in iLastWatched */
      time_t tNow;
      CDateTime::GetCurrentDateTime().GetAsTime(tNow);
      playingChannel->SetLastWatched(tNow);
      bPersistChannel = true;
    }
  }

  if (bPersistChannel)
    playingChannel->Persist();

  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());

    CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error,
        g_localizeStrings.Get(19166), // PVR information
        g_localizeStrings.Get(19035)); // This channel cannot be played. Check the log for details.
  }
  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;
}
Esempio n. 10
0
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;
}