修复转码可能失败的bug

This commit is contained in:
xiongziliang 2018-11-16 18:46:05 +08:00
parent 65b5a1272b
commit 0efe7a26b5
4 changed files with 38 additions and 32 deletions

View File

@ -52,34 +52,36 @@ PlayerBase::Ptr PlayerBase::createPlayer(const char* strUrl) {
} }
///////////////////////////Demuxer////////////////////////////// ///////////////////////////Demuxer//////////////////////////////
bool Demuxer::isInited() { bool Demuxer::isInited(int analysisMs) {
if(_ticker.createdTime() < 500){ if(_ticker.createdTime() < analysisMs){
//500毫秒内判断条件 //analysisMs毫秒内判断条件
//如果音视频都准备好了 说明Track全部就绪 //如果音视频都准备好了 说明Track全部就绪
return (_videoTrack && _videoTrack->ready() && _audioTrack && _audioTrack->ready()); return (_videoTrack && _videoTrack->ready() && _audioTrack && _audioTrack->ready());
} }
//analysisMs毫秒后强制初始化完毕
//500毫秒之后,去除还未就绪的Track
if(_videoTrack && !_videoTrack->ready()){
//有视频但是视频未就绪
_videoTrack = nullptr;
}
if(_audioTrack && !_audioTrack->ready()){
//有音频但是音频未就绪
_audioTrack = nullptr;
}
return true; return true;
} }
vector<Track::Ptr> Demuxer::getTracks() const { vector<Track::Ptr> Demuxer::getTracks(bool trackReady) const {
vector<Track::Ptr> ret; vector<Track::Ptr> ret;
if(_videoTrack){ if(_videoTrack){
if(trackReady){
if(_videoTrack->ready()){
ret.emplace_back(_videoTrack); ret.emplace_back(_videoTrack);
} }
}else{
ret.emplace_back(_videoTrack);
}
}
if(_audioTrack){ if(_audioTrack){
if(trackReady){
if(_audioTrack->ready()){
ret.emplace_back(_audioTrack); ret.emplace_back(_audioTrack);
} }
}else{
ret.emplace_back(_audioTrack);
}
}
return ret; return ret;
} }

View File

@ -53,23 +53,26 @@ public:
/** /**
* getTrack方法 * getTrack方法
* @param analysisMs
* @return * @return
*/ */
virtual bool isInited() { return true; } virtual bool isInited(int analysisMs = 2000) { return true; }
/** /**
* Track * Track
* @param trackReady Track
* @return * @return
*/ */
virtual vector<Track::Ptr> getTracks() const { return vector<Track::Ptr>();} virtual vector<Track::Ptr> getTracks(bool trackReady = true) const { return vector<Track::Ptr>();}
/** /**
* Track * Track
* @param type * @param type track类型
* @param trackReady Track
* @return * @return
*/ */
virtual Track::Ptr getTrack(TrackType type) const { virtual Track::Ptr getTrack(TrackType type , bool trackReady = true) const {
auto tracks = getTracks(); auto tracks = getTracks(trackReady);
for(auto &track : tracks){ for(auto &track : tracks){
if(track->getTrackType() == type){ if(track->getTrackType() == type){
return track; return track;
@ -183,11 +186,11 @@ public:
_playResultCB = cb; _playResultCB = cb;
} }
bool isInited() override{ bool isInited(int analysisMs = 2000) override{
if (_parser) { if (_parser) {
return _parser->isInited(); return _parser->isInited(analysisMs);
} }
return PlayerBase::isInited(); return PlayerBase::isInited(analysisMs);
} }
float getDuration() const override { float getDuration() const override {
if (_parser) { if (_parser) {
@ -215,11 +218,11 @@ public:
_pMediaSrc = src; _pMediaSrc = src;
} }
vector<Track::Ptr> getTracks() const override{ vector<Track::Ptr> getTracks(bool trackReady = true) const override{
if (_parser) { if (_parser) {
return _parser->getTracks(); return _parser->getTracks(trackReady);
} }
return PlayerBase::getTracks(); return PlayerBase::getTracks(trackReady);
} }
protected: protected:
void onShutdown(const SockException &ex) override { void onShutdown(const SockException &ex) override {
@ -278,15 +281,16 @@ public:
* *
* RtmpDemuxer对象时是无法获取sps pps aac_cfg等这些信息 * RtmpDemuxer对象时是无法获取sps pps aac_cfg等这些信息
* inputRtmp后才会获取到这些信息 * inputRtmp后才会获取到这些信息
* @param analysisMs
* @return * @return
*/ */
bool isInited() override; bool isInited(int analysisMs = 2000) override;
/** /**
* TrackisInited()true时调用 * TrackisInited()true时调用
* @return * @return
*/ */
vector<Track::Ptr> getTracks() const override; vector<Track::Ptr> getTracks(bool trackReady = true) const override;
/** /**
* *

View File

@ -72,7 +72,7 @@ public:
getId(), getId(),
std::make_shared<TitleSdp>( std::make_shared<TitleSdp>(
_rtmpDemuxer->getDuration())); _rtmpDemuxer->getDuration()));
for (auto &track : _rtmpDemuxer->getTracks()){ for (auto &track : _rtmpDemuxer->getTracks(false)){
_rtspMuxer->addTrack(track); _rtspMuxer->addTrack(track);
_recorder->addTrack(track); _recorder->addTrack(track);
track->addDelegate(_rtspMuxer); track->addDelegate(_rtspMuxer);

View File

@ -66,7 +66,7 @@ public:
getId(), getId(),
std::make_shared<TitleMete>( std::make_shared<TitleMete>(
_rtspDemuxer->getDuration())); _rtspDemuxer->getDuration()));
for (auto &track : _rtspDemuxer->getTracks()) { for (auto &track : _rtspDemuxer->getTracks(false)) {
_rtmpMuxer->addTrack(track); _rtmpMuxer->addTrack(track);
_recorder->addTrack(track); _recorder->addTrack(track);
track->addDelegate(_rtmpMuxer); track->addDelegate(_rtmpMuxer);