Vuo
2.1.1
node
vuo.video
VuoAvDecoder.cc
Go to the documentation of this file.
1
10
#include "
VuoAvDecoder.h
"
11
12
extern
"C"
13
{
14
#ifdef VUO_COMPILER
15
VuoModuleMetadata
({
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
52
VuoAvDecoder
*
VuoAvDecoder::Create
(
VuoUrl
url)
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
75
VuoAvDecoder::~VuoAvDecoder
()
76
{
77
videoPlayer
= NULL;
78
onReadyToPlay
= NULL;
79
80
if
(player != NULL)
81
{
82
dispatch_sync(
queue
, ^
83
{
84
VuoAvPlayer_setOnPlaybackReadyCallbackObject
(player, NULL, NULL);
85
VuoAvPlayer_release
(player);
86
});
87
}
88
89
dispatch_release(
queue
);
90
}
91
92
bool
VuoAvDecoder::IsReady
()
93
{
94
__block
bool
isReady =
false
;
95
dispatch_sync(
queue
, ^{
96
isReady =
VuoAvPlayer_isReady
(player);
97
});
98
return
isReady;
99
}
100
101
bool
VuoAvDecoder::CanPlayAudio
()
102
{
103
__block
bool
canPlayAudio =
false
;
104
dispatch_sync(
queue
, ^{
105
canPlayAudio =
VuoAvPlayer_canPlayAudio
(player);
106
});
107
return
canPlayAudio;
108
}
109
110
unsigned
int
VuoAvDecoder::GetAudioChannelCount
()
111
{
112
__block
unsigned
int
count = 0;
113
dispatch_sync(
queue
, ^{
114
count =
VuoAvPlayer_audioChannelCount
(player);
115
});
116
return
count;
117
}
118
119
bool
VuoAvDecoder::NextVideoFrame
(
VuoVideoFrame
* frame)
120
{
121
__block
bool
success =
false
;
122
dispatch_sync(
queue
, ^{
123
success =
VuoAvPlayer_nextVideoFrame
(player, frame);
124
});
125
return
success;
126
}
127
128
bool
VuoAvDecoder::NextAudioFrame
(
VuoAudioFrame
* frame)
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
146
double
VuoAvDecoder::GetDuration
()
147
{
148
__block
double
duration = 0;
149
dispatch_sync(
queue
, ^{
150
duration =
VuoAvPlayer_getDuration
(player);
151
});
152
return
duration;
153
}
154
155
double
VuoAvDecoder::GetFrameRate
()
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
171
double
VuoAvDecoder::GetLastDecodedVideoTimeStamp
()
172
{
173
__block
double
timestamp = 0;
174
dispatch_sync(
queue
, ^{
175
timestamp =
VuoAvPlayer_getCurrentTimestamp
(player);
176
});
177
return
timestamp;
178
}
Generated on Thu Jul 9 2020 21:02:24 for Vuo by
1.8.18