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

View File

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

View File

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

View File

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