mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修复转码可能失败的bug
This commit is contained in:
parent
65b5a1272b
commit
0efe7a26b5
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* 获取所有可用Track,请在isInited()返回true时调用
|
||||
* @return
|
||||
*/
|
||||
vector<Track::Ptr> getTracks() const override;
|
||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
|
||||
/**
|
||||
* 获取节目总时长
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user