修改文件录制、hls生成、拉流代理逻辑

This commit is contained in:
xiongziliang
2018-02-07 11:16:43 +08:00
parent ae1b62c78f
commit 5ed2ce40fe
14 changed files with 160 additions and 133 deletions

View File

@@ -36,8 +36,12 @@ using namespace ZL::Network;
namespace ZL {
namespace Rtmp {
RtmpToRtspMediaSource::RtmpToRtspMediaSource(const string &vhost,const string &app, const string &id) :
RtmpMediaSource(vhost,app,id) {
RtmpToRtspMediaSource::RtmpToRtspMediaSource(const string &vhost,
const string &app,
const string &id,
bool bEnableHls,
bool bEnableMp4) :
RtmpMediaSource(vhost,app,id),m_bEnableHls(bEnableHls),m_bEnableMp4(bEnableMp4) {
}
RtmpToRtspMediaSource::~RtmpToRtspMediaSource() {}
@@ -56,14 +60,18 @@ bool RtmpToRtspMediaSource::unregist() {
}
void RtmpToRtspMediaSource::onGetH264(const H264Frame &frame) {
m_pRecorder->inputH264((char *) frame.data.data(), frame.data.size(), frame.timeStamp, frame.type);
if(m_pRecorder){
m_pRecorder->inputH264((char *) frame.data.data(), frame.data.size(), frame.timeStamp, frame.type);
}
if(m_pRtpMaker_h264){
m_pRtpMaker_h264->makeRtp(frame.data.data() + 4, frame.data.size() - 4, frame.timeStamp);
}
}
inline void RtmpToRtspMediaSource::onGetAdts(const AdtsFrame &frame) {
m_pRecorder->inputAAC((char *) frame.data, frame.aac_frame_length, frame.timeStamp);
if(m_pRecorder){
m_pRecorder->inputAAC((char *) frame.data, frame.aac_frame_length, frame.timeStamp);
}
if (m_pRtpMaker_aac) {
m_pRtpMaker_aac->makeRtp((char *) frame.data + 7, frame.aac_frame_length - 7, frame.timeStamp);

View File

@@ -56,7 +56,11 @@ class RtmpToRtspMediaSource: public RtmpMediaSource {
public:
typedef std::shared_ptr<RtmpToRtspMediaSource> Ptr;
RtmpToRtspMediaSource(const string &vhost,const string &app, const string &id);
RtmpToRtspMediaSource(const string &vhost,
const string &app,
const string &id,
bool bEnableHls = true,
bool bEnableMp4 = false);
virtual ~RtmpToRtspMediaSource();
bool regist() override;
@@ -65,7 +69,7 @@ public:
void onGetMetaData(const AMFValue &_metadata) override {
try {
m_pParser.reset(new RtmpParser(_metadata));
m_pRecorder.reset(new MediaRecorder(getVhost(),getApp(),getId(),m_pParser));
m_pRecorder.reset(new MediaRecorder(getVhost(),getApp(),getId(),m_pParser,m_bEnableHls,m_bEnableMp4));
m_pParser->setOnAudioCB(std::bind(&RtmpToRtspMediaSource::onGetAdts, this, placeholders::_1));
m_pParser->setOnVideoCB(std::bind(&RtmpToRtspMediaSource::onGetH264, this, placeholders::_1));
} catch (exception &ex) {
@@ -90,7 +94,8 @@ private:
RtpMaker_AAC::Ptr m_pRtpMaker_aac;
RtpMaker_H264::Ptr m_pRtpMaker_h264;
MediaRecorder::Ptr m_pRecorder;
bool m_bEnableHls;
bool m_bEnableMp4;
void onGetH264(const H264Frame &frame);
void onGetAdts(const AdtsFrame &frame);
void makeSDP();