Commit 9511a9fe by xiongziliang

规范代码

parent b4f8d35e
......@@ -152,7 +152,7 @@ public:
throw std::invalid_argument("adts配置必须为2个字节");
}
_cfg = aac_cfg;
parseAacCfg(_cfg);
onReady();
}
/**
......@@ -165,7 +165,7 @@ public:
throw std::invalid_argument("adts头必须不少于7个字节");
}
_cfg = makeAdtsConfig((uint8_t*)adts_header);
parseAacCfg(_cfg);
onReady();
}
/**
......@@ -177,7 +177,7 @@ public:
throw std::invalid_argument("必须输入带adts头的aac帧");
}
_cfg = makeAdtsConfig((uint8_t*)aac_frame_with_adts->data());
parseAacCfg(_cfg);
onReady();
}
/**
......@@ -235,18 +235,17 @@ public:
if(_cfg.empty() && frame->prefixSize() >= 7){
//7个字节的adts头
_cfg = makeAdtsConfig(reinterpret_cast<const uint8_t *>(frame->data()));
parseAacCfg(_cfg);
onReady();
}
AudioTrack::inputFrame(frame);
}
private:
/**
* 解析2个字节的aac配置
* @param aac_cfg
*/
void parseAacCfg(const string &aac_cfg){
void onReady(){
AACFrame aacFrame;
makeAdtsHeader(aac_cfg,aacFrame);
makeAdtsHeader(_cfg,aacFrame);
getAACInfo(aacFrame,_sampleRate,_channel);
}
Track::Ptr clone() override {
......
......@@ -131,7 +131,7 @@ public:
H264Track(const string &sps,const string &pps,int sps_prefix_len = 4,int pps_prefix_len = 4){
_sps = sps.substr(sps_prefix_len);
_pps = pps.substr(pps_prefix_len);
parseSps(_sps);
onReady();
}
/**
......@@ -145,7 +145,7 @@ public:
}
_sps = string(sps->data() + sps->prefixSize(),sps->size() - sps->prefixSize());
_pps = string(pps->data() + pps->prefixSize(),pps->size() - pps->prefixSize());
parseSps(_sps);
onReady();
}
/**
......@@ -207,11 +207,7 @@ public:
switch (type){
case H264Frame::NAL_SPS:{
//sps
bool flag = _sps.empty();
_sps = string(frame->data() + frame->prefixSize(),frame->size() - frame->prefixSize());
if(flag && _width == 0){
parseSps(_sps);
}
}
break;
case H264Frame::NAL_PPS:{
......@@ -261,14 +257,17 @@ public:
}
break;
}
if(_width == 0 && ready()){
onReady();
}
}
private:
/**
* 解析sps获取宽高fps
* @param sps sps不含头数据
*/
void parseSps(const string &sps){
getAVCInfo(sps,_width,_height,_fps);
void onReady(){
getAVCInfo(_sps,_width,_height,_fps);
}
Track::Ptr clone() override {
return std::make_shared<std::remove_reference<decltype(*this)>::type >(*this);
......
......@@ -161,29 +161,26 @@ public:
/**
* 构造h265类型的媒体
* @param vps vps帧数据
* @param sps sps帧数据
* @param pps pps帧数据
* @param vps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
* @param sps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
* @param pps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
*/
H265Track(const string &sps, const string &pps, int sps_prefix_len = 4, int pps_prefix_len = 4) {
H265Track(const string &vps,const string &sps, const string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4) {
_vps = vps.substr(vps_prefix_len);
_sps = sps.substr(sps_prefix_len);
_pps = pps.substr(pps_prefix_len);
parseSps(_sps);
onReady();
}
/**
* 构造h265类型的媒体
* @param sps sps帧
* @param pps pps帧
* 返回不带0x00 00 00 01头的vps
* @return
*/
H265Track(const Frame::Ptr &sps, const Frame::Ptr &pps) {
if (sps->getCodecId() != CodecH265 || pps->getCodecId() != CodecH265) {
throw std::invalid_argument("必须输入H265类型的帧");
}
_sps = string(sps->data() + sps->prefixSize(), sps->size() - sps->prefixSize());
_pps = string(pps->data() + pps->prefixSize(), pps->size() - pps->prefixSize());
parseSps(_sps);
const string &getVps() const {
return _vps;
}
/**
......@@ -231,7 +228,7 @@ public:
}
bool ready() override {
return !_sps.empty() && !_pps.empty();
return !_sps.empty() && !_pps.empty() && !_vps.empty();
}
......@@ -312,13 +309,17 @@ public:
}
break;
}
if(_width == 0 && ready() ){
onReady();
}
}
private:
/**
* 解析sps获取宽高fps
* @param sps sps不含头数据
*/
void parseSps(const string &sps) {
void onReady() {
// getAVCInfo(sps,_width,_height,_fps);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论