智慧保安互联网APP
zengh
2022-06-21 4efeb31d5b4921d7e851c256009486ad86bc70e2
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
//
//  anyrtc Rtc Engine SDK
//
//  Copyright (c) 2019 anyrtc.io. All rights reserved.
//
 
#ifndef __I_AR_MEDIA_PLAYER_H__
#define __I_AR_MEDIA_PLAYER_H__
 
#include "ArMediaBase.h"
 
#ifndef AR
#define AR ar::rtc
#endif
 
// external key
/**
 * set analyze duration for real time stream
 * @example "setPlayerOption(KEY_PLAYER_REAL_TIME_STREAM_ANALYZE_DURATION,1000000)"
 */
#define KEY_PLAYER_REAL_TIME_STREAM_ANALYZE_DURATION    "analyzeduration"
 
/**
 * set the player disable to play audio
 * @example  "setPlayerOption(KEY_PLAYER_DISABLE_AUDIO,0)"
 */
#define KEY_PLAYER_DISABLE_AUDIO                  "audio_disable"
 
/**
 * set the player disable to play video
 * @example  "setPlayerOption(KEY_PLAYER_DISABLE_VIDEO,0)"
 */
#define KEY_PLAYER_DISABLE_VIDEO                  "video_disable"
 
namespace ar {
namespace rtc {
 
/** Definition of MediaPlayerContext.
 */
struct MediaPlayerContext {
  /** User Context, i.e., activity context in Android.
   */
  void* context;
 
  MediaPlayerContext()
      : context(nullptr) {}
};
 
class IMediaPlayerObserver;
 
/**
 * @brief Player interface
 *
 */
class IMediaPlayer {
 public:
 
  virtual int initialize(const MediaPlayerContext& context) = 0;
 
  /**
   * @brief Open media file
   *
   * @param src Media path, local path or network path
   * @param startPos Set the starting position for playback, in seconds
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int open(const char* src, int64_t startPos) = 0;
 
  /**
   * @brief Play
   *
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int play() = 0;
 
  /**
   * @brief pause
   *
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int pause() = 0;
 
  /**
   * @brief stop
   *
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int stop() = 0;
 
  /**
   * @brief Play to a specified position
   *
   * @param pos The position to play, in seconds
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int seek(int64_t pos) = 0;
 
  /**
   * @brief Turn mute on or off
   *
   * @param mute Whether to mute on
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int mute(bool mute) = 0;
 
  /**
   * @brief Get mute state
   *
   * @param[out] mute Whether is mute on
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int getMute(bool& mute) = 0;
 
  /**
   * @brief Adjust playback volume
   *
   * @param volume The volume value to be adjusted
   * The volume can be adjusted from 0 to 400:
   * 0: mute;
   * 100: original volume;
   * 400: Up to 4 times the original volume (with built-in overflow protection).
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int adjustPlayoutVolume(int volume) = 0;
 
  /**
   * @brief Get the current playback volume
   *
   * @param[out] volume
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int getPlayoutVolume(int& volume) = 0;
 
  /**
   * @brief Get the current playback progress
   *
   * @param[out] pos Progress in seconds
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int getPlayPosition(int64_t& pos) = 0;
 
  /**
   * @brief Get the current playback progress
   *
   * @param[out] pos Progress in millisecond
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int getPlayPositionInMillisecond(int64_t& positionInMs) = 0;
 
  /**
   * @brief Get media duration
   *
   * @param[out] duration Duration in seconds
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int getDuration(int64_t& duration) = 0;
 
  /**
   * @brief Get player state
   *
   * @return PLAYER_STATE
   */
  virtual ar::media::MEDIA_PLAYER_STATE getState() = 0;
 
  /**
   * @brief Get the streams info count in the media
   *
   * @param[out] count
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int getStreamCount(int& count) = 0;
 
  /**
   * @brief Get the streams info by index
   *
   * @param[in] index, index
   * @param[out] info, stream info for return
   */
  virtual int getStreamInfo(int index, ar::media::MediaStreamInfo* info) = 0;
 
