Vuo  2.3.2
VuoVideoPlayer.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "module.h"
13 
14 #ifdef __cplusplus
15 extern "C"
16 {
17 #endif
18 
19 #include "VuoAudioFrame.h"
20 #include "VuoVideoFrame.h"
21 #include "VuoUrl.h"
22 #include "VuoVideoOptimization.h"
23 #include <pthread.h>
24 
29 {
30 private:
31 
33  VuoVideoPlayer(VuoUrl url) :
34  playbackRate(1),
35  playOnReady(false),
36  onReadySeek(-1),
37  onReadyPlaybackRate(1),
38  lastVideoFrameDelta(0),
39  loop(VuoLoopType_None)
40  {
41  failedLoading = false;
42  isReady = false;
43 
46 
47  pthread_mutex_init(&decoderMutex, NULL);
48 
52 
53  video_timer = NULL;
54  audio_timer = NULL;
55  }
56 
58  ~VuoVideoPlayer();
59 
62  double playbackRate;
63 
67  double userSetPlaybackRate;
68 
70  class VuoVideoDecoder* decoder;
71 
73  dispatch_time_t playbackStart;
74 
79  double timestampStart;
80 
82  dispatch_source_t video_timer;
83 
85  dispatch_semaphore_t video_semaphore;
86 
88  dispatch_source_t audio_timer;
89 
91  dispatch_semaphore_t audio_semaphore;
92 
94  dispatch_time_t lastSentVideoTime;
95 
97  VuoVideoFrame videoFrame;
98 
100  VuoAudioFrame audioFrame;
101 
103  bool audioEnabled;
104 
106  bool isPlaying;
107 
109  bool isReady;
110 
112  bool failedLoading;
113 
116  bool playOnReady;
117 
119  double onReadySeek;
120 
122  double onReadyPlaybackRate;
123 
125  double lastVideoTimestamp;
126 
128  double lastVideoFrameDelta;
129 
131  double lastAudioTimestamp;
132 
134  void sendVideoFrame();
135 
137  void sendAudioFrame();
138 
140  void startTimer(dispatch_source_t* timer, dispatch_time_t start, dispatch_semaphore_t* semaphore, void (VuoVideoPlayer::*func)(void));
141 
143  void stopTimer(dispatch_source_t* timer, dispatch_semaphore_t* semaphore);
144 
146  void OnDecoderPlaybackReady(bool canPlayMedia);
147 
149  bool preferFfmpeg;
150 
152  pthread_mutex_t decoderMutex;
153 
155  void _SetPlaybackRate(double rate);
156 
158  void _Play(dispatch_time_t start);
159 
161  void _Pause();
162 
164  bool _Seek(double second) VuoWarnUnusedResult;
165 
166 public:
167 
172  static VuoVideoPlayer* Create(VuoUrl url, VuoVideoOptimization optimization);
173 
175  void Destroy();
176 
179 
182 
185 
190 
193 
198  void SetVideoDelegate(void(*func)(VuoVideoFrame)) {
200  }
201 
207  }
208 
213  void SetFinishedDelegate(void(*func)()) {
215  }
216 
218  void SetPlaybackRate(double rate);
220  // bool ContainsAudio();
222  void Play();
224  void Pause();
227  bool Seek(double second) VuoWarnUnusedResult;
229  double GetCurrentTimestamp();
231  double GetLastFrameDelta();
233  double GetDuration();
238  bool GetVideoFrameAtSecond(double second, VuoVideoFrame* videoFrame) VuoWarnUnusedResult;
240  unsigned int GetAudioChannels();
242  bool IsReady();
244  bool IsPlaying() { return isPlaying; }
249 };
250 
251 #ifdef __cplusplus
252 }
253 #endif