/xbmc/cores/DummyVideoPlayer.cpp

http://github.com/xbmc/xbmc · C++ · 303 lines · 240 code · 37 blank · 26 comment · 15 complexity · 59ef3d8980414fc9b1da02d4071cb501 MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2013 Team XBMC
  3. * http://xbmc.org
  4. *
  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)
  8. * any later version.
  9. *
  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.
  14. *
  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/>.
  18. *
  19. */
  20. #include "threads/SystemClock.h"
  21. #include "system.h"
  22. #include "DummyVideoPlayer.h"
  23. #include "guilib/GUIFontManager.h"
  24. #include "guilib/GUITextLayout.h"
  25. #include "guilib/GUIFont.h" // for XBFONT_* defines
  26. #include "Application.h"
  27. #include "settings/AdvancedSettings.h"
  28. #include "windowing/WindowingFactory.h"
  29. #include "utils/log.h"
  30. #include "utils/TimeUtils.h"
  31. CDummyVideoPlayer::CDummyVideoPlayer(IPlayerCallback& callback)
  32. : IPlayer(callback),
  33. CThread("DummyVideoPlayer")
  34. {
  35. m_paused = false;
  36. m_clock = 0;
  37. m_lastTime = 0;
  38. m_speed = 1;
  39. }
  40. CDummyVideoPlayer::~CDummyVideoPlayer()
  41. {
  42. CloseFile();
  43. }
  44. bool CDummyVideoPlayer::OpenFile(const CFileItem& file, const CPlayerOptions &options)
  45. {
  46. try
  47. {
  48. Create();
  49. if( options.starttime > 0 )
  50. SeekTime( (int64_t)(options.starttime * 1000) );
  51. return true;
  52. }
  53. catch(...)
  54. {
  55. CLog::Log(LOGERROR,"%s - Exception thrown on open", __FUNCTION__);
  56. return false;
  57. }
  58. }
  59. bool CDummyVideoPlayer::CloseFile()
  60. {
  61. StopThread();
  62. return true;
  63. }
  64. bool CDummyVideoPlayer::IsPlaying() const
  65. {
  66. return !m_bStop;
  67. }
  68. void CDummyVideoPlayer::Process()
  69. {
  70. m_clock = 0;
  71. m_lastTime = XbmcThreads::SystemClockMillis();
  72. m_callback.OnPlayBackStarted();
  73. while (!m_bStop)
  74. {
  75. if (!m_paused)
  76. m_clock += (XbmcThreads::SystemClockMillis() - m_lastTime)*m_speed;
  77. m_lastTime = XbmcThreads::SystemClockMillis();
  78. Sleep(0);
  79. g_graphicsContext.Lock();
  80. if (g_graphicsContext.IsFullScreenVideo())
  81. {
  82. #ifdef HAS_DX
  83. g_Windowing.Get3DDevice()->BeginScene();
  84. #endif
  85. g_graphicsContext.Clear();
  86. g_graphicsContext.SetRenderingResolution(g_graphicsContext.GetResInfo(), false);
  87. Render();
  88. g_application.RenderNoPresent();
  89. #ifdef HAS_DX
  90. g_Windowing.Get3DDevice()->EndScene();
  91. #endif
  92. }
  93. g_graphicsContext.Unlock();
  94. }
  95. if (m_bStop)
  96. m_callback.OnPlayBackEnded();
  97. }
  98. void CDummyVideoPlayer::Pause()
  99. {
  100. if (m_paused)
  101. m_callback.OnPlayBackResumed();
  102. else
  103. m_callback.OnPlayBackPaused();
  104. m_paused = !m_paused;
  105. }
  106. bool CDummyVideoPlayer::IsPaused() const
  107. {
  108. return m_paused;
  109. }
  110. bool CDummyVideoPlayer::HasVideo() const
  111. {
  112. return true;
  113. }
  114. bool CDummyVideoPlayer::HasAudio() const
  115. {
  116. return true;
  117. }
  118. void CDummyVideoPlayer::SwitchToNextLanguage()
  119. {
  120. }
  121. void CDummyVideoPlayer::ToggleSubtitles()
  122. {
  123. }
  124. bool CDummyVideoPlayer::CanSeek()
  125. {
  126. return GetTotalTime() > 0;
  127. }
  128. void CDummyVideoPlayer::Seek(bool bPlus, bool bLargeStep, bool bChapterOverride)
  129. {
  130. if (g_advancedSettings.m_videoUseTimeSeeking && GetTotalTime() > 2000*g_advancedSettings.m_videoTimeSeekForwardBig)
  131. {
  132. int seek = 0;
  133. if (bLargeStep)
  134. seek = bPlus ? g_advancedSettings.m_videoTimeSeekForwardBig : g_advancedSettings.m_videoTimeSeekBackwardBig;
  135. else
  136. seek = bPlus ? g_advancedSettings.m_videoTimeSeekForward : g_advancedSettings.m_videoTimeSeekBackward;
  137. // do the seek
  138. SeekTime(GetTime() + seek * 1000);
  139. }
  140. else
  141. {
  142. float percent = GetPercentage();
  143. if (bLargeStep)
  144. percent += bPlus ? g_advancedSettings.m_videoPercentSeekForwardBig : g_advancedSettings.m_videoPercentSeekBackwardBig;
  145. else
  146. percent += bPlus ? g_advancedSettings.m_videoPercentSeekForward : g_advancedSettings.m_videoPercentSeekBackward;
  147. if (percent >= 0 && percent <= 100)
  148. {
  149. // should be modified to seektime
  150. SeekPercentage(percent);
  151. }
  152. }
  153. }
  154. void CDummyVideoPlayer::GetAudioInfo(CStdString& strAudioInfo)
  155. {
  156. strAudioInfo = "DummyVideoPlayer - nothing to see here";
  157. }
  158. void CDummyVideoPlayer::GetVideoInfo(CStdString& strVideoInfo)
  159. {
  160. strVideoInfo = "DummyVideoPlayer - nothing to see here";
  161. }
  162. void CDummyVideoPlayer::GetGeneralInfo(CStdString& strGeneralInfo)
  163. {
  164. strGeneralInfo = "DummyVideoPlayer - what are you still looking for?";
  165. }
  166. void CDummyVideoPlayer::SwitchToNextAudioLanguage()
  167. {
  168. }
  169. void CDummyVideoPlayer::SeekPercentage(float iPercent)
  170. {
  171. int64_t iTime = (int64_t)(GetTotalTime() * iPercent / 100);
  172. SeekTime(iTime);
  173. }
  174. float CDummyVideoPlayer::GetPercentage()
  175. {
  176. int64_t iTotalTime = GetTotalTime();
  177. if (iTotalTime != 0)
  178. {
  179. return GetTime() * 100 / (float)iTotalTime;
  180. }
  181. return 0.0f;
  182. }
  183. //This is how much audio is delayed to video, we count the oposite in the dvdplayer
  184. void CDummyVideoPlayer::SetAVDelay(float fValue)
  185. {
  186. }
  187. float CDummyVideoPlayer::GetAVDelay()
  188. {
  189. return 0.0f;
  190. }
  191. void CDummyVideoPlayer::SetSubTitleDelay(float fValue)
  192. {
  193. }
  194. float CDummyVideoPlayer::GetSubTitleDelay()
  195. {
  196. return 0.0;
  197. }
  198. void CDummyVideoPlayer::SeekTime(int64_t iTime)
  199. {
  200. int seekOffset = (int)(iTime - m_clock);
  201. m_clock = iTime;
  202. m_callback.OnPlayBackSeek((int)iTime, seekOffset);
  203. }
  204. // return the time in milliseconds
  205. int64_t CDummyVideoPlayer::GetTime()
  206. {
  207. return m_clock;
  208. }
  209. // return length in milliseconds
  210. int64_t CDummyVideoPlayer::GetTotalTime()
  211. {
  212. return 1000000;
  213. }
  214. void CDummyVideoPlayer::ToFFRW(int iSpeed)
  215. {
  216. m_speed = iSpeed;
  217. m_callback.OnPlayBackSpeedChanged(iSpeed);
  218. }
  219. void CDummyVideoPlayer::ShowOSD(bool bOnoff)
  220. {
  221. }
  222. CStdString CDummyVideoPlayer::GetPlayerState()
  223. {
  224. return "";
  225. }
  226. bool CDummyVideoPlayer::SetPlayerState(CStdString state)
  227. {
  228. return true;
  229. }
  230. void CDummyVideoPlayer::Render()
  231. {
  232. const CRect vw = g_graphicsContext.GetViewWindow();
  233. #ifdef HAS_DX
  234. D3DVIEWPORT9 newviewport;
  235. D3DVIEWPORT9 oldviewport;
  236. g_Windowing.Get3DDevice()->GetViewport(&oldviewport);
  237. newviewport.MinZ = 0.0f;
  238. newviewport.MaxZ = 1.0f;
  239. newviewport.X = (DWORD)vw.x1;
  240. newviewport.Y = (DWORD)vw.y1;
  241. newviewport.Width = (DWORD)vw.Width();
  242. newviewport.Height = (DWORD)vw.Height();
  243. g_graphicsContext.SetClipRegion(vw.x1, vw.y1, vw.Width(), vw.Height());
  244. #else
  245. g_graphicsContext.SetViewPort(vw.x1, vw.y1, vw.Width(), vw.Height());
  246. #endif
  247. CGUIFont *font = g_fontManager.GetFont("font13");
  248. if (font)
  249. {
  250. // minor issue: The font rendering here is performed in screen coords
  251. // so shouldn't really be scaled
  252. int mins = (int)(m_clock / 60000);
  253. int secs = (int)((m_clock / 1000) % 60);
  254. int ms = (int)(m_clock % 1000);
  255. CStdString currentTime;
  256. currentTime.Format("Video goes here %02i:%02i:%03i", mins, secs, ms);
  257. float posX = (vw.x1 + vw.x2) * 0.5f;
  258. float posY = (vw.y1 + vw.y2) * 0.5f;
  259. CGUITextLayout::DrawText(font, posX, posY, 0xffffffff, 0, currentTime, XBFONT_CENTER_X | XBFONT_CENTER_Y);
  260. }
  261. #ifdef HAS_DX
  262. g_graphicsContext.RestoreClipRegion();
  263. #else
  264. g_graphicsContext.RestoreViewPort();
  265. #endif
  266. }