mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
完善mk_media接口
This commit is contained in:
parent
c493f0da1b
commit
3bc0769ccb
@ -46,8 +46,9 @@ API_EXPORT void API_CALL mk_media_release(mk_media ctx);
|
|||||||
* @param width 视频宽度
|
* @param width 视频宽度
|
||||||
* @param height 视频高度
|
* @param height 视频高度
|
||||||
* @param fps 视频fps
|
* @param fps 视频fps
|
||||||
|
* @return 1代表成功,0失败
|
||||||
*/
|
*/
|
||||||
API_EXPORT void API_CALL mk_media_init_video(mk_media ctx, int codec_id, int width, int height, float fps);
|
API_EXPORT int API_CALL mk_media_init_video(mk_media ctx, int codec_id, int width, int height, float fps);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加音频轨道
|
* 添加音频轨道
|
||||||
@ -56,8 +57,9 @@ API_EXPORT void API_CALL mk_media_init_video(mk_media ctx, int codec_id, int wid
|
|||||||
* @param channel 通道数
|
* @param channel 通道数
|
||||||
* @param sample_bit 采样位数,只支持16
|
* @param sample_bit 采样位数,只支持16
|
||||||
* @param sample_rate 采样率
|
* @param sample_rate 采样率
|
||||||
|
* @return 1代表成功,0失败
|
||||||
*/
|
*/
|
||||||
API_EXPORT void API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sample_rate, int channels, int sample_bit);
|
API_EXPORT int API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sample_rate, int channels, int sample_bit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加静音音频轨道
|
* 添加静音音频轨道
|
||||||
@ -80,8 +82,9 @@ API_EXPORT void API_CALL mk_media_init_complete(mk_media ctx);
|
|||||||
* @param len 单帧H264数据字节数
|
* @param len 单帧H264数据字节数
|
||||||
* @param dts 解码时间戳,单位毫秒
|
* @param dts 解码时间戳,单位毫秒
|
||||||
* @param pts 播放时间戳,单位毫秒
|
* @param pts 播放时间戳,单位毫秒
|
||||||
|
* @return 1代表成功,0失败
|
||||||
*/
|
*/
|
||||||
API_EXPORT void API_CALL mk_media_input_h264(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts);
|
API_EXPORT int API_CALL mk_media_input_h264(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入单帧H265视频,帧起始字节00 00 01,00 00 00 01均可
|
* 输入单帧H265视频,帧起始字节00 00 01,00 00 00 01均可
|
||||||
@ -90,8 +93,9 @@ API_EXPORT void API_CALL mk_media_input_h264(mk_media ctx, const void *data, int
|
|||||||
* @param len 单帧H265数据字节数
|
* @param len 单帧H265数据字节数
|
||||||
* @param dts 解码时间戳,单位毫秒
|
* @param dts 解码时间戳,单位毫秒
|
||||||
* @param pts 播放时间戳,单位毫秒
|
* @param pts 播放时间戳,单位毫秒
|
||||||
|
* @return 1代表成功,0失败
|
||||||
*/
|
*/
|
||||||
API_EXPORT void API_CALL mk_media_input_h265(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts);
|
API_EXPORT int API_CALL mk_media_input_h265(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入单帧AAC音频(单独指定adts头)
|
* 输入单帧AAC音频(单独指定adts头)
|
||||||
@ -100,8 +104,9 @@ API_EXPORT void API_CALL mk_media_input_h265(mk_media ctx, const void *data, int
|
|||||||
* @param len 单帧AAC数据字节数
|
* @param len 单帧AAC数据字节数
|
||||||
* @param dts 时间戳,毫秒
|
* @param dts 时间戳,毫秒
|
||||||
* @param adts adts头,可以为null
|
* @param adts adts头,可以为null
|
||||||
|
* @return 1代表成功,0失败
|
||||||
*/
|
*/
|
||||||
API_EXPORT void API_CALL mk_media_input_aac(mk_media ctx, const void *data, int len, uint32_t dts, void *adts);
|
API_EXPORT int API_CALL mk_media_input_aac(mk_media ctx, const void *data, int len, uint32_t dts, void *adts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入单帧PCM音频,启用ENABLE_FAAC编译时,该函数才有效
|
* 输入单帧PCM音频,启用ENABLE_FAAC编译时,该函数才有效
|
||||||
@ -109,8 +114,9 @@ API_EXPORT void API_CALL mk_media_input_aac(mk_media ctx, const void *data, int
|
|||||||
* @param data 单帧PCM数据
|
* @param data 单帧PCM数据
|
||||||
* @param len 单帧PCM数据字节数
|
* @param len 单帧PCM数据字节数
|
||||||
* @param dts 时间戳,毫秒
|
* @param dts 时间戳,毫秒
|
||||||
|
* @return 1代表成功,0失败
|
||||||
*/
|
*/
|
||||||
API_EXPORT void API_CALL mk_media_input_pcm(mk_media ctx, void *data, int len, uint32_t pts);
|
API_EXPORT int API_CALL mk_media_input_pcm(mk_media ctx, void *data, int len, uint32_t pts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入单帧OPUS/G711音频帧
|
* 输入单帧OPUS/G711音频帧
|
||||||
@ -118,8 +124,9 @@ API_EXPORT void API_CALL mk_media_input_pcm(mk_media ctx, void *data, int len, u
|
|||||||
* @param data 单帧音频数据
|
* @param data 单帧音频数据
|
||||||
* @param len 单帧音频数据字节数
|
* @param len 单帧音频数据字节数
|
||||||
* @param dts 时间戳,毫秒
|
* @param dts 时间戳,毫秒
|
||||||
|
* @return 1代表成功,0失败
|
||||||
*/
|
*/
|
||||||
API_EXPORT void API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint32_t dts);
|
API_EXPORT int API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint32_t dts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MediaSource.close()回调事件
|
* MediaSource.close()回调事件
|
||||||
|
@ -174,7 +174,7 @@ API_EXPORT void API_CALL mk_media_release(mk_media ctx) {
|
|||||||
delete obj;
|
delete obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_init_video(mk_media ctx, int codec_id, int width, int height, float fps){
|
API_EXPORT int API_CALL mk_media_init_video(mk_media ctx, int codec_id, int width, int height, float fps){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
||||||
VideoInfo info;
|
VideoInfo info;
|
||||||
@ -182,10 +182,10 @@ API_EXPORT void API_CALL mk_media_init_video(mk_media ctx, int codec_id, int wid
|
|||||||
info.iFrameRate = fps;
|
info.iFrameRate = fps;
|
||||||
info.iWidth = width;
|
info.iWidth = width;
|
||||||
info.iHeight = height;
|
info.iHeight = height;
|
||||||
(*obj)->getChannel()->initVideo(info);
|
return (*obj)->getChannel()->initVideo(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sample_rate, int channels, int sample_bit){
|
API_EXPORT int API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sample_rate, int channels, int sample_bit){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
||||||
AudioInfo info;
|
AudioInfo info;
|
||||||
@ -193,7 +193,7 @@ API_EXPORT void API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sam
|
|||||||
info.iSampleRate = sample_rate;
|
info.iSampleRate = sample_rate;
|
||||||
info.iChannel = channels;
|
info.iChannel = channels;
|
||||||
info.iSampleBit = sample_bit;
|
info.iSampleBit = sample_bit;
|
||||||
(*obj)->getChannel()->initAudio(info);
|
return (*obj)->getChannel()->initAudio(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_init_mute_audio(mk_media ctx) {
|
API_EXPORT void API_CALL mk_media_init_mute_audio(mk_media ctx) {
|
||||||
@ -208,34 +208,34 @@ API_EXPORT void API_CALL mk_media_init_complete(mk_media ctx){
|
|||||||
(*obj)->getChannel()->addTrackCompleted();
|
(*obj)->getChannel()->addTrackCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_input_h264(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts) {
|
API_EXPORT int API_CALL mk_media_input_h264(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts) {
|
||||||
assert(ctx && data && len > 0);
|
assert(ctx && data && len > 0);
|
||||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
||||||
(*obj)->getChannel()->inputH264((const char *) data, len, dts, pts);
|
return (*obj)->getChannel()->inputH264((const char *) data, len, dts, pts);
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_input_h265(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts) {
|
API_EXPORT int API_CALL mk_media_input_h265(mk_media ctx, const void *data, int len, uint32_t dts, uint32_t pts) {
|
||||||
assert(ctx && data && len > 0);
|
assert(ctx && data && len > 0);
|
||||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
||||||
(*obj)->getChannel()->inputH265((const char *) data, len, dts, pts);
|
return (*obj)->getChannel()->inputH265((const char *) data, len, dts, pts);
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_input_aac(mk_media ctx, const void *data, int len, uint32_t dts, void *adts) {
|
API_EXPORT int API_CALL mk_media_input_aac(mk_media ctx, const void *data, int len, uint32_t dts, void *adts) {
|
||||||
assert(ctx && data && len > 0 && adts);
|
assert(ctx && data && len > 0 && adts);
|
||||||
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
|
||||||
(*obj)->getChannel()->inputAAC((const char *) data, len, dts, (char *) adts);
|
return (*obj)->getChannel()->inputAAC((const char *) data, len, dts, (char *) adts);
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_input_pcm(mk_media ctx, void *data , int len, uint32_t pts){
|
API_EXPORT int API_CALL mk_media_input_pcm(mk_media ctx, void *data , int len, uint32_t pts){
|
||||||
assert(ctx && data && len > 0);
|
assert(ctx && data && len > 0);
|
||||||
MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx;
|
MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx;
|
||||||
(*obj)->getChannel()->inputPCM((char*)data, len, pts);
|
return (*obj)->getChannel()->inputPCM((char*)data, len, pts);
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint32_t dts){
|
API_EXPORT int API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint32_t dts){
|
||||||
assert(ctx && data && len > 0);
|
assert(ctx && data && len > 0);
|
||||||
MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx;
|
MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx;
|
||||||
(*obj)->getChannel()->inputAudio((const char*)data, len, dts);
|
return (*obj)->getChannel()->inputAudio((const char*)data, len, dts);
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int is_udp, on_mk_media_send_rtp_result cb, void *user_data){
|
API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int is_udp, on_mk_media_send_rtp_result cb, void *user_data){
|
||||||
|
@ -33,7 +33,7 @@ DevChannel::DevChannel(const string &vhost, const string &app, const string &str
|
|||||||
|
|
||||||
DevChannel::~DevChannel() {}
|
DevChannel::~DevChannel() {}
|
||||||
|
|
||||||
void DevChannel::inputYUV(char* apcYuv[3], int aiYuvLen[3], uint32_t uiStamp) {
|
bool DevChannel::inputYUV(char* apcYuv[3], int aiYuvLen[3], uint32_t uiStamp) {
|
||||||
#ifdef ENABLE_X264
|
#ifdef ENABLE_X264
|
||||||
//TimeTicker1(50);
|
//TimeTicker1(50);
|
||||||
if (!_pH264Enc) {
|
if (!_pH264Enc) {
|
||||||
@ -46,16 +46,20 @@ void DevChannel::inputYUV(char* apcYuv[3], int aiYuvLen[3], uint32_t uiStamp) {
|
|||||||
if (_pH264Enc) {
|
if (_pH264Enc) {
|
||||||
H264Encoder::H264Frame *pOut;
|
H264Encoder::H264Frame *pOut;
|
||||||
int iFrames = _pH264Enc->inputData(apcYuv, aiYuvLen, uiStamp, &pOut);
|
int iFrames = _pH264Enc->inputData(apcYuv, aiYuvLen, uiStamp, &pOut);
|
||||||
|
bool ret = false;
|
||||||
for (int i = 0; i < iFrames; i++) {
|
for (int i = 0; i < iFrames; i++) {
|
||||||
inputH264((char *) pOut[i].pucData, pOut[i].iLength, uiStamp);
|
ret = inputH264((char *) pOut[i].pucData, pOut[i].iLength, uiStamp) ? true : ret;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
WarnL << "h264编码未启用,该方法无效,编译时请打开ENABLE_X264选项";
|
WarnL << "h264编码未启用,该方法无效,编译时请打开ENABLE_X264选项";
|
||||||
|
return false;
|
||||||
#endif //ENABLE_X264
|
#endif //ENABLE_X264
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevChannel::inputPCM(char* pcData, int iDataLen, uint32_t uiStamp) {
|
bool DevChannel::inputPCM(char* pcData, int iDataLen, uint32_t uiStamp) {
|
||||||
#ifdef ENABLE_FAAC
|
#ifdef ENABLE_FAAC
|
||||||
if (!_pAacEnc) {
|
if (!_pAacEnc) {
|
||||||
_pAacEnc.reset(new AACEncoder());
|
_pAacEnc.reset(new AACEncoder());
|
||||||
@ -68,15 +72,17 @@ void DevChannel::inputPCM(char* pcData, int iDataLen, uint32_t uiStamp) {
|
|||||||
unsigned char *pucOut;
|
unsigned char *pucOut;
|
||||||
int iRet = _pAacEnc->inputData(pcData, iDataLen, &pucOut);
|
int iRet = _pAacEnc->inputData(pcData, iDataLen, &pucOut);
|
||||||
if (iRet > 7) {
|
if (iRet > 7) {
|
||||||
inputAAC((char *) pucOut + 7, iRet - 7, uiStamp, (char *)pucOut);
|
return inputAAC((char *) pucOut + 7, iRet - 7, uiStamp, (char *)pucOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
WarnL << "aac编码未启用,该方法无效,编译时请打开ENABLE_FAAC选项";
|
WarnL << "aac编码未启用,该方法无效,编译时请打开ENABLE_FAAC选项";
|
||||||
|
return false;
|
||||||
#endif //ENABLE_FAAC
|
#endif //ENABLE_FAAC
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevChannel::inputH264(const char *data, int len, uint32_t dts, uint32_t pts) {
|
bool DevChannel::inputH264(const char *data, int len, uint32_t dts, uint32_t pts) {
|
||||||
if(dts == 0){
|
if(dts == 0){
|
||||||
dts = (uint32_t)_aTicker[0].elapsedTime();
|
dts = (uint32_t)_aTicker[0].elapsedTime();
|
||||||
}
|
}
|
||||||
@ -92,10 +98,10 @@ void DevChannel::inputH264(const char *data, int len, uint32_t dts, uint32_t pts
|
|||||||
frame->_pts = pts;
|
frame->_pts = pts;
|
||||||
frame->_buffer.assign(data, len);
|
frame->_buffer.assign(data, len);
|
||||||
frame->_prefix_size = prefixSize(data,len);
|
frame->_prefix_size = prefixSize(data,len);
|
||||||
inputFrame(frame);
|
return inputFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevChannel::inputH265(const char *data, int len, uint32_t dts, uint32_t pts) {
|
bool DevChannel::inputH265(const char *data, int len, uint32_t dts, uint32_t pts) {
|
||||||
if(dts == 0){
|
if(dts == 0){
|
||||||
dts = (uint32_t)_aTicker[0].elapsedTime();
|
dts = (uint32_t)_aTicker[0].elapsedTime();
|
||||||
}
|
}
|
||||||
@ -111,7 +117,7 @@ void DevChannel::inputH265(const char *data, int len, uint32_t dts, uint32_t pts
|
|||||||
frame->_pts = pts;
|
frame->_pts = pts;
|
||||||
frame->_buffer.assign(data, len);
|
frame->_buffer.assign(data, len);
|
||||||
frame->_prefix_size = prefixSize(data,len);
|
frame->_prefix_size = prefixSize(data,len);
|
||||||
inputFrame(frame);
|
return inputFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
class FrameAutoDelete : public FrameFromPtr{
|
class FrameAutoDelete : public FrameFromPtr{
|
||||||
@ -128,52 +134,53 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void DevChannel::inputAAC(const char *data_without_adts, int len, uint32_t dts, const char *adts_header){
|
bool DevChannel::inputAAC(const char *data_without_adts, int len, uint32_t dts, const char *adts_header){
|
||||||
if (dts == 0) {
|
if (dts == 0) {
|
||||||
dts = (uint32_t) _aTicker[1].elapsedTime();
|
dts = (uint32_t) _aTicker[1].elapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adts_header) {
|
if (!adts_header) {
|
||||||
if (adts_header + ADTS_HEADER_LEN == data_without_adts) {
|
|
||||||
//adts头和帧在一起
|
|
||||||
inputFrame(std::make_shared<FrameFromPtr>(_audio->codecId, (char *) data_without_adts - ADTS_HEADER_LEN, len + ADTS_HEADER_LEN, dts, 0, ADTS_HEADER_LEN));
|
|
||||||
} else {
|
|
||||||
//adts头和帧不在一起
|
|
||||||
char *data_with_adts = new char[len + ADTS_HEADER_LEN];
|
|
||||||
memcpy(data_with_adts, adts_header, ADTS_HEADER_LEN);
|
|
||||||
memcpy(data_with_adts + ADTS_HEADER_LEN, data_without_adts, len);
|
|
||||||
inputFrame(std::make_shared<FrameAutoDelete>(_audio->codecId, data_with_adts, len + ADTS_HEADER_LEN, dts, 0, ADTS_HEADER_LEN));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//没有adts头
|
//没有adts头
|
||||||
inputFrame(std::make_shared<FrameFromPtr>(_audio->codecId, (char *) data_without_adts, len, dts, 0, 0));
|
return inputFrame(std::make_shared<FrameFromPtr>(_audio->codecId, (char *) data_without_adts, len, dts, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (adts_header + ADTS_HEADER_LEN == data_without_adts) {
|
||||||
|
//adts头和帧在一起
|
||||||
|
return inputFrame(std::make_shared<FrameFromPtr>(_audio->codecId, (char *) data_without_adts - ADTS_HEADER_LEN, len + ADTS_HEADER_LEN, dts, 0, ADTS_HEADER_LEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
//adts头和帧不在一起
|
||||||
|
char *data_with_adts = new char[len + ADTS_HEADER_LEN];
|
||||||
|
memcpy(data_with_adts, adts_header, ADTS_HEADER_LEN);
|
||||||
|
memcpy(data_with_adts + ADTS_HEADER_LEN, data_without_adts, len);
|
||||||
|
return inputFrame(std::make_shared<FrameAutoDelete>(_audio->codecId, data_with_adts, len + ADTS_HEADER_LEN, dts, 0, ADTS_HEADER_LEN));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevChannel::inputAudio(const char *data, int len, uint32_t dts){
|
bool DevChannel::inputAudio(const char *data, int len, uint32_t dts){
|
||||||
if (dts == 0) {
|
if (dts == 0) {
|
||||||
dts = (uint32_t) _aTicker[1].elapsedTime();
|
dts = (uint32_t) _aTicker[1].elapsedTime();
|
||||||
}
|
}
|
||||||
inputFrame(std::make_shared<FrameFromPtr>(_audio->codecId, (char *) data, len, dts, 0));
|
return inputFrame(std::make_shared<FrameFromPtr>(_audio->codecId, (char *) data, len, dts, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevChannel::initVideo(const VideoInfo &info) {
|
bool DevChannel::initVideo(const VideoInfo &info) {
|
||||||
_video = std::make_shared<VideoInfo>(info);
|
_video = std::make_shared<VideoInfo>(info);
|
||||||
switch (info.codecId){
|
switch (info.codecId){
|
||||||
case CodecH265 : addTrack(std::make_shared<H265Track>()); break;
|
case CodecH265 : return addTrack(std::make_shared<H265Track>());
|
||||||
case CodecH264 : addTrack(std::make_shared<H264Track>()); break;
|
case CodecH264 : return addTrack(std::make_shared<H264Track>());
|
||||||
default: WarnL << "不支持该类型的视频编码类型:" << info.codecId; break;
|
default: WarnL << "不支持该类型的视频编码类型:" << info.codecId; return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevChannel::initAudio(const AudioInfo &info) {
|
bool DevChannel::initAudio(const AudioInfo &info) {
|
||||||
_audio = std::make_shared<AudioInfo>(info);
|
_audio = std::make_shared<AudioInfo>(info);
|
||||||
switch (info.codecId) {
|
switch (info.codecId) {
|
||||||
case CodecAAC : addTrack(std::make_shared<AACTrack>()); break;
|
case CodecAAC : return addTrack(std::make_shared<AACTrack>());
|
||||||
case CodecG711A :
|
case CodecG711A :
|
||||||
case CodecG711U : addTrack(std::make_shared<G711Track>(info.codecId, info.iSampleRate, info.iChannel, info.iSampleBit)); break;
|
case CodecG711U : return addTrack(std::make_shared<G711Track>(info.codecId, info.iSampleRate, info.iChannel, info.iSampleBit));
|
||||||
case CodecOpus : addTrack(std::make_shared<OpusTrack>()); break;
|
case CodecOpus : return addTrack(std::make_shared<OpusTrack>());
|
||||||
default: WarnL << "不支持该类型的音频编码类型:" << info.codecId; break;
|
default: WarnL << "不支持该类型的音频编码类型:" << info.codecId; return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,14 +58,14 @@ public:
|
|||||||
* 相当于MultiMediaSourceMuxer::addTrack(VideoTrack::Ptr );
|
* 相当于MultiMediaSourceMuxer::addTrack(VideoTrack::Ptr );
|
||||||
* @param info 视频相关信息
|
* @param info 视频相关信息
|
||||||
*/
|
*/
|
||||||
void initVideo(const VideoInfo &info);
|
bool initVideo(const VideoInfo &info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化音频Track
|
* 初始化音频Track
|
||||||
* 相当于MultiMediaSourceMuxer::addTrack(AudioTrack::Ptr );
|
* 相当于MultiMediaSourceMuxer::addTrack(AudioTrack::Ptr );
|
||||||
* @param info 音频相关信息
|
* @param info 音频相关信息
|
||||||
*/
|
*/
|
||||||
void initAudio(const AudioInfo &info);
|
bool initAudio(const AudioInfo &info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入264帧
|
* 输入264帧
|
||||||
@ -74,7 +74,7 @@ public:
|
|||||||
* @param dts 解码时间戳,单位毫秒;等于0时内部会自动生成时间戳
|
* @param dts 解码时间戳,单位毫秒;等于0时内部会自动生成时间戳
|
||||||
* @param pts 播放时间戳,单位毫秒;等于0时内部会赋值为dts
|
* @param pts 播放时间戳,单位毫秒;等于0时内部会赋值为dts
|
||||||
*/
|
*/
|
||||||
void inputH264(const char *data, int len, uint32_t dts, uint32_t pts = 0);
|
bool inputH264(const char *data, int len, uint32_t dts, uint32_t pts = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入265帧
|
* 输入265帧
|
||||||
@ -83,7 +83,7 @@ public:
|
|||||||
* @param dts 解码时间戳,单位毫秒;等于0时内部会自动生成时间戳
|
* @param dts 解码时间戳,单位毫秒;等于0时内部会自动生成时间戳
|
||||||
* @param pts 播放时间戳,单位毫秒;等于0时内部会赋值为dts
|
* @param pts 播放时间戳,单位毫秒;等于0时内部会赋值为dts
|
||||||
*/
|
*/
|
||||||
void inputH265(const char *data, int len, uint32_t dts, uint32_t pts = 0);
|
bool inputH265(const char *data, int len, uint32_t dts, uint32_t pts = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入aac帧
|
* 输入aac帧
|
||||||
@ -92,7 +92,7 @@ public:
|
|||||||
* @param dts 时间戳,单位毫秒
|
* @param dts 时间戳,单位毫秒
|
||||||
* @param adts_header adts头
|
* @param adts_header adts头
|
||||||
*/
|
*/
|
||||||
void inputAAC(const char *data_without_adts, int len, uint32_t dts, const char *adts_header);
|
bool inputAAC(const char *data_without_adts, int len, uint32_t dts, const char *adts_header);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入OPUS/G711音频帧
|
* 输入OPUS/G711音频帧
|
||||||
@ -100,7 +100,7 @@ public:
|
|||||||
* @param len 帧数据长度
|
* @param len 帧数据长度
|
||||||
* @param dts 时间戳,单位毫秒
|
* @param dts 时间戳,单位毫秒
|
||||||
*/
|
*/
|
||||||
void inputAudio(const char *data, int len, uint32_t dts);
|
bool inputAudio(const char *data, int len, uint32_t dts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入yuv420p视频帧,内部会完成编码并调用inputH264方法
|
* 输入yuv420p视频帧,内部会完成编码并调用inputH264方法
|
||||||
@ -108,8 +108,7 @@ public:
|
|||||||
* @param aiYuvLen
|
* @param aiYuvLen
|
||||||
* @param uiStamp
|
* @param uiStamp
|
||||||
*/
|
*/
|
||||||
void inputYUV(char *apcYuv[3], int aiYuvLen[3], uint32_t uiStamp);
|
bool inputYUV(char *apcYuv[3], int aiYuvLen[3], uint32_t uiStamp);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入pcm数据,内部会完成编码并调用inputAAC方法
|
* 输入pcm数据,内部会完成编码并调用inputAAC方法
|
||||||
@ -117,7 +116,7 @@ public:
|
|||||||
* @param iDataLen
|
* @param iDataLen
|
||||||
* @param uiStamp
|
* @param uiStamp
|
||||||
*/
|
*/
|
||||||
void inputPCM(char *pcData, int iDataLen, uint32_t uiStamp);
|
bool inputPCM(char *pcData, int iDataLen, uint32_t uiStamp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||||
|
@ -80,7 +80,7 @@ bool PSEncoder::addTrack(const Track::Ptr &track) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: WarnL << "mpeg-ps 不支持该编码格式,已忽略:" << track->getCodecName(); return false;;
|
default: WarnL << "mpeg-ps 不支持该编码格式,已忽略:" << track->getCodecName(); return false;
|
||||||
}
|
}
|
||||||
//尝试音视频同步
|
//尝试音视频同步
|
||||||
stampSync();
|
stampSync();
|
||||||
|
Loading…
Reference in New Issue
Block a user