整理MediaSource派生类

修复转协议或录制时忽然Track的问题
This commit is contained in:
xiongziliang
2019-12-26 12:10:54 +08:00
parent 9e8fe8c86a
commit 453660ab79
7 changed files with 47 additions and 18 deletions

View File

@@ -29,6 +29,21 @@
namespace mediakit {
void RtmpDemuxer::loadMetaData(const AMFValue &val){
try {
makeVideoTrack(val["videocodecid"]);
makeAudioTrack(val["audiocodecid"]);
val.object_for_each([&](const string &key, const AMFValue &val) {
if (key == "duration") {
_fDuration = val.as_number();
return;
}
});
}catch (std::exception &ex){
WarnL << ex.what();
}
}
bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
switch (pkt->typeId) {
case MSG_VIDEO: {

View File

@@ -43,11 +43,10 @@ class RtmpDemuxer : public Demuxer{
public:
typedef std::shared_ptr<RtmpDemuxer> Ptr;
/**
* 等效于RtmpDemuxer(AMFValue(AMF_NULL))
*/
RtmpDemuxer(){}
virtual ~RtmpDemuxer(){};
RtmpDemuxer() = default;
virtual ~RtmpDemuxer() = default;
void loadMetaData(const AMFValue &metadata);
/**
* 开始解复用

View File

@@ -61,11 +61,19 @@ public:
~RtmpMediaSourceImp() = default;
/**
* 设置metadata
*/
void setMetaData(const AMFValue &metadata) override{
_demuxer->loadMetaData(metadata);
RtmpMediaSource::setMetaData(metadata);
}
/**
* 输入rtmp并解析
*/
void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos = true) override {
_demuxer->inputRtmp(pkt);
key_pos = _demuxer->inputRtmp(pkt);
RtmpMediaSource::onWrite(pkt,key_pos);
}
@@ -95,7 +103,7 @@ public:
*/
void setProtocolTranslation(bool enableRtsp, bool enableHls, bool enableMP4) {
//不重复生成rtmp
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), 0, enableRtsp, false, enableHls, enableMP4);
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), enableRtsp, false, enableHls, enableMP4);
_muxer->setListener(getListener());
_muxer->setTrackListener(this);
}