完成MediaSource生成器

This commit is contained in:
xiongziliang 2018-10-25 16:46:00 +08:00
parent 84dbe5597d
commit 1ff490d119
8 changed files with 161 additions and 21 deletions

@ -1 +1 @@
Subproject commit 6e69a082a2f6e6161785b00c7421bf1a811ed34a Subproject commit 3a9c916454897ad02c6ee4cba89f5e370718cd91

View File

@ -0,0 +1,68 @@
/*
* MIT License
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ZLMEDIAKIT_MULTIMEDIASOURCEMUXER_H
#define ZLMEDIAKIT_MULTIMEDIASOURCEMUXER_H
#include "RtspMuxer/RtspMediaSourceMuxer.h"
#include "RtmpMuxer/RtmpMediaSourceMuxer.h"
class MultiMediaSourceMuxer {
public:
MultiMediaSourceMuxer(const string &vhost,
const string &strApp,
const string &strId,
float dur_sec = 0.0){
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost,strApp,strId,std::make_shared<TitleMete>(dur_sec));
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost,strApp,strId,std::make_shared<TitleSdp>(dur_sec));
}
virtual ~MultiMediaSourceMuxer(){}
/**
*
* @param track
*/
void addTrack(const Track::Ptr & track,int mtu = 1400) {
_rtmp->addTrack(track);
_rtsp->addTrack(track,0,mtu);
}
/**
* rtmp
* @param frame
*/
void inputFrame(const Frame::Ptr &frame) {
_rtmp->inputFrame(frame);
_rtsp->inputFrame(frame);
}
private:
RtmpMediaSourceMuxer::Ptr _rtmp;
RtspMediaSourceMuxer::Ptr _rtsp;
};
#endif //ZLMEDIAKIT_MULTIMEDIASOURCEMUXER_H

View File

