整理命名空间 (#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:
夏楚
2022-02-02 20:34:50 +08:00
committed by GitHub
parent 80a0e27d8c
commit c72cf4cbcc
239 changed files with 1887 additions and 1766 deletions

View File

@@ -21,6 +21,8 @@
#include "mpeg-ts-proto.h"
#endif
using namespace toolkit;
namespace mediakit {
static Decoder::Ptr createDecoder_l(DecoderImp::Type type) {
switch (type){

View File

@@ -16,7 +16,6 @@
#include <functional>
#include "Common/MediaSink.h"
using namespace std;
namespace mediakit {
class Decoder {
@@ -60,7 +59,7 @@ private:
Decoder::Ptr _decoder;
MediaSinkInterface *_sink;
FrameMerger _merger{FrameMerger::none};
Ticker _last_unsported_print;
toolkit::Ticker _last_unsported_print;
Track::Ptr _tracks[TrackMax];
};

View File

@@ -19,10 +19,13 @@
#include "Extension/G711.h"
#include "Extension/H265.h"
namespace mediakit{
using namespace std;
using namespace toolkit;
namespace mediakit {
//判断是否为ts负载
static inline bool checkTS(const uint8_t *packet, size_t bytes){
static inline bool checkTS(const uint8_t *packet, size_t bytes) {
return bytes % TS_PACKET_SIZE == 0 && packet[0] == TS_SYNC_BYTE;
}

View File

@@ -47,8 +47,8 @@ private:
DecoderImp::Ptr _decoder;
MediaSinkInterface *_interface;
std::shared_ptr<FILE> _save_file_ps;
unordered_map<uint8_t, std::shared_ptr<RtpCodec> > _rtp_decoder;
unordered_map<uint8_t, std::shared_ptr<RtpReceiverImp> > _rtp_receiver;
std::unordered_map<uint8_t, std::shared_ptr<RtpCodec> > _rtp_decoder;
std::unordered_map<uint8_t, std::shared_ptr<RtpReceiverImp> > _rtp_receiver;
};
}//namespace mediakit

View File

@@ -9,8 +9,12 @@
*/
#if defined(ENABLE_RTPPROXY)
#include "PSDecoder.h"
#include "mpeg-ps.h"
using namespace toolkit;
namespace mediakit{
PSDecoder::PSDecoder() {

View File

@@ -14,6 +14,8 @@
#include "Extension/H264.h"
#include "Rtsp/RtspMuxer.h"
using namespace toolkit;
namespace mediakit{
PSEncoderImp::PSEncoderImp(uint32_t ssrc, uint8_t payload_type) : MpegMuxer(true) {

View File

@@ -27,10 +27,10 @@ public:
protected:
//rtp打包后回调
virtual void onRTP(Buffer::Ptr rtp) = 0;
virtual void onRTP(toolkit::Buffer::Ptr rtp) = 0;
protected:
void onWrite(std::shared_ptr<Buffer> buffer, uint32_t stamp, bool key_pos) override;
void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint32_t stamp, bool key_pos) override;
private:
std::shared_ptr<CommonRtpEncoder> _rtp_encoder;

View File

@@ -12,6 +12,8 @@
#if defined(ENABLE_RTPPROXY)
using namespace toolkit;
namespace mediakit{
RtpCache::RtpCache(onFlushed cb) {
@@ -27,7 +29,7 @@ void RtpCache::input(uint64_t stamp, Buffer::Ptr buffer) {
}
void RtpCachePS::onRTP(Buffer::Ptr buffer) {
auto rtp = static_pointer_cast<RtpPacket>(buffer);
auto rtp = std::static_pointer_cast<RtpPacket>(buffer);
auto stamp = rtp->getStampMS();
input(stamp, std::move(buffer));
}

View File

@@ -18,9 +18,9 @@
namespace mediakit{
class RtpCache : private PacketCache<Buffer> {
class RtpCache : private PacketCache<toolkit::Buffer> {
public:
using onFlushed = function<void(std::shared_ptr<List<Buffer::Ptr> >)>;
using onFlushed = std::function<void(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> >)>;
RtpCache(onFlushed cb);
~RtpCache() override = default;
@@ -29,10 +29,10 @@ protected:
* 输入rtp(目的是为了合并写)
* @param buffer rtp数据
*/
void input(uint64_t stamp, Buffer::Ptr buffer);
void input(uint64_t stamp, toolkit::Buffer::Ptr buffer);
protected:
void onFlush(std::shared_ptr<List<Buffer::Ptr> > rtp_list, bool) override;
void onFlush(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> > rtp_list, bool) override;
private:
onFlushed _cb;
@@ -44,7 +44,7 @@ public:
~RtpCachePS() override = default;
protected:
void onRTP(Buffer::Ptr rtp) override;
void onRTP(toolkit::Buffer::Ptr rtp) override;
};
}//namespace mediakit

View File

@@ -13,6 +13,9 @@
#include "RtpProcess.h"
#include "Http/HttpTSPlayer.h"
using namespace std;
using namespace toolkit;
static constexpr char kRtpAppName[] = "rtp";
//在创建_muxer对象前(也就是推流鉴权成功前)需要先缓存frame这样可以防止丢包提高体验
//但是同时需要控制缓冲长度防止内存溢出。200帧数据大概有10秒数据应该足矣等待鉴权hook返回

View File

@@ -17,11 +17,11 @@
namespace mediakit {
class RtpProcess : public SockInfo, public MediaSinkInterface, public MediaSourceEventInterceptor, public std::enable_shared_from_this<RtpProcess>{
class RtpProcess : public toolkit::SockInfo, public MediaSinkInterface, public MediaSourceEventInterceptor, public std::enable_shared_from_this<RtpProcess>{
public:
typedef std::shared_ptr<RtpProcess> Ptr;
friend class RtpProcessHelper;
RtpProcess(const string &stream_id);
RtpProcess(const std::string &stream_id);
~RtpProcess();
/**
@@ -34,7 +34,7 @@ public:
* @param dts_out 解析出最新的dts
* @return 是否解析成功
*/
bool inputRtp(bool is_udp, const Socket::Ptr &sock, const char *data, size_t len, const struct sockaddr *addr , uint32_t *dts_out = nullptr);
bool inputRtp(bool is_udp, const toolkit::Socket::Ptr &sock, const char *data, size_t len, const struct sockaddr *addr , uint32_t *dts_out = nullptr);
/**
* 是否超时,用于超时移除对象
@@ -49,7 +49,7 @@ public:
/**
* 设置onDetach事件回调
*/
void setOnDetach(const function<void()> &cb);
void setOnDetach(const std::function<void()> &cb);
/**
* 设置onDetach事件回调,false检查RTP超时true停止
@@ -57,11 +57,11 @@ public:
void setStopCheckRtp(bool is_check=false);
/// SockInfo override
string get_local_ip() override;
std::string get_local_ip() override;
uint16_t get_local_port() override;
string get_peer_ip() override;
std::string get_peer_ip() override;
uint16_t get_peer_port() override;
string getIdentifier() const override;
std::string getIdentifier() const override;
int getTotalReaderCount();
void setListener(const std::weak_ptr<MediaSourceEvent> &listener);
@@ -74,7 +74,7 @@ protected:
//// MediaSourceEvent override ////
MediaOriginType getOriginType(MediaSource &sender) const override;
string getOriginUrl(MediaSource &sender) const override;
std::string getOriginUrl(MediaSource &sender) const override;
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
private:
@@ -85,19 +85,19 @@ private:
uint32_t _dts = 0;
uint64_t _total_bytes = 0;
struct sockaddr _addr{0};
Socket::Ptr _sock;
toolkit::Socket::Ptr _sock;
MediaInfo _media_info;
Ticker _last_frame_time;
function<void()> _on_detach;
toolkit::Ticker _last_frame_time;
std::function<void()> _on_detach;
std::shared_ptr<FILE> _save_file_rtp;
std::shared_ptr<FILE> _save_file_video;
ProcessInterface::Ptr _process;
MultiMediaSourceMuxer::Ptr _muxer;
atomic_bool _stop_rtp_check{false};
atomic_flag _busy_flag{false};
Ticker _last_check_alive;
recursive_mutex _func_mtx;
deque<function<void()> > _cached_func;
std::atomic_bool _stop_rtp_check{false};
std::atomic_flag _busy_flag{false};
toolkit::Ticker _last_check_alive;
std::recursive_mutex _func_mtx;
std::deque<std::function<void()> > _cached_func;
};
}//namespace mediakit

View File

@@ -13,6 +13,9 @@
#include "RtpSelector.h"
#include "RtpSplitter.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
INSTANCE_IMP(RtpSelector);

View File

@@ -24,7 +24,7 @@ class RtpSelector;
class RtpProcessHelper : public MediaSourceEvent , public std::enable_shared_from_this<RtpProcessHelper> {
public:
typedef std::shared_ptr<RtpProcessHelper> Ptr;
RtpProcessHelper(const string &stream_id, const weak_ptr<RtpSelector > &parent);
RtpProcessHelper(const std::string &stream_id, const std::weak_ptr<RtpSelector > &parent);
~RtpProcessHelper();
void attachEvent();
RtpProcess::Ptr & getProcess();
@@ -36,9 +36,9 @@ protected:
int totalReaderCount(MediaSource &sender) override;
private:
weak_ptr<RtpSelector > _parent;
std::weak_ptr<RtpSelector > _parent;
RtpProcess::Ptr _process;
string _stream_id;
std::string _stream_id;
};
class RtpSelector : public std::enable_shared_from_this<RtpSelector>{
@@ -63,7 +63,7 @@ public:
* @param dts_out 解析出最新的dts
* @return 是否成功
*/
bool inputRtp(const Socket::Ptr &sock, const char *data, size_t data_len,
bool inputRtp(const toolkit::Socket::Ptr &sock, const char *data, size_t data_len,
const struct sockaddr *addr, uint32_t *dts_out = nullptr);
/**
@@ -72,23 +72,23 @@ public:
* @param makeNew 不存在时是否新建
* @return rtp处理器
*/
RtpProcess::Ptr getProcess(const string &stream_id, bool makeNew);
RtpProcess::Ptr getProcess(const std::string &stream_id, bool makeNew);
/**
* 删除rtp处理器
* @param stream_id 流id
* @param ptr rtp处理器指针
*/
void delProcess(const string &stream_id, const RtpProcess *ptr);
void delProcess(const std::string &stream_id, const RtpProcess *ptr);
private:
void onManager();
void createTimer();
private:
Timer::Ptr _timer;
recursive_mutex _mtx_map;
unordered_map<string,RtpProcessHelper::Ptr> _map_rtp_process;
toolkit::Timer::Ptr _timer;
std::recursive_mutex _mtx_map;
std::unordered_map<std::string,RtpProcessHelper::Ptr> _map_rtp_process;
};
}//namespace mediakit

View File

@@ -14,6 +14,9 @@
#include "Thread/WorkThreadPool.h"
#include "RtpCache.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
RtpSender::RtpSender(uint32_t ssrc, uint8_t payload_type) {
@@ -23,8 +26,7 @@ RtpSender::RtpSender(uint32_t ssrc, uint8_t payload_type) {
}, ssrc, payload_type);
}
RtpSender::~RtpSender() {
}
RtpSender::~RtpSender() {}
void RtpSender::startSend(const string &dst_url, uint16_t dst_port, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb){
_is_udp = is_udp;

View File

@@ -37,7 +37,7 @@ public:
* @param is_udp 是否采用udp方式发送rtp
* @param cb 连接目标端口是否成功的回调
*/
void startSend(const string &dst_url, uint16_t dst_port, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb);
void startSend(const std::string &dst_url, uint16_t dst_port, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb);
/**
* 输入帧数据
@@ -63,21 +63,21 @@ public:
private:
//合并写输出
void onFlushRtpList(std::shared_ptr<List<Buffer::Ptr> > rtp_list);
void onFlushRtpList(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> > rtp_list);
//udp/tcp连接成功回调
void onConnect();
//异常断开socket事件
void onErr(const SockException &ex, bool is_connect = false);
void onErr(const toolkit::SockException &ex, bool is_connect = false);
private:
bool _is_udp;
bool _is_connect = false;
string _dst_url;
std::string _dst_url;
uint16_t _dst_port;
uint16_t _src_port;
Socket::Ptr _socket;
EventPoller::Ptr _poller;
Timer::Ptr _connect_timer;
toolkit::Socket::Ptr _socket;
toolkit::EventPoller::Ptr _poller;
toolkit::Timer::Ptr _connect_timer;
MediaSinkInterface::Ptr _interface;
};

View File

@@ -9,13 +9,17 @@
*/
#if defined(ENABLE_RTPPROXY)
#include "Util/uv_errno.h"
#include "RtpServer.h"
#include "RtpSelector.h"
#include "Rtcp/RtcpContext.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
RtpServer::RtpServer() {
}
RtpServer::RtpServer() {}
RtpServer::~RtpServer() {
if(_on_clearup){
@@ -161,8 +165,8 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable
_rtp_process = process;
}
void RtpServer::setOnDetach(const function<void()> &cb){
if(_rtp_process){
void RtpServer::setOnDetach(const function<void()> &cb) {
if (_rtp_process) {
_rtp_process->setOnDetach(cb);
}
}

View File

@@ -18,9 +18,6 @@
#include "Network/UdpServer.h"
#include "RtpSession.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
/**
@@ -28,8 +25,8 @@ namespace mediakit{
*/
class RtpServer {
public:
typedef std::shared_ptr<RtpServer> Ptr;
typedef function<void(const Buffer::Ptr &buf)> onRecv;
using Ptr = std::shared_ptr<RtpServer>;
using onRecv = std::function<void(const toolkit::Buffer::Ptr &buf)>;
RtpServer();
~RtpServer();
@@ -41,7 +38,7 @@ public:
* @param enable_tcp 是否启用tcp服务器
* @param local_ip 绑定的本地网卡ip
*/
void start(uint16_t local_port, const string &stream_id = "", bool enable_tcp = true, const char *local_ip = "0.0.0.0",bool enable_reuse = true);
void start(uint16_t local_port, const std::string &stream_id = "", bool enable_tcp = true, const char *local_ip = "0.0.0.0",bool enable_reuse = true);
/**
* 获取绑定的本地端口
@@ -51,14 +48,14 @@ public:
/**
* 设置RtpProcess onDetach事件回调
*/
void setOnDetach(const function<void()> &cb);
void setOnDetach(const std::function<void()> &cb);
protected:
Socket::Ptr _rtp_socket;
UdpServer::Ptr _udp_server;
TcpServer::Ptr _tcp_server;
toolkit::Socket::Ptr _rtp_socket;
toolkit::UdpServer::Ptr _udp_server;
toolkit::TcpServer::Ptr _tcp_server;
RtpProcess::Ptr _rtp_process;
function<void()> _on_clearup;
std::function<void()> _on_clearup;
};
}//namespace mediakit

View File

@@ -13,6 +13,10 @@
#include "RtpSelector.h"
#include "Network/TcpServer.h"
#include "Rtsp/RtpReceiver.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
const string RtpSession::kStreamID = "stream_id";

View File

@@ -12,25 +12,25 @@
#define ZLMEDIAKIT_RTPSESSION_H
#if defined(ENABLE_RTPPROXY)
#include "Network/TcpSession.h"
#include "RtpSplitter.h"
#include "RtpProcess.h"
#include "Util/TimeTicker.h"
using namespace toolkit;
namespace mediakit{
class RtpSession : public Session , public RtpSplitter , public MediaSourceEvent{
class RtpSession : public toolkit::Session, public RtpSplitter, public MediaSourceEvent {
public:
static const string kStreamID;
static const string kIsUDP;
static const std::string kStreamID;
static const std::string kIsUDP;
RtpSession(const Socket::Ptr &sock);
RtpSession(const toolkit::Socket::Ptr &sock);
~RtpSession() override;
void onRecv(const Buffer::Ptr &) override;
void onError(const SockException &err) override;
void onRecv(const toolkit::Buffer::Ptr &) override;
void onError(const toolkit::SockException &err) override;
void onManager() override;
void attachServer(const Server &server) override;
void attachServer(const toolkit::Server &server) override;
protected:
// 通知其停止推流
@@ -47,12 +47,12 @@ private:
bool _search_rtp = false;
bool _search_rtp_finished = false;
uint32_t _ssrc = 0;
Ticker _ticker;
string _stream_id;
toolkit::Ticker _ticker;
std::string _stream_id;
struct sockaddr _addr;
RtpProcess::Ptr _process;
std::shared_ptr<ObjectStatistic<TcpSession> > _statistic_tcp;
std::shared_ptr<ObjectStatistic<UdpSession> > _statistic_udp;
std::shared_ptr<toolkit::ObjectStatistic<toolkit::TcpSession> > _statistic_tcp;
std::shared_ptr<toolkit::ObjectStatistic<toolkit::UdpSession> > _statistic_udp;
};
}//namespace mediakit

View File

@@ -15,12 +15,11 @@
#include "Http/HttpRequestSplitter.h"
#include "Decoder.h"
using namespace toolkit;
namespace mediakit {
#define TS_PACKET_SIZE 188
#define TS_SYNC_BYTE 0x47
namespace mediakit {
//TS包分割器用于split一个一个的ts包
class TSSegment : public HttpRequestSplitter {
public: