forked from alibaba/CicadaPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMediaPlayer.h
481 lines (348 loc) · 12.2 KB
/
MediaPlayer.h
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
//
// MediaPlayer.h
// apsara_player
//
// Created by shiping.csp on 2018/11/12.
//
#ifndef CicadaPlayer_h
#define CicadaPlayer_h
#include "MediaPlayerConfig.h"
#include "abr/AbrBufferRefererData.h"
#include "native_cicada_player_def.h"
#include <cstdio>
class AbrManager;
class AbrAlgoStrategy;
#include <cacheModule/CacheManager.h>
#include <drm/DrmHandler.h>
#include <mutex>
#include <render/video/IVideoRender.h>
#include <sstream>
#include <string>
#include <utils/AFMediaType.h>
#include <vector>
#ifdef ANDROID
namespace std {
template<typename T>
std::string to_string(T value)
{
std::ostringstream os;
os << value;
return os.str();
}
}// namespace std
#endif
namespace Cicada {
class AnalyticsQueryListener;
class IAnalyticsCollector;
class IAnalyticsCollectorFactory;
typedef void (*CicadaLogCallback)(void *userData, int prio, const char *buf);
class MediaPlayer {
public:
explicit MediaPlayer(const char *opt = nullptr);
explicit MediaPlayer(IAnalyticsCollectorFactory &factory, const char *opt = nullptr);
~MediaPlayer();
static string GetSdkVersion()
{
return "paas 0.9";//TODO version
}
std::string getName();
public:
void SetAnalyticsCollector(IAnalyticsCollector * collector);
void EnableVideoRenderedCallback(bool enable);
void SetOnRenderFrameCallback(onRenderFrame cb, void *userData);
void SetAudioRenderingCallback(onRenderFrame cb, void *userData);
void SetVideoRenderingCallback(videoRenderingFrameCB cb, void *userData);
void SetUpdateViewCallback(UpdateViewCB cb, void *userData);
void SetUrlHashCallback(UrlHashCB cb, void *userData);
void SetStreamTypeFlags(uint64_t flags);
void SetIPResolveType(IpResolveType type);
void SetFastStart(bool mode);
/*
* set player listener
*/
void SetListener(const playerListener &Listener);
/*
* enable hardware decoder or not
*/
void EnableHardwareDecoder(bool bEnabled);
/*
* set player view
*/
void SetView(void *view);
void ClearScreen();
/*
* set player url source
*/
void SetDataSource(const char *url);
/*
* when play url not equals SetDataSource , will callback.
*/
void SetDataSourceChangedCallback(function<void(const string &)> urlChangedCallbak);
void setDrmRequestCallback(const std::function<DrmResponseData*(const DrmRequestParam& drmRequestParam)> & drmCallback);
/*
*select specific track info
*/
void SelectTrack(int index);
/*
* prepare the url
*/
void Prepare();
/*
* start to play
*/
void Start();
/*
* Pause the player
*/
void Pause();
/*
* set the volume
*/
void SetVolume(float volume);
/**
* get current volume of the player
*/
float GetVolume();
/*
* seekt to new Postion by seekmode
*/
void SeekTo(int64_t seekPos, SeekMode mode);
/*
* capture screen, buffer will get by callback
*/
void CaptureScreen();
/*
* stop playing
*/
void Stop();
/*
* get the total duration of playing url
*/
int64_t GetDuration();
/*
* get master clock pts
*/
int64_t GetMasterClockPts();//TODO ??这是什么?
void SetClockRefer(clockRefer cb, void *arg);
/*
* get current stream index
*/
int GetCurrentStreamIndex(StreamType type);//TODO ??这是什么?
/*
* get current stream info
*/
StreamInfo *GetCurrentStreamInfo(StreamType type);
/*
* get the current playing position of the player
*/
int64_t GetCurrentPosition();
/*
* get the buffered postion of the player
*/
int64_t GetBufferedPosition();
/*
* enter background if back is true, or enter foreground
* this function is only used for ios?
*/
void EnterBackGround(bool back);
/*
* set the player mute
*/
void SetMute(bool bMute);
/**
* return ismuted or not
*/
bool IsMuted();
/**
* set player config
*/
void SetConfig(const MediaPlayerConfig *config);
/**
* get playerg config
*/
const MediaPlayerConfig *GetConfig();
/*
* set Scale Mode
*/
void SetScaleMode(ScaleMode mode);
/*
* Get Scale Mode
*/
ScaleMode GetScaleMode();
/*
* set loop
*/
void SetLoop(bool bLoop);
/*
* get loop or not
*/
bool IsLoop();
/*
* get video width of current playing
*/
int GetVideoWidth();
/*
* get video height of current playing
*/
int GetVideoHeight();
/*
* get video rotation angle from video metadata
*/
int GetVideoRotation();
/*
* set rotate mode, refer to RotateMode
*/
void SetRotateMode(RotateMode mode);
/*
* get rotate mode
*/
RotateMode GetRotateMode();
/*
* set mirror mode, refer to MirrorMode
*/
void SetMirrorMode(MirrorMode mode);
/*
* get mirror mode
*/
MirrorMode GetMirrorMode();
/*
* set clear color
*/
void SetVideoBackgroundColor(uint32_t color);
/*
* set speed of current playing, 0.5-2.0
*/
void SetSpeed(float speed);
/*
* get the speed of current playing
*/
float GetSpeed();
/*
* set traceID for debug log tracing
*/
void SetTraceID(const char *traceID);
/**
* set auto play
*/
void SetAutoPlay(bool bAutoPlay);
/**
* get is auto play or not
*/
bool IsAutoPlay();
void Reload();
/*
* set Component callback by type
*/
void SetComponentCb(player_component_type type, void *factory);
void setBitStreamCb(readCB read, seekCB seek, void *arg);
void SetMediaFrameCb(playerMediaFrameCb func, void *arg);
int GetCurrentStreamMeta(Stream_meta *meta, StreamType type);
void AddExtSubtitle(const char *uri);
void SelectExtSubtitle(int index, bool select);
int SetStreamDelayTime(int index, int64_t time);
void setErrorConverter(ErrorConverter *converter);
std::string GetPropertyString(PropertyKey key);
std::string GetPropertyString(PropertyKey key, const CicadaJSONItem ¶m);
void SetOption(const char *key, const char *value);
void GetOption(const char *key, char *value);
IAnalyticsCollector *GetAnalyticsCollector()
{
return mCollector;
}
//
// long ApsaraGetPropertyLong(playerHandle *player, int key);
// void SetMediaFrameCb(plyerMediaFrameCb func, void* arg);
/**
* set cache config.
* @param config
*/
void SetCacheConfig(const CacheConfig &config);
/**
* Set filter config. call this before prepare. If want update filter config, call updateFilterConfig()
* @param filterConfig
*/
void SetFilterConfig(const std::string &filterConfig);
/**
* upadate filter config.
* @param target Empty or not found, will make no effect. Should not be empty.
* @param options
*/
void UpdateFilterConfig(const std::string &target, const std::string &options);
/**
* disable/enable filter.
* @param target if empty , disable all filters.
* @param invalid true: enable(default); false: disable
*/
void SetFilterInvalid(const std::string &target, bool invalid);
/**
* get cache url. Should SetCacheConfig before call this.
* @param URL orignal url
* @return cached url.
*/
string GetCachePathByURL(const string &URL);
void SetDefaultBandWidth(int bandWidth);
int InvokeComponent(const char *content);
string GetPlayerSessionId();
bool IsEnableAbr();
private:
static void preparedCallback(void *userData);
static void completionCallback(void *userData);
static void firstFrameCallback(void *userData);
static void errorFrameCallback(int64_t errorCode, const void *errorMsg, void *userData);
static void eventCallback(int64_t code, const void *msg, void *userData);
static void videoSizeChangedCallback(int64_t width, int64_t height, void *userData);
static void videoRenderedCallback(int64_t timeMs, int64_t pts, void *userData);
static void audioRenderedCallback(int64_t timeMs, int64_t pts, void *userData);
static void currentPositionCallback(int64_t position, void *userData);
static void currentUtcTimeCallback(int64_t time, void *userData);
static void bufferPositionCallback(int64_t position, void *userData);
static void loopingStartCallback(void *userData);
static void loadingStartCallback(void *userData);
static void loadingEndCallback(void *userData);
static void loadingProgressCallback(int64_t prg, void *userData);
static void currentDownLoadSpeed(int64_t speed, void *userData);
static void subtitleShowCallback(int64_t index, int64_t size, const void *content, void *userData);
static void subtitleHideCallback(int64_t index, int64_t size, const void *content, void *userData);
static void subtitleExtAddedCallback(int64_t index, const void *url, void *userData);
static void subtitleHeaderCallback(int64_t index, const void *header, void *userData);
static void streamChangedSucCallback(int64_t type, const void *Info, void *userData);
static void PlayerSeeking(int64_t seekInCache, void *userData);
static void PlayerSeekEnd(int64_t seekInCache, void *userData);
static void PlayerStatusChanged(int64_t oldStatus, int64_t newStatus, void *userData);
static void mediaInfoGetCallback(int64_t count, const void *Infos, void *userData);
static void captureScreenResult(int64_t width, int64_t height, const void *buffer, void *userData);
static void autoPlayStart(void *userData);
void abrChanged(int stream);
static void onMediaFrameCallback(void *arg, const IAFPacket *frame, StreamType type);
void mediaFrameCallback(const IAFPacket *frame, StreamType type);
void configPlayer(const MediaPlayerConfig *config) const;
void refreshPlayerSessionId();
static void dummyFunction(bool dummy);
private:
void *mPlayerHandle = nullptr;
playerListener mListener{nullptr};
MediaPlayerConfig *mConfig{};
AnalyticsQueryListener *mQueryListener{};
IAnalyticsCollector *mCollector{nullptr};
bool bExternalCollector{false};
IAnalyticsCollectorFactory &mCollectorFactory;
AbrManager *mAbrManager{};
AbrAlgoStrategy *mAbrAlgo{};
AbrBufferRefererData *mAbrRefData{nullptr};
std::mutex mMutexAbr;
bool mLoop{false};
bool waitingForStart{false};
bool waitingForLoop{false};
string mPlayUrl;
CacheManager *mCacheManager{};
CacheConfig mCacheConfig{};
std::atomic<bool> mCacheSuccess{false};
PlayerStatus mOldPlayStatus{PLAYER_IDLE};
playerMediaFrameCb mMediaFrameFunc{nullptr};
void *mMediaFrameArg{nullptr};
function<void(const string &)> mPlayUrlChangedCallback{nullptr};
std::string mPlayerSessionId{};
bool mFirstPrepared{false};
};
}// namespace Cicada
#endif /* CicadaPlayer_h */