• 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     /* Event type indicating playback rate configuration completed. */
213     AV_INFO_TYPE_PLAYBACK_RATE_DONE = 18,
214 } AVPlayerOnInfoType;
215 
216 /**
217  * @brief Player Buffering Type
218  * @syscap SystemCapability.Multimedia.Media.AVPlayer
219  * @since 12
220  * @version 1.0
221  */
222 typedef enum AVPlayerBufferingType {
223     /** Indicates the buffer to start buffering. */
224     AVPLAYER_BUFFERING_START = 1,
225 
226     /** Indicates the buffer to end buffering and start playback. */
227     AVPLAYER_BUFFERING_END,
228 
229     /** Indicates the current buffering percentage of the buffer. */
230     AVPLAYER_BUFFERING_PERCENT,
231 
232     /** Indicates how long the buffer cache data can be played. */
233     AVPLAYER_BUFFERING_CACHED_DURATION,
234 } AVPlayerBufferingType;
235 
236 /**
237  * @brief Key to get state, value type is int32_t.
238  * @syscap SystemCapability.Multimedia.Media.AVPlayer
239  * @since 12
240  * @version 1.0
241  */
242 extern const char* OH_PLAYER_STATE;
243 
244 /**
245  * @brief Key to get state change reason, value type is int32_t.
246  * @syscap SystemCapability.Multimedia.Media.AVPlayer
247  * @since 12
248  * @version 1.0
249  */
250 extern const char* OH_PLAYER_STATE_CHANGE_REASON;
251 
252 /**
253  * @brief Key to get volume, value type is float.
254  * @syscap SystemCapability.Multimedia.Media.AVPlayer
255  * @since 12
256  * @version 1.0
257  */
258 extern const char* OH_PLAYER_VOLUME;
259 
260 /**
261  * @brief Key to get bitrate count, value type is uint32_t array.
262  * @syscap SystemCapability.Multimedia.Media.AVPlayer
263  * @since 12
264  * @version 1.0
265  */
266 extern const char* OH_PLAYER_BITRATE_ARRAY;
267 
268 /**
269  * @brief Key to get audio interrupt type, value type is int32_t.
270  * @syscap SystemCapability.Multimedia.Media.AVPlayer
271  * @since 12
272  * @version 1.0
273  */
274 extern const char* OH_PLAYER_AUDIO_INTERRUPT_TYPE;
275 
276 /**
277  * @brief Key to get audio interrupt force, value type is int32_t.
278  * @syscap SystemCapability.Multimedia.Media.AVPlayer
279  * @since 12
280  * @version 1.0
281  */
282 extern const char* OH_PLAYER_AUDIO_INTERRUPT_FORCE;
283 
284 /**
285  * @brief Key to get audio interrupt hint, value type is int32_t.
286  * @syscap SystemCapability.Multimedia.Media.AVPlayer
287  * @since 12
288  * @version 1.0
289  */
290 extern const char* OH_PLAYER_AUDIO_INTERRUPT_HINT;
291 
292 /**
293  * @brief Key to get audio device change reason, value type is int32_t.
294  * @syscap SystemCapability.Multimedia.Media.AVPlayer
295  * @since 12
296  * @version 1.0
297  */
298 extern const char* OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON;
299 
300 /**
301  * @brief Key to get buffering type, value type is AVPlayerBufferingType.
302  * @syscap SystemCapability.Multimedia.Media.AVPlayer
303  * @since 12
304  * @version 1.0
305  */
306 extern const char* OH_PLAYER_BUFFERING_TYPE;
307 
308 /**
309  * @brief Key to get buffering value, value type is int32_t.
310  * @syscap SystemCapability.Multimedia.Media.AVPlayer
311  * @since 12
312  * @version 1.0
313  */
314 extern const char* OH_PLAYER_BUFFERING_VALUE;
315 
316 /**
317  * @brief Key to get seek position, value type is int32_t.
318  * @syscap SystemCapability.Multimedia.Media.AVPlayer
319  * @since 12
320  */
321 extern const char* OH_PLAYER_SEEK_POSITION;
322 
323 /**
324  * @brief Key to get playback speed, value type is AVPlaybackSpeed.
325  * @syscap SystemCapability.Multimedia.Media.AVPlayer
326  * @since 12
327  */
328 extern const char* OH_PLAYER_PLAYBACK_SPEED;
329 
330 /**
331  * @brief Key to get bitrate, value type is uint32_t.
332  * @syscap SystemCapability.Multimedia.Media.AVPlayer
333  * @since 12
334  */
335 extern const char* OH_PLAYER_BITRATE;
336 
337 /**
338  * @brief Key to get current position, value type is int32_t.
339  * @syscap SystemCapability.Multimedia.Media.AVPlayer
340  * @since 12
341  */
342 extern const char* OH_PLAYER_CURRENT_POSITION;
343 
344 /**
345  * @brief Key to get duration, value type is int64_t.
346  * @syscap SystemCapability.Multimedia.Media.AVPlayer
347  * @since 12
348  */
349 extern const char* OH_PLAYER_DURATION;
350 
351 /**
352  * @brief Key to get video width, value type is int32_t.
353  * @syscap SystemCapability.Multimedia.Media.AVPlayer
354  * @since 12
355  */
356 extern const char* OH_PLAYER_VIDEO_WIDTH;
357 
358 /**
359  * @brief Key to get video height, value type is int32_t.
360  * @syscap SystemCapability.Multimedia.Media.AVPlayer
361  * @since 12
362  */
363 extern const char* OH_PLAYER_VIDEO_HEIGHT;
364 
365 /**
366  * @brief Key to get message type, value type is int32_t.
367  * @syscap SystemCapability.Multimedia.Media.AVPlayer
368  * @since 12
369  */
370 extern const char* OH_PLAYER_MESSAGE_TYPE;
371 
372 /**
373  * @brief Key to get is live stream, value type is int32_t.
374  * @syscap SystemCapability.Multimedia.Media.AVPlayer
375  * @since 12
376  */
377 extern const char* OH_PLAYER_IS_LIVE_STREAM;
378 
379 /**
380  * @brief Called when a player message or alarm is received.
381  * @syscap SystemCapability.Multimedia.Media.AVPlayer
382  * @param player The pointer to an OH_AVPlayer instance.
383  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
384  * @param extra Indicates other information, for example, the start time position of a playing file.
385  * @since 11
386  * @deprecated since 12
387  * @useinstead {@link OH_AVPlayerOnInfoCallback}
388  * @version 1.0
389  */
390 typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra);
391 
392 /**
393  * @brief Called when a player info event is received.
394  * @syscap SystemCapability.Multimedia.Media.AVPlayer
395  * @param player The pointer to an OH_AVPlayer instance.
396  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
397  * @param infoBody Indicates the information parameters, only valid in callback function.
398  * @param userData Pointer to user specific data.
399  * @since 12
400  */
401 typedef void (*OH_AVPlayerOnInfoCallback)(OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat* infoBody,
402     void *userData);
403 
404 /**
405  * @brief Called when an error occurred for versions above api9
406  * @syscap SystemCapability.Multimedia.Media.AVPlayer
407  * @param player The pointer to an OH_AVPlayer instance.
408  * @param errorCode Error code.
409  * @param errorMsg Error message.
410  * @since 11
411  * @deprecated since 12
412  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnError}
413  * @version 1.0
414  */
415 typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg);
416 
417 /**
418  * @brief Called when an error occurred.
419  * @syscap SystemCapability.Multimedia.Media.AVPlayer
420  * @param player The pointer to an OH_AVPlayer instance.
421  * @param errorCode Error code.
422  * @param errorMsg Error message, only valid in callback function.
423  * @param userData Pointer to user specific data.
424  * @since 12
425  */
426 typedef void (*OH_AVPlayerOnErrorCallback)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg,
427     void *userData);
428 
429 /**
430  * @brief A collection of all callback function pointers in OH_AVPlayer. Register an instance of this
431  * structure to the OH_AVPlayer instance, and process the information reported through the callback to ensure the
432  * normal operation of OH_AVPlayer.
433  * @syscap SystemCapability.Multimedia.Media.AVPlayer
434  * @param onInfo Monitor OH_AVPlayer operation information, refer to {@link OH_AVPlayerOnInfo}
435  * @param onError Monitor OH_AVPlayer operation errors, refer to {@link OH_AVPlayerOnError}
436  * @since 11
437  * @deprecated since 12
438  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnErrorCallback}
439  * @version 1.0
440  */
441 typedef struct AVPlayerCallback {
442     OH_AVPlayerOnInfo onInfo = nullptr;
443     OH_AVPlayerOnError onError = nullptr;
444 } AVPlayerCallback;
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
450