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