2018-09-20 15:43:49 +08:00
|
|
|
|
//
|
2018-08-30 19:29:54 +08:00
|
|
|
|
// Created by xzl on 2018/8/30.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_FLVRECORDER_H
|
|
|
|
|
#define ZLMEDIAKIT_FLVRECORDER_H
|
|
|
|
|
|
|
|
|
|
#include "Rtmp.h"
|
|
|
|
|
#include "RtmpMediaSource.h"
|
|
|
|
|
#include "Network/Socket.h"
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
2018-08-30 19:29:54 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit {
|
2018-08-30 19:29:54 +08:00
|
|
|
|
|
|
|
|
|
class FlvMuxer{
|
|
|
|
|
public:
|
2018-08-31 14:13:00 +08:00
|
|
|
|
typedef std::shared_ptr<FlvMuxer> Ptr;
|
2018-08-30 19:29:54 +08:00
|
|
|
|
FlvMuxer();
|
|
|
|
|
virtual ~FlvMuxer();
|
|
|
|
|
void stop();
|
|
|
|
|
protected:
|
|
|
|
|
void start(const RtmpMediaSource::Ptr &media);
|
|
|
|
|
virtual void onWrite(const Buffer::Ptr &data) = 0;
|
|
|
|
|
virtual void onWrite(const char *data,int len) = 0;
|
|
|
|
|
virtual void onDetach() = 0;
|
|
|
|
|
virtual std::shared_ptr<FlvMuxer> getSharedPtr() = 0;
|
|
|
|
|
private:
|
|
|
|
|
void onWriteFlvHeader(const RtmpMediaSource::Ptr &media);
|
|
|
|
|
void onWriteRtmp(const RtmpPacket::Ptr &pkt);
|
|
|
|
|
void onWriteFlvTag(const RtmpPacket::Ptr &pkt, uint32_t ui32TimeStamp);
|
|
|
|
|
void onWriteFlvTag(uint8_t ui8Type, const std::string &strBuf, uint32_t ui32TimeStamp);
|
|
|
|
|
private:
|
|
|
|
|
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
|
2018-10-24 15:43:52 +08:00
|
|
|
|
uint32_t _aui32FirstStamp[2] = {0};
|
|
|
|
|
uint32_t _previousTagSize = 0;
|
2018-08-30 19:29:54 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FlvRecorder : public FlvMuxer , public std::enable_shared_from_this<FlvRecorder>{
|
|
|
|
|
public:
|
2018-08-31 14:13:00 +08:00
|
|
|
|
typedef std::shared_ptr<FlvRecorder> Ptr;
|
2018-08-30 19:29:54 +08:00
|
|
|
|
FlvRecorder();
|
|
|
|
|
virtual ~FlvRecorder();
|
|
|
|
|
void startRecord(const string &vhost,const string &app,const string &stream,const string &file_path);
|
|
|
|
|
void startRecord(const RtmpMediaSource::Ptr &media,const string &file_path);
|
|
|
|
|
private:
|
|
|
|
|
virtual void onWrite(const Buffer::Ptr &data) override ;
|
|
|
|
|
virtual void onWrite(const char *data,int len) override;
|
|
|
|
|
virtual void onDetach() override;
|
|
|
|
|
virtual std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
|
|
|
|
private:
|
|
|
|
|
std::shared_ptr<FILE> _file;
|
|
|
|
|
recursive_mutex _file_mtx;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
}//namespace mediakit
|
2018-08-30 19:29:54 +08:00
|
|
|
|
|
|
|
|
|
#endif //ZLMEDIAKIT_FLVRECORDER_H
|