mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-30 06:59:22 +08:00
DevChannle对象替换成MultiMediaSourceMuxer对象
This commit is contained in:
parent
3bf1a9fddb
commit
d8a1173469
@ -127,15 +127,15 @@ MediaReader::MediaReader(const string &strVhost,const string &strApp, const stri
|
||||
}
|
||||
|
||||
_iDuration = MAX(_video_ms,_audio_ms);
|
||||
_pChn.reset(new DevChannel(strVhost.data(),strApp.data(),strId.data(),_iDuration/1000.0,false, false));
|
||||
_mediaMuxer.reset(new MultiMediaSourceMuxer(strVhost.data(),strApp.data(),strId.data(),_iDuration/1000.0,false, false));
|
||||
if (_audio_trId != MP4_INVALID_TRACK_ID) {
|
||||
AACTrack::Ptr track = std::make_shared<AACTrack>(_strAacCfg);
|
||||
_pChn->addTrack(track);
|
||||
_mediaMuxer->addTrack(track);
|
||||
}
|
||||
|
||||
if (_video_trId != MP4_INVALID_TRACK_ID) {
|
||||
H264Track::Ptr track = std::make_shared<H264Track>(_strSps,_strPps);
|
||||
_pChn->addTrack(track);
|
||||
_mediaMuxer->addTrack(track);
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ void MediaReader::startReadMP4() {
|
||||
AsyncTaskThread::Instance().DoTaskDelay(reinterpret_cast<uint64_t>(this), sampleMS, [strongSelf](){
|
||||
return strongSelf->readSample();
|
||||
});
|
||||
_pChn->setListener(strongSelf);
|
||||
_mediaMuxer->setListener(strongSelf);
|
||||
}
|
||||
bool MediaReader::seekTo(uint32_t ui32Stamp){
|
||||
seek(ui32Stamp);
|
||||
@ -171,7 +171,7 @@ bool MediaReader::readSample(int iTimeInc) {
|
||||
lock_guard<recursive_mutex> lck(_mtx);
|
||||
auto bFlag0 = readVideoSample(iTimeInc);//数据没读完
|
||||
auto bFlag1 = readAudioSample(iTimeInc);//数据没读完
|
||||
auto bFlag2 = _pChn->readerCount() > 0;//读取者大于0
|
||||
auto bFlag2 = _mediaMuxer->readerCount() > 0;//读取者大于0
|
||||
if((bFlag0 || bFlag1) && bFlag2){
|
||||
_alive.resetTime();
|
||||
}
|
||||
@ -236,11 +236,11 @@ inline bool MediaReader::readAudioSample(int iTimeInc) {
|
||||
}
|
||||
|
||||
inline void MediaReader::writeH264(uint8_t *pucData,int iLen,uint32_t uiStamp) {
|
||||
_pChn->inputFrame(std::make_shared<H264FrameNoCopyAble>((char*)pucData,iLen,uiStamp));
|
||||
_mediaMuxer->inputFrame(std::make_shared<H264FrameNoCopyAble>((char*)pucData,iLen,uiStamp));
|
||||
}
|
||||
|
||||
inline void MediaReader::writeAAC(uint8_t *pucData,int iLen,uint32_t uiStamp) {
|
||||
_pChn->inputFrame(std::make_shared<AACFrameNoCopyAble>((char*)pucData,iLen,uiStamp));
|
||||
_mediaMuxer->inputFrame(std::make_shared<AACFrameNoCopyAble>((char*)pucData,iLen,uiStamp));
|
||||
}
|
||||
|
||||
inline MP4SampleId MediaReader::getVideoSampleId(int iTimeInc ) {
|
||||
@ -287,7 +287,7 @@ void MediaReader::seek(uint32_t iSeekTime,bool bReStart){
|
||||
setSeekTime(iSeekTime);
|
||||
}
|
||||
}
|
||||
_pChn->setTimeStamp(_iSeekTime);
|
||||
_mediaMuxer->setTimeStamp(_iSeekTime);
|
||||
|
||||
if(bReStart){
|
||||
AsyncTaskThread::Instance().CancelTask(reinterpret_cast<uint64_t>(this));
|
||||
|
@ -47,9 +47,21 @@ public:
|
||||
public:
|
||||
bool seekTo(uint32_t ui32Stamp) override;
|
||||
bool close() override;
|
||||
private:
|
||||
|
||||
#ifdef ENABLE_MP4V2
|
||||
private:
|
||||
void seek(uint32_t iSeekTime,bool bReStart = true);
|
||||
inline void setSeekTime(uint32_t iSeekTime);
|
||||
inline uint32_t getVideoCurrentTime();
|
||||
void startReadMP4();
|
||||
inline MP4SampleId getVideoSampleId(int iTimeInc = 0);
|
||||
inline MP4SampleId getAudioSampleId(int iTimeInc = 0);
|
||||
bool readSample(int iTimeInc = 0);
|
||||
inline bool readVideoSample(int iTimeInc = 0);
|
||||
inline bool readAudioSample(int iTimeInc = 0);
|
||||
inline void writeH264(uint8_t *pucData,int iLen,uint32_t uiStamp);
|
||||
inline void writeAAC(uint8_t *pucData,int iLen,uint32_t uiStamp);
|
||||
private:
|
||||
MP4FileHandle _hMP4File = MP4_INVALID_FILE_HANDLE;
|
||||
MP4TrackId _video_trId = MP4_INVALID_TRACK_ID;
|
||||
uint32_t _video_ms = 0;
|
||||
@ -72,7 +84,7 @@ private:
|
||||
AACFrame _adts;
|
||||
|
||||
int _iDuration = 0;
|
||||
DevChannel::Ptr _pChn;
|
||||
MultiMediaSourceMuxer::Ptr _mediaMuxer;
|
||||
MP4SampleId _video_current = 0;
|
||||
MP4SampleId _audio_current = 0;
|
||||
std::shared_ptr<uint8_t> _pcVideoSample;
|
||||
@ -81,20 +93,6 @@ private:
|
||||
Ticker _ticker;
|
||||
Ticker _alive;
|
||||
recursive_mutex _mtx;
|
||||
|
||||
void seek(uint32_t iSeekTime,bool bReStart = true);
|
||||
inline void setSeekTime(uint32_t iSeekTime);
|
||||
inline uint32_t getVideoCurrentTime();
|
||||
void startReadMP4();
|
||||
inline MP4SampleId getVideoSampleId(int iTimeInc = 0);
|
||||
inline MP4SampleId getAudioSampleId(int iTimeInc = 0);
|
||||
bool readSample(int iTimeInc = 0);
|
||||
inline bool readVideoSample(int iTimeInc = 0);
|
||||
inline bool readAudioSample(int iTimeInc = 0);
|
||||
inline void writeH264(uint8_t *pucData,int iLen,uint32_t uiStamp);
|
||||
inline void writeAAC(uint8_t *pucData,int iLen,uint32_t uiStamp);
|
||||
|
||||
|
||||
#endif //ENABLE_MP4V2
|
||||
};
|
||||
|
||||
|
@ -99,12 +99,12 @@ void PlayerProxy::play(const char* strUrl) {
|
||||
if(!strongSelf) {
|
||||
return;
|
||||
}
|
||||
if(strongSelf->_pChn) {
|
||||
if(strongSelf->_mediaMuxer) {
|
||||
auto tracks = strongSelf->getTracks();
|
||||
for (auto & track : tracks){
|
||||
track->delDelegate(strongSelf->_pChn.get());
|
||||
track->delDelegate(strongSelf->_mediaMuxer.get());
|
||||
}
|
||||
strongSelf->_pChn.reset();
|
||||
strongSelf->_mediaMuxer.reset();
|
||||
}
|
||||
//播放异常中断,延时重试播放
|
||||
if(*piFailedCnt < strongSelf->_iRetryCount || strongSelf->_iRetryCount < 0) {
|
||||
@ -142,7 +142,7 @@ bool PlayerProxy::close() {
|
||||
executor->async_first([weakSlef]() {
|
||||
auto stronSelf = weakSlef.lock();
|
||||
if (stronSelf) {
|
||||
stronSelf->_pChn.reset();
|
||||
stronSelf->_mediaMuxer.reset();
|
||||
stronSelf->teardown();
|
||||
}
|
||||
});
|
||||
@ -174,32 +174,32 @@ private:
|
||||
};
|
||||
|
||||
void PlayerProxy::onPlaySuccess() {
|
||||
_pChn.reset(new DevChannel(_strVhost.data(),_strApp.data(),_strSrc.data(),getDuration(),_bEnableHls,_bEnableMp4));
|
||||
_pChn->setListener(shared_from_this());
|
||||
_mediaMuxer.reset(new MultiMediaSourceMuxer(_strVhost.data(),_strApp.data(),_strSrc.data(),getDuration(),_bEnableHls,_bEnableMp4));
|
||||
_mediaMuxer->setListener(shared_from_this());
|
||||
|
||||
auto videoTrack = getTrack(TrackVideo);
|
||||
if(videoTrack){
|
||||
//添加视频
|
||||
_pChn->addTrack(videoTrack);
|
||||
_mediaMuxer->addTrack(videoTrack);
|
||||
//视频数据写入_pChn
|
||||
videoTrack->addDelegate(_pChn);
|
||||
videoTrack->addDelegate(_mediaMuxer);
|
||||
}
|
||||
|
||||
auto audioTrack = getTrack(TrackAudio);
|
||||
if(audioTrack){
|
||||
//添加音频
|
||||
_pChn->addTrack(audioTrack);
|
||||
_mediaMuxer->addTrack(audioTrack);
|
||||
//音频数据写入_pChn
|
||||
audioTrack->addDelegate(_pChn);
|
||||
audioTrack->addDelegate(_mediaMuxer);
|
||||
}else if(videoTrack){
|
||||
//没有音频信息,产生一个静音音频
|
||||
MuteAudioMaker::Ptr audioMaker = std::make_shared<MuteAudioMaker>();
|
||||
//videoTrack把数据写入MuteAudioMaker
|
||||
videoTrack->addDelegate(audioMaker);
|
||||
//添加一个静音Track至_pChn
|
||||
_pChn->addTrack(std::make_shared<AACTrack>());
|
||||
_mediaMuxer->addTrack(std::make_shared<AACTrack>());
|
||||
//MuteAudioMaker生成静音音频然后写入_pChn;
|
||||
audioMaker->addDelegate(_pChn);
|
||||
audioMaker->addDelegate(_mediaMuxer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ private:
|
||||
bool _bEnableHls;
|
||||
bool _bEnableMp4;
|
||||
int _iRetryCount;
|
||||
DevChannel::Ptr _pChn;
|
||||
MultiMediaSourceMuxer::Ptr _mediaMuxer;
|
||||
string _strVhost;
|
||||
string _strApp;
|
||||
string _strSrc;
|
||||
|
Loading…
Reference in New Issue
Block a user