mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-30 06:42:22 +08:00
开始修改播放器
This commit is contained in:
@@ -85,7 +85,7 @@ public:
|
||||
lock_guard<recursive_mutex> lock(m_mtxMap);
|
||||
m_metadata = _metadata;
|
||||
RtmpParser parser(_metadata);
|
||||
m_iCfgFrameSize = parser.containAudio() + parser.containVideo();
|
||||
m_iCfgFrameSize = parser.getTrackCount();
|
||||
if(ready()){
|
||||
MediaSource::regist();
|
||||
m_bRegisted = true;
|
||||
|
||||
@@ -53,58 +53,6 @@ public:
|
||||
|
||||
bool inputRtmp(const RtmpPacket::Ptr &pkt);
|
||||
|
||||
void setOnVideoCB(const function<void(const H264Frame &frame)> &cb) override{
|
||||
lock_guard<recursive_mutex> lck(m_mtxCB);
|
||||
onVideo = cb;
|
||||
}
|
||||
void setOnAudioCB(const function<void(const AACFrame &frame)> &cb) override{
|
||||
lock_guard<recursive_mutex> lck(m_mtxCB);
|
||||
onAudio = cb;
|
||||
}
|
||||
|
||||
int getVideoHeight() const override{
|
||||
return m_iVideoHeight;
|
||||
}
|
||||
|
||||
int getVideoWidth() const override{
|
||||
return m_iVideoWidth;
|
||||
}
|
||||
|
||||
float getVideoFps() const override{
|
||||
return m_fVideoFps;
|
||||
}
|
||||
|
||||
int getAudioSampleRate() const override{
|
||||
return m_iSampleRate;
|
||||
}
|
||||
|
||||
int getAudioSampleBit() const override{
|
||||
return m_iSampleBit;
|
||||
}
|
||||
|
||||
int getAudioChannel() const override{
|
||||
return m_iChannel;
|
||||
}
|
||||
|
||||
const string& getPps() const override{
|
||||
return m_strPPS;
|
||||
}
|
||||
|
||||
const string& getSps() const override{
|
||||
return m_strSPS;
|
||||
}
|
||||
|
||||
const string& getAudioCfg() const override{
|
||||
return m_strAudioCfg;
|
||||
}
|
||||
bool containAudio() const override{
|
||||
//音频只支持aac
|
||||
return m_iAudioCodecID == AAC_CODEC_ID;
|
||||
}
|
||||
bool containVideo () const override{
|
||||
//视频只支持264
|
||||
return m_iVideoCodecID == H264_CODEC_ID;
|
||||
}
|
||||
bool isInited() const override{
|
||||
if((m_iAudioCodecID | m_iVideoCodecID) == 0){
|
||||
//音视频codec_id都未获取到,说明还未初始化成功
|
||||
|
||||
@@ -69,8 +69,9 @@ private:
|
||||
}
|
||||
try {
|
||||
m_parser.reset(new RtmpParser(val));
|
||||
m_parser->setOnVideoCB(m_onGetVideoCB);
|
||||
m_parser->setOnAudioCB(m_onGetAudioCB);
|
||||
//todo(xzl) 修复此处
|
||||
// m_parser->setOnVideoCB(m_onGetVideoCB);
|
||||
// m_parser->setOnAudioCB(m_onGetAudioCB);
|
||||
return true;
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << ex.what();
|
||||
|
||||
@@ -79,76 +79,79 @@ void RtmpToRtspMediaSource::makeSDP() {
|
||||
strSDP += StrPrinter << "0-"<< m_pParser->getDuration()<< "\r\n" << endl;
|
||||
}
|
||||
strSDP += "a=control:*\r\n";
|
||||
if (m_pParser->containVideo()) {
|
||||
uint32_t ssrc0;
|
||||
memcpy(&ssrc0, makeRandStr(4, false).data(), 4);
|
||||
auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) {
|
||||
m_pRtspSrc->onGetRTP(pkt,bKeyPos);
|
||||
};
|
||||
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,videoMtu,Config::Rtp::kVideoMtuSize);
|
||||
m_pRtpMaker_h264.reset(new RtpMaker_H264(lam, ssrc0,videoMtu));
|
||||
//todo(xzl) 修复此处
|
||||
|
||||
char strTemp[100];
|
||||
int profile_level_id = 0;
|
||||
string strSPS =m_pParser->getSps().substr(4);
|
||||
string strPPS =m_pParser->getPps().substr(4);
|
||||
if (strSPS.length() >= 4) { // sanity check
|
||||
profile_level_id = (strSPS[1] << 16) | (strSPS[2] << 8) | strSPS[3]; // profile_idc|constraint_setN_flag|level_idc
|
||||
}
|
||||
|
||||
//视频通道
|
||||
strSDP += StrPrinter << "m=video 0 RTP/AVP " << m_pRtpMaker_h264->getPlayloadType()
|
||||
<< "\r\n" << endl;
|
||||
strSDP += "b=AS:5100\r\n";
|
||||
strSDP += StrPrinter << "a=rtpmap:" << m_pRtpMaker_h264->getPlayloadType()
|
||||
<< " H264/" << m_pRtpMaker_h264->getSampleRate() << "\r\n" << endl;
|
||||
strSDP += StrPrinter << "a=fmtp:" << m_pRtpMaker_h264->getPlayloadType()
|
||||
<< " packetization-mode=1;profile-level-id=" << endl;
|
||||
|
||||
memset(strTemp, 0, 100);
|
||||
sprintf(strTemp, "%06X", profile_level_id);
|
||||
strSDP += strTemp;
|
||||
strSDP += ";sprop-parameter-sets=";
|
||||
memset(strTemp, 0, 100);
|
||||
av_base64_encode(strTemp, 100, (uint8_t *) strSPS.data(), strSPS.size());
|
||||
strSDP += strTemp;
|
||||
strSDP += ",";
|
||||
memset(strTemp, 0, 100);
|
||||
av_base64_encode(strTemp, 100, (uint8_t *) strPPS.data(), strPPS.size());
|
||||
strSDP += strTemp;
|
||||
strSDP += "\r\n";
|
||||
strSDP += StrPrinter << "a=control:trackID=" << m_pRtpMaker_h264->getInterleaved() / 2
|
||||
<< "\r\n" << endl;
|
||||
}
|
||||
|
||||
if (m_pParser->containAudio()) {
|
||||
uint32_t ssrc1;
|
||||
memcpy(&ssrc1, makeRandStr(8, false).data() + 4, 4);
|
||||
auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) {
|
||||
m_pRtspSrc->onGetRTP(pkt,bKeyPos);
|
||||
};
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,audioMtu,Config::Rtp::kAudioMtuSize);
|
||||
m_pRtpMaker_aac.reset(new RtpMaker_AAC(lam, ssrc1, audioMtu,m_pParser->getAudioSampleRate()));
|
||||
|
||||
char configStr[32];
|
||||
const string & strAacCfg = m_pParser->getAudioCfg();
|
||||
snprintf(configStr, sizeof(configStr), "%02X%02x", strAacCfg[0], strAacCfg[1]);
|
||||
strSDP += StrPrinter << "m=audio 0 RTP/AVP " << m_pRtpMaker_aac->getPlayloadType()
|
||||
<< "\r\n" << endl;
|
||||
strSDP += "b=AS:96\r\n";
|
||||
strSDP += StrPrinter << "a=rtpmap:" << m_pRtpMaker_aac->getPlayloadType()
|
||||
<< " MPEG4-GENERIC/" << m_pRtpMaker_aac->getSampleRate() << "\r\n"
|
||||
<< endl;
|
||||
strSDP += StrPrinter << "a=fmtp:" << m_pRtpMaker_aac->getPlayloadType()
|
||||
<< " streamtype=5;profile-level-id=1;mode=AAC-hbr;"
|
||||
<< "sizelength=13;indexlength=3;indexdeltalength=3;config="
|
||||
<< endl;
|
||||
strSDP.append(configStr, 4);
|
||||
strSDP += "\r\n";
|
||||
strSDP += StrPrinter << "a=control:trackID=" << m_pRtpMaker_aac->getInterleaved() / 2
|
||||
<< "\r\n" << endl;
|
||||
}
|
||||
// if (m_pParser->containVideo()) {
|
||||
// uint32_t ssrc0;
|
||||
// memcpy(&ssrc0, makeRandStr(4, false).data(), 4);
|
||||
// auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) {
|
||||
// m_pRtspSrc->onGetRTP(pkt,bKeyPos);
|
||||
// };
|
||||
//
|
||||
// GET_CONFIG_AND_REGISTER(uint32_t,videoMtu,Config::Rtp::kVideoMtuSize);
|
||||
// m_pRtpMaker_h264.reset(new RtpMaker_H264(lam, ssrc0,videoMtu));
|
||||
//
|
||||
// char strTemp[100];
|
||||
// int profile_level_id = 0;
|
||||
// string strSPS =m_pParser->getSps().substr(4);
|
||||
// string strPPS =m_pParser->getPps().substr(4);
|
||||
// if (strSPS.length() >= 4) { // sanity check
|
||||
// profile_level_id = (strSPS[1] << 16) | (strSPS[2] << 8) | strSPS[3]; // profile_idc|constraint_setN_flag|level_idc
|
||||
// }
|
||||
//
|
||||
// //视频通道
|
||||
// strSDP += StrPrinter << "m=video 0 RTP/AVP " << m_pRtpMaker_h264->getPlayloadType()
|
||||
// << "\r\n" << endl;
|
||||
// strSDP += "b=AS:5100\r\n";
|
||||
// strSDP += StrPrinter << "a=rtpmap:" << m_pRtpMaker_h264->getPlayloadType()
|
||||
// << " H264/" << m_pRtpMaker_h264->getSampleRate() << "\r\n" << endl;
|
||||
// strSDP += StrPrinter << "a=fmtp:" << m_pRtpMaker_h264->getPlayloadType()
|
||||
// << " packetization-mode=1;profile-level-id=" << endl;
|
||||
//
|
||||
// memset(strTemp, 0, 100);
|
||||
// sprintf(strTemp, "%06X", profile_level_id);
|
||||
// strSDP += strTemp;
|
||||
// strSDP += ";sprop-parameter-sets=";
|
||||
// memset(strTemp, 0, 100);
|
||||
// av_base64_encode(strTemp, 100, (uint8_t *) strSPS.data(), strSPS.size());
|
||||
// strSDP += strTemp;
|
||||
// strSDP += ",";
|
||||
// memset(strTemp, 0, 100);
|
||||
// av_base64_encode(strTemp, 100, (uint8_t *) strPPS.data(), strPPS.size());
|
||||
// strSDP += strTemp;
|
||||
// strSDP += "\r\n";
|
||||
// strSDP += StrPrinter << "a=control:trackID=" << m_pRtpMaker_h264->getInterleaved() / 2
|
||||
// << "\r\n" << endl;
|
||||
// }
|
||||
//
|
||||
// if (m_pParser->containAudio()) {
|
||||
// uint32_t ssrc1;
|
||||
// memcpy(&ssrc1, makeRandStr(8, false).data() + 4, 4);
|
||||
// auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) {
|
||||
// m_pRtspSrc->onGetRTP(pkt,bKeyPos);
|
||||
// };
|
||||
// GET_CONFIG_AND_REGISTER(uint32_t,audioMtu,Config::Rtp::kAudioMtuSize);
|
||||
// m_pRtpMaker_aac.reset(new RtpMaker_AAC(lam, ssrc1, audioMtu,m_pParser->getAudioSampleRate()));
|
||||
//
|
||||
// char configStr[32];
|
||||
// const string & strAacCfg = m_pParser->getAudioCfg();
|
||||
// snprintf(configStr, sizeof(configStr), "%02X%02x", strAacCfg[0], strAacCfg[1]);
|
||||
// strSDP += StrPrinter << "m=audio 0 RTP/AVP " << m_pRtpMaker_aac->getPlayloadType()
|
||||
// << "\r\n" << endl;
|
||||
// strSDP += "b=AS:96\r\n";
|
||||
// strSDP += StrPrinter << "a=rtpmap:" << m_pRtpMaker_aac->getPlayloadType()
|
||||
// << " MPEG4-GENERIC/" << m_pRtpMaker_aac->getSampleRate() << "\r\n"
|
||||
// << endl;
|
||||
// strSDP += StrPrinter << "a=fmtp:" << m_pRtpMaker_aac->getPlayloadType()
|
||||
// << " streamtype=5;profile-level-id=1;mode=AAC-hbr;"
|
||||
// << "sizelength=13;indexlength=3;indexdeltalength=3;config="
|
||||
// << endl;
|
||||
// strSDP.append(configStr, 4);
|
||||
// strSDP += "\r\n";
|
||||
// strSDP += StrPrinter << "a=control:trackID=" << m_pRtpMaker_aac->getInterleaved() / 2
|
||||
// << "\r\n" << endl;
|
||||
// }
|
||||
|
||||
m_pRtspSrc.reset(new RtspMediaSource(getVhost(),getApp(),getId()));
|
||||
m_pRtspSrc->setListener(m_listener);
|
||||
|
||||
@@ -67,8 +67,10 @@ public:
|
||||
try {
|
||||
m_pParser.reset(new RtmpParser(_metadata));
|
||||
m_pRecorder.reset(new MediaRecorder(getVhost(),getApp(),getId(),m_pParser,m_bEnableHls,m_bEnableMp4));
|
||||
m_pParser->setOnAudioCB(std::bind(&RtmpToRtspMediaSource::onGetAdts, this, placeholders::_1));
|
||||
m_pParser->setOnVideoCB(std::bind(&RtmpToRtspMediaSource::onGetH264, this, placeholders::_1));
|
||||
//todo(xzl) 修复此处
|
||||
|
||||
// m_pParser->setOnAudioCB(std::bind(&RtmpToRtspMediaSource::onGetAdts, this, placeholders::_1));
|
||||
// m_pParser->setOnVideoCB(std::bind(&RtmpToRtspMediaSource::onGetH264, this, placeholders::_1));
|
||||
} catch (exception &ex) {
|
||||
WarnL << ex.what();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user