Example #1
0
HRESULT CSchemeHandler::OnSourceOpen(_In_ IMFAsyncResult *pResult)
{
    ComPtr<IUnknown> spState = pResult->GetStateNoAddRef();
    if (!spState)
    {
        return MF_E_UNEXPECTED;
    }
    ComPtr<IMFAsyncResult> spSavedResult;
    HRESULT hr = S_OK;

    hr = spState.As(&spSavedResult);
    if (FAILED(hr))
    {
        TRACEHR_RET(hr);
    }

    ComPtr<IUnknown> spunkSource;
    ComPtr<IMFMediaSource> spSource;
    hr = spSavedResult->GetObject(&spunkSource);

    if (SUCCEEDED(hr))
    {
        hr = spunkSource.As(&spSource);
        if (SUCCEEDED(hr))
        {
            CMediaSource *pSource = static_cast<CMediaSource *>(spSource.Get());
            hr = pSource->EndOpen(pResult);
        }
    }

    spSavedResult->SetStatus(hr);    
    hr = MFInvokeCallback(spSavedResult.Get());

    TRACEHR_RET(hr);
}
Example #2
0
void CGUIDialogMediaSource::OnOK()
{
  // verify the path by doing a GetDirectory.
  CFileItemList items;

  CMediaSource share;
  share.FromNameAndPaths(m_type, m_name, GetPaths());
  // hack: Need to temporarily add the share, then get path, then remove share
  VECSOURCES *shares = CMediaSourceSettings::Get().GetSources(m_type);
  if (shares)
    shares->push_back(share);
  if (StringUtils::StartsWithNoCase(share.strPath, "plugin://") || CDirectory::GetDirectory(share.strPath, items, "", DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_ALLOW_PROMPT) || CGUIDialogYesNo::ShowAndGetInput(1001,1025,1003,1004))
  {
    m_confirmed = true;
    Close();
    if (m_type == "video" && !URIUtils::IsLiveTV(share.strPath) && 
        !StringUtils::StartsWithNoCase(share.strPath, "rss://") &&
        !StringUtils::StartsWithNoCase(share.strPath, "upnp://"))
    {
      CGUIWindowVideoBase::OnAssignContent(share.strPath);
    }
  }

  // and remove the share again
  if (shares)
    shares->erase(--shares->end());
}
Example #3
0
void CGUIDialogMediaSource::OnOK()
{
  // verify the path by doing a GetDirectory.
  CFileItemList items;

  CMediaSource share;
  share.FromNameAndPaths(m_type, m_name, GetPaths());
  // hack: Need to temporarily add the share, then get path, then remove share
  VECSOURCES *shares = g_settings.GetSourcesFromType(m_type);
  if (shares)
    shares->push_back(share);
  if (share.strPath.Left(9).Equals("plugin://") || CDirectory::GetDirectory(share.strPath, items, "", false, true) || CGUIDialogYesNo::ShowAndGetInput(1001,1025,1003,1004))
  {
    m_confirmed = true;
    Close();
  }

  // Special handling of multipath:// shares.
  // * GetScraperForPath takes the first path of the multipath:// element to fetch needed scraper and scan settings.
  // * SetScraperForPath loops through all elements and adds the appropriate settings for each path.
  if (CUtil::IsMultiPath(share.strPath))
  {
    CVideoDatabase database;
    database.Open();
    m_info = database.GetScraperForPath(share.strPath, m_settings);
    database.SetScraperForPath(share.strPath, m_info, m_settings);
    database.Close();
  }

  // and remove the share again
  if (shares)
    shares->erase(--shares->end());
}
Example #4
0
void CGUIDialogMediaSource::OnOK()
{
    // verify the path by doing a GetDirectory.
    CFileItemList items;

    CMediaSource share;
    share.FromNameAndPaths(m_type, m_name, GetPaths());
    // hack: Need to temporarily add the share, then get path, then remove share
    VECSOURCES *shares = g_settings.GetSourcesFromType(m_type);
    if (shares)
        shares->push_back(share);
    if (share.strPath.Left(9).Equals("plugin://") || CDirectory::GetDirectory(share.strPath, items, "", false, true) || CGUIDialogYesNo::ShowAndGetInput(1001,1025,1003,1004))
    {
        m_confirmed = true;
        Close();
        if (m_type == "video" && !URIUtils::IsLiveTV(share.strPath) &&
                !share.strPath.Left(6).Equals("rss://"))
        {
            CGUIWindowVideoBase::OnAssignContent(share.strPath, 0, m_info, m_settings);
        }
    }

    // and remove the share again
    if (shares)
        shares->erase(--shares->end());
}
bool CGUIDialogMediaSource::OnMessage(CGUIMessage& message)
{
  switch ( message.GetMessage() )
  {
  case GUI_MSG_CLICKED:
    {
      int iControl = message.GetSenderId();
      int iAction = message.GetParam1();
      if (iControl == CONTROL_PATH && (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK))
        OnPath(GetSelectedItem());
      else if (iControl == CONTROL_PATH_BROWSE)
        OnPathBrowse(GetSelectedItem());
      else if (iControl == CONTROL_PATH_ADD)
        OnPathAdd();
      else if (iControl == CONTROL_PATH_REMOVE)
        OnPathRemove(GetSelectedItem());
      else if (iControl == CONTROL_NAME)
      {
        OnEditChanged(iControl, m_name);
        UpdateButtons();
      }
      else if (iControl == CONTROL_OK)
        OnOK();
      else if (iControl == CONTROL_CANCEL)
        OnCancel();
      else if (iControl == CONTROL_CONTENT)
      {
        CMediaSource share;
        share.FromNameAndPaths("video", m_name, GetPaths());

        CGUIDialogContentSettings::ShowForDirectory(share.strPath,m_info,m_settings,m_bRunScan);
      }
      return true;
    }
    break;
  case GUI_MSG_WINDOW_INIT:
    {
      m_confirmed = false;
      m_bRunScan = false;
      m_bNameChanged=false;
      m_settings.parent_name = false;
      m_settings.recurse = 0;
      UpdateButtons();
    }
    break;
  case GUI_MSG_SETFOCUS:
    if (message.GetControlId() == CONTROL_PATH_BROWSE ||
             message.GetControlId() == CONTROL_PATH_ADD ||
             message.GetControlId() == CONTROL_PATH_REMOVE)
    {
      HighlightItem(GetSelectedItem());
    }
    else
      HighlightItem(-1);
    break;
  }
  return CGUIDialog::OnMessage(message);
}
void CGUIDialogMediaSource::OnOK()
{
  // verify the path by doing a GetDirectory.
  CFileItemList items;

  CMediaSource share;
  share.FromNameAndPaths(m_type, m_name, GetPaths());
  // hack: Need to temporarily add the share, then get path, then remove share
  VECSOURCES *shares = g_settings.GetSourcesFromType(m_type);
  if (shares)
    shares->push_back(share);
  if (share.strPath.Left(9).Equals("plugin://") || CDirectory::GetDirectory(share.strPath, items, "", false, true) || CGUIDialogYesNo::ShowAndGetInput(1001,1025,1003,1004))
  {
    if (share.strPath.Left(9).Equals("plugin://"))
    {
      CStdString strPath=share.strPath;
      strPath.Replace("plugin://","special://home/system/plugins/");
      CFileItem item(strPath,true);
      item.SetCachedProgramThumb();
      if (!item.HasThumbnail())
        item.SetUserProgramThumb();
      if (!item.HasThumbnail())
      {
        item.SetPath(URIUtils::AddFileToFolder(strPath,"default.py"));
        item.m_bIsFolder = false;
        item.SetCachedProgramThumb();
        if (!item.HasThumbnail())
          item.SetUserProgramThumb();
      }
      if (item.HasThumbnail() && m_paths->Size())
      {
        CFileItem item2(share.strPath,true);
        XFILE::CFile::Cache(item.GetThumbnailImage(),item2.GetCachedProgramThumb());
        m_paths->Get(0)->SetThumbnailImage(item2.GetCachedProgramThumb());
      }
    }
    m_confirmed = true;
    Close();
  }

  // Special handling of multipath:// shares.
  // * GetScraperForPath takes the first path of the multipath:// element to fetch needed scraper and scan settings.
  // * SetScraperForPath loops through all elements and adds the appropriate settings for each path.
  if (URIUtils::IsMultiPath(share.strPath))
  {
    CVideoDatabase database;
    database.Open();
    database.GetScraperForPath(share.strPath, m_info, m_settings);
    database.SetScraperForPath(share.strPath, m_info, m_settings);
    database.Close();
  }

  // and remove the share again
  if (shares)
    shares->erase(--shares->end());
}
void CGUIDialogAudioSubtitleSettings::OnSettingAction(const CSetting *setting)
{
  if (setting == NULL)
    return;

  CGUIDialogSettingsManualBase::OnSettingAction(setting);
  
  const std::string &settingId = setting->GetId();
  if (settingId == SETTING_SUBTITLE_BROWSER)
  {
    CStdString strPath;
    if (URIUtils::IsInRAR(g_application.CurrentFileItem().GetPath()) || URIUtils::IsInZIP(g_application.CurrentFileItem().GetPath()))
      strPath = CURL(g_application.CurrentFileItem().GetPath()).GetHostName();
    else
      strPath = g_application.CurrentFileItem().GetPath();

    std::string strMask = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.idx|.rar|.zip";
    if (g_application.GetCurrentPlayer() == EPC_DVDPLAYER)
      strMask = ".srt|.rar|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa|.txt";
    VECSOURCES shares(*CMediaSourceSettings::Get().GetSources("video"));
    if (CMediaSettings::Get().GetAdditionalSubtitleDirectoryChecked() != -1 && !CSettings::Get().GetString("subtitles.custompath").empty())
    {
      CMediaSource share;
      std::vector<std::string> paths;
      paths.push_back(URIUtils::GetDirectory(strPath));
      paths.push_back(CSettings::Get().GetString("subtitles.custompath"));
      share.FromNameAndPaths("video",g_localizeStrings.Get(21367),paths);
      shares.push_back(share);
      strPath = share.strPath;
      URIUtils::AddSlashAtEnd(strPath);
    }
    if (CGUIDialogFileBrowser::ShowAndGetFile(shares, strMask, g_localizeStrings.Get(293), strPath, false, true)) // "subtitles"
    {
      if (URIUtils::HasExtension(strPath, ".sub"))
      {
        if (XFILE::CFile::Exists(URIUtils::ReplaceExtension(strPath, ".idx")))
          strPath = URIUtils::ReplaceExtension(strPath, ".idx");
      }
      
      int id = g_application.m_pPlayer->AddSubtitle(strPath);
      if (id >= 0)
      {
        m_subtitleStream = id;
        g_application.m_pPlayer->SetSubtitle(m_subtitleStream);
        g_application.m_pPlayer->SetSubtitleVisible(true);
      }
      CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleCached = true;
      Close();
    }
  }
  else if (settingId == SETTING_AUDIO_MAKE_DEFAULT)
    Save();
}
void CGUIDialogAudioSubtitleSettings::OnSettingAction(const CSetting *setting)
{
  if (setting == NULL)
    return;

  CGUIDialogSettingsManualBase::OnSettingAction(setting);
  
  const std::string &settingId = setting->GetId();
  if (settingId == SETTING_AUDIO_DSP)
  {
    g_windowManager.ActivateWindow(WINDOW_DIALOG_AUDIO_DSP_OSD_SETTINGS);
  }
  else if (settingId == SETTING_SUBTITLE_BROWSER)
  {
    std::string strPath;
    if (URIUtils::IsInRAR(g_application.CurrentFileItem().GetPath()) || URIUtils::IsInZIP(g_application.CurrentFileItem().GetPath()))
      strPath = CURL(g_application.CurrentFileItem().GetPath()).GetHostName();
    else
      strPath = g_application.CurrentFileItem().GetPath();

    std::string strMask = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.idx|.rar|.zip";
    if (g_application.GetCurrentPlayer() == "VideoPlayer")
      strMask = ".srt|.rar|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa|.txt";
    VECSOURCES shares(*CMediaSourceSettings::GetInstance().GetSources("video"));
    if (CMediaSettings::GetInstance().GetAdditionalSubtitleDirectoryChecked() != -1 && !CServiceBroker::GetSettings().GetString(CSettings::SETTING_SUBTITLES_CUSTOMPATH).empty())
    {
      CMediaSource share;
      std::vector<std::string> paths;
      paths.push_back(URIUtils::GetDirectory(strPath));
      paths.push_back(CServiceBroker::GetSettings().GetString(CSettings::SETTING_SUBTITLES_CUSTOMPATH));
      share.FromNameAndPaths("video",g_localizeStrings.Get(21367),paths);
      shares.push_back(share);
      strPath = share.strPath;
      URIUtils::AddSlashAtEnd(strPath);
    }
    if (CGUIDialogFileBrowser::ShowAndGetFile(shares, strMask, g_localizeStrings.Get(293), strPath, false, true)) // "subtitles"
    {
      if (URIUtils::HasExtension(strPath, ".sub"))
      {
        if (XFILE::CFile::Exists(URIUtils::ReplaceExtension(strPath, ".idx")))
          strPath = URIUtils::ReplaceExtension(strPath, ".idx");
      }
      
      g_application.m_pPlayer->AddSubtitle(strPath);
      Close();
    }
  }
  else if (settingId == SETTING_AUDIO_MAKE_DEFAULT)
    Save();
}
std::string CGUIDialogSubtitleSettings::BrowseForSubtitle()
{
  std::string extras;
  for (const auto& vfsAddon : CServiceBroker::GetVFSAddonCache().GetAddonInstances())
  {
    if (vfsAddon->ID() == "vfs.rar" || vfsAddon->ID() == "vfs.libarchive")
      extras += '|' + vfsAddon->GetExtensions();
  }

  std::string strPath;
  if (URIUtils::IsInRAR(g_application.CurrentFileItem().GetPath()) || URIUtils::IsInZIP(g_application.CurrentFileItem().GetPath()))
    strPath = CURL(g_application.CurrentFileItem().GetPath()).GetHostName();
  else
    strPath = g_application.CurrentFileItem().GetPath();

  std::string strMask = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.idx|.zip";

  if (g_application.GetCurrentPlayer() == "VideoPlayer")
    strMask = ".srt|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa|.txt";

  strMask += extras;

  VECSOURCES shares(*CMediaSourceSettings::GetInstance().GetSources("video"));
  if (CMediaSettings::GetInstance().GetAdditionalSubtitleDirectoryChecked() != -1 && !CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_SUBTITLES_CUSTOMPATH).empty())
  {
    CMediaSource share;
    std::vector<std::string> paths;
    paths.push_back(URIUtils::GetDirectory(strPath));
    paths.push_back(CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_SUBTITLES_CUSTOMPATH));
    share.FromNameAndPaths("video",g_localizeStrings.Get(21367),paths);
    shares.push_back(share);
    strPath = share.strPath;
    URIUtils::AddSlashAtEnd(strPath);
  }

  if (CGUIDialogFileBrowser::ShowAndGetFile(shares, strMask, g_localizeStrings.Get(293), strPath, false, true)) // "subtitles"
  {
    if (URIUtils::HasExtension(strPath, ".sub"))
    {
      if (XFILE::CFile::Exists(URIUtils::ReplaceExtension(strPath, ".idx")))
        strPath = URIUtils::ReplaceExtension(strPath, ".idx");
    }

    return strPath;
  }

  return "";
}
Example #10
0
// \brief Show CGUIDialogMediaSource dialog and prompt for a new media source.
// \return True if the media source is added, false otherwise.
bool CGUIDialogMediaSource::ShowAndAddMediaSource(const CStdString &type)
{
    CGUIDialogMediaSource *dialog = (CGUIDialogMediaSource *)g_windowManager.GetWindow(WINDOW_DIALOG_MEDIA_SOURCE);
    if (!dialog) return false;
    dialog->Initialize();
    dialog->SetShare(CMediaSource());
    dialog->SetTypeOfMedia(type);
    dialog->DoModal();
    bool confirmed(dialog->IsConfirmed());
    if (confirmed)
    {   // yay, add this share
        CMediaSource share;
        unsigned int i,j=2;
        bool bConfirmed=false;
        VECSOURCES* pShares = g_settings.GetSourcesFromType(type);
        CStdString strName = dialog->m_name;
        while (!bConfirmed)
        {
            for (i=0; i<pShares->size(); ++i)
            {
                if ((*pShares)[i].strName.Equals(strName))
                    break;
            }
            if (i < pShares->size()) // found a match -  try next
                strName.Format("%s (%i)",dialog->m_name,j++);
            else
                bConfirmed = true;
        }
        share.FromNameAndPaths(type, strName, dialog->GetPaths());
        if (dialog->m_paths->Size() > 0) {
            share.m_strThumbnailImage = dialog->m_paths->Get(0)->GetThumbnailImage();
        }
        g_settings.AddShare(type, share);

        if (type == "video")
        {
            if (dialog->m_bRunScan)
            {
                CGUIDialogVideoScan* scanner = (CGUIDialogVideoScan*)g_windowManager.GetWindow(WINDOW_DIALOG_VIDEO_SCAN);
                if (scanner)
                    scanner->StartScanning(share.strPath, true);
            }
        }
    }
    dialog->m_paths->Clear();
    return confirmed;
}
Example #11
0
void CGUIViewState::AddLiveTVSources()
{
  VECSOURCES *sources = g_settings.GetSourcesFromType("video");
  for (IVECSOURCES it = sources->begin(); it != sources->end(); it++)
  {
    if (URIUtils::IsLiveTV((*it).strPath))
    {
      CMediaSource source;
      source.strPath = (*it).strPath;
      source.strName = (*it).strName;
      source.vecPaths = (*it).vecPaths;
      source.m_strThumbnailImage = "";
      source.FromNameAndPaths("video", source.strName, source.vecPaths);
      m_sources.push_back(source);
    }
  }
}
Example #12
0
void CBoxeeMediaSourceList::addSource(CBoxeeMediaSource source)
{
  CMediaSource xbmcSource;
  std::vector<CStdString> paths;
  paths.push_back(source.path);
  xbmcSource.m_iScanType = source.scanType;
  xbmcSource.m_strThumbnailImage = source.thumbPath;
  xbmcSource.m_adult = source.isAdult;
  xbmcSource.m_country = source.country;
  xbmcSource.m_countryAllow = source.countryAllow;

  std::string sourceType;
  
  if (source.isVideo)
  {
    xbmcSource.FromNameAndPaths("video", source.name, paths);
    g_settings.AddShare("video", xbmcSource);
	  sourceType = "video";
  }  

  if (source.isMusic)
  {
    xbmcSource.FromNameAndPaths("music", source.name, paths);
    g_settings.AddShare("music", xbmcSource);
	  sourceType = "music";
  }  

  if (source.isPicture)
  {
    xbmcSource.FromNameAndPaths("pictures", source.name, paths);
    g_settings.AddShare("pictures", xbmcSource);
	  sourceType = "pictures";
  }  

  CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addSource, new source added, type = %s, path = %s", sourceType.c_str(), source.path.c_str());

  g_settings.SaveSources();
  load();
}
Example #13
0
bool CAVMediaFlow::GetStatus(u_int32_t valueName, void* pValue) 
{
	CMediaSource* source = NULL;
	if (m_videoSource) {
		source = m_videoSource;
	} else if (m_audioSource) {
		source = m_audioSource;
	} else if (m_textSource) {
	  source = m_textSource;
	}

	switch (valueName) {
	case FLOW_STATUS_DONE: 
		{
		bool done = true;
		if (m_videoSource) {
			done = m_videoSource->IsDone();
		}
		if (m_audioSource) {
			done = (done && m_audioSource->IsDone());
		}
		if (m_textSource) {
		  done = (done && m_textSource->IsDone());
		}
		*(bool*)pValue = done;
		}
		break;
	case FLOW_STATUS_PROGRESS:
		if (source) {
			*(float*)pValue = source->GetProgress();
		} else {
			*(float*)pValue = 0.0;
		}
		break;
	default:
	  return false;
	}
	return true;
}
Example #14
0
// \brief Show CGUIDialogMediaSource dialog and prompt for a new media source.
// \return True if the media source is added, false otherwise.
bool CGUIDialogMediaSource::ShowAndAddMediaSource(const CStdString &type)
{
  CGUIDialogMediaSource *dialog = (CGUIDialogMediaSource *)g_windowManager.GetWindow(WINDOW_DIALOG_MEDIA_SOURCE);
  if (!dialog) return false;
  dialog->Initialize();
  dialog->SetShare(CMediaSource());
  dialog->SetTypeOfMedia(type);
  dialog->DoModal();
  bool confirmed(dialog->IsConfirmed());
  if (confirmed)
  { // yay, add this share
    CMediaSource share;
    unsigned int i,j=2;
    bool bConfirmed=false;
    VECSOURCES* pShares = CMediaSourceSettings::Get().GetSources(type);
    CStdString strName = dialog->m_name;
    while (!bConfirmed)
    {
      for (i=0;i<pShares->size();++i)
      {
        if ((*pShares)[i].strName.Equals(strName))
          break;
      }
      if (i < pShares->size()) // found a match -  try next
        strName = StringUtils::Format("%s (%i)", dialog->m_name.c_str(), j++);
      else
        bConfirmed = true;
    }
    share.FromNameAndPaths(type, strName, dialog->GetPaths());
    if (dialog->m_paths->Size() > 0) {
      share.m_strThumbnailImage = dialog->m_paths->Get(0)->GetArt("thumb");
    }
    CMediaSourceSettings::Get().AddShare(type, share);
  }
  dialog->m_paths->Clear();
  return confirmed;
}
Example #15
0
bool CGUIDialogMediaSource::ShowAndEditMediaSource(const CStdString &type, const CMediaSource &share)
{
    CStdString strOldName = share.strName;
    CGUIDialogMediaSource *dialog = (CGUIDialogMediaSource *)g_windowManager.GetWindow(WINDOW_DIALOG_MEDIA_SOURCE);
    if (!dialog) return false;
    dialog->Initialize();
    dialog->SetShare(share);
    dialog->SetTypeOfMedia(type, true);
    dialog->DoModal();
    bool confirmed(dialog->IsConfirmed());
    if (confirmed)
    {   // yay, add this share
        unsigned int i,j=2;
        bool bConfirmed=false;
        VECSOURCES* pShares = g_settings.GetSourcesFromType(type);
        CStdString strName = dialog->m_name;
        while (!bConfirmed)
        {
            for (i=0; i<pShares->size(); ++i)
            {
                if ((*pShares)[i].strName.Equals(strName))
                    break;
            }
            if (i < pShares->size() && (*pShares)[i].strName != strOldName) // found a match -  try next
                strName.Format("%s (%i)",dialog->m_name,j++);
            else
                bConfirmed = true;
        }

        CMediaSource newShare;
        newShare.FromNameAndPaths(type, strName, dialog->GetPaths());
        g_settings.UpdateShare(type, strOldName, newShare);
    }
    dialog->m_paths->Clear();
    return confirmed;
}
void CGUIDialogAudioSubtitleSettings::OnSettingChanged(SettingInfo &setting)
{
  // check and update anything that needs it
  if (setting.id == AUDIO_SETTINGS_VOLUME)
    g_application.SetVolume(m_volume, false); //false - value is not in percent
  else if (setting.id == AUDIO_SETTINGS_VOLUME_AMPLIFICATION)
  {
    g_application.m_pPlayer->SetDynamicRangeCompression((long)(CMediaSettings::Get().GetCurrentVideoSettings().m_VolumeAmplification * 100));
  }
  else if (setting.id == AUDIO_SETTINGS_DELAY)
  {
    g_application.m_pPlayer->SetAVDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay);
  }
  else if (setting.id == AUDIO_SETTINGS_STREAM)
  {
    // first check if it's a stereo track that we can change between stereo, left and right
    if (g_application.m_pPlayer->GetAudioStreamCount() == 1)
    {
      if (setting.max == 2)
      { // we're in the case we want - call the code to switch channels etc.
        // update the screen setting...
        CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = -1 - m_audioStream;
        // call monkeyh1's code here...
        //bool bAudioOnAllSpeakers = (CSettings::Get().GetInt("audiooutput.mode") == AUDIO_IEC958) && CMediaSettings::Get().GetCurrentVideoSettings().m_OutputToAllSpeakers;
        return;
      }
    }
    // only change the audio stream if a different one has been asked for
    if (g_application.m_pPlayer->GetAudioStream() != m_audioStream)
    {
      CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = m_audioStream;
      g_application.m_pPlayer->SetAudioStream(m_audioStream);    // Set the audio stream to the one selected
      EnableSettings(AUDIO_SETTINGS_VOLUME, !g_application.m_pPlayer->IsPassthrough());
    }
  }
  else if (setting.id == AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS)
  {
    g_application.Restart();
  }
  else if (setting.id == AUDIO_SETTINGS_DIGITAL_ANALOG)
  {
    CSettings::Get().SetBool("audiooutput.passthrough", !m_outputmode);

    EnableSettings(AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS, true);
    EnableSettings(AUDIO_SETTINGS_VOLUME, !g_application.m_pPlayer->IsPassthrough());
  }
  else if (setting.id == SUBTITLE_SETTINGS_ENABLE)
  {
    CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = m_subtitleVisible;
    g_application.m_pPlayer->SetSubtitleVisible(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn);
  }
  else if (setting.id == SUBTITLE_SETTINGS_DELAY)
  {
    g_application.m_pPlayer->SetSubTitleDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay);
  }
  else if (setting.id == SUBTITLE_SETTINGS_STREAM && setting.max > 0)
  {
    CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = m_subtitleStream;
    g_application.m_pPlayer->SetSubtitle(m_subtitleStream);
  }
  else if (setting.id == SUBTITLE_SETTINGS_BROWSER)
  {
    CStdString strPath;
    if (URIUtils::IsInRAR(g_application.CurrentFileItem().GetPath()) || URIUtils::IsInZIP(g_application.CurrentFileItem().GetPath()))
    {
      CURL url(g_application.CurrentFileItem().GetPath());
      strPath = url.GetHostName();
    }
    else
      strPath = g_application.CurrentFileItem().GetPath();

    CStdString strMask = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.idx|.rar|.zip";
    if (g_application.GetCurrentPlayer() == EPC_DVDPLAYER)
      strMask = ".srt|.rar|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa|.txt";
    VECSOURCES shares(*CMediaSourceSettings::Get().GetSources("video"));
    if (CMediaSettings::Get().GetAdditionalSubtitleDirectoryChecked() != -1 && !CSettings::Get().GetString("subtitles.custompath").empty())
    {
      CMediaSource share;
      std::vector<CStdString> paths;
      paths.push_back(URIUtils::GetDirectory(strPath));
      paths.push_back(CSettings::Get().GetString("subtitles.custompath"));
      share.FromNameAndPaths("video",g_localizeStrings.Get(21367),paths);
      shares.push_back(share);
      strPath = share.strPath;
      URIUtils::AddSlashAtEnd(strPath);
    }
    if (CGUIDialogFileBrowser::ShowAndGetFile(shares,strMask,g_localizeStrings.Get(293),strPath,false,true)) // "subtitles"
    {
      if (URIUtils::HasExtension(strPath, ".sub"))
        if (CFile::Exists(URIUtils::ReplaceExtension(strPath, ".idx")))
          strPath = URIUtils::ReplaceExtension(strPath, ".idx");
      
      int id = g_application.m_pPlayer->AddSubtitle(strPath);
      if(id >= 0)
      {
        m_subtitleStream = id;
        g_application.m_pPlayer->SetSubtitle(m_subtitleStream);
        g_application.m_pPlayer->SetSubtitleVisible(true);
      }
      CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleCached = true;
      Close();
    }
  }
  else if (setting.id == AUDIO_SETTINGS_MAKE_DEFAULT)
  {
    if (!g_passwordManager.CheckSettingLevelLock(SettingLevelExpert) &&
        CProfilesManager::Get().GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE)
      return;

    // prompt user if they are sure
    if (CGUIDialogYesNo::ShowAndGetInput(12376, 750, 0, 12377))
    { // reset the settings
      CVideoDatabase db;
      db.Open();
      db.EraseVideoSettings();
      db.Close();
      CMediaSettings::Get().GetDefaultVideoSettings() = CMediaSettings::Get().GetCurrentVideoSettings();
      CMediaSettings::Get().GetDefaultVideoSettings().m_SubtitleStream = -1;
      CMediaSettings::Get().GetDefaultVideoSettings().m_AudioStream = -1;
      CSettings::Get().Save();
    }
  }

  if (g_PVRManager.IsPlayingRadio() || g_PVRManager.IsPlayingTV())
    g_PVRManager.TriggerSaveChannelSettings();
}
void CGUIDialogAudioSubtitleSettings::OnSettingChanged(unsigned int num)
{
  // setting has changed - update anything that needs it
  if (num >= m_settings.size()) return;
  SettingInfo &setting = m_settings.at(num);
  // check and update anything that needs it
  if (setting.id == AUDIO_SETTINGS_VOLUME)
  {
    g_stSettings.m_nVolumeLevel = (long)(m_volume * 100.0f);
    g_application.SetVolume(int(((float)(g_stSettings.m_nVolumeLevel - VOLUME_MINIMUM)) / (VOLUME_MAXIMUM - VOLUME_MINIMUM)*100.0f + 0.5f));
  }
  else if (setting.id == AUDIO_SETTINGS_VOLUME_AMPLIFICATION)
  {
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetDynamicRangeCompression((long)(g_stSettings.m_currentVideoSettings.m_VolumeAmplification * 100));
  }
  else if (setting.id == AUDIO_SETTINGS_DELAY)
  {
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetAVDelay(g_stSettings.m_currentVideoSettings.m_AudioDelay);
  }
  else if (setting.id == AUDIO_SETTINGS_STREAM)
  {
    // first check if it's a stereo track that we can change between stereo, left and right
    if (g_application.m_pPlayer->GetAudioStreamCount() == 1)
    {
      if (setting.max == 2)
      { // we're in the case we want - call the code to switch channels etc.
        // update the screen setting...
        g_stSettings.m_currentVideoSettings.m_AudioStream = -1 - m_audioStream;
        // call monkeyh1's code here...
        //bool bAudioOnAllSpeakers = (g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL) && g_stSettings.m_currentVideoSettings.m_OutputToAllSpeakers;
#if defined(HAS_VIDEO_PLAYBACK) && defined(HAS_XBOX_HARDWARE)
        xbox_audio_switch_channel(m_audioStream, bAudioOnAllSpeakers);
#endif
        return;
      }
    }
    // only change the audio stream if a different one has been asked for
    if (g_application.m_pPlayer->GetAudioStream() != m_audioStream)
    {
      g_stSettings.m_currentVideoSettings.m_AudioStream = m_audioStream;
      g_application.m_pPlayer->SetAudioStream(m_audioStream);    // Set the audio stream to the one selected
    }
  }
  else if (setting.id == AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS)
  {
    g_application.Restart();
  }
  else if (setting.id == AUDIO_SETTINGS_DIGITAL_ANALOG)
  {
    if(m_outputmode == 0) // might be unneccesary (indexes match), but just for clearity
      g_guiSettings.SetInt("audiooutput.mode", AUDIO_ANALOG);
    else
      g_guiSettings.SetInt("audiooutput.mode", AUDIO_DIGITAL);

    EnableSettings(AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS, g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL);
    g_application.Restart();
  }
  else if (setting.id == SUBTITLE_SETTINGS_ENABLE)
  {
    g_stSettings.m_currentVideoSettings.m_SubtitleOn = m_subtitleVisible;
    g_application.m_pPlayer->SetSubtitleVisible(g_stSettings.m_currentVideoSettings.m_SubtitleOn);
    if (!g_stSettings.m_currentVideoSettings.m_SubtitleCached && g_stSettings.m_currentVideoSettings.m_SubtitleOn)
    {
      g_application.Restart(true); // cache subtitles
      Close();
    }
  }
  else if (setting.id == SUBTITLE_SETTINGS_DELAY)
    g_application.m_pPlayer->SetSubTitleDelay(g_stSettings.m_currentVideoSettings.m_SubtitleDelay);
  else if (setting.id == SUBTITLE_SETTINGS_STREAM && setting.max > 0)
  {
    g_stSettings.m_currentVideoSettings.m_SubtitleStream = m_subtitleStream;
    g_application.m_pPlayer->SetSubtitle(m_subtitleStream);
  }
  else if (setting.id == SUBTITLE_SETTINGS_BROWSER)
  {
    CStdString strPath;
    if (CUtil::IsInRAR(g_application.CurrentFileItem().m_strPath) || CUtil::IsInZIP(g_application.CurrentFileItem().m_strPath))
    {
      CURL url(g_application.CurrentFileItem().m_strPath);
      strPath = url.GetHostName();
    }
    else
      strPath = g_application.CurrentFileItem().m_strPath;

    CStdString strMask = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.idx|.rar|.zip";
    if (g_application.GetCurrentPlayer() == EPC_DVDPLAYER)
      strMask = ".srt|.rar|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa";
    VECSOURCES shares(g_settings.m_videoSources);
    if (g_stSettings.iAdditionalSubtitleDirectoryChecked != -1 && !g_guiSettings.GetString("subtitles.custompath").IsEmpty())
    {
      CMediaSource share;
      std::vector<CStdString> paths;
      CStdString strPath1;
      CUtil::GetDirectory(strPath,strPath1);
      paths.push_back(strPath1);
      strPath1 = g_guiSettings.GetString("subtitles.custompath");
      paths.push_back(g_guiSettings.GetString("subtitles.custompath"));
      share.FromNameAndPaths("video",g_localizeStrings.Get(21367),paths);
      // hack
      g_settings.m_videoSources.push_back(share);
      strPath = share.strPath;
      CUtil::AddSlashAtEnd(strPath);
    }
    else // add source pointing to movie path
    {
      CMediaSource share;
      share.strName = g_localizeStrings.Get(20338);
      CUtil::GetParentPath(strPath,share.strPath);
      g_settings.m_videoSources.push_back(share);
      strPath = share.strPath;
      CUtil::AddSlashAtEnd(strPath);
    }
    if (CGUIDialogFileBrowser::ShowAndGetFile(g_settings.m_videoSources,strMask,g_localizeStrings.Get(293),strPath,false,true)) // "subtitles"
    {
      CStdString strExt;
      CUtil::GetExtension(strPath,strExt);
      if (strExt.CompareNoCase(".idx") == 0 || strExt.CompareNoCase(".sub") == 0)
      {
        // else get current position
        double time = g_application.GetTime();

        // get player state, needed for dvd's
        CStdString state = g_application.m_pPlayer->GetPlayerState();

        g_application.m_pPlayer->CloseFile(); // to conserve memory if unraring
        if (CFile::Cache(strPath,"z:\\subtitle"+strExt+".keep"))
        {
          CStdString strPath2;
          CStdString strPath3;
          if (strExt.CompareNoCase(".idx") == 0)
          {
            CUtil::ReplaceExtension(strPath,".sub",strPath2);
            strPath3 = "z:\\subtitle.sub.keep";
          }
          else
          {
            CUtil::ReplaceExtension(strPath,".idx",strPath2);
            if (!CFile::Exists(strPath2) && (CUtil::IsInRAR(strPath2) || CUtil::IsInZIP(strPath2)))
            {
              CStdString strFileName = CUtil::GetFileName(strPath);
              CUtil::GetDirectory(strPath,strPath3);
              CUtil::GetParentPath(strPath3,strPath2);
              CUtil::AddFileToFolder(strPath2,strFileName,strPath2);
              CUtil::ReplaceExtension(strPath2,".idx",strPath2);
            }
            strPath3 = "z:\\subtitle.idx.keep";
          }
          if (CFile::Exists(strPath2))
            CFile::Cache(strPath2,strPath3);
          else
          {
            CFileItemList items;
            CStdString strDir,strFileNameNoExtNoCase;
            CUtil::Split(strPath,strDir,strPath3);
            CUtil::ReplaceExtension(strPath3,".",strFileNameNoExtNoCase);
            strFileNameNoExtNoCase.ToLower();
            CUtil::GetDirectory(strPath,strDir);
            CDirectory::GetDirectory(strDir,items,".rar|.zip",false);
            vector<CStdString> vecExts;
            for (int i=0;i<items.Size();++i)
              CUtil::CacheRarSubtitles(vecExts,items[i]->m_strPath,strFileNameNoExtNoCase,".keep");
          }
          g_stSettings.m_currentVideoSettings.m_SubtitleCached = false;
          g_stSettings.m_currentVideoSettings.m_SubtitleOn = true;

          // reopen the file
          if ( g_application.PlayFile(g_application.CurrentFileItem(), true) && g_application.m_pPlayer )
          {
            // and seek to the position
            g_application.m_pPlayer->SetPlayerState(state);
            g_application.SeekTime(time);
          }

          Close();
        }
      }
      else
      {
        m_subtitleStream = g_application.m_pPlayer->GetSubtitleCount();
        CStdString strExt;
        CUtil::GetExtension(strPath,strExt);
        if (CFile::Cache(strPath,"z:\\subtitle.browsed"+strExt))
        {
          g_stSettings.m_currentVideoSettings.m_SubtitleOn = true;
          g_application.m_pPlayer->SetSubtitleVisible(true);
          g_application.m_pPlayer->AddSubtitle("z:\\subtitle.browsed"+strExt);
          g_application.m_pPlayer->SetSubtitle(m_subtitleStream);
        }

        Close();
      }
      g_stSettings.m_currentVideoSettings.m_SubtitleCached = true;
    }
    g_settings.m_videoSources = shares;
  }
  else if (setting.id == AUDIO_SETTINGS_MAKE_DEFAULT)
  {
    if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].settingsLocked() && 
        g_settings.m_vecProfiles[0].getLockMode() != ::LOCK_MODE_EVERYONE)
      if (!g_passwordManager.IsMasterLockUnlocked(true))
        return;

    // prompt user if they are sure
    if (CGUIDialogYesNo::ShowAndGetInput(12376, 750, 0, 12377))
    { // reset the settings
      CVideoDatabase db;
      db.Open();
      db.EraseVideoSettings();
      db.Close();
      g_stSettings.m_defaultVideoSettings = g_stSettings.m_currentVideoSettings;
      g_settings.Save();
    }
  }
}
void CGUIDialogAudioSubtitleSettings::OnSettingChanged(SettingInfo &setting)
{
  // check and update anything that needs it
  if (setting.id == AUDIO_SETTINGS_VOLUME)
  {
    g_settings.m_nVolumeLevel = (long)(m_volume * 100.0f);
    g_application.SetVolume(int(((float)(g_settings.m_nVolumeLevel - VOLUME_MINIMUM)) / (VOLUME_MAXIMUM - VOLUME_MINIMUM)*100.0f + 0.5f));
  }
  else if (setting.id == AUDIO_SETTINGS_VOLUME_AMPLIFICATION)
  {
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetDynamicRangeCompression((long)(g_settings.m_currentVideoSettings.m_VolumeAmplification * 100));
  }
  else if (setting.id == AUDIO_SETTINGS_DELAY)
  {
    if (g_application.m_pPlayer)
      g_application.m_pPlayer->SetAVDelay(g_settings.m_currentVideoSettings.m_AudioDelay);
  }
  else if (setting.id == AUDIO_SETTINGS_STREAM)
  {
    // first check if it's a stereo track that we can change between stereo, left and right
    if (g_application.m_pPlayer->GetAudioStreamCount() == 1)
    {
      if (setting.max == 2)
      { // we're in the case we want - call the code to switch channels etc.
        // update the screen setting...
        g_settings.m_currentVideoSettings.m_AudioStream = -1 - m_audioStream;
        // call monkeyh1's code here...
        //bool bAudioOnAllSpeakers = (g_guiSettings.GetInt("audiooutput.mode") == AUDIO_IEC958) && g_settings.m_currentVideoSettings.m_OutputToAllSpeakers;
        return;
      }
    }
    // only change the audio stream if a different one has been asked for
    if (g_application.m_pPlayer->GetAudioStream() != m_audioStream)
    {
      g_settings.m_currentVideoSettings.m_AudioStream = m_audioStream;
      g_application.m_pPlayer->SetAudioStream(m_audioStream);    // Set the audio stream to the one selected
      EnableSettings(AUDIO_SETTINGS_VOLUME, !g_application.m_pPlayer->IsPassthrough());
    }
  }
  else if (setting.id == AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS)
  {
    g_application.Restart();
  }
  else if (setting.id == AUDIO_SETTINGS_DIGITAL_ANALOG)
  {
    bool bitstream = false;

    switch(m_outputmode)
    {
      case 0: g_guiSettings.SetInt("audiooutput.mode", AUDIO_ANALOG ); break;
      case 1: g_guiSettings.SetInt("audiooutput.mode", AUDIO_IEC958 ); bitstream = true; break;
      case 2: g_guiSettings.SetInt("audiooutput.mode", AUDIO_HDMI   ); bitstream = true; break;
    }

    EnableSettings(AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS, bitstream);
    g_application.Restart();
    EnableSettings(AUDIO_SETTINGS_VOLUME, !g_application.m_pPlayer->IsPassthrough());
  }
  else if (setting.id == SUBTITLE_SETTINGS_ENABLE)
  {
    g_settings.m_currentVideoSettings.m_SubtitleOn = m_subtitleVisible;
    g_application.m_pPlayer->SetSubtitleVisible(g_settings.m_currentVideoSettings.m_SubtitleOn);
  }
  else if (setting.id == SUBTITLE_SETTINGS_DELAY)
  {
    g_application.m_pPlayer->SetSubTitleDelay(g_settings.m_currentVideoSettings.m_SubtitleDelay);
  }
  else if (setting.id == SUBTITLE_SETTINGS_STREAM && setting.max > 0)
  {
    g_settings.m_currentVideoSettings.m_SubtitleStream = m_subtitleStream;
    g_application.m_pPlayer->SetSubtitle(m_subtitleStream);
  }
  else if (setting.id == SUBTITLE_SETTINGS_BROWSER)
  {
    CStdString strPath;
    if (CUtil::IsInRAR(g_application.CurrentFileItem().m_strPath) || CUtil::IsInZIP(g_application.CurrentFileItem().m_strPath))
    {
      CURL url(g_application.CurrentFileItem().m_strPath);
      strPath = url.GetHostName();
    }
    else
      strPath = g_application.CurrentFileItem().m_strPath;

    CStdString strMask = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.aqt|.jss|.ass|.idx|.rar|.zip";
    if (g_application.GetCurrentPlayer() == EPC_DVDPLAYER)
      strMask = ".srt|.rar|.zip|.ifo|.smi|.sub|.idx|.ass|.ssa|.txt";
    VECSOURCES shares(g_settings.m_videoSources);
    if (g_settings.iAdditionalSubtitleDirectoryChecked != -1 && !g_guiSettings.GetString("subtitles.custompath").IsEmpty())
    {
      CMediaSource share;
      std::vector<CStdString> paths;
      CStdString strPath1;
      CUtil::GetDirectory(strPath,strPath1);
      paths.push_back(strPath1);
      strPath1 = g_guiSettings.GetString("subtitles.custompath");
      paths.push_back(g_guiSettings.GetString("subtitles.custompath"));
      share.FromNameAndPaths("video",g_localizeStrings.Get(21367),paths);
      shares.push_back(share);
      strPath = share.strPath;
      CUtil::AddSlashAtEnd(strPath);
    }
    if (CGUIDialogFileBrowser::ShowAndGetFile(shares,strMask,g_localizeStrings.Get(293),strPath,false,true)) // "subtitles"
    {
      if ( CUtil::GetExtension(strPath) == ".sub" )
        if ( CFile::Exists(CUtil::ReplaceExtension(strPath, ".idx")) )
          strPath = CUtil::ReplaceExtension(strPath, ".idx");
      
      int id = g_application.m_pPlayer->AddSubtitle(strPath);
      if(id >= 0)
      {
        m_subtitleStream = id;
        g_application.m_pPlayer->SetSubtitle(m_subtitleStream);
        g_application.m_pPlayer->SetSubtitleVisible(true);
      }
      g_settings.m_currentVideoSettings.m_SubtitleCached = true;
      Close();
    }
  }
  else if (setting.id == AUDIO_SETTINGS_MAKE_DEFAULT)
  {
    if (g_settings.GetCurrentProfile().settingsLocked() &&
        g_settings.GetMasterProfile().getLockMode() != ::LOCK_MODE_EVERYONE)
      if (!g_passwordManager.IsMasterLockUnlocked(true))
        return;

    // prompt user if they are sure
    if (CGUIDialogYesNo::ShowAndGetInput(12376, 750, 0, 12377))
    { // reset the settings
      CVideoDatabase db;
      db.Open();
      db.EraseVideoSettings();
      db.Close();
      g_settings.m_defaultVideoSettings = g_settings.m_currentVideoSettings;
      g_settings.m_defaultVideoSettings.m_SubtitleStream = -1;
      g_settings.m_defaultVideoSettings.m_AudioStream = -1;
      g_settings.Save();
    }
  }
}
Example #19
0
void CBoxeeMediaSourceList::addOrEditSource(CBoxeeMediaSource orig_source, CBoxeeMediaSource source)
{
  CMediaSource xbmcSource;
  std::vector<CStdString> paths;
  paths.push_back(source.path);
  xbmcSource.m_iScanType = source.scanType;
  xbmcSource.m_strThumbnailImage = source.thumbPath;
  xbmcSource.m_adult = source.isAdult;
  xbmcSource.m_country = source.country;
  xbmcSource.m_countryAllow = source.countryAllow;

  // for each type - check if we need to add , delete or untouch

  //VIDEO
  if (source.isVideo == orig_source.isVideo)
  {
    CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource video scan type wasn't change - don't delete or add");
}
  else
  {
    if (orig_source.isVideo)
    {
      CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource source use to be video - erase video source");
      g_settings.DeleteSource("video", orig_source.name, source.path);
    }
    else
    {
      CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource source scan type change to video - add it ");
      xbmcSource.FromNameAndPaths("video", orig_source.name, paths);
      g_settings.AddShare("video", xbmcSource);
    }
  }

  //MUSIC
  if (source.isMusic == orig_source.isMusic)
  {
    CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource music scan type wasn't change - don't delete or add");
  }
  else
  {
    if (orig_source.isMusic)
    {
      CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource source use to be music - erase music source");
      g_settings.DeleteSource("music", orig_source.name, source.path);
    }
    else
    {
      CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource source scan type change to music - add it ");
      xbmcSource.FromNameAndPaths("music", source.name, paths);
      g_settings.AddShare("music", xbmcSource);
    }
  }

  //PICTURE
  if (source.isPicture == orig_source.isPicture)
  {
    CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource picture scan type wasn't change - don't delete or add");
  }
  else
  {
    if (orig_source.isPicture)
    {
      CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource source use to be picture - erase picture source");
      g_settings.DeleteSource("pictures", orig_source.name, source.path);
    }
    else
    {
      CLog::Log(LOGDEBUG,"CBoxeeMediaSourceList::addOrEditSource source scan type change to picture - add it ");
      xbmcSource.FromNameAndPaths("pictures", source.name, paths);
      g_settings.AddShare("pictures", xbmcSource);
    }
  }

  g_settings.SaveSources();
  load();

}
Example #20
0
void CMediaPlayer::PlayFunc(ThreadParam *pParam)
{
	CMediaSource *pSource;
	CMediaDecoder *pDecoder;
	CMediaRenderer *pRenderer;
	int nTime;
	bool bDrop;
	int nReadSize, nSrcSize, nDecSize, nRndSize;
	unsigned char *pSrcFrame, *pDecFrame, *pRndFrame;

	pSource = pParam->pSource;
	pDecoder = pParam->pDecoder;
	pRenderer = pParam->pRenderer;
	nTime = 0;
	bDrop = false;
	if (pDecoder != NULL)
	{
		nReadSize = pDecoder->GetInputSize();
		pSrcFrame = new unsigned char[nReadSize];
		nDecSize = pDecoder->GetOutputSize();
		pDecFrame = new unsigned char[nDecSize];
		pRndFrame = pDecFrame;
	}
	else
	{
		nReadSize = 0x1000;
		pSrcFrame = new unsigned char[nReadSize];
		pDecFrame = NULL;
		pRndFrame = pSrcFrame;
	}

	for (;;)
	{
		m_pSemaphore->Wait();  //when paused, this thread will be blocked here
		if (m_nState == STATE_STOP)
		{
			m_pSemaphore->Release();
			break;
		}

		if (!pParam->bReferenceClock)
			if (nTime + 100 < m_pClock->GetTime())  //time stamp behind the clock too much
				bDrop = true;
		m_pMutex->Lock();  //only one thread can read data from media source
		nSrcSize = pSource->ReadData(pParam->nIndex, bDrop? NULL : pSrcFrame, nReadSize);  //read a frame
		m_pMutex->Unlock();
		if (nSrcSize == 0)  //no more frame to render
		{
			pRenderer->Flush(true);
			m_pSemaphore->Release();
			break;
		}

		nTime = pSource->GetOutputTime(pParam->nIndex);
		if (bDrop)  //drop this frame
			bDrop = false;
		else
		{
			if (pDecoder != NULL)
			{
				if (pParam->type != RENDER_TYPE_SPDIF)
					nDecSize = pDecoder->Decode(pSrcFrame, nSrcSize, pDecFrame);
				else
					nDecSize = pDecoder->SPDIF(pSrcFrame, nSrcSize, pDecFrame);
			}
			else
				nDecSize = nSrcSize;
			nRndSize = nDecSize;

			if (!pParam->bReferenceClock)
				m_pClock->WaitFor(nTime);  //wait until this frame can be rendered
			pRenderer->Write(pRndFrame, nRndSize);  //render a frame
			if (pParam->bReferenceClock && nTime > 0)
				m_pClock->SetTime(nTime);  //update clock
		}

		m_pSemaphore->Release();
	}  //while

	if (pParam->pDecoder)
		pParam->pDecoder->Flush();
	delete[] pSrcFrame;
	delete[] pDecFrame;
}
Example #21
0
bool CMediaSourceSettings::GetSource(const std::string &category, const TiXmlNode *source, CMediaSource &share)
{
  const TiXmlNode *pNodeName = source->FirstChild("name");
  std::string strName;
  if (pNodeName && pNodeName->FirstChild())
    strName = pNodeName->FirstChild()->ValueStr();

  // get multiple paths
  std::vector<std::string> vecPaths;
  const TiXmlElement *pPathName = source->FirstChildElement("path");
  while (pPathName != NULL)
  {
    if (pPathName->FirstChild())
    {
      std::string strPath = pPathName->FirstChild()->ValueStr();

      // make sure there are no virtualpaths or stack paths defined in sources.xml
      if (!URIUtils::IsStack(strPath))
      {
        // translate special tags
        if (!strPath.empty() && strPath.at(0) == '$')
          strPath = CUtil::TranslateSpecialSource(strPath);

        // need to check path validity again as CUtil::TranslateSpecialSource() may have failed
        if (!strPath.empty())
        {
          URIUtils::AddSlashAtEnd(strPath);
          vecPaths.push_back(strPath);
        }
      }
      else
        CLog::Log(LOGERROR, "CMediaSourceSettings:    invalid path type (%s) in source", strPath.c_str());
    }

    pPathName = pPathName->NextSiblingElement("path");
  }

  const TiXmlNode *pLockMode = source->FirstChild("lockmode");
  const TiXmlNode *pLockCode = source->FirstChild("lockcode");
  const TiXmlNode *pBadPwdCount = source->FirstChild("badpwdcount");
  const TiXmlNode *pThumbnailNode = source->FirstChild("thumbnail");

  if (strName.empty() || vecPaths.empty())
    return false;

  std::vector<std::string> verifiedPaths;
  // disallowed for files, or theres only a single path in the vector
  if (StringUtils::EqualsNoCase(category, "files") || vecPaths.size() == 1)
    verifiedPaths.push_back(vecPaths[0]);
  // multiple paths?
  else
  {
    // validate the paths
    for (std::vector<std::string>::const_iterator path = vecPaths.begin(); path != vecPaths.end(); ++path)
    {
      CURL url(*path);
      bool bIsInvalid = false;

      // for my programs
      if (StringUtils::EqualsNoCase(category, "programs") || StringUtils::EqualsNoCase(category, "myprograms"))
      {
        // only allow HD and plugins
        if (url.IsLocal() || url.IsProtocol("plugin"))
          verifiedPaths.push_back(*path);
        else
          bIsInvalid = true;
      }
      // for others allow everything (if the user does something silly, we can't stop them)
      else
        verifiedPaths.push_back(*path);

      // error message
      if (bIsInvalid)
        CLog::Log(LOGERROR,"CMediaSourceSettings:    invalid path type (%s) for multipath source", path->c_str());
    }

    // no valid paths? skip to next source
    if (verifiedPaths.empty())
    {
      CLog::Log(LOGERROR,"CMediaSourceSettings:    missing or invalid <name> and/or <path> in source");
      return false;
    }
  }

  share.FromNameAndPaths(category, strName, verifiedPaths);

  share.m_iBadPwdCount = 0;
  if (pLockMode)
  {
    share.m_iLockMode = (LockType)std::strtol(pLockMode->FirstChild()->Value(), NULL, 10);
    share.m_iHasLock = 2;
  }

  if (pLockCode && pLockCode->FirstChild())
    share.m_strLockCode = pLockCode->FirstChild()->Value();

  if (pBadPwdCount && pBadPwdCount->FirstChild())
    share.m_iBadPwdCount = (int)std::strtol(pBadPwdCount->FirstChild()->Value(), NULL, 10);

  if (pThumbnailNode && pThumbnailNode->FirstChild())
    share.m_strThumbnailImage = pThumbnailNode->FirstChild()->Value();

  XMLUtils::GetBoolean(source, "allowsharing", share.m_allowSharing);

  return true;
}