mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-28 21:52:22 +08:00
整理命名空间 (#1409)
* feat: remove using namespace mediakit in header files. (cherry picked from commit d44aeb339a8a0e1f0455be82b21fe4b1b536299f) * feat: remove using namespace mediakit in FFmpegSource.h * feat: remove using namespace mediakit in RtpExt.h * feat: remove using namespace mediakit in header files. * feat: remove using namespace std in header files. * feat: remove using namespace std in header files when zltoolkit remove std in header * 补充命名空间 * 整理命名空间 * 整理命名空间2 * 修复macos ci * 修复编译问题 * 修复编译问题2 * 修复编译问题3 Co-authored-by: Johnny <hellojinqiang@gmail.com> Co-authored-by: Xiaofeng Wang <wasphin@gmail.com>
This commit is contained in:
@@ -14,6 +14,9 @@
|
||||
|
||||
#define FILE_BUF_SIZE (64 * 1024)
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
FlvMuxer::FlvMuxer(){
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "Rtmp/RtmpMediaSource.h"
|
||||
#include "Network/Socket.h"
|
||||
#include "Common/Stamp.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -28,8 +27,8 @@ public:
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
void start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media, uint32_t start_pts = 0);
|
||||
virtual void onWrite(const Buffer::Ptr &data, bool flush) = 0;
|
||||
void start(const toolkit::EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media, uint32_t start_pts = 0);
|
||||
virtual void onWrite(const toolkit::Buffer::Ptr &data, bool flush) = 0;
|
||||
virtual void onDetach() = 0;
|
||||
virtual std::shared_ptr<FlvMuxer> getSharedPtr() = 0;
|
||||
|
||||
@@ -37,12 +36,12 @@ private:
|
||||
void onWriteFlvHeader(const RtmpMediaSource::Ptr &src);
|
||||
void onWriteRtmp(const RtmpPacket::Ptr &pkt, bool flush);
|
||||
void onWriteFlvTag(const RtmpPacket::Ptr &pkt, uint32_t time_stamp, bool flush);
|
||||
void onWriteFlvTag(uint8_t type, const Buffer::Ptr &buffer, uint32_t time_stamp, bool flush);
|
||||
BufferRaw::Ptr obtainBuffer(const void *data, size_t len);
|
||||
BufferRaw::Ptr obtainBuffer();
|
||||
void onWriteFlvTag(uint8_t type, const toolkit::Buffer::Ptr &buffer, uint32_t time_stamp, bool flush);
|
||||
toolkit::BufferRaw::Ptr obtainBuffer(const void *data, size_t len);
|
||||
toolkit::BufferRaw::Ptr obtainBuffer();
|
||||
|
||||
private:
|
||||
ResourcePool<BufferRaw> _packet_pool;
|
||||
toolkit::ResourcePool<toolkit::BufferRaw> _packet_pool;
|
||||
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
|
||||
};
|
||||
|
||||
@@ -52,17 +51,17 @@ public:
|
||||
FlvRecorder() = default;
|
||||
~FlvRecorder() override = default;
|
||||
|
||||
void startRecord(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media, const string &file_path);
|
||||
void startRecord(const EventPoller::Ptr &poller, const string &vhost, const string &app, const string &stream, const string &file_path);
|
||||
void startRecord(const toolkit::EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media, const std::string &file_path);
|
||||
void startRecord(const toolkit::EventPoller::Ptr &poller, const std::string &vhost, const std::string &app, const std::string &stream, const std::string &file_path);
|
||||
|
||||
private:
|
||||
virtual void onWrite(const Buffer::Ptr &data, bool flush) override ;
|
||||
virtual void onWrite(const toolkit::Buffer::Ptr &data, bool flush) override ;
|
||||
virtual void onDetach() override;
|
||||
virtual std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<FILE> _file;
|
||||
recursive_mutex _file_mtx;
|
||||
std::recursive_mutex _file_mtx;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -49,7 +49,7 @@ AudioMeta::AudioMeta(const AudioTrack::Ptr &audio){
|
||||
uint8_t getAudioRtmpFlags(const Track::Ptr &track){
|
||||
switch (track->getTrackType()){
|
||||
case TrackAudio : {
|
||||
auto audioTrack = dynamic_pointer_cast<AudioTrack>(track);
|
||||
auto audioTrack = std::dynamic_pointer_cast<AudioTrack>(track);
|
||||
if (!audioTrack) {
|
||||
WarnL << "获取AudioTrack失败";
|
||||
return 0;
|
||||
@@ -116,11 +116,11 @@ void Metadata::addTrack(AMFValue &metadata, const Track::Ptr &track) {
|
||||
Metadata::Ptr new_metadata;
|
||||
switch (track->getTrackType()) {
|
||||
case TrackVideo: {
|
||||
new_metadata = std::make_shared<VideoMeta>(dynamic_pointer_cast<VideoTrack>(track));
|
||||
new_metadata = std::make_shared<VideoMeta>(std::dynamic_pointer_cast<VideoTrack>(track));
|
||||
}
|
||||
break;
|
||||
case TrackAudio: {
|
||||
new_metadata = std::make_shared<AudioMeta>(dynamic_pointer_cast<AudioTrack>(track));
|
||||
new_metadata = std::make_shared<AudioMeta>(std::dynamic_pointer_cast<AudioTrack>(track));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include "amf.h"
|
||||
#include "Extension/Track.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#define PACKED __attribute__((packed))
|
||||
#else
|
||||
@@ -175,7 +173,7 @@ public:
|
||||
#pragma pack(pop)
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
class RtmpPacket : public Buffer{
|
||||
class RtmpPacket : public toolkit::Buffer{
|
||||
public:
|
||||
friend class RtmpProtocol;
|
||||
using Ptr = std::shared_ptr<RtmpPacket>;
|
||||
@@ -186,7 +184,7 @@ public:
|
||||
uint32_t stream_index;
|
||||
uint32_t chunk_id;
|
||||
size_t body_size;
|
||||
BufferLikeString buffer;
|
||||
toolkit::BufferLikeString buffer;
|
||||
|
||||
public:
|
||||
static Ptr create();
|
||||
@@ -259,7 +257,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
friend class ResourcePool_l<RtmpPacket>;
|
||||
friend class toolkit::ResourcePool_l<RtmpPacket>;
|
||||
RtmpPacket(){
|
||||
clear();
|
||||
}
|
||||
@@ -276,7 +274,7 @@ private:
|
||||
|
||||
private:
|
||||
//对象个数统计
|
||||
ObjectStatistic<RtmpPacket> _statistic;
|
||||
toolkit::ObjectStatistic<RtmpPacket> _statistic;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -306,7 +304,7 @@ public:
|
||||
|
||||
TitleMeta(float dur_sec = 0,
|
||||
size_t fileSize = 0,
|
||||
const map<string,string> &header = map<string,string>()){
|
||||
const std::map<std::string, std::string> &header = std::map<std::string, std::string>()){
|
||||
_metadata.set("duration", dur_sec);
|
||||
_metadata.set("fileSize", (int)fileSize);
|
||||
_metadata.set("server",kServerName);
|
||||
|
||||
@@ -14,32 +14,29 @@
|
||||
#include "Rtmp/Rtmp.h"
|
||||
#include "Extension/Frame.h"
|
||||
#include "Util/RingBuffer.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
class RtmpRing{
|
||||
class RtmpRing {
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpRing> Ptr;
|
||||
typedef RingBuffer<RtmpPacket::Ptr> RingType;
|
||||
using Ptr = std::shared_ptr<RtmpRing>;
|
||||
using RingType = toolkit::RingBuffer<RtmpPacket::Ptr>;
|
||||
|
||||
RtmpRing() {}
|
||||
virtual ~RtmpRing() {}
|
||||
RtmpRing() = default;
|
||||
virtual ~RtmpRing() = default;
|
||||
|
||||
/**
|
||||
* 获取rtmp环形缓存
|
||||
* @return
|
||||
*/
|
||||
virtual RingType::Ptr getRtmpRing() const {
|
||||
return _rtmpRing;
|
||||
return _ring;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置rtmp环形缓存
|
||||
* @param ring
|
||||
*/
|
||||
virtual void setRtmpRing(const RingType::Ptr &ring) {
|
||||
_rtmpRing = ring;
|
||||
_ring = ring;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,13 +44,13 @@ public:
|
||||
* @param rtmp rtmp包
|
||||
*/
|
||||
virtual void inputRtmp(const RtmpPacket::Ptr &rtmp) {
|
||||
if (_rtmpRing) {
|
||||
_rtmpRing->write(rtmp, rtmp->isVideoKeyFrame());
|
||||
if (_ring) {
|
||||
_ring->write(rtmp, rtmp->isVideoKeyFrame());
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
RingType::Ptr _rtmpRing;
|
||||
RingType::Ptr _ring;
|
||||
};
|
||||
|
||||
class RtmpCodec : public RtmpRing, public FrameDispatcher , public CodecInfo{
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "RtmpDemuxer.h"
|
||||
#include "Extension/Factory.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
size_t RtmpDemuxer::trackCount(const AMFValue &metadata) {
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "RtmpCodec.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpDemuxer : public Demuxer {
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include "Util/ResourcePool.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Thread/ThreadPool.h"
|
||||
using namespace toolkit;
|
||||
|
||||
#define RTMP_GOP_SIZE 512
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
/**
|
||||
@@ -40,11 +40,11 @@ namespace mediakit {
|
||||
* 只要生成了这三要素,那么要实现rtmp推流、rtmp服务器就很简单了
|
||||
* rtmp推拉流协议中,先传递metadata,然后传递config帧,然后一直传递普通帧
|
||||
*/
|
||||
class RtmpMediaSource : public MediaSource, public RingDelegate<RtmpPacket::Ptr>, private PacketCache<RtmpPacket>{
|
||||
class RtmpMediaSource : public MediaSource, public toolkit::RingDelegate<RtmpPacket::Ptr>, private PacketCache<RtmpPacket>{
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpMediaSource> Ptr;
|
||||
typedef std::shared_ptr<List<RtmpPacket::Ptr> > RingDataType;
|
||||
typedef RingBuffer<RingDataType> RingType;
|
||||
using Ptr = std::shared_ptr<RtmpMediaSource>;
|
||||
using RingDataType = std::shared_ptr<toolkit::List<RtmpPacket::Ptr> >;
|
||||
using RingType = toolkit::RingBuffer<RingDataType>;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
@@ -53,9 +53,9 @@ public:
|
||||
* @param stream_id 流id
|
||||
* @param ring_size 可以设置固定的环形缓冲大小,0则自适应
|
||||
*/
|
||||
RtmpMediaSource(const string &vhost,
|
||||
const string &app,
|
||||
const string &stream_id,
|
||||
RtmpMediaSource(const std::string &vhost,
|
||||
const std::string &app,
|
||||
const std::string &stream_id,
|
||||
int ring_size = RTMP_GOP_SIZE) :
|
||||
MediaSource(RTMP_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
* 获取metadata
|
||||
*/
|
||||
const AMFValue &getMetaData() const {
|
||||
lock_guard<recursive_mutex> lock(_mtx);
|
||||
std::lock_guard<std::recursive_mutex> lock(_mtx);
|
||||
return _metadata;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
*/
|
||||
template<typename FUNC>
|
||||
void getConfigFrame(const FUNC &f) {
|
||||
lock_guard<recursive_mutex> lock(_mtx);
|
||||
std::lock_guard<std::recursive_mutex> lock(_mtx);
|
||||
for (auto &pr : _config_frame_map) {
|
||||
f(pr.second);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
* 更新metadata
|
||||
*/
|
||||
void updateMetaData(const AMFValue &metadata) {
|
||||
lock_guard<recursive_mutex> lock(_mtx);
|
||||
std::lock_guard<std::recursive_mutex> lock(_mtx);
|
||||
_metadata = metadata;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
}
|
||||
|
||||
if (pkt->isCfgFrame()) {
|
||||
lock_guard<recursive_mutex> lock(_mtx);
|
||||
std::lock_guard<std::recursive_mutex> lock(_mtx);
|
||||
_config_frame_map[pkt->type_id] = pkt;
|
||||
if (!_ring) {
|
||||
//注册后收到config帧更新到各播放器
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
}
|
||||
|
||||
if (!_ring) {
|
||||
weak_ptr<RtmpMediaSource> weakSelf = dynamic_pointer_cast<RtmpMediaSource>(shared_from_this());
|
||||
std::weak_ptr<RtmpMediaSource> weakSelf = std::dynamic_pointer_cast<RtmpMediaSource>(shared_from_this());
|
||||
auto lam = [weakSelf](int size) {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
@@ -203,7 +203,7 @@ private:
|
||||
* @param rtmp_list rtmp包列表
|
||||
* @param key_pos 是否包含关键帧
|
||||
*/
|
||||
void onFlush(std::shared_ptr<List<RtmpPacket::Ptr> > rtmp_list, bool key_pos) override {
|
||||
void onFlush(std::shared_ptr<toolkit::List<RtmpPacket::Ptr> > rtmp_list, bool key_pos) override {
|
||||
//如果不存在视频,那么就没有存在GOP缓存的意义,所以is_key一直为true确保一直清空GOP缓存
|
||||
_ring->write(std::move(rtmp_list), _have_video ? key_pos : true);
|
||||
}
|
||||
@@ -216,8 +216,8 @@ private:
|
||||
AMFValue _metadata;
|
||||
RingType::Ptr _ring;
|
||||
|
||||
mutable recursive_mutex _mtx;
|
||||
unordered_map<int, RtmpPacket::Ptr> _config_frame_map;
|
||||
mutable std::recursive_mutex _mtx;
|
||||
std::unordered_map<int, RtmpPacket::Ptr> _config_frame_map;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
#include "RtmpMediaSource.h"
|
||||
#include "RtmpDemuxer.h"
|
||||
#include "Common/MultiMediaSourceMuxer.h"
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpMediaSourceImp: public RtmpMediaSource, private TrackListener, public MultiMediaSourceMuxer::Listener {
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpMediaSourceImp> Ptr;
|
||||
@@ -38,7 +37,7 @@ public:
|
||||
* @param id 流id
|
||||
* @param ringSize 环形缓存大小
|
||||
*/
|
||||
RtmpMediaSourceImp(const string &vhost, const string &app, const string &id, int ringSize = RTMP_GOP_SIZE) : RtmpMediaSource(vhost, app, id, ringSize) {
|
||||
RtmpMediaSourceImp(const std::string &vhost, const std::string &app, const std::string &id, int ringSize = RTMP_GOP_SIZE) : RtmpMediaSource(vhost, app, id, ringSize) {
|
||||
_demuxer = std::make_shared<RtmpDemuxer>();
|
||||
_demuxer->setTrackListener(this);
|
||||
}
|
||||
@@ -84,7 +83,7 @@ public:
|
||||
//不重复生成rtmp
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), true, false, enableHls, enableMP4);
|
||||
_muxer->setMediaListener(getListener());
|
||||
_muxer->setTrackListener(static_pointer_cast<RtmpMediaSourceImp>(shared_from_this()));
|
||||
_muxer->setTrackListener(std::static_pointer_cast<RtmpMediaSourceImp>(shared_from_this()));
|
||||
//让_muxer对象拦截一部分事件(比如说录像相关事件)
|
||||
MediaSource::setListener(_muxer);
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ class RtmpMediaSourceMuxer : public RtmpMuxer, public MediaSourceEventIntercepto
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpMediaSourceMuxer> Ptr;
|
||||
|
||||
RtmpMediaSourceMuxer(const string &vhost,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
RtmpMediaSourceMuxer(const std::string &vhost,
|
||||
const std::string &strApp,
|
||||
const std::string &strId,
|
||||
const TitleMeta::Ptr &title = nullptr) : RtmpMuxer(title){
|
||||
_media_src = std::make_shared<RtmpMediaSource>(vhost, strApp, strId);
|
||||
getRtmpRing()->setDelegate(_media_src);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "Util/onceToken.h"
|
||||
#include "Thread/ThreadPool.h"
|
||||
using namespace toolkit;
|
||||
using namespace mediakit::Client;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -65,12 +65,12 @@ void RtmpPlayer::play(const string &strUrl) {
|
||||
//服务器域名
|
||||
host_url = FindField(host_url.data(), NULL, ":");
|
||||
}
|
||||
if (!(*this)[kNetAdapter].empty()) {
|
||||
setNetAdapter((*this)[kNetAdapter]);
|
||||
if (!(*this)[Client::kNetAdapter].empty()) {
|
||||
setNetAdapter((*this)[Client::kNetAdapter]);
|
||||
}
|
||||
|
||||
weak_ptr<RtmpPlayer> weak_self = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
float play_timeout_sec = (*this)[kTimeoutMS].as<int>() / 1000.0f;
|
||||
float play_timeout_sec = (*this)[Client::kTimeoutMS].as<int>() / 1000.0f;
|
||||
_play_timer.reset(new Timer(play_timeout_sec, [weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
@@ -113,7 +113,7 @@ void RtmpPlayer::onPlayResult_l(const SockException &ex, bool handshake_done) {
|
||||
if (!ex) {
|
||||
//播放成功,恢复rtmp接收超时定时器
|
||||
_rtmp_recv_ticker.resetTime();
|
||||
auto timeout_ms = (*this)[kMediaTimeoutMS].as<uint64_t>();
|
||||
auto timeout_ms = (*this)[Client::kMediaTimeoutMS].as<uint64_t>();
|
||||
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
auto lam = [weakSelf, timeout_ms]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
@@ -255,7 +255,7 @@ inline void RtmpPlayer::send_pause(bool pause) {
|
||||
_beat_timer.reset();
|
||||
if (pause) {
|
||||
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
_beat_timer.reset(new Timer((*this)[kBeatIntervalMS].as<int>() / 1000.0f, [weakSelf]() {
|
||||
_beat_timer.reset(new Timer((*this)[Client::kBeatIntervalMS].as<int>() / 1000.0f, [weakSelf]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
return false;
|
||||
|
||||
@@ -24,19 +24,16 @@
|
||||
#include "Network/Socket.h"
|
||||
#include "Network/TcpClient.h"
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace mediakit::Client;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
//实现了rtmp播放器协议部分的功能,及数据接收功能
|
||||
class RtmpPlayer : public PlayerBase, public TcpClient, public RtmpProtocol {
|
||||
class RtmpPlayer : public PlayerBase, public toolkit::TcpClient, public RtmpProtocol {
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpPlayer> Ptr;
|
||||
RtmpPlayer(const EventPoller::Ptr &poller);
|
||||
RtmpPlayer(const toolkit::EventPoller::Ptr &poller);
|
||||
~RtmpPlayer() override;
|
||||
|
||||
void play(const string &strUrl) override;
|
||||
void play(const std::string &strUrl) override;
|
||||
void pause(bool bPause) override;
|
||||
void speed(float speed) override;
|
||||
void teardown() override;
|
||||
@@ -50,16 +47,16 @@ protected:
|
||||
protected:
|
||||
void onMediaData_l(RtmpPacket::Ptr chunk_data);
|
||||
//在获取config帧后才触发onPlayResult_l(而不是收到play命令回复),所以此时所有track都初始化完毕了
|
||||
void onPlayResult_l(const SockException &ex, bool handshake_done);
|
||||
void onPlayResult_l(const toolkit::SockException &ex, bool handshake_done);
|
||||
|
||||
//form Tcpclient
|
||||
void onRecv(const Buffer::Ptr &buf) override;
|
||||
void onConnect(const SockException &err) override;
|
||||
void onErr(const SockException &ex) override;
|
||||
void onRecv(const toolkit::Buffer::Ptr &buf) override;
|
||||
void onConnect(const toolkit::SockException &err) override;
|
||||
void onErr(const toolkit::SockException &ex) override;
|
||||
//from RtmpProtocol
|
||||
void onRtmpChunk(RtmpPacket::Ptr chunk_data) override;
|
||||
void onStreamDry(uint32_t stream_index) override;
|
||||
void onSendRawData(Buffer::Ptr buffer) override {
|
||||
void onSendRawData(toolkit::Buffer::Ptr buffer) override {
|
||||
send(std::move(buffer));
|
||||
}
|
||||
|
||||
@@ -82,9 +79,9 @@ protected:
|
||||
void send_pause(bool pause);
|
||||
|
||||
private:
|
||||
string _app;
|
||||
string _stream_id;
|
||||
string _tc_url;
|
||||
std::string _app;
|
||||
std::string _stream_id;
|
||||
std::string _tc_url;
|
||||
|
||||
bool _paused = false;
|
||||
bool _metadata_got = false;
|
||||
@@ -95,18 +92,18 @@ private:
|
||||
uint32_t _seek_ms = 0;
|
||||
uint32_t _fist_stamp[2] = {0, 0};
|
||||
uint32_t _now_stamp[2] = {0, 0};
|
||||
Ticker _now_stamp_ticker[2];
|
||||
deque<function<void(AMFValue &dec)> > _deque_on_status;
|
||||
unordered_map<int, function<void(AMFDecoder &dec)> > _map_on_result;
|
||||
toolkit::Ticker _now_stamp_ticker[2];
|
||||
std::deque<std::function<void(AMFValue &dec)> > _deque_on_status;
|
||||
std::unordered_map<int, std::function<void(AMFDecoder &dec)> > _map_on_result;
|
||||
|
||||
//rtmp接收超时计时器
|
||||
Ticker _rtmp_recv_ticker;
|
||||
toolkit::Ticker _rtmp_recv_ticker;
|
||||
//心跳发送定时器
|
||||
std::shared_ptr<Timer> _beat_timer;
|
||||
std::shared_ptr<toolkit::Timer> _beat_timer;
|
||||
//播放超时定时器
|
||||
std::shared_ptr<Timer> _play_timer;
|
||||
std::shared_ptr<toolkit::Timer> _play_timer;
|
||||
//rtmp接收超时定时器
|
||||
std::shared_ptr<Timer> _rtmp_recv_timer;
|
||||
std::shared_ptr<toolkit::Timer> _rtmp_recv_timer;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include "RtmpDemuxer.h"
|
||||
#include "Poller/Timer.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
using namespace toolkit;
|
||||
using namespace mediakit::Client;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -29,10 +27,10 @@ public:
|
||||
using Ptr = std::shared_ptr<RtmpPlayerImp>;
|
||||
using Super = PlayerImp<RtmpPlayer,PlayerBase>;
|
||||
|
||||
RtmpPlayerImp(const EventPoller::Ptr &poller) : Super(poller) {};
|
||||
RtmpPlayerImp(const toolkit::EventPoller::Ptr &poller) : Super(poller) {};
|
||||
|
||||
~RtmpPlayerImp() override {
|
||||
DebugL << endl;
|
||||
DebugL << std::endl;
|
||||
}
|
||||
|
||||
float getProgress() const override {
|
||||
@@ -56,7 +54,7 @@ public:
|
||||
return _demuxer ? _demuxer->getDuration() : 0;
|
||||
}
|
||||
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override {
|
||||
std::vector<Track::Ptr> getTracks(bool ready = true) const override {
|
||||
return _demuxer ? _demuxer->getTracks(ready) : Super::getTracks(ready);
|
||||
}
|
||||
|
||||
@@ -80,7 +78,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void onPlayResult(const SockException &ex) override {
|
||||
void onPlayResult(const toolkit::SockException &ex) override {
|
||||
if (!_wait_track_ready || ex) {
|
||||
Super::onPlayResult(ex);
|
||||
return;
|
||||
@@ -91,13 +89,13 @@ private:
|
||||
|
||||
void addTrackCompleted() override {
|
||||
if (_wait_track_ready) {
|
||||
Super::onPlayResult(SockException(Err_success, "play success"));
|
||||
Super::onPlayResult(toolkit::SockException(toolkit::Err_success, "play success"));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void onCheckMeta_l(const AMFValue &val) {
|
||||
_rtmp_src = dynamic_pointer_cast<RtmpMediaSource>(_media_src);
|
||||
_rtmp_src = std::dynamic_pointer_cast<RtmpMediaSource>(_media_src);
|
||||
if (_rtmp_src) {
|
||||
_rtmp_src->setMetaData(val);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "Rtmp/utils.h"
|
||||
#include "RtmpMediaSource.h"
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
#define C1_DIGEST_SIZE 32
|
||||
#define C1_KEY_SIZE 128
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
#include "Util/ResourcePool.h"
|
||||
#include "Http/HttpRequestSplitter.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpProtocol : public HttpRequestSplitter{
|
||||
@@ -35,10 +32,10 @@ public:
|
||||
|
||||
void onParseRtmp(const char *data, size_t size);
|
||||
//作为客户端发送c0c1,等待s0s1s2并且回调
|
||||
void startClientSession(const function<void()> &cb);
|
||||
void startClientSession(const std::function<void()> &cb);
|
||||
|
||||
protected:
|
||||
virtual void onSendRawData(Buffer::Ptr buffer) = 0;
|
||||
virtual void onSendRawData(toolkit::Buffer::Ptr buffer) = 0;
|
||||
virtual void onRtmpChunk(RtmpPacket::Ptr chunk_data) = 0;
|
||||
virtual void onStreamBegin(uint32_t stream_index){
|
||||
_stream_index = stream_index;
|
||||
@@ -61,25 +58,25 @@ protected:
|
||||
void sendPingResponse(uint32_t time_stamp = ::time(NULL));
|
||||
void sendSetBufferLength(uint32_t stream_index, uint32_t len);
|
||||
void sendUserControl(uint16_t event_type, uint32_t event_data);
|
||||
void sendUserControl(uint16_t event_type, const string &event_data);
|
||||
void sendInvoke(const string &cmd, const AMFValue &val);
|
||||
void sendRequest(int cmd, const string &str);
|
||||
void sendResponse(int type, const string &str);
|
||||
void sendUserControl(uint16_t event_type, const std::string &event_data);
|
||||
void sendInvoke(const std::string &cmd, const AMFValue &val);
|
||||
void sendRequest(int cmd, const std::string &str);
|
||||
void sendResponse(int type, const std::string &str);
|
||||
void sendRtmp(uint8_t type, uint32_t stream_index, const std::string &buffer, uint32_t stamp, int chunk_id);
|
||||
void sendRtmp(uint8_t type, uint32_t stream_index, const Buffer::Ptr &buffer, uint32_t stamp, int chunk_id);
|
||||
BufferRaw::Ptr obtainBuffer(const void *data = nullptr, size_t len = 0);
|
||||
void sendRtmp(uint8_t type, uint32_t stream_index, const toolkit::Buffer::Ptr &buffer, uint32_t stamp, int chunk_id);
|
||||
toolkit::BufferRaw::Ptr obtainBuffer(const void *data = nullptr, size_t len = 0);
|
||||
|
||||
private:
|
||||
void handle_C1_simple(const char *data);
|
||||
#ifdef ENABLE_OPENSSL
|
||||
void handle_C1_complex(const char *data);
|
||||
string get_C1_digest(const uint8_t *ptr,char **digestPos);
|
||||
string get_C1_key(const uint8_t *ptr);
|
||||
void check_C1_Digest(const string &digest,const string &data);
|
||||
void send_complex_S0S1S2(int schemeType,const string &digest);
|
||||
std::string get_C1_digest(const uint8_t *ptr,char **digestPos);
|
||||
std::string get_C1_key(const uint8_t *ptr);
|
||||
void check_C1_Digest(const std::string &digest,const std::string &data);
|
||||
void send_complex_S0S1S2(int schemeType,const std::string &digest);
|
||||
#endif //ENABLE_OPENSSL
|
||||
|
||||
const char* handle_S0S1S2(const char *data, size_t len, const function<void()> &func);
|
||||
const char* handle_S0S1S2(const char *data, size_t len, const std::function<void()> &func);
|
||||
const char* handle_C0C1(const char *data, size_t len);
|
||||
const char* handle_C2(const char *data, size_t len);
|
||||
const char* handle_rtmp(const char *data, size_t len);
|
||||
@@ -104,11 +101,11 @@ private:
|
||||
uint32_t _bandwidth = 2500000;
|
||||
uint8_t _band_limit_type = 2;
|
||||
//////////Rtmp parser//////////
|
||||
function<const char * (const char *data, size_t len)> _next_step_func;
|
||||
std::function<const char * (const char *data, size_t len)> _next_step_func;
|
||||
////////////Chunk////////////
|
||||
unordered_map<int, std::pair<RtmpPacket::Ptr/*now*/, RtmpPacket::Ptr/*last*/> > _map_chunk_data;
|
||||
std::unordered_map<int, std::pair<RtmpPacket::Ptr/*now*/, RtmpPacket::Ptr/*last*/> > _map_chunk_data;
|
||||
//循环池
|
||||
ResourcePool<BufferRaw> _packet_pool;
|
||||
toolkit::ResourcePool<toolkit::BufferRaw> _packet_pool;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
#include "Util/util.h"
|
||||
#include "Util/onceToken.h"
|
||||
#include "Thread/ThreadPool.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit::Client;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -83,7 +84,7 @@ void RtmpPusher::publish(const string &url) {
|
||||
}
|
||||
|
||||
weak_ptr<RtmpPusher> weakSelf = dynamic_pointer_cast<RtmpPusher>(shared_from_this());
|
||||
float publishTimeOutSec = (*this)[kTimeoutMS].as<int>() / 1000.0f;
|
||||
float publishTimeOutSec = (*this)[Client::kTimeoutMS].as<int>() / 1000.0f;
|
||||
_publish_timer.reset(new Timer(publishTimeOutSec, [weakSelf]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
@@ -93,8 +94,8 @@ void RtmpPusher::publish(const string &url) {
|
||||
return false;
|
||||
}, getPoller()));
|
||||
|
||||
if (!(*this)[kNetAdapter].empty()) {
|
||||
setNetAdapter((*this)[kNetAdapter]);
|
||||
if (!(*this)[Client::kNetAdapter].empty()) {
|
||||
setNetAdapter((*this)[Client::kNetAdapter]);
|
||||
}
|
||||
|
||||
startConnect(host_url, iPort);
|
||||
|
||||
@@ -18,29 +18,29 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpPusher : public RtmpProtocol, public TcpClient, public PusherBase {
|
||||
class RtmpPusher : public RtmpProtocol, public toolkit::TcpClient, public PusherBase {
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpPusher> Ptr;
|
||||
RtmpPusher(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &src);
|
||||
RtmpPusher(const toolkit::EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &src);
|
||||
~RtmpPusher() override;
|
||||
|
||||
void publish(const string &url) override ;
|
||||
void publish(const std::string &url) override ;
|
||||
void teardown() override;
|
||||
|
||||
protected:
|
||||
//for Tcpclient override
|
||||
void onRecv(const Buffer::Ptr &buf) override;
|
||||
void onConnect(const SockException &err) override;
|
||||
void onErr(const SockException &ex) override;
|
||||
void onRecv(const toolkit::Buffer::Ptr &buf) override;
|
||||
void onConnect(const toolkit::SockException &err) override;
|
||||
void onErr(const toolkit::SockException &ex) override;
|
||||
|
||||
//for RtmpProtocol override
|
||||
void onRtmpChunk(RtmpPacket::Ptr chunk_data) override;
|
||||
void onSendRawData(Buffer::Ptr buffer) override{
|
||||
void onSendRawData(toolkit::Buffer::Ptr buffer) override{
|
||||
send(std::move(buffer));
|
||||
}
|
||||
|
||||
private:
|
||||
void onPublishResult_l(const SockException &ex, bool handshake_done);
|
||||
void onPublishResult_l(const toolkit::SockException &ex, bool handshake_done);
|
||||
|
||||
template<typename FUN>
|
||||
inline void addOnResultCB(const FUN &fun) {
|
||||
@@ -62,14 +62,14 @@ private:
|
||||
void setSocketFlags();
|
||||
|
||||
private:
|
||||
string _app;
|
||||
string _stream_id;
|
||||
string _tc_url;
|
||||
deque<function<void(AMFValue &dec)> > _deque_on_status;
|
||||
unordered_map<int, function<void(AMFDecoder &dec)> > _map_on_result;
|
||||
std::string _app;
|
||||
std::string _stream_id;
|
||||
std::string _tc_url;
|
||||
std::deque<std::function<void(AMFValue &dec)> > _deque_on_status;
|
||||
std::unordered_map<int, std::function<void(AMFDecoder &dec)> > _map_on_result;
|
||||
|
||||
//推流超时定时器
|
||||
std::shared_ptr<Timer> _publish_timer;
|
||||
std::shared_ptr<toolkit::Timer> _publish_timer;
|
||||
std::weak_ptr<RtmpMediaSource> _publish_src;
|
||||
RtmpMediaSource::RingType::RingReader::Ptr _rtmp_reader;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "RtmpSession.h"
|
||||
#include "Common/config.h"
|
||||
#include "Util/onceToken.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
RtmpSession::RtmpSession(const Socket::Ptr &sock) : TcpSession(sock) {
|
||||
|
||||
@@ -23,18 +23,17 @@
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Common/Stamp.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpSession: public TcpSession ,public RtmpProtocol , public MediaSourceEvent{
|
||||
class RtmpSession : public toolkit::TcpSession, public RtmpProtocol, public MediaSourceEvent {
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpSession> Ptr;
|
||||
RtmpSession(const Socket::Ptr &sock);
|
||||
using Ptr = std::shared_ptr<RtmpSession>;
|
||||
|
||||
RtmpSession(const toolkit::Socket::Ptr &sock);
|
||||
~RtmpSession() override;
|
||||
|
||||
void onRecv(const Buffer::Ptr &buf) override;
|
||||
void onError(const SockException &err) override;
|
||||
void onRecv(const toolkit::Buffer::Ptr &buf) override;
|
||||
void onError(const toolkit::SockException &err) override;
|
||||
void onManager() override;
|
||||
|
||||
private:
|
||||
@@ -48,8 +47,8 @@ private:
|
||||
void onCmd_play(AMFDecoder &dec);
|
||||
void onCmd_play2(AMFDecoder &dec);
|
||||
void doPlay(AMFDecoder &dec);
|
||||
void doPlayResponse(const string &err,const std::function<void(bool)> &cb);
|
||||
void sendPlayResponse(const string &err,const RtmpMediaSource::Ptr &src);
|
||||
void doPlayResponse(const std::string &err,const std::function<void(bool)> &cb);
|
||||
void sendPlayResponse(const std::string &err,const RtmpMediaSource::Ptr &src);
|
||||
|
||||
void onCmd_seek(AMFDecoder &dec);
|
||||
void onCmd_pause(AMFDecoder &dec);
|
||||
@@ -57,7 +56,7 @@ private:
|
||||
void setMetaData(AMFDecoder &dec);
|
||||
|
||||
void onSendMedia(const RtmpPacket::Ptr &pkt);
|
||||
void onSendRawData(Buffer::Ptr buffer) override{
|
||||
void onSendRawData(toolkit::Buffer::Ptr buffer) override{
|
||||
_total_bytes += buffer->size();
|
||||
send(std::move(buffer));
|
||||
}
|
||||
@@ -78,14 +77,14 @@ private:
|
||||
// 获取媒体源类型
|
||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||
// 获取媒体源url或者文件路径
|
||||
string getOriginUrl(MediaSource &sender) const override;
|
||||
std::string getOriginUrl(MediaSource &sender) const override;
|
||||
// 获取媒体源客户端相关信息
|
||||
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
|
||||
void setSocketFlags();
|
||||
string getStreamId(const string &str);
|
||||
std::string getStreamId(const std::string &str);
|
||||
void dumpMetadata(const AMFValue &metadata);
|
||||
void sendStatus(const std::initializer_list<string> &key_value);
|
||||
void sendStatus(const std::initializer_list<std::string> &key_value);
|
||||
|
||||
private:
|
||||
bool _set_meta_data = false;
|
||||
@@ -96,7 +95,7 @@ private:
|
||||
//推流时间戳修整器
|
||||
Stamp _stamp[2];
|
||||
//数据接收超时计时器
|
||||
Ticker _ticker;
|
||||
toolkit::Ticker _ticker;
|
||||
MediaInfo _media_info;
|
||||
std::weak_ptr<RtmpMediaSource> _play_src;
|
||||
AMFValue _push_metadata;
|
||||
@@ -108,7 +107,7 @@ private:
|
||||
/**
|
||||
* 支持ssl加密的rtmp服务器
|
||||
*/
|
||||
typedef TcpSessionWithSSL<RtmpSession> RtmpSessionWithSSL;
|
||||
using RtmpSessionWithSSL = toolkit::TcpSessionWithSSL<RtmpSession>;
|
||||
|
||||
} /* namespace mediakit */
|
||||
#endif /* SRC_RTMP_RTMPSESSION_H_ */
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "Util/logger.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Util/util.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
/////////////////////AMFValue/////////////////////////////
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include "Network/Buffer.h"
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
enum AMFType {
|
||||
AMF_NUMBER,
|
||||
@@ -39,8 +37,9 @@ class AMFValue;
|
||||
class AMFValue {
|
||||
public:
|
||||
friend class AMFEncoder;
|
||||
typedef std::map<std::string, AMFValue> mapType;
|
||||
typedef std::vector<AMFValue> arrayType;
|
||||
|
||||
using mapType = std::map<std::string, AMFValue>;
|
||||
using arrayType = std::vector<AMFValue>;
|
||||
|
||||
~AMFValue();
|
||||
AMFValue(AMFType type = AMF_NULL);
|
||||
@@ -58,17 +57,19 @@ public:
|
||||
double as_number() const;
|
||||
int as_integer() const;
|
||||
bool as_boolean() const;
|
||||
string to_string() const;
|
||||
std::string to_string() const;
|
||||
const AMFValue &operator[](const char *str) const;
|
||||
void object_for_each(const function<void(const string &key, const AMFValue &val)> &fun) const ;
|
||||
void object_for_each(const std::function<void(const std::string &key, const AMFValue &val)> &fun) const ;
|
||||
operator bool() const;
|
||||
void set(const std::string &s, const AMFValue &val);
|
||||
void add(const AMFValue &val);
|
||||
|
||||
private:
|
||||
const mapType &getMap() const;
|
||||
const arrayType &getArr() const;
|
||||
void destroy();
|
||||
void init();
|
||||
|
||||
private:
|
||||
AMFType _type;
|
||||
union {
|
||||
@@ -83,9 +84,10 @@ private:
|
||||
|
||||
class AMFDecoder {
|
||||
public:
|
||||
AMFDecoder(const BufferLikeString &buf, size_t pos, int version = 0);
|
||||
AMFDecoder(const toolkit::BufferLikeString &buf, size_t pos, int version = 0);
|
||||
template<typename TP>
|
||||
TP load();
|
||||
|
||||
private:
|
||||
std::string load_key();
|
||||
AMFValue load_object();
|
||||
@@ -93,8 +95,9 @@ private:
|
||||
AMFValue load_arr();
|
||||
uint8_t front();
|
||||
uint8_t pop_front();
|
||||
|
||||
private:
|
||||
const BufferLikeString &buf;
|
||||
const toolkit::BufferLikeString &buf;
|
||||
size_t pos;
|
||||
int version;
|
||||
};
|
||||
@@ -110,9 +113,11 @@ public:
|
||||
AMFEncoder & operator <<(const AMFValue &value);
|
||||
const std::string& data() const ;
|
||||
void clear() ;
|
||||
|
||||
private:
|
||||
void write_key(const std::string &s);
|
||||
AMFEncoder &write_undefined();
|
||||
|
||||
private:
|
||||
std::string buf;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <stdarg.h>
|
||||
#include "Util/util.h"
|
||||
#include "Network/sockutil.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user