Vuo  2.3.2
VuoVideo.cc
Go to the documentation of this file.
1 
10 #include "VuoVideo.h"
11 #include "VuoVideoPlayer.h"
12 
13 extern "C"
14 {
15 
16 #ifdef VUO_COMPILER
18  "title" : "VuoVideo",
19  "dependencies" : [
20  "VuoVideoPlayer",
21  "VuoImage",
22  "VuoAudioSamples",
23  "VuoUrl",
24  "VuoVideoFrame",
25  "VuoReal",
26  "VuoList_VuoAudioSamples",
27  "VuoList_VuoReal"
28  ]
29  });
30 #endif
31 }
32 
36 void VuoVideo_free(void* player)
37 {
38  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
39  if(obj == NULL) return;
40  obj->Destroy();
41 }
42 
47 {
48  if (VuoText_isEmpty(path))
49  return NULL;
50 
51  VuoVideoPlayer* player = VuoVideoPlayer::Create(path, optimization);
52 
53  if(player != NULL)
54  VuoRegister(player, VuoVideo_free);
55 
56  return player;
57 }
58 
61 void VuoVideo_setVideoDelegate(VuoVideo player, void(*delegate)(VuoVideoFrame))
62 {
63  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
64  if(obj == NULL) return;
65  obj->SetVideoDelegate(delegate);
66 }
67 
68 
72 {
73  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
74  if(obj == NULL) return;
75  obj->SetAudioDelegate(delegate);
76 }
77 
78 void VuoVideo_setPlaybackFinishedDelegate(VuoVideo player, void(*delegate)(void))
79 {
80  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
81  if(obj == NULL) return;
82  obj->SetFinishedDelegate(delegate);
83 }
84 
88 const char* VuoVideo_getPath(VuoVideo player);
89 
93 void VuoVideo_play(VuoVideo player)
94 {
95  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
96  if(obj == NULL) return;
97  obj->Play();
98 }
99 
104 {
105  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
106  if(obj == NULL) return;
107  obj->Pause();
108 }
109 
111 {
112  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
113  if(obj == NULL) return false;
114 
115  return obj->Seek(second);
116 }
117 
119 {
120  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
121  if(obj == NULL) return 0;
122  return obj->GetDuration();
123 }
124 
126 {
127  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
128  if(obj == NULL) return;
129 
130  obj->loop = loop;
131 }
132 
134 {
135  VuoVideoPlayer* obj = (VuoVideoPlayer*) player;
136  if(!obj) return;
137 
138  obj->SetPlaybackRate(rate);
139 }
140 
142 {
143  VuoVideoPlayer* obj = (VuoVideoPlayer*) player;
144  if(obj == NULL) return 0.;
145  return obj->GetCurrentTimestamp();
146 }
147 
149 {
150  VuoVideoPlayer* obj = (VuoVideoPlayer*) player;
151  if(obj == NULL) return 0.;
152  return obj->IsPlaying();
153 }
154 
156 {
157  VuoVideoPlayer* obj = (VuoVideoPlayer*) player;
158  if(obj == NULL) return 0.;
159  return obj->GetLastFrameDelta();
160 }
161 
162 bool VuoVideo_getFrameAtSecond(VuoVideo player, VuoReal second, VuoVideoFrame* videoFrame)
163 {
164  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
165 
166  if(obj == NULL)
167  return false;
168 
169  return obj->GetVideoFrameAtSecond(second, videoFrame);
170 }
171 
173 {
174  VuoVideoPlayer* obj = (VuoVideoPlayer*) player;
175  if(obj == NULL) return false;
176  return obj->NextVideoFrame(videoFrame);
177 }
178 
180 {
181  VuoVideoPlayer* obj = (VuoVideoPlayer*) player;
182  if(obj == NULL) return false;
183  return obj->NextAudioFrame(audioFrame);
184 }
185 
187 {
188  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
189  if(obj == NULL)
190  return 0;
191 
192  return obj->GetAudioChannels();
193 }
194 
196 {
197  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
198  if(obj == NULL) return false;
199  return obj->IsReady();
200 }
201 
203 {
204  VuoVideoPlayer* obj = (VuoVideoPlayer*)player;
205  if(obj == NULL) return false;
206  return obj->GetCurrentVideoFrame(videoFrame);
207 }
208 
209 VuoReal VuoVideo_validateTimestamp(VuoReal frameTime, VuoReal duration, VuoLoopType loop, int *outputDirection)
210 {
211  if (outputDirection)
212  {
213  if (loop == VuoLoopType_Mirror && ((int)floor(fabs(frameTime) / duration) % 2))
214  *outputDirection = -1;
215  else
216  *outputDirection = 1;
217  }
218 
219  bool reverse = frameTime < 0;
220  VuoReal timestamp = frameTime;
221 
222  if(loop != VuoLoopType_None && (frameTime < 0 || frameTime > duration))
223  {
224  timestamp = fabs(frameTime);
225  float mod = fmod(timestamp, duration);
226 
227  if(loop == VuoLoopType_Loop)
228  timestamp = reverse ? duration - mod : mod;
229  else if(loop == VuoLoopType_Mirror)
230  timestamp = ((int)floor(timestamp / duration) % 2) ? duration - mod : mod;
231  }
232 
233  return timestamp;
234 }