• 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  * @syscap SystemCapability.Multimedia.Media.AVPlayer
35  * @since 11
36  * @version 1.0
37  */
38 
39 #ifndef MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
40 #define MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
41 
42 #include <stdint.h>
43 
44 #include "native_avformat.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 typedef struct OH_AVPlayer OH_AVPlayer;
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 Playback Speed
100  * @syscap SystemCapability.Multimedia.Media.AVPlayer
101  * @since 11
102  * @version 1.0
103  */
104 typedef enum AVPlaybackSpeed {
105     /* Video playback at 0.75x normal speed */
106     AV_SPEED_FORWARD_0_75_X,
107     /* Video playback at normal speed */
108     AV_SPEED_FORWARD_1_00_X,
109     /* Video playback at 1.25x normal speed */
110     AV_SPEED_FORWARD_1_25_X,
111     /* Video playback at 1.75x normal speed */
112     AV_SPEED_FORWARD_1_75_X,
113     /* Video playback at 2.0x normal speed */
114     AV_SPEED_FORWARD_2_00_X,
115     /**
116      * @brief Video playback at 0.5x normal speed.
117      * @syscap SystemCapability.Multimedia.Media.AVPlayer
118      * @since 12
119      */
120     AV_SPEED_FORWARD_0_50_X,
121     /**
122      * @brief Video playback at 1.5x normal speed.
123      * @syscap SystemCapability.Multimedia.Media.AVPlayer
124      * @since 12
125      */
126     AV_SPEED_FORWARD_1_50_X,
127     /**
128      * @brief Video playback at 3.0x normal speed.
129      * @syscap SystemCapability.Multimedia.Media.AVPlayer
130      * @since 13
131     */
132     AV_SPEED_FORWARD_3_00_X,
133     /**
134      * @brief Video playback at 0.25x normal speed.
135      * @syscap SystemCapability.Multimedia.Media.AVPlayer
136      * @since 13
137     */
138     AV_SPEED_FORWARD_0_25_X,
139     /**
140      * @brief Video playback at 0.125x normal speed.
141      * @syscap SystemCapability.Multimedia.Media.AVPlayer
142      * @since 13
143     */
144     AV_SPEED_FORWARD_0_125_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     /**
195      * @brief Event type indicating playback rate configuration completed.
196      *
197      * Triggered when playback rate are successfully applied,
198      * notifying the application of the actual effective value.
199      * Use defined key {@link OH_PLAYER_PLAYBACK_RATE} to retrieve value from the event data.
200      * @since 20
201      */
202     AV_INFO_TYPE_PLAYBACK_RATE_DONE = 18,
203 } AVPlayerOnInfoType;
204 
205 /**
206  * @brief Player Buffering Type
207  * @syscap SystemCapability.Multimedia.Media.AVPlayer
208  * @since 12
209  * @version 1.0
210  */
211 typedef enum AVPlayerBufferingType {
212     /** Indicates the buffer to start buffering. */
213     AVPLAYER_BUFFERING_START = 1,
214 
215     /** Indicates the buffer to end buffering and start playback. */
216     AVPLAYER_BUFFERING_END,
217 
218     /** Indicates the current buffering percentage of the buffer. */
219     AVPLAYER_BUFFERING_PERCENT,
220 
221     /** Indicates how long the buffer cache data can be played. */
222     AVPLAYER_BUFFERING_CACHED_DURATION,
223 } AVPlayerBufferingType;
224 
225 /**
226  * @brief Key to get state, value type is int32_t.
227  * @syscap SystemCapability.Multimedia.Media.AVPlayer
228  * @since 12
229  * @version 1.0
230  */
231 extern const char* OH_PLAYER_STATE;
232 
233 /**
234  * @brief Key to get state change reason, value type is int32_t.
235  * @syscap SystemCapability.Multimedia.Media.AVPlayer
236  * @since 12
237  * @version 1.0
238  */
239 extern const char* OH_PLAYER_STATE_CHANGE_REASON;
240 
241 /**
242  * @brief Key to get volume, value type is float.
243  * @syscap SystemCapability.Multimedia.Media.AVPlayer
244  * @since 12
245  * @version 1.0
246  */
247 extern const char* OH_PLAYER_VOLUME;
248 
249 /**
250  * @brief Key to get bitrate count, value type is uint32_t array.
251  * @syscap SystemCapability.Multimedia.Media.AVPlayer
252  * @since 12
253  * @version 1.0
254  */
255 extern const char* OH_PLAYER_BITRATE_ARRAY;
256 
257 /**
258  * @brief Key to get audio interrupt type, value type is int32_t.
259  * @syscap SystemCapability.Multimedia.Media.AVPlayer
260  * @since 12
261  * @version 1.0
262  */
263 extern const char* OH_PLAYER_AUDIO_INTERRUPT_TYPE;
264 
265 /**
266  * @brief Key to get audio interrupt force, value type is int32_t.
267  * @syscap SystemCapability.Multimedia.Media.AVPlayer
268  * @since 12
269  * @version 1.0
270  */
271 extern const char* OH_PLAYER_AUDIO_INTERRUPT_FORCE;
272 
273 /**
274  * @brief Key to get audio interrupt hint, value type is int32_t.
275  * @syscap SystemCapability.Multimedia.Media.AVPlayer
276  * @since 12
277  * @version 1.0
278  */
279 extern const char* OH_PLAYER_AUDIO_INTERRUPT_HINT;
280 
281 /**
282  * @brief Key to get audio device change reason, value type is int32_t.
283  * @syscap SystemCapability.Multimedia.Media.AVPlayer
284  * @since 12
285  * @version 1.0
286  */
287 extern const char* OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON;
288 
289 /**
290  * @brief Key to get buffering type, value type is AVPlayerBufferingType.
291  * @syscap SystemCapability.Multimedia.Media.AVPlayer
292  * @since 12
293  * @version 1.0
294  */
295 extern const char* OH_PLAYER_BUFFERING_TYPE;
296 
297 /**
298  * @brief Key to get buffering value, value type is int32_t.
299  * @syscap SystemCapability.Multimedia.Media.AVPlayer
300  * @since 12
301  * @version 1.0
302  */
303 extern const char* OH_PLAYER_BUFFERING_VALUE;
304 
305 /**
306  * @brief Key to get seek position, value type is int32_t.
307  * @syscap SystemCapability.Multimedia.Media.AVPlayer
308  * @since 12
309  */
310 extern const char* OH_PLAYER_SEEK_POSITION;
311 
312 /**
313  * @brief Key to get playback speed, value type is AVPlaybackSpeed.
314  * @syscap SystemCapability.Multimedia.Media.AVPlayer
315  * @since 12
316  */
317 extern const char* OH_PLAYER_PLAYBACK_SPEED;
318 
319 /**
320  * @brief Key for retrieving effective playback rate, the value type is float.
321  * @syscap SystemCapability.Multimedia.Media.AVPlayer
322  * @since 20
323  */
324 extern const char* OH_PLAYER_PLAYBACK_RATE;
325 
326 /**
327  * @brief Key to get bitrate, value type is uint32_t.
328  * @syscap SystemCapability.Multimedia.Media.AVPlayer
329  * @since 12
330  */
331 extern const char* OH_PLAYER_BITRATE;
332 
333 /**
334  * @brief Key to get current position, value type is int32_t.
335  * @syscap SystemCapability.Multimedia.Media.AVPlayer
336  * @since 12
337  */
338 extern const char* OH_PLAYER_CURRENT_POSITION;
339 
340 /**
341  * @brief Key to get duration, value type is int64_t.
342  * @syscap SystemCapability.Multimedia.Media.AVPlayer
343  * @since 12
344  */
345 extern const char* OH_PLAYER_DURATION;
346 
347 /**
348  * @brief Key to get video width, value type is int32_t.
349  * @syscap SystemCapability.Multimedia.Media.AVPlayer
350  * @since 12
351  */
352 extern const char* OH_PLAYER_VIDEO_WIDTH;
353 
354 /**
355  * @brief Key to get video height, value type is int32_t.
356  * @syscap SystemCapability.Multimedia.Media.AVPlayer
357  * @since 12
358  */
359 extern const char* OH_PLAYER_VIDEO_HEIGHT;
360 
361 /**
362  * @brief Key to get message type, value type is int32_t.
363  * @syscap SystemCapability.Multimedia.Media.AVPlayer
364  * @since 12
365  */
366 extern const char* OH_PLAYER_MESSAGE_TYPE;
367 
368 /**
369  * @brief Key to get is live stream, value type is int32_t.
370  * @syscap SystemCapability.Multimedia.Media.AVPlayer
371  * @since 12
372  */
373 extern const char* OH_PLAYER_IS_LIVE_STREAM;
374 
375 /**
376  * @brief Called when a player message or alarm is received.
377  * @syscap SystemCapability.Multimedia.Media.AVPlayer
378  * @param player The pointer to an OH_AVPlayer instance.
379  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
380  * @param extra Indicates other information, for example, the start time position of a playing file.
381  * @since 11
382  * @deprecated since 12
383  * @useinstead {@link OH_AVPlayerOnInfoCallback}
384  * @version 1.0
385  */
386 typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra);
387 
388 /**
389  * @brief Called when a player info event is received.
390  * @syscap SystemCapability.Multimedia.Media.AVPlayer
391  * @param player The pointer to an OH_AVPlayer instance.
392  * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}.
393  * @param infoBody Indicates the information parameters, only valid in callback function.
394  * @param userData Pointer to user specific data.
395  * @since 12
396  */
397 typedef void (*OH_AVPlayerOnInfoCallback)(OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat* infoBody,
398     void *userData);
399 
400 /**
401  * @brief Called when an error occurred for versions above api9
402  * @syscap SystemCapability.Multimedia.Media.AVPlayer
403  * @param player The pointer to an OH_AVPlayer instance.
404  * @param errorCode Error code.
405  * @param errorMsg Error message.
406  * @since 11
407  * @deprecated since 12
408  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnError}
409  * @version 1.0
410  */
411 typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg);
412 
413 /**
414  * @brief Called when an error occurred.
415  * @syscap SystemCapability.Multimedia.Media.AVPlayer
416  * @param player The pointer to an OH_AVPlayer instance.
417  * @param errorCode Error code.
418  * @param errorMsg Error message, only valid in callback function.
419  * @param userData Pointer to user specific data.
420  * @since 12
421  */
422 typedef void (*OH_AVPlayerOnErrorCallback)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg,
423     void *userData);
424 
425 /**
426  * @brief A collection of all callback function pointers in OH_AVPlayer. Register an instance of this
427  * structure to the OH_AVPlayer instance, and process the information reported through the callback to ensure the
428  * normal operation of OH_AVPlayer.
429  * @syscap SystemCapability.Multimedia.Media.AVPlayer
430  * @param onInfo Monitor OH_AVPlayer operation information, refer to {@link OH_AVPlayerOnInfo}
431  * @param onError Monitor OH_AVPlayer operation errors, refer to {@link OH_AVPlayerOnError}
432  * @since 11
433  * @deprecated since 12
434  * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnErrorCallback}
435  * @version 1.0
436  */
437 typedef struct AVPlayerCallback {
438     OH_AVPlayerOnInfo onInfo;
439     OH_AVPlayerOnError onError;
440 } AVPlayerCallback;
441 
442 #ifdef __cplusplus
443 }
444 #endif
445 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H
446 /** @} */