@ -48,7 +48,7 @@ using namespace toolkit;
namespace mediakit { namespace mediakit {
class RtmpMediaSource: public MediaSource { class RtmpMediaSource: public MediaSource ,public RingDelegate<RtmpPacket::Ptr> {
public: public:
typedef std::shared_ptr<RtmpMediaSource> Ptr; typedef std::shared_ptr<RtmpMediaSource> Ptr;
typedef RingBuffer<RtmpPacket::Ptr> RingType; typedef RingBuffer<RtmpPacket::Ptr> RingType;
@ -107,6 +107,10 @@ private:
lock_guard<recursive_mutex> lock(_mtxMap); lock_guard<recursive_mutex> lock(_mtxMap);
return _iCfgFrameSize != -1 && _iCfgFrameSize == _mapCfgFrame.size(); return _iCfgFrameSize != -1 && _iCfgFrameSize == _mapCfgFrame.size();
} }
void onWrite(const RtmpPacket::Ptr &pkt,bool isKey = true) override {
onGetMedia(pkt);
}
protected: protected:
AMFValue _metadata; AMFValue _metadata;
unordered_map<int, RtmpPacket::Ptr> _mapCfgFrame; unordered_map<int, RtmpPacket::Ptr> _mapCfgFrame;

View File

@ -24,7 +24,43 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include "MediaSourceMaker.h" #ifndef ZLMEDIAKIT_RTMPMEDIASOURCEMUXER_H
namespace mediakit{ #define ZLMEDIAKIT_RTMPMEDIASOURCEMUXER_H
} #include "RtmpMuxer/RtmpMuxer.h"
#include "Rtmp/RtmpMediaSource.h"
namespace mediakit {
class RtmpMediaSourceMuxer : public RtmpMuxer {
public:
typedef std::shared_ptr<RtmpMediaSourceMuxer> Ptr;
RtmpMediaSourceMuxer(const string &vhost,
const string &strApp,
const string &strId,
const TitleMete::Ptr &title = nullptr) : RtmpMuxer(title){
_mediaSouce = std::make_shared<RtmpMediaSource>(vhost,strApp,strId);
getRtmpRing()->setDelegate(_mediaSouce);
}
virtual ~RtmpMediaSourceMuxer(){}
void setListener(const std::weak_ptr<MediaSourceEvent> &listener){
_mediaSouce->setListener(listener);
}
private:
void onInited() override {
_mediaSouce->onGetMetaData(getMetedata());
}
private:
RtmpMediaSource::Ptr _mediaSouce;
};
}//namespace mediakit
#endif //ZLMEDIAKIT_RTMPMEDIASOURCEMUXER_H

View File

@ -33,11 +33,17 @@ namespace mediakit{
class RtmpMuxer{ class RtmpMuxer{
public: public:
typedef std::shared_ptr<RtmpMuxer> Ptr;
/** /**
* *
*/ */
RtmpMuxer(const TitleMete::Ptr &title = std::make_shared<TitleMete>()) : _metedata(AMF_OBJECT){ RtmpMuxer(const TitleMete::Ptr &title = nullptr) : _metedata(AMF_OBJECT){
_metedata = title->getMetedata(); if(!title){
_metedata = std::make_shared<TitleMete>()->getMetedata();
}else{
_metedata = title->getMetedata();
}
_rtmpRing = std::make_shared<RtmpRingInterface::RingType>(); _rtmpRing = std::make_shared<RtmpRingInterface::RingType>();
} }
virtual ~RtmpMuxer(){} virtual ~RtmpMuxer(){}

View File

@ -49,7 +49,7 @@ using namespace toolkit;
namespace mediakit { namespace mediakit {
class RtspMediaSource: public MediaSource { class RtspMediaSource: public MediaSource , public RingDelegate<RtpPacket::Ptr> {
public: public:
typedef ResourcePool<RtpPacket> PoolType; typedef ResourcePool<RtpPacket> PoolType;
typedef std::shared_ptr<RtspMediaSource> Ptr; typedef std::shared_ptr<RtspMediaSource> Ptr;
@ -93,6 +93,11 @@ public:
trackRef.type = rtppt->type; trackRef.type = rtppt->type;
_pRing->write(rtppt,keyPos); _pRing->write(rtppt,keyPos);
} }
private:
void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override {
onGetRTP(rtppt,keyPos);
}
protected: protected:
unordered_map<int, RtspTrack> _mapTracks; unordered_map<int, RtspTrack> _mapTracks;
string _strSdp; //媒体描述信息 string _strSdp; //媒体描述信息

View File

@ -24,23 +24,38 @@
* SOFTWARE. * SOFTWARE.
*/ */
#ifndef ZLMEDIAKIT_MEDIASOURCEMAKER_H #ifndef ZLMEDIAKIT_RTSPMEDIASOURCEMUXER_H
#define ZLMEDIAKIT_MEDIASOURCEMAKER_H #define ZLMEDIAKIT_RTSPMEDIASOURCEMUXER_H
#include "Player/Track.h" #include "RtspMuxer/RtspMuxer.h"
#include "Rtsp/RtspMediaSource.h" #include "Rtsp/RtspMediaSource.h"
#include "Rtmp/RtmpMediaSource.h"
namespace mediakit { namespace mediakit {
class MediaSourceMaker { class RtspMediaSourceMuxer : public RtspMuxer {
public: public:
MediaSourceMaker() {} typedef std::shared_ptr<RtspMediaSourceMuxer> Ptr;
virtual ~MediaSourceMaker() {}
RtspMediaSourceMuxer(const string &vhost,
const string &strApp,
const string &strId,
const TitleSdp::Ptr &title = nullptr) : RtspMuxer(title){
_mediaSouce = std::make_shared<RtspMediaSource>(vhost,strApp,strId);
getRtpRing()->setDelegate(_mediaSouce);
}
virtual ~RtspMediaSourceMuxer(){}
void setListener(const std::weak_ptr<MediaSourceEvent> &listener){
_mediaSouce->setListener(listener);
}
private: private:
RtspMediaSource::Ptr _rtspSrc; void onInited() override {
RtmpMediaSource::Ptr _rtmpSrc; _mediaSouce->onGetSDP(getSdp());
}
private:
RtspMediaSource::Ptr _mediaSouce;
}; };
} //namespace mediakit
#endif //ZLMEDIAKIT_MEDIASOURCEMAKER_H }//namespace mediakit
#endif //ZLMEDIAKIT_RTSPMEDIASOURCEMUXER_H

View File

@ -35,11 +35,17 @@ namespace mediakit{
*/ */
class RtspMuxer{ class RtspMuxer{
public: public:
typedef std::shared_ptr<RtspMuxer> Ptr;
/** /**
* *
*/ */
RtspMuxer(const TitleSdp::Ptr &title = std::make_shared<TitleSdp>()){ RtspMuxer(const TitleSdp::Ptr &title = nullptr){
_sdp = title->getSdp(); if(!title){
_sdp = std::make_shared<TitleSdp>()->getSdp();
} else{
_sdp = title->getSdp();
}
_rtpRing = std::make_shared<RtpRingInterface::RingType>(); _rtpRing = std::make_shared<RtpRingInterface::RingType>();
} }
virtual ~RtspMuxer(){} virtual ~RtspMuxer(){}