完善判断解复用器是否准备好的机制

This commit is contained in:
xiongziliang 2018-10-24 22:29:19 +08:00
parent 3921bfb2d9
commit 5ae154642c
4 changed files with 56 additions and 38 deletions

View File

@ -20,6 +20,12 @@ public:
typedef std::shared_ptr<Track> Ptr; typedef std::shared_ptr<Track> Ptr;
Track(){} Track(){}
virtual ~Track(){} virtual ~Track(){}
/**
*
* @return
*/
virtual bool ready() = 0;
}; };
class VideoTrack : public Track { class VideoTrack : public Track {
@ -152,11 +158,8 @@ public:
return _fps; return _fps;
} }
TrackType getTrackType() const override { bool ready() override {
if(_sps.empty() || _pps.empty()){ return !_sps.empty() && !_pps.empty();
return TrackInvalid;
}
return TrackVideo;
} }
@ -295,12 +298,11 @@ public:
* aac_cfg前是无效的Track * aac_cfg前是无效的Track
* @return * @return
*/ */
TrackType getTrackType() const override { bool ready() override {
if(_cfg.empty()){ return !_cfg.empty();
return TrackInvalid;
}
return TrackAudio;
} }
/** /**
* *
* @return * @return

View File

@ -29,6 +29,7 @@
namespace mediakit { namespace mediakit {
RtmpDemuxer::RtmpDemuxer(const AMFValue &val) { RtmpDemuxer::RtmpDemuxer(const AMFValue &val) {
try { try {
makeVideoTrack(val["videocodecid"]); makeVideoTrack(val["videocodecid"]);
@ -44,17 +45,14 @@ RtmpDemuxer::RtmpDemuxer(const AMFValue &val) {
} }
} }
RtmpDemuxer::~RtmpDemuxer() {
}
bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) { bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
switch (pkt->typeId) { switch (pkt->typeId) {
case MSG_VIDEO: { case MSG_VIDEO: {
if(_videoRtmpDecoder){ if(_videoRtmpDecoder){
return _videoRtmpDecoder->inputRtmp(pkt, true); return _videoRtmpDecoder->inputRtmp(pkt, true);
} }
if(!_tryGetVideoTrack){ if(!_tryedGetVideoTrack){
_tryGetVideoTrack = true; _tryedGetVideoTrack = true;
auto codec = AMFValue(pkt->getMediaType()); auto codec = AMFValue(pkt->getMediaType());
makeVideoTrack(codec); makeVideoTrack(codec);
} }
@ -66,8 +64,8 @@ bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
_audioRtmpDecoder->inputRtmp(pkt, false); _audioRtmpDecoder->inputRtmp(pkt, false);
return false; return false;
} }
if(!_tryGetAudioTrack) { if(!_tryedGetAudioTrack) {
_tryGetAudioTrack = true; _tryedGetAudioTrack = true;
auto codec = AMFValue(pkt->getMediaType()); auto codec = AMFValue(pkt->getMediaType());
makeAudioTrack(codec); makeAudioTrack(codec);
} }
@ -122,16 +120,22 @@ vector<Track::Ptr> RtmpDemuxer::getTracks() const {
} }
bool RtmpDemuxer::isInited() const { bool RtmpDemuxer::isInited() const {
bool ret = true; bool videoReady ,auidoReady;
if(ret && _audioTrack){
//getTrackType() 等于TrackInvalid时说明该Track还未准备好 if(_videoTrack){
ret = _audioTrack->getTrackType() != TrackInvalid; //getTrackType() != TrackInvalid说明其已经准备好了
videoReady = _videoTrack->ready();
}else{
videoReady = _tryedGetVideoTrack || _tryedGetAudioTrack;
} }
if(ret && _videoTrack){
//getTrackType() 等于TrackInvalid时说明该Track还未准备好 if(_audioTrack){
ret = _videoTrack->getTrackType() != TrackInvalid; auidoReady = _audioTrack->ready();
}else{
auidoReady = _tryedGetVideoTrack || _tryedGetAudioTrack;
} }
return ret;
return videoReady && auidoReady;
} }
float RtmpDemuxer::getDuration() const { float RtmpDemuxer::getDuration() const {

View File

@ -43,8 +43,19 @@ namespace mediakit {
class RtmpDemuxer : public PlayerBase{ class RtmpDemuxer : public PlayerBase{
public: public:
typedef std::shared_ptr<RtmpDemuxer> Ptr; typedef std::shared_ptr<RtmpDemuxer> Ptr;
/**
* RtmpDemuxer(AMFValue(AMF_NULL))
*/
RtmpDemuxer(){}
/**
* rtmp解复用器
* @param val rtmp的metedatanull类型
* inputRtmp时异步探测媒体编码格式
*/
RtmpDemuxer(const AMFValue &val); RtmpDemuxer(const AMFValue &val);
virtual ~RtmpDemuxer();
virtual ~RtmpDemuxer(){};
/** /**
* *
@ -77,8 +88,8 @@ private:
void makeAudioTrack(const AMFValue &val); void makeAudioTrack(const AMFValue &val);
private: private:
float _fDuration = 0; float _fDuration = 0;
bool _tryGetVideoTrack = false; bool _tryedGetVideoTrack = false;
bool _tryGetAudioTrack = false; bool _tryedGetAudioTrack = false;
AudioTrack::Ptr _audioTrack; AudioTrack::Ptr _audioTrack;
VideoTrack::Ptr _videoTrack; VideoTrack::Ptr _videoTrack;
RtmpCodec::Ptr _audioRtmpDecoder; RtmpCodec::Ptr _audioRtmpDecoder;

View File

@ -135,16 +135,17 @@ vector<Track::Ptr> RtspDemuxer::getTracks() const {
} }
bool RtspDemuxer::isInited() const { bool RtspDemuxer::isInited() const {
bool ret = true; bool videoReady = true ,auidoReady = true;
if(ret && _audioTrack){
//getTrackType() 等于TrackInvalid时说明该Track还未准备好 if(_videoTrack){
ret = _audioTrack->getTrackType() != TrackInvalid; videoReady = _videoTrack->ready();
} }
if(ret && _videoTrack){
//getTrackType() 等于TrackInvalid时说明该Track还未准备好 if(_audioTrack){
ret = _videoTrack->getTrackType() != TrackInvalid; auidoReady = _audioTrack->ready();
} }
return ret;
return videoReady && auidoReady;
} }
float RtspDemuxer::getDuration() const { float RtspDemuxer::getDuration() const {