整理命名空间 (#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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
239 changed files with 1887 additions and 1766 deletions

View File

@ -1,4 +1,4 @@
name: C/C++ CI
name: linux C/C++ CI
on: [push]

39
.github/workflows/macos.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: macos C/C++ CI
on: [push]
jobs:
build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: 下载submodule源码
run: git submodule update --init
# - name: 安装brew
# run: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#
# - name: brew安装依赖库(非必选)
# run: brew update && brew install cmake openssl sdl2 ffmpeg
# - name: 下载 SRTP
# uses: actions/checkout@v2
# with:
# repository: cisco/libsrtp
# fetch-depth: 1
# ref: v2.3.0
# path: 3rdpart/libsrtp
#
# - name: 编译 SRTP
# run: cd 3rdpart/libsrtp && ./configure --enable-openssl && make -j4 && sudo make install
- name: 编译
run: mkdir -p build && cd build && cmake .. && make -j4
- name: 运行MediaServer
run: pwd && cd release/linux/Debug && sudo ./MediaServer -d &

@ -1 +1 @@
Subproject commit 25062620233c62475aaffc0a9960e2689d8418ce
Subproject commit b49676057e05bed1b43070c99bc4e541f2302526

View File

@ -14,6 +14,8 @@
#include "Http/HttpSession.h"
#include "Rtsp/RtspSession.h"
#include "Record/MP4Recorder.h"
using namespace toolkit;
using namespace mediakit;
static void* s_tag;

View File

@ -16,6 +16,8 @@
#include "Http/HttpBody.h"
#include "Http/HttpClient.h"
#include "Rtsp/RtspSession.h"
using namespace toolkit;
using namespace mediakit;
///////////////////////////////////////////RecordInfo/////////////////////////////////////////////
@ -247,7 +249,7 @@ API_EXPORT mk_http_body API_CALL mk_http_body_from_string(const char *str, size_
if(!len){
len = strlen(str);
}
return new HttpBody::Ptr(new HttpStringBody(string(str,len)));
return new HttpBody::Ptr(new HttpStringBody(std::string(str, len)));
}
API_EXPORT mk_http_body API_CALL mk_http_body_from_file(const char *file_path){

View File

@ -15,7 +15,7 @@ using namespace mediakit;
class H264Splitter : public HttpRequestSplitter {
public:
using onH264 = function<void(const char *data, size_t len)>;
using onH264 = std::function<void(const char *data, size_t len)>;
H264Splitter() = default;
~H264Splitter() override;
void setOnSplitted(onH264 cb);

View File

@ -29,7 +29,7 @@ API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx) {
API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const char *key, const char *val){
assert(ctx && key && val);
PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
string key_str(key),val_str(val);
std::string key_str(key), val_str(val);
obj->getPoller()->async([obj,key_str,val_str](){
//切换线程再操作
(*obj)[key_str] = val_str;
@ -39,7 +39,7 @@ API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const c
API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *url) {
assert(ctx && url);
PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
string url_str(url);
std::string url_str(url);
obj->getPoller()->async([obj,url_str](){
//切换线程再操作
obj->play(url_str);

View File

@ -11,6 +11,8 @@
#include <assert.h>
#include "mk_pusher.h"
#include "Pusher/MediaPusher.h"
using namespace toolkit;
using namespace mediakit;
API_EXPORT mk_pusher API_CALL mk_pusher_create(const char *schema,const char *vhost,const char *app, const char *stream){
@ -35,7 +37,7 @@ API_EXPORT void API_CALL mk_pusher_release(mk_pusher ctx){
API_EXPORT void API_CALL mk_pusher_set_option(mk_pusher ctx, const char *key, const char *val){
assert(ctx && key && val);
MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
string key_str(key),val_str(val);
std::string key_str(key), val_str(val);
obj->getPoller()->async([obj,key_str,val_str](){
//切换线程再操作
(*obj)[key_str] = val_str;
@ -45,7 +47,7 @@ API_EXPORT void API_CALL mk_pusher_set_option(mk_pusher ctx, const char *key, co
API_EXPORT void API_CALL mk_pusher_publish(mk_pusher ctx,const char *url){
assert(ctx && url);
MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
string url_str(url);
std::string url_str(url);
obj->getPoller()->async([obj,url_str](){
//切换线程再操作
obj->publish(url_str);

View File

@ -13,6 +13,8 @@
#include "mk_tcp_private.h"
#include "Http/WebSocketClient.h"
#include "Http/WebSocketSession.h"
using namespace toolkit;
using namespace mediakit;
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx, char *buf){
@ -66,8 +68,8 @@ API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx,const
len = strlen(data);
}
try {
weak_ptr<TcpSession> weak_session = ((TcpSessionForC *)ctx)->shared_from_this();
string str = string(data,len);
std::weak_ptr<TcpSession> weak_session = ((TcpSessionForC *)ctx)->shared_from_this();
std::string str = std::string(data,len);
((TcpSessionForC *)ctx)->async([weak_session,str](){
auto session_session = weak_session.lock();
if(session_session){
@ -208,13 +210,13 @@ TcpClientForC::Ptr *mk_tcp_client_create_l(mk_tcp_client_events *events, mk_tcp_
case mk_type_tcp:
return new TcpClientForC::Ptr(new TcpClientForC(events));
case mk_type_ssl:
return (TcpClientForC::Ptr *)new shared_ptr<TcpSessionWithSSL<TcpClientForC> >(new TcpSessionWithSSL<TcpClientForC>(events));
return (TcpClientForC::Ptr *)new std::shared_ptr<TcpSessionWithSSL<TcpClientForC> >(new TcpSessionWithSSL<TcpClientForC>(events));
case mk_type_ws:
//此处你也可以修改WebSocketHeader::BINARY
return (TcpClientForC::Ptr *)new shared_ptr<WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, false> >(new WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, false>(events));
return (TcpClientForC::Ptr *)new std::shared_ptr<WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, false> >(new WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, false>(events));
case mk_type_wss:
//此处你也可以修改WebSocketHeader::BINARY
return (TcpClientForC::Ptr *)new shared_ptr<WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, true> >(new WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, true>(events));
return (TcpClientForC::Ptr *)new std::shared_ptr<WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, true> >(new WebSocketClient<TcpClientForC, WebSocketHeader::TEXT, true>(events));
default:
return nullptr;
}
@ -253,7 +255,7 @@ API_EXPORT void API_CALL mk_tcp_client_send(mk_tcp_client ctx, const char *data,
API_EXPORT void API_CALL mk_tcp_client_send_safe(mk_tcp_client ctx, const char *data, int len){
assert(ctx && data);
TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
weak_ptr<TcpClient> weakClient = *client;
std::weak_ptr<TcpClient> weakClient = *client;
auto buf = BufferRaw::create();
buf->assign(data,len);
(*client)->async([weakClient,buf](){

View File

@ -14,17 +14,16 @@
#include "mk_tcp.h"
#include "Network/TcpClient.h"
#include "Network/TcpSession.h"
using namespace toolkit;
class TcpClientForC : public TcpClient {
class TcpClientForC : public toolkit::TcpClient {
public:
typedef std::shared_ptr<TcpClientForC> Ptr;
TcpClientForC(mk_tcp_client_events *events) ;
~TcpClientForC() override ;
void onRecv(const Buffer::Ptr &pBuf) override;
void onErr(const SockException &ex) override;
void onRecv(const toolkit::Buffer::Ptr &pBuf) override;
void onErr(const toolkit::SockException &ex) override;
void onManager() override;
void onConnect(const SockException &ex) override;
void onConnect(const toolkit::SockException &ex) override;
void setClient(mk_tcp_client client);
void *_user_data;
private:
@ -32,12 +31,12 @@ private:
mk_tcp_client _client;
};
class TcpSessionForC : public TcpSession {
class TcpSessionForC : public toolkit::TcpSession {
public:
TcpSessionForC(const Socket::Ptr &pSock) ;
TcpSessionForC(const toolkit::Socket::Ptr &pSock) ;
~TcpSessionForC() override = default;
void onRecv(const Buffer::Ptr &buffer) override ;
void onError(const SockException &err) override;
void onRecv(const toolkit::Buffer::Ptr &buffer) override ;
void onError(const toolkit::SockException &err) override;
void onManager() override;
void *_user_data;
uint16_t _local_port;

View File

@ -91,7 +91,7 @@ private:
on_mk_timer _cb = nullptr;
void *_user_data = nullptr;
recursive_mutex _mxt;
DelayTask::Ptr _task;
EventPoller::DelayTask::Ptr _task;
};
API_EXPORT mk_timer API_CALL mk_timer_create(mk_thread ctx,uint64_t delay_ms,on_mk_timer cb, void *user_data){

View File

@ -8,10 +8,13 @@
* may be found in the AUTHORS file in the root of the source tree.
*/
#include <cstdarg>
#include <cassert>
#include "mk_util.h"
#include <assert.h>
#include "Util/util.h"
#include "Util/logger.h"
using namespace std;
using namespace toolkit;

View File

@ -30,9 +30,6 @@ extern "C" {
#include "SDLAudioDevice.h"
#include "FFMpegDecoder.h"
using namespace std;
using namespace toolkit;
class AudioSRCDelegate {
public:
virtual ~AudioSRCDelegate() {};
@ -58,7 +55,7 @@ private:
int _buf_size = 0;
std::shared_ptr<char> _buf;
AudioSRCDelegate *_delegate = nullptr;
BufferLikeString _target_buf;
toolkit::BufferLikeString _target_buf;
SDL_AudioCVT _audio_cvt;
};
@ -79,8 +76,8 @@ private:
private:
int _sample_rate, _channel;
SDL_AudioFormat _format;
mutex _mtx;
BufferLikeString _buffer;
std::mutex _mtx;
toolkit::BufferLikeString _buffer;
SDLAudioDevice::Ptr _device;
};

View File

@ -12,6 +12,7 @@
#define MAX_DELAY_SECOND 3
using namespace std;
using namespace toolkit;
using namespace mediakit;
static string ffmpeg_err(int errnum) {

View File

@ -60,15 +60,15 @@ public:
~TaskManager();
protected:
void startThread(const string &name);
void startThread(const std::string &name);
void stopThread();
void addEncodeTask(function<void()> task);
void addDecodeTask(bool key_frame, function<void()> task);
void addEncodeTask(std::function<void()> task);
void addDecodeTask(bool key_frame, std::function<void()> task);
bool isEnabled() const;
private:
void onThreadRun(const string &name);
void onThreadRun(const std::string &name);
void pushExit();
private:
@ -81,36 +81,36 @@ private:
private:
bool _decode_drop_start = false;
bool _exit = false;
mutex _task_mtx;
semaphore _sem;
List<function<void()> > _task;
std::shared_ptr<thread> _thread;
std::mutex _task_mtx;
toolkit::semaphore _sem;
toolkit::List<std::function<void()> > _task;
std::shared_ptr<std::thread> _thread;
};
class FFmpegDecoder : private TaskManager {
public:
using Ptr = std::shared_ptr<FFmpegDecoder>;
using onDec = function<void(const FFmpegFrame::Ptr &)>;
using onDec = std::function<void(const FFmpegFrame::Ptr &)>;
FFmpegDecoder(const Track::Ptr &track);
FFmpegDecoder(const mediakit::Track::Ptr &track);
~FFmpegDecoder();
bool inputFrame(const Frame::Ptr &frame, bool may_async = true);
bool inputFrame(const mediakit::Frame::Ptr &frame, bool may_async = true);
void setOnDecode(onDec cb);
void flush();
const AVCodecContext *getContext() const;
private:
void onDecode(const FFmpegFrame::Ptr &frame);
bool inputFrame_l(const Frame::Ptr &frame);
bool inputFrame_l(const mediakit::Frame::Ptr &frame);
bool decodeFrame(const char *data, size_t size, uint32_t dts, uint32_t pts);
private:
bool _do_merger = false;
Ticker _ticker;
toolkit::Ticker _ticker;
onDec _cb;
std::shared_ptr<AVCodecContext> _context;
FrameMerger _merger{FrameMerger::h264_prefix};
mediakit::FrameMerger _merger { mediakit::FrameMerger::h264_prefix };
};
#endif /* FFMpegDecoder_H_ */

View File

@ -21,7 +21,6 @@
#define DEFAULT_CHANNEL 2
#define DEFAULT_SAMPLES 1024
using namespace std;
class AudioSRC;
@ -43,8 +42,8 @@ private:
private:
std::shared_ptr<char> _play_buf;
SDL_AudioSpec _audio_config;
recursive_mutex _channel_mtx;
unordered_set<AudioSRC *> _channels;
std::recursive_mutex _channel_mtx;
std::unordered_set<AudioSRC *> _channels;
};
#endif /* SDLAUDIOMIXER_SDLAUDIODEVICE_H_ */

View File

@ -25,12 +25,8 @@ extern "C" {
#pragma comment(lib,"SDL2.lib")
#endif //defined(_WIN32)
using namespace toolkit;
using namespace mediakit;
#define REFRESH_EVENT (SDL_USEREVENT + 1)
class SDLDisplayerHelper
{
public:
@ -44,7 +40,7 @@ public:
template<typename FUN>
void doTask(FUN &&f){
{
lock_guard<mutex> lck(_mtxTask);
std::lock_guard<std::mutex> lck(_mtxTask);
_taskList.emplace_back(f);
}
SDL_Event event;
@ -61,7 +57,7 @@ public:
switch (event.type){
case REFRESH_EVENT:{
{
lock_guard<mutex> lck(_mtxTask);
std::lock_guard<std::mutex> lck(_mtxTask);
if (_taskList.empty()) {
//not reachable
continue;
@ -102,9 +98,9 @@ public:
using Ptr = std::shared_ptr<YuvDisplayer>;
YuvDisplayer(void *hwnd = nullptr,const char *title = "untitled"){
static onceToken token([]() {
static toolkit::onceToken token([]() {
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) == -1) {
string err = "初始化SDL失败:";
std::string err = "初始化SDL失败:";
err+= SDL_GetError();
ErrorL << err;
throw std::runtime_error(err);
@ -194,7 +190,7 @@ public:
return false;
}
private:
string _title;
std::string _title;
SDL_Window *_win = nullptr;
SDL_Renderer *_render = nullptr;
SDL_Texture *_texture = nullptr;

View File

@ -116,7 +116,7 @@ int main(int argc, char *argv[]) {
WarnL << "play shutdown: " << ex.what();
});
(*player)[kRtpType] = atoi(argv[2]);
(*player)[Client::kRtpType] = atoi(argv[2]);
//不等待track ready再回调播放成功事件这样可以加快秒开速度
(*player)[Client::kWaitTrackReady] = false;
player->play(argv[1]);

View File

@ -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";

View File

@ -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;
};

View File

@ -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);

View File

@ -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();

View File

@ -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

View File

@ -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();
};

View File

@ -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;
}
//开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试

View File

@ -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

View File

@ -21,6 +21,8 @@
#include "WebHook.h"
#include "WebApi.h"
using namespace std;
using namespace Json;
using namespace toolkit;
using namespace mediakit;

View File

@ -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

View File

@ -24,6 +24,7 @@
#include "Codec/H264Encoder.h"
#endif //ENABLE_X264
using namespace toolkit;
using namespace std;
namespace mediakit {

View File

@ -17,8 +17,6 @@
#include "Util/util.h"
#include "Util/TimeTicker.h"
#include "Common/MultiMediaSourceMuxer.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
@ -48,7 +46,7 @@ class DevChannel : public MultiMediaSourceMuxer{
public:
typedef std::shared_ptr<DevChannel> Ptr;
//fDuration<=0为直播否则为点播
DevChannel(const string &vhost, const string &app, const string &stream_id,
DevChannel(const std::string &vhost, const std::string &app, const std::string &stream_id,
float duration = 0, bool enable_hls = true, bool enable_mp4 = false);
~DevChannel() override ;
@ -126,7 +124,7 @@ private:
std::shared_ptr<AACEncoder> _pAacEnc;
std::shared_ptr<VideoInfo> _video;
std::shared_ptr<AudioInfo> _audio;
SmoothTicker _aTicker[2];
toolkit::SmoothTicker _aTicker[2];
};
} /* namespace mediakit */

View File

@ -11,6 +11,8 @@
#include "MediaSink.h"
#include "Extension/AAC.h"
using namespace std;
namespace mediakit{
bool MediaSink::addTrack(const Track::Ptr &track_in) {

View File

@ -17,9 +17,6 @@
#include "Extension/Frame.h"
#include "Extension/Track.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
class TrackListener {
@ -106,7 +103,7 @@ public:
* Track
* @param trackReady Track
*/
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
std::vector<Track::Ptr> getTracks(bool trackReady = true) const override;
/**
* track已经准备完成
@ -154,10 +151,10 @@ private:
private:
bool _all_track_ready = false;
size_t _max_track_size = 2;
unordered_map<int, pair<Track::Ptr, bool/*got frame*/> > _track_map;
unordered_map<int, List<Frame::Ptr> > _frame_unread;
unordered_map<int, function<void()> > _track_ready_callback;
Ticker _ticker;
std::unordered_map<int, std::pair<Track::Ptr, bool/*got frame*/> > _track_map;
std::unordered_map<int, toolkit::List<Frame::Ptr> > _frame_unread;
std::unordered_map<int, std::function<void()> > _track_ready_callback;
toolkit::Ticker _ticker;
MuteAudioMaker::Ptr _mute_audio_maker;
};

View File

@ -13,6 +13,8 @@
#include "Util/util.h"
#include "Network/sockutil.h"
#include "Network/TcpSession.h"
using namespace std;
using namespace toolkit;
namespace toolkit {

View File

@ -29,9 +29,6 @@
#include "Extension/Track.h"
#include "Record/Recorder.h"
using namespace std;
using namespace toolkit;
namespace toolkit{
class Session;
}// namespace toolkit
@ -50,7 +47,7 @@ enum class MediaOriginType : uint8_t {
rtc_push,
};
string getOriginTypeString(MediaOriginType type);
std::string getOriginTypeString(MediaOriginType type);
class MediaSource;
class MediaSourceEvent{
@ -62,9 +59,9 @@ public:
// 获取媒体源类型
virtual MediaOriginType getOriginType(MediaSource &sender) const { return MediaOriginType::unknown; }
// 获取媒体源url或者文件路径
virtual string getOriginUrl(MediaSource &sender) const;
virtual std::string getOriginUrl(MediaSource &sender) const;
// 获取媒体源客户端相关信息
virtual std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const { return nullptr; }
virtual std::shared_ptr<toolkit::SockInfo> getOriginSock(MediaSource &sender) const { return nullptr; }
// 通知拖动进度条
virtual bool seekTo(MediaSource &sender, uint32_t stamp) { return false; }
@ -83,18 +80,18 @@ public:
////////////////////////仅供MultiMediaSourceMuxer对象继承////////////////////////
// 开启或关闭录制
virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) { return false; };
virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) { return false; };
// 获取录制状态
virtual bool isRecording(MediaSource &sender, Recorder::type type) { return false; };
// 获取所有track相关信息
virtual vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const { return vector<Track::Ptr>(); };
virtual std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const { return std::vector<Track::Ptr>(); };
// 开始发送ps-rtp
virtual void startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb) { cb(0, SockException(Err_other, "not implemented"));};
virtual void startSendRtp(MediaSource &sender, const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb) { cb(0, toolkit::SockException(toolkit::Err_other, "not implemented"));};
// 停止发送ps-rtp
virtual bool stopSendRtp(MediaSource &sender, const string &ssrc) {return false; }
virtual bool stopSendRtp(MediaSource &sender, const std::string &ssrc) {return false; }
private:
Timer::Ptr _async_close_timer;
toolkit::Timer::Ptr _async_close_timer;
};
//该对象用于拦截感兴趣的MediaSourceEvent事件
@ -107,8 +104,8 @@ public:
std::shared_ptr<MediaSourceEvent> getDelegate() const;
MediaOriginType getOriginType(MediaSource &sender) const override;
string getOriginUrl(MediaSource &sender) const override;
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
std::string getOriginUrl(MediaSource &sender) const override;
std::shared_ptr<toolkit::SockInfo> getOriginSock(MediaSource &sender) const override;
bool seekTo(MediaSource &sender, uint32_t stamp) override;
bool pause(MediaSource &sender, bool pause) override;
@ -117,11 +114,11 @@ public:
int totalReaderCount(MediaSource &sender) override;
void onReaderChanged(MediaSource &sender, int size) override;
void onRegist(MediaSource &sender, bool regist) override;
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) override;
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) override;
bool isRecording(MediaSource &sender, Recorder::type type) override;
vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
void startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb) override;
bool stopSendRtp(MediaSource &sender, const string &ssrc) override;
std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
void startSendRtp(MediaSource &sender, const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb) override;
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
private:
std::weak_ptr<MediaSourceEvent> _listener;
@ -134,18 +131,18 @@ class MediaInfo{
public:
~MediaInfo() {}
MediaInfo() {}
MediaInfo(const string &url) { parse(url); }
void parse(const string &url);
MediaInfo(const std::string &url) { parse(url); }
void parse(const std::string &url);
public:
string _full_url;
string _schema;
string _host;
string _port;
string _vhost;
string _app;
string _streamid;
string _param_strs;
std::string _full_url;
std::string _schema;
std::string _host;
std::string _port;
std::string _vhost;
std::string _app;
std::string _streamid;
std::string _param_strs;
};
class BytesSpeed {
@ -191,40 +188,40 @@ private:
private:
int _speed = 0;
size_t _bytes = 0;
Ticker _ticker;
toolkit::Ticker _ticker;
};
/**
* rtsp/rtmp的直播流都源自该对象
*/
class MediaSource: public TrackSource, public enable_shared_from_this<MediaSource> {
class MediaSource: public TrackSource, public std::enable_shared_from_this<MediaSource> {
public:
static MediaSource * const NullMediaSource;
using Ptr = std::shared_ptr<MediaSource>;
using StreamMap = unordered_map<string/*strema_id*/, weak_ptr<MediaSource> >;
using AppStreamMap = unordered_map<string/*app*/, StreamMap>;
using VhostAppStreamMap = unordered_map<string/*vhost*/, AppStreamMap>;
using SchemaVhostAppStreamMap = unordered_map<string/*schema*/, VhostAppStreamMap>;
using StreamMap = std::unordered_map<std::string/*strema_id*/, std::weak_ptr<MediaSource> >;
using AppStreamMap = std::unordered_map<std::string/*app*/, StreamMap>;
using VhostAppStreamMap = std::unordered_map<std::string/*vhost*/, AppStreamMap>;
using SchemaVhostAppStreamMap = std::unordered_map<std::string/*schema*/, VhostAppStreamMap>;
MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id) ;
MediaSource(const std::string &schema, const std::string &vhost, const std::string &app, const std::string &stream_id) ;
virtual ~MediaSource();
////////////////获取MediaSource相关信息////////////////
// 获取协议类型
const string& getSchema() const;
const std::string& getSchema() const;
// 虚拟主机
const string& getVhost() const;
const std::string& getVhost() const;
// 应用名
const string& getApp() const;
const std::string& getApp() const;
// 流id
const string& getId() const;
const std::string& getId() const;
//获取对象所有权
std::shared_ptr<void> getOwnership();
// 获取所有Track
vector<Track::Ptr> getTracks(bool ready = true) const override;
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
// 获取流当前时间戳
virtual uint32_t getTimeStamp(TrackType type) { return 0; };
@ -253,9 +250,9 @@ public:
// 获取媒体源类型
MediaOriginType getOriginType() const;
// 获取媒体源url或者文件路径
string getOriginUrl() const;
std::string getOriginUrl() const;
// 获取媒体源客户端相关信息
std::shared_ptr<SockInfo> getOriginSock() const;
std::shared_ptr<toolkit::SockInfo> getOriginSock() const;
// 拖动进度条
bool seekTo(uint32_t stamp);
@ -268,28 +265,28 @@ public:
// 该流观看人数变化
void onReaderChanged(int size);
// 开启或关闭录制
bool setupRecord(Recorder::type type, bool start, const string &custom_path, size_t max_second);
bool setupRecord(Recorder::type type, bool start, const std::string &custom_path, size_t max_second);
// 获取录制状态
bool isRecording(Recorder::type type);
// 开始发送ps-rtp
void startSendRtp(const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb);
void startSendRtp(const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb);
// 停止发送ps-rtp
bool stopSendRtp(const string &ssrc);
bool stopSendRtp(const std::string &ssrc);
////////////////static方法查找或生成MediaSource////////////////
// 同步查找流
static Ptr find(const string &schema, const string &vhost, const string &app, const string &id, bool from_mp4 = false);
static Ptr find(const std::string &schema, const std::string &vhost, const std::string &app, const std::string &id, bool from_mp4 = false);
// 忽略类型同步查找流可能返回rtmp/rtsp/hls类型
static Ptr find(const string &vhost, const string &app, const string &stream_id, bool from_mp4 = false);
static Ptr find(const std::string &vhost, const std::string &app, const std::string &stream_id, bool from_mp4 = false);
// 异步查找流
static void findAsync(const MediaInfo &info, const std::shared_ptr<Session> &session, const function<void(const Ptr &src)> &cb);
static void findAsync(const MediaInfo &info, const std::shared_ptr<toolkit::Session> &session, const std::function<void(const Ptr &src)> &cb);
// 遍历所有流
static void for_each_media(const function<void(const Ptr &src)> &cb, const string &schema = "", const string &vhost = "", const string &app = "", const string &stream = "");
static void for_each_media(const std::function<void(const Ptr &src)> &cb, const std::string &schema = "", const std::string &vhost = "", const std::string &app = "", const std::string &stream = "");
// 从mp4文件生成MediaSource
static MediaSource::Ptr createFromMP4(const string &schema, const string &vhost, const string &app, const string &stream, const string &file_path = "", bool check_app = true);
static MediaSource::Ptr createFromMP4(const std::string &schema, const std::string &vhost, const std::string &app, const std::string &stream, const std::string &file_path = "", bool check_app = true);
protected:
//媒体注册
@ -305,16 +302,16 @@ protected:
BytesSpeed _speed[TrackMax];
private:
atomic_flag _owned { false };
std::atomic_flag _owned { false };
time_t _create_stamp;
Ticker _ticker;
string _schema;
string _vhost;
string _app;
string _stream_id;
toolkit::Ticker _ticker;
std::string _schema;
std::string _vhost;
std::string _app;
std::string _stream_id;
std::weak_ptr<MediaSourceEvent> _listener;
//对象个数统计
ObjectStatistic<MediaSource> _statistic;
toolkit::ObjectStatistic<MediaSource> _statistic;
};
///缓存刷新策略类
@ -333,7 +330,7 @@ private:
/// \tparam packet 包类型
/// \tparam policy 刷新缓存策略
/// \tparam packet_list 包缓存类型
template<typename packet, typename policy = FlushPolicy, typename packet_list = List<std::shared_ptr<packet> > >
template<typename packet, typename policy = FlushPolicy, typename packet_list = toolkit::List<std::shared_ptr<packet> > >
class PacketCache {
public:
PacketCache(){

View File

@ -12,6 +12,9 @@
#include "Common/config.h"
#include "MultiMediaSourceMuxer.h"
using namespace std;
using namespace toolkit;
namespace toolkit {
StatisticImp(mediakit::MultiMediaSourceMuxer);
}

View File

@ -35,7 +35,7 @@ public:
};
~MultiMediaSourceMuxer() override = default;
MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec = 0.0,
MultiMediaSourceMuxer(const std::string &vhost, const std::string &app, const std::string &stream, float dur_sec = 0.0,
bool enable_rtsp = true, bool enable_rtmp = true, bool enable_hls = true, bool enable_mp4 = false);
/**
@ -87,7 +87,7 @@ public:
* @param custom_path
* @return
*/
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) override;
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) override;
/**
*
@ -104,20 +104,20 @@ public:
* @param is_udp udp
* @param cb
*/
void startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb) override;
void startSendRtp(MediaSource &sender, const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb) override;
/**
* ps-rtp发送
* @return
*/
bool stopSendRtp(MediaSource &sender, const string &ssrc) override;
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
/**
* Track
* @param trackReady track
* @return Track
*/
vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
protected:
/////////////////////////////////MediaSink override/////////////////////////////////
@ -142,13 +142,13 @@ protected:
private:
bool _is_enable = false;
Ticker _last_check;
toolkit::Ticker _last_check;
Stamp _stamp[2];
std::weak_ptr<Listener> _track_listener;
function<string()> _get_origin_url;
std::function<std::string()> _get_origin_url;
#if defined(ENABLE_RTPPROXY)
mutex _rtp_sender_mtx;
unordered_map<string, RtpSender::Ptr> _rtp_sender;
std::mutex _rtp_sender_mtx;
std::unordered_map<std::string, RtpSender::Ptr> _rtp_sender;
#endif //ENABLE_RTPPROXY
#if defined(ENABLE_MP4)
@ -161,7 +161,7 @@ private:
HlsRecorder::Ptr _hls;
//对象个数统计
ObjectStatistic<MultiMediaSourceMuxer> _statistic;
toolkit::ObjectStatistic<MultiMediaSourceMuxer> _statistic;
};
}//namespace mediakit

View File

@ -10,6 +10,9 @@
#include "Parser.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
string FindField(const char* buf, const char* start, const char *end ,size_t bufSize) {

View File

@ -15,26 +15,23 @@
#include <string>
#include "Util/util.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
string FindField(const char *buf, const char *start, const char *end, size_t bufSize = 0);
std::string FindField(const char *buf, const char *start, const char *end, size_t bufSize = 0);
struct StrCaseCompare {
bool operator()(const string &__x, const string &__y) const {
bool operator()(const std::string &__x, const std::string &__y) const {
return strcasecmp(__x.data(), __y.data()) < 0;
}
};
class StrCaseMap : public multimap<string, string, StrCaseCompare> {
class StrCaseMap : public std::multimap<std::string, std::string, StrCaseCompare> {
public:
using Super = multimap<string, string, StrCaseCompare>;
using Super = multimap<std::string, std::string, StrCaseCompare>;
StrCaseMap() = default;
~StrCaseMap() = default;
string &operator[](const string &k) {
std::string &operator[](const std::string &k) {
auto it = find(k);
if (it == end()) {
it = Super::emplace(k, "");
@ -43,7 +40,7 @@ public:
}
template<typename V>
void emplace(const string &k, V &&v) {
void emplace(const std::string &k, V &&v) {
auto it = find(k);
if (it != end()) {
return;
@ -52,7 +49,7 @@ public:
}
template<typename V>
void emplace_force(const string k, V &&v) {
void emplace_force(const std::string k, V &&v) {
Super::emplace(k, std::forward<V>(v));
}
};
@ -67,34 +64,34 @@ public:
void Parse(const char *buf);
//获取命令字
const string &Method() const;
const std::string &Method() const;
//获取中间url不包含?后面的参数
const string &Url() const;
const std::string &Url() const;
//获取中间url包含?后面的参数
string FullUrl() const;
std::string FullUrl() const;
//获取命令协议名
const string &Tail() const;
const std::string &Tail() const;
//根据header key名获取请求header value值
const string &operator[](const char *name) const;
const std::string &operator[](const char *name) const;
//获取http body或sdp
const string &Content() const;
const std::string &Content() const;
//清空,为了重用
void Clear();
//获取?后面的参数
const string &Params() const;
const std::string &Params() const;
//重新设置url
void setUrl(string url);
void setUrl(std::string url);
//重新设置content
void setContent(string content);
void setContent(std::string content);
//获取header列表
StrCaseMap &getHeader() const;
@ -103,15 +100,15 @@ public:
StrCaseMap &getUrlArgs() const;
//解析?后面的参数
static StrCaseMap parseArgs(const string &str, const char *pair_delim = "&", const char *key_delim = "=");
static StrCaseMap parseArgs(const std::string &str, const char *pair_delim = "&", const char *key_delim = "=");
private:
string _strMethod;
string _strUrl;
string _strTail;
string _strContent;
string _strNull;
string _params;
std::string _strMethod;
std::string _strUrl;
std::string _strTail;
std::string _strContent;
std::string _strNull;
std::string _params;
mutable StrCaseMap _mapHeaders;
mutable StrCaseMap _mapUrlArgs;
};

View File

@ -16,6 +16,8 @@
#define MAX_CTS 500
#define ABS(x) ((x) > 0 ? (x) : (-x))
using namespace toolkit;
namespace mediakit {
int64_t DeltaStamp::deltaStamp(int64_t stamp) {

View File

@ -14,7 +14,6 @@
#include <set>
#include <cstdint>
#include "Util/TimeTicker.h"
using namespace toolkit;
namespace mediakit {
@ -87,7 +86,7 @@ private:
int64_t _last_dts_in = 0;
int64_t _last_dts_out = 0;
int64_t _last_pts_out = 0;
SmoothTicker _ticker;
toolkit::SmoothTicker _ticker;
bool _playback = false;
Stamp *_sync_master = nullptr;
};
@ -111,7 +110,7 @@ private:
size_t _frames_since_last_max_pts = 0;
size_t _sorter_max_size = 0;
size_t _count_sorter_max_size = 0;
set<uint32_t> _pts_sorter;
std::set<uint32_t> _pts_sorter;
};
class NtpStamp {

View File

@ -15,6 +15,7 @@
#include "Util/onceToken.h"
#include "Util/NoticeCenter.h"
using namespace std;
using namespace toolkit;
namespace mediakit {

View File

@ -18,9 +18,6 @@
#include "Util/NoticeCenter.h"
#include "macros.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
//加载配置文件,如果配置文件不存在,那么会导出默认配置并生成配置文件
@ -34,81 +31,81 @@ bool loadIniConfig(const char *ini_path = nullptr);
namespace Broadcast {
//注册或反注册MediaSource事件广播
extern const string kBroadcastMediaChanged;
extern const std::string kBroadcastMediaChanged;
#define BroadcastMediaChangedArgs const bool &bRegist, MediaSource &sender
//录制mp4文件成功后广播
extern const string kBroadcastRecordMP4;
extern const std::string kBroadcastRecordMP4;
#define BroadcastRecordMP4Args const RecordInfo &info
// 录制 ts 文件后广播
extern const string kBroadcastRecordTs;
extern const std::string kBroadcastRecordTs;
#define BroadcastRecordTsArgs const RecordInfo &info
//收到http api请求广播
extern const string kBroadcastHttpRequest;
extern const std::string kBroadcastHttpRequest;
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,SockInfo &sender
//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
extern const string kBroadcastHttpAccess;
#define BroadcastHttpAccessArgs const Parser &parser,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
extern const std::string kBroadcastHttpAccess;
#define BroadcastHttpAccessArgs const Parser &parser,const std::string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
//在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
//在该事件中通过自行覆盖path参数可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
extern const string kBroadcastHttpBeforeAccess;
#define BroadcastHttpBeforeAccessArgs const Parser &parser,string &path,SockInfo &sender
extern const std::string kBroadcastHttpBeforeAccess;
#define BroadcastHttpBeforeAccessArgs const Parser &parser, std::string &path, SockInfo &sender
//该流是否需要认证是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证
extern const string kBroadcastOnGetRtspRealm;
extern const std::string kBroadcastOnGetRtspRealm;
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,SockInfo &sender
//请求认证用户密码事件user_name为用户名must_no_encrypt如果为true则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
//获取到密码后请调用invoker并输入对应类型的密码和密码类型invoker执行时会匹配密码
extern const string kBroadcastOnRtspAuth;
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const string &realm,const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,SockInfo &sender
extern const std::string kBroadcastOnRtspAuth;
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const std::string &realm,const std::string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,SockInfo &sender
//推流鉴权结果回调对象
//如果errMessage为空则代表鉴权成功
//enableHls: 是否允许转换hls
//enableMP4: 是否运行MP4录制
typedef std::function<void(const string &errMessage, bool enableHls, bool enableMP4)> PublishAuthInvoker;
typedef std::function<void(const std::string &errMessage, bool enableHls, bool enableMP4)> PublishAuthInvoker;
//收到rtsp/rtmp推流事件广播通过该事件控制推流鉴权
extern const string kBroadcastMediaPublish;
extern const std::string kBroadcastMediaPublish;
#define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
//播放鉴权结果回调对象
//如果errMessage为空则代表鉴权成功
typedef std::function<void(const string &errMessage)> AuthInvoker;
typedef std::function<void(const std::string &errMessage)> AuthInvoker;
//播放rtsp/rtmp/http-flv事件广播通过该事件控制播放鉴权
extern const string kBroadcastMediaPlayed;
extern const std::string kBroadcastMediaPlayed;
#define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,SockInfo &sender
//shell登录鉴权
extern const string kBroadcastShellLogin;
#define BroadcastShellLoginArgs const string &user_name,const string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
extern const std::string kBroadcastShellLogin;
#define BroadcastShellLoginArgs const std::string &user_name,const std::string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播
extern const string kBroadcastFlowReport;
extern const std::string kBroadcastFlowReport;
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer, SockInfo &sender
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
extern const string kBroadcastNotFoundStream;
#define BroadcastNotFoundStreamArgs const MediaInfo &args,SockInfo &sender, const function<void()> &closePlayer
extern const std::string kBroadcastNotFoundStream;
#define BroadcastNotFoundStreamArgs const MediaInfo &args, SockInfo &sender, const std::function<void()> &closePlayer
//某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑
extern const string kBroadcastStreamNoneReader;
extern const std::string kBroadcastStreamNoneReader;
#define BroadcastStreamNoneReaderArgs MediaSource &sender
//更新配置文件事件广播,执行loadIniConfig函数加载配置文件成功后会触发该广播
extern const string kBroadcastReloadConfig;
extern const std::string kBroadcastReloadConfig;
#define BroadcastReloadConfigArgs void
#define ReloadConfigTag ((void *)(0xFF))
#define RELOAD_KEY(arg,key) \
do { \
decltype(arg) arg##_tmp = mINI::Instance()[key]; \
decltype(arg) arg##_tmp = toolkit::mINI::Instance()[key]; \
if (arg == arg##_tmp) { \
return; \
} \
@ -119,8 +116,8 @@ extern const string kBroadcastReloadConfig;
//监听某个配置发送变更
#define LISTEN_RELOAD_KEY(arg, key, ...) \
do { \
static onceToken s_token_listen([](){ \
NoticeCenter::Instance().addListener(ReloadConfigTag, \
static toolkit::onceToken s_token_listen([](){ \
toolkit::NoticeCenter::Instance().addListener(ReloadConfigTag, \
Broadcast::kBroadcastReloadConfig,[](BroadcastReloadConfigArgs) { \
__VA_ARGS__; \
}); \
@ -128,7 +125,7 @@ extern const string kBroadcastReloadConfig;
} while(0)
#define GET_CONFIG(type, arg, key) \
static type arg = mINI::Instance()[key]; \
static type arg = toolkit::mINI::Instance()[key]; \
LISTEN_RELOAD_KEY(arg, key, { \
RELOAD_KEY(arg, key); \
});
@ -136,9 +133,9 @@ extern const string kBroadcastReloadConfig;
#define GET_CONFIG_FUNC(type, arg, key, ...) \
static type arg; \
do { \
static onceToken s_token_set([](){ \
static toolkit::onceToken s_token_set([](){ \
static auto lam = __VA_ARGS__ ; \
static auto arg##_str = mINI::Instance()[key]; \
static auto arg##_str = toolkit::mINI::Instance()[key]; \
arg = lam(arg##_str); \
LISTEN_RELOAD_KEY(arg, key, { \
RELOAD_KEY(arg##_str, key); \
@ -152,168 +149,168 @@ extern const string kBroadcastReloadConfig;
////////////通用配置///////////
namespace General{
//每个流媒体服务器的IDGUID
extern const string kMediaServerId;
extern const std::string kMediaServerId;
//流量汇报事件流量阈值,单位KB默认1MB
extern const string kFlowThreshold;
extern const std::string kFlowThreshold;
//流无人观看并且超过若干时间后才触发kBroadcastStreamNoneReader事件
//默认连续5秒无人观看然后触发kBroadcastStreamNoneReader事件
extern const string kStreamNoneReaderDelayMS;
extern const std::string kStreamNoneReaderDelayMS;
//等待流注册超时时间,收到播放器后请求后,如果未找到相关流,服务器会等待一定时间,
//如果在这个时间内,相关流注册上了,那么服务器会立即响应播放器播放成功,
//否则会最多等待kMaxStreamWaitTimeMS毫秒然后响应播放器播放失败
extern const string kMaxStreamWaitTimeMS;
extern const std::string kMaxStreamWaitTimeMS;
//是否启动虚拟主机
extern const string kEnableVhost;
extern const std::string kEnableVhost;
//拉流代理时是否添加静音音频
extern const string kAddMuteAudio;
extern const std::string kAddMuteAudio;
//拉流代理时如果断流再重连成功是否删除前一次的媒体流数据,如果删除将重新开始,
//如果不删除将会接着上一次的数据继续写(录制hls/mp4时会继续在前一个文件后面写)
extern const string kResetWhenRePlay;
extern const std::string kResetWhenRePlay;
//是否默认推流时转换成hlshook接口(on_publish)中可以覆盖该设置
extern const string kPublishToHls ;
extern const std::string kPublishToHls ;
//是否默认推流时mp4录像hook接口(on_publish)中可以覆盖该设置
extern const string kPublishToMP4 ;
extern const std::string kPublishToMP4 ;
//合并写缓存大小(单位毫秒)合并写指服务器缓存一定的数据后才会一次性写入socket这样能提高性能但是会提高延时
//开启后会同时关闭TCP_NODELAY并开启MSG_MORE
extern const string kMergeWriteMS ;
extern const std::string kMergeWriteMS ;
//全局的时间戳覆盖开关在转协议时对frame进行时间戳覆盖
extern const string kModifyStamp;
extern const std::string kModifyStamp;
//按需转协议的开关
extern const string kHlsDemand;
extern const string kRtspDemand;
extern const string kRtmpDemand;
extern const string kTSDemand;
extern const string kFMP4Demand;
extern const std::string kHlsDemand;
extern const std::string kRtspDemand;
extern const std::string kRtmpDemand;
extern const std::string kTSDemand;
extern const std::string kFMP4Demand;
//转协议是否全局开启或忽略音频
extern const string kEnableAudio;
extern const std::string kEnableAudio;
//最多等待未初始化的Track 10秒超时之后会忽略未初始化的Track
extern const string kWaitTrackReadyMS;
extern const std::string kWaitTrackReadyMS;
//如果直播流只有单Track最多等待3秒超时后未收到其他Track的数据则认为是单Track
//如果协议元数据有声明特定track数那么无此等待时间
extern const string kWaitAddTrackMS;
extern const std::string kWaitAddTrackMS;
//如果track未就绪我们先缓存帧数据但是有最大个数限制(100帧时大约4秒),防止内存溢出
extern const string kUnreadyFrameCache;
extern const std::string kUnreadyFrameCache;
//推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
//置0关闭此特性(推流断开会导致立即断开播放器)
extern const string kContinuePushMS;
extern const std::string kContinuePushMS;
}//namespace General
////////////HTTP配置///////////
namespace Http {
//http 文件发送缓存大小
extern const string kSendBufSize;
extern const std::string kSendBufSize;
//http 最大请求字节数
extern const string kMaxReqSize;
extern const std::string kMaxReqSize;
//http keep-alive秒数
extern const string kKeepAliveSecond;
extern const std::string kKeepAliveSecond;
//http 字符编码
extern const string kCharSet;
extern const std::string kCharSet;
//http 服务器根目录
extern const string kRootPath;
extern const std::string kRootPath;
//http 服务器虚拟目录 虚拟目录名和文件路径使用","隔开,多个配置路径间用";"隔开,例如 path_d,d:/record;path_e,e:/record
extern const string kVirtualPath;
extern const std::string kVirtualPath;
//http 404错误提示内容
extern const string kNotFound;
extern const std::string kNotFound;
//是否显示文件夹菜单
extern const string kDirMenu;
extern const std::string kDirMenu;
}//namespace Http
////////////SHELL配置///////////
namespace Shell {
extern const string kMaxReqSize;
extern const std::string kMaxReqSize;
} //namespace Shell
////////////RTSP服务器配置///////////
namespace Rtsp {
//是否优先base64方式认证默认Md5方式认证
extern const string kAuthBasic;
extern const std::string kAuthBasic;
//握手超时时间默认15秒
extern const string kHandshakeSecond;
extern const std::string kHandshakeSecond;
//维持链接超时时间默认15秒
extern const string kKeepAliveSecond;
extern const std::string kKeepAliveSecond;
//rtsp拉流代理是否直接代理
//直接代理后支持任意编码格式但是会导致GOP缓存无法定位到I帧可能会导致开播花屏
//并且如果是tcp方式拉流如果rtp大于mtu会导致无法使用udp方式代理
//假定您的拉流源地址不是264或265或AAC那么你可以使用直接代理的方式来支持rtsp代理
//默认开启rtsp直接代理rtmp由于没有这些问题是强制开启直接代理的
extern const string kDirectProxy;
extern const std::string kDirectProxy;
} //namespace Rtsp
////////////RTMP服务器配置///////////
namespace Rtmp {
//rtmp推流时间戳覆盖开关
extern const string kModifyStamp;
extern const std::string kModifyStamp;
//握手超时时间默认15秒
extern const string kHandshakeSecond;
extern const std::string kHandshakeSecond;
//维持链接超时时间默认15秒
extern const string kKeepAliveSecond;
extern const std::string kKeepAliveSecond;
} //namespace RTMP
////////////RTP配置///////////
namespace Rtp {
//RTP打包最大MTU,公网情况下更小
extern const string kVideoMtuSize;
extern const std::string kVideoMtuSize;
//RTP打包最大MTU,公网情况下更小
extern const string kAudioMtuSize;
extern const std::string kAudioMtuSize;
//rtp包最大长度限制, 单位KB
extern const string kRtpMaxSize;
extern const std::string kRtpMaxSize;
} //namespace Rtsp
////////////组播配置///////////
namespace MultiCast {
//组播分配起始地址
extern const string kAddrMin;
extern const std::string kAddrMin;
//组播分配截止地址
extern const string kAddrMax;
extern const std::string kAddrMax;
//组播TTL
extern const string kUdpTTL;
extern const std::string kUdpTTL;
} //namespace MultiCast
////////////录像配置///////////
namespace Record {
//查看录像的应用名称
extern const string kAppName;
extern const std::string kAppName;
//每次流化MP4文件的时长,单位毫秒
extern const string kSampleMS;
extern const std::string kSampleMS;
//MP4文件录制大小,默认一个小时
extern const string kFileSecond;
extern const std::string kFileSecond;
//录制文件路径
extern const string kFilePath;
extern const std::string kFilePath;
//mp4文件写缓存大小
extern const string kFileBufSize;
extern const std::string kFileBufSize;
//mp4录制完成后是否进行二次关键帧索引写入头部
extern const string kFastStart;
extern const std::string kFastStart;
//mp4文件是否重头循环读取
extern const string kFileRepeat;
extern const std::string kFileRepeat;
} //namespace Record
////////////HLS相关配置///////////
namespace Hls {
//HLS切片时长,单位秒
extern const string kSegmentDuration;
extern const std::string kSegmentDuration;
//m3u8文件中HLS切片个数如果设置为0则不删除切片而是保存为点播
extern const string kSegmentNum;
extern const std::string kSegmentNum;
//HLS切片从m3u8文件中移除后继续保留在磁盘上的个数
extern const string kSegmentRetain;
extern const std::string kSegmentRetain;
//HLS文件写缓存大小
extern const string kFileBufSize;
extern const std::string kFileBufSize;
//录制文件路径
extern const string kFilePath;
extern const std::string kFilePath;
// 是否广播 ts 切片完成通知
extern const string kBroadcastRecordTs;
extern const std::string kBroadcastRecordTs;
//hls直播文件删除延时单位秒
extern const string kDeleteDelaySec;
extern const std::string kDeleteDelaySec;
} //namespace Hls
////////////Rtp代理相关配置///////////
namespace RtpProxy {
//rtp调试数据保存目录,置空则不生成
extern const string kDumpDir;
extern const std::string kDumpDir;
//rtp接收超时时间
extern const string kTimeoutSec;
extern const std::string kTimeoutSec;
} //namespace RtpProxy
/**
@ -323,26 +320,26 @@ extern const string kTimeoutSec;
*/
namespace Client {
//指定网卡ip
extern const string kNetAdapter;
extern const std::string kNetAdapter;
//设置rtp传输类型可选项有0(tcp默认)、1(udp)、2(组播)
//设置方法:player[PlayerBase::kRtpType] = 0/1/2;
extern const string kRtpType;
extern const std::string kRtpType;
//rtsp认证用户名
extern const string kRtspUser;
extern const std::string kRtspUser;
//rtsp认证用用户密码可以是明文也可以是md5,md5密码生成方式 md5(username:realm:password)
extern const string kRtspPwd;
extern const std::string kRtspPwd;
//rtsp认证用用户密码是否为md5类型
extern const string kRtspPwdIsMD5;
extern const std::string kRtspPwdIsMD5;
//握手超时时间默认10,000 毫秒
extern const string kTimeoutMS;
extern const std::string kTimeoutMS;
//rtp/rtmp包接收超时时间默认5000秒
extern const string kMediaTimeoutMS;
extern const std::string kMediaTimeoutMS;
//rtsp/rtmp心跳时间,默认5000毫秒
extern const string kBeatIntervalMS;
extern const std::string kBeatIntervalMS;
//是否为性能测试模式性能测试模式开启后不会解析rtp或rtmp包
extern const string kBenchmarkMode;
extern const std::string kBenchmarkMode;
//播放器在触发播放成功事件时是否等待所有track ready时再回调
extern const string kWaitTrackReady;
extern const std::string kWaitTrackReady;
}
} // namespace mediakit

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,6 +11,9 @@
#include "AACRtmp.h"
#include "Rtmp/Rtmp.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
static string getAacCfg(const RtmpPacket &thiz) {

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 264340x00 00 00 01
* @param pps_prefix_len 264340x00 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 01sps/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,6 +10,10 @@
#include "Rtmp/utils.h"
#include "H264Rtmp.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
H264RtmpDecoder::H264RtmpDecoder() {

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,6 +11,9 @@
#include "H265.h"
#include "SPSParser.h"
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){

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 265340x00 00 00 01
* @param pps_prefix_len 265340x00 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 01vps/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

View File

@ -12,18 +12,18 @@
#define ZLMEDIAKIT_FMP4MEDIASOURCE_H
#include "Common/MediaSource.h"
using namespace toolkit;
#define FMP4_GOP_SIZE 512
namespace mediakit {
//FMP4直播数据包
class FMP4Packet : public BufferString{
class FMP4Packet : public toolkit::BufferString{
public:
using Ptr = std::shared_ptr<FMP4Packet>;
template<typename ...ARGS>
FMP4Packet(ARGS && ...args) : BufferString(std::forward<ARGS>(args)...) {};
FMP4Packet(ARGS && ...args) : toolkit::BufferString(std::forward<ARGS>(args)...) {};
~FMP4Packet() override = default;
public:
@ -31,15 +31,15 @@ public:
};
//FMP4直播源
class FMP4MediaSource : public MediaSource, public RingDelegate<FMP4Packet::Ptr>, private PacketCache<FMP4Packet>{
class FMP4MediaSource : public MediaSource, public toolkit::RingDelegate<FMP4Packet::Ptr>, private PacketCache<FMP4Packet>{
public:
using Ptr = std::shared_ptr<FMP4MediaSource>;
using RingDataType = std::shared_ptr<List<FMP4Packet::Ptr> >;
using RingType = RingBuffer<RingDataType>;
using RingDataType = std::shared_ptr<toolkit::List<FMP4Packet::Ptr> >;
using RingType = toolkit::RingBuffer<RingDataType>;
FMP4MediaSource(const string &vhost,
const string &app,
const string &stream_id,
FMP4MediaSource(const std::string &vhost,
const std::string &app,
const std::string &stream_id,
int ring_size = FMP4_GOP_SIZE) : MediaSource(FMP4_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {}
~FMP4MediaSource() override = default;
@ -54,7 +54,7 @@ public:
/**
* fmp4 init segment
*/
const string &getInitSegment() const{
const std::string &getInitSegment() const{
return _init_segment;
}
@ -62,7 +62,7 @@ public:
* fmp4 init segment
* @param str init segment
*/
void setInitSegment(string str) {
void setInitSegment(std::string str) {
_init_segment = std::move(str);
createRing();
}
@ -101,7 +101,7 @@ public:
private:
void createRing(){
weak_ptr<FMP4MediaSource> weak_self = dynamic_pointer_cast<FMP4MediaSource>(shared_from_this());
std::weak_ptr<FMP4MediaSource> weak_self = std::dynamic_pointer_cast<FMP4MediaSource>(shared_from_this());
_ring = std::make_shared<RingType>(_ring_size, [weak_self](int size) {
auto strong_self = weak_self.lock();
if (!strong_self) {
@ -120,7 +120,7 @@ private:
* @param packet_list
* @param key_pos
*/
void onFlush(std::shared_ptr<List<FMP4Packet::Ptr> > packet_list, bool key_pos) override {
void onFlush(std::shared_ptr<toolkit::List<FMP4Packet::Ptr> > packet_list, bool key_pos) override {
//如果不存在视频那么就没有存在GOP缓存的意义所以确保一直清空GOP缓存
_ring->write(std::move(packet_list), _have_video ? key_pos : true);
}
@ -128,7 +128,7 @@ private:
private:
bool _have_video = false;
int _ring_size;
string _init_segment;
std::string _init_segment;
RingType::Ptr _ring;
};

View File

@ -23,9 +23,9 @@ class FMP4MediaSourceMuxer : public MP4MuxerMemory, public MediaSourceEventInter
public:
using Ptr = std::shared_ptr<FMP4MediaSourceMuxer>;
FMP4MediaSourceMuxer(const string &vhost,
const string &app,
const string &stream_id) {
FMP4MediaSourceMuxer(const std::string &vhost,
const std::string &app,
const std::string &stream_id) {
_media_src = std::make_shared<FMP4MediaSource>(vhost, app, stream_id);
}
@ -72,7 +72,7 @@ public:
}
protected:
void onSegmentData(string string, uint32_t stamp, bool key_frame) override {
void onSegmentData(std::string string, uint32_t stamp, bool key_frame) override {
if (string.empty()) {
return;
}

View File

@ -13,7 +13,10 @@
#include "HlsParser.h"
#include "Util/util.h"
#include "Common/Parser.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
bool HlsParser::parse(const string &http_url, const string &m3u8) {

View File

@ -14,12 +14,12 @@
#include <string>
#include <list>
#include <map>
using namespace std;
namespace mediakit {
typedef struct{
//url地址
string url;
std::string url;
//ts切片长度
float duration;
@ -38,7 +38,7 @@ class HlsParser {
public:
HlsParser(){}
~HlsParser(){}
bool parse(const string &http_url,const string &m3u8);
bool parse(const std::string &http_url,const std::string &m3u8);
/**
* #EXTM3U字段m3u8文件
@ -82,7 +82,7 @@ public:
protected:
//解析出ts文件地址回调
virtual void onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_segment> &ts_list) {};
virtual void onParsed(bool is_m3u8_inner,int64_t sequence,const std::map<int,ts_segment> &ts_list) {};
private:
bool _is_m3u8 = false;

View File

@ -10,6 +10,9 @@
#include "HlsPlayer.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller) {
@ -27,8 +30,8 @@ void HlsPlayer::fetchIndexFile() {
if (waitResponse()) {
return;
}
if (!(*this)[kNetAdapter].empty()) {
setNetAdapter((*this)[kNetAdapter]);
if (!(*this)[Client::kNetAdapter].empty()) {
setNetAdapter((*this)[Client::kNetAdapter]);
}
setCompleteTimeout((*this)[Client::kTimeoutMS].as<int>());
setMethod("GET");
@ -83,7 +86,7 @@ void HlsPlayer::fetchSegment() {
strong_self->onPacket_l(data, len);
});
if (!(*this)[kNetAdapter].empty()) {
if (!(*this)[Client::kNetAdapter].empty()) {
_http_ts_player->setNetAdapter((*this)[Client::kNetAdapter]);
}
}

View File

@ -17,8 +17,6 @@
#include "HlsParser.h"
#include "Rtp/TSDecoder.h"
using namespace toolkit;
namespace mediakit {
class HlsDemuxer
@ -29,12 +27,12 @@ public:
HlsDemuxer() = default;
~HlsDemuxer() override { _timer = nullptr; }
void start(const EventPoller::Ptr &poller, TrackListener *listener);
void start(const toolkit::EventPoller::Ptr &poller, TrackListener *listener);
bool inputFrame(const Frame::Ptr &frame) override;
bool addTrack(const Track::Ptr &track) override { return _delegate.addTrack(track); }
void addTrackCompleted() override { _delegate.addTrackCompleted(); }
void resetTracks() override { ((MediaSink &)_delegate).resetTracks(); }
vector<Track::Ptr> getTracks(bool ready = true) const override { return _delegate.getTracks(ready); }
std::vector<Track::Ptr> getTracks(bool ready = true) const override { return _delegate.getTracks(ready); }
private:
void onTick();
@ -44,22 +42,22 @@ private:
private:
int64_t _ticker_offset = 0;
Ticker _ticker;
toolkit::Ticker _ticker;
Stamp _stamp[2];
Timer::Ptr _timer;
toolkit::Timer::Ptr _timer;
MediaSinkDelegate _delegate;
multimap<int64_t, Frame::Ptr> _frame_cache;
std::multimap<int64_t, Frame::Ptr> _frame_cache;
};
class HlsPlayer : public HttpClientImp , public PlayerBase , public HlsParser{
public:
HlsPlayer(const EventPoller::Ptr &poller);
HlsPlayer(const toolkit::EventPoller::Ptr &poller);
~HlsPlayer() override = default;
/**
*
*/
void play(const string &url) override;
void play(const std::string &url) override;
/**
*
@ -76,37 +74,37 @@ protected:
private:
void onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_segment> &ts_map) override;
void onResponseHeader(const string &status,const HttpHeader &headers) override;
void onResponseHeader(const std::string &status,const HttpHeader &headers) override;
void onResponseBody(const char *buf,size_t size) override;
void onResponseCompleted(const SockException &e) override;
bool onRedirectUrl(const string &url,bool temporary) override;
void onResponseCompleted(const toolkit::SockException &e) override;
bool onRedirectUrl(const std::string &url,bool temporary) override;
private:
void playDelay();
float delaySecond();
void fetchSegment();
void teardown_l(const SockException &ex);
void teardown_l(const toolkit::SockException &ex);
void fetchIndexFile();
void onPacket_l(const char *data, size_t len);
private:
struct UrlComp {
//url忽略后面的参数
bool operator()(const string& __x, const string& __y) const {
return split(__x,"?")[0] < split(__y,"?")[0];
bool operator()(const std::string& __x, const std::string& __y) const {
return toolkit::split(__x,"?")[0] < toolkit::split(__y,"?")[0];
}
};
private:
bool _play_result = false;
int64_t _last_sequence = -1;
string _m3u8;
string _play_url;
Timer::Ptr _timer;
Timer::Ptr _timer_ts;
list<ts_segment> _ts_list;
list<string> _ts_url_sort;
set<string, UrlComp> _ts_url_cache;
std::string _m3u8;
std::string _play_url;
toolkit::Timer::Ptr _timer;
toolkit::Timer::Ptr _timer_ts;
std::list<ts_segment> _ts_list;
std::list<std::string> _ts_url_sort;
std::set<std::string, UrlComp> _ts_url_cache;
HttpTSPlayer::Ptr _http_ts_player;
TSSegment _segment;
};
@ -114,7 +112,7 @@ private:
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {
public:
typedef std::shared_ptr<HlsPlayerImp> Ptr;
HlsPlayerImp(const EventPoller::Ptr &poller = nullptr);
HlsPlayerImp(const toolkit::EventPoller::Ptr &poller = nullptr);
~HlsPlayerImp() override = default;
private:
@ -123,9 +121,9 @@ private:
private:
//// PlayerBase override////
void onPlayResult(const SockException &ex) override;
vector<Track::Ptr> getTracks(bool ready = true) const override;
void onShutdown(const SockException &ex) override;
void onPlayResult(const toolkit::SockException &ex) override;
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
void onShutdown(const toolkit::SockException &ex) override;
private:
//// TrackListener override////

View File

@ -22,6 +22,9 @@
#define ENABLE_MMAP
#endif
using namespace std;
using namespace toolkit;
namespace mediakit {
HttpStringBody::HttpStringBody(string str){

View File

@ -18,9 +18,6 @@
#include "Util/logger.h"
#include "Thread/WorkThreadPool.h"
using namespace std;
using namespace toolkit;
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b) )
#endif //MIN
@ -47,14 +44,14 @@ public:
* @param size
* @return ,nullptr
*/
virtual Buffer::Ptr readData(size_t size) { return nullptr;};
virtual toolkit::Buffer::Ptr readData(size_t size) { return nullptr;};
/**
* size
* @param size
* @param cb
*/
virtual void readDataAsync(size_t size,const function<void(const Buffer::Ptr &buf)> &cb){
virtual void readDataAsync(size_t size,const std::function<void(const toolkit::Buffer::Ptr &buf)> &cb){
//由于unix和linux是通过mmap的方式读取文件所以把读文件操作放在后台线程并不能提高性能
//反而会由于频繁的线程切换导致性能降低以及延时增加,所以我们默认同步获取文件内容
//(其实并没有读,拷贝文件数据时在内核态完成文件读)
@ -63,20 +60,20 @@ public:
};
/**
* string类型的content
* std::string类型的content
*/
class HttpStringBody : public HttpBody{
public:
typedef std::shared_ptr<HttpStringBody> Ptr;
HttpStringBody(string str);
HttpStringBody(std::string str);
~HttpStringBody() override = default;
ssize_t remainSize() override;
Buffer::Ptr readData(size_t size) override ;
toolkit::Buffer::Ptr readData(size_t size) override ;
private:
size_t _offset = 0;
mutable string _str;
mutable std::string _str;
};
/**
@ -85,14 +82,14 @@ private:
class HttpBufferBody : public HttpBody{
public:
typedef std::shared_ptr<HttpBufferBody> Ptr;
HttpBufferBody(Buffer::Ptr buffer);
HttpBufferBody(toolkit::Buffer::Ptr buffer);
~HttpBufferBody() override = default;
ssize_t remainSize() override;
Buffer::Ptr readData(size_t size) override;
toolkit::Buffer::Ptr readData(size_t size) override;
private:
Buffer::Ptr _buffer;
toolkit::Buffer::Ptr _buffer;
};
/**
@ -110,11 +107,11 @@ public:
* @param use_mmap 使mmap方式访问文件
*/
HttpFileBody(const std::shared_ptr<FILE> &fp, size_t offset, size_t max_size, bool use_mmap = true);
HttpFileBody(const string &file_path, bool use_mmap = true);
HttpFileBody(const std::string &file_path, bool use_mmap = true);
~HttpFileBody() override = default;
ssize_t remainSize() override ;
Buffer::Ptr readData(size_t size) override;
toolkit::Buffer::Ptr readData(size_t size) override;
private:
void init(const std::shared_ptr<FILE> &fp,size_t offset,size_t max_size, bool use_mmap);
@ -124,7 +121,7 @@ private:
size_t _offset = 0;
std::shared_ptr<FILE> _fp;
std::shared_ptr<char> _map_addr;
ResourcePool<BufferRaw> _pool;
toolkit::ResourcePool<toolkit::BufferRaw> _pool;
};
class HttpArgs;
@ -142,21 +139,21 @@ public:
* @param filePath
* @param boundary boundary字符串
*/
HttpMultiFormBody(const HttpArgs &args,const string &filePath,const string &boundary = "0xKhTmLbOuNdArY");
HttpMultiFormBody(const HttpArgs &args,const std::string &filePath,const std::string &boundary = "0xKhTmLbOuNdArY");
virtual ~HttpMultiFormBody(){}
ssize_t remainSize() override ;
Buffer::Ptr readData(size_t size) override;
toolkit::Buffer::Ptr readData(size_t size) override;
public:
static string multiFormBodyPrefix(const HttpArgs &args,const string &boundary,const string &fileName);
static string multiFormBodySuffix(const string &boundary);
static string multiFormContentType(const string &boundary);
static std::string multiFormBodyPrefix(const HttpArgs &args,const std::string &boundary,const std::string &fileName);
static std::string multiFormBodySuffix(const std::string &boundary);
static std::string multiFormContentType(const std::string &boundary);
private:
size_t _offset = 0;
size_t _totalSize;
string _bodyPrefix;
string _bodySuffix;
std::string _bodyPrefix;
std::string _bodySuffix;
HttpFileBody::Ptr _fileBody;
};

View File

@ -11,6 +11,8 @@
#include <string.h>
#include "HttpChunkedSplitter.h"
using namespace std;
namespace mediakit{
const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, size_t len) {

View File

@ -13,6 +13,9 @@
#include "HttpClient.h"
#include "Common/config.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
void HttpClient::sendRequest(const string &url) {

View File

@ -25,18 +25,15 @@
#include "strCoding.h"
#include "HttpBody.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
class HttpArgs : public map<string, variant, StrCaseCompare> {
class HttpArgs : public std::map<std::string, toolkit::variant, StrCaseCompare> {
public:
HttpArgs() = default;
~HttpArgs() = default;
string make() const {
string ret;
std::string make() const {
std::string ret;
for (auto &pr : *this) {
ret.append(pr.first);
ret.append("=");
@ -50,7 +47,7 @@ public:
}
};
class HttpClient : public TcpClient, public HttpRequestSplitter {
class HttpClient : public toolkit::TcpClient, public HttpRequestSplitter {
public:
using HttpHeader = StrCaseMap;
using Ptr = std::shared_ptr<HttpClient>;
@ -62,7 +59,7 @@ public:
* http[s]
* @param url url
*/
virtual void sendRequest(const string &url);
virtual void sendRequest(const std::string &url);
/**
*
@ -73,7 +70,7 @@ public:
* http方法
* @param method GET/POST等
*/
void setMethod(string method);
void setMethod(std::string method);
/**
* http头
@ -81,13 +78,13 @@ public:
*/
void setHeader(HttpHeader header);
HttpClient &addHeader(string key, string val, bool force = false);
HttpClient &addHeader(std::string key, std::string val, bool force = false);
/**
* http content
* @param body http content
*/
void setBody(string body);
void setBody(std::string body);
/**
* http content
@ -113,7 +110,7 @@ public:
/**
* url
*/
const string &getUrl() const;
const std::string &getUrl() const;
/**
*
@ -150,7 +147,7 @@ protected:
* @param status :200 OK
* @param headers http头
*/
virtual void onResponseHeader(const string &status, const HttpHeader &headers) = 0;
virtual void onResponseHeader(const std::string &status, const HttpHeader &headers) = 0;
/**
* http conten数据
@ -162,7 +159,7 @@ protected:
/**
* http回复完毕,
*/
virtual void onResponseCompleted(const SockException &ex) = 0;
virtual void onResponseCompleted(const toolkit::SockException &ex) = 0;
/**
*
@ -170,7 +167,7 @@ protected:
* @param temporary
* @return
*/
virtual bool onRedirectUrl(const string &url, bool temporary) { return true; };
virtual bool onRedirectUrl(const std::string &url, bool temporary) { return true; };
protected:
//// HttpRequestSplitter override ////
@ -178,15 +175,15 @@ protected:
void onRecvContent(const char *data, size_t len) override;
//// TcpClient override ////
void onConnect(const SockException &ex) override;
void onRecv(const Buffer::Ptr &pBuf) override;
void onErr(const SockException &ex) override;
void onConnect(const toolkit::SockException &ex) override;
void onRecv(const toolkit::Buffer::Ptr &pBuf) override;
void onErr(const toolkit::SockException &ex) override;
void onFlush() override;
void onManager() override;
private:
void onResponseCompleted_l(const SockException &ex);
void onConnect_l(const SockException &ex);
void onResponseCompleted_l(const toolkit::SockException &ex);
void onConnect_l(const toolkit::SockException &ex);
void checkCookie(HttpHeader &headers);
void clearResponse();
@ -201,23 +198,23 @@ private:
//for request args
bool _is_https;
string _url;
std::string _url;
HttpHeader _user_set_header;
HttpBody::Ptr _body;
string _method;
string _last_host;
std::string _method;
std::string _last_host;
//for this request
string _path;
std::string _path;
HttpHeader _header;
//for timeout
size_t _wait_header_ms = 10 * 1000;
size_t _wait_body_ms = 10 * 1000;
size_t _wait_complete_ms = 0;
Ticker _wait_header;
Ticker _wait_body;
Ticker _wait_complete;
toolkit::Ticker _wait_header;
toolkit::Ticker _wait_body;
toolkit::Ticker _wait_complete;
};
} /* namespace mediakit */

View File

@ -10,6 +10,8 @@
#include "Http/HttpClientImp.h"
using namespace toolkit;
namespace mediakit {
void HttpClientImp::onConnect(const SockException &ex) {

View File

@ -13,17 +13,17 @@
#include "HttpClient.h"
#include "Util/SSLBox.h"
using namespace toolkit;
namespace mediakit {
class HttpClientImp : public TcpClientWithSSL<HttpClient> {
class HttpClientImp : public toolkit::TcpClientWithSSL<HttpClient> {
public:
using Ptr = std::shared_ptr<HttpClientImp>;
HttpClientImp() = default;
~HttpClientImp() override = default;
protected:
void onConnect(const SockException &ex) override;
void onConnect(const toolkit::SockException &ex) override;
};
} /* namespace mediakit */

View File

@ -13,6 +13,9 @@
#include "Common/Parser.h"
#include "Util/onceToken.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
const char *getHttpStatusMessage(int status) {

View File

@ -12,7 +12,6 @@
#define ZLMEDIAKIT_HTTPCONST_H
#include <string>
using namespace std;
namespace mediakit{
@ -28,7 +27,7 @@ const char *getHttpStatusMessage(int status);
* @param name html
* @return mime值text/html
*/
const string &getHttpContentType(const char *name);
const std::string &getHttpContentType(const char *name);
}//mediakit

View File

@ -17,6 +17,8 @@
#endif
using namespace toolkit;
using namespace std;
namespace mediakit {
void HttpCookie::setPath(const string &path){

View File

@ -17,7 +17,6 @@
#include <map>
#include <unordered_map>
#include <mutex>
using namespace std;
namespace mediakit {
@ -31,19 +30,19 @@ public:
HttpCookie(){}
~HttpCookie(){}
void setPath(const string &path);
void setHost(const string &host);
void setExpires(const string &expires,const string &server_date);
void setKeyVal(const string &key,const string &val);
void setPath(const std::string &path);
void setHost(const std::string &host);
void setExpires(const std::string &expires,const std::string &server_date);
void setKeyVal(const std::string &key,const std::string &val);
operator bool ();
const string &getKey() const ;
const string &getVal() const ;
const std::string &getKey() const ;
const std::string &getVal() const ;
private:
string _host;
string _path = "/";
string _key;
string _val;
std::string _host;
std::string _path = "/";
std::string _key;
std::string _val;
time_t _expire = 0;
};
@ -56,12 +55,12 @@ public:
~HttpCookieStorage(){}
static HttpCookieStorage &Instance();
void set(const HttpCookie::Ptr &cookie);
vector<HttpCookie::Ptr> get(const string &host,const string &path);
std::vector<HttpCookie::Ptr> get(const std::string &host,const std::string &path);
private:
HttpCookieStorage(){};
private:
unordered_map<string/*host*/,map<string/*cookie path*/,map<string/*cookie_key*/,HttpCookie::Ptr> > > _all_cookie;
mutex _mtx_cookie;
std::unordered_map<std::string/*host*/, std::map<std::string/*cookie path*/,std::map<std::string/*cookie_key*/, HttpCookie::Ptr> > > _all_cookie;
std::mutex _mtx_cookie;
};

View File

@ -13,6 +13,9 @@
#include "Common/config.h"
#include "HttpCookieManager.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
//////////////////////////////HttpServerCookie////////////////////////////////////

View File

@ -19,10 +19,6 @@
#include "Network/Socket.h"
#include "Common/Parser.h"
using namespace std;
using namespace toolkit;
using namespace mediakit;
#define COOKIE_DEFAULT_LIFE (7 * 24 * 60 * 60)
namespace mediakit {
@ -32,7 +28,7 @@ class HttpCookieManager;
/**
* cookie对象cookie的一些相关属性
*/
class HttpServerCookie : public AnyStorage , public noncopyable{
class HttpServerCookie : public toolkit::AnyStorage , public toolkit::noncopyable{
public:
typedef std::shared_ptr<HttpServerCookie> Ptr;
/**
@ -45,9 +41,9 @@ public:
*/
HttpServerCookie(const std::shared_ptr<HttpCookieManager> &manager,
const string &cookie_name,
const string &uid,
const string &cookie,
const std::string &cookie_name,
const std::string &uid,
const std::string &cookie,
uint64_t max_elapsed);
~HttpServerCookie() ;
@ -55,7 +51,7 @@ public:
* uid
* @return uid
*/
const string &getUid() const;
const std::string &getUid() const;
/**
* http中Set-Cookie字段的值
@ -63,19 +59,19 @@ public:
* @param path http访问路径
* @return MY_SESSION=XXXXXX;expires=Wed, Jun 12 2019 06:30:48 GMT;path=/index/files/
*/
string getCookie(const string &path) const;
std::string getCookie(const std::string &path) const;
/**
* cookie随机字符串
* @return cookie随机字符串
*/
const string& getCookie() const;
const std::string& getCookie() const;
/**
* cookie名
* @return
*/
const string& getCookieName() const;
const std::string& getCookieName() const;
/**
* cookie的过期时间cookie不失效
@ -92,16 +88,16 @@ public:
*
* @return
*/
std::shared_ptr<lock_guard<recursive_mutex> > getLock();
std::shared_ptr<std::lock_guard<std::recursive_mutex> > getLock();
private:
string cookieExpireTime() const ;
std::string cookieExpireTime() const ;
private:
string _uid;
string _cookie_name;
string _cookie_uuid;
std::string _uid;
std::string _cookie_name;
std::string _cookie_uuid;
uint64_t _max_elapsed;
Ticker _ticker;
recursive_mutex _mtx;
toolkit::Ticker _ticker;
std::recursive_mutex _mtx;
std::weak_ptr<HttpCookieManager> _manager;
};
@ -117,18 +113,18 @@ public:
*
* @return
*/
string obtain();
std::string obtain();
/**
*
* @param str
*/
void release(const string &str);
void release(const std::string &str);
private:
string obtain_l();
std::string obtain_l();
private:
//碰撞库
unordered_set<string> _obtained;
std::unordered_set<std::string> _obtained;
//增长index防止碰撞用
int _index = 0;
};
@ -156,7 +152,7 @@ public:
* @param max_elapsed cookie过期时间
* @return cookie对象
*/
HttpServerCookie::Ptr addCookie(const string &cookie_name,const string &uid, uint64_t max_elapsed = COOKIE_DEFAULT_LIFE,int max_client = 1);
HttpServerCookie::Ptr addCookie(const std::string &cookie_name,const std::string &uid, uint64_t max_elapsed = COOKIE_DEFAULT_LIFE,int max_client = 1);
/**
* cookie随机字符串查找cookie对象
@ -164,7 +160,7 @@ public:
* @param cookie cookie随机字符串
* @return cookie对象nullptr
*/
HttpServerCookie::Ptr getCookie(const string &cookie_name,const string &cookie);
HttpServerCookie::Ptr getCookie(const std::string &cookie_name,const std::string &cookie);
/**
* http头中获取cookie对象
@ -172,7 +168,7 @@ public:
* @param http_header http头
* @return cookie对象
*/
HttpServerCookie::Ptr getCookie(const string &cookie_name,const StrCaseMap &http_header);
HttpServerCookie::Ptr getCookie(const std::string &cookie_name,const StrCaseMap &http_header);
/**
* uid获取cookie
@ -180,7 +176,7 @@ public:
* @param uid id
* @return cookie对象
*/
HttpServerCookie::Ptr getCookieByUid(const string &cookie_name,const string &uid);
HttpServerCookie::Ptr getCookieByUid(const std::string &cookie_name,const std::string &uid);
/**
* cookie使
@ -197,7 +193,7 @@ private:
* @param uid id
* @param cookie cookie随机字符串
*/
void onAddCookie(const string &cookie_name,const string &uid,const string &cookie);
void onAddCookie(const std::string &cookie_name,const std::string &uid,const std::string &cookie);
/**
* cookie对象时触发
@ -205,7 +201,7 @@ private:
* @param uid id
* @param cookie cookie随机字符串
*/
void onDelCookie(const string &cookie_name,const string &uid,const string &cookie);
void onDelCookie(const std::string &cookie_name,const std::string &uid,const std::string &cookie);
/**
* cookie
@ -214,7 +210,7 @@ private:
* @param max_client
* @return cookie随机字符串
*/
string getOldestCookie(const string &cookie_name,const string &uid, int max_client = 1);
std::string getOldestCookie(const std::string &cookie_name,const std::string &uid, int max_client = 1);
/**
* cookie
@ -222,12 +218,12 @@ private:
* @param cookie cookie随机字符串
* @return true
*/
bool delCookie(const string &cookie_name,const string &cookie);
bool delCookie(const std::string &cookie_name,const std::string &cookie);
private:
unordered_map<string/*cookie_name*/,unordered_map<string/*cookie*/,HttpServerCookie::Ptr/*cookie_data*/> >_map_cookie;
unordered_map<string/*cookie_name*/,unordered_map<string/*uid*/,map<uint64_t/*cookie time stamp*/,string/*cookie*/> > >_map_uid_to_cookie;
recursive_mutex _mtx_cookie;
Timer::Ptr _timer;
std::unordered_map<std::string/*cookie_name*/,std::unordered_map<std::string/*cookie*/,HttpServerCookie::Ptr/*cookie_data*/> >_map_cookie;
std::unordered_map<std::string/*cookie_name*/,std::unordered_map<std::string/*uid*/,std::map<uint64_t/*cookie time stamp*/,std::string/*cookie*/> > >_map_uid_to_cookie;
std::recursive_mutex _mtx_cookie;
toolkit::Timer::Ptr _timer;
RandStrGeneator _geneator;
};

View File

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

View File

@ -18,7 +18,7 @@ namespace mediakit {
class HttpDownloader : public HttpClientImp {
public:
using Ptr = std::shared_ptr<HttpDownloader>;
using onDownloadResult = std::function<void(const SockException &ex, const string &filePath)>;
using onDownloadResult = std::function<void(const toolkit::SockException &ex, const std::string &filePath)>;
HttpDownloader() = default;
~HttpDownloader() override;
@ -29,9 +29,9 @@ public:
* @param file_path
* @param append
*/
void startDownload(const string &url, const string &file_path = "", bool append = false);
void startDownload(const std::string &url, const std::string &file_path = "", bool append = false);
void startDownload(const string &url, const onDownloadResult &cb) {
void startDownload(const std::string &url, const onDownloadResult &cb) {
setOnResult(cb);
startDownload(url, "", false);
}
@ -40,15 +40,15 @@ public:
protected:
void onResponseBody(const char *buf, size_t size) override;
void onResponseHeader(const string &status, const HttpHeader &headers) override;
void onResponseCompleted(const SockException &ex) override;
void onResponseHeader(const std::string &status, const HttpHeader &headers) override;
void onResponseCompleted(const toolkit::SockException &ex) override;
private:
void closeFile();
private:
FILE *_save_file = nullptr;
string _file_path;
std::string _file_path;
onDownloadResult _on_result;
};

View File

@ -20,6 +20,9 @@
#include "Record/HlsMediaSource.h"
#include "Common/Parser.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
// hls的播放cookie缓存时间默认60秒

View File

@ -22,20 +22,20 @@ namespace mediakit {
class HttpResponseInvokerImp{
public:
typedef std::function<void(int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body)> HttpResponseInvokerLambda0;
typedef std::function<void(int code, const StrCaseMap &headerOut, const string &body)> HttpResponseInvokerLambda1;
typedef std::function<void(int code, const StrCaseMap &headerOut, const std::string &body)> HttpResponseInvokerLambda1;
HttpResponseInvokerImp(){}
~HttpResponseInvokerImp(){}
template<typename C>
HttpResponseInvokerImp(const C &c):HttpResponseInvokerImp(typename function_traits<C>::stl_function_type(c)) {}
HttpResponseInvokerImp(const C &c):HttpResponseInvokerImp(typename toolkit::function_traits<C>::stl_function_type(c)) {}
HttpResponseInvokerImp(const HttpResponseInvokerLambda0 &lambda);
HttpResponseInvokerImp(const HttpResponseInvokerLambda1 &lambda);
void operator()(int code, const StrCaseMap &headerOut, const Buffer::Ptr &body) const;
void operator()(int code, const StrCaseMap &headerOut, const toolkit::Buffer::Ptr &body) const;
void operator()(int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body) const;
void operator()(int code, const StrCaseMap &headerOut, const string &body) const;
void operator()(int code, const StrCaseMap &headerOut, const std::string &body) const;
void responseFile(const StrCaseMap &requestHeader,const StrCaseMap &responseHeader,const string &filePath, bool use_mmap = true) const;
void responseFile(const StrCaseMap &requestHeader,const StrCaseMap &responseHeader,const std::string &filePath, bool use_mmap = true) const;
operator bool();
private:
HttpResponseInvokerLambda0 _lambad;
@ -46,7 +46,7 @@ private:
*/
class HttpFileManager {
public:
typedef function<void(int code, const string &content_type, const StrCaseMap &responseHeader, const HttpBody::Ptr &body)> invoker;
typedef std::function<void(int code, const std::string &content_type, const StrCaseMap &responseHeader, const HttpBody::Ptr &body)> invoker;
/**
* 访
@ -54,14 +54,14 @@ public:
* @param parser http请求
* @param cb
*/
static void onAccessPath(TcpSession &sender, Parser &parser, const invoker &cb);
static void onAccessPath(toolkit::TcpSession &sender, Parser &parser, const invoker &cb);
/**
* mime值
* @param name
* @return mime值
*/
static const string &getContentType(const char *name);
static const std::string &getContentType(const char *name);
private:
HttpFileManager() = delete;
~HttpFileManager() = delete;

View File

@ -12,6 +12,7 @@
#include "Util/logger.h"
#include "Util/util.h"
using namespace toolkit;
using namespace std;
//协议解析最大缓存1兆数据
static constexpr size_t kMaxCacheSize = 1 * 1024 * 1024;

View File

@ -13,8 +13,6 @@
#include <string>
#include "Network/Buffer.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
@ -83,7 +81,7 @@ protected:
private:
ssize_t _content_len = 0;
size_t _remain_data_size = 0;
BufferLikeString _remain_data;
toolkit::BufferLikeString _remain_data;
};
} /* namespace mediakit */

View File

@ -10,6 +10,9 @@
#include "HttpRequester.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
void HttpRequester::onResponseHeader(const string &status, const HttpHeader &headers) {

View File

@ -18,22 +18,22 @@ namespace mediakit {
class HttpRequester : public HttpClientImp {
public:
using Ptr = std::shared_ptr<HttpRequester>;
using HttpRequesterResult = std::function<void(const SockException &ex, const Parser &response)>;
using HttpRequesterResult = std::function<void(const toolkit::SockException &ex, const Parser &response)>;
HttpRequester() = default;
~HttpRequester() override = default;
void setOnResult(const HttpRequesterResult &onResult);
void startRequester(const string &url, const HttpRequesterResult &on_result, float timeout_sec = 10);
void startRequester(const std::string &url, const HttpRequesterResult &on_result, float timeout_sec = 10);
void clear() override;
private:
void onResponseHeader(const string &status, const HttpHeader &headers) override;
void onResponseHeader(const std::string &status, const HttpHeader &headers) override;
void onResponseBody(const char *buf, size_t size) override;
void onResponseCompleted(const SockException &ex) override;
void onResponseCompleted(const toolkit::SockException &ex) override;
private:
string _res_body;
std::string _res_body;
HttpRequesterResult _on_result;
};

View File

@ -17,6 +17,8 @@
#include "HttpConst.h"
#include "Util/base64.h"
#include "Util/SHA1.h"
using namespace std;
using namespace toolkit;
namespace mediakit {

View File

@ -22,12 +22,9 @@
#include "TS/TSMediaSource.h"
#include "FMP4/FMP4MediaSource.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
class HttpSession: public TcpSession,
class HttpSession: public toolkit::TcpSession,
public FlvMuxer,
public HttpRequestSplitter,
public WebSocketSplitter {
@ -40,19 +37,19 @@ public:
* @param accessPath 访
* @param cookieLifeSecond cookie有效期
**/
typedef std::function<void(const string &errMsg,const string &accessPath, int cookieLifeSecond)> HttpAccessPathInvoker;
typedef std::function<void(const std::string &errMsg,const std::string &accessPath, int cookieLifeSecond)> HttpAccessPathInvoker;
HttpSession(const Socket::Ptr &pSock);
HttpSession(const toolkit::Socket::Ptr &pSock);
~HttpSession() 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;
static string urlDecode(const string &str);
static std::string urlDecode(const std::string &str);
protected:
//FlvMuxer override
void onWrite(const Buffer::Ptr &data, bool flush) override ;
void onWrite(const toolkit::Buffer::Ptr &data, bool flush) override ;
void onDetach() override;
std::shared_ptr<FlvMuxer> getSharedPtr() override;
@ -74,7 +71,7 @@ protected:
size_t len,
size_t totalSize,
size_t recvedSize){
shutdown(SockException(Err_shutdown,"http post content is too huge,default closed"));
shutdown(toolkit::SockException(toolkit::Err_shutdown,"http post content is too huge,default closed"));
}
/**
@ -92,7 +89,7 @@ protected:
* websocket协议打包后回调
* @param buffer websocket协议数据
*/
void onWebSocketEncodeData(Buffer::Ptr buffer) override;
void onWebSocketEncodeData(toolkit::Buffer::Ptr buffer) override;
/**
* webSocket数据包后回调
@ -107,11 +104,11 @@ private:
void Handle_Req_HEAD(ssize_t &content_len);
void Handle_Req_OPTIONS(ssize_t &content_len);
bool checkLiveStream(const string &schema, const string &url_suffix, const function<void(const MediaSource::Ptr &src)> &cb);
bool checkLiveStream(const std::string &schema, const std::string &url_suffix, const std::function<void(const MediaSource::Ptr &src)> &cb);
bool checkLiveStreamFlv(const function<void()> &cb = nullptr);
bool checkLiveStreamTS(const function<void()> &cb = nullptr);
bool checkLiveStreamFMP4(const function<void()> &fmp4_list = nullptr);
bool checkLiveStreamFlv(const std::function<void()> &cb = nullptr);
bool checkLiveStreamTS(const std::function<void()> &cb = nullptr);
bool checkLiveStreamFMP4(const std::function<void()> &fmp4_list = nullptr);
bool checkWebSocket();
bool emitHttpEvent(bool doInvoke);
@ -129,18 +126,17 @@ private:
bool _live_over_websocket = false;
//消耗的总流量
uint64_t _total_bytes_usage = 0;
string _origin;
std::string _origin;
Parser _parser;
Ticker _ticker;
toolkit::Ticker _ticker;
MediaInfo _mediaInfo;
TSMediaSource::RingType::RingReader::Ptr _ts_reader;
FMP4MediaSource::RingType::RingReader::Ptr _fmp4_reader;
//处理content数据的callback
function<bool (const char *data,size_t len) > _contentCallBack;
std::function<bool (const char *data,size_t len) > _contentCallBack;
};
typedef TcpSessionWithSSL<HttpSession> HttpsSession;
using HttpsSession = toolkit::TcpSessionWithSSL<HttpSession>;
} /* namespace mediakit */

View File

@ -10,6 +10,9 @@
#include "HttpTSPlayer.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts) {

View File

@ -15,17 +15,15 @@
#include "Player/MediaPlayer.h"
#include "Rtp/TSDecoder.h"
using namespace toolkit;
namespace mediakit {
//http-ts播发器未实现ts解复用
class HttpTSPlayer : public HttpClientImp {
public:
using Ptr = std::shared_ptr<HttpTSPlayer>;
using onComplete = std::function<void(const SockException &)>;
using onComplete = std::function<void(const toolkit::SockException &)>;
HttpTSPlayer(const EventPoller::Ptr &poller = nullptr, bool split_ts = true);
HttpTSPlayer(const toolkit::EventPoller::Ptr &poller = nullptr, bool split_ts = true);
~HttpTSPlayer() override = default;
/**
@ -40,9 +38,9 @@ public:
protected:
///HttpClient override///
void onResponseHeader(const string &status, const HttpHeader &header) override;
void onResponseHeader(const std::string &status, const HttpHeader &header) override;
void onResponseBody(const char *buf, size_t size) override;
void onResponseCompleted(const SockException &ex) override;
void onResponseCompleted(const toolkit::SockException &ex) override;
protected:
/**
@ -51,7 +49,7 @@ protected:
virtual void onPacket(const char *data, size_t len);
private:
void emitOnComplete(const SockException &ex);
void emitOnComplete(const toolkit::SockException &ex);
private:
bool _split_ts;

View File

@ -10,6 +10,9 @@
#include "TsPlayer.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {}

View File

@ -14,18 +14,17 @@
#include "HttpTSPlayer.h"
#include "Player/PlayerBase.h"
using namespace toolkit;
namespace mediakit {
class TsPlayer : public HttpTSPlayer , public PlayerBase {
public:
TsPlayer(const EventPoller::Ptr &poller);
TsPlayer(const toolkit::EventPoller::Ptr &poller);
~TsPlayer() override = default;
/**
*
*/
void play(const string &url) override;
void play(const std::string &url) override;
/**
*
@ -34,7 +33,7 @@ public:
protected:
void onResponseBody(const char *buf, size_t size) override;
void onResponseCompleted(const SockException &ex) override;
void onResponseCompleted(const toolkit::SockException &ex) override;
private:
bool _play_result = true;

View File

@ -14,15 +14,13 @@
#include <unordered_set>
#include "TsPlayer.h"
using namespace toolkit;
namespace mediakit {
class TsPlayerImp : public PlayerImp<TsPlayer, PlayerBase>, private TrackListener {
public:
using Ptr = std::shared_ptr<TsPlayerImp>;
TsPlayerImp(const EventPoller::Ptr &poller = nullptr);
TsPlayerImp(const toolkit::EventPoller::Ptr &poller = nullptr);
~TsPlayerImp() override = default;
private:
@ -31,9 +29,9 @@ private:
private:
//// PlayerBase override////
void onPlayResult(const SockException &ex) override;
vector<Track::Ptr> getTracks(bool ready = true) const override;
void onShutdown(const SockException &ex) override;
void onPlayResult(const toolkit::SockException &ex) override;
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
void onShutdown(const toolkit::SockException &ex) override;
private:
//// TrackListener override////

Some files were not shown because too many files have changed in this diff Show More