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"
24 #define VOLUME_MINIMUM 0.0f // -60dB
25 #define VOLUME_MAXIMUM 1.0f // 0dB
27 CApplicationPlayer::CApplicationPlayer()
30 m_eCurrentPlayer = EPC_NONE;
33 boost::shared_ptr<IPlayer> CApplicationPlayer::GetInternal() const
35 CSingleLock lock(m_player_lock);
39 void CApplicationPlayer::ClosePlayer()
41 boost::shared_ptr<IPlayer> player = GetInternal();
45 // we need to do this directly on the member
46 CSingleLock lock(m_player_lock);
51 void CApplicationPlayer::CloseFile()
53 boost::shared_ptr<IPlayer> player = GetInternal();
61 void CApplicationPlayer::ClosePlayerGapless(PLAYERCOREID newCore)
63 boost::shared_ptr<IPlayer> player = GetInternal();
67 bool gaplessSupported = (m_eCurrentPlayer == EPC_DVDPLAYER || m_eCurrentPlayer == EPC_PAPLAYER);
68 #if defined(HAS_OMXPLAYER)
69 gaplessSupported = gaplessSupported || (m_eCurrentPlayer == EPC_OMXPLAYER);
71 gaplessSupported = gaplessSupported && (m_eCurrentPlayer == newCore);
72 if (!gaplessSupported)
78 // XXX: we had to stop the previous playing item, it was done in dvdplayer::OpenFile.
79 // but in paplayer::OpenFile, it sometimes just fade in without call CloseFile.
80 // but if we do not stop it, we can not distingush callbacks from previous
81 // item and current item, it will confused us then we can not make correct delay
82 // callback after the starting state.
87 void CApplicationPlayer::CreatePlayer(PLAYERCOREID newCore, IPlayerCallback& callback)
89 CSingleLock lock(m_player_lock);
92 m_eCurrentPlayer = newCore;
93 m_pPlayer.reset(CPlayerCoreFactory::Get().CreatePlayer(newCore, callback));
97 PlayBackRet CApplicationPlayer::OpenFile(const CFileItem& item, const CPlayerOptions& options)
99 boost::shared_ptr<IPlayer> player = GetInternal();
100 PlayBackRet iResult = PLAYBACK_FAIL;
103 // op seq for detect cancel (CloseFile be called or OpenFile be called again) during OpenFile.
104 unsigned int startingSeq = ++m_iPlayerOPSeq;
106 iResult = player->OpenFile(item, options) ? PLAYBACK_OK : PLAYBACK_FAIL;
107 // check whether the OpenFile was canceled by either CloseFile or another OpenFile.
108 if (m_iPlayerOPSeq != startingSeq)
109 iResult = PLAYBACK_CANCELED;
114 bool CApplicationPlayer::HasPlayer() const
116 boost::shared_ptr<IPlayer> player = GetInternal();
117 return player != NULL;
120 void CApplicationPlayer::RegisterAudioCallback(IAudioCallback* pCallback)
122 boost::shared_ptr<IPlayer> player = GetInternal();
124 player->RegisterAudioCallback(pCallback);
127 void CApplicationPlayer::UnRegisterAudioCallback()
129 boost::shared_ptr<IPlayer> player = GetInternal();
131 player->UnRegisterAudioCallback();
134 int CApplicationPlayer::GetChapter()
136 boost::shared_ptr<IPlayer> player = GetInternal();
138 return player->GetChapter();
143 int CApplicationPlayer::GetChapterCount()
145 boost::shared_ptr<IPlayer> player = GetInternal();
147 return player->GetChapterCount();
152 void CApplicationPlayer::GetChapterName(CStdString& strChapterName)
154 boost::shared_ptr<IPlayer> player = GetInternal();
156 player->GetChapterName(strChapterName);
159 bool CApplicationPlayer::HasAudio() const
161 boost::shared_ptr<IPlayer> player = GetInternal();
162 return (player && player->HasAudio());
165 bool CApplicationPlayer::HasVideo() const
167 boost::shared_ptr<IPlayer> player = GetInternal();
168 return (player && player->HasVideo());
171 bool CApplicationPlayer::IsPaused() const
173 boost::shared_ptr<IPlayer> player = GetInternal();
174 return (player && player->IsPaused());
177 bool CApplicationPlayer::IsPlaying() const
179 boost::shared_ptr<IPlayer> player = GetInternal();
180 return (player && player->IsPlaying());
183 bool CApplicationPlayer::IsPausedPlayback() const
185 return (IsPlaying() && IsPaused());
188 bool CApplicationPlayer::IsPlayingAudio() const
190 return (IsPlaying() && !HasVideo() && HasAudio());
193 bool CApplicationPlayer::IsPlayingVideo() const
195 return (IsPlaying() && HasVideo());
198 void CApplicationPlayer::Pause()
200 boost::shared_ptr<IPlayer> player = GetInternal();
205 bool CApplicationPlayer::ControlsVolume() const
207 boost::shared_ptr<IPlayer> player = GetInternal();
208 return (player && player->ControlsVolume());
211 void CApplicationPlayer::SetMute(bool bOnOff)
213 boost::shared_ptr<IPlayer> player = GetInternal();
215 player->SetMute(bOnOff);
218 void CApplicationPlayer::SetVolume(float volume)
220 boost::shared_ptr<IPlayer> player = GetInternal();
222 player->SetVolume(volume);
225 void CApplicationPlayer::Seek(bool bPlus, bool bLargeStep, bool bChapterOverride)
227 boost::shared_ptr<IPlayer> player = GetInternal();
229 player->Seek(bPlus, bLargeStep, bChapterOverride);
232 void CApplicationPlayer::SeekPercentage(float fPercent)
234 boost::shared_ptr<IPlayer> player = GetInternal();
236 player->SeekPercentage(fPercent);
239 bool CApplicationPlayer::IsPassthrough() const
241 boost::shared_ptr<IPlayer> player = GetInternal();
242 return (player && player->IsPassthrough());
245 bool CApplicationPlayer::CanSeek()
247 boost::shared_ptr<IPlayer> player = GetInternal();
248 return (player && player->CanSeek());
251 bool CApplicationPlayer::SeekScene(bool bPlus)
253 boost::shared_ptr<IPlayer> player = GetInternal();
254 return (player && player->SeekScene(bPlus));
257 void CApplicationPlayer::SeekTime(int64_t iTime)
259 boost::shared_ptr<IPlayer> player = GetInternal();
261 player->SeekTime(iTime);
264 CStdString CApplicationPlayer::GetPlayingTitle()
266 boost::shared_ptr<IPlayer> player = GetInternal();
268 return player->GetPlayingTitle();
273 int64_t CApplicationPlayer::GetTime() const
275 boost::shared_ptr<IPlayer> player = GetInternal();
277 return player->GetTime();
282 int CApplicationPlayer::GetPictureHeight()
284 boost::shared_ptr<IPlayer> player = GetInternal();
286 return player->GetPictureHeight();
291 int CApplicationPlayer::GetPictureWidth()
293 boost::shared_ptr<IPlayer> player = GetInternal();
295 return player->GetPictureWidth();
300 int CApplicationPlayer::GetSampleRate()
302 boost::shared_ptr<IPlayer> player = GetInternal();
304 return player->GetSampleRate();
309 bool CApplicationPlayer::IsCaching() const
311 boost::shared_ptr<IPlayer> player = GetInternal();
312 return (player && player->IsCaching());
315 bool CApplicationPlayer::IsInMenu() const
317 boost::shared_ptr<IPlayer> player = GetInternal();
318 return (player && player->IsInMenu());
321 bool CApplicationPlayer::HasMenu() const
323 boost::shared_ptr<IPlayer> player = GetInternal();
324 return (player && player->HasMenu());
327 int CApplicationPlayer::GetCacheLevel() const
329 boost::shared_ptr<IPlayer> player = GetInternal();
331 return player->GetCacheLevel();
336 int CApplicationPlayer::GetSubtitleCount()
338 boost::shared_ptr<IPlayer> player = GetInternal();
340 return player->GetSubtitleCount();
345 int CApplicationPlayer::GetBitsPerSample()
347 boost::shared_ptr<IPlayer> player = GetInternal();
349 return player->GetBitsPerSample();
354 int CApplicationPlayer::GetAudioStream()
356 boost::shared_ptr<IPlayer> player = GetInternal();
358 return player->GetAudioStream();
363 int CApplicationPlayer::GetSubtitle()
365 boost::shared_ptr<IPlayer> player = GetInternal();
367 return player->GetSubtitle();
372 bool CApplicationPlayer::GetSubtitleVisible()
374 boost::shared_ptr<IPlayer> player = GetInternal();
375 return (player && player->GetSubtitleVisible());
378 bool CApplicationPlayer::CanRecord()
380 boost::shared_ptr<IPlayer> player = GetInternal();
381 return (player && player->CanRecord());
384 bool CApplicationPlayer::CanPause()
386 boost::shared_ptr<IPlayer> player = GetInternal();
387 return (player && player->CanPause());
390 bool CApplicationPlayer::IsRecording() const
392 boost::shared_ptr<IPlayer> player = GetInternal();
393 return (player && player->IsRecording());
396 TextCacheStruct_t* CApplicationPlayer::GetTeletextCache()
398 boost::shared_ptr<IPlayer> player = GetInternal();
400 return player->GetTeletextCache();
405 int64_t CApplicationPlayer::GetTotalTime() const
407 boost::shared_ptr<IPlayer> player = GetInternal();
409 return player->GetTotalTime();
414 float CApplicationPlayer::GetPercentage() const
416 boost::shared_ptr<IPlayer> player = GetInternal();
418 return player->GetPercentage();
423 float CApplicationPlayer::GetCachePercentage() const
425 boost::shared_ptr<IPlayer> player = GetInternal();
427 return player->GetCachePercentage();
432 void CApplicationPlayer::ToFFRW(int iSpeed)
434 boost::shared_ptr<IPlayer> player = GetInternal();
436 player->ToFFRW(iSpeed);
439 void CApplicationPlayer::DoAudioWork()
441 boost::shared_ptr<IPlayer> player = GetInternal();
443 player->DoAudioWork();
446 CStdString CApplicationPlayer::GetPlayerState()
448 boost::shared_ptr<IPlayer> player = GetInternal();
450 return player->GetPlayerState();
455 bool CApplicationPlayer::QueueNextFile(const CFileItem &file)
457 boost::shared_ptr<IPlayer> player = GetInternal();
458 return (player && player->QueueNextFile(file));
461 bool CApplicationPlayer::GetStreamDetails(CStreamDetails &details)
463 boost::shared_ptr<IPlayer> player = GetInternal();
464 return (player && player->GetStreamDetails(details));
467 bool CApplicationPlayer::SetPlayerState(CStdString state)
469 boost::shared_ptr<IPlayer> player = GetInternal();
470 return (player && player->SetPlayerState(state));
473 void CApplicationPlayer::OnNothingToQueueNotify()
475 boost::shared_ptr<IPlayer> player = GetInternal();
477 player->OnNothingToQueueNotify();
480 void CApplicationPlayer::GetVideoStreamInfo(SPlayerVideoStreamInfo &info)
482 boost::shared_ptr<IPlayer> player = GetInternal();
484 player->GetVideoStreamInfo(info);
487 void CApplicationPlayer::GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info)
489 boost::shared_ptr<IPlayer> player = GetInternal();
491 player->GetAudioStreamInfo(index, info);
494 bool CApplicationPlayer::OnAction(const CAction &action)
496 boost::shared_ptr<IPlayer> player = GetInternal();
497 return (player && player->OnAction(action));
500 bool CApplicationPlayer::Record(bool bOnOff)
502 boost::shared_ptr<IPlayer> player = GetInternal();
503 return (player && player->Record(bOnOff));
506 int CApplicationPlayer::GetAudioStreamCount()
508 boost::shared_ptr<IPlayer> player = GetInternal();
510 return player->GetAudioStreamCount();
515 void CApplicationPlayer::SetAudioStream(int iStream)
517 boost::shared_ptr<IPlayer> player = GetInternal();
519 player->SetAudioStream(iStream);
522 void CApplicationPlayer::GetSubtitleStreamInfo(int index, SPlayerSubtitleStreamInfo &info)
524 boost::shared_ptr<IPlayer> player = GetInternal();
526 player->GetSubtitleStreamInfo(index, info);
529 void CApplicationPlayer::SetSubtitle(int iStream)
531 boost::shared_ptr<IPlayer> player = GetInternal();
533 player->SetSubtitle(iStream);
536 void CApplicationPlayer::SetSubtitleVisible(bool bVisible)
538 boost::shared_ptr<IPlayer> player = GetInternal();
540 player->SetSubtitleVisible(bVisible);
543 int CApplicationPlayer::AddSubtitle(const CStdString& strSubPath)
545 boost::shared_ptr<IPlayer> player = GetInternal();
547 return player->AddSubtitle(strSubPath);
552 void CApplicationPlayer::SetSubTitleDelay(float fValue)
554 boost::shared_ptr<IPlayer> player = GetInternal();
556 player->SetSubTitleDelay(fValue);
559 void CApplicationPlayer::SetAVDelay(float fValue)
561 boost::shared_ptr<IPlayer> player = GetInternal();
563 player->SetAVDelay(fValue);
566 void CApplicationPlayer::SetDynamicRangeCompression(long drc)
568 boost::shared_ptr<IPlayer> player = GetInternal();
570 player->SetDynamicRangeCompression(drc);
573 bool CApplicationPlayer::SwitchChannel(const PVR::CPVRChannel &channel)
575 boost::shared_ptr<IPlayer> player = GetInternal();
576 return (player && player->SwitchChannel(channel));
579 void CApplicationPlayer::LoadPage(int p, int sp, unsigned char* buffer)
581 boost::shared_ptr<IPlayer> player = GetInternal();
583 player->LoadPage(p, sp, buffer);
586 void CApplicationPlayer::GetAudioCapabilities(std::vector<int> &audioCaps)
588 boost::shared_ptr<IPlayer> player = GetInternal();
590 player->GetAudioCapabilities(audioCaps);
593 void CApplicationPlayer::GetSubtitleCapabilities(std::vector<int> &subCaps)
595 boost::shared_ptr<IPlayer> player = GetInternal();
597 player->GetSubtitleCapabilities(subCaps);
600 void CApplicationPlayer::GetAudioInfo( CStdString& strAudioInfo)
602 boost::shared_ptr<IPlayer> player = GetInternal();
604 player->GetAudioInfo(strAudioInfo);
607 void CApplicationPlayer::GetVideoInfo( CStdString& strVideoInfo)
609 boost::shared_ptr<IPlayer> player = GetInternal();
611 player->GetVideoInfo(strVideoInfo);
614 void CApplicationPlayer::GetGeneralInfo( CStdString& strVideoInfo)
616 boost::shared_ptr<IPlayer> player = GetInternal();
618 player->GetGeneralInfo(strVideoInfo);
621 bool CApplicationPlayer::GetCurrentSubtitle(CStdString& strSubtitle)
623 boost::shared_ptr<IPlayer> player = GetInternal();
624 return (player && player->GetCurrentSubtitle(strSubtitle));
627 int CApplicationPlayer::SeekChapter(int iChapter)
629 boost::shared_ptr<IPlayer> player = GetInternal();
631 return player->SeekChapter(iChapter);
636 void CApplicationPlayer::GetRenderFeatures(std::vector<int> &renderFeatures)
638 boost::shared_ptr<IPlayer> player = GetInternal();
640 player->GetRenderFeatures(renderFeatures);
643 void CApplicationPlayer::GetDeinterlaceMethods(std::vector<int> &deinterlaceMethods)
645 boost::shared_ptr<IPlayer> player = GetInternal();
647 player->GetDeinterlaceMethods(deinterlaceMethods);
650 void CApplicationPlayer::GetDeinterlaceModes(std::vector<int> &deinterlaceModes)
652 boost::shared_ptr<IPlayer> player = GetInternal();
654 player->GetDeinterlaceModes(deinterlaceModes);
657 void CApplicationPlayer::GetScalingMethods(std::vector<int> &scalingMethods)
659 boost::shared_ptr<IPlayer> player = GetInternal();
661 player->GetScalingMethods(scalingMethods);
664 void CApplicationPlayer::SetPlaySpeed(int iSpeed, bool bApplicationMuted)
666 boost::shared_ptr<IPlayer> player = GetInternal();
670 if (!IsPlayingAudio() && !IsPlayingVideo())
672 if (m_iPlaySpeed == iSpeed)
679 ((m_iPlaySpeed > 1) && (iSpeed > m_iPlaySpeed)) ||
680 ((m_iPlaySpeed < -1) && (iSpeed < m_iPlaySpeed))
683 iSpeed = m_iPlaySpeed; // from pause to ff/rw, do previous ff/rw speed
687 m_iPlaySpeed = iSpeed;
689 ToFFRW(m_iPlaySpeed);
691 // if player has volume control, set it.
692 if (ControlsVolume())
694 if (m_iPlaySpeed == 1)
696 player->SetVolume(VOLUME_MAXIMUM);
700 player->SetVolume(VOLUME_MINIMUM);
702 player->SetMute(bApplicationMuted);
706 int CApplicationPlayer::GetPlaySpeed() const