PageRenderTime 46ms CodeModel.GetById 15ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

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