整理命名空间 (#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

@@ -13,6 +13,9 @@
#include "mpeg4-aac.h"
#endif
using namespace std;
using namespace toolkit;
namespace mediakit{
#ifndef ENABLE_MP4

View File

@@ -17,10 +17,10 @@
namespace mediakit{
string makeAacConfig(const uint8_t *hex, size_t length);
std::string makeAacConfig(const uint8_t *hex, size_t length);
int getAacFrameLength(const uint8_t *hex, size_t length);
int dumpAacConfig(const string &config, size_t length, uint8_t *out, size_t out_size);
bool parseAacConfig(const string &config, int &samplerate, int &channels);
int dumpAacConfig(const std::string &config, size_t length, uint8_t *out, size_t out_size);
bool parseAacConfig(const std::string &config, int &samplerate, int &channels);
/**
* aac音频通道
@@ -39,12 +39,12 @@ public:
* 构造aac类型的媒体
* @param aac_cfg aac配置信息
*/
AACTrack(const string &aac_cfg);
AACTrack(const std::string &aac_cfg);
/**
* 获取aac 配置信息
*/
const string &getAacCfg() const;
const std::string &getAacCfg() const;
bool ready() override;
CodecId getCodecId() const override;
@@ -60,7 +60,7 @@ private:
bool inputFrame_l(const Frame::Ptr &frame);
private:
string _cfg;
std::string _cfg;
int _channel = 0;
int _sampleRate = 0;
int _sampleBit = 16;

View File

@@ -11,7 +11,10 @@
#include "AACRtmp.h"
#include "Rtmp/Rtmp.h"
namespace mediakit{
using namespace std;
using namespace toolkit;
namespace mediakit {
static string getAacCfg(const RtmpPacket &thiz) {
string ret;

View File

@@ -40,7 +40,7 @@ private:
void onGetAAC(const char *data, size_t len, uint32_t stamp);
private:
string _aac_cfg;
std::string _aac_cfg;
};
@@ -77,7 +77,7 @@ private:
private:
uint8_t _audio_flv_flags;
AACTrack::Ptr _track;
string _aac_cfg;
std::string _aac_cfg;
};
}//namespace mediakit

View File

@@ -60,7 +60,7 @@ void AACRtpEncoder::makeAACRtp(const void *data, size_t len, bool mark, uint32_t
/////////////////////////////////////////////////////////////////////////////////////
AACRtpDecoder::AACRtpDecoder(const Track::Ptr &track) {
auto aacTrack = dynamic_pointer_cast<AACTrack>(track);
auto aacTrack = std::dynamic_pointer_cast<AACTrack>(track);
if (!aacTrack || !aacTrack->ready()) {
WarnL << "该aac track无效!";
} else {

View File

@@ -44,7 +44,7 @@ private:
private:
uint32_t _last_dts = 0;
string _aac_cfg;
std::string _aac_cfg;
FrameImp::Ptr _frame;
};

View File

@@ -10,6 +10,8 @@
#include "CommonRtp.h"
using namespace mediakit;
CommonRtpDecoder::CommonRtpDecoder(CodecId codec, size_t max_frame_size ){
_codec = codec;
_max_frame_size = max_frame_size;

View File

@@ -24,6 +24,8 @@
#include "L16.h"
#include "Common/Parser.h"
using namespace std;
namespace mediakit{
Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {

View File

@@ -17,9 +17,6 @@
#include "Rtsp/RtpCodec.h"
#include "Rtmp/RtmpCodec.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
class Factory {

View File

@@ -16,9 +16,6 @@
#include "Util/RingBuffer.h"
#include "Network/Socket.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
typedef enum {
@@ -53,7 +50,7 @@ typedef enum {
/**
* 字符串转媒体类型转
*/
TrackType getTrackType(const string &str);
TrackType getTrackType(const std::string &str);
/**
* 媒体类型转字符串
@@ -65,7 +62,7 @@ const char* getTrackString(TrackType type);
* @param str
* @return
*/
CodecId getCodecId(const string &str);
CodecId getCodecId(const std::string &str);
/**
* 获取编码器名称
@@ -106,7 +103,7 @@ public:
/**
* 帧类型的抽象接口
*/
class Frame : public Buffer, public CodecInfo {
class Frame : public toolkit::Buffer, public CodecInfo {
public:
typedef std::shared_ptr<Frame> Ptr;
virtual ~Frame(){}
@@ -171,7 +168,7 @@ public:
private:
//对象个数统计
ObjectStatistic<Frame> _statistic;
toolkit::ObjectStatistic<Frame> _statistic;
};
class FrameImp : public Frame {
@@ -233,14 +230,14 @@ public:
uint32_t _dts = 0;
uint32_t _pts = 0;
size_t _prefix_size = 0;
BufferLikeString _buffer;
toolkit::BufferLikeString _buffer;
private:
//对象个数统计
ObjectStatistic<FrameImp> _statistic;
toolkit::ObjectStatistic<FrameImp> _statistic;
protected:
friend class ResourcePool_l<FrameImp>;
friend class toolkit::ResourcePool_l<FrameImp>;
FrameImp() = default;
};
@@ -323,7 +320,7 @@ public:
*/
void addDelegate(const FrameWriterInterface::Ptr &delegate){
//_delegates_write可能多线程同时操作
lock_guard<mutex> lck(_mtx);
std::lock_guard<std::mutex> lck(_mtx);
_delegates_write.emplace(delegate.get(),delegate);
_need_update = true;
}
@@ -333,7 +330,7 @@ public:
*/
void delDelegate(FrameWriterInterface *ptr){
//_delegates_write可能多线程同时操作
lock_guard<mutex> lck(_mtx);
std::lock_guard<std::mutex> lck(_mtx);
_delegates_write.erase(ptr);
_need_update = true;
}
@@ -344,7 +341,7 @@ public:
bool inputFrame(const Frame::Ptr &frame) override{
if(_need_update){
//发现代理列表发生变化了,这里同步一次
lock_guard<mutex> lck(_mtx);
std::lock_guard<std::mutex> lck(_mtx);
_delegates_read = _delegates_write;
_need_update = false;
}
@@ -366,9 +363,9 @@ public:
return _delegates_write.size();
}
private:
mutex _mtx;
map<void *,FrameWriterInterface::Ptr> _delegates_read;
map<void *,FrameWriterInterface::Ptr> _delegates_write;
std::mutex _mtx;
std::map<void *,FrameWriterInterface::Ptr> _delegates_read;
std::map<void *,FrameWriterInterface::Ptr> _delegates_write;
bool _need_update = false;
};
@@ -463,7 +460,7 @@ public:
* @param prefix 帧前缀长度
* @param offset buffer有效数据偏移量
*/
FrameWrapper(const Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset) : Parent(buf->data() + offset, buf->size() - offset, dts, pts, prefix){
FrameWrapper(const toolkit::Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset) : Parent(buf->data() + offset, buf->size() - offset, dts, pts, prefix){
_buf = buf;
}
@@ -476,7 +473,7 @@ public:
* @param offset buffer有效数据偏移量
* @param codec 帧类型
*/
FrameWrapper(const Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset, CodecId codec) : Parent(codec, buf->data() + offset, buf->size() - offset, dts, pts, prefix){
FrameWrapper(const toolkit::Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset, CodecId codec) : Parent(codec, buf->data() + offset, buf->size() - offset, dts, pts, prefix){
_buf = buf;
}
@@ -488,7 +485,7 @@ public:
}
private:
Buffer::Ptr _buf;
toolkit::Buffer::Ptr _buf;
};
/**
@@ -496,7 +493,7 @@ private:
*/
class FrameMerger {
public:
using onOutput = function<void(uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer, bool have_key_frame)>;
using onOutput = std::function<void(uint32_t dts, uint32_t pts, const toolkit::Buffer::Ptr &buffer, bool have_key_frame)>;
using Ptr = std::shared_ptr<FrameMerger>;
enum {
none = 0,
@@ -508,16 +505,16 @@ public:
~FrameMerger() = default;
void clear();
bool inputFrame(const Frame::Ptr &frame, const onOutput &cb, BufferLikeString *buffer = nullptr);
bool inputFrame(const Frame::Ptr &frame, const onOutput &cb, toolkit::BufferLikeString *buffer = nullptr);
private:
bool willFlush(const Frame::Ptr &frame) const;
void doMerge(BufferLikeString &buffer, const Frame::Ptr &frame) const;
void doMerge(toolkit::BufferLikeString &buffer, const Frame::Ptr &frame) const;
private:
int _type;
bool _have_decode_able_frame = false;
List<Frame::Ptr> _frame_cache;
toolkit::List<Frame::Ptr> _frame_cache;
};
}//namespace mediakit

View File

@@ -10,6 +10,9 @@
#include "G711.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
/**

View File

@@ -12,6 +12,7 @@
#include "SPSParser.h"
#include "Util/logger.h"
using namespace toolkit;
using namespace std;
namespace mediakit{

View File

@@ -14,12 +14,12 @@
#include "Frame.h"
#include "Track.h"
#include "Util/base64.h"
#define H264_TYPE(v) ((uint8_t)(v) & 0x1F)
using namespace toolkit;
namespace mediakit{
bool getAVCInfo(const string &strSps,int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
bool getAVCInfo(const std::string &strSps,int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
void splitH264(const char *ptr, size_t len, size_t prefix, const std::function<void(const char *, size_t, size_t)> &cb);
size_t prefixSize(const char *ptr, size_t len);
@@ -27,7 +27,7 @@ template<typename Parent>
class H264FrameHelper : public Parent{
public:
friend class FrameImp;
friend class ResourcePool_l<H264FrameHelper>;
friend class toolkit::ResourcePool_l<H264FrameHelper>;
using Ptr = std::shared_ptr<H264FrameHelper>;
enum {
@@ -108,7 +108,7 @@ public:
* @param sps_prefix_len 264头长度可以为3个或4个字节一般为0x00 00 00 01
* @param pps_prefix_len 264头长度可以为3个或4个字节一般为0x00 00 00 01
*/
H264Track(const string &sps,const string &pps,int sps_prefix_len = 4,int pps_prefix_len = 4);
H264Track(const std::string &sps,const std::string &pps,int sps_prefix_len = 4,int pps_prefix_len = 4);
/**
* 构造h264类型的媒体
@@ -120,8 +120,8 @@ public:
/**
* 返回不带0x00 00 00 01头的sps/pps
*/
const string &getSps() const;
const string &getPps() const;
const std::string &getSps() const;
const std::string &getPps() const;
bool ready() override;
CodecId getCodecId() const override;
@@ -142,8 +142,8 @@ private:
int _width = 0;
int _height = 0;
float _fps = 0;
string _sps;
string _pps;
std::string _sps;
std::string _pps;
};
}//namespace mediakit

View File

@@ -10,7 +10,11 @@
#include "Rtmp/utils.h"
#include "H264Rtmp.h"
namespace mediakit{
using namespace std;
using namespace toolkit;
namespace mediakit {
H264RtmpDecoder::H264RtmpDecoder() {
_h264frame = obtainFrame();

View File

@@ -15,7 +15,6 @@
#include "Extension/Track.h"
#include "Util/ResourcePool.h"
#include "Extension/H264.h"
using namespace toolkit;
namespace mediakit{
/**
@@ -45,8 +44,8 @@ protected:
protected:
H264Frame::Ptr _h264frame;
string _sps;
string _pps;
std::string _sps;
std::string _pps;
};
/**

View File

@@ -15,7 +15,6 @@
#include "Util/ResourcePool.h"
#include "Extension/H264.h"
#include "Common/Stamp.h"
using namespace toolkit;
namespace mediakit{

View File

@@ -11,7 +11,10 @@
#include "H265.h"
#include "SPSParser.h"
namespace mediakit{
using namespace std;
using namespace toolkit;
namespace mediakit {
bool getHEVCInfo(const char * vps, size_t vps_len,const char * sps,size_t sps_len,int &iVideoWidth, int &iVideoHeight, float &iVideoFps){
T_GetBitContext tGetBitBuf;

View File

@@ -15,18 +15,18 @@
#include "Track.h"
#include "Util/base64.h"
#include "H264.h"
#define H265_TYPE(v) (((uint8_t)(v) >> 1) & 0x3f)
using namespace toolkit;
namespace mediakit {
bool getHEVCInfo(const string &strVps, const string &strSps, int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
bool getHEVCInfo(const std::string &strVps, const std::string &strSps, int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
template<typename Parent>
class H265FrameHelper : public Parent{
public:
friend class FrameImp;
friend class ResourcePool_l<H265FrameHelper>;
friend class toolkit::ResourcePool_l<H265FrameHelper>;
using Ptr = std::shared_ptr<H265FrameHelper>;
enum {
@@ -136,14 +136,14 @@ public:
* @param sps_prefix_len 265头长度可以为3个或4个字节一般为0x00 00 00 01
* @param pps_prefix_len 265头长度可以为3个或4个字节一般为0x00 00 00 01
*/
H265Track(const string &vps,const string &sps, const string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4);
H265Track(const std::string &vps,const std::string &sps, const std::string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4);
/**
* 返回不带0x00 00 00 01头的vps/sps/pps
*/
const string &getVps() const;
const string &getSps() const;
const string &getPps() const;
const std::string &getVps() const;
const std::string &getSps() const;
const std::string &getPps() const;
bool ready() override;
CodecId getCodecId() const override;
@@ -164,9 +164,9 @@ private:
int _width = 0;
int _height = 0;
float _fps = 0;
string _vps;
string _sps;
string _pps;
std::string _vps;
std::string _sps;
std::string _pps;
};
}//namespace mediakit

View File

@@ -14,6 +14,9 @@
#include "mpeg4-hevc.h"
#endif//ENABLE_MP4
using namespace std;
using namespace toolkit;
namespace mediakit{
H265RtmpDecoder::H265RtmpDecoder() {

View File

@@ -15,7 +15,6 @@
#include "Extension/Track.h"
#include "Util/ResourcePool.h"
#include "Extension/H265.h"
using namespace toolkit;
namespace mediakit{
/**
@@ -79,9 +78,9 @@ private:
private:
bool _got_config_frame = false;
string _vps;
string _sps;
string _pps;
std::string _vps;
std::string _sps;
std::string _pps;
H265Track::Ptr _track;
RtmpPacket::Ptr _rtmp_packet;
FrameMerger _merger{FrameMerger::mp4_nal_size};

View File

@@ -16,8 +16,6 @@
#include "Extension/H265.h"
#include "Common/Stamp.h"
using namespace toolkit;
namespace mediakit{
/**

View File

@@ -10,6 +10,9 @@
#include "L16.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
/**

View File

@@ -10,6 +10,9 @@
#include "Opus.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
/**

View File

@@ -16,7 +16,6 @@
#include "Frame.h"
#include "Util/RingBuffer.h"
#include "Rtsp/Rtsp.h"
using namespace toolkit;
namespace mediakit{
@@ -186,7 +185,7 @@ public:
* 获取全部的Track
* @param trackReady 是否获取全部已经准备好的Track
*/
virtual vector<Track::Ptr> getTracks(bool trackReady = true) const = 0;
virtual std::vector<Track::Ptr> getTracks(bool trackReady = true) const = 0;
/**
* 获取特定Track