xref: /OK3568_Linux_fs/external/rknpu2/examples/3rdparty/zlmediakit/include/mk_player.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
3  *
4  * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
5  *
6  * Use of this source code is governed by MIT license that can be found in the
7  * LICENSE file in the root of the source tree. All contributing project authors
8  * may be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MK_PLAYER_H_
12 #define MK_PLAYER_H_
13 
14 #include "mk_common.h"
15 #include "mk_frame.h"
16 #include "mk_track.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 typedef void* mk_player;
23 
24 /**
25  * 播放结果或播放中断事件的回调
26  * @param user_data 用户数据指针
27  * @param err_code 错误代码,0为成功
28  * @param err_msg 错误提示
29  * @param tracks track列表
30  * @param track_count track个数
31  */
32 typedef void(API_CALL *on_mk_play_event)(void *user_data, int err_code, const char *err_msg, mk_track tracks[],
33                                          int track_count);
34 
35 /**
36  * 创建一个播放器,支持rtmp[s]/rtsp[s]
37  * @return 播放器指针
38  */
39 API_EXPORT mk_player API_CALL mk_player_create();
40 
41 /**
42  * 销毁播放器
43  * @param ctx 播放器指针
44  */
45 API_EXPORT void API_CALL mk_player_release(mk_player ctx);
46 
47 /**
48  * 设置播放器配置选项
49  * @param ctx 播放器指针
50  * @param key 配置项键,支持 net_adapter/rtp_type/rtsp_user/rtsp_pwd/protocol_timeout_ms/media_timeout_ms/beat_interval_ms/wait_track_ready
51  * @param val 配置项值,如果是整形,需要转换成统一转换成string
52  */
53 API_EXPORT void API_CALL mk_player_set_option(mk_player ctx, const char *key, const char *val);
54 
55 /**
56  * 开始播放url
57  * @param ctx 播放器指针
58  * @param url rtsp[s]/rtmp[s] url
59  */
60 API_EXPORT void API_CALL mk_player_play(mk_player ctx, const char *url);
61 
62 /**
63  * 暂停或恢复播放,仅对点播有用
64  * @param ctx 播放器指针
65  * @param pause 1:暂停播放,0:恢复播放
66  */
67 API_EXPORT void API_CALL mk_player_pause(mk_player ctx, int pause);
68 
69 /**
70  * 倍数播放,仅对点播有用
71  * @param ctx 播放器指针
72  * @param speed 0.5 1.0 2.0
73  */
74 API_EXPORT void API_CALL mk_player_speed(mk_player ctx, float speed);
75 
76 /**
77  * 设置点播进度条
78  * @param ctx 对象指针
79  * @param progress 取值范围未 0.0~1.0
80  */
81 API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress);
82 
83 /**
84  * 设置点播进度条
85  * @param ctx 对象指针
86  * @param seek_pos 取值范围 相对于开始时间增量 单位秒
87  */
88 API_EXPORT void API_CALL mk_player_seekto_pos(mk_player ctx, int seek_pos);
89 
90 /**
91  * 设置播放器开启播放结果回调函数
92  * @param ctx 播放器指针
93  * @param cb 回调函数指针,设置null立即取消回调
94  * @param user_data 用户数据指针
95  */
96 API_EXPORT void API_CALL mk_player_set_on_result(mk_player ctx, on_mk_play_event cb, void *user_data);
97 
98 /**
99  * 设置播放被异常中断的回调
100  * @param ctx 播放器指针
101  * @param cb 回调函数指针,设置null立即取消回调
102  * @param user_data 用户数据指针
103  */
104 API_EXPORT void API_CALL mk_player_set_on_shutdown(mk_player ctx, on_mk_play_event cb, void *user_data);
105 
106 ///////////////////////////获取音视频相关信息接口在播放成功回调触发后才有效///////////////////////////////
107 
108 /**
109  * 获取点播节目时长,如果是直播返回0,否则返回秒数
110  */
111 API_EXPORT float API_CALL mk_player_duration(mk_player ctx);
112 
113 /**
114  * 获取点播播放进度,取值范围 0.0~1.0
115  */
116 API_EXPORT float API_CALL mk_player_progress(mk_player ctx);
117 
118 /**
119  * 获取点播播放进度位置,取值范围 相对于开始时间增量 单位秒
120  */
121 API_EXPORT int API_CALL mk_player_progress_pos(mk_player ctx);
122 
123 /**
124  * 获取丢包率,rtsp时有效
125  * @param ctx 对象指针
126  * @param track_type 0:视频,1:音频
127  */
128 API_EXPORT float API_CALL mk_player_loss_rate(mk_player ctx, int track_type);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* MK_PLAYER_H_ */
135