player.h 7.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * MIT License
 *
 * Copyright (c) 2016 xiongziliang <771730766@qq.com>
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef SRC_PLAYER_H_
#define SRC_PLAYER_H_

#include "common.h"

#ifdef __cplusplus
extern "C" {
#endif


////////////////////////////////////////RTSP Player/////////////////////////////////////////////////
typedef void* PlayerContext;
39 40 41
typedef void(API_CALL *player_onResult)(void *userData,int errCode,const char *errMsg);
typedef void(API_CALL *player_onGetAAC)(void *userData,void *data,int len,unsigned long timeStamp);
typedef void(API_CALL *player_onGetH264)(void *userData,void *data,int len,unsigned long dts,unsigned long pts);
42 43 44 45 46
/*
 * 描述:创建一个Rtsp播放器
 * 参数:无
 * 返回值:Rtsp播放器句柄
 */
47
API_EXPORT PlayerContext API_CALL createPlayer();
48 49 50 51 52 53

/*
 * 描述:销毁一个播放器
 * 参数:ctx:播放器句柄
 * 返回值:无
 */
54
API_EXPORT void API_CALL releasePlayer(PlayerContext ctx);
55 56 57 58 59 60 61 62 63


/*
 * 描述:设置播放器配置选项
 * 参数:	ctx:播放器句柄
 *		key:配置项键,例如 rtp_type
 *		val:值,例如 //设置rtp传输类型,可选项有0(tcp,默认)、1(udp)、2(组播)
 * 返回值:无
 */
64 65
API_EXPORT void API_CALL player_setOptionInt(PlayerContext ctx,const char* key,int val);
API_EXPORT void API_CALL player_setOptionString(PlayerContext ctx,const char* key,const char *val);
66 67 68 69 70 71 72 73


/*
 * 描述:播放rtsp链接(仅支持H264与AAC负载)
 * 参数:	ctx:播放器句柄
 *		url:rtsp链接
 * 返回值:无
 */
74
API_EXPORT void API_CALL player_play(PlayerContext ctx,const char* url);
75 76 77 78 79 80

/*
 * 描述:暂停播放RTSP
 * 参数:ctx:播放器句柄;pause:1:暂停播放,0:恢复播放
 * 返回值:无
 */
81
API_EXPORT void API_CALL player_pause(PlayerContext ctx,int pause);
82 83 84 85 86 87

/*
 * 描述:设置播放器异常停止回调函数
 * 参数:ctx:播放器句柄;cb:回调函数指针;userData:用户数据指针
 * 返回值:无
 */
88
API_EXPORT void API_CALL player_setOnShutdown(PlayerContext ctx,player_onResult cb,void *userData);
89 90 91 92 93 94

/*
 * 描述:设置播放器播放结果回调函数
 * 参数:ctx:播放器句柄,cb:回调函数指针;userData:用户数据指针
 * 返回值:无
 */
95
API_EXPORT void API_CALL player_setOnPlayResult(PlayerContext ctx,player_onResult cb,void *userData);
96 97 98 99 100 101

/*
 * 描述:设置播放器收到视频帧回调,I帧前为SPS,PPS帧;每帧包含00 00 00 01的帧头
 * 参数:ctx:播放器句柄,cb:回调函数指针;userData:用户数据指针
 * 返回值:无
 */
102
API_EXPORT void API_CALL player_setOnGetVideo(PlayerContext ctx,player_onGetH264 cb,void *userData);
103 104 105 106 107 108 109


/*
 * 描述:设置播放器收到音频帧回调,每帧数据包含ADTS头
 * 参数:ctx:播放器句柄,cb:回调函数指针;userData:用户数据指针
 * 返回值:无
 */
110
API_EXPORT void API_CALL player_setOnGetAudio(PlayerContext ctx,player_onGetAAC cb,void *userData);
111 112 113 114 115 116

/*
 * 描述:获取视频宽度
 * 参数:ctx:播放器句柄
 * 返回值:视频宽度
 */
117
API_EXPORT int API_CALL player_getVideoWidth(PlayerContext ctx);
118 119 120 121 122 123

/*
 * 描述:获取视频高度
 * 参数:ctx:播放器句柄
 * 返回值:视频高度
 */
124
API_EXPORT int API_CALL API_CALL player_getVideoHeight(PlayerContext ctx);
125 126 127 128 129 130

/*
 * 描述:获取视频帧率
 * 参数:ctx:播放器句柄
 * 返回值:视频帧率
 */
131
API_EXPORT int API_CALL player_getVideoFps(PlayerContext ctx);
132 133 134 135 136 137

/*
 * 描述:获取音频采样率
 * 参数:ctx:播放器句柄
 * 返回值:音频采样率
 */
138
API_EXPORT int API_CALL player_getAudioSampleRate(PlayerContext ctx);
139 140 141 142 143 144

/*
 * 描述:获取音频采样位数(8bit或16bit)
 * 参数:ctx:播放器句柄
 * 返回值:音频采样位数
 */
145
API_EXPORT int API_CALL player_getAudioSampleBit(PlayerContext ctx);
146 147 148 149 150 151

/*
 * 描述:获取音频通道数(单声道1,双声道2)
 * 参数:ctx:播放器句柄
 * 返回值:音频通道数
 */
152
API_EXPORT int API_CALL player_getAudioChannel(PlayerContext ctx);
153 154 155 156 157 158 159


/*
 * 描述:获取H264的PPS帧
 * 参数:ctx:播放器句柄,buf:存放PPS数据的缓存;bufsize:缓存大小
 * 返回值:帧数据长度
 */
160
API_EXPORT int API_CALL player_getH264PPS(PlayerContext ctx,char *buf,int bufsize);
161 162 163 164 165 166 167


/*
 * 描述:获取H264的SPS帧
 * 参数:ctx:播放器句柄,buf:存放SPS数据的缓存;bufsize:缓存大小
 * 返回值:帧数据长度
 */
168
API_EXPORT int API_CALL player_getH264SPS(PlayerContext ctx,char *buf,int bufsize);
169 170 171 172 173 174 175


/*
 * 描述:获取AAC编码配置信息
 * 参数:ctx:播放器句柄;buf:存放CFG数据的缓存;bufsize:缓存大小
 * 返回值:CFG数据长度
 */
176
API_EXPORT int API_CALL player_getAacCfg(PlayerContext ctx,char *buf,int bufsize);
177 178 179 180 181 182 183


/*
 * 描述:是否包含音频数据
 * 参数:ctx:播放器句柄
 * 返回值:1:包含,0:不包含
 */
184
API_EXPORT int API_CALL player_containAudio(PlayerContext ctx);
185 186 187 188 189 190 191


/*
 * 描述:是否包含视频数据
 * 参数:ctx:播放器句柄
 * 返回值:1:包含,0:不包含
 */
192
API_EXPORT int API_CALL player_containVideo(PlayerContext ctx);
193 194 195 196 197 198 199


/*
 * 描述:是否已经初始化完成(获取完整的播放信息)
 * 参数:ctx:播放器句柄
 * 返回值:1:初始化完成,0:未完成
 */
200
API_EXPORT int API_CALL player_isInited(PlayerContext ctx);
201 202 203 204 205 206

/*
 * 描述:获取点播的时间长度,单位为秒(小于等于0,说明是直播,否则为点播)
 * 参数:ctx:播放器句柄
 * 返回值:点播的时间长度,单位秒
 */
207
API_EXPORT float API_CALL player_getDuration(PlayerContext ctx);
208 209 210 211 212 213

/*
 * 描述:获取点播播放进度
 * 参数:ctx:播放器句柄
 * 返回值:点播播放进度,取值范围未 0.0~1.0
 */
214
API_EXPORT float API_CALL player_getProgress(PlayerContext ctx);
215 216 217 218 219 220

/*
 * 描述:设置点播播放进度
 * 参数:ctx:播放器句柄;fProgress:播放进度,取值范围未 0.0~1.0
 * 返回值:无
 */
221
API_EXPORT void API_CALL player_seekTo(PlayerContext ctx, float fProgress);
222 223 224 225 226 227

/*
 * 描述:获取丢包率
 * 参数:ctx:播放器句柄;trackId:如果是-1,则返回总丢包率,否则返回视频或者音频的丢包率
 * 返回值:丢包率
 */
228
API_EXPORT float API_CALL player_getLossRate(PlayerContext ctx,int trackId);
229 230 231 232 233 234 235


#ifdef __cplusplus
}
#endif

#endif /* SRC_PLAYER_H_ */