Commit 453660ab by xiongziliang

整理MediaSource派生类

修复转协议或录制时忽然Track的问题
parent 9e8fe8c8
...@@ -29,6 +29,21 @@ ...@@ -29,6 +29,21 @@
namespace mediakit { 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) { bool RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
switch (pkt->typeId) { switch (pkt->typeId) {
case MSG_VIDEO: { case MSG_VIDEO: {
......
...@@ -43,11 +43,10 @@ class RtmpDemuxer : public Demuxer{ ...@@ -43,11 +43,10 @@ class RtmpDemuxer : public Demuxer{
public: public:
typedef std::shared_ptr<RtmpDemuxer> Ptr; typedef std::shared_ptr<RtmpDemuxer> Ptr;
/** RtmpDemuxer() = default;
* 等效于RtmpDemuxer(AMFValue(AMF_NULL)) virtual ~RtmpDemuxer() = default;
*/
RtmpDemuxer(){} void loadMetaData(const AMFValue &metadata);
virtual ~RtmpDemuxer(){};
/** /**
* 开始解复用 * 开始解复用
......
...@@ -62,10 +62,18 @@ public: ...@@ -62,10 +62,18 @@ public:
~RtmpMediaSourceImp() = default; ~RtmpMediaSourceImp() = default;
/** /**
* 设置metadata
*/
void setMetaData(const AMFValue &metadata) override{
_demuxer->loadMetaData(metadata);
RtmpMediaSource::setMetaData(metadata);
}
/**
* 输入rtmp并解析 * 输入rtmp并解析
*/ */
void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos = true) override { void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos = true) override {
_demuxer->inputRtmp(pkt); key_pos = _demuxer->inputRtmp(pkt);
RtmpMediaSource::onWrite(pkt,key_pos); RtmpMediaSource::onWrite(pkt,key_pos);
} }
...@@ -95,7 +103,7 @@ public: ...@@ -95,7 +103,7 @@ public:
*/ */
void setProtocolTranslation(bool enableRtsp, bool enableHls, bool enableMP4) { void setProtocolTranslation(bool enableRtsp, bool enableHls, bool enableMP4) {
//不重复生成rtmp //不重复生成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->setListener(getListener());
_muxer->setTrackListener(this); _muxer->setTrackListener(this);
} }
......
...@@ -34,7 +34,7 @@ using namespace std; ...@@ -34,7 +34,7 @@ using namespace std;
namespace mediakit { namespace mediakit {
RtspDemuxer::RtspDemuxer(const string& sdp) { void RtspDemuxer::loadSdp(const string &sdp){
loadSdp(SdpParser(sdp)); loadSdp(SdpParser(sdp));
} }
......
...@@ -40,8 +40,13 @@ namespace mediakit { ...@@ -40,8 +40,13 @@ namespace mediakit {
class RtspDemuxer : public Demuxer{ class RtspDemuxer : public Demuxer{
public: public:
typedef std::shared_ptr<RtspDemuxer> Ptr; typedef std::shared_ptr<RtspDemuxer> Ptr;
RtspDemuxer(const string &sdp); RtspDemuxer() = default;
virtual ~RtspDemuxer(){}; virtual ~RtspDemuxer() = default;
/**
* 加载sdp
*/
void loadSdp(const string &sdp);
/** /**
* 开始解复用 * 开始解复用
......
...@@ -45,15 +45,18 @@ public: ...@@ -45,15 +45,18 @@ public:
* @param id 流id * @param id 流id
* @param ringSize 环形缓存大小 * @param ringSize 环形缓存大小
*/ */
RtspMediaSourceImp(const string &vhost, const string &app, const string &id, int ringSize = 0) : RtspMediaSource(vhost, app, id,ringSize) {} RtspMediaSourceImp(const string &vhost, const string &app, const string &id, int ringSize = 0) : RtspMediaSource(vhost, app, id,ringSize) {
_demuxer = std::make_shared<RtspDemuxer>();
_demuxer->setTrackListener(this);
}
~RtspMediaSourceImp() = default; ~RtspMediaSourceImp() = default;
/** /**
* 设置sdp * 设置sdp
*/ */
void setSdp(const string &strSdp) override { void setSdp(const string &strSdp) override {
_demuxer = std::make_shared<RtspDemuxer>(strSdp); _demuxer->loadSdp(strSdp);
_demuxer->setTrackListener(this);
RtspMediaSource::setSdp(strSdp); RtspMediaSource::setSdp(strSdp);
} }
...@@ -61,9 +64,7 @@ public: ...@@ -61,9 +64,7 @@ public:
* 输入rtp并解析 * 输入rtp并解析
*/ */
void onWrite(const RtpPacket::Ptr &rtp, bool key_pos) override { void onWrite(const RtpPacket::Ptr &rtp, bool key_pos) override {
if (_demuxer) {
key_pos = _demuxer->inputRtp(rtp); key_pos = _demuxer->inputRtp(rtp);
}
RtspMediaSource::onWrite(rtp, key_pos); RtspMediaSource::onWrite(rtp, key_pos);
} }
...@@ -93,7 +94,7 @@ public: ...@@ -93,7 +94,7 @@ public:
*/ */
void setProtocolTranslation(bool enableRtmp,bool enableHls,bool enableMP4){ void setProtocolTranslation(bool enableRtmp,bool enableHls,bool enableMP4){
//不重复生成rtsp //不重复生成rtsp
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), 0, false, enableRtmp, enableHls, enableMP4); _muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), false, enableRtmp, enableHls, enableMP4);
_muxer->setListener(getListener()); _muxer->setListener(getListener());
_muxer->setTrackListener(this); _muxer->setTrackListener(this);
} }
......
...@@ -66,7 +66,8 @@ private: ...@@ -66,7 +66,8 @@ private:
if(_pRtspMediaSrc){ if(_pRtspMediaSrc){
_pRtspMediaSrc->setSdp(sdp); _pRtspMediaSrc->setSdp(sdp);
} }
_delegate.reset(new RtspDemuxer(sdp)); _delegate.reset(new RtspDemuxer);
_delegate->loadSdp(sdp);
return true; return true;
} }
void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) override { void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) override {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论