mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修复rtmp注册时还未生成完整config包的bug
This commit is contained in:
parent
444137e5b7
commit
2610ba7c8b
@ -76,17 +76,24 @@ AACRtmpEncoder::AACRtmpEncoder(const Track::Ptr &track) {
|
||||
_track = dynamic_pointer_cast<AACTrack>(track);
|
||||
}
|
||||
|
||||
void AACRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
||||
if(_aac_cfg.empty()){
|
||||
if(frame->prefixSize() >= 7){
|
||||
//包含adts头,从adts头获取aac配置信息
|
||||
_aac_cfg = makeAdtsConfig(reinterpret_cast<const uint8_t *>(frame->data()));
|
||||
makeAudioConfigPkt();
|
||||
} else if(_track && _track->ready()){
|
||||
void AACRtmpEncoder::makeConfigPacket() {
|
||||
if (_track && _track->ready()) {
|
||||
//从track中和获取aac配置信息
|
||||
_aac_cfg = _track->getAacCfg();
|
||||
}
|
||||
|
||||
if (!_aac_cfg.empty()) {
|
||||
makeAudioConfigPkt();
|
||||
}
|
||||
}
|
||||
|
||||
void AACRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
||||
if (_aac_cfg.empty()) {
|
||||
if (frame->prefixSize() >= 7) {
|
||||
//包含adts头,从adts头获取aac配置信息
|
||||
_aac_cfg = makeAdtsConfig(reinterpret_cast<const uint8_t *>(frame->data()));
|
||||
}
|
||||
makeConfigPacket();
|
||||
}
|
||||
|
||||
if(!_aac_cfg.empty()){
|
||||
|
@ -88,6 +88,10 @@ public:
|
||||
*/
|
||||
void inputFrame(const Frame::Ptr &frame) override;
|
||||
|
||||
/**
|
||||
* 生成config包
|
||||
*/
|
||||
void makeConfigPacket() override;
|
||||
private:
|
||||
void makeAudioConfigPkt();
|
||||
private:
|
||||
|
@ -99,7 +99,20 @@ inline void H264RtmpDecoder::onGetH264(const char* pcData, int iLen, uint32_t dt
|
||||
|
||||
H264RtmpEncoder::H264RtmpEncoder(const Track::Ptr &track) {
|
||||
_track = dynamic_pointer_cast<H264Track>(track);
|
||||
}
|
||||
|
||||
void H264RtmpEncoder::makeConfigPacket(){
|
||||
if (_track && _track->ready()) {
|
||||
//尝试从track中获取sps pps信息
|
||||
_sps = _track->getSps();
|
||||
_pps = _track->getPps();
|
||||
}
|
||||
|
||||
if (!_sps.empty() && !_pps.empty()) {
|
||||
//获取到sps/pps
|
||||
makeVideoConfigPkt();
|
||||
_gotSpsPps = true;
|
||||
}
|
||||
}
|
||||
|
||||
void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
||||
@ -107,37 +120,24 @@ void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) {
|
||||
auto iLen = frame->size() - frame->prefixSize();
|
||||
auto type = H264_TYPE(((uint8_t*)pcData)[0]);
|
||||
|
||||
if(!_gotSpsPps){
|
||||
if (!_gotSpsPps) {
|
||||
//尝试从frame中获取sps pps
|
||||
switch (type){
|
||||
case H264Frame::NAL_SPS:{
|
||||
switch (type) {
|
||||
case H264Frame::NAL_SPS: {
|
||||
//sps
|
||||
if(_sps.empty()){
|
||||
_sps = string(pcData,iLen);
|
||||
}
|
||||
}
|
||||
_sps = string(pcData, iLen);
|
||||
makeConfigPacket();
|
||||
break;
|
||||
case H264Frame::NAL_PPS:{
|
||||
}
|
||||
case H264Frame::NAL_PPS: {
|
||||
//pps
|
||||
if(_pps.empty()){
|
||||
_pps = string(pcData,iLen);
|
||||
}
|
||||
}
|
||||
_pps = string(pcData, iLen);
|
||||
makeConfigPacket();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(_track && _track->ready()){
|
||||
//尝试从track中获取sps pps信息
|
||||
_sps = _track->getSps();
|
||||
_pps = _track->getPps();
|
||||
}
|
||||
|
||||
if(!_sps.empty() && !_pps.empty()){
|
||||
_gotSpsPps = true;
|
||||
makeVideoConfigPkt();
|
||||
}
|
||||
}
|
||||
|
||||
if(type == H264Frame::NAL_SEI){
|
||||
|
@ -90,6 +90,11 @@ public:
|
||||
* @param frame 帧数据
|
||||
*/
|
||||
void inputFrame(const Frame::Ptr &frame) override;
|
||||
|
||||
/**
|
||||
* 生成config包
|
||||
*/
|
||||
void makeConfigPacket() override;
|
||||
private:
|
||||
void makeVideoConfigPkt();
|
||||
private:
|
||||
|
@ -80,6 +80,7 @@ public:
|
||||
typedef std::shared_ptr<RtmpCodec> Ptr;
|
||||
RtmpCodec(){}
|
||||
virtual ~RtmpCodec(){}
|
||||
virtual void makeConfigPacket() {};
|
||||
};
|
||||
|
||||
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
}
|
||||
|
||||
void onAllTrackReady(){
|
||||
makeConfigPacket();
|
||||
_mediaSouce->setMetaData(getMetadata());
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,14 @@ void RtmpMuxer::inputFrame(const Frame::Ptr &frame) {
|
||||
}
|
||||
}
|
||||
|
||||
void RtmpMuxer::makeConfigPacket(){
|
||||
for(auto &encoder : _encoder){
|
||||
if(encoder){
|
||||
encoder->makeConfigPacket();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const AMFValue &RtmpMuxer::getMetadata() const {
|
||||
return _metadata;
|
||||
}
|
||||
|
@ -71,6 +71,11 @@ public:
|
||||
* 重置所有track
|
||||
*/
|
||||
void resetTracks() override ;
|
||||
|
||||
/**
|
||||
* 生成config包
|
||||
*/
|
||||
void makeConfigPacket();
|
||||
private:
|
||||
RtmpRing::RingType::Ptr _rtmpRing;
|
||||
AMFValue _metadata;
|
||||
|
Loading…
Reference in New Issue
Block a user