parent
9e8fe8c86a
commit
453660ab79
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* 开始解复用
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ using namespace std;
|
|||
|
||||
namespace mediakit {
|
||||
|
||||
RtspDemuxer::RtspDemuxer(const string& sdp) {
|
||||
void RtspDemuxer::loadSdp(const string &sdp){
|
||||
loadSdp(SdpParser(sdp));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,13 @@ namespace mediakit {
|
|||
class RtspDemuxer : public Demuxer{
|
||||
public:
|
||||
typedef std::shared_ptr<RtspDemuxer> Ptr;
|
||||
RtspDemuxer(const string &sdp);
|
||||
virtual ~RtspDemuxer(){};
|
||||
RtspDemuxer() = default;
|
||||
virtual ~RtspDemuxer() = default;
|
||||
|
||||
/**
|
||||
* 加载sdp
|
||||
*/
|
||||
void loadSdp(const string &sdp);
|
||||
|
||||
/**
|
||||
* 开始解复用
|
||||
|
|
|
|||
|
|
@ -45,15 +45,18 @@ public:
|
|||
* @param id 流id
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* 设置sdp
|
||||
*/
|
||||
void setSdp(const string &strSdp) override {
|
||||
_demuxer = std::make_shared<RtspDemuxer>(strSdp);
|
||||
_demuxer->setTrackListener(this);
|
||||
_demuxer->loadSdp(strSdp);
|
||||
RtspMediaSource::setSdp(strSdp);
|
||||
}
|
||||
|
||||
|
|
@ -61,9 +64,7 @@ public:
|
|||
* 输入rtp并解析
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +94,7 @@ public:
|
|||
*/
|
||||
void setProtocolTranslation(bool enableRtmp,bool enableHls,bool enableMP4){
|
||||
//不重复生成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->setTrackListener(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ private:
|
|||
if(_pRtspMediaSrc){
|
||||
_pRtspMediaSrc->setSdp(sdp);
|
||||
}
|
||||
_delegate.reset(new RtspDemuxer(sdp));
|
||||
_delegate.reset(new RtspDemuxer);
|
||||
_delegate->loadSdp(sdp);
|
||||
return true;
|
||||
}
|
||||
void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) override {
|
||||
|
|
|
|||
Loading…
Reference in New Issue