mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-02-13 11:50:53 +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:
@@ -16,6 +16,10 @@
|
||||
#include "Thread/WorkThreadPool.h"
|
||||
#include "Network/sockutil.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
namespace FFmpeg {
|
||||
#define FFmpeg_FIELD "ffmpeg."
|
||||
const string kBin = FFmpeg_FIELD"bin";
|
||||
|
||||
@@ -19,12 +19,8 @@
|
||||
#include "Network/Socket.h"
|
||||
#include "Common/MediaSource.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
namespace FFmpeg {
|
||||
extern const string kSnap;
|
||||
extern const std::string kSnap;
|
||||
}
|
||||
|
||||
class FFmpegSnap {
|
||||
@@ -34,16 +30,16 @@ public:
|
||||
/// \param save_path 截图jpeg文件保存路径
|
||||
/// \param timeout_sec 生成截图超时时间(防止阻塞太久)
|
||||
/// \param cb 生成截图成功与否回调
|
||||
static void makeSnap(const string &play_url, const string &save_path, float timeout_sec, const function<void(bool)> &cb);
|
||||
static void makeSnap(const std::string &play_url, const std::string &save_path, float timeout_sec, const std::function<void(bool)> &cb);
|
||||
private:
|
||||
FFmpegSnap() = delete;
|
||||
~FFmpegSnap() = delete;
|
||||
};
|
||||
|
||||
class FFmpegSource : public std::enable_shared_from_this<FFmpegSource> , public MediaSourceEventInterceptor{
|
||||
class FFmpegSource : public std::enable_shared_from_this<FFmpegSource> , public mediakit::MediaSourceEventInterceptor{
|
||||
public:
|
||||
typedef shared_ptr<FFmpegSource> Ptr;
|
||||
typedef function<void(const SockException &ex)> onPlay;
|
||||
using Ptr = std::shared_ptr<FFmpegSource>;
|
||||
using onPlay = std::function<void(const toolkit::SockException &ex)>;
|
||||
|
||||
FFmpegSource();
|
||||
~FFmpegSource();
|
||||
@@ -51,7 +47,7 @@ public:
|
||||
/**
|
||||
* 设置主动关闭回调
|
||||
*/
|
||||
void setOnClose(const function<void()> &cb);
|
||||
void setOnClose(const std::function<void()> &cb);
|
||||
|
||||
/**
|
||||
* 开始播放url
|
||||
@@ -61,7 +57,7 @@ public:
|
||||
* @param timeout_ms 等待结果超时时间,单位毫秒
|
||||
* @param cb 成功与否回调
|
||||
*/
|
||||
void play(const string &ffmpeg_cmd_key, const string &src_url, const string &dst_url, int timeout_ms, const onPlay &cb);
|
||||
void play(const std::string &ffmpeg_cmd_key, const std::string &src_url, const std::string &dst_url, int timeout_ms, const onPlay &cb);
|
||||
|
||||
/**
|
||||
* 设置录制
|
||||
@@ -71,32 +67,32 @@ public:
|
||||
void setupRecordFlag(bool enable_hls, bool enable_mp4);
|
||||
|
||||
private:
|
||||
void findAsync(int maxWaitMS ,const function<void(const MediaSource::Ptr &src)> &cb);
|
||||
void findAsync(int maxWaitMS ,const std::function<void(const mediakit::MediaSource::Ptr &src)> &cb);
|
||||
void startTimer(int timeout_ms);
|
||||
void onGetMediaSource(const MediaSource::Ptr &src);
|
||||
void onGetMediaSource(const mediakit::MediaSource::Ptr &src);
|
||||
|
||||
///////MediaSourceEvent override///////
|
||||
// 关闭
|
||||
bool close(MediaSource &sender,bool force) override;
|
||||
bool close(mediakit::MediaSource &sender,bool force) override;
|
||||
// 获取媒体源类型
|
||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||
mediakit::MediaOriginType getOriginType(mediakit::MediaSource &sender) const override;
|
||||
//获取媒体源url或者文件路径
|
||||
string getOriginUrl(MediaSource &sender) const override;
|
||||
std::string getOriginUrl(mediakit::MediaSource &sender) const override;
|
||||
// 获取媒体源客户端相关信息
|
||||
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
std::shared_ptr<toolkit::SockInfo> getOriginSock(mediakit::MediaSource &sender) const override;
|
||||
|
||||
private:
|
||||
bool _enable_hls = false;
|
||||
bool _enable_mp4 = false;
|
||||
Process _process;
|
||||
Timer::Ptr _timer;
|
||||
EventPoller::Ptr _poller;
|
||||
MediaInfo _media_info;
|
||||
string _src_url;
|
||||
string _dst_url;
|
||||
string _ffmpeg_cmd_key;
|
||||
function<void()> _onClose;
|
||||
Ticker _replay_ticker;
|
||||
toolkit::Timer::Ptr _timer;
|
||||
toolkit::EventPoller::Ptr _poller;
|
||||
mediakit::MediaInfo _media_info;
|
||||
std::string _src_url;
|
||||
std::string _dst_url;
|
||||
std::string _ffmpeg_cmd_key;
|
||||
std::function<void()> _onClose;
|
||||
toolkit::Ticker _replay_ticker;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "Poller/EventPoller.h"
|
||||
#include "Process.h"
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
void Process::run(const string &cmd, const string &log_file_tmp) {
|
||||
kill(2000);
|
||||
|
||||
@@ -19,13 +19,12 @@ typedef int pid_t;
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class Process {
|
||||
public:
|
||||
Process();
|
||||
~Process();
|
||||
void run(const string &cmd,const string &log_file);
|
||||
void run(const std::string &cmd,const std::string &log_file);
|
||||
void kill(int max_delay,bool force = false);
|
||||
bool wait(bool block = true);
|
||||
int exit_code();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Util/uv_errno.h"
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
const int MAX_STACK_FRAMES = 128;
|
||||
#define BroadcastOnCrashDumpArgs int &sig,const vector<vector<string> > &stack
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
#define ZLMEDIAKIT_SYSTEM_H
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class System {
|
||||
public:
|
||||
static string execute(const string &cmd);
|
||||
static std::string execute(const std::string &cmd);
|
||||
static void startDaemon();
|
||||
static void systemSetup();
|
||||
};
|
||||
|
||||
@@ -48,7 +48,8 @@
|
||||
#include <tchar.h>
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace Json;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
@@ -461,11 +462,11 @@ void addStreamProxy(const string &vhost, const string &app, const string &stream
|
||||
s_proxyMap[key] = player;
|
||||
|
||||
//指定RTP over TCP(播放rtsp时有效)
|
||||
(*player)[kRtpType] = rtp_type;
|
||||
(*player)[Client::kRtpType] = rtp_type;
|
||||
|
||||
if (timeout_sec > 0.1) {
|
||||
//播放握手超时时间
|
||||
(*player)[kTimeoutMS] = timeout_sec * 1000;
|
||||
(*player)[Client::kTimeoutMS] = timeout_sec * 1000;
|
||||
}
|
||||
|
||||
//开始播放,如果播放失败或者播放中止,将会自动重试若干次,默认一直重试
|
||||
@@ -839,11 +840,11 @@ void installWebApi() {
|
||||
s_proxyPusherMap[key] = pusher;
|
||||
|
||||
//指定RTP over TCP(播放rtsp时有效)
|
||||
(*pusher)[kRtpType] = rtp_type;
|
||||
(*pusher)[Client::kRtpType] = rtp_type;
|
||||
|
||||
if (timeout_sec > 0.1) {
|
||||
//推流握手超时时间
|
||||
(*pusher)[kTimeoutMS] = timeout_sec * 1000;
|
||||
(*pusher)[Client::kTimeoutMS] = timeout_sec * 1000;
|
||||
}
|
||||
|
||||
//开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试
|
||||
|
||||
@@ -18,23 +18,18 @@
|
||||
#include "Network/Socket.h"
|
||||
#include "Http/HttpSession.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Json;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
//配置文件路径
|
||||
extern string g_ini_file;
|
||||
extern std::string g_ini_file;
|
||||
|
||||
namespace mediakit {
|
||||
////////////RTSP服务器配置///////////
|
||||
namespace Rtsp {
|
||||
extern const string kPort;
|
||||
extern const std::string kPort;
|
||||
} //namespace Rtsp
|
||||
|
||||
////////////RTMP服务器配置///////////
|
||||
namespace Rtmp {
|
||||
extern const string kPort;
|
||||
extern const std::string kPort;
|
||||
} //namespace RTMP
|
||||
} // namespace mediakit
|
||||
|
||||
@@ -79,25 +74,25 @@ public:
|
||||
~SuccessException() = default;
|
||||
};
|
||||
|
||||
using ApiArgsType = map<string, string, StrCaseCompare>;
|
||||
using ApiArgsType = std::map<std::string, std::string, mediakit::StrCaseCompare>;
|
||||
|
||||
template<typename Args, typename First>
|
||||
string getValue(Args &args, const First &first) {
|
||||
std::string getValue(Args &args, const First &first) {
|
||||
return args[first];
|
||||
}
|
||||
|
||||
template<typename First>
|
||||
string getValue(Json::Value &args, const First &first) {
|
||||
std::string getValue(Json::Value &args, const First &first) {
|
||||
return args[first].asString();
|
||||
}
|
||||
|
||||
template<typename First>
|
||||
string getValue(string &args, const First &first) {
|
||||
std::string getValue(std::string &args, const First &first) {
|
||||
return "";
|
||||
}
|
||||
|
||||
template<typename First>
|
||||
string getValue(const Parser &parser, const First &first) {
|
||||
std::string getValue(const mediakit::Parser &parser, const First &first) {
|
||||
auto ret = parser.getUrlArgs()[first];
|
||||
if (!ret.empty()) {
|
||||
return ret;
|
||||
@@ -106,12 +101,12 @@ string getValue(const Parser &parser, const First &first) {
|
||||
}
|
||||
|
||||
template<typename First>
|
||||
string getValue(Parser &parser, const First &first) {
|
||||
return getValue((const Parser &) parser, first);
|
||||
std::string getValue(mediakit::Parser &parser, const First &first) {
|
||||
return getValue((const mediakit::Parser &) parser, first);
|
||||
}
|
||||
|
||||
template<typename Args, typename First>
|
||||
string getValue(const Parser &parser, Args &args, const First &first) {
|
||||
std::string getValue(const mediakit::Parser &parser, Args &args, const First &first) {
|
||||
auto ret = getValue(args, first);
|
||||
if (!ret.empty()) {
|
||||
return ret;
|
||||
@@ -122,24 +117,24 @@ string getValue(const Parser &parser, Args &args, const First &first) {
|
||||
template<typename Args>
|
||||
class HttpAllArgs {
|
||||
public:
|
||||
HttpAllArgs(const Parser &parser, Args &args) {
|
||||
HttpAllArgs(const mediakit::Parser &parser, Args &args) {
|
||||
_get_args = [&args]() {
|
||||
return (void *) &args;
|
||||
};
|
||||
_get_parser = [&parser]() -> const Parser & {
|
||||
_get_parser = [&parser]() -> const mediakit::Parser & {
|
||||
return parser;
|
||||
};
|
||||
_get_value = [](HttpAllArgs &that, const string &key) {
|
||||
_get_value = [](HttpAllArgs &that, const std::string &key) {
|
||||
return getValue(that.getParser(), that.getArgs(), key);
|
||||
};
|
||||
_clone = [&](HttpAllArgs &that) {
|
||||
that._get_args = [args]() {
|
||||
return (void *) &args;
|
||||
};
|
||||
that._get_parser = [parser]() -> const Parser & {
|
||||
that._get_parser = [parser]() -> const mediakit::Parser & {
|
||||
return parser;
|
||||
};
|
||||
that._get_value = [](HttpAllArgs &that, const string &key) {
|
||||
that._get_value = [](HttpAllArgs &that, const std::string &key) {
|
||||
return getValue(that.getParser(), that.getArgs(), key);
|
||||
};
|
||||
that._cache_able = true;
|
||||
@@ -160,11 +155,11 @@ public:
|
||||
~HttpAllArgs() = default;
|
||||
|
||||
template<typename Key>
|
||||
variant operator[](const Key &key) const {
|
||||
return (variant)_get_value(*(HttpAllArgs*)this, key);
|
||||
toolkit::variant operator[](const Key &key) const {
|
||||
return (toolkit::variant)_get_value(*(HttpAllArgs*)this, key);
|
||||
}
|
||||
|
||||
const Parser &getParser() const {
|
||||
const mediakit::Parser &getParser() const {
|
||||
return _get_parser();
|
||||
}
|
||||
|
||||
@@ -178,34 +173,34 @@ public:
|
||||
|
||||
private:
|
||||
bool _cache_able = false;
|
||||
function<void *() > _get_args;
|
||||
function<const Parser &() > _get_parser;
|
||||
function<string(HttpAllArgs &that, const string &key)> _get_value;
|
||||
function<void(HttpAllArgs &that) > _clone;
|
||||
std::function<void *() > _get_args;
|
||||
std::function<const mediakit::Parser &() > _get_parser;
|
||||
std::function<std::string(HttpAllArgs &that, const std::string &key)> _get_value;
|
||||
std::function<void(HttpAllArgs &that) > _clone;
|
||||
};
|
||||
|
||||
#define API_ARGS_MAP SockInfo &sender, HttpSession::KeyValue &headerOut, const HttpAllArgs<ApiArgsType> &allArgs, Json::Value &val
|
||||
#define API_ARGS_MAP_ASYNC API_ARGS_MAP, const HttpSession::HttpResponseInvoker &invoker
|
||||
#define API_ARGS_JSON SockInfo &sender, HttpSession::KeyValue &headerOut, const HttpAllArgs<Json::Value> &allArgs, Json::Value &val
|
||||
#define API_ARGS_JSON_ASYNC API_ARGS_JSON, const HttpSession::HttpResponseInvoker &invoker
|
||||
#define API_ARGS_STRING SockInfo &sender, HttpSession::KeyValue &headerOut, const HttpAllArgs<string> &allArgs, Json::Value &val
|
||||
#define API_ARGS_STRING_ASYNC API_ARGS_STRING, const HttpSession::HttpResponseInvoker &invoker
|
||||
#define API_ARGS_MAP toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const HttpAllArgs<ApiArgsType> &allArgs, Json::Value &val
|
||||
#define API_ARGS_MAP_ASYNC API_ARGS_MAP, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||
#define API_ARGS_JSON toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const HttpAllArgs<Json::Value> &allArgs, Json::Value &val
|
||||
#define API_ARGS_JSON_ASYNC API_ARGS_JSON, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||
#define API_ARGS_STRING toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const HttpAllArgs<std::string> &allArgs, Json::Value &val
|
||||
#define API_ARGS_STRING_ASYNC API_ARGS_STRING, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||
#define API_ARGS_VALUE sender, headerOut, allArgs, val
|
||||
|
||||
//注册http请求参数是map<string, variant, StrCaseCompare>类型的http api
|
||||
void api_regist(const string &api_path, const function<void(API_ARGS_MAP)> &func);
|
||||
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_MAP)> &func);
|
||||
//注册http请求参数是map<string, variant, StrCaseCompare>类型,但是可以异步回复的的http api
|
||||
void api_regist(const string &api_path, const function<void(API_ARGS_MAP_ASYNC)> &func);
|
||||
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_MAP_ASYNC)> &func);
|
||||
|
||||
//注册http请求参数是Json::Value类型的http api(可以支持多级嵌套的json参数对象)
|
||||
void api_regist(const string &api_path, const function<void(API_ARGS_JSON)> &func);
|
||||
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_JSON)> &func);
|
||||
//注册http请求参数是Json::Value类型,但是可以异步回复的的http api
|
||||
void api_regist(const string &api_path, const function<void(API_ARGS_JSON_ASYNC)> &func);
|
||||
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_JSON_ASYNC)> &func);
|
||||
|
||||
//注册http请求参数是http原始请求信息的http api
|
||||
void api_regist(const string &api_path, const function<void(API_ARGS_STRING)> &func);
|
||||
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_STRING)> &func);
|
||||
//注册http请求参数是http原始请求信息的异步回复的http api
|
||||
void api_regist(const string &api_path, const function<void(API_ARGS_STRING_ASYNC)> &func);
|
||||
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_STRING_ASYNC)> &func);
|
||||
|
||||
template<typename Args, typename First>
|
||||
bool checkArgs(Args &args, const First &first) {
|
||||
@@ -234,9 +229,9 @@ bool checkArgs(Args &args, const First &first, const KeyTypes &...keys) {
|
||||
|
||||
void installWebApi();
|
||||
void unInstallWebApi();
|
||||
Value makeMediaSourceJson(MediaSource &media);
|
||||
void getStatisticJson(const function<void(Value &val)> &cb);
|
||||
void addStreamProxy(const string &vhost, const string &app, const string &stream, const string &url, int retry_count,
|
||||
Json::Value makeMediaSourceJson(mediakit::MediaSource &media);
|
||||
void getStatisticJson(const std::function<void(Json::Value &val)> &cb);
|
||||
void addStreamProxy(const std::string &vhost, const std::string &app, const std::string &stream, const std::string &url, int retry_count,
|
||||
bool enable_hls, bool enable_mp4, int rtp_type, float timeout_sec,
|
||||
const function<void(const SockException &ex, const string &key)> &cb);
|
||||
const std::function<void(const toolkit::SockException &ex, const std::string &key)> &cb);
|
||||
#endif //ZLMEDIAKIT_WEBAPI_H
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "WebHook.h"
|
||||
#include "WebApi.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Json;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
|
||||
@@ -14,21 +14,19 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include "jsoncpp/json.h"
|
||||
using namespace std;
|
||||
using namespace Json;
|
||||
|
||||
//支持json或urlencoded方式传输参数
|
||||
#define JSON_ARGS
|
||||
|
||||
#ifdef JSON_ARGS
|
||||
typedef Value ArgsType;
|
||||
typedef Json::Value ArgsType;
|
||||
#else
|
||||
typedef HttpArgs ArgsType;
|
||||
typedef mediakit::HttpArgs ArgsType;
|
||||
#endif
|
||||
|
||||
namespace Hook {
|
||||
//web hook回复最大超时时间
|
||||
extern const string kTimeoutSec;
|
||||
extern const std::string kTimeoutSec;
|
||||
}//namespace Hook
|
||||
|
||||
void installWebHook();
|
||||
@@ -39,5 +37,5 @@ void unInstallWebHook();
|
||||
* @param body 请求body
|
||||
* @param func 回调
|
||||
*/
|
||||
void do_http_hook(const string &url, const ArgsType &body, const function<void(const Value &, const string &)> &func = nullptr);
|
||||
void do_http_hook(const std::string &url, const ArgsType &body, const std::function<void(const Json::Value &, const std::string &)> &func = nullptr);
|
||||
#endif //ZLMEDIAKIT_WEBHOOK_H
|
||||
|
||||
Reference in New Issue
Block a user