  /**
   * @brief Set video rendering view
   *
   * @param view view object, windows platform is HWND
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int setView(ar::media::base::view_t view) = 0;
 
  /**
   * @brief Set video display mode
   *
   * @param renderMode Video display mode
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int setRenderMode(ar::media::base::RENDER_MODE_TYPE renderMode) = 0;
 
  /**
   * @brief Register the player observer
   *
   * @param observer observer object
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int registerPlayerObserver(IMediaPlayerObserver* observer) = 0;
 
  /**
   * @brief Unregister the player observer
   *
   * @param observer observer object
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int unregisterPlayerObserver(IMediaPlayerObserver* observer) = 0;
 
  /**
   * @brief Register the player video observer
   *
   * @param observer observer object
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int registerVideoFrameObserver(ar::media::base::IVideoFrameObserver* observer) = 0;
 
  /**
   * @brief UnRegister the player video observer
   *
   * @param observer observer object
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int unregisterVideoFrameObserver(ar::media::base::IVideoFrameObserver* observer) = 0;
 
  /**
   * @brief register the player audio observer
   *
   * @param observer observer object
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int registerAudioFrameObserver(ar::media::base::IAudioFrameObserver* observer) = 0;
 
  /**
   * @brief Unregister the player audio observer
   *
   * @param observer observer object
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int unregisterAudioFrameObserver(ar::media::base::IAudioFrameObserver* observer) = 0;
 
  /**
   * @brief change log file position
   *
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int setLogFile(const char* filePath) = 0;
 
  /**
   * Sets the output log level of the SDK.
   *
   * You can use one or a combination of the filters. The log level follows the
   * sequence of `OFF`, `CRITICAL`, `ERROR`, `WARNING`, `INFO`, and `DEBUG`. Choose a level
   * and you will see logs preceding that level. For example, if you set the log level to
   * `WARNING`, you see the logs within levels `CRITICAL`, `ERROR`, and `WARNING`.
   *
   * @param filter Sets the log filter level:
   * - LOG_FILTER_DEBUG (0x80f): Output all API logs. Set your log filter as DEBUG
   * if you want to get the most complete log file.
   * - LOG_FILTER_INFO (0x0f): Output logs of the CRITICAL, ERROR, WARNING, and INFO
   * level. We recommend setting your log filter as this level.
   * - LOG_FILTER_WARNING (0x0e): Output logs of the CRITICAL, ERROR, and WARNING level.
   * - LOG_FILTER_ERROR (0x0c): Output logs of the CRITICAL and ERROR level.
   * - LOG_FILTER_CRITICAL (0x08): Output logs of the CRITICAL level.
   * - LOG_FILTER_OFF (0): Do not output any log.
   *
   * @return
   * - 0: Success.
   * - < 0: Failure.
   */
  virtual int setLogFilter(unsigned int filter) = 0;
 
   /**
   * @brief modify player option before play,
   * @param [in] key
   *        the option key name
   * @param [in] value
   *        the option value
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int setPlayerOption(const char *key ,int value) = 0;
 
  /**
   * @brief change playback speed
   *
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int changePlaybackSpeed(const ar::media::MEDIA_PLAYER_PLAY_SPEED speed) = 0;
 
  /**
   * @brief change audio track
   *
   * @return int <= 0 On behalf of an error, the value corresponds to one of PLAYER_ERROR
   */
  virtual int selectAudioTrack(int index) = 0;
 
  /**
   * @brief release IMediaPlayer object.
   *
   */
  virtual void release(bool sync = true) = 0;
 
  virtual ~IMediaPlayer() {}
};
 
class IMediaPlayerObserver {
 public:
  /**
   * @brief Triggered when the player state changes
   *
   * @param state New player state
   * @param ec Player error message
   */
  virtual void onPlayerStateChanged(ar::media::MEDIA_PLAYER_STATE state,
                                    ar::media::MEDIA_PLAYER_ERROR ec) = 0;
 
  /**
   * @brief Triggered when the player progress changes, once every 1 second
   *
   * @param position Current playback progress, in seconds
   */
  virtual void onPositionChanged(const int64_t position) = 0;
 
  /**
   * @brief Triggered when the player have some event
   *
   * @param event
   */
  virtual void onPlayerEvent(ar::media::MEDIA_PLAYER_EVENT event) = 0;
 
  /**
   * @brief Triggered when metadata is obtained
   *
   * @param type Metadata type
   * @param data data
   * @param length  data length
   */
  virtual void onMetadata(ar::media::MEDIA_PLAYER_METADATA_TYPE type, const uint8_t* data,
                                  uint32_t length) = 0;
 
  virtual ~IMediaPlayerObserver() {}
};
 
}  // namespace rtc
}  // namespace ar
 
 
#if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#define AR_PLAYER_API extern "C" __declspec(dllexport)
#define AR_PLAYER_CALL
#elif defined(__APPLE__)
#include <TargetConditionals.h>
#define AR_PLAYER_API __attribute__((visibility("default"))) extern "C"
#define AR_PLAYER_CALL
#elif defined(__ANDROID__) || defined(__linux__)
#define AR_PLAYER_API extern "C" __attribute__((visibility("default")))
#define AR_PLAYER_CALL
#else
#define AR_PLAYER_API extern "C"
#define AR_PLAYER_CALL
#endif
 
/**
 * Creates an anyrtc media player object and returns the pointer.
 * @return
 * - The pointer to \ref ar::rtc::IMediaPlayer "IMediaPlayer", if the method call succeeds.
 * - The empty pointer NULL, if the method call fails.
 */
AR_PLAYER_API ar::rtc::IMediaPlayer* AR_PLAYER_CALL createArMediaPlayer();
 
#endif  // __I_AR_MEDIA_PLAYER_H__