Vuo  2.3.2
VuoAvDecoder.cc
Go to the documentation of this file.
1 
10 #include "VuoAvDecoder.h"
11 
12 extern "C"
13 {
14 #ifdef VUO_COMPILER
16  "title" : "VuoAvDecoder",
17  "dependencies" : [
18  "VuoAvPlayerInterface",
19  "VuoAvPlayerObject",
20  "VuoImage",
21  "VuoAudioFrame",
22  "VuoAudioSamples",
23  "VuoReal",
24  "VuoList_VuoAudioSamples"
25  ]
26  });
27 #endif
28 }
29 
33 void OnDecoderPlaybackReady(void* id, bool canPlayMedia)
34 {
35  VuoAvDecoder* decoder = (VuoAvDecoder*) id;
36 
37  if(decoder != NULL)
38  decoder->DecoderReady(canPlayMedia);
39 }
40 
41 void VuoAvDecoder::DecoderReady(bool canPlayMedia)
42 {
43  if(videoPlayer != NULL && onReadyToPlay != NULL)
44  {
45  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void)
46  {
47  (videoPlayer->*onReadyToPlay)(canPlayMedia);
48  });
49  }
50 }
51 
53 {
54  VuoAvDecoder* decoder = new VuoAvDecoder();
55 
56  dispatch_sync(decoder->queue, ^
57  {
58  decoder->player = VuoAvPlayer_make(url);
59 
60  if(decoder->player != NULL)
61  {
62  VuoAvPlayer_setOnPlaybackReadyCallbackObject(decoder->player, OnDecoderPlaybackReady, decoder);
63  }
64  });
65 
66  if(!decoder->player)
67  {
68  delete decoder;
69  decoder = NULL;
70  }
71 
72  return decoder;
73 }
74 
76 {
77  videoPlayer = NULL;
78  onReadyToPlay = NULL;
79 
80  if(player != NULL)
81  {
82  dispatch_sync(queue, ^
83  {
85  VuoAvPlayer_release(player);
86  });
87  }
88 
89  dispatch_release(queue);
90 }
91 
93 {
94  __block bool isReady = false;
95  dispatch_sync(queue, ^{
96  isReady = VuoAvPlayer_isReady(player);
97  });
98  return isReady;
99 }
100 
102 {
103  __block bool canPlayAudio = false;
104  dispatch_sync(queue, ^{
105  canPlayAudio = VuoAvPlayer_canPlayAudio(player);
106  });
107  return canPlayAudio;
108 }
109 
111 {
112  __block unsigned int count = 0;
113  dispatch_sync(queue, ^{
114  count = VuoAvPlayer_audioChannelCount(player);
115  });
116  return count;
117 }
118 
120 {
121  __block bool success = false;
122  dispatch_sync(queue, ^{
123  success = VuoAvPlayer_nextVideoFrame(player, frame);
124  });
125  return success;
126 }
127 
129 {
130  __block bool success = false;
131  dispatch_sync(queue, ^{
132  success = VuoAvPlayer_nextAudioFrame(player, frame);
133  });
134  return success;
135 }
136 
137 bool VuoAvDecoder::SeekToSecond(double second, VuoVideoFrame *frame)
138 {
139  __block bool success = false;
140  dispatch_sync(queue, ^{
141  success = VuoAvPlayer_seekToSecond(player, second, frame);
142  });
143  return success;
144 }
145 
147 {
148  __block double duration = 0;
149  dispatch_sync(queue, ^{
150  duration = VuoAvPlayer_getDuration(player);
151  });
152  return duration;
153 }
154 
156 {
157  __block double fps = 0;
158  dispatch_sync(queue, ^{
159  fps = VuoAvPlayer_getFrameRate(player);
160  });
161  return fps;
162 }
163 
164 void VuoAvDecoder::SetPlaybackRate(double second)
165 {
166  dispatch_sync(queue, ^{
167  VuoAvPlayer_setPlaybackRate(player, second);
168  });
169 }
170 
172 {
173  __block double timestamp = 0;
174  dispatch_sync(queue, ^{
175  timestamp = VuoAvPlayer_getCurrentTimestamp(player);
176  });
177  return timestamp;
178 }