2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
2019-05-08 15:40:07 +08:00
|
|
|
|
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2018-08-30 19:29:54 +08:00
|
|
|
|
|
2018-10-24 18:16:08 +08:00
|
|
|
|
#ifndef ZLMEDIAKIT_FLVMUXER_H
|
|
|
|
|
#define ZLMEDIAKIT_FLVMUXER_H
|
2018-08-30 19:29:54 +08:00
|
|
|
|
|
2018-10-24 18:09:54 +08:00
|
|
|
|
#include "Rtmp/Rtmp.h"
|
|
|
|
|
#include "Rtmp/RtmpMediaSource.h"
|
2018-08-30 19:29:54 +08:00
|
|
|
|
#include "Network/Socket.h"
|
2019-08-27 11:34:50 +08:00
|
|
|
|
#include "MediaFile/Stamp.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:
|
2019-03-21 22:28:12 +08:00
|
|
|
|
void start(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &media);
|
2018-08-30 19:29:54 +08:00
|
|
|
|
virtual void onWrite(const Buffer::Ptr &data) = 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);
|
2019-04-08 15:06:40 +08:00
|
|
|
|
void onWriteFlvTag(uint8_t ui8Type, const Buffer::Ptr &buffer, uint32_t ui32TimeStamp);
|
2018-08-30 19:29:54 +08:00
|
|
|
|
private:
|
|
|
|
|
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
|
2019-08-27 11:34:50 +08:00
|
|
|
|
//时间戳修整器
|
|
|
|
|
Stamp _stamp[2];
|
2019-03-21 22:28:12 +08:00
|
|
|
|
|
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();
|
2019-03-21 22:28:12 +08:00
|
|
|
|
void startRecord(const EventPoller::Ptr &poller,const string &vhost,const string &app,const string &stream,const string &file_path);
|
|
|
|
|
void startRecord(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &media,const string &file_path);
|
2018-08-30 19:29:54 +08:00
|
|
|
|
private:
|
|
|
|
|
virtual void onWrite(const Buffer::Ptr &data) 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
|
|
|
|
|
2018-10-24 18:16:08 +08:00
|
|
|
|
#endif //ZLMEDIAKIT_FLVMUXER_H
|