[ExecString] combine SplitParameters with identical function of CUtil
[xbmc.git] / xbmc / application / ApplicationPlayer.cpp
blob9d14233e2217bdb0b313ac02d658f9325c33083b
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "ApplicationPlayer.h"
11 #include "ServiceBroker.h"
12 #include "cores/DataCacheCore.h"
13 #include "cores/IPlayer.h"
14 #include "cores/VideoPlayer/VideoPlayer.h"
15 #include "cores/playercorefactory/PlayerCoreFactory.h"
16 #include "guilib/GUIComponent.h"
17 #include "guilib/GUIWindowManager.h"
18 #include "settings/AdvancedSettings.h"
19 #include "settings/SettingsComponent.h"
21 #include <mutex>
23 using namespace std::chrono_literals;
25 std::shared_ptr<const IPlayer> CApplicationPlayer::GetInternal() const
27 std::unique_lock<CCriticalSection> lock(m_playerLock);
28 return m_pPlayer;
31 std::shared_ptr<IPlayer> CApplicationPlayer::GetInternal()
33 std::unique_lock<CCriticalSection> lock(m_playerLock);
34 return m_pPlayer;
37 void CApplicationPlayer::ClosePlayer()
39 m_nextItem.pItem.reset();
40 std::shared_ptr<IPlayer> player = GetInternal();
41 if (player)
43 CloseFile();
44 ResetPlayer();
48 void CApplicationPlayer::ResetPlayer()
50 // we need to do this directly on the member
51 std::unique_lock<CCriticalSection> lock(m_playerLock);
52 m_pPlayer.reset();
55 void CApplicationPlayer::CloseFile(bool reopen)
57 std::shared_ptr<IPlayer> player = GetInternal();
58 if (player)
60 player->CloseFile(reopen);
64 void CApplicationPlayer::CreatePlayer(const CPlayerCoreFactory &factory, const std::string &player, IPlayerCallback& callback)
66 std::unique_lock<CCriticalSection> lock(m_playerLock);
67 if (!m_pPlayer)
69 CDataCacheCore::GetInstance().Reset();
70 m_pPlayer = factory.CreatePlayer(player, callback);
74 std::string CApplicationPlayer::GetCurrentPlayer() const
76 std::shared_ptr<const IPlayer> player = GetInternal();
77 if (player)
79 return player->m_name;
81 return "";
84 bool CApplicationPlayer::OpenFile(const CFileItem& item, const CPlayerOptions& options,
85 const CPlayerCoreFactory &factory,
86 const std::string &playerName, IPlayerCallback& callback)
88 // get player type
89 std::string newPlayer;
90 if (!playerName.empty())
91 newPlayer = playerName;
92 else
93 newPlayer = factory.GetDefaultPlayer(item);
95 // check if we need to close current player
96 // VideoPlayer can open a new file while playing
97 std::shared_ptr<IPlayer> player = GetInternal();
98 if (player && player->IsPlaying())
100 bool needToClose = false;
102 if (item.IsDiscImage() || item.IsDVDFile())
103 needToClose = true;
105 if (player->m_name != newPlayer)
106 needToClose = true;
108 if (player->m_type != "video" && player->m_type != "remote")
109 needToClose = true;
111 if (needToClose)
113 m_nextItem.pItem = std::make_shared<CFileItem>(item);
114 m_nextItem.options = options;
115 m_nextItem.playerName = newPlayer;
116 m_nextItem.callback = &callback;
118 CloseFile();
119 if (player->m_name != newPlayer)
121 std::unique_lock<CCriticalSection> lock(m_playerLock);
122 m_pPlayer.reset();
124 return true;
127 else if (player && player->m_name != newPlayer)
129 CloseFile();
131 std::unique_lock<CCriticalSection> lock(m_playerLock);
132 m_pPlayer.reset();
133 player.reset();
137 if (!player)
139 CreatePlayer(factory, newPlayer, callback);
140 player = GetInternal();
141 if (!player)
142 return false;
145 bool ret = player->OpenFile(item, options);
147 m_nextItem.pItem.reset();
149 // reset caching timers
150 m_audioStreamUpdate.SetExpired();
151 m_videoStreamUpdate.SetExpired();
152 m_subtitleStreamUpdate.SetExpired();
154 return ret;
157 void CApplicationPlayer::OpenNext(const CPlayerCoreFactory &factory)
159 if (m_nextItem.pItem)
161 OpenFile(*m_nextItem.pItem, m_nextItem.options,
162 factory,
163 m_nextItem.playerName, *m_nextItem.callback);
164 m_nextItem.pItem.reset();
168 bool CApplicationPlayer::HasPlayer() const
170 std::shared_ptr<const IPlayer> player = GetInternal();
171 return player != nullptr;
174 int CApplicationPlayer::GetChapter() const
176 const std::shared_ptr<const IPlayer> player = GetInternal();
177 if (player)
178 return player->GetChapter();
179 else
180 return -1;
183 int CApplicationPlayer::GetChapterCount() const
185 const std::shared_ptr<const IPlayer> player = GetInternal();
186 if (player)
187 return player->GetChapterCount();
188 else
189 return 0;
192 void CApplicationPlayer::GetChapterName(std::string& strChapterName, int chapterIdx) const
194 const std::shared_ptr<const IPlayer> player = GetInternal();
195 if (player)
196 player->GetChapterName(strChapterName, chapterIdx);
199 int64_t CApplicationPlayer::GetChapterPos(int chapterIdx) const
201 const std::shared_ptr<const IPlayer> player = GetInternal();
202 if (player)
203 return player->GetChapterPos(chapterIdx);
205 return -1;
208 bool CApplicationPlayer::HasAudio() const
210 std::shared_ptr<const IPlayer> player = GetInternal();
211 return (player && player->HasAudio());
214 bool CApplicationPlayer::HasVideo() const
216 std::shared_ptr<const IPlayer> player = GetInternal();
217 return (player && player->HasVideo());
220 bool CApplicationPlayer::HasGame() const
222 std::shared_ptr<const IPlayer> player = GetInternal();
223 return (player && player->HasGame());
226 PLAYLIST::Id CApplicationPlayer::GetPreferredPlaylist() const
228 if (IsPlayingVideo())
229 return PLAYLIST::TYPE_VIDEO;
231 if (IsPlayingAudio())
232 return PLAYLIST::TYPE_MUSIC;
234 return PLAYLIST::TYPE_NONE;
237 bool CApplicationPlayer::HasRDS() const
239 std::shared_ptr<const IPlayer> player = GetInternal();
240 return (player && player->HasRDS());
243 bool CApplicationPlayer::IsPaused() const
245 return (GetPlaySpeed() == 0);
248 bool CApplicationPlayer::IsPlaying() const
250 std::shared_ptr<const IPlayer> player = GetInternal();
251 return (player && player->IsPlaying());
254 bool CApplicationPlayer::IsPausedPlayback() const
256 return (IsPlaying() && (GetPlaySpeed() == 0));
259 bool CApplicationPlayer::IsPlayingAudio() const
261 return (IsPlaying() && !HasVideo() && HasAudio());
264 bool CApplicationPlayer::IsPlayingVideo() const
266 return (IsPlaying() && HasVideo());
269 bool CApplicationPlayer::IsPlayingGame() const
271 return (IsPlaying() && HasGame());
274 bool CApplicationPlayer::IsPlayingRDS() const
276 return (IsPlaying() && HasRDS());
279 void CApplicationPlayer::Pause()
281 std::shared_ptr<IPlayer> player = GetInternal();
282 if (player)
284 player->Pause();
288 void CApplicationPlayer::SetMute(bool bOnOff)
290 std::shared_ptr<IPlayer> player = GetInternal();
291 if (player)
292 player->SetMute(bOnOff);
295 void CApplicationPlayer::SetVolume(float volume)
297 std::shared_ptr<IPlayer> player = GetInternal();
298 if (player)
299 player->SetVolume(volume);
302 void CApplicationPlayer::Seek(bool bPlus, bool bLargeStep, bool bChapterOverride)
304 std::shared_ptr<IPlayer> player = GetInternal();
305 if (player)
306 player->Seek(bPlus, bLargeStep, bChapterOverride);
309 void CApplicationPlayer::SeekPercentage(float fPercent)
311 std::shared_ptr<IPlayer> player = GetInternal();
312 if (player)
313 player->SeekPercentage(fPercent);
316 bool CApplicationPlayer::IsPassthrough() const
318 std::shared_ptr<const IPlayer> player = GetInternal();
319 return (player && player->IsPassthrough());
322 bool CApplicationPlayer::CanSeek() const
324 const std::shared_ptr<const IPlayer> player = GetInternal();
325 return (player && player->CanSeek());
328 bool CApplicationPlayer::SeekScene(bool bPlus)
330 std::shared_ptr<IPlayer> player = GetInternal();
331 return (player && player->SeekScene(bPlus));
334 void CApplicationPlayer::SeekTime(int64_t iTime)
336 std::shared_ptr<IPlayer> player = GetInternal();
337 if (player)
338 player->SeekTime(iTime);
341 void CApplicationPlayer::SeekTimeRelative(int64_t iTime)
343 std::shared_ptr<IPlayer> player = GetInternal();
344 if (player)
346 // use relative seeking if implemented by player
347 if (!player->SeekTimeRelative(iTime))
349 int64_t abstime = GetTime() + iTime;
350 player->SeekTime(abstime);
355 int64_t CApplicationPlayer::GetTime() const
357 std::shared_ptr<const IPlayer> player = GetInternal();
358 if (player)
359 return CDataCacheCore::GetInstance().GetPlayTime();
360 else
361 return 0;
364 int64_t CApplicationPlayer::GetMinTime() const
366 std::shared_ptr<const IPlayer> player = GetInternal();
367 if (player)
368 return CDataCacheCore::GetInstance().GetMinTime();
369 else
370 return 0;
373 int64_t CApplicationPlayer::GetMaxTime() const
375 std::shared_ptr<const IPlayer> player = GetInternal();
376 if (player)
377 return CDataCacheCore::GetInstance().GetMaxTime();
378 else
379 return 0;
382 time_t CApplicationPlayer::GetStartTime() const
384 std::shared_ptr<const IPlayer> player = GetInternal();
385 if (player)
386 return CDataCacheCore::GetInstance().GetStartTime();
387 else
388 return 0;
391 int64_t CApplicationPlayer::GetTotalTime() const
393 std::shared_ptr<const IPlayer> player = GetInternal();
394 if (player)
396 int64_t total = CDataCacheCore::GetInstance().GetMaxTime() - CDataCacheCore::GetInstance().GetMinTime();
397 return total;
399 else
400 return 0;
403 bool CApplicationPlayer::IsCaching() const
405 std::shared_ptr<const IPlayer> player = GetInternal();
406 return (player && player->IsCaching());
409 bool CApplicationPlayer::IsInMenu() const
411 std::shared_ptr<const IPlayer> player = GetInternal();
412 return (player && player->IsInMenu());
415 MenuType CApplicationPlayer::GetSupportedMenuType() const
417 std::shared_ptr<const IPlayer> player = GetInternal();
418 if (!player)
420 return MenuType::NONE;
422 return player->GetSupportedMenuType();
425 int CApplicationPlayer::GetCacheLevel() const
427 std::shared_ptr<const IPlayer> player = GetInternal();
428 if (player)
429 return player->GetCacheLevel();
430 else
431 return 0;
434 int CApplicationPlayer::GetSubtitleCount() const
436 const std::shared_ptr<const IPlayer> player = GetInternal();
437 if (player)
438 return player->GetSubtitleCount();
439 else
440 return 0;
443 int CApplicationPlayer::GetAudioStream()
445 if (!m_audioStreamUpdate.IsTimePast())
446 return m_iAudioStream;
448 std::shared_ptr<IPlayer> player = GetInternal();
449 if (player)
451 m_iAudioStream = player->GetAudioStream();
452 m_audioStreamUpdate.Set(1000ms);
453 return m_iAudioStream;
455 else
456 return 0;
459 int CApplicationPlayer::GetSubtitle()
461 if (!m_subtitleStreamUpdate.IsTimePast())
462 return m_iSubtitleStream;
464 std::shared_ptr<IPlayer> player = GetInternal();
465 if (player)
467 m_iSubtitleStream = player->GetSubtitle();
468 m_subtitleStreamUpdate.Set(1000ms);
469 return m_iSubtitleStream;
471 else
472 return 0;
475 bool CApplicationPlayer::GetSubtitleVisible() const
477 const std::shared_ptr<const IPlayer> player = GetInternal();
478 return player && player->GetSubtitleVisible();
481 bool CApplicationPlayer::CanPause() const
483 const std::shared_ptr<const IPlayer> player = GetInternal();
484 return (player && player->CanPause());
487 bool CApplicationPlayer::HasTeletextCache() const
489 const std::shared_ptr<const IPlayer> player = GetInternal();
490 if (player)
491 return player->HasTeletextCache();
492 else
493 return false;
496 std::shared_ptr<TextCacheStruct_t> CApplicationPlayer::GetTeletextCache()
498 std::shared_ptr<IPlayer> player = GetInternal();
499 if (player)
500 return player->GetTeletextCache();
501 else
502 return {};
505 float CApplicationPlayer::GetPercentage() const
507 std::shared_ptr<const IPlayer> player = GetInternal();
508 if (player)
510 float fPercent = CDataCacheCore::GetInstance().GetPlayPercentage();
511 return std::max(0.0f, std::min(fPercent, 100.0f));
513 else
514 return 0.0;
517 float CApplicationPlayer::GetCachePercentage() const
519 std::shared_ptr<const IPlayer> player = GetInternal();
520 if (player)
521 return player->GetCachePercentage();
522 else
523 return 0.0;
526 void CApplicationPlayer::SetSpeed(float speed)
528 std::shared_ptr<IPlayer> player = GetInternal();
529 if (player)
530 player->SetSpeed(speed);
533 void CApplicationPlayer::SetTempo(float tempo)
535 std::shared_ptr<IPlayer> player = GetInternal();
536 if (player)
537 player->SetTempo(tempo);
540 void CApplicationPlayer::FrameAdvance(int frames)
542 std::shared_ptr<IPlayer> player = GetInternal();
543 if (player)
544 player->FrameAdvance(frames);
547 std::string CApplicationPlayer::GetPlayerState()
549 std::shared_ptr<IPlayer> player = GetInternal();
550 if (player)
551 return player->GetPlayerState();
552 else
553 return "";
556 bool CApplicationPlayer::QueueNextFile(const CFileItem &file)
558 std::shared_ptr<IPlayer> player = GetInternal();
559 return (player && player->QueueNextFile(file));
562 bool CApplicationPlayer::SetPlayerState(const std::string& state)
564 std::shared_ptr<IPlayer> player = GetInternal();
565 return (player && player->SetPlayerState(state));
568 void CApplicationPlayer::OnNothingToQueueNotify()
570 std::shared_ptr<IPlayer> player = GetInternal();
571 if (player)
572 player->OnNothingToQueueNotify();
575 void CApplicationPlayer::GetVideoStreamInfo(int streamId, VideoStreamInfo& info) const
577 const std::shared_ptr<const IPlayer> player = GetInternal();
578 if (player)
579 player->GetVideoStreamInfo(streamId, info);
582 void CApplicationPlayer::GetAudioStreamInfo(int index, AudioStreamInfo& info) const
584 const std::shared_ptr<const IPlayer> player = GetInternal();
585 if (player)
586 player->GetAudioStreamInfo(index, info);
589 int CApplicationPlayer::GetPrograms(std::vector<ProgramInfo> &programs)
591 int ret = 0;
592 std::shared_ptr<IPlayer> player = GetInternal();
593 if (player)
594 ret = player->GetPrograms(programs);
595 return ret;
598 void CApplicationPlayer::SetProgram(int progId)
600 std::shared_ptr<IPlayer> player = GetInternal();
601 if (player)
602 player->SetProgram(progId);
605 int CApplicationPlayer::GetProgramsCount() const
607 int ret = 0;
608 const std::shared_ptr<const IPlayer> player = GetInternal();
609 if (player)
610 ret = player->GetProgramsCount();
611 return ret;
614 bool CApplicationPlayer::OnAction(const CAction &action)
616 std::shared_ptr<IPlayer> player = GetInternal();
617 return (player && player->OnAction(action));
620 int CApplicationPlayer::GetAudioStreamCount() const
622 const std::shared_ptr<const IPlayer> player = GetInternal();
623 if (player)
624 return player->GetAudioStreamCount();
625 else
626 return 0;
629 int CApplicationPlayer::GetVideoStream()
631 if (!m_videoStreamUpdate.IsTimePast())
632 return m_iVideoStream;
634 std::shared_ptr<IPlayer> player = GetInternal();
635 if (player)
637 m_iVideoStream = player->GetVideoStream();
638 m_videoStreamUpdate.Set(1000ms);
639 return m_iVideoStream;
641 else
642 return 0;
645 int CApplicationPlayer::GetVideoStreamCount() const
647 const std::shared_ptr<const IPlayer> player = GetInternal();
648 if (player)
649 return player->GetVideoStreamCount();
650 else
651 return 0;
654 void CApplicationPlayer::SetAudioStream(int iStream)
656 std::shared_ptr<IPlayer> player = GetInternal();
657 if (player)
659 player->SetAudioStream(iStream);
660 m_iAudioStream = iStream;
661 m_audioStreamUpdate.Set(1000ms);
665 void CApplicationPlayer::GetSubtitleStreamInfo(int index, SubtitleStreamInfo& info) const
667 const std::shared_ptr<const IPlayer> player = GetInternal();
668 if (player)
669 player->GetSubtitleStreamInfo(index, info);
672 void CApplicationPlayer::SetSubtitle(int iStream)
674 std::shared_ptr<IPlayer> player = GetInternal();
675 if (player)
677 player->SetSubtitle(iStream);
678 m_iSubtitleStream = iStream;
679 m_subtitleStreamUpdate.Set(1000ms);
683 void CApplicationPlayer::SetSubtitleVisible(bool bVisible)
685 std::shared_ptr<IPlayer> player = GetInternal();
686 if (player)
688 player->SetSubtitleVisible(bVisible);
692 void CApplicationPlayer::SetSubtitleVerticalPosition(int value, bool save)
694 std::shared_ptr<IPlayer> player = GetInternal();
695 if (player)
697 player->SetSubtitleVerticalPosition(value, save);
701 void CApplicationPlayer::SetTime(int64_t time)
703 std::shared_ptr<IPlayer> player = GetInternal();
704 if (player)
705 return player->SetTime(time);
708 void CApplicationPlayer::SetTotalTime(int64_t time)
710 std::shared_ptr<IPlayer> player = GetInternal();
711 if (player)
712 player->SetTotalTime(time);
715 void CApplicationPlayer::SetVideoStream(int iStream)
717 std::shared_ptr<IPlayer> player = GetInternal();
718 if (player)
720 player->SetVideoStream(iStream);
721 m_iVideoStream = iStream;
722 m_videoStreamUpdate.Set(1000ms);
726 void CApplicationPlayer::AddSubtitle(const std::string& strSubPath)
728 std::shared_ptr<IPlayer> player = GetInternal();
729 if (player)
730 player->AddSubtitle(strSubPath);
733 void CApplicationPlayer::SetSubTitleDelay(float fValue)
735 std::shared_ptr<IPlayer> player = GetInternal();
736 if (player)
737 player->SetSubTitleDelay(fValue);
740 void CApplicationPlayer::SetAVDelay(float fValue)
742 std::shared_ptr<IPlayer> player = GetInternal();
743 if (player)
744 player->SetAVDelay(fValue);
747 void CApplicationPlayer::SetDynamicRangeCompression(long drc)
749 std::shared_ptr<IPlayer> player = GetInternal();
750 if (player)
751 player->SetDynamicRangeCompression(drc);
754 void CApplicationPlayer::LoadPage(int p, int sp, unsigned char* buffer)
756 std::shared_ptr<IPlayer> player = GetInternal();
757 if (player)
758 player->LoadPage(p, sp, buffer);
761 void CApplicationPlayer::GetAudioCapabilities(std::vector<int>& audioCaps) const
763 const std::shared_ptr<const IPlayer> player = GetInternal();
764 if (player)
765 player->GetAudioCapabilities(audioCaps);
768 void CApplicationPlayer::GetSubtitleCapabilities(std::vector<int>& subCaps) const
770 const std::shared_ptr<const IPlayer> player = GetInternal();
771 if (player)
772 player->GetSubtitleCapabilities(subCaps);
775 int CApplicationPlayer::SeekChapter(int iChapter)
777 std::shared_ptr<IPlayer> player = GetInternal();
778 if (player)
779 return player->SeekChapter(iChapter);
780 else
781 return 0;
784 void CApplicationPlayer::SetPlaySpeed(float speed)
786 std::shared_ptr<IPlayer> player = GetInternal();
787 if (!player)
788 return;
790 if (!IsPlayingAudio() && !IsPlayingVideo())
791 return ;
793 SetSpeed(speed);
796 float CApplicationPlayer::GetPlaySpeed() const
798 std::shared_ptr<const IPlayer> player = GetInternal();
799 if (player)
801 return CDataCacheCore::GetInstance().GetSpeed();
803 else
804 return 0;
807 float CApplicationPlayer::GetPlayTempo() const
809 std::shared_ptr<const IPlayer> player = GetInternal();
810 if (player)
812 return CDataCacheCore::GetInstance().GetTempo();
814 else
815 return 0;
818 bool CApplicationPlayer::SupportsTempo() const
820 const std::shared_ptr<const IPlayer> player = GetInternal();
821 if (player)
822 return player->SupportsTempo();
823 else
824 return false;
827 void CApplicationPlayer::FrameMove()
829 std::shared_ptr<IPlayer> player = GetInternal();
830 if (player)
832 if (CDataCacheCore::GetInstance().IsPlayerStateChanged())
833 // CApplicationMessenger would be overhead because we are already in gui thread
834 CServiceBroker::GetGUI()->GetWindowManager().SendMessage(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_STATE_CHANGED);
838 void CApplicationPlayer::Render(bool clear, uint32_t alpha, bool gui)
840 std::shared_ptr<IPlayer> player = GetInternal();
841 if (player)
842 player->Render(clear, alpha, gui);
845 void CApplicationPlayer::FlushRenderer()
847 std::shared_ptr<IPlayer> player = GetInternal();
848 if (player)
849 player->FlushRenderer();
852 void CApplicationPlayer::SetRenderViewMode(int mode, float zoom, float par, float shift, bool stretch)
854 std::shared_ptr<IPlayer> player = GetInternal();
855 if (player)
856 player->SetRenderViewMode(mode, zoom, par, shift, stretch);
859 float CApplicationPlayer::GetRenderAspectRatio() const
861 const std::shared_ptr<const IPlayer> player = GetInternal();
862 if (player)
863 return player->GetRenderAspectRatio();
864 else
865 return 1.0;
868 void CApplicationPlayer::TriggerUpdateResolution()
870 std::shared_ptr<IPlayer> player = GetInternal();
871 if (player)
872 player->TriggerUpdateResolution();
875 bool CApplicationPlayer::IsRenderingVideo() const
877 const std::shared_ptr<const IPlayer> player = GetInternal();
878 if (player)
879 return player->IsRenderingVideo();
880 else
881 return false;
884 bool CApplicationPlayer::IsRenderingGuiLayer() const
886 const std::shared_ptr<const IPlayer> player = GetInternal();
887 if (player)
888 return CServiceBroker::GetDataCacheCore().GetGuiRender();
889 else
890 return false;
893 bool CApplicationPlayer::IsRenderingVideoLayer() const
895 const std::shared_ptr<const IPlayer> player = GetInternal();
896 if (player)
897 return CServiceBroker::GetDataCacheCore().GetVideoRender();
898 else
899 return false;
902 bool CApplicationPlayer::Supports(EINTERLACEMETHOD method) const
904 const std::shared_ptr<const IPlayer> player = GetInternal();
905 if (player)
906 return player->Supports(method);
907 else
908 return false;
911 EINTERLACEMETHOD CApplicationPlayer::GetDeinterlacingMethodDefault() const
913 const std::shared_ptr<const IPlayer> player = GetInternal();
914 if (player)
915 return player->GetDeinterlacingMethodDefault();
916 else
917 return EINTERLACEMETHOD::VS_INTERLACEMETHOD_NONE;
920 bool CApplicationPlayer::Supports(ESCALINGMETHOD method) const
922 const std::shared_ptr<const IPlayer> player = GetInternal();
923 if (player)
924 return player->Supports(method);
925 else
926 return false;
929 bool CApplicationPlayer::Supports(ERENDERFEATURE feature) const
931 const std::shared_ptr<const IPlayer> player = GetInternal();
932 if (player)
933 return player->Supports(feature);
934 else
935 return false;
938 unsigned int CApplicationPlayer::RenderCaptureAlloc()
940 std::shared_ptr<IPlayer> player = GetInternal();
941 if (player)
942 return player->RenderCaptureAlloc();
943 else
944 return 0;
947 void CApplicationPlayer::RenderCapture(unsigned int captureId, unsigned int width, unsigned int height, int flags)
949 std::shared_ptr<IPlayer> player = GetInternal();
950 if (player)
951 player->RenderCapture(captureId, width, height, flags);
954 void CApplicationPlayer::RenderCaptureRelease(unsigned int captureId)
956 std::shared_ptr<IPlayer> player = GetInternal();
957 if (player)
958 player->RenderCaptureRelease(captureId);
961 bool CApplicationPlayer::RenderCaptureGetPixels(unsigned int captureId, unsigned int millis, uint8_t *buffer, unsigned int size)
963 std::shared_ptr<IPlayer> player = GetInternal();
964 if (player)
965 return player->RenderCaptureGetPixels(captureId, millis, buffer, size);
966 else
967 return false;
970 bool CApplicationPlayer::IsExternalPlaying() const
972 const std::shared_ptr<const IPlayer> player = GetInternal();
973 if (player)
975 if (player->IsPlaying() && player->m_type == "external")
976 return true;
978 return false;
981 bool CApplicationPlayer::IsRemotePlaying() const
983 const std::shared_ptr<const IPlayer> player = GetInternal();
984 if (player)
986 if (player->IsPlaying() && player->m_type == "remote")
987 return true;
989 return false;
992 std::string CApplicationPlayer::GetName() const
994 const std::shared_ptr<const IPlayer> player = GetInternal();
995 if (player)
997 return player->m_name;
999 return {};
1002 CVideoSettings CApplicationPlayer::GetVideoSettings() const
1004 std::shared_ptr<const IPlayer> player = GetInternal();
1005 if (player)
1007 return player->GetVideoSettings();
1009 return CVideoSettings();
1012 void CApplicationPlayer::SetVideoSettings(CVideoSettings& settings)
1014 std::shared_ptr<IPlayer> player = GetInternal();
1015 if (player)
1017 return player->SetVideoSettings(settings);
1021 CSeekHandler& CApplicationPlayer::GetSeekHandler()
1023 return m_seekHandler;
1026 const CSeekHandler& CApplicationPlayer::GetSeekHandler() const
1028 return m_seekHandler;
1031 void CApplicationPlayer::SetUpdateStreamDetails()
1033 std::shared_ptr<IPlayer> player = GetInternal();
1034 CVideoPlayer* vp = dynamic_cast<CVideoPlayer*>(player.get());
1035 if (vp)
1036 vp->SetUpdateStreamDetails();
1039 bool CApplicationPlayer::HasGameAgent() const
1041 const std::shared_ptr<const IPlayer> player = GetInternal();
1042 if (player)
1043 return player->HasGameAgent();
1045 return false;
1048 int CApplicationPlayer::GetSubtitleDelay() const
1050 // converts subtitle delay to a percentage
1051 const auto& advSettings = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings();
1052 const auto delay = this->GetVideoSettings().m_SubtitleDelay;
1053 const auto range = advSettings->m_videoSubsDelayRange;
1054 return static_cast<int>(0.5f + (delay + range) / (2.f * range) * 100.0f);
1057 int CApplicationPlayer::GetAudioDelay() const
1059 // converts audio delay to a percentage
1060 const auto& advSettings = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings();
1061 const auto delay = this->GetVideoSettings().m_AudioDelay;
1062 const auto range = advSettings->m_videoAudioDelayRange;
1063 return static_cast<int>(0.5f + (delay + range) / (2.f * range) * 100.0f);