-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAgrippinaPlaybackGroup.cpp
398 lines (340 loc) · 12.9 KB
/
AgrippinaPlaybackGroup.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
* (c) 1997-2016 Netflix, Inc. All content herein is protected by
* U.S. copyright and other applicable intellectual property laws and
* may not be copied without the express permission of Netflix, Inc.,
* which reserves all rights. Reuse of any of this content for any
* purpose without the permission of Netflix, Inc. is strictly
* prohibited.
*/
#include "AgrippinaPlaybackGroup.h"
#include "ESPlayerConstants.h"
#include "AgrippinaESManager.h"
#include "AgrippinaAudioESPlayer.h"
#include "AgrippinaVideoESPlayer.h"
#include "AgrippinaDeviceLib.h"
#include <nrd/IPlaybackDevice.h>
#include <nrdbase/Log.h>
#include <nrdbase/ScopedMutex.h>
#include <nrdbase/MutexRanks.h>
#include <nrd/NrdApplication.h>
using namespace netflix;
using namespace netflix::device::esplayer;
using namespace netflix::device;
using namespace std;
static uint32_t videoPlayerCount = 0;
AgrippinaPlaybackGroup::AgrippinaPlaybackGroup(AgrippinaESManager& ESManager, uint32_t pipelineId) :
mPlaybackState(PAUSE),
mPlaybackStateMutex(ESP_PLAYBACKGROUP_MUTEX, "ESP Playback Group Mutex"),
mPlayersMutex(UNTRACKED_MUTEX, "ESP Players Mutex"),
mESManager(ESManager),
mPipelineId(pipelineId)
{
NeroSystemClock::init();
Nero_stc_type_t SyncMode = NERO_STC_VIDEO_MASTER;
m_stc = new NeroSTC(SyncMode);
m_NeroAudioDecoder = new NeroAudioDecoder();
m_NeroVideoDecoder = new NeroVideoDecoder();
m_stc->ConncectSources(m_NeroAudioDecoder, m_NeroVideoDecoder);
m_NeroVideoDecoder->SetupPlane();
}
AgrippinaPlaybackGroup::~AgrippinaPlaybackGroup()
{
ScopedMutex cs(mPlayersMutex);
// Delete any stream players that have not been deleted
NeroSystemClock::fini();
m_stc->DisconncectSources();
delete m_stc;
delete m_NeroAudioDecoder;
delete m_NeroVideoDecoder;
m_stc = NULL;
m_NeroAudioDecoder = NULL;
m_NeroVideoDecoder = NULL;
set<AgrippinaESPlayer*>::iterator it;
for (it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++) {
delete *it;
}
}
NFErr
AgrippinaPlaybackGroup::createStreamPlayer(const struct StreamPlayerInitData& initData,
std::shared_ptr<IESPlayerCallback> callback,
IElementaryStreamPlayer*& pStreamPlayer)
{
NFErr err;
ullong deviceSpecificErrorCode = 0;
std::string deviceSpecificErrorMsg;
std::string deviceStackTraceMsg;
AgrippinaESPlayer* player = NULL;
pStreamPlayer = NULL;
// Check initData pointers.
if(initData.mInitialStreamAttributes == NULL) {
assert(initData.mInitialStreamAttributes != NULL);
//this should be replaced by partner specific error code
deviceSpecificErrorCode = AgrippinaAppDeviceSpecific_NoInitialStreamAttributes;
Variant errInfo;
errInfo["errorDescription"] = "initial stream attributes NULL";
return err.push(new IDeviceError(INITIALIZATION_ERROR,
deviceSpecificErrorCode,
errInfo));
}
MediaType streamType = initData.mInitialStreamAttributes->mStreamType;
// Initialize the audio player if this is an audio stream.
if(streamType == AUDIO)
{
// Check audio attributes pointer
assert(initData.mInitialStreamAttributes->mAudioAttributes != NULL);
if(initData.mInitialStreamAttributes->mAudioAttributes == NULL)
{
// this should be replaced by partner specific error code
deviceSpecificErrorCode = AgrippinaAppDeviceSpecific_NoInitialAudioStreamAttributes;
deviceSpecificErrorMsg = "no initialStreamAttributes for Audio";
Variant errInfo;
errInfo["errorDescription"] = "no initialStreamAttributes for Audio";
return err.push(new IDeviceError(INITIALIZATION_ERROR,
deviceSpecificErrorCode,
errInfo));
}
player = new AgrippinaAudioESPlayer(m_NeroAudioDecoder,m_stc);
} else {
// Initialize a video player
// Check video attributes pointer.
assert(initData.mInitialStreamAttributes->mVideoAttributes != NULL);
if(initData.mInitialStreamAttributes->mVideoAttributes == NULL)
{
// this should be replaced by partner specific error code
deviceSpecificErrorCode = AgrippinaAppDeviceSpecific_NoInitialVideoStreamAttributes;
Variant errInfo;
errInfo["errorDescription"] = "no initialStreamAttributes for Video";
return err.push(new IDeviceError(INITIALIZATION_ERROR,
deviceSpecificErrorCode,
errInfo));
}
// If a device requires MVC delivered with the base and depenent view
// NALUs in separate buffers, USE_MVC_SPLIT should be defined. See
// IElementaryStreamPlayer.h for details about MVC_SPLIT and
// MVC_COMBINED mode.
// #define USE_MVC_SPLIT
#ifdef USE_MVC_SPLIT
if(initData.mInitialStreamAttributes->mVideoAttributes->mFormat3D == MVC_COMBINED)
{
// this should be replaced by partner specific error code
deviceSpecificErrorCode = skeletonDeviceSpecific_Wrong3DMode;
Variant errInfo;
errInfo["errorDescription"] = "wrong 3D stream architecture";
return err.push(new IDeviceError(SPLIT_MVC_REQUIRED,
deviceSpecificErrorCode,
errInfo));
}
#endif
if (streamType == VIDEO) {
uint32_t maxVideoPipelines = 1;
ScopedMutex cs(mPlayersMutex);
if (videoPlayerCount < maxVideoPipelines) {
++videoPlayerCount;
} else {
NTRACE(TRACE_MEDIAPLAYBACK, "Cannot create more than %d video players at a time", maxVideoPipelines);
deviceSpecificErrorCode = AgrippinaAppDeviceSpecific_VideoResourceError;
Variant errInfo;
errInfo["errorDescription"] = "platform does not have enough resource";
return err.push(new IDeviceError(INITIALIZATION_ERROR,
deviceSpecificErrorCode,
errInfo));
}
}
player = new AgrippinaVideoESPlayer(m_NeroVideoDecoder,m_stc);
}
if(player == NULL)
{
if(streamType == AUDIO){
deviceSpecificErrorCode = AgrippinaAppDeviceSpecific_AudioPlayerCreationFailed;
} else {
deviceSpecificErrorCode = AgrippinaAppDeviceSpecific_VideoPlayerCreationFailed;
}
Variant errInfo;
errInfo["errorDescription"] = "failed to create player";
return err.push(new IDeviceError(INITIALIZATION_ERROR,
deviceSpecificErrorCode,
errInfo));
}
err = player->init(initData, callback, this);
if(!err.ok()){
delete player;
return err;
}
NTRACE(TRACE_MEDIAPLAYBACK, "AgrippinaPlaybackGroup::createStreamPlayer: %s player initialized",
streamType == AUDIO ? "audio" : "video");
pStreamPlayer = player;
ScopedMutex cs(mPlayersMutex);
mStreamPlayers.insert(player);
return err;
}
void AgrippinaPlaybackGroup::destroyStreamPlayer(IElementaryStreamPlayer* iesPlayer)
{
AgrippinaESPlayer* streamPlayer = static_cast<AgrippinaESPlayer*>(iesPlayer);
ScopedMutex cs(mPlayersMutex);
assert(mStreamPlayers.find(streamPlayer) != mStreamPlayers.end());
if (mStreamPlayers.find(streamPlayer) != mStreamPlayers.end()) {
if(streamPlayer->getMediaType() == VIDEO) {
--videoPlayerCount;
}
mStreamPlayers.erase(streamPlayer);
delete streamPlayer;
}
}
bool AgrippinaPlaybackGroup::streamPlayersAreReadyForPlaybackStart()
{
set<AgrippinaESPlayer*>::iterator it;
for(it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++)
{
if(!(*it)->readyForPlaybackStart())
{
return false;
}
}
return true;
}
bool AgrippinaPlaybackGroup::setPlaybackState(PlaybackState state)
{
NTRACE(TRACE_MEDIAPLAYBACK, "AgrippinaPlaybackGroup::setPlaybackState(): "
"state = %s\n", state == PLAY ? "PLAY":"PAUSE");
Nero_error_t result = NERO_SUCCESS;
if(state == PAUSE)
{
/* Pause Nero Video Decoder first */
result = m_NeroVideoDecoder->Pause();
if (NERO_SUCCESS != result){
// Players are not ready to transition from play to pause. Return
// false. The SDK will wait a few ms and try again.
return false;
}
/* Pause Nero Audio Decoder sed */
// Partners should pause the pipeline
result = m_NeroAudioDecoder->Pause();
if (NERO_SUCCESS != result){
// Players are not ready to transition from play to pause. Return
// false. The SDK will wait a few ms and try again.
return false;
}
}
else if(state == PLAY)
{
if(!streamPlayersAreReadyForPlaybackStart() )
{
// Players are not ready to transition from paused to play. Return
// false. The SDK will wait a few ms and try again.
return false;
}
// Partners should play the pipeline
result = m_NeroVideoDecoder->Play();
if (NERO_SUCCESS != result){
// Players are not ready to transition from play to pause. Return
// false. The SDK will wait a few ms and try again.
return false;
}
result = m_NeroAudioDecoder->Play();
if (NERO_SUCCESS != result){
// Players are not ready to transition from play to pause. Return
// false. The SDK will wait a few ms and try again.
return false;
}
}
else {
// We only support PAUSE and PLAY. If a new state is added make sure handling gets implemented here!
assert(0);
}
{
ScopedMutex cs(mPlaybackStateMutex);
mPlaybackState = state;
}
return true;
}
IPlaybackGroup::PlaybackState AgrippinaPlaybackGroup::getPlaybackState()
{
ScopedMutex cs(mPlaybackStateMutex);
return mPlaybackState;
}
void AgrippinaPlaybackGroup::flush()
{
set<AgrippinaESPlayer*>::iterator it;
NTRACE(TRACE_MEDIAPLAYBACK, "AgrippinaPlaybackGroup::flush() begin");
// Partners should pause the pipeline
for(it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++)
{
(*it)->beginFlush();
}
// Partners should invalidate the presentation time (if needed)
for(it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++)
{
(*it)->endFlush();
}
NTRACE(TRACE_MEDIAPLAYBACK, "AgrippinaPlaybackGroup::flush() end");
}
void AgrippinaPlaybackGroup::audioFlushed()
{
// Partners should invalidate the presentation time (if needed)
}
void AgrippinaPlaybackGroup::setVideoPlaneProperties(VideoPlaneProperties p)
{
ScopedMutex cs(mPlayersMutex);
set<AgrippinaESPlayer*>::iterator it;
for (it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++) {
if ((*it)->getMediaType() == VIDEO) {
(*it)->setVideoPlaneProperties(p);
return;
}
}
}
VideoPlaneProperties AgrippinaPlaybackGroup::getVideoPlaneProperties()
{
ScopedMutex cs(mPlayersMutex);
set<AgrippinaESPlayer*>::iterator it;
for (it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++) {
if ((*it)->getMediaType() == VIDEO) {
return (*it)->getVideoPlaneProperties();
}
}
VideoPlaneProperties p = VideoPlaneProperties();
p.zorder = UINT_MAX;
return p;
}
VideoPlaneProperties AgrippinaPlaybackGroup::getPendingVideoPlaneProperties()
{
ScopedMutex cs(mPlayersMutex);
set<AgrippinaESPlayer*>::iterator it;
for (it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++) {
if ((*it)->getMediaType() == VIDEO) {
return (*it)->getPendingVideoPlaneProperties();
}
}
VideoPlaneProperties p = VideoPlaneProperties();
p.zorder = UINT_MAX;
return p;
}
void AgrippinaPlaybackGroup::commitVideoPlaneProperties()
{
ScopedMutex cs(mPlayersMutex);
set<AgrippinaESPlayer*>::iterator it;
for (it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++) {
if ((*it)->getMediaType() == VIDEO) {
(*it)->commitVideoPlaneProperties();
}
}
}
bool AgrippinaPlaybackGroup::getRenderMode()
{
ScopedMutex cs(mPlayersMutex);
set<AgrippinaESPlayer*>::iterator it;
for (it = mStreamPlayers.begin(); it != mStreamPlayers.end(); it++) {
if ((*it)->getMediaType() == VIDEO) {
return (*it)->getRenderMode();
}
}
return false;
}
AgrippinaESManager* AgrippinaPlaybackGroup::getESManager()
{
return &mESManager;
}
uint32_t AgrippinaPlaybackGroup::getPipelineId() const
{
return mPipelineId;
}