2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "ApplicationPlayer.h"
22 #include "cores/IPlayer.h"
23 #include "Application.h"
25 #define VOLUME_MINIMUM 0.0f // -60dB
26 #define VOLUME_MAXIMUM 1.0f // 0dB
28 CApplicationPlayer::CApplicationPlayer()
31 m_eCurrentPlayer = EPC_NONE;
34 boost::shared_ptr<IPlayer> CApplicationPlayer::GetInternal() const
36 CSingleLock lock(m_player_lock);
40 void CApplicationPlayer::ClosePlayer()
42 boost::shared_ptr<IPlayer> player = GetInternal();
46 // we need to do this directly on the member
47 CSingleLock lock(m_player_lock);
52 void CApplicationPlayer::CloseFile()
54 boost::shared_ptr<IPlayer> player = GetInternal();
62 void CApplicationPlayer::ClosePlayerGapless(PLAYERCOREID newCore)
64 boost::shared_ptr<IPlayer> player = GetInternal();
68 bool gaplessSupported = (m_eCurrentPlayer == EPC_DVDPLAYER || m_eCurrentPlayer == EPC_PAPLAYER);
69 #if defined(HAS_OMXPLAYER)
70 gaplessSupported = gaplessSupported || (m_eCurrentPlayer == EPC_OMXPLAYER);
72 gaplessSupported = gaplessSupported && (m_eCurrentPlayer == newCore);
73 if (!gaplessSupported)
79 // XXX: we had to stop the previous playing item, it was done in dvdplayer::OpenFile.
80 // but in paplayer::OpenFile, it sometimes just fade in without call CloseFile.
81 // but if we do not stop it, we can not distingush callbacks from previous
82 // item and current item, it will confused us then we can not make correct delay
83 // callback after the starting state.
88 void CApplicationPlayer::CreatePlayer(PLAYERCOREID newCore, IPlayerCallback& callback)
90 CSingleLock lock(m_player_lock);
93 m_eCurrentPlayer = newCore;
94 m_pPlayer.reset(CPlayerCoreFactory::Get().CreatePlayer(newCore, callback));
98 PlayBackRet CApplicationPlayer::OpenFile(const CFileItem& item, const CPlayerOptions& options)
100 boost::shared_ptr<IPlayer> player = GetInternal();
101 PlayBackRet iResult = PLAYBACK_FAIL;
104 // op seq for detect cancel (CloseFile be called or OpenFile be called again) during OpenFile.
105 unsigned int startingSeq = ++m_iPlayerOPSeq;
107 iResult = player->OpenFile(item, options) ? PLAYBACK_OK : PLAYBACK_FAIL;
108 // check whether the OpenFile was canceled by either CloseFile or another OpenFile.
109 if (m_iPlayerOPSeq != startingSeq)
110 iResult = PLAYBACK_CANCELED;
115 bool CApplicationPlayer::HasPlayer() const
117 boost::shared_ptr<IPlayer> player = GetInternal();
118 return player != NULL;
121 void CApplicationPlayer::RegisterAudioCallback(IAudioCallback* pCallback)
123 boost::shared_ptr<IPlayer> player = GetInternal();
125 player->RegisterAudioCallback(pCallback);
128 void CApplicationPlayer::UnRegisterAudioCallback()
130 boost::shared_ptr<IPlayer> player = GetInternal();
132 player->UnRegisterAudioCallback();
135 int CApplicationPlayer::GetChapter()
137 boost::shared_ptr<IPlayer> player = GetInternal();
139 return player->GetChapter();
144 int CApplicationPlayer::GetChapterCount()
146 boost::shared_ptr<IPlayer> player = GetInternal();
148 return player->GetChapterCount();
153 void CApplicationPlayer::GetChapterName(CStdString& strChapterName)
155 boost::shared_ptr<IPlayer> player = GetInternal();
157 player->GetChapterName(strChapterName);
160 bool CApplicationPlayer::HasAudio() const
162 boost::shared_ptr<IPlayer> player = GetInternal();
163 return (player && player->HasAudio());
166 bool CApplicationPlayer::HasVideo() const
168 boost::shared_ptr<IPlayer> player = GetInternal();
169 return (player && player->HasVideo());
172 bool CApplicationPlayer::IsPaused() const
174 boost::shared_ptr<IPlayer> player = GetInternal();
175 return (player && player->IsPaused());
178 bool CApplicationPlayer::IsPlaying() const
180 boost::shared_ptr<IPlayer> player = GetInternal();
181 return (player && player->IsPlaying());
184 bool CApplicationPlayer::IsPausedPlayback() const
186 return (IsPlaying() && IsPaused());
189 bool CApplicationPlayer::IsPlayingAudio() const
191 return (IsPlaying() && !HasVideo() && HasAudio());
194 bool CApplicationPlayer::IsPlayingVideo() const
196 return (IsPlaying() && HasVideo());
199 void CApplicationPlayer::Pause()
201 boost::shared_ptr<IPlayer> player = GetInternal();
206 bool CApplicationPlayer::ControlsVolume() const
208 boost::shared_ptr<IPlayer> player = GetInternal();
209 return (player && player->ControlsVolume());
212 void CApplicationPlayer::SetMute(bool bOnOff)
214 boost::shared_ptr<IPlayer> player = GetInternal();
216 player->SetMute(bOnOff);
219 void CApplicationPlayer::SetVolume(float volume)
221 boost::shared_ptr<IPlayer> player = GetInternal();
223 player->SetVolume(volume);
226 void CApplicationPlayer::Seek(bool bPlus, bool bLargeStep, bool bChapterOverride)
228 boost::shared_ptr<IPlayer> player = GetInternal();
230 player->Seek(bPlus, bLargeStep, bChapterOverride);
233 void CApplicationPlayer::SeekPercentage(float fPercent)
235 boost::shared_ptr<IPlayer> player = GetInternal();
237 player->SeekPercentage(fPercent);
240 bool CApplicationPlayer::IsPassthrough() const
242 boost::shared_ptr<IPlayer> player = GetInternal();
243 return (player && player->IsPassthrough());
246 bool CApplicationPlayer::CanSeek()
248 boost::shared_ptr<IPlayer> player = GetInternal();
249 return (player && player->CanSeek());
252 bool CApplicationPlayer::SeekScene(bool bPlus)
254 boost::shared_ptr<IPlayer> player = GetInternal();
255 return (player && player->SeekScene(bPlus));
258 void CApplicationPlayer::SeekTime(int64_t iTime)
260 boost::shared_ptr<IPlayer> player = GetInternal();
262 player->SeekTime(iTime);
265 CStdString CApplicationPlayer::GetPlayingTitle()
267 boost::shared_ptr<IPlayer> player = GetInternal();
269 return player->GetPlayingTitle();
274 int64_t CApplicationPlayer::GetTime() const
276 boost::shared_ptr<IPlayer> player = GetInternal();
278 return player->GetTime();
283 int CApplicationPlayer::GetPictureHeight()
285 boost::shared_ptr<IPlayer> player = GetInternal();
287 return player->GetPictureHeight();
292 int CApplicationPlayer::GetPictureWidth()
294 boost::shared_ptr<IPlayer> player = GetInternal();
296 return player->GetPictureWidth();
301 int CApplicationPlayer::GetSampleRate()
303 boost::shared_ptr<IPlayer> player = GetInternal();
305 return player->GetSampleRate();
310 bool CApplicationPlayer::IsCaching() const
312 boost::shared_ptr<IPlayer> player = GetInternal();
313 return (player && player->IsCaching());
316 bool CApplicationPlayer::IsInMenu() const
318 boost::shared_ptr<IPlayer> player = GetInternal();
319 return (player && player->IsInMenu());
322 bool CApplicationPlayer::HasMenu() const
324 boost::shared_ptr<IPlayer> player = GetInternal();
325 return (player && player->HasMenu());
328 int CApplicationPlayer::GetCacheLevel() const
330 boost::shared_ptr<IPlayer> player = GetInternal();
332 return player->GetCacheLevel();
337 int CApplicationPlayer::GetSubtitleCount()
339 boost::shared_ptr<IPlayer> player = GetInternal();
341 return player->GetSubtitleCount();
346 int CApplicationPlayer::GetBitsPerSample()
348 boost::shared_ptr<IPlayer> player = GetInternal();
350 return player->GetBitsPerSample();
355 int CApplicationPlayer::GetAudioStream()
357 boost::shared_ptr<IPlayer> player = GetInternal();
359 return player->GetAudioStream();
364 int CApplicationPlayer::GetSubtitle()
366 boost::shared_ptr<IPlayer> player = GetInternal();
368 return player->GetSubtitle();
373 bool CApplicationPlayer::GetSubtitleVisible()
375 boost::shared_ptr<IPlayer> player = GetInternal();
376 return (player && player->GetSubtitleVisible());
379 bool CApplicationPlayer::CanRecord()
381 boost::shared_ptr<IPlayer> player = GetInternal();
382 return (player && player->CanRecord());
385 bool CApplicationPlayer::CanPause()
387 boost::shared_ptr<IPlayer> player = GetInternal();
388 return (player && player->CanPause());
391 bool CApplicationPlayer::IsRecording() const
393 boost::shared_ptr<IPlayer> player = GetInternal();
394 return (player && player->IsRecording());
397 TextCacheStruct_t* CApplicationPlayer::GetTeletextCache()
399 boost::shared_ptr<IPlayer> player = GetInternal();
401 return player->GetTeletextCache();
406 int64_t CApplicationPlayer::GetTotalTime() const
408 boost::shared_ptr<IPlayer> player = GetInternal();
410 return player->GetTotalTime();
415 float CApplicationPlayer::GetPercentage() const
417 boost::shared_ptr<IPlayer> player = GetInternal();
419 return player->GetPercentage();
424 float CApplicationPlayer::GetCachePercentage() const
426 boost::shared_ptr<IPlayer> player = GetInternal();
428 return player->GetCachePercentage();
433 void CApplicationPlayer::ToFFRW(int iSpeed)
435 boost::shared_ptr<IPlayer> player = GetInternal();
437 player->ToFFRW(iSpeed);
440 void CApplicationPlayer::DoAudioWork()
442 boost::shared_ptr<IPlayer> player = GetInternal();
444 player->DoAudioWork();
447 CStdString CApplicationPlayer::GetPlayerState()
449 boost::shared_ptr<IPlayer> player = GetInternal();
451 return player->GetPlayerState();
456 bool CApplicationPlayer::QueueNextFile(const CFileItem &file)
458 boost::shared_ptr<IPlayer> player = GetInternal();
459 return (player && player->QueueNextFile(file));
462 bool CApplicationPlayer::GetStreamDetails(CStreamDetails &details)
464 boost::shared_ptr<IPlayer> player = GetInternal();
465 return (player && player->GetStreamDetails(details));
468 bool CApplicationPlayer::SetPlayerState(CStdString state)
470 boost::shared_ptr<IPlayer> player = GetInternal();
471 return (player && player->SetPlayerState(state));
474 void CApplicationPlayer::OnNothingToQueueNotify()
476 boost::shared_ptr<IPlayer> player = GetInternal();
478 player->OnNothingToQueueNotify();
481 void CApplicationPlayer::GetVideoStreamInfo(SPlayerVideoStreamInfo &info)
483 boost::shared_ptr<IPlayer> player = GetInternal();
485 player->GetVideoStreamInfo(info);
488 void CApplicationPlayer::GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info)
490 boost::shared_ptr<IPlayer> player = GetInternal();
492 player->GetAudioStreamInfo(index, info);
495 bool CApplicationPlayer::OnAction(const CAction &action)
497 boost::shared_ptr<IPlayer> player = GetInternal();
498 return (player && player->OnAction(action));
501 bool CApplicationPlayer::Record(bool bOnOff)
503 boost::shared_ptr<IPlayer> player = GetInternal();
504 return (player && player->Record(bOnOff));
507 int CApplicationPlayer::GetAudioStreamCount()
509 boost::shared_ptr<IPlayer> player = GetInternal();
511 return player->GetAudioStreamCount();
516 void CApplicationPlayer::SetAudioStream(int iStream)
518 boost::shared_ptr<IPlayer> player = GetInternal();
520 player->SetAudioStream(iStream);
523 void CApplicationPlayer::GetSubtitleStreamInfo(int index, SPlayerSubtitleStreamInfo &info)
525 boost::shared_ptr<IPlayer> player = GetInternal();
527 player->GetSubtitleStreamInfo(index, info);
530 void CApplicationPlayer::SetSubtitle(int iStream)
532 boost::shared_ptr<IPlayer> player = GetInternal();
534 player->SetSubtitle(iStream);
537 void CApplicationPlayer::SetSubtitleVisible(bool bVisible)
539 boost::shared_ptr<IPlayer> player = GetInternal();
541 player->SetSubtitleVisible(bVisible);
544 int CApplicationPlayer::AddSubtitle(const CStdString& strSubPath)
546 boost::shared_ptr<IPlayer> player = GetInternal();
548 return player->AddSubtitle(strSubPath);
553 void CApplicationPlayer::SetSubTitleDelay(float fValue)
555 boost::shared_ptr<IPlayer> player = GetInternal();
557 player->SetSubTitleDelay(fValue);
560 void CApplicationPlayer::SetAVDelay(float fValue)
562 boost::shared_ptr<IPlayer> player = GetInternal();
564 player->SetAVDelay(fValue);
567 void CApplicationPlayer::SetDynamicRangeCompression(long drc)
569 boost::shared_ptr<IPlayer> player = GetInternal();
571 player->SetDynamicRangeCompression(drc);
574 bool CApplicationPlayer::SwitchChannel(const PVR::CPVRChannel &channel)
576 boost::shared_ptr<IPlayer> player = GetInternal();
577 return (player && player->SwitchChannel(channel));
580 void CApplicationPlayer::LoadPage(int p, int sp, unsigned char* buffer)
582 boost::shared_ptr<IPlayer> player = GetInternal();
584 player->LoadPage(p, sp, buffer);
587 void CApplicationPlayer::GetAudioCapabilities(std::vector<int> &audioCaps)
589 boost::shared_ptr<IPlayer> player = GetInternal();
591 player->GetAudioCapabilities(audioCaps);
594 void CApplicationPlayer::GetSubtitleCapabilities(std::vector<int> &subCaps)
596 boost::shared_ptr<IPlayer> player = GetInternal();
598 player->GetSubtitleCapabilities(subCaps);
601 void CApplicationPlayer::GetAudioInfo( CStdString& strAudioInfo)
603 boost::shared_ptr<IPlayer> player = GetInternal();
605 player->GetAudioInfo(strAudioInfo);
608 void CApplicationPlayer::GetVideoInfo( CStdString& strVideoInfo)
610 boost::shared_ptr<IPlayer> player = GetInternal();
612 player->GetVideoInfo(strVideoInfo);
615 void CApplicationPlayer::GetGeneralInfo( CStdString& strVideoInfo)
617 boost::shared_ptr<IPlayer> player = GetInternal();
619 player->GetGeneralInfo(strVideoInfo);
622 int CApplicationPlayer::SeekChapter(int iChapter)
624 boost::shared_ptr<IPlayer> player = GetInternal();
626 return player->SeekChapter(iChapter);
631 void CApplicationPlayer::GetRenderFeatures(std::vector<int> &renderFeatures)
633 boost::shared_ptr<IPlayer> player = GetInternal();
635 player->GetRenderFeatures(renderFeatures);
638 void CApplicationPlayer::GetDeinterlaceMethods(std::vector<int> &deinterlaceMethods)
640 boost::shared_ptr<IPlayer> player = GetInternal();
642 player->GetDeinterlaceMethods(deinterlaceMethods);
645 void CApplicationPlayer::GetDeinterlaceModes(std::vector<int> &deinterlaceModes)
647 boost::shared_ptr<IPlayer> player = GetInternal();
649 player->GetDeinterlaceModes(deinterlaceModes);
652 void CApplicationPlayer::GetScalingMethods(std::vector<int> &scalingMethods)
654 boost::shared_ptr<IPlayer> player = GetInternal();
656 player->GetScalingMethods(scalingMethods);
659 void CApplicationPlayer::SetPlaySpeed(int iSpeed, bool bApplicationMuted)
661 boost::shared_ptr<IPlayer> player = GetInternal();
665 if (!IsPlayingAudio() && !IsPlayingVideo())
667 if (m_iPlaySpeed == iSpeed)
674 ((m_iPlaySpeed > 1) && (iSpeed > m_iPlaySpeed)) ||
675 ((m_iPlaySpeed < -1) && (iSpeed < m_iPlaySpeed))
678 iSpeed = m_iPlaySpeed; // from pause to ff/rw, do previous ff/rw speed
682 m_iPlaySpeed = iSpeed;
684 ToFFRW(m_iPlaySpeed);
686 // if player has volume control, set it.
687 if (ControlsVolume())
689 if (m_iPlaySpeed == 1)
691 player->SetVolume(g_application.GetVolume(false));
695 player->SetVolume(VOLUME_MINIMUM);
697 player->SetMute(bApplicationMuted);
701 int CApplicationPlayer::GetPlaySpeed() const