mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
RtmpPlay: 兼容无metadata的rtmp流
This commit is contained in:
parent
e51a78ebdc
commit
ac41a1e933
@ -13,6 +13,23 @@
|
|||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
|
size_t RtmpDemuxer::trackCount(const AMFValue &metadata) {
|
||||||
|
size_t ret = 0;
|
||||||
|
metadata.object_for_each([&](const string &key, const AMFValue &val) {
|
||||||
|
if (key == "videocodecid") {
|
||||||
|
//找到视频
|
||||||
|
++ret;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key == "audiocodecid") {
|
||||||
|
//找到音频
|
||||||
|
++ret;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool RtmpDemuxer::loadMetaData(const AMFValue &val){
|
bool RtmpDemuxer::loadMetaData(const AMFValue &val){
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
try {
|
try {
|
||||||
|
@ -30,6 +30,8 @@ public:
|
|||||||
RtmpDemuxer() = default;
|
RtmpDemuxer() = default;
|
||||||
~RtmpDemuxer() override = default;
|
~RtmpDemuxer() override = default;
|
||||||
|
|
||||||
|
static size_t trackCount(const AMFValue &metadata);
|
||||||
|
|
||||||
bool loadMetaData(const AMFValue &metadata);
|
bool loadMetaData(const AMFValue &metadata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,6 +63,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
//派生类回调函数
|
//派生类回调函数
|
||||||
bool onCheckMeta(const AMFValue &val) override {
|
bool onCheckMeta(const AMFValue &val) override {
|
||||||
|
//无metadata或metadata中无track信息时,需要从数据包中获取track
|
||||||
|
_wait_track_ready = (*this)[Client::kWaitTrackReady].as<bool>() || RtmpDemuxer::trackCount(val) == 0;
|
||||||
onCheckMeta_l(val);
|
onCheckMeta_l(val);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -79,7 +81,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onPlayResult(const SockException &ex) override {
|
void onPlayResult(const SockException &ex) override {
|
||||||
if (!(*this)[Client::kWaitTrackReady].as<bool>() || ex) {
|
if (!_wait_track_ready || ex) {
|
||||||
Super::onPlayResult(ex);
|
Super::onPlayResult(ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -88,7 +90,7 @@ private:
|
|||||||
bool addTrack(const Track::Ptr &track) override { return true; }
|
bool addTrack(const Track::Ptr &track) override { return true; }
|
||||||
|
|
||||||
void addTrackCompleted() override {
|
void addTrackCompleted() override {
|
||||||
if ((*this)[Client::kWaitTrackReady].as<bool>()) {
|
if (_wait_track_ready) {
|
||||||
Super::onPlayResult(SockException(Err_success, "play success"));
|
Super::onPlayResult(SockException(Err_success, "play success"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,11 +102,12 @@ private:
|
|||||||
_rtmp_src->setMetaData(val);
|
_rtmp_src->setMetaData(val);
|
||||||
}
|
}
|
||||||
_demuxer = std::make_shared<RtmpDemuxer>();
|
_demuxer = std::make_shared<RtmpDemuxer>();
|
||||||
_demuxer->setTrackListener(this, (*this)[Client::kWaitTrackReady].as<bool>());
|
_demuxer->setTrackListener(this, _wait_track_ready);
|
||||||
_demuxer->loadMetaData(val);
|
_demuxer->loadMetaData(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool _wait_track_ready = true;
|
||||||
RtmpDemuxer::Ptr _demuxer;
|
RtmpDemuxer::Ptr _demuxer;
|
||||||
RtmpMediaSource::Ptr _rtmp_src;
|
RtmpMediaSource::Ptr _rtmp_src;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user