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 } AVPlaybackSpeed;
146 
147 /**
148  * @brief Player OnInfo Type
149  * @syscap SystemCapability.Multimedia.Media.AVPlayer
150  * @since 11
151  * @version 1.0
152  */
153 typedef enum AVPlayerOnInfoType {
154     /* return the message when seeking done. */
155     AV_INFO_TYPE_SEEKDONE = 0,
156     /* return the message when speeding done. */
157     AV_INFO_TYPE_SPEEDDONE = 1,
158     /* return the message when select bitrate done */
159     AV_INFO_TYPE_BITRATEDONE = 2,
160     /* return the message when playback is end of steam. */
161     AV_INFO_TYPE_EOS = 3,
162     /* return the message when PlayerStates changed. */
163     AV_INFO_TYPE_STATE_CHANGE = 4,
164     /* return the current posion of playback automatically. */
165     AV_INFO_TYPE_POSITION_UPDATE = 5,
166     /* return the playback message. */
167     AV_INFO_TYPE_MESSAGE = 6,
168     /* return the message when volume changed. */
169     AV_INFO_TYPE_VOLUME_CHANGE = 7,
170     /* return the message when video size is first known or updated. */
171     AV_INFO_TYPE_RESOLUTION_CHANGE = 8,
172     /* return multiqueue buffering time. */
173     AV_INFO_TYPE_BUFFERING_UPDATE = 9,
174     /* return hls bitrate.
175        Bitrate is to convert data into uint8_t array storage,
176        which needs to be forcibly converted to uint32_t through offset access. */
177     AV_INFO_TYPE_BITRATE_COLLECT = 10,
178     /* return the message when audio focus changed. */
179     AV_INFO_TYPE_INTERRUPT_EVENT = 11,
180     /* return the duration of playback. */
181     AV_INFO_TYPE_DURATION_UPDATE = 12,
182     /* return the playback is live stream. */
183     AV_INFO_TYPE_IS_LIVE_STREAM = 13,
184     /* return the message when track changes. */
185     AV_INFO_TYPE_TRACKCHANGE = 14,
186     /* return the message when subtitle track info updated. */
187     AV_INFO_TYPE_TRACK_INFO_UPDATE = 15,
188     /* return the subtitle of playback. */
189     AV_INFO_TYPE_SUBTITLE_UPDATE = 16,
190     /** Return the reason when the audio output device changes. When this info is reported, the extra param of
191      * {@link OH_AVPlayerOnInfo} is the same as {@OH_AudioStream_DeviceChangeReason} in audio framework.
192      */
193     AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE = 17,
194 } AVPlayerOnInfoType;
195 
196 /**
197  * @brief Player Buffering Type
198  * @syscap SystemCapability.Multimedia.Media.AVPlayer
199  * @since 12
200  * @version 1.0
201  */
202 typedef enum AVPlayerBufferingType {
203     /** Indicates the buffer to start buffering. */
204     AVPLAYER_BUFFERING_START = 1,
205 
206     /** Indicates the buffer to end buffering and start playback. */
207     AVPLAYER_BUFFERING_END,
208 
209     /** Indicates the current buffering percentage of the buffer. */
210     AVPLAYER_BUFFERING_PERCENT,
211 
212     /** Indicates how long the buffer cache data can be played. */
213     AVPLAYER_BUFFERING_CACHED_DURATION,
214 } AVPlayerBufferingType;
215 
216 /**
217  * @brief Key to get state, value type is int32_t.
218  * @syscap SystemCapability.Multimedia.Media.AVPlayer
219  * @since 12
220  * @version 1.0
221  */
222 extern const char* OH_PLAYER_STATE;
223 
224 /**
225  * @brief Key to get state change reason, value type is int32_t.
226  * @syscap SystemCapability.Multimedia.Media.AVPlayer
227  * @since 12
228  * @version 1.0
229  */
230 extern const char* OH_PLAYER_STATE_CHANGE_REASON;
231 
232 /**
233  * @brief Key to get volume, value type is float.
234  * @syscap SystemCapability.Multimedia.Media.AVPlayer
235  * @since 12
236  * @version 1.0
237  */
238 extern const char* OH_PLAYER_VOLUME;
239 
240 /**
241  * @brief Key to get bitrate count, value type is uint32_t array.
242  * @syscap SystemCapability.Multimedia.Media.AVPlayer
243  * @since 12
244  * @version 1.0
245  */
246 extern const char* OH_PLAYER_BITRATE_ARRAY;
247 
248 /**
249  * @brief Key to get audio interrupt type, value type is int32_t.
250  * @syscap SystemCapability.Multimedia.Media.AVPlayer
251  * @since 12
252  * @version 1.0
253  */
254 extern const char* OH_PLAYER_AUDIO_INTERRUPT_TYPE;
255 
256 /**
257  * @brief Key to get audio interrupt force, value type is int32_t.
258  * @syscap SystemCapability.Multimedia.Media.AVPlayer
259  * @since 12
260  * @version 1.0
261  */
262 extern const char* OH_PLAYER_AUDIO_INTERRUPT_FORCE;
263 
264 /**
265  * @brief Key to get audio interrupt hint, value type is int32_t.
266  * @syscap SystemCapability.Multimedia.Media.AVPlayer
267  * @since 12
268  * @version 1.0
269  */
270 extern const char* OH_PLAYER_AUDIO_INTERRUPT_HINT;
271 
272 /**
273  * @brief Key to get audio device change reason, value type is int32_t.
274  * @syscap SystemCapability.Multimedia.Media.AVPlayer
275  * @since 12
276  * @version 1.0
277  */
278 extern const char* OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON;
279 
280 /**
281  * @brief Key to get buffering type, value type is AVPlayerBufferingType.
282  * @syscap SystemCapability.Multimedia.Media.AVPlayer
283  * @since 12
284  * @version 1.0
285  */
286 extern const char* OH_PLAYER_BUFFERING_TYPE;
287 
288 /**
289  * @brief Key to get buffering value, value type is int32_t.
290  * @syscap SystemCapability.Multimedia.Media.AVPlayer
291  * @since 12
292  * @version 1.0
293  */
294 extern const char* OH_PLAYER_BUFFERING_VALUE;
295 
296 /**
297  * @brief Key to get seek position, value type is int32_t.
298  * @syscap SystemCapability.Multimedia.Media.AVPlayer
299  * @since 12
300  */
301 extern const char* OH_PLAYER_SEEK_POSITION;
302 
303 /**
304  * @brief Key to get playback speed, value type is AVPlaybackSpeed.
305  * @syscap SystemCapability.Multimedia.Media.AVPlayer
306  * @since 12
307  */
308 extern const char* OH_PLAYER_PLAYBACK_SPEED;
309 
310 /**
311  * @brief Key to get bitrate, value type is uint32_t.
312  * @syscap SystemCapability.Multimedia.Media.AVPlayer
313  * @since 12
314  */
315 extern const char* OH_PLAYER_BITRATE;
316 
317 /**
318  * @brief Key to get current position, value type is int32_t.
319  * @syscap SystemCapability.Multimedia.Media.AVPlayer
320  * @since 12
321  */
322 extern const char* OH_PLAYER_CURRENT_POSITION;
323 
324 /**
325  * @brief Key to get duration, value type is int64_t.
326  * @syscap SystemCapability.Multimedia.Media.AVPlayer
327  * @since 12
328  */
329 extern const char* OH_PLAYER_DURATION;
330 
331 /**
332  * @brief Key to get video width, value type is int32_t.
333  * @syscap SystemCapability.Multimedia.Media.AVPlayer
334  * @since 12
335  */
336 extern const char* OH_PLAYER_VIDEO_WIDTH;
337 
338 /**
339  * @brief Key to get video height, value type is int32_t.
340  * @syscap SystemCapability.Multimedia.Media.AVPlayer
341  * @since 12
342  */
343 extern const char* OH_PLAYER_VIDEO_HEIGHT;
344 
345 /**
346  * @brief Key to get message type, value type is int32_t.
347  * @syscap SystemCapability.Multimedia.Media.AVPlayer
348  * @since 12
349  */
350 extern const char* OH_PLAYER_MESSAGE_TYPE;
351 
352 /**
353  * @brief Key to get is live stream, value type is int32_t.
354  * @syscap SystemCapability.Multimedia.Media.AVPlayer
355  * @since 12
356  */
357 extern const char* OH_PLAYER_IS_LIVE_STREAM;
358 
359 /**
360  * @brief Called when a player message or alarm is received.
361  * @syscap SystemCapability.Multimedia.Media.AVPlayer
362  * @param player The pointer to an OH_AVPlayer instance.
363  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
364  * @param extra Indicates other information, for example, the start time position of a playing file.
365  * @since 11
366  * @deprecated since 12
367  * @useinstead {@link OH_AVPlayerOnInfoCallback}
368  * @version 1.0
369  */
370 typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra);
371 
372 /**
373  * @brief Called when a player info event is received.
374  * @syscap SystemCapability.Multimedia.Media.AVPlayer
375  * @param player The pointer to an OH_AVPlayer instance.
376  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
377  * @param infoBody Indicates the information parameters, only valid in callback function.
378  * @param userData Pointer to user specific data.
379  * @since 12
380  */
381 typedef void (*OH_AVPlayerOnInfoCallback)(OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat* infoBody,
382     void *userData);
383 
384 /**
385  * @brief Called when an error occurred for versions above api9
386  * @syscap SystemCapability.Multimedia.Media.AVPlayer
387  * @param player The pointer to an OH_AVPlayer instance.
388  * @param errorCode Error code.
389  * @param errorMsg Error message.
390  * @since 11
391  * @deprecated since 12
392  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnError}
393  * @version 1.0
394  */
395 typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg);
396 
397 /**
398  * @brief Called when an error occurred.
399  * @syscap SystemCapability.Multimedia.Media.AVPlayer
400  * @param player The pointer to an OH_AVPlayer instance.
401  * @param errorCode Error code.
402  * @param errorMsg Error message, only valid in callback function.
403  * @param userData Pointer to user specific data.
404  * @since 12
405  */
406 typedef void (*OH_AVPlayerOnErrorCallback)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg,
407     void *userData);
408 
409 /**
410  * @brief A collection of all callback function pointers in OH_AVPlayer. Register an instance of this
411  * structure to the OH_AVPlayer instance, and process the information reported through the callback to ensure the
412  * normal operation of OH_AVPlayer.
413  * @syscap SystemCapability.Multimedia.Media.AVPlayer
414  * @param onInfo Monitor OH_AVPlayer operation information, refer to {@link OH_AVPlayerOnInfo}
415  * @param onError Monitor OH_AVPlayer operation errors, refer to {@link OH_AVPlayerOnError}
416  * @since 11
417  * @deprecated since 12
418  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnErrorCallback}
419  * @version 1.0
420  */
421 typedef struct AVPlayerCallback {
422     OH_AVPlayerOnInfo onInfo = nullptr;
423     OH_AVPlayerOnError onError = nullptr;
424 } AVPlayerCallback;
425 
426 #ifdef __cplusplus
427 }
428 #endif
429 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
430