• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup AVPlayer
18  * @{
19  *
20  * @brief Provides APIs of Playback capability for Media Source.
21  *
22  * @Syscap SystemCapability.Multimedia.Media.AVPlayer
23  * @since 11
24  * @version 1.0
25  */
26 
27 /**
28  * @file avplayer_base.h
29  *
30  * @brief Defines the structure and enumeration for Media AVPlayer.
31  *
32  * @kit MediaKit
33  * @library libavplayer.so
34  * @since 11
35  * @version 1.0
36  */
37 
38 #ifndef MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
39 #define MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
40 
41 #include <stdint.h>
42 
43 #include "native_avformat.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 typedef struct OH_AVPlayer OH_AVPlayer;
50 typedef struct NativeWindow OHNativeWindow;
51 
52 /**
53  * @brief Player States
54  * @syscap SystemCapability.Multimedia.Media.AVPlayer
55  * @since 11
56  * @version 1.0
57  */
58 typedef enum AVPlayerState {
59     /* idle states */
60     AV_IDLE = 0,
61     /* initialized states */
62     AV_INITIALIZED = 1,
63     /* prepared states */
64     AV_PREPARED = 2,
65     /* playing states */
66     AV_PLAYING = 3,
67     /* paused states */
68     AV_PAUSED = 4,
69     /* stopped states */
70     AV_STOPPED = 5,
71     /* Play to the end states */
72     AV_COMPLETED = 6,
73     /* released states */
74     AV_RELEASED = 7,
75     /* error states */
76     AV_ERROR = 8,
77 } AVPlayerState;
78 
79 /**
80  * @brief Player Seek Mode
81  * @syscap SystemCapability.Multimedia.Media.AVPlayer
82  * @since 11
83  * @version 1.0
84  */
85 typedef enum AVPlayerSeekMode {
86     /* sync to keyframes after the time point. */
87     AV_SEEK_NEXT_SYNC = 0,
88     /* sync to keyframes before the time point. */
89     AV_SEEK_PREVIOUS_SYNC,
90     /**
91      * @brief Sync to frames closest to the time point.
92      * @syscap SystemCapability.Multimedia.Media.AVPlayer
93      * @since 12
94      */
95     AV_SEEK_CLOSEST = 2,
96 } AVPlayerSeekMode;
97 
98 /**
99  * @brief Player Switch Mode
100  * @syscap SystemCapability.Multimedia.Media.AVPlayer
101  * @since 12
102  * @version 1.0
103  */
104 typedef enum AVPlayerSwitchMode {
105     /* sync to keyframes after the time point. */
106     AV_SWITCH_SOOMTH = 0,
107     /* sync to keyframes before the time point. */
108     AV_SWITCH_SEGMENT,
109     /**
110      * @brief sync to the closest frame of the given timestamp.
111      * @since 12
112      */
113     AV_SWITCH_CLOSEST = 2,
114 } AVPlayerSwitchMode;
115 
116 /**
117  * @brief Playback Speed
118  * @syscap SystemCapability.Multimedia.Media.AVPlayer
119  * @since 11
120  * @version 1.0
121  */
122 typedef enum AVPlaybackSpeed {
123     /* Video playback at 0.75x normal speed */
124     AV_SPEED_FORWARD_0_75_X,
125     /* Video playback at normal speed */
126     AV_SPEED_FORWARD_1_00_X,
127     /* Video playback at 1.25x normal speed */
128     AV_SPEED_FORWARD_1_25_X,
129     /* Video playback at 1.75x normal speed */
130     AV_SPEED_FORWARD_1_75_X,
131     /* Video playback at 2.0x normal speed */
132     AV_SPEED_FORWARD_2_00_X,
133     /**
134      * @brief Video playback at 0.5x normal speed.
135      * @syscap SystemCapability.Multimedia.Media.AVPlayer
136      * @since 12
137      */
138     AV_SPEED_FORWARD_0_50_X,
139     /**
140      * @brief Video playback at 1.5x normal speed.
141      * @syscap SystemCapability.Multimedia.Media.AVPlayer
142      * @since 12
143      */
144     AV_SPEED_FORWARD_1_50_X,
145     /**
146      * @brief Video playback at 3.0x normal speed.
147      * @syscap SystemCapability.Multimedia.Media.AVPlayer
148      * @since 13
149     */
150     AV_SPEED_FORWARD_3_00_X,
151     /**
152      * @brief Video playback at 0.25x normal speed.
153      * @syscap SystemCapability.Multimedia.Media.AVPlayer
154      * @since 13
155     */
156     AV_SPEED_FORWARD_0_25_X,
157     /**
158      * @brief Video playback at 0.125x normal speed.
159      * @syscap SystemCapability.Multimedia.Media.AVPlayer
160      * @since 13
161     */
162     AV_SPEED_FORWARD_0_125_X,
163 } AVPlaybackSpeed;
164 
165 /**
166  * @brief Player OnInfo Type
167  * @syscap SystemCapability.Multimedia.Media.AVPlayer
168  * @since 11
169  * @version 1.0
170  */
171 typedef enum AVPlayerOnInfoType {
172     /* return the message when seeking done. */
173     AV_INFO_TYPE_SEEKDONE = 0,
174     /* return the message when speeding done. */
175     AV_INFO_TYPE_SPEEDDONE = 1,
176     /* return the message when select bitrate done */
177     AV_INFO_TYPE_BITRATEDONE = 2,
178     /* return the message when playback is end of steam. */
179     AV_INFO_TYPE_EOS = 3,
180     /* return the message when PlayerStates changed. */
181     AV_INFO_TYPE_STATE_CHANGE = 4,
182     /* return the current posion of playback automatically. */
183     AV_INFO_TYPE_POSITION_UPDATE = 5,
184     /* return the playback message. */
185     AV_INFO_TYPE_MESSAGE = 6,
186     /* return the message when volume changed. */
187     AV_INFO_TYPE_VOLUME_CHANGE = 7,
188     /* return the message when video size is first known or updated. */
189     AV_INFO_TYPE_RESOLUTION_CHANGE = 8,
190     /* return multiqueue buffering time. */
191     AV_INFO_TYPE_BUFFERING_UPDATE = 9,
192     /* return hls bitrate.
193        Bitrate is to convert data into uint8_t array storage,
194        which needs to be forcibly converted to uint32_t through offset access. */
195     AV_INFO_TYPE_BITRATE_COLLECT = 10,
196     /* return the message when audio focus changed. */
197     AV_INFO_TYPE_INTERRUPT_EVENT = 11,
198     /* return the duration of playback. */
199     AV_INFO_TYPE_DURATION_UPDATE = 12,
200     /* return the playback is live stream. */
201     AV_INFO_TYPE_IS_LIVE_STREAM = 13,
202     /* return the message when track changes. */
203     AV_INFO_TYPE_TRACKCHANGE = 14,
204     /* return the message when subtitle track info updated. */
205     AV_INFO_TYPE_TRACK_INFO_UPDATE = 15,
206     /* return the subtitle of playback. */
207     AV_INFO_TYPE_SUBTITLE_UPDATE = 16,
208     /** Return the reason when the audio output device changes. When this info is reported, the extra param of
209      * {@link OH_AVPlayerOnInfo} is the same as {@OH_AudioStream_DeviceChangeReason} in audio framework.
210      */
211     AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE = 17,
212 } AVPlayerOnInfoType;
213 
214 /**
215  * @brief Player Buffering Type
216  * @syscap SystemCapability.Multimedia.Media.AVPlayer
217  * @since 12
218  * @version 1.0
219  */
220 typedef enum AVPlayerBufferingType {
221     /** Indicates the buffer to start buffering. */
222     AVPLAYER_BUFFERING_START = 1,
223 
224     /** Indicates the buffer to end buffering and start playback. */
225     AVPLAYER_BUFFERING_END,
226 
227     /** Indicates the current buffering percentage of the buffer. */
228     AVPLAYER_BUFFERING_PERCENT,
229 
230     /** Indicates how long the buffer cache data can be played. */
231     AVPLAYER_BUFFERING_CACHED_DURATION,
232 } AVPlayerBufferingType;
233 
234 /**
235  * @brief Key to get state, value type is int32_t.
236  * @syscap SystemCapability.Multimedia.Media.AVPlayer
237  * @since 12
238  * @version 1.0
239  */
240 extern const char* OH_PLAYER_STATE;
241 
242 /**
243  * @brief Key to get state change reason, value type is int32_t.
244  * @syscap SystemCapability.Multimedia.Media.AVPlayer
245  * @since 12
246  * @version 1.0
247  */
248 extern const char* OH_PLAYER_STATE_CHANGE_REASON;
249 
250 /**
251  * @brief Key to get volume, value type is float.
252  * @syscap SystemCapability.Multimedia.Media.AVPlayer
253  * @since 12
254  * @version 1.0
255  */
256 extern const char* OH_PLAYER_VOLUME;
257 
258 /**
259  * @brief Key to get bitrate count, value type is uint32_t array.
260  * @syscap SystemCapability.Multimedia.Media.AVPlayer
261  * @since 12
262  * @version 1.0
263  */
264 extern const char* OH_PLAYER_BITRATE_ARRAY;
265 
266 /**
267  * @brief Key to get audio interrupt type, value type is int32_t.
268  * @syscap SystemCapability.Multimedia.Media.AVPlayer
269  * @since 12
270  * @version 1.0
271  */
272 extern const char* OH_PLAYER_AUDIO_INTERRUPT_TYPE;
273 
274 /**
275  * @brief Key to get audio interrupt force, value type is int32_t.
276  * @syscap SystemCapability.Multimedia.Media.AVPlayer
277  * @since 12
278  * @version 1.0
279  */
280 extern const char* OH_PLAYER_AUDIO_INTERRUPT_FORCE;
281 
282 /**
283  * @brief Key to get audio interrupt hint, value type is int32_t.
284  * @syscap SystemCapability.Multimedia.Media.AVPlayer
285  * @since 12
286  * @version 1.0
287  */
288 extern const char* OH_PLAYER_AUDIO_INTERRUPT_HINT;
289 
290 /**
291  * @brief Key to get audio device change reason, value type is int32_t.
292  * @syscap SystemCapability.Multimedia.Media.AVPlayer
293  * @since 12
294  * @version 1.0
295  */
296 extern const char* OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON;
297 
298 /**
299  * @brief Key to get buffering type, value type is AVPlayerBufferingType.
300  * @syscap SystemCapability.Multimedia.Media.AVPlayer
301  * @since 12
302  * @version 1.0
303  */
304 extern const char* OH_PLAYER_BUFFERING_TYPE;
305 
306 /**
307  * @brief Key to get buffering value, value type is int32_t.
308  * @syscap SystemCapability.Multimedia.Media.AVPlayer
309  * @since 12
310  * @version 1.0
311  */
312 extern const char* OH_PLAYER_BUFFERING_VALUE;
313 
314 /**
315  * @brief Key to get seek position, value type is int32_t.
316  * @syscap SystemCapability.Multimedia.Media.AVPlayer
317  * @since 12
318  */
319 extern const char* OH_PLAYER_SEEK_POSITION;
320 
321 /**
322  * @brief Key to get playback speed, value type is AVPlaybackSpeed.
323  * @syscap SystemCapability.Multimedia.Media.AVPlayer
324  * @since 12
325  */
326 extern const char* OH_PLAYER_PLAYBACK_SPEED;
327 
328 /**
329  * @brief Key to get bitrate, value type is uint32_t.
330  * @syscap SystemCapability.Multimedia.Media.AVPlayer
331  * @since 12
332  */
333 extern const char* OH_PLAYER_BITRATE;
334 
335 /**
336  * @brief Key to get current position, value type is int32_t.
337  * @syscap SystemCapability.Multimedia.Media.AVPlayer
338  * @since 12
339  */
340 extern const char* OH_PLAYER_CURRENT_POSITION;
341 
342 /**
343  * @brief Key to get duration, value type is int64_t.
344  * @syscap SystemCapability.Multimedia.Media.AVPlayer
345  * @since 12
346  */
347 extern const char* OH_PLAYER_DURATION;
348 
349 /**
350  * @brief Key to get video width, value type is int32_t.
351  * @syscap SystemCapability.Multimedia.Media.AVPlayer
352  * @since 12
353  */
354 extern const char* OH_PLAYER_VIDEO_WIDTH;
355 
356 /**
357  * @brief Key to get video height, value type is int32_t.
358  * @syscap SystemCapability.Multimedia.Media.AVPlayer
359  * @since 12
360  */
361 extern const char* OH_PLAYER_VIDEO_HEIGHT;
362 
363 /**
364  * @brief Key to get message type, value type is int32_t.
365  * @syscap SystemCapability.Multimedia.Media.AVPlayer
366  * @since 12
367  */
368 extern const char* OH_PLAYER_MESSAGE_TYPE;
369 
370 /**
371  * @brief Key to get is live stream, value type is int32_t.
372  * @syscap SystemCapability.Multimedia.Media.AVPlayer
373  * @since 12
374  */
375 extern const char* OH_PLAYER_IS_LIVE_STREAM;
376 
377 /**
378  * @brief Called when a player message or alarm is received.
379  * @syscap SystemCapability.Multimedia.Media.AVPlayer
380  * @param player The pointer to an OH_AVPlayer instance.
381  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
382  * @param extra Indicates other information, for example, the start time position of a playing file.
383  * @since 11
384  * @deprecated since 12
385  * @useinstead {@link OH_AVPlayerOnInfoCallback}
386  * @version 1.0
387  */
388 typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra);
389 
390 /**
391  * @brief Called when a player info event is received.
392  * @syscap SystemCapability.Multimedia.Media.AVPlayer
393  * @param player The pointer to an OH_AVPlayer instance.
394  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
395  * @param infoBody Indicates the information parameters, only valid in callback function.
396  * @param userData Pointer to user specific data.
397  * @since 12
398  */
399 typedef void (*OH_AVPlayerOnInfoCallback)(OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat* infoBody,
400     void *userData);
401 
402 /**
403  * @brief Called when an error occurred for versions above api9
404  * @syscap SystemCapability.Multimedia.Media.AVPlayer
405  * @param player The pointer to an OH_AVPlayer instance.
406  * @param errorCode Error code.
407  * @param errorMsg Error message.
408  * @since 11
409  * @deprecated since 12
410  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnError}
411  * @version 1.0
412  */
413 typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg);
414 
415 /**
416  * @brief Called when an error occurred.
417  * @syscap SystemCapability.Multimedia.Media.AVPlayer
418  * @param player The pointer to an OH_AVPlayer instance.
419  * @param errorCode Error code.
420  * @param errorMsg Error message, only valid in callback function.
421  * @param userData Pointer to user specific data.
422  * @since 12
423  */
424 typedef void (*OH_AVPlayerOnErrorCallback)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg,
425     void *userData);
426 
427 /**
428  * @brief A collection of all callback function pointers in OH_AVPlayer. Register an instance of this
429  * structure to the OH_AVPlayer instance, and process the information reported through the callback to ensure the
430  * normal operation of OH_AVPlayer.
431  * @syscap SystemCapability.Multimedia.Media.AVPlayer
432  * @param onInfo Monitor OH_AVPlayer operation information, refer to {@link OH_AVPlayerOnInfo}
433  * @param onError Monitor OH_AVPlayer operation errors, refer to {@link OH_AVPlayerOnError}
434  * @since 11
435  * @deprecated since 12
436  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnErrorCallback}
437  * @version 1.0
438  */
439 typedef struct AVPlayerCallback {
440     OH_AVPlayerOnInfo onInfo = nullptr;
441     OH_AVPlayerOnError onError = nullptr;
442 } AVPlayerCallback;
443 
444 #ifdef __cplusplus
445 }
446 #endif
447 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
448