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

@@ -9,6 +9,9 @@
*/
#include "HlsMaker.h"
using namespace std;
namespace mediakit {
HlsMaker::HlsMaker(float seg_duration, uint32_t seg_number) {

View File

@@ -18,7 +18,6 @@
#include "Util/File.h"
#include "Util/util.h"
#include "Util/logger.h"
using namespace toolkit;
namespace mediakit {
@@ -56,7 +55,7 @@ protected:
* @param index
* @return
*/
virtual string onOpenSegment(uint64_t index) = 0;
virtual std::string onOpenSegment(uint64_t index) = 0;
/**
* 删除ts切片文件回调
@@ -114,8 +113,8 @@ private:
uint32_t _last_timestamp = 0;
uint32_t _last_seg_timestamp = 0;
uint64_t _file_index = 0;
string _last_file_name;
std::deque<tuple<int,string> > _seg_dur_list;
std::string _last_file_name;
std::deque<std::tuple<int,std::string> > _seg_dur_list;
};
}//namespace mediakit

View File

@@ -14,6 +14,7 @@
#include "Util/util.h"
#include "Util/uv_errno.h"
using namespace std;
using namespace toolkit;
namespace mediakit {

View File

@@ -17,14 +17,12 @@
#include "HlsMaker.h"
#include "HlsMediaSource.h"
using namespace std;
namespace mediakit {
class HlsMakerImp : public HlsMaker{
public:
HlsMakerImp(const string &m3u8_file,
const string &params,
HlsMakerImp(const std::string &m3u8_file,
const std::string &params,
uint32_t bufSize = 64 * 1024,
float seg_duration = 5,
uint32_t seg_number = 3);
@@ -37,7 +35,7 @@ public:
* @param app 应用名
* @param stream_id 流id
*/
void setMediaSource(const string &vhost, const string &app, const string &stream_id);
void setMediaSource(const std::string &vhost, const std::string &app, const std::string &stream_id);
/**
* 获取MediaSource
@@ -52,26 +50,26 @@ public:
void clearCache(bool immediately = true);
protected:
string onOpenSegment(uint64_t index) override ;
std::string onOpenSegment(uint64_t index) override ;
void onDelSegment(uint64_t index) override;
void onWriteSegment(const char *data, size_t len) override;
void onWriteHls(const char *data, size_t len) override;
void onFlushLastSegment(uint32_t duration_ms) override;
private:
std::shared_ptr<FILE> makeFile(const string &file,bool setbuf = false);
std::shared_ptr<FILE> makeFile(const std::string &file,bool setbuf = false);
private:
int _buf_size;
string _params;
string _path_hls;
string _path_prefix;
std::string _params;
std::string _path_hls;
std::string _path_prefix;
RecordInfo _info;
std::shared_ptr<FILE> _file;
std::shared_ptr<char> _file_buf;
HlsMediaSource::Ptr _media_src;
EventPoller::Ptr _poller;
map<uint64_t/*index*/,string/*file_path*/> _segment_file_paths;
toolkit::EventPoller::Ptr _poller;
std::map<uint64_t/*index*/,std::string/*file_path*/> _segment_file_paths;
};
}//namespace mediakit

View File

@@ -10,6 +10,8 @@
#include "HlsMediaSource.h"
using namespace toolkit;
namespace mediakit{
HlsCookieData::HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockInfo> &sock_info) {
@@ -21,7 +23,7 @@ HlsCookieData::HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockIn
void HlsCookieData::addReaderCount(){
if(!*_added){
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
auto src = std::dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
if(src){
*_added = true;
_ring_reader = src->getRing()->attach(EventPollerPool::Instance().getPoller());

View File

@@ -14,14 +14,17 @@
#include <atomic>
#include "Util/TimeTicker.h"
#include "Common/MediaSource.h"
namespace mediakit{
class HlsMediaSource : public MediaSource {
public:
friend class HlsCookieData;
typedef RingBuffer<string> RingType;
typedef std::shared_ptr<HlsMediaSource> Ptr;
HlsMediaSource(const string &vhost, const string &app, const string &stream_id) : MediaSource(HLS_SCHEMA, vhost, app, stream_id){}
using RingType = toolkit::RingBuffer<std::string>;
using Ptr = std::shared_ptr<HlsMediaSource>;
HlsMediaSource(const std::string &vhost, const std::string &app, const std::string &stream_id) : MediaSource(HLS_SCHEMA, vhost, app, stream_id){}
~HlsMediaSource() override = default;
/**
@@ -45,7 +48,7 @@ public:
void registHls(bool file_created){
if (!_is_regist) {
_is_regist = true;
weak_ptr<HlsMediaSource> weakSelf = dynamic_pointer_cast<HlsMediaSource>(shared_from_this());
std::weak_ptr<HlsMediaSource> weakSelf = std::dynamic_pointer_cast<HlsMediaSource>(shared_from_this());
auto lam = [weakSelf](int size) {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
@@ -65,17 +68,17 @@ public:
//m3u8文件生成发送给播放器
decltype(_list_cb) copy;
{
lock_guard<mutex> lck(_mtx_cb);
std::lock_guard<std::mutex> lck(_mtx_cb);
copy.swap(_list_cb);
}
copy.for_each([](const function<void()> &cb) {
copy.for_each([](const std::function<void()> &cb) {
cb();
});
}
void waitForFile(function<void()> cb) {
void waitForFile(std::function<void()> cb) {
//等待生成m3u8文件
lock_guard<mutex> lck(_mtx_cb);
std::lock_guard<std::mutex> lck(_mtx_cb);
_list_cb.emplace_back(std::move(cb));
}
@@ -86,14 +89,14 @@ public:
private:
bool _is_regist = false;
RingType::Ptr _ring;
mutex _mtx_cb;
List<function<void()> > _list_cb;
std::mutex _mtx_cb;
toolkit::List<std::function<void()> > _list_cb;
};
class HlsCookieData{
public:
typedef std::shared_ptr<HlsCookieData> Ptr;
HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockInfo> &sock_info);
HlsCookieData(const MediaInfo &info, const std::shared_ptr<toolkit::SockInfo> &sock_info);
~HlsCookieData();
void addByteUsage(size_t bytes);
@@ -101,14 +104,13 @@ private:
void addReaderCount();
private:
atomic<uint64_t> _bytes {0};
std::atomic<uint64_t> _bytes {0};
MediaInfo _info;
std::shared_ptr<bool> _added;
Ticker _ticker;
std::shared_ptr<SockInfo> _sock_info;
toolkit::Ticker _ticker;
std::shared_ptr<toolkit::SockInfo> _sock_info;
HlsMediaSource::RingType::RingReader::Ptr _ring_reader;
};
}//namespace mediakit
#endif //ZLMEDIAKIT_HLSMEDIASOURCE_H

View File

@@ -20,7 +20,7 @@ class HlsRecorder : public MediaSourceEventInterceptor, public MpegMuxer, public
public:
using Ptr = std::shared_ptr<HlsRecorder>;
HlsRecorder(const string &m3u8_file, const string &params) : MpegMuxer(false) {
HlsRecorder(const std::string &m3u8_file, const std::string &params) : MpegMuxer(false) {
GET_CONFIG(uint32_t, hlsNum, Hls::kSegmentNum);
GET_CONFIG(uint32_t, hlsBufSize, Hls::kFileBufSize);
GET_CONFIG(float, hlsDuration, Hls::kSegmentDuration);
@@ -31,7 +31,7 @@ public:
~HlsRecorder() = default;
void setMediaSource(const string &vhost, const string &app, const string &stream_id) {
void setMediaSource(const std::string &vhost, const std::string &app, const std::string &stream_id) {
_hls->setMediaSource(vhost, app, stream_id);
}
@@ -76,7 +76,7 @@ public:
}
private:
void onWrite(std::shared_ptr<Buffer> buffer, uint32_t timestamp, bool key_pos) override {
void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint32_t timestamp, bool key_pos) override {
if (!buffer) {
_hls->inputData(nullptr, 0, timestamp, key_pos);
} else {

View File

@@ -15,6 +15,8 @@
#include "Common/config.h"
using namespace toolkit;
using namespace std;
namespace mediakit {
static struct mov_buffer_t s_io = {

View File

@@ -24,8 +24,6 @@
#include "mov-buffer.h"
#include "mov-format.h"
using namespace std;
namespace mediakit {
//mp4文件IO的抽象接口类
@@ -124,7 +122,7 @@ public:
/**
* 获取并清空文件缓存
*/
string getAndClearMemory();
std::string getAndClearMemory();
protected:
uint64_t onTell() override;
@@ -134,7 +132,7 @@ protected:
private:
uint64_t _offset = 0;
string _memory;
std::string _memory;
};
}//namespace mediakit

View File

@@ -17,6 +17,8 @@
#include "Extension/G711.h"
#include "Extension/Opus.h"
using namespace toolkit;
using namespace std;
namespace mediakit {
MP4Demuxer::MP4Demuxer() {}

View File

@@ -30,7 +30,7 @@ public:
* 打开文件
* @param file mp4文件路径
*/
void openMP4(const string &file);
void openMP4(const std::string &file);
/**
* @brief 关闭 mp4 文件
@@ -57,7 +57,7 @@ public:
* @param trackReady 是否要求track为就绪状态
* @return 所有Track
*/
vector<Track::Ptr> getTracks(bool trackReady) const override;
std::vector<Track::Ptr> getTracks(bool trackReady) const override;
/**
* 获取文件长度
@@ -69,14 +69,14 @@ private:
int getAllTracks();
void onVideoTrack(uint32_t track_id, uint8_t object, int width, int height, const void *extra, size_t bytes);
void onAudioTrack(uint32_t track_id, uint8_t object, int channel_count, int bit_per_sample, int sample_rate, const void *extra, size_t bytes);
Frame::Ptr makeFrame(uint32_t track_id, const Buffer::Ptr &buf, int64_t pts, int64_t dts);
Frame::Ptr makeFrame(uint32_t track_id, const toolkit::Buffer::Ptr &buf, int64_t pts, int64_t dts);
private:
MP4FileDisk::Ptr _mp4_file;
MP4FileDisk::Reader _mov_reader;
uint64_t _duration_ms = 0;
map<int, Track::Ptr> _track_to_codec;
ResourcePool<BufferRaw> _buffer_pool;
std::map<int, Track::Ptr> _track_to_codec;
toolkit::ResourcePool<toolkit::BufferRaw> _buffer_pool;
};

View File

@@ -14,6 +14,9 @@
#include "Util/File.h"
#include "Extension/H264.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
MP4Muxer::MP4Muxer() {}

View File

@@ -72,7 +72,7 @@ private:
int track_id = -1;
Stamp stamp;
};
unordered_map<int, track_info> _codec_to_trackid;
std::unordered_map<int, track_info> _codec_to_trackid;
FrameMerger _frame_merger{FrameMerger::mp4_nal_size};
};
@@ -92,7 +92,7 @@ public:
* 打开mp4
* @param file 文件完整路径
*/
void openMP4(const string &file);
void openMP4(const std::string &file);
/**
* 手动关闭文件(对象析构时会自动关闭)
@@ -103,7 +103,7 @@ protected:
MP4FileIO::Writer createWriter() override;
private:
string _file_name;
std::string _file_name;
MP4FileDisk::Ptr _mp4_file;
};
@@ -125,23 +125,23 @@ public:
/**
* 获取fmp4 init segment
*/
const string &getInitSegment();
const std::string &getInitSegment();
protected:
/**
* 输出fmp4切片回调函数
* @param string 切片内容
* @param std::string 切片内容
* @param stamp 切片末尾时间戳
* @param key_frame 是否有关键帧
*/
virtual void onSegmentData(string string, uint32_t stamp, bool key_frame) = 0;
virtual void onSegmentData(std::string string, uint32_t stamp, bool key_frame) = 0;
protected:
MP4FileIO::Writer createWriter() override;
private:
bool _key_frame = false;
string _init_segment;
std::string _init_segment;
MP4FileMemory::Ptr _memory_file;
};

View File

@@ -14,6 +14,7 @@
#include "Common/config.h"
#include "Thread/WorkThreadPool.h"
using namespace std;
using namespace toolkit;
namespace mediakit {

View File

@@ -11,9 +11,10 @@
#ifndef SRC_MEDIAFILE_MEDIAREADER_H_
#define SRC_MEDIAFILE_MEDIAREADER_H_
#ifdef ENABLE_MP4
#include "MP4Demuxer.h"
#include "Common/MultiMediaSourceMuxer.h"
using namespace toolkit;
namespace mediakit {
class MP4Reader : public std::enable_shared_from_this<MP4Reader>, public MediaSourceEvent {
@@ -27,7 +28,7 @@ public:
* @param stream_id 流id,置空时,只解复用mp4,但是不生成MediaSource
* @param file_path 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件
*/
MP4Reader(const string &vhost, const string &app, const string &stream_id, const string &file_path = "");
MP4Reader(const std::string &vhost, const std::string &app, const std::string &stream_id, const std::string &file_path = "");
~MP4Reader() override = default;
/**
@@ -37,7 +38,7 @@ public:
* @param ref_self 是否让定时器引用此对象本身,如果无其他对象引用本身,在不循环读文件时,读取文件结束后本对象将自动销毁
* @param file_repeat 是否循环读取文件,如果配置文件设置为循环读文件,此参数无效
*/
void startReadMP4(const EventPoller::Ptr &poller = nullptr, uint64_t sample_ms = 0, bool ref_self = true, bool file_repeat = false);
void startReadMP4(const toolkit::EventPoller::Ptr &poller = nullptr, uint64_t sample_ms = 0, bool ref_self = true, bool file_repeat = false);
/**
* 停止解复用MP4定时器
@@ -58,7 +59,7 @@ private:
bool close(MediaSource &sender,bool force) override;
int totalReaderCount(MediaSource &sender) override;
MediaOriginType getOriginType(MediaSource &sender) const override;
string getOriginUrl(MediaSource &sender) const override;
std::string getOriginUrl(MediaSource &sender) const override;
bool readSample();
bool readNextSample();
@@ -73,10 +74,10 @@ private:
float _speed = 1.0;
uint32_t _last_dts = 0;
uint32_t _seek_to = 0;
string _file_path;
recursive_mutex _mtx;
Ticker _seek_ticker;
Timer::Ptr _timer;
std::string _file_path;
std::recursive_mutex _mtx;
toolkit::Ticker _seek_ticker;
toolkit::Timer::Ptr _timer;
MP4Demuxer::Ptr _demuxer;
MultiMediaSourceMuxer::Ptr _muxer;
};

View File

@@ -16,6 +16,7 @@
#include "MP4Recorder.h"
#include "Thread/WorkThreadPool.h"
using namespace std;
using namespace toolkit;
namespace mediakit {

View File

@@ -21,8 +21,6 @@
#include "Common/MediaSink.h"
#include "MP4Muxer.h"
using namespace toolkit;
namespace mediakit {
#ifdef ENABLE_MP4
@@ -30,7 +28,7 @@ class MP4Recorder : public MediaSinkInterface {
public:
using Ptr = std::shared_ptr<MP4Recorder>;
MP4Recorder(const string &path, const string &vhost, const string &app, const string &stream_id, size_t max_second);
MP4Recorder(const std::string &path, const std::string &vhost, const std::string &app, const std::string &stream_id, size_t max_second);
~MP4Recorder() override;
/**
@@ -56,12 +54,12 @@ private:
private:
bool _have_video = false;
size_t _max_second;
string _folder_path;
string _full_path;
string _full_path_tmp;
std::string _folder_path;
std::string _full_path;
std::string _full_path_tmp;
RecordInfo _info;
MP4Muxer::Ptr _muxer;
list<Track::Ptr> _tracks;
std::list<Track::Ptr> _tracks;
uint64_t _last_dts = 0;
};

View File

@@ -13,8 +13,11 @@
#if defined(ENABLE_HLS) || defined(ENABLE_RTPPROXY)
#include "mpeg-ts-proto.h"
#include "mpeg-muxer.h"
using namespace toolkit;
namespace mediakit{
MpegMuxer::MpegMuxer(bool is_ps) {
@@ -32,7 +35,7 @@ MpegMuxer::~MpegMuxer() {
if (mpeg_id == PSI_STREAM_RESERVED) { \
break; \
} \
_codec_to_trackid[track->getCodecId()] = mpeg_muxer_add_stream(_context, mpeg_id, nullptr, 0); \
_codec_to_trackid[track->getCodecId()] = mpeg_muxer_add_stream((::mpeg_muxer_t *)_context, mpeg_id, nullptr, 0); \
return true; \
}
@@ -65,7 +68,7 @@ bool MpegMuxer::inputFrame(const Frame::Ptr &frame) {
//取视频时间戳为TS的时间戳
_timestamp = (uint32_t) dts;
_max_cache_size = 512 + 1.2 * buffer->size();
mpeg_muxer_input(_context, track_id, have_idr ? 0x0001 : 0, pts * 90LL,dts * 90LL, buffer->data(), buffer->size());
mpeg_muxer_input((::mpeg_muxer_t *)_context, track_id, have_idr ? 0x0001 : 0, pts * 90LL,dts * 90LL, buffer->data(), buffer->size());
flushCache();
});
}
@@ -83,7 +86,7 @@ bool MpegMuxer::inputFrame(const Frame::Ptr &frame) {
_timestamp = (uint32_t) frame->dts();
}
_max_cache_size = 512 + 1.2 * frame->size();
mpeg_muxer_input(_context, track_id, frame->keyFrame() ? 0x0001 : 0, frame->pts() * 90LL, frame->dts() * 90LL, frame->data(), frame->size());
mpeg_muxer_input((::mpeg_muxer_t *)_context, track_id, frame->keyFrame() ? 0x0001 : 0, frame->pts() * 90LL, frame->dts() * 90LL, frame->data(), frame->size());
flushCache();
return true;
}
@@ -127,7 +130,7 @@ void MpegMuxer::createContext() {
}
};
if (_context == nullptr) {
_context = mpeg_muxer_create(_is_ps, &func, this);
_context = (struct mpeg_muxer_t *)mpeg_muxer_create(_is_ps, &func, this);
}
}
@@ -143,7 +146,7 @@ void MpegMuxer::flushCache() {
void MpegMuxer::releaseContext() {
if (_context) {
mpeg_muxer_destroy(_context);
mpeg_muxer_destroy((::mpeg_muxer_t *)_context);
_context = nullptr;
}
_codec_to_trackid.clear();

View File

@@ -52,7 +52,7 @@ protected:
* @param timestamp 时间戳,单位毫秒
* @param key_pos 是否为关键帧的第一个ts/ps包用于确保ts切片第一帧为关键帧
*/
virtual void onWrite(std::shared_ptr<Buffer> buffer, uint32_t timestamp, bool key_pos) = 0;
virtual void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint32_t timestamp, bool key_pos) = 0;
private:
void createContext();
@@ -67,10 +67,10 @@ private:
uint32_t _max_cache_size = 0;
uint32_t _timestamp = 0;
struct mpeg_muxer_t *_context = nullptr;
unordered_map<int, int/*track_id*/> _codec_to_trackid;
std::unordered_map<int, int/*track_id*/> _codec_to_trackid;
FrameMerger _frame_merger{FrameMerger::h264_prefix};
BufferRaw::Ptr _current_buffer;
ResourcePool<BufferRaw> _buffer_pool;
toolkit::BufferRaw::Ptr _current_buffer;
toolkit::ResourcePool<toolkit::BufferRaw> _buffer_pool;
};
}//mediakit
@@ -90,7 +90,7 @@ public:
bool inputFrame(const Frame::Ptr &frame) override { return false; }
protected:
virtual void onWrite(std::shared_ptr<Buffer> buffer, uint32_t timestamp, bool key_pos) = 0;
virtual void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint32_t timestamp, bool key_pos) = 0;
};
}//namespace mediakit

View File

@@ -14,6 +14,7 @@
#include "MP4Recorder.h"
#include "HlsRecorder.h"
using namespace std;
using namespace toolkit;
namespace mediakit {

View File

@@ -12,7 +12,7 @@
#define SRC_MEDIAFILE_RECORDER_H_
#include <memory>
#include <string>
using namespace std;
namespace mediakit {
class MediaSinkInterface;
@@ -21,13 +21,13 @@ public:
time_t start_time; // GMT 标准时间,单位秒
float time_len; // 录像长度,单位秒
off_t file_size; // 文件大小,单位 BYTE
string file_path; // 文件路径
string file_name; // 文件名称
string folder; // 文件夹路径
string url; // 播放路径
string app; // 应用名称
string stream; // 流 ID
string vhost; // 虚拟主机
std::string file_path; // 文件路径
std::string file_name; // 文件名称
std::string folder; // 文件夹路径
std::string url; // 播放路径
std::string app; // 应用名称
std::string stream; // 流 ID
std::string vhost; // 虚拟主机
};
class Recorder{
@@ -48,7 +48,7 @@ public:
* @param customized_path 录像文件保存自定义根目录,为空则采用配置文件设置
* @return 录制文件绝对路径
*/
static string getRecordPath(type type, const string &vhost, const string &app, const string &stream_id,const string &customized_path = "");
static std::string getRecordPath(type type, const std::string &vhost, const std::string &app, const std::string &stream_id,const std::string &customized_path = "");
/**
* 创建录制器对象
@@ -60,7 +60,7 @@ public:
* @param max_second mp4录制最大切片时间单位秒置0则采用配置文件配置
* @return 对象指针可能为nullptr
*/
static std::shared_ptr<MediaSinkInterface> createRecorder(type type, const string &vhost, const string &app, const string &stream_id, const string &customized_path = "", size_t max_second = 0);
static std::shared_ptr<MediaSinkInterface> createRecorder(type type, const std::string &vhost, const std::string &app, const std::string &stream_id, const std::string &customized_path = "", size_t max_second = 0);
/**
* 获取录制状态
@@ -70,7 +70,7 @@ public:
* @param stream_id 流id
* @return 是否真正录制
*/
static bool isRecording(type type, const string &vhost, const string &app, const string &stream_id);
static bool isRecording(type type, const std::string &vhost, const std::string &app, const std::string &stream_id);
/**
* 开始录制
@@ -81,7 +81,7 @@ public:
* @param customized_path 录像文件保存自定义根目录,为空则采用配置文件设置
* @return 成功与否
*/
static bool startRecord(type type, const string &vhost, const string &app, const string &stream_id,const string &customized_path, size_t max_second);
static bool startRecord(type type, const std::string &vhost, const std::string &app, const std::string &stream_id,const std::string &customized_path, size_t max_second);
/**
* 停止录制
@@ -90,7 +90,7 @@ public:
* @param app 应用名
* @param stream_id 流id
*/
static bool stopRecord(type type, const string &vhost, const string &app, const string &stream_id);
static bool stopRecord(type type, const std::string &vhost, const std::string &app, const std::string &stream_id);
private:
Recorder() = delete;