mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 04:08:57 +08:00
整理命名空间 (#1409)
* feat: remove using namespace mediakit in header files. (cherry picked from commit d44aeb339a8a0e1f0455be82b21fe4b1b536299f) * feat: remove using namespace mediakit in FFmpegSource.h * feat: remove using namespace mediakit in RtpExt.h * feat: remove using namespace mediakit in header files. * feat: remove using namespace std in header files. * feat: remove using namespace std in header files when zltoolkit remove std in header * 补充命名空间 * 整理命名空间 * 整理命名空间2 * 修复macos ci * 修复编译问题 * 修复编译问题2 * 修复编译问题3 Co-authored-by: Johnny <hellojinqiang@gmail.com> Co-authored-by: Xiaofeng Wang <wasphin@gmail.com>
This commit is contained in:
parent
80a0e27d8c
commit
c72cf4cbcc
2
.github/workflows/ccpp.yml
vendored
2
.github/workflows/ccpp.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: C/C++ CI
|
name: linux C/C++ CI
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
|
39
.github/workflows/macos.yml
vendored
Normal file
39
.github/workflows/macos.yml
vendored
Normal 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
|
@ -14,6 +14,8 @@
|
|||||||
#include "Http/HttpSession.h"
|
#include "Http/HttpSession.h"
|
||||||
#include "Rtsp/RtspSession.h"
|
#include "Rtsp/RtspSession.h"
|
||||||
#include "Record/MP4Recorder.h"
|
#include "Record/MP4Recorder.h"
|
||||||
|
|
||||||
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
static void* s_tag;
|
static void* s_tag;
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include "Http/HttpBody.h"
|
#include "Http/HttpBody.h"
|
||||||
#include "Http/HttpClient.h"
|
#include "Http/HttpClient.h"
|
||||||
#include "Rtsp/RtspSession.h"
|
#include "Rtsp/RtspSession.h"
|
||||||
|
|
||||||
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
///////////////////////////////////////////RecordInfo/////////////////////////////////////////////
|
///////////////////////////////////////////RecordInfo/////////////////////////////////////////////
|
||||||
@ -247,7 +249,7 @@ API_EXPORT mk_http_body API_CALL mk_http_body_from_string(const char *str, size_
|
|||||||
if(!len){
|
if(!len){
|
||||||
len = strlen(str);
|
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){
|
API_EXPORT mk_http_body API_CALL mk_http_body_from_file(const char *file_path){
|
||||||
|
@ -15,7 +15,7 @@ using namespace mediakit;
|
|||||||
|
|
||||||
class H264Splitter : public HttpRequestSplitter {
|
class H264Splitter : public HttpRequestSplitter {
|
||||||
public:
|
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() = default;
|
||||||
~H264Splitter() override;
|
~H264Splitter() override;
|
||||||
void setOnSplitted(onH264 cb);
|
void setOnSplitted(onH264 cb);
|
||||||
|
@ -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){
|
API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const char *key, const char *val){
|
||||||
assert(ctx && key && val);
|
assert(ctx && key && val);
|
||||||
PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
|
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->getPoller()->async([obj,key_str,val_str](){
|
||||||
//切换线程再操作
|
//切换线程再操作
|
||||||
(*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) {
|
API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *url) {
|
||||||
assert(ctx && url);
|
assert(ctx && url);
|
||||||
PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
|
PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
|
||||||
string url_str(url);
|
std::string url_str(url);
|
||||||
obj->getPoller()->async([obj,url_str](){
|
obj->getPoller()->async([obj,url_str](){
|
||||||
//切换线程再操作
|
//切换线程再操作
|
||||||
obj->play(url_str);
|
obj->play(url_str);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "mk_pusher.h"
|
#include "mk_pusher.h"
|
||||||
#include "Pusher/MediaPusher.h"
|
#include "Pusher/MediaPusher.h"
|
||||||
|
|
||||||
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
API_EXPORT mk_pusher API_CALL mk_pusher_create(const char *schema,const char *vhost,const char *app, const char *stream){
|
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){
|
API_EXPORT void API_CALL mk_pusher_set_option(mk_pusher ctx, const char *key, const char *val){
|
||||||
assert(ctx && key && val);
|
assert(ctx && key && val);
|
||||||
MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
|
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->getPoller()->async([obj,key_str,val_str](){
|
||||||
//切换线程再操作
|
//切换线程再操作
|
||||||
(*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){
|
API_EXPORT void API_CALL mk_pusher_publish(mk_pusher ctx,const char *url){
|
||||||
assert(ctx && url);
|
assert(ctx && url);
|
||||||
MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
|
MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
|
||||||
string url_str(url);
|
std::string url_str(url);
|
||||||
obj->getPoller()->async([obj,url_str](){
|
obj->getPoller()->async([obj,url_str](){
|
||||||
//切换线程再操作
|
//切换线程再操作
|
||||||
obj->publish(url_str);
|
obj->publish(url_str);
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include "mk_tcp_private.h"
|
#include "mk_tcp_private.h"
|
||||||
#include "Http/WebSocketClient.h"
|
#include "Http/WebSocketClient.h"
|
||||||
#include "Http/WebSocketSession.h"
|
#include "Http/WebSocketSession.h"
|
||||||
|
|
||||||
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx, char *buf){
|
API_EXPORT const char* API_CALL mk_sock_info_peer_ip(const mk_sock_info ctx, char *buf){
|
||||||
@ -62,19 +64,19 @@ API_EXPORT void API_CALL mk_tcp_session_send(const mk_tcp_session ctx,const char
|
|||||||
|
|
||||||
API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx,const char *data,size_t len){
|
API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx,const char *data,size_t len){
|
||||||
assert(ctx && data);
|
assert(ctx && data);
|
||||||
if(!len){
|
if (!len) {
|
||||||
len = strlen(data);
|
len = strlen(data);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
weak_ptr<TcpSession> weak_session = ((TcpSessionForC *)ctx)->shared_from_this();
|
std::weak_ptr<TcpSession> weak_session = ((TcpSessionForC *)ctx)->shared_from_this();
|
||||||
string str = string(data,len);
|
std::string str = std::string(data,len);
|
||||||
((TcpSessionForC *)ctx)->async([weak_session,str](){
|
((TcpSessionForC *)ctx)->async([weak_session,str](){
|
||||||
auto session_session = weak_session.lock();
|
auto session_session = weak_session.lock();
|
||||||
if(session_session){
|
if(session_session){
|
||||||
session_session->SockSender::send(str);
|
session_session->SockSender::send(str);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}catch (std::exception &ex){
|
} catch (std::exception &ex) {
|
||||||
WarnL << "can not got the strong pionter of this mk_tcp_session:" << ex.what();
|
WarnL << "can not got the strong pionter of this mk_tcp_session:" << ex.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,13 +210,13 @@ TcpClientForC::Ptr *mk_tcp_client_create_l(mk_tcp_client_events *events, mk_tcp_
|
|||||||
case mk_type_tcp:
|
case mk_type_tcp:
|
||||||
return new TcpClientForC::Ptr(new TcpClientForC(events));
|
return new TcpClientForC::Ptr(new TcpClientForC(events));
|
||||||
case mk_type_ssl:
|
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:
|
case mk_type_ws:
|
||||||
//此处你也可以修改WebSocketHeader::BINARY
|
//此处你也可以修改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:
|
case mk_type_wss:
|
||||||
//此处你也可以修改WebSocketHeader::BINARY
|
//此处你也可以修改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:
|
default:
|
||||||
return nullptr;
|
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){
|
API_EXPORT void API_CALL mk_tcp_client_send_safe(mk_tcp_client ctx, const char *data, int len){
|
||||||
assert(ctx && data);
|
assert(ctx && data);
|
||||||
TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
|
TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx;
|
||||||
weak_ptr<TcpClient> weakClient = *client;
|
std::weak_ptr<TcpClient> weakClient = *client;
|
||||||
auto buf = BufferRaw::create();
|
auto buf = BufferRaw::create();
|
||||||
buf->assign(data,len);
|
buf->assign(data,len);
|
||||||
(*client)->async([weakClient,buf](){
|
(*client)->async([weakClient,buf](){
|
||||||
|
@ -14,17 +14,16 @@
|
|||||||
#include "mk_tcp.h"
|
#include "mk_tcp.h"
|
||||||
#include "Network/TcpClient.h"
|
#include "Network/TcpClient.h"
|
||||||
#include "Network/TcpSession.h"
|
#include "Network/TcpSession.h"
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
class TcpClientForC : public TcpClient {
|
class TcpClientForC : public toolkit::TcpClient {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<TcpClientForC> Ptr;
|
typedef std::shared_ptr<TcpClientForC> Ptr;
|
||||||
TcpClientForC(mk_tcp_client_events *events) ;
|
TcpClientForC(mk_tcp_client_events *events) ;
|
||||||
~TcpClientForC() override ;
|
~TcpClientForC() override ;
|
||||||
void onRecv(const Buffer::Ptr &pBuf) override;
|
void onRecv(const toolkit::Buffer::Ptr &pBuf) override;
|
||||||
void onErr(const SockException &ex) override;
|
void onErr(const toolkit::SockException &ex) override;
|
||||||
void onManager() override;
|
void onManager() override;
|
||||||
void onConnect(const SockException &ex) override;
|
void onConnect(const toolkit::SockException &ex) override;
|
||||||
void setClient(mk_tcp_client client);
|
void setClient(mk_tcp_client client);
|
||||||
void *_user_data;
|
void *_user_data;
|
||||||
private:
|
private:
|
||||||
@ -32,12 +31,12 @@ private:
|
|||||||
mk_tcp_client _client;
|
mk_tcp_client _client;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TcpSessionForC : public TcpSession {
|
class TcpSessionForC : public toolkit::TcpSession {
|
||||||
public:
|
public:
|
||||||
TcpSessionForC(const Socket::Ptr &pSock) ;
|
TcpSessionForC(const toolkit::Socket::Ptr &pSock) ;
|
||||||
~TcpSessionForC() override = default;
|
~TcpSessionForC() override = default;
|
||||||
void onRecv(const Buffer::Ptr &buffer) override ;
|
void onRecv(const toolkit::Buffer::Ptr &buffer) override ;
|
||||||
void onError(const SockException &err) override;
|
void onError(const toolkit::SockException &err) override;
|
||||||
void onManager() override;
|
void onManager() override;
|
||||||
void *_user_data;
|
void *_user_data;
|
||||||
uint16_t _local_port;
|
uint16_t _local_port;
|
||||||
|
@ -91,7 +91,7 @@ private:
|
|||||||
on_mk_timer _cb = nullptr;
|
on_mk_timer _cb = nullptr;
|
||||||
void *_user_data = nullptr;
|
void *_user_data = nullptr;
|
||||||
recursive_mutex _mxt;
|
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){
|
API_EXPORT mk_timer API_CALL mk_timer_create(mk_thread ctx,uint64_t delay_ms,on_mk_timer cb, void *user_data){
|
||||||
|
@ -8,10 +8,13 @@
|
|||||||
* may be found in the AUTHORS file in the root of the source tree.
|
* may be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "mk_util.h"
|
#include "mk_util.h"
|
||||||
#include <assert.h>
|
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
|
@ -30,9 +30,6 @@ extern "C" {
|
|||||||
#include "SDLAudioDevice.h"
|
#include "SDLAudioDevice.h"
|
||||||
#include "FFMpegDecoder.h"
|
#include "FFMpegDecoder.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
class AudioSRCDelegate {
|
class AudioSRCDelegate {
|
||||||
public:
|
public:
|
||||||
virtual ~AudioSRCDelegate() {};
|
virtual ~AudioSRCDelegate() {};
|
||||||
@ -58,7 +55,7 @@ private:
|
|||||||
int _buf_size = 0;
|
int _buf_size = 0;
|
||||||
std::shared_ptr<char> _buf;
|
std::shared_ptr<char> _buf;
|
||||||
AudioSRCDelegate *_delegate = nullptr;
|
AudioSRCDelegate *_delegate = nullptr;
|
||||||
BufferLikeString _target_buf;
|
toolkit::BufferLikeString _target_buf;
|
||||||
SDL_AudioCVT _audio_cvt;
|
SDL_AudioCVT _audio_cvt;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,8 +76,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
int _sample_rate, _channel;
|
int _sample_rate, _channel;
|
||||||
SDL_AudioFormat _format;
|
SDL_AudioFormat _format;
|
||||||
mutex _mtx;
|
std::mutex _mtx;
|
||||||
BufferLikeString _buffer;
|
toolkit::BufferLikeString _buffer;
|
||||||
SDLAudioDevice::Ptr _device;
|
SDLAudioDevice::Ptr _device;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#define MAX_DELAY_SECOND 3
|
#define MAX_DELAY_SECOND 3
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
static string ffmpeg_err(int errnum) {
|
static string ffmpeg_err(int errnum) {
|
||||||
|
@ -60,15 +60,15 @@ public:
|
|||||||
~TaskManager();
|
~TaskManager();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void startThread(const string &name);
|
void startThread(const std::string &name);
|
||||||
void stopThread();
|
void stopThread();
|
||||||
|
|
||||||
void addEncodeTask(function<void()> task);
|
void addEncodeTask(std::function<void()> task);
|
||||||
void addDecodeTask(bool key_frame, function<void()> task);
|
void addDecodeTask(bool key_frame, std::function<void()> task);
|
||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onThreadRun(const string &name);
|
void onThreadRun(const std::string &name);
|
||||||
void pushExit();
|
void pushExit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -81,36 +81,36 @@ private:
|
|||||||
private:
|
private:
|
||||||
bool _decode_drop_start = false;
|
bool _decode_drop_start = false;
|
||||||
bool _exit = false;
|
bool _exit = false;
|
||||||
mutex _task_mtx;
|
std::mutex _task_mtx;
|
||||||
semaphore _sem;
|
toolkit::semaphore _sem;
|
||||||
List<function<void()> > _task;
|
toolkit::List<std::function<void()> > _task;
|
||||||
std::shared_ptr<thread> _thread;
|
std::shared_ptr<std::thread> _thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FFmpegDecoder : private TaskManager {
|
class FFmpegDecoder : private TaskManager {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<FFmpegDecoder>;
|
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();
|
~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 setOnDecode(onDec cb);
|
||||||
void flush();
|
void flush();
|
||||||
const AVCodecContext *getContext() const;
|
const AVCodecContext *getContext() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onDecode(const FFmpegFrame::Ptr &frame);
|
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);
|
bool decodeFrame(const char *data, size_t size, uint32_t dts, uint32_t pts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _do_merger = false;
|
bool _do_merger = false;
|
||||||
Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
onDec _cb;
|
onDec _cb;
|
||||||
std::shared_ptr<AVCodecContext> _context;
|
std::shared_ptr<AVCodecContext> _context;
|
||||||
FrameMerger _merger{FrameMerger::h264_prefix};
|
mediakit::FrameMerger _merger { mediakit::FrameMerger::h264_prefix };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FFMpegDecoder_H_ */
|
#endif /* FFMpegDecoder_H_ */
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#define DEFAULT_CHANNEL 2
|
#define DEFAULT_CHANNEL 2
|
||||||
#define DEFAULT_SAMPLES 1024
|
#define DEFAULT_SAMPLES 1024
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class AudioSRC;
|
class AudioSRC;
|
||||||
|
|
||||||
@ -43,8 +42,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
std::shared_ptr<char> _play_buf;
|
std::shared_ptr<char> _play_buf;
|
||||||
SDL_AudioSpec _audio_config;
|
SDL_AudioSpec _audio_config;
|
||||||
recursive_mutex _channel_mtx;
|
std::recursive_mutex _channel_mtx;
|
||||||
unordered_set<AudioSRC *> _channels;
|
std::unordered_set<AudioSRC *> _channels;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SDLAUDIOMIXER_SDLAUDIODEVICE_H_ */
|
#endif /* SDLAUDIOMIXER_SDLAUDIODEVICE_H_ */
|
||||||
|
@ -25,12 +25,8 @@ extern "C" {
|
|||||||
#pragma comment(lib,"SDL2.lib")
|
#pragma comment(lib,"SDL2.lib")
|
||||||
#endif //defined(_WIN32)
|
#endif //defined(_WIN32)
|
||||||
|
|
||||||
using namespace toolkit;
|
|
||||||
using namespace mediakit;
|
|
||||||
|
|
||||||
#define REFRESH_EVENT (SDL_USEREVENT + 1)
|
#define REFRESH_EVENT (SDL_USEREVENT + 1)
|
||||||
|
|
||||||
|
|
||||||
class SDLDisplayerHelper
|
class SDLDisplayerHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -44,7 +40,7 @@ public:
|
|||||||
template<typename FUN>
|
template<typename FUN>
|
||||||
void doTask(FUN &&f){
|
void doTask(FUN &&f){
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lck(_mtxTask);
|
std::lock_guard<std::mutex> lck(_mtxTask);
|
||||||
_taskList.emplace_back(f);
|
_taskList.emplace_back(f);
|
||||||
}
|
}
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
@ -61,8 +57,8 @@ public:
|
|||||||
switch (event.type){
|
switch (event.type){
|
||||||
case REFRESH_EVENT:{
|
case REFRESH_EVENT:{
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lck(_mtxTask);
|
std::lock_guard<std::mutex> lck(_mtxTask);
|
||||||
if(_taskList.empty()){
|
if (_taskList.empty()) {
|
||||||
//not reachable
|
//not reachable
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -102,17 +98,17 @@ public:
|
|||||||
using Ptr = std::shared_ptr<YuvDisplayer>;
|
using Ptr = std::shared_ptr<YuvDisplayer>;
|
||||||
|
|
||||||
YuvDisplayer(void *hwnd = nullptr,const char *title = "untitled"){
|
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) {
|
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) == -1) {
|
||||||
string err = "初始化SDL失败:";
|
std::string err = "初始化SDL失败:";
|
||||||
err+= SDL_GetError();
|
err+= SDL_GetError();
|
||||||
ErrorL << err;
|
ErrorL << err;
|
||||||
throw std::runtime_error(err);
|
throw std::runtime_error(err);
|
||||||
}
|
}
|
||||||
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_CRITICAL);
|
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_CRITICAL);
|
||||||
SDL_LogSetOutputFunction([](void *userdata, int category, SDL_LogPriority priority, const char *message){
|
SDL_LogSetOutputFunction([](void *userdata, int category, SDL_LogPriority priority, const char *message) {
|
||||||
DebugL << category << " " << priority << message;
|
DebugL << category << " " << priority << message;
|
||||||
},nullptr);
|
}, nullptr);
|
||||||
InfoL << "SDL_Init";
|
InfoL << "SDL_Init";
|
||||||
}, []() {
|
}, []() {
|
||||||
SDLDisplayerHelper::Destory();
|
SDLDisplayerHelper::Destory();
|
||||||
@ -194,7 +190,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
string _title;
|
std::string _title;
|
||||||
SDL_Window *_win = nullptr;
|
SDL_Window *_win = nullptr;
|
||||||
SDL_Renderer *_render = nullptr;
|
SDL_Renderer *_render = nullptr;
|
||||||
SDL_Texture *_texture = nullptr;
|
SDL_Texture *_texture = nullptr;
|
||||||
|
@ -116,7 +116,7 @@ int main(int argc, char *argv[]) {
|
|||||||
WarnL << "play shutdown: " << ex.what();
|
WarnL << "play shutdown: " << ex.what();
|
||||||
});
|
});
|
||||||
|
|
||||||
(*player)[kRtpType] = atoi(argv[2]);
|
(*player)[Client::kRtpType] = atoi(argv[2]);
|
||||||
//不等待track ready再回调播放成功事件,这样可以加快秒开速度
|
//不等待track ready再回调播放成功事件,这样可以加快秒开速度
|
||||||
(*player)[Client::kWaitTrackReady] = false;
|
(*player)[Client::kWaitTrackReady] = false;
|
||||||
player->play(argv[1]);
|
player->play(argv[1]);
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
#include "Thread/WorkThreadPool.h"
|
#include "Thread/WorkThreadPool.h"
|
||||||
#include "Network/sockutil.h"
|
#include "Network/sockutil.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
using namespace mediakit;
|
||||||
|
|
||||||
namespace FFmpeg {
|
namespace FFmpeg {
|
||||||
#define FFmpeg_FIELD "ffmpeg."
|
#define FFmpeg_FIELD "ffmpeg."
|
||||||
const string kBin = FFmpeg_FIELD"bin";
|
const string kBin = FFmpeg_FIELD"bin";
|
||||||
|
@ -19,12 +19,8 @@
|
|||||||
#include "Network/Socket.h"
|
#include "Network/Socket.h"
|
||||||
#include "Common/MediaSource.h"
|
#include "Common/MediaSource.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
using namespace mediakit;
|
|
||||||
|
|
||||||
namespace FFmpeg {
|
namespace FFmpeg {
|
||||||
extern const string kSnap;
|
extern const std::string kSnap;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FFmpegSnap {
|
class FFmpegSnap {
|
||||||
@ -34,16 +30,16 @@ public:
|
|||||||
/// \param save_path 截图jpeg文件保存路径
|
/// \param save_path 截图jpeg文件保存路径
|
||||||
/// \param timeout_sec 生成截图超时时间(防止阻塞太久)
|
/// \param timeout_sec 生成截图超时时间(防止阻塞太久)
|
||||||
/// \param cb 生成截图成功与否回调
|
/// \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:
|
private:
|
||||||
FFmpegSnap() = delete;
|
FFmpegSnap() = delete;
|
||||||
~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:
|
public:
|
||||||
typedef shared_ptr<FFmpegSource> Ptr;
|
using Ptr = std::shared_ptr<FFmpegSource>;
|
||||||
typedef function<void(const SockException &ex)> onPlay;
|
using onPlay = std::function<void(const toolkit::SockException &ex)>;
|
||||||
|
|
||||||
FFmpegSource();
|
FFmpegSource();
|
||||||
~FFmpegSource();
|
~FFmpegSource();
|
||||||
@ -51,7 +47,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 设置主动关闭回调
|
* 设置主动关闭回调
|
||||||
*/
|
*/
|
||||||
void setOnClose(const function<void()> &cb);
|
void setOnClose(const std::function<void()> &cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始播放url
|
* 开始播放url
|
||||||
@ -61,7 +57,7 @@ public:
|
|||||||
* @param timeout_ms 等待结果超时时间,单位毫秒
|
* @param timeout_ms 等待结果超时时间,单位毫秒
|
||||||
* @param cb 成功与否回调
|
* @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);
|
void setupRecordFlag(bool enable_hls, bool enable_mp4);
|
||||||
|
|
||||||
private:
|
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 startTimer(int timeout_ms);
|
||||||
void onGetMediaSource(const MediaSource::Ptr &src);
|
void onGetMediaSource(const mediakit::MediaSource::Ptr &src);
|
||||||
|
|
||||||
///////MediaSourceEvent override///////
|
///////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或者文件路径
|
//获取媒体源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:
|
private:
|
||||||
bool _enable_hls = false;
|
bool _enable_hls = false;
|
||||||
bool _enable_mp4 = false;
|
bool _enable_mp4 = false;
|
||||||
Process _process;
|
Process _process;
|
||||||
Timer::Ptr _timer;
|
toolkit::Timer::Ptr _timer;
|
||||||
EventPoller::Ptr _poller;
|
toolkit::EventPoller::Ptr _poller;
|
||||||
MediaInfo _media_info;
|
mediakit::MediaInfo _media_info;
|
||||||
string _src_url;
|
std::string _src_url;
|
||||||
string _dst_url;
|
std::string _dst_url;
|
||||||
string _ffmpeg_cmd_key;
|
std::string _ffmpeg_cmd_key;
|
||||||
function<void()> _onClose;
|
std::function<void()> _onClose;
|
||||||
Ticker _replay_ticker;
|
toolkit::Ticker _replay_ticker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "Poller/EventPoller.h"
|
#include "Poller/EventPoller.h"
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
void Process::run(const string &cmd, const string &log_file_tmp) {
|
void Process::run(const string &cmd, const string &log_file_tmp) {
|
||||||
kill(2000);
|
kill(2000);
|
||||||
|
@ -19,13 +19,12 @@ typedef int pid_t;
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Process {
|
class Process {
|
||||||
public:
|
public:
|
||||||
Process();
|
Process();
|
||||||
~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);
|
void kill(int max_delay,bool force = false);
|
||||||
bool wait(bool block = true);
|
bool wait(bool block = true);
|
||||||
int exit_code();
|
int exit_code();
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "Util/NoticeCenter.h"
|
#include "Util/NoticeCenter.h"
|
||||||
#include "Util/uv_errno.h"
|
#include "Util/uv_errno.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
const int MAX_STACK_FRAMES = 128;
|
const int MAX_STACK_FRAMES = 128;
|
||||||
#define BroadcastOnCrashDumpArgs int &sig,const vector<vector<string> > &stack
|
#define BroadcastOnCrashDumpArgs int &sig,const vector<vector<string> > &stack
|
||||||
|
@ -12,11 +12,10 @@
|
|||||||
#define ZLMEDIAKIT_SYSTEM_H
|
#define ZLMEDIAKIT_SYSTEM_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class System {
|
class System {
|
||||||
public:
|
public:
|
||||||
static string execute(const string &cmd);
|
static std::string execute(const std::string &cmd);
|
||||||
static void startDaemon();
|
static void startDaemon();
|
||||||
static void systemSetup();
|
static void systemSetup();
|
||||||
};
|
};
|
||||||
|
@ -48,7 +48,8 @@
|
|||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Json;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
@ -461,11 +462,11 @@ void addStreamProxy(const string &vhost, const string &app, const string &stream
|
|||||||
s_proxyMap[key] = player;
|
s_proxyMap[key] = player;
|
||||||
|
|
||||||
//指定RTP over TCP(播放rtsp时有效)
|
//指定RTP over TCP(播放rtsp时有效)
|
||||||
(*player)[kRtpType] = rtp_type;
|
(*player)[Client::kRtpType] = rtp_type;
|
||||||
|
|
||||||
if (timeout_sec > 0.1) {
|
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;
|
s_proxyPusherMap[key] = pusher;
|
||||||
|
|
||||||
//指定RTP over TCP(播放rtsp时有效)
|
//指定RTP over TCP(播放rtsp时有效)
|
||||||
(*pusher)[kRtpType] = rtp_type;
|
(*pusher)[Client::kRtpType] = rtp_type;
|
||||||
|
|
||||||
if (timeout_sec > 0.1) {
|
if (timeout_sec > 0.1) {
|
||||||
//推流握手超时时间
|
//推流握手超时时间
|
||||||
(*pusher)[kTimeoutMS] = timeout_sec * 1000;
|
(*pusher)[Client::kTimeoutMS] = timeout_sec * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试
|
//开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试
|
||||||
|
@ -18,23 +18,18 @@
|
|||||||
#include "Network/Socket.h"
|
#include "Network/Socket.h"
|
||||||
#include "Http/HttpSession.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 {
|
namespace mediakit {
|
||||||
////////////RTSP服务器配置///////////
|
////////////RTSP服务器配置///////////
|
||||||
namespace Rtsp {
|
namespace Rtsp {
|
||||||
extern const string kPort;
|
extern const std::string kPort;
|
||||||
} //namespace Rtsp
|
} //namespace Rtsp
|
||||||
|
|
||||||
////////////RTMP服务器配置///////////
|
////////////RTMP服务器配置///////////
|
||||||
namespace Rtmp {
|
namespace Rtmp {
|
||||||
extern const string kPort;
|
extern const std::string kPort;
|
||||||
} //namespace RTMP
|
} //namespace RTMP
|
||||||
} // namespace mediakit
|
} // namespace mediakit
|
||||||
|
|
||||||
@ -79,25 +74,25 @@ public:
|
|||||||
~SuccessException() = default;
|
~SuccessException() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ApiArgsType = map<string, string, StrCaseCompare>;
|
using ApiArgsType = std::map<std::string, std::string, mediakit::StrCaseCompare>;
|
||||||
|
|
||||||
template<typename Args, typename First>
|
template<typename Args, typename First>
|
||||||
string getValue(Args &args, const First &first) {
|
std::string getValue(Args &args, const First &first) {
|
||||||
return args[first];
|
return args[first];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename 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();
|
return args[first].asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename First>
|
template<typename First>
|
||||||
string getValue(string &args, const First &first) {
|
std::string getValue(std::string &args, const First &first) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename First>
|
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];
|
auto ret = parser.getUrlArgs()[first];
|
||||||
if (!ret.empty()) {
|
if (!ret.empty()) {
|
||||||
return ret;
|
return ret;
|
||||||
@ -106,12 +101,12 @@ string getValue(const Parser &parser, const First &first) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename First>
|
template<typename First>
|
||||||
string getValue(Parser &parser, const First &first) {
|
std::string getValue(mediakit::Parser &parser, const First &first) {
|
||||||
return getValue((const Parser &) parser, first);
|
return getValue((const mediakit::Parser &) parser, first);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Args, typename 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);
|
auto ret = getValue(args, first);
|
||||||
if (!ret.empty()) {
|
if (!ret.empty()) {
|
||||||
return ret;
|
return ret;
|
||||||
@ -122,24 +117,24 @@ string getValue(const Parser &parser, Args &args, const First &first) {
|
|||||||
template<typename Args>
|
template<typename Args>
|
||||||
class HttpAllArgs {
|
class HttpAllArgs {
|
||||||
public:
|
public:
|
||||||
HttpAllArgs(const Parser &parser, Args &args) {
|
HttpAllArgs(const mediakit::Parser &parser, Args &args) {
|
||||||
_get_args = [&args]() {
|
_get_args = [&args]() {
|
||||||
return (void *) &args;
|
return (void *) &args;
|
||||||
};
|
};
|
||||||
_get_parser = [&parser]() -> const Parser & {
|
_get_parser = [&parser]() -> const mediakit::Parser & {
|
||||||
return 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);
|
return getValue(that.getParser(), that.getArgs(), key);
|
||||||
};
|
};
|
||||||
_clone = [&](HttpAllArgs &that) {
|
_clone = [&](HttpAllArgs &that) {
|
||||||
that._get_args = [args]() {
|
that._get_args = [args]() {
|
||||||
return (void *) &args;
|
return (void *) &args;
|
||||||
};
|
};
|
||||||
that._get_parser = [parser]() -> const Parser & {
|
that._get_parser = [parser]() -> const mediakit::Parser & {
|
||||||
return 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);
|
return getValue(that.getParser(), that.getArgs(), key);
|
||||||
};
|
};
|
||||||
that._cache_able = true;
|
that._cache_able = true;
|
||||||
@ -160,11 +155,11 @@ public:
|
|||||||
~HttpAllArgs() = default;
|
~HttpAllArgs() = default;
|
||||||
|
|
||||||
template<typename Key>
|
template<typename Key>
|
||||||
variant operator[](const Key &key) const {
|
toolkit::variant operator[](const Key &key) const {
|
||||||
return (variant)_get_value(*(HttpAllArgs*)this, key);
|
return (toolkit::variant)_get_value(*(HttpAllArgs*)this, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Parser &getParser() const {
|
const mediakit::Parser &getParser() const {
|
||||||
return _get_parser();
|
return _get_parser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,34 +173,34 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool _cache_able = false;
|
bool _cache_able = false;
|
||||||
function<void *() > _get_args;
|
std::function<void *() > _get_args;
|
||||||
function<const Parser &() > _get_parser;
|
std::function<const mediakit::Parser &() > _get_parser;
|
||||||
function<string(HttpAllArgs &that, const string &key)> _get_value;
|
std::function<std::string(HttpAllArgs &that, const std::string &key)> _get_value;
|
||||||
function<void(HttpAllArgs &that) > _clone;
|
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 toolkit::SockInfo &sender, mediakit::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_MAP_ASYNC API_ARGS_MAP, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||||
#define API_ARGS_JSON SockInfo &sender, HttpSession::KeyValue &headerOut, const HttpAllArgs<Json::Value> &allArgs, Json::Value &val
|
#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 HttpSession::HttpResponseInvoker &invoker
|
#define API_ARGS_JSON_ASYNC API_ARGS_JSON, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||||
#define API_ARGS_STRING SockInfo &sender, HttpSession::KeyValue &headerOut, const HttpAllArgs<string> &allArgs, Json::Value &val
|
#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 HttpSession::HttpResponseInvoker &invoker
|
#define API_ARGS_STRING_ASYNC API_ARGS_STRING, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||||
#define API_ARGS_VALUE sender, headerOut, allArgs, val
|
#define API_ARGS_VALUE sender, headerOut, allArgs, val
|
||||||
|
|
||||||
//注册http请求参数是map<string, variant, StrCaseCompare>类型的http api
|
//注册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
|
//注册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参数对象)
|
//注册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
|
//注册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
|
//注册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
|
//注册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>
|
template<typename Args, typename First>
|
||||||
bool checkArgs(Args &args, const First &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 installWebApi();
|
||||||
void unInstallWebApi();
|
void unInstallWebApi();
|
||||||
Value makeMediaSourceJson(MediaSource &media);
|
Json::Value makeMediaSourceJson(mediakit::MediaSource &media);
|
||||||
void getStatisticJson(const function<void(Value &val)> &cb);
|
void getStatisticJson(const std::function<void(Json::Value &val)> &cb);
|
||||||
void addStreamProxy(const string &vhost, const string &app, const string &stream, const string &url, int retry_count,
|
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,
|
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
|
#endif //ZLMEDIAKIT_WEBAPI_H
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include "WebHook.h"
|
#include "WebHook.h"
|
||||||
#include "WebApi.h"
|
#include "WebApi.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Json;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
|
@ -14,21 +14,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "jsoncpp/json.h"
|
#include "jsoncpp/json.h"
|
||||||
using namespace std;
|
|
||||||
using namespace Json;
|
|
||||||
|
|
||||||
//支持json或urlencoded方式传输参数
|
//支持json或urlencoded方式传输参数
|
||||||
#define JSON_ARGS
|
#define JSON_ARGS
|
||||||
|
|
||||||
#ifdef JSON_ARGS
|
#ifdef JSON_ARGS
|
||||||
typedef Value ArgsType;
|
typedef Json::Value ArgsType;
|
||||||
#else
|
#else
|
||||||
typedef HttpArgs ArgsType;
|
typedef mediakit::HttpArgs ArgsType;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Hook {
|
namespace Hook {
|
||||||
//web hook回复最大超时时间
|
//web hook回复最大超时时间
|
||||||
extern const string kTimeoutSec;
|
extern const std::string kTimeoutSec;
|
||||||
}//namespace Hook
|
}//namespace Hook
|
||||||
|
|
||||||
void installWebHook();
|
void installWebHook();
|
||||||
@ -39,5 +37,5 @@ void unInstallWebHook();
|
|||||||
* @param body 请求body
|
* @param body 请求body
|
||||||
* @param func 回调
|
* @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
|
#endif //ZLMEDIAKIT_WEBHOOK_H
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "Codec/H264Encoder.h"
|
#include "Codec/H264Encoder.h"
|
||||||
#endif //ENABLE_X264
|
#endif //ENABLE_X264
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
#include "Util/TimeTicker.h"
|
#include "Util/TimeTicker.h"
|
||||||
#include "Common/MultiMediaSourceMuxer.h"
|
#include "Common/MultiMediaSourceMuxer.h"
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
@ -48,7 +46,7 @@ class DevChannel : public MultiMediaSourceMuxer{
|
|||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<DevChannel> Ptr;
|
typedef std::shared_ptr<DevChannel> Ptr;
|
||||||
//fDuration<=0为直播,否则为点播
|
//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);
|
float duration = 0, bool enable_hls = true, bool enable_mp4 = false);
|
||||||
|
|
||||||
~DevChannel() override ;
|
~DevChannel() override ;
|
||||||
@ -126,7 +124,7 @@ private:
|
|||||||
std::shared_ptr<AACEncoder> _pAacEnc;
|
std::shared_ptr<AACEncoder> _pAacEnc;
|
||||||
std::shared_ptr<VideoInfo> _video;
|
std::shared_ptr<VideoInfo> _video;
|
||||||
std::shared_ptr<AudioInfo> _audio;
|
std::shared_ptr<AudioInfo> _audio;
|
||||||
SmoothTicker _aTicker[2];
|
toolkit::SmoothTicker _aTicker[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include "MediaSink.h"
|
#include "MediaSink.h"
|
||||||
#include "Extension/AAC.h"
|
#include "Extension/AAC.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
bool MediaSink::addTrack(const Track::Ptr &track_in) {
|
bool MediaSink::addTrack(const Track::Ptr &track_in) {
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
#include "Extension/Frame.h"
|
#include "Extension/Frame.h"
|
||||||
#include "Extension/Track.h"
|
#include "Extension/Track.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
class TrackListener {
|
class TrackListener {
|
||||||
@ -106,7 +103,7 @@ public:
|
|||||||
* 获取所有Track
|
* 获取所有Track
|
||||||
* @param trackReady 是否获取已经准备好的Track
|
* @param trackReady 是否获取已经准备好的Track
|
||||||
*/
|
*/
|
||||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
std::vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回是否所有track已经准备完成
|
* 返回是否所有track已经准备完成
|
||||||
@ -154,10 +151,10 @@ private:
|
|||||||
private:
|
private:
|
||||||
bool _all_track_ready = false;
|
bool _all_track_ready = false;
|
||||||
size_t _max_track_size = 2;
|
size_t _max_track_size = 2;
|
||||||
unordered_map<int, pair<Track::Ptr, bool/*got frame*/> > _track_map;
|
std::unordered_map<int, std::pair<Track::Ptr, bool/*got frame*/> > _track_map;
|
||||||
unordered_map<int, List<Frame::Ptr> > _frame_unread;
|
std::unordered_map<int, toolkit::List<Frame::Ptr> > _frame_unread;
|
||||||
unordered_map<int, function<void()> > _track_ready_callback;
|
std::unordered_map<int, std::function<void()> > _track_ready_callback;
|
||||||
Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
MuteAudioMaker::Ptr _mute_audio_maker;
|
MuteAudioMaker::Ptr _mute_audio_maker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
#include "Network/sockutil.h"
|
#include "Network/sockutil.h"
|
||||||
#include "Network/TcpSession.h"
|
#include "Network/TcpSession.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace toolkit {
|
namespace toolkit {
|
||||||
|
@ -29,9 +29,6 @@
|
|||||||
#include "Extension/Track.h"
|
#include "Extension/Track.h"
|
||||||
#include "Record/Recorder.h"
|
#include "Record/Recorder.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace toolkit{
|
namespace toolkit{
|
||||||
class Session;
|
class Session;
|
||||||
}// namespace toolkit
|
}// namespace toolkit
|
||||||
@ -50,7 +47,7 @@ enum class MediaOriginType : uint8_t {
|
|||||||
rtc_push,
|
rtc_push,
|
||||||
};
|
};
|
||||||
|
|
||||||
string getOriginTypeString(MediaOriginType type);
|
std::string getOriginTypeString(MediaOriginType type);
|
||||||
|
|
||||||
class MediaSource;
|
class MediaSource;
|
||||||
class MediaSourceEvent{
|
class MediaSourceEvent{
|
||||||
@ -62,9 +59,9 @@ public:
|
|||||||
// 获取媒体源类型
|
// 获取媒体源类型
|
||||||
virtual MediaOriginType getOriginType(MediaSource &sender) const { return MediaOriginType::unknown; }
|
virtual MediaOriginType getOriginType(MediaSource &sender) const { return MediaOriginType::unknown; }
|
||||||
// 获取媒体源url或者文件路径
|
// 获取媒体源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; }
|
virtual bool seekTo(MediaSource &sender, uint32_t stamp) { return false; }
|
||||||
@ -83,18 +80,18 @@ public:
|
|||||||
|
|
||||||
////////////////////////仅供MultiMediaSourceMuxer对象继承////////////////////////
|
////////////////////////仅供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; };
|
virtual bool isRecording(MediaSource &sender, Recorder::type type) { return false; };
|
||||||
// 获取所有track相关信息
|
// 获取所有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
|
// 开始发送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
|
// 停止发送ps-rtp
|
||||||
virtual bool stopSendRtp(MediaSource &sender, const string &ssrc) {return false; }
|
virtual bool stopSendRtp(MediaSource &sender, const std::string &ssrc) {return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Timer::Ptr _async_close_timer;
|
toolkit::Timer::Ptr _async_close_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
//该对象用于拦截感兴趣的MediaSourceEvent事件
|
//该对象用于拦截感兴趣的MediaSourceEvent事件
|
||||||
@ -107,8 +104,8 @@ public:
|
|||||||
std::shared_ptr<MediaSourceEvent> getDelegate() const;
|
std::shared_ptr<MediaSourceEvent> getDelegate() const;
|
||||||
|
|
||||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||||
string getOriginUrl(MediaSource &sender) const override;
|
std::string getOriginUrl(MediaSource &sender) const override;
|
||||||
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
std::shared_ptr<toolkit::SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||||
|
|
||||||
bool seekTo(MediaSource &sender, uint32_t stamp) override;
|
bool seekTo(MediaSource &sender, uint32_t stamp) override;
|
||||||
bool pause(MediaSource &sender, bool pause) override;
|
bool pause(MediaSource &sender, bool pause) override;
|
||||||
@ -117,11 +114,11 @@ public:
|
|||||||
int totalReaderCount(MediaSource &sender) override;
|
int totalReaderCount(MediaSource &sender) override;
|
||||||
void onReaderChanged(MediaSource &sender, int size) override;
|
void onReaderChanged(MediaSource &sender, int size) override;
|
||||||
void onRegist(MediaSource &sender, bool regist) 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;
|
bool isRecording(MediaSource &sender, Recorder::type type) override;
|
||||||
vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
|
std::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;
|
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 string &ssrc) override;
|
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::weak_ptr<MediaSourceEvent> _listener;
|
std::weak_ptr<MediaSourceEvent> _listener;
|
||||||
@ -134,18 +131,18 @@ class MediaInfo{
|
|||||||
public:
|
public:
|
||||||
~MediaInfo() {}
|
~MediaInfo() {}
|
||||||
MediaInfo() {}
|
MediaInfo() {}
|
||||||
MediaInfo(const string &url) { parse(url); }
|
MediaInfo(const std::string &url) { parse(url); }
|
||||||
void parse(const string &url);
|
void parse(const std::string &url);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string _full_url;
|
std::string _full_url;
|
||||||
string _schema;
|
std::string _schema;
|
||||||
string _host;
|
std::string _host;
|
||||||
string _port;
|
std::string _port;
|
||||||
string _vhost;
|
std::string _vhost;
|
||||||
string _app;
|
std::string _app;
|
||||||
string _streamid;
|
std::string _streamid;
|
||||||
string _param_strs;
|
std::string _param_strs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BytesSpeed {
|
class BytesSpeed {
|
||||||
@ -191,40 +188,40 @@ private:
|
|||||||
private:
|
private:
|
||||||
int _speed = 0;
|
int _speed = 0;
|
||||||
size_t _bytes = 0;
|
size_t _bytes = 0;
|
||||||
Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 媒体源,任何rtsp/rtmp的直播流都源自该对象
|
* 媒体源,任何rtsp/rtmp的直播流都源自该对象
|
||||||
*/
|
*/
|
||||||
class MediaSource: public TrackSource, public enable_shared_from_this<MediaSource> {
|
class MediaSource: public TrackSource, public std::enable_shared_from_this<MediaSource> {
|
||||||
public:
|
public:
|
||||||
static MediaSource * const NullMediaSource;
|
static MediaSource * const NullMediaSource;
|
||||||
using Ptr = std::shared_ptr<MediaSource>;
|
using Ptr = std::shared_ptr<MediaSource>;
|
||||||
using StreamMap = unordered_map<string/*strema_id*/, weak_ptr<MediaSource> >;
|
using StreamMap = std::unordered_map<std::string/*strema_id*/, std::weak_ptr<MediaSource> >;
|
||||||
using AppStreamMap = unordered_map<string/*app*/, StreamMap>;
|
using AppStreamMap = std::unordered_map<std::string/*app*/, StreamMap>;
|
||||||
using VhostAppStreamMap = unordered_map<string/*vhost*/, AppStreamMap>;
|
using VhostAppStreamMap = std::unordered_map<std::string/*vhost*/, AppStreamMap>;
|
||||||
using SchemaVhostAppStreamMap = unordered_map<string/*schema*/, VhostAppStreamMap>;
|
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();
|
virtual ~MediaSource();
|
||||||
|
|
||||||
////////////////获取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
|
// 流id
|
||||||
const string& getId() const;
|
const std::string& getId() const;
|
||||||
|
|
||||||
//获取对象所有权
|
//获取对象所有权
|
||||||
std::shared_ptr<void> getOwnership();
|
std::shared_ptr<void> getOwnership();
|
||||||
|
|
||||||
// 获取所有Track
|
// 获取所有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; };
|
virtual uint32_t getTimeStamp(TrackType type) { return 0; };
|
||||||
@ -253,9 +250,9 @@ public:
|
|||||||
// 获取媒体源类型
|
// 获取媒体源类型
|
||||||
MediaOriginType getOriginType() const;
|
MediaOriginType getOriginType() const;
|
||||||
// 获取媒体源url或者文件路径
|
// 获取媒体源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);
|
bool seekTo(uint32_t stamp);
|
||||||
@ -268,28 +265,28 @@ public:
|
|||||||
// 该流观看人数变化
|
// 该流观看人数变化
|
||||||
void onReaderChanged(int size);
|
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);
|
bool isRecording(Recorder::type type);
|
||||||
// 开始发送ps-rtp
|
// 开始发送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
|
// 停止发送ps-rtp
|
||||||
bool stopSendRtp(const string &ssrc);
|
bool stopSendRtp(const std::string &ssrc);
|
||||||
|
|
||||||
////////////////static方法,查找或生成MediaSource////////////////
|
////////////////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类型
|
// 忽略类型,同步查找流,可能返回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
|
// 从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:
|
protected:
|
||||||
//媒体注册
|
//媒体注册
|
||||||
@ -305,16 +302,16 @@ protected:
|
|||||||
BytesSpeed _speed[TrackMax];
|
BytesSpeed _speed[TrackMax];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
atomic_flag _owned { false };
|
std::atomic_flag _owned { false };
|
||||||
time_t _create_stamp;
|
time_t _create_stamp;
|
||||||
Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
string _schema;
|
std::string _schema;
|
||||||
string _vhost;
|
std::string _vhost;
|
||||||
string _app;
|
std::string _app;
|
||||||
string _stream_id;
|
std::string _stream_id;
|
||||||
std::weak_ptr<MediaSourceEvent> _listener;
|
std::weak_ptr<MediaSourceEvent> _listener;
|
||||||
//对象个数统计
|
//对象个数统计
|
||||||
ObjectStatistic<MediaSource> _statistic;
|
toolkit::ObjectStatistic<MediaSource> _statistic;
|
||||||
};
|
};
|
||||||
|
|
||||||
///缓存刷新策略类
|
///缓存刷新策略类
|
||||||
@ -333,7 +330,7 @@ private:
|
|||||||
/// \tparam packet 包类型
|
/// \tparam packet 包类型
|
||||||
/// \tparam policy 刷新缓存策略
|
/// \tparam policy 刷新缓存策略
|
||||||
/// \tparam packet_list 包缓存类型
|
/// \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 {
|
class PacketCache {
|
||||||
public:
|
public:
|
||||||
PacketCache(){
|
PacketCache(){
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "MultiMediaSourceMuxer.h"
|
#include "MultiMediaSourceMuxer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace toolkit {
|
namespace toolkit {
|
||||||
StatisticImp(mediakit::MultiMediaSourceMuxer);
|
StatisticImp(mediakit::MultiMediaSourceMuxer);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
~MultiMediaSourceMuxer() override = default;
|
~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);
|
bool enable_rtsp = true, bool enable_rtmp = true, bool enable_hls = true, bool enable_mp4 = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +87,7 @@ public:
|
|||||||
* @param custom_path 开启录制时,指定自定义路径
|
* @param custom_path 开启录制时,指定自定义路径
|
||||||
* @return 是否设置成功
|
* @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 is_udp 是否为udp
|
||||||
* @param cb 启动成功或失败回调
|
* @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发送
|
* 停止ps-rtp发送
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
bool stopSendRtp(MediaSource &sender, const string &ssrc) override;
|
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有Track
|
* 获取所有Track
|
||||||
* @param trackReady 是否筛选过滤未就绪的track
|
* @param trackReady 是否筛选过滤未就绪的track
|
||||||
* @return 所有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:
|
protected:
|
||||||
/////////////////////////////////MediaSink override/////////////////////////////////
|
/////////////////////////////////MediaSink override/////////////////////////////////
|
||||||
@ -142,13 +142,13 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool _is_enable = false;
|
bool _is_enable = false;
|
||||||
Ticker _last_check;
|
toolkit::Ticker _last_check;
|
||||||
Stamp _stamp[2];
|
Stamp _stamp[2];
|
||||||
std::weak_ptr<Listener> _track_listener;
|
std::weak_ptr<Listener> _track_listener;
|
||||||
function<string()> _get_origin_url;
|
std::function<std::string()> _get_origin_url;
|
||||||
#if defined(ENABLE_RTPPROXY)
|
#if defined(ENABLE_RTPPROXY)
|
||||||
mutex _rtp_sender_mtx;
|
std::mutex _rtp_sender_mtx;
|
||||||
unordered_map<string, RtpSender::Ptr> _rtp_sender;
|
std::unordered_map<std::string, RtpSender::Ptr> _rtp_sender;
|
||||||
#endif //ENABLE_RTPPROXY
|
#endif //ENABLE_RTPPROXY
|
||||||
|
|
||||||
#if defined(ENABLE_MP4)
|
#if defined(ENABLE_MP4)
|
||||||
@ -161,7 +161,7 @@ private:
|
|||||||
HlsRecorder::Ptr _hls;
|
HlsRecorder::Ptr _hls;
|
||||||
|
|
||||||
//对象个数统计
|
//对象个数统计
|
||||||
ObjectStatistic<MultiMediaSourceMuxer> _statistic;
|
toolkit::ObjectStatistic<MultiMediaSourceMuxer> _statistic;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
string FindField(const char* buf, const char* start, const char *end ,size_t bufSize) {
|
string FindField(const char* buf, const char* start, const char *end ,size_t bufSize) {
|
||||||
|
@ -15,26 +15,23 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
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 {
|
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;
|
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:
|
public:
|
||||||
using Super = multimap<string, string, StrCaseCompare>;
|
using Super = multimap<std::string, std::string, StrCaseCompare>;
|
||||||
StrCaseMap() = default;
|
StrCaseMap() = default;
|
||||||
~StrCaseMap() = default;
|
~StrCaseMap() = default;
|
||||||
|
|
||||||
string &operator[](const string &k) {
|
std::string &operator[](const std::string &k) {
|
||||||
auto it = find(k);
|
auto it = find(k);
|
||||||
if (it == end()) {
|
if (it == end()) {
|
||||||
it = Super::emplace(k, "");
|
it = Super::emplace(k, "");
|
||||||
@ -43,7 +40,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void emplace(const string &k, V &&v) {
|
void emplace(const std::string &k, V &&v) {
|
||||||
auto it = find(k);
|
auto it = find(k);
|
||||||
if (it != end()) {
|
if (it != end()) {
|
||||||
return;
|
return;
|
||||||
@ -52,7 +49,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
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));
|
Super::emplace(k, std::forward<V>(v));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -67,34 +64,34 @@ public:
|
|||||||
void Parse(const char *buf);
|
void Parse(const char *buf);
|
||||||
|
|
||||||
//获取命令字
|
//获取命令字
|
||||||
const string &Method() const;
|
const std::string &Method() const;
|
||||||
|
|
||||||
//获取中间url,不包含?后面的参数
|
//获取中间url,不包含?后面的参数
|
||||||
const string &Url() const;
|
const std::string &Url() const;
|
||||||
|
|
||||||
//获取中间url,包含?后面的参数
|
//获取中间url,包含?后面的参数
|
||||||
string FullUrl() const;
|
std::string FullUrl() const;
|
||||||
|
|
||||||
//获取命令协议名
|
//获取命令协议名
|
||||||
const string &Tail() const;
|
const std::string &Tail() const;
|
||||||
|
|
||||||
//根据header key名,获取请求header value值
|
//根据header key名,获取请求header value值
|
||||||
const string &operator[](const char *name) const;
|
const std::string &operator[](const char *name) const;
|
||||||
|
|
||||||
//获取http body或sdp
|
//获取http body或sdp
|
||||||
const string &Content() const;
|
const std::string &Content() const;
|
||||||
|
|
||||||
//清空,为了重用
|
//清空,为了重用
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
//获取?后面的参数
|
//获取?后面的参数
|
||||||
const string &Params() const;
|
const std::string &Params() const;
|
||||||
|
|
||||||
//重新设置url
|
//重新设置url
|
||||||
void setUrl(string url);
|
void setUrl(std::string url);
|
||||||
|
|
||||||
//重新设置content
|
//重新设置content
|
||||||
void setContent(string content);
|
void setContent(std::string content);
|
||||||
|
|
||||||
//获取header列表
|
//获取header列表
|
||||||
StrCaseMap &getHeader() const;
|
StrCaseMap &getHeader() const;
|
||||||
@ -103,15 +100,15 @@ public:
|
|||||||
StrCaseMap &getUrlArgs() const;
|
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:
|
private:
|
||||||
string _strMethod;
|
std::string _strMethod;
|
||||||
string _strUrl;
|
std::string _strUrl;
|
||||||
string _strTail;
|
std::string _strTail;
|
||||||
string _strContent;
|
std::string _strContent;
|
||||||
string _strNull;
|
std::string _strNull;
|
||||||
string _params;
|
std::string _params;
|
||||||
mutable StrCaseMap _mapHeaders;
|
mutable StrCaseMap _mapHeaders;
|
||||||
mutable StrCaseMap _mapUrlArgs;
|
mutable StrCaseMap _mapUrlArgs;
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#define MAX_CTS 500
|
#define MAX_CTS 500
|
||||||
#define ABS(x) ((x) > 0 ? (x) : (-x))
|
#define ABS(x) ((x) > 0 ? (x) : (-x))
|
||||||
|
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
int64_t DeltaStamp::deltaStamp(int64_t stamp) {
|
int64_t DeltaStamp::deltaStamp(int64_t stamp) {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "Util/TimeTicker.h"
|
#include "Util/TimeTicker.h"
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
@ -87,7 +86,7 @@ private:
|
|||||||
int64_t _last_dts_in = 0;
|
int64_t _last_dts_in = 0;
|
||||||
int64_t _last_dts_out = 0;
|
int64_t _last_dts_out = 0;
|
||||||
int64_t _last_pts_out = 0;
|
int64_t _last_pts_out = 0;
|
||||||
SmoothTicker _ticker;
|
toolkit::SmoothTicker _ticker;
|
||||||
bool _playback = false;
|
bool _playback = false;
|
||||||
Stamp *_sync_master = nullptr;
|
Stamp *_sync_master = nullptr;
|
||||||
};
|
};
|
||||||
@ -111,7 +110,7 @@ private:
|
|||||||
size_t _frames_since_last_max_pts = 0;
|
size_t _frames_since_last_max_pts = 0;
|
||||||
size_t _sorter_max_size = 0;
|
size_t _sorter_max_size = 0;
|
||||||
size_t _count_sorter_max_size = 0;
|
size_t _count_sorter_max_size = 0;
|
||||||
set<uint32_t> _pts_sorter;
|
std::set<uint32_t> _pts_sorter;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NtpStamp {
|
class NtpStamp {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "Util/onceToken.h"
|
#include "Util/onceToken.h"
|
||||||
#include "Util/NoticeCenter.h"
|
#include "Util/NoticeCenter.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
#include "Util/NoticeCenter.h"
|
#include "Util/NoticeCenter.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
//加载配置文件,如果配置文件不存在,那么会导出默认配置并生成配置文件
|
//加载配置文件,如果配置文件不存在,那么会导出默认配置并生成配置文件
|
||||||
@ -34,93 +31,93 @@ bool loadIniConfig(const char *ini_path = nullptr);
|
|||||||
namespace Broadcast {
|
namespace Broadcast {
|
||||||
|
|
||||||
//注册或反注册MediaSource事件广播
|
//注册或反注册MediaSource事件广播
|
||||||
extern const string kBroadcastMediaChanged;
|
extern const std::string kBroadcastMediaChanged;
|
||||||
#define BroadcastMediaChangedArgs const bool &bRegist, MediaSource &sender
|
#define BroadcastMediaChangedArgs const bool &bRegist, MediaSource &sender
|
||||||
|
|
||||||
//录制mp4文件成功后广播
|
//录制mp4文件成功后广播
|
||||||
extern const string kBroadcastRecordMP4;
|
extern const std::string kBroadcastRecordMP4;
|
||||||
#define BroadcastRecordMP4Args const RecordInfo &info
|
#define BroadcastRecordMP4Args const RecordInfo &info
|
||||||
|
|
||||||
// 录制 ts 文件后广播
|
// 录制 ts 文件后广播
|
||||||
extern const string kBroadcastRecordTs;
|
extern const std::string kBroadcastRecordTs;
|
||||||
#define BroadcastRecordTsArgs const RecordInfo &info
|
#define BroadcastRecordTsArgs const RecordInfo &info
|
||||||
|
|
||||||
//收到http api请求广播
|
//收到http api请求广播
|
||||||
extern const string kBroadcastHttpRequest;
|
extern const std::string kBroadcastHttpRequest;
|
||||||
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,SockInfo &sender
|
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,SockInfo &sender
|
||||||
|
|
||||||
//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
|
//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
|
||||||
extern const string kBroadcastHttpAccess;
|
extern const std::string kBroadcastHttpAccess;
|
||||||
#define BroadcastHttpAccessArgs const Parser &parser,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
|
#define BroadcastHttpAccessArgs const Parser &parser,const std::string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
|
||||||
|
|
||||||
//在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
|
//在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
|
||||||
//在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
|
//在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
|
||||||
extern const string kBroadcastHttpBeforeAccess;
|
extern const std::string kBroadcastHttpBeforeAccess;
|
||||||
#define BroadcastHttpBeforeAccessArgs const Parser &parser,string &path,SockInfo &sender
|
#define BroadcastHttpBeforeAccessArgs const Parser &parser, std::string &path, SockInfo &sender
|
||||||
|
|
||||||
//该流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证
|
//该流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证
|
||||||
extern const string kBroadcastOnGetRtspRealm;
|
extern const std::string kBroadcastOnGetRtspRealm;
|
||||||
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,SockInfo &sender
|
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,SockInfo &sender
|
||||||
|
|
||||||
//请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
|
//请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
|
||||||
//获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码
|
//获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码
|
||||||
extern const string kBroadcastOnRtspAuth;
|
extern const std::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
|
#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为空则代表鉴权成功
|
//如果errMessage为空则代表鉴权成功
|
||||||
//enableHls: 是否允许转换hls
|
//enableHls: 是否允许转换hls
|
||||||
//enableMP4: 是否运行MP4录制
|
//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推流事件广播,通过该事件控制推流鉴权
|
//收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权
|
||||||
extern const string kBroadcastMediaPublish;
|
extern const std::string kBroadcastMediaPublish;
|
||||||
#define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
|
#define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
|
||||||
|
|
||||||
//播放鉴权结果回调对象
|
//播放鉴权结果回调对象
|
||||||
//如果errMessage为空则代表鉴权成功
|
//如果errMessage为空则代表鉴权成功
|
||||||
typedef std::function<void(const string &errMessage)> AuthInvoker;
|
typedef std::function<void(const std::string &errMessage)> AuthInvoker;
|
||||||
|
|
||||||
//播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权
|
//播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权
|
||||||
extern const string kBroadcastMediaPlayed;
|
extern const std::string kBroadcastMediaPlayed;
|
||||||
#define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
#define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
||||||
|
|
||||||
//shell登录鉴权
|
//shell登录鉴权
|
||||||
extern const string kBroadcastShellLogin;
|
extern const std::string kBroadcastShellLogin;
|
||||||
#define BroadcastShellLoginArgs const string &user_name,const string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
#define BroadcastShellLoginArgs const std::string &user_name,const std::string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
||||||
|
|
||||||
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播
|
//停止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
|
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer, SockInfo &sender
|
||||||
|
|
||||||
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
||||||
extern const string kBroadcastNotFoundStream;
|
extern const std::string kBroadcastNotFoundStream;
|
||||||
#define BroadcastNotFoundStreamArgs const MediaInfo &args,SockInfo &sender, const function<void()> &closePlayer
|
#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
|
#define BroadcastStreamNoneReaderArgs MediaSource &sender
|
||||||
|
|
||||||
//更新配置文件事件广播,执行loadIniConfig函数加载配置文件成功后会触发该广播
|
//更新配置文件事件广播,执行loadIniConfig函数加载配置文件成功后会触发该广播
|
||||||
extern const string kBroadcastReloadConfig;
|
extern const std::string kBroadcastReloadConfig;
|
||||||
#define BroadcastReloadConfigArgs void
|
#define BroadcastReloadConfigArgs void
|
||||||
|
|
||||||
#define ReloadConfigTag ((void *)(0xFF))
|
#define ReloadConfigTag ((void *)(0xFF))
|
||||||
#define RELOAD_KEY(arg,key) \
|
#define RELOAD_KEY(arg,key) \
|
||||||
do { \
|
do { \
|
||||||
decltype(arg) arg##_tmp = mINI::Instance()[key]; \
|
decltype(arg) arg##_tmp = toolkit::mINI::Instance()[key]; \
|
||||||
if (arg == arg##_tmp) { \
|
if (arg == arg##_tmp) { \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
arg = arg##_tmp; \
|
arg = arg##_tmp; \
|
||||||
InfoL << "reload config:" << key << "=" << arg; \
|
InfoL << "reload config:" << key << "=" << arg; \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
//监听某个配置发送变更
|
//监听某个配置发送变更
|
||||||
#define LISTEN_RELOAD_KEY(arg, key, ...) \
|
#define LISTEN_RELOAD_KEY(arg, key, ...) \
|
||||||
do { \
|
do { \
|
||||||
static onceToken s_token_listen([](){ \
|
static toolkit::onceToken s_token_listen([](){ \
|
||||||
NoticeCenter::Instance().addListener(ReloadConfigTag, \
|
toolkit::NoticeCenter::Instance().addListener(ReloadConfigTag, \
|
||||||
Broadcast::kBroadcastReloadConfig,[](BroadcastReloadConfigArgs) { \
|
Broadcast::kBroadcastReloadConfig,[](BroadcastReloadConfigArgs) { \
|
||||||
__VA_ARGS__; \
|
__VA_ARGS__; \
|
||||||
}); \
|
}); \
|
||||||
@ -128,23 +125,23 @@ extern const string kBroadcastReloadConfig;
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define GET_CONFIG(type, arg, key) \
|
#define GET_CONFIG(type, arg, key) \
|
||||||
static type arg = mINI::Instance()[key]; \
|
static type arg = toolkit::mINI::Instance()[key]; \
|
||||||
LISTEN_RELOAD_KEY(arg, key, { \
|
LISTEN_RELOAD_KEY(arg, key, { \
|
||||||
RELOAD_KEY(arg, key); \
|
RELOAD_KEY(arg, key); \
|
||||||
});
|
});
|
||||||
|
|
||||||
#define GET_CONFIG_FUNC(type, arg, key, ...) \
|
#define GET_CONFIG_FUNC(type, arg, key, ...) \
|
||||||
static type arg; \
|
static type arg; \
|
||||||
do { \
|
do { \
|
||||||
static onceToken s_token_set([](){ \
|
static toolkit::onceToken s_token_set([](){ \
|
||||||
static auto lam = __VA_ARGS__ ; \
|
static auto lam = __VA_ARGS__ ; \
|
||||||
static auto arg##_str = mINI::Instance()[key]; \
|
static auto arg##_str = toolkit::mINI::Instance()[key]; \
|
||||||
arg = lam(arg##_str); \
|
arg = lam(arg##_str); \
|
||||||
LISTEN_RELOAD_KEY(arg, key, { \
|
LISTEN_RELOAD_KEY(arg, key, { \
|
||||||
RELOAD_KEY(arg##_str, key); \
|
RELOAD_KEY(arg##_str, key); \
|
||||||
arg = lam(arg##_str); \
|
arg = lam(arg##_str); \
|
||||||
}); \
|
}); \
|
||||||
}); \
|
}); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
} //namespace Broadcast
|
} //namespace Broadcast
|
||||||
@ -152,168 +149,168 @@ extern const string kBroadcastReloadConfig;
|
|||||||
////////////通用配置///////////
|
////////////通用配置///////////
|
||||||
namespace General{
|
namespace General{
|
||||||
//每个流媒体服务器的ID(GUID)
|
//每个流媒体服务器的ID(GUID)
|
||||||
extern const string kMediaServerId;
|
extern const std::string kMediaServerId;
|
||||||
//流量汇报事件流量阈值,单位KB,默认1MB
|
//流量汇报事件流量阈值,单位KB,默认1MB
|
||||||
extern const string kFlowThreshold;
|
extern const std::string kFlowThreshold;
|
||||||
//流无人观看并且超过若干时间后才触发kBroadcastStreamNoneReader事件
|
//流无人观看并且超过若干时间后才触发kBroadcastStreamNoneReader事件
|
||||||
//默认连续5秒无人观看然后触发kBroadcastStreamNoneReader事件
|
//默认连续5秒无人观看然后触发kBroadcastStreamNoneReader事件
|
||||||
extern const string kStreamNoneReaderDelayMS;
|
extern const std::string kStreamNoneReaderDelayMS;
|
||||||
//等待流注册超时时间,收到播放器后请求后,如果未找到相关流,服务器会等待一定时间,
|
//等待流注册超时时间,收到播放器后请求后,如果未找到相关流,服务器会等待一定时间,
|
||||||
//如果在这个时间内,相关流注册上了,那么服务器会立即响应播放器播放成功,
|
//如果在这个时间内,相关流注册上了,那么服务器会立即响应播放器播放成功,
|
||||||
//否则会最多等待kMaxStreamWaitTimeMS毫秒,然后响应播放器播放失败
|
//否则会最多等待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时会继续在前一个文件后面写)
|
//如果不删除将会接着上一次的数据继续写(录制hls/mp4时会继续在前一个文件后面写)
|
||||||
extern const string kResetWhenRePlay;
|
extern const std::string kResetWhenRePlay;
|
||||||
//是否默认推流时转换成hls,hook接口(on_publish)中可以覆盖该设置
|
//是否默认推流时转换成hls,hook接口(on_publish)中可以覆盖该设置
|
||||||
extern const string kPublishToHls ;
|
extern const std::string kPublishToHls ;
|
||||||
//是否默认推流时mp4录像,hook接口(on_publish)中可以覆盖该设置
|
//是否默认推流时mp4录像,hook接口(on_publish)中可以覆盖该设置
|
||||||
extern const string kPublishToMP4 ;
|
extern const std::string kPublishToMP4 ;
|
||||||
//合并写缓存大小(单位毫秒),合并写指服务器缓存一定的数据后才会一次性写入socket,这样能提高性能,但是会提高延时
|
//合并写缓存大小(单位毫秒),合并写指服务器缓存一定的数据后才会一次性写入socket,这样能提高性能,但是会提高延时
|
||||||
//开启后会同时关闭TCP_NODELAY并开启MSG_MORE
|
//开启后会同时关闭TCP_NODELAY并开启MSG_MORE
|
||||||
extern const string kMergeWriteMS ;
|
extern const std::string kMergeWriteMS ;
|
||||||
//全局的时间戳覆盖开关,在转协议时,对frame进行时间戳覆盖
|
//全局的时间戳覆盖开关,在转协议时,对frame进行时间戳覆盖
|
||||||
extern const string kModifyStamp;
|
extern const std::string kModifyStamp;
|
||||||
//按需转协议的开关
|
//按需转协议的开关
|
||||||
extern const string kHlsDemand;
|
extern const std::string kHlsDemand;
|
||||||
extern const string kRtspDemand;
|
extern const std::string kRtspDemand;
|
||||||
extern const string kRtmpDemand;
|
extern const std::string kRtmpDemand;
|
||||||
extern const string kTSDemand;
|
extern const std::string kTSDemand;
|
||||||
extern const string kFMP4Demand;
|
extern const std::string kFMP4Demand;
|
||||||
//转协议是否全局开启或忽略音频
|
//转协议是否全局开启或忽略音频
|
||||||
extern const string kEnableAudio;
|
extern const std::string kEnableAudio;
|
||||||
//最多等待未初始化的Track 10秒,超时之后会忽略未初始化的Track
|
//最多等待未初始化的Track 10秒,超时之后会忽略未初始化的Track
|
||||||
extern const string kWaitTrackReadyMS;
|
extern const std::string kWaitTrackReadyMS;
|
||||||
//如果直播流只有单Track,最多等待3秒,超时后未收到其他Track的数据,则认为是单Track
|
//如果直播流只有单Track,最多等待3秒,超时后未收到其他Track的数据,则认为是单Track
|
||||||
//如果协议元数据有声明特定track数,那么无此等待时间
|
//如果协议元数据有声明特定track数,那么无此等待时间
|
||||||
extern const string kWaitAddTrackMS;
|
extern const std::string kWaitAddTrackMS;
|
||||||
//如果track未就绪,我们先缓存帧数据,但是有最大个数限制(100帧时大约4秒),防止内存溢出
|
//如果track未就绪,我们先缓存帧数据,但是有最大个数限制(100帧时大约4秒),防止内存溢出
|
||||||
extern const string kUnreadyFrameCache;
|
extern const std::string kUnreadyFrameCache;
|
||||||
//推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
|
//推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
|
||||||
//置0关闭此特性(推流断开会导致立即断开播放器)
|
//置0关闭此特性(推流断开会导致立即断开播放器)
|
||||||
extern const string kContinuePushMS;
|
extern const std::string kContinuePushMS;
|
||||||
}//namespace General
|
}//namespace General
|
||||||
|
|
||||||
|
|
||||||
////////////HTTP配置///////////
|
////////////HTTP配置///////////
|
||||||
namespace Http {
|
namespace Http {
|
||||||
//http 文件发送缓存大小
|
//http 文件发送缓存大小
|
||||||
extern const string kSendBufSize;
|
extern const std::string kSendBufSize;
|
||||||
//http 最大请求字节数
|
//http 最大请求字节数
|
||||||
extern const string kMaxReqSize;
|
extern const std::string kMaxReqSize;
|
||||||
//http keep-alive秒数
|
//http keep-alive秒数
|
||||||
extern const string kKeepAliveSecond;
|
extern const std::string kKeepAliveSecond;
|
||||||
//http 字符编码
|
//http 字符编码
|
||||||
extern const string kCharSet;
|
extern const std::string kCharSet;
|
||||||
//http 服务器根目录
|
//http 服务器根目录
|
||||||
extern const string kRootPath;
|
extern const std::string kRootPath;
|
||||||
//http 服务器虚拟目录 虚拟目录名和文件路径使用","隔开,多个配置路径间用";"隔开,例如 path_d,d:/record;path_e,e:/record
|
//http 服务器虚拟目录 虚拟目录名和文件路径使用","隔开,多个配置路径间用";"隔开,例如 path_d,d:/record;path_e,e:/record
|
||||||
extern const string kVirtualPath;
|
extern const std::string kVirtualPath;
|
||||||
//http 404错误提示内容
|
//http 404错误提示内容
|
||||||
extern const string kNotFound;
|
extern const std::string kNotFound;
|
||||||
//是否显示文件夹菜单
|
//是否显示文件夹菜单
|
||||||
extern const string kDirMenu;
|
extern const std::string kDirMenu;
|
||||||
}//namespace Http
|
}//namespace Http
|
||||||
|
|
||||||
////////////SHELL配置///////////
|
////////////SHELL配置///////////
|
||||||
namespace Shell {
|
namespace Shell {
|
||||||
extern const string kMaxReqSize;
|
extern const std::string kMaxReqSize;
|
||||||
} //namespace Shell
|
} //namespace Shell
|
||||||
|
|
||||||
////////////RTSP服务器配置///////////
|
////////////RTSP服务器配置///////////
|
||||||
namespace Rtsp {
|
namespace Rtsp {
|
||||||
//是否优先base64方式认证?默认Md5方式认证
|
//是否优先base64方式认证?默认Md5方式认证
|
||||||
extern const string kAuthBasic;
|
extern const std::string kAuthBasic;
|
||||||
//握手超时时间,默认15秒
|
//握手超时时间,默认15秒
|
||||||
extern const string kHandshakeSecond;
|
extern const std::string kHandshakeSecond;
|
||||||
//维持链接超时时间,默认15秒
|
//维持链接超时时间,默认15秒
|
||||||
extern const string kKeepAliveSecond;
|
extern const std::string kKeepAliveSecond;
|
||||||
|
|
||||||
//rtsp拉流代理是否直接代理
|
//rtsp拉流代理是否直接代理
|
||||||
//直接代理后支持任意编码格式,但是会导致GOP缓存无法定位到I帧,可能会导致开播花屏
|
//直接代理后支持任意编码格式,但是会导致GOP缓存无法定位到I帧,可能会导致开播花屏
|
||||||
//并且如果是tcp方式拉流,如果rtp大于mtu会导致无法使用udp方式代理
|
//并且如果是tcp方式拉流,如果rtp大于mtu会导致无法使用udp方式代理
|
||||||
//假定您的拉流源地址不是264或265或AAC,那么你可以使用直接代理的方式来支持rtsp代理
|
//假定您的拉流源地址不是264或265或AAC,那么你可以使用直接代理的方式来支持rtsp代理
|
||||||
//默认开启rtsp直接代理,rtmp由于没有这些问题,是强制开启直接代理的
|
//默认开启rtsp直接代理,rtmp由于没有这些问题,是强制开启直接代理的
|
||||||
extern const string kDirectProxy;
|
extern const std::string kDirectProxy;
|
||||||
} //namespace Rtsp
|
} //namespace Rtsp
|
||||||
|
|
||||||
////////////RTMP服务器配置///////////
|
////////////RTMP服务器配置///////////
|
||||||
namespace Rtmp {
|
namespace Rtmp {
|
||||||
//rtmp推流时间戳覆盖开关
|
//rtmp推流时间戳覆盖开关
|
||||||
extern const string kModifyStamp;
|
extern const std::string kModifyStamp;
|
||||||
//握手超时时间,默认15秒
|
//握手超时时间,默认15秒
|
||||||
extern const string kHandshakeSecond;
|
extern const std::string kHandshakeSecond;
|
||||||
//维持链接超时时间,默认15秒
|
//维持链接超时时间,默认15秒
|
||||||
extern const string kKeepAliveSecond;
|
extern const std::string kKeepAliveSecond;
|
||||||
} //namespace RTMP
|
} //namespace RTMP
|
||||||
|
|
||||||
|
|
||||||
////////////RTP配置///////////
|
////////////RTP配置///////////
|
||||||
namespace Rtp {
|
namespace Rtp {
|
||||||
//RTP打包最大MTU,公网情况下更小
|
//RTP打包最大MTU,公网情况下更小
|
||||||
extern const string kVideoMtuSize;
|
extern const std::string kVideoMtuSize;
|
||||||
//RTP打包最大MTU,公网情况下更小
|
//RTP打包最大MTU,公网情况下更小
|
||||||
extern const string kAudioMtuSize;
|
extern const std::string kAudioMtuSize;
|
||||||
//rtp包最大长度限制, 单位KB
|
//rtp包最大长度限制, 单位KB
|
||||||
extern const string kRtpMaxSize;
|
extern const std::string kRtpMaxSize;
|
||||||
} //namespace Rtsp
|
} //namespace Rtsp
|
||||||
|
|
||||||
////////////组播配置///////////
|
////////////组播配置///////////
|
||||||
namespace MultiCast {
|
namespace MultiCast {
|
||||||
//组播分配起始地址
|
//组播分配起始地址
|
||||||
extern const string kAddrMin;
|
extern const std::string kAddrMin;
|
||||||
//组播分配截止地址
|
//组播分配截止地址
|
||||||
extern const string kAddrMax;
|
extern const std::string kAddrMax;
|
||||||
//组播TTL
|
//组播TTL
|
||||||
extern const string kUdpTTL;
|
extern const std::string kUdpTTL;
|
||||||
} //namespace MultiCast
|
} //namespace MultiCast
|
||||||
|
|
||||||
////////////录像配置///////////
|
////////////录像配置///////////
|
||||||
namespace Record {
|
namespace Record {
|
||||||
//查看录像的应用名称
|
//查看录像的应用名称
|
||||||
extern const string kAppName;
|
extern const std::string kAppName;
|
||||||
//每次流化MP4文件的时长,单位毫秒
|
//每次流化MP4文件的时长,单位毫秒
|
||||||
extern const string kSampleMS;
|
extern const std::string kSampleMS;
|
||||||
//MP4文件录制大小,默认一个小时
|
//MP4文件录制大小,默认一个小时
|
||||||
extern const string kFileSecond;
|
extern const std::string kFileSecond;
|
||||||
//录制文件路径
|
//录制文件路径
|
||||||
extern const string kFilePath;
|
extern const std::string kFilePath;
|
||||||
//mp4文件写缓存大小
|
//mp4文件写缓存大小
|
||||||
extern const string kFileBufSize;
|
extern const std::string kFileBufSize;
|
||||||
//mp4录制完成后是否进行二次关键帧索引写入头部
|
//mp4录制完成后是否进行二次关键帧索引写入头部
|
||||||
extern const string kFastStart;
|
extern const std::string kFastStart;
|
||||||
//mp4文件是否重头循环读取
|
//mp4文件是否重头循环读取
|
||||||
extern const string kFileRepeat;
|
extern const std::string kFileRepeat;
|
||||||
} //namespace Record
|
} //namespace Record
|
||||||
|
|
||||||
////////////HLS相关配置///////////
|
////////////HLS相关配置///////////
|
||||||
namespace Hls {
|
namespace Hls {
|
||||||
//HLS切片时长,单位秒
|
//HLS切片时长,单位秒
|
||||||
extern const string kSegmentDuration;
|
extern const std::string kSegmentDuration;
|
||||||
//m3u8文件中HLS切片个数,如果设置为0,则不删除切片,而是保存为点播
|
//m3u8文件中HLS切片个数,如果设置为0,则不删除切片,而是保存为点播
|
||||||
extern const string kSegmentNum;
|
extern const std::string kSegmentNum;
|
||||||
//HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
|
//HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
|
||||||
extern const string kSegmentRetain;
|
extern const std::string kSegmentRetain;
|
||||||
//HLS文件写缓存大小
|
//HLS文件写缓存大小
|
||||||
extern const string kFileBufSize;
|
extern const std::string kFileBufSize;
|
||||||
//录制文件路径
|
//录制文件路径
|
||||||
extern const string kFilePath;
|
extern const std::string kFilePath;
|
||||||
// 是否广播 ts 切片完成通知
|
// 是否广播 ts 切片完成通知
|
||||||
extern const string kBroadcastRecordTs;
|
extern const std::string kBroadcastRecordTs;
|
||||||
//hls直播文件删除延时,单位秒
|
//hls直播文件删除延时,单位秒
|
||||||
extern const string kDeleteDelaySec;
|
extern const std::string kDeleteDelaySec;
|
||||||
} //namespace Hls
|
} //namespace Hls
|
||||||
|
|
||||||
////////////Rtp代理相关配置///////////
|
////////////Rtp代理相关配置///////////
|
||||||
namespace RtpProxy {
|
namespace RtpProxy {
|
||||||
//rtp调试数据保存目录,置空则不生成
|
//rtp调试数据保存目录,置空则不生成
|
||||||
extern const string kDumpDir;
|
extern const std::string kDumpDir;
|
||||||
//rtp接收超时时间
|
//rtp接收超时时间
|
||||||
extern const string kTimeoutSec;
|
extern const std::string kTimeoutSec;
|
||||||
} //namespace RtpProxy
|
} //namespace RtpProxy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -323,26 +320,26 @@ extern const string kTimeoutSec;
|
|||||||
*/
|
*/
|
||||||
namespace Client {
|
namespace Client {
|
||||||
//指定网卡ip
|
//指定网卡ip
|
||||||
extern const string kNetAdapter;
|
extern const std::string kNetAdapter;
|
||||||
//设置rtp传输类型,可选项有0(tcp,默认)、1(udp)、2(组播)
|
//设置rtp传输类型,可选项有0(tcp,默认)、1(udp)、2(组播)
|
||||||
//设置方法:player[PlayerBase::kRtpType] = 0/1/2;
|
//设置方法:player[PlayerBase::kRtpType] = 0/1/2;
|
||||||
extern const string kRtpType;
|
extern const std::string kRtpType;
|
||||||
//rtsp认证用户名
|
//rtsp认证用户名
|
||||||
extern const string kRtspUser;
|
extern const std::string kRtspUser;
|
||||||
//rtsp认证用用户密码,可以是明文也可以是md5,md5密码生成方式 md5(username:realm:password)
|
//rtsp认证用用户密码,可以是明文也可以是md5,md5密码生成方式 md5(username:realm:password)
|
||||||
extern const string kRtspPwd;
|
extern const std::string kRtspPwd;
|
||||||
//rtsp认证用用户密码是否为md5类型
|
//rtsp认证用用户密码是否为md5类型
|
||||||
extern const string kRtspPwdIsMD5;
|
extern const std::string kRtspPwdIsMD5;
|
||||||
//握手超时时间,默认10,000 毫秒
|
//握手超时时间,默认10,000 毫秒
|
||||||
extern const string kTimeoutMS;
|
extern const std::string kTimeoutMS;
|
||||||
//rtp/rtmp包接收超时时间,默认5000秒
|
//rtp/rtmp包接收超时时间,默认5000秒
|
||||||
extern const string kMediaTimeoutMS;
|
extern const std::string kMediaTimeoutMS;
|
||||||
//rtsp/rtmp心跳时间,默认5000毫秒
|
//rtsp/rtmp心跳时间,默认5000毫秒
|
||||||
extern const string kBeatIntervalMS;
|
extern const std::string kBeatIntervalMS;
|
||||||
//是否为性能测试模式,性能测试模式开启后不会解析rtp或rtmp包
|
//是否为性能测试模式,性能测试模式开启后不会解析rtp或rtmp包
|
||||||
extern const string kBenchmarkMode;
|
extern const std::string kBenchmarkMode;
|
||||||
//播放器在触发播放成功事件时,是否等待所有track ready时再回调
|
//播放器在触发播放成功事件时,是否等待所有track ready时再回调
|
||||||
extern const string kWaitTrackReady;
|
extern const std::string kWaitTrackReady;
|
||||||
}
|
}
|
||||||
} // namespace mediakit
|
} // namespace mediakit
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
#include "mpeg4-aac.h"
|
#include "mpeg4-aac.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
#ifndef ENABLE_MP4
|
#ifndef ENABLE_MP4
|
||||||
|
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
namespace mediakit{
|
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 getAacFrameLength(const uint8_t *hex, size_t length);
|
||||||
int dumpAacConfig(const string &config, size_t length, uint8_t *out, size_t out_size);
|
int dumpAacConfig(const std::string &config, size_t length, uint8_t *out, size_t out_size);
|
||||||
bool parseAacConfig(const string &config, int &samplerate, int &channels);
|
bool parseAacConfig(const std::string &config, int &samplerate, int &channels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* aac音频通道
|
* aac音频通道
|
||||||
@ -39,12 +39,12 @@ public:
|
|||||||
* 构造aac类型的媒体
|
* 构造aac类型的媒体
|
||||||
* @param aac_cfg aac配置信息
|
* @param aac_cfg aac配置信息
|
||||||
*/
|
*/
|
||||||
AACTrack(const string &aac_cfg);
|
AACTrack(const std::string &aac_cfg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取aac 配置信息
|
* 获取aac 配置信息
|
||||||
*/
|
*/
|
||||||
const string &getAacCfg() const;
|
const std::string &getAacCfg() const;
|
||||||
|
|
||||||
bool ready() override;
|
bool ready() override;
|
||||||
CodecId getCodecId() const override;
|
CodecId getCodecId() const override;
|
||||||
@ -60,7 +60,7 @@ private:
|
|||||||
bool inputFrame_l(const Frame::Ptr &frame);
|
bool inputFrame_l(const Frame::Ptr &frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string _cfg;
|
std::string _cfg;
|
||||||
int _channel = 0;
|
int _channel = 0;
|
||||||
int _sampleRate = 0;
|
int _sampleRate = 0;
|
||||||
int _sampleBit = 16;
|
int _sampleBit = 16;
|
||||||
|
@ -11,7 +11,10 @@
|
|||||||
#include "AACRtmp.h"
|
#include "AACRtmp.h"
|
||||||
#include "Rtmp/Rtmp.h"
|
#include "Rtmp/Rtmp.h"
|
||||||
|
|
||||||
namespace mediakit{
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
|
namespace mediakit {
|
||||||
|
|
||||||
static string getAacCfg(const RtmpPacket &thiz) {
|
static string getAacCfg(const RtmpPacket &thiz) {
|
||||||
string ret;
|
string ret;
|
||||||
|
@ -40,7 +40,7 @@ private:
|
|||||||
void onGetAAC(const char *data, size_t len, uint32_t stamp);
|
void onGetAAC(const char *data, size_t len, uint32_t stamp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string _aac_cfg;
|
std::string _aac_cfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
uint8_t _audio_flv_flags;
|
uint8_t _audio_flv_flags;
|
||||||
AACTrack::Ptr _track;
|
AACTrack::Ptr _track;
|
||||||
string _aac_cfg;
|
std::string _aac_cfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -60,7 +60,7 @@ void AACRtpEncoder::makeAACRtp(const void *data, size_t len, bool mark, uint32_t
|
|||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AACRtpDecoder::AACRtpDecoder(const Track::Ptr &track) {
|
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()) {
|
if (!aacTrack || !aacTrack->ready()) {
|
||||||
WarnL << "该aac track无效!";
|
WarnL << "该aac track无效!";
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,7 +44,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t _last_dts = 0;
|
uint32_t _last_dts = 0;
|
||||||
string _aac_cfg;
|
std::string _aac_cfg;
|
||||||
FrameImp::Ptr _frame;
|
FrameImp::Ptr _frame;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "CommonRtp.h"
|
#include "CommonRtp.h"
|
||||||
|
|
||||||
|
using namespace mediakit;
|
||||||
|
|
||||||
CommonRtpDecoder::CommonRtpDecoder(CodecId codec, size_t max_frame_size ){
|
CommonRtpDecoder::CommonRtpDecoder(CodecId codec, size_t max_frame_size ){
|
||||||
_codec = codec;
|
_codec = codec;
|
||||||
_max_frame_size = max_frame_size;
|
_max_frame_size = max_frame_size;
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "L16.h"
|
#include "L16.h"
|
||||||
#include "Common/Parser.h"
|
#include "Common/Parser.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
|
Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
#include "Rtsp/RtpCodec.h"
|
#include "Rtsp/RtpCodec.h"
|
||||||
#include "Rtmp/RtmpCodec.h"
|
#include "Rtmp/RtmpCodec.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
class Factory {
|
class Factory {
|
||||||
|
@ -16,9 +16,6 @@
|
|||||||
#include "Util/RingBuffer.h"
|
#include "Util/RingBuffer.h"
|
||||||
#include "Network/Socket.h"
|
#include "Network/Socket.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
typedef enum {
|
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
|
* @param str
|
||||||
* @return
|
* @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:
|
public:
|
||||||
typedef std::shared_ptr<Frame> Ptr;
|
typedef std::shared_ptr<Frame> Ptr;
|
||||||
virtual ~Frame(){}
|
virtual ~Frame(){}
|
||||||
@ -171,7 +168,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//对象个数统计
|
//对象个数统计
|
||||||
ObjectStatistic<Frame> _statistic;
|
toolkit::ObjectStatistic<Frame> _statistic;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FrameImp : public Frame {
|
class FrameImp : public Frame {
|
||||||
@ -233,14 +230,14 @@ public:
|
|||||||
uint32_t _dts = 0;
|
uint32_t _dts = 0;
|
||||||
uint32_t _pts = 0;
|
uint32_t _pts = 0;
|
||||||
size_t _prefix_size = 0;
|
size_t _prefix_size = 0;
|
||||||
BufferLikeString _buffer;
|
toolkit::BufferLikeString _buffer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//对象个数统计
|
//对象个数统计
|
||||||
ObjectStatistic<FrameImp> _statistic;
|
toolkit::ObjectStatistic<FrameImp> _statistic;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class ResourcePool_l<FrameImp>;
|
friend class toolkit::ResourcePool_l<FrameImp>;
|
||||||
FrameImp() = default;
|
FrameImp() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -323,7 +320,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void addDelegate(const FrameWriterInterface::Ptr &delegate){
|
void addDelegate(const FrameWriterInterface::Ptr &delegate){
|
||||||
//_delegates_write可能多线程同时操作
|
//_delegates_write可能多线程同时操作
|
||||||
lock_guard<mutex> lck(_mtx);
|
std::lock_guard<std::mutex> lck(_mtx);
|
||||||
_delegates_write.emplace(delegate.get(),delegate);
|
_delegates_write.emplace(delegate.get(),delegate);
|
||||||
_need_update = true;
|
_need_update = true;
|
||||||
}
|
}
|
||||||
@ -333,7 +330,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void delDelegate(FrameWriterInterface *ptr){
|
void delDelegate(FrameWriterInterface *ptr){
|
||||||
//_delegates_write可能多线程同时操作
|
//_delegates_write可能多线程同时操作
|
||||||
lock_guard<mutex> lck(_mtx);
|
std::lock_guard<std::mutex> lck(_mtx);
|
||||||
_delegates_write.erase(ptr);
|
_delegates_write.erase(ptr);
|
||||||
_need_update = true;
|
_need_update = true;
|
||||||
}
|
}
|
||||||
@ -344,7 +341,7 @@ public:
|
|||||||
bool inputFrame(const Frame::Ptr &frame) override{
|
bool inputFrame(const Frame::Ptr &frame) override{
|
||||||
if(_need_update){
|
if(_need_update){
|
||||||
//发现代理列表发生变化了,这里同步一次
|
//发现代理列表发生变化了,这里同步一次
|
||||||
lock_guard<mutex> lck(_mtx);
|
std::lock_guard<std::mutex> lck(_mtx);
|
||||||
_delegates_read = _delegates_write;
|
_delegates_read = _delegates_write;
|
||||||
_need_update = false;
|
_need_update = false;
|
||||||
}
|
}
|
||||||
@ -366,9 +363,9 @@ public:
|
|||||||
return _delegates_write.size();
|
return _delegates_write.size();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
mutex _mtx;
|
std::mutex _mtx;
|
||||||
map<void *,FrameWriterInterface::Ptr> _delegates_read;
|
std::map<void *,FrameWriterInterface::Ptr> _delegates_read;
|
||||||
map<void *,FrameWriterInterface::Ptr> _delegates_write;
|
std::map<void *,FrameWriterInterface::Ptr> _delegates_write;
|
||||||
bool _need_update = false;
|
bool _need_update = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -463,7 +460,7 @@ public:
|
|||||||
* @param prefix 帧前缀长度
|
* @param prefix 帧前缀长度
|
||||||
* @param offset buffer有效数据偏移量
|
* @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;
|
_buf = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +473,7 @@ public:
|
|||||||
* @param offset buffer有效数据偏移量
|
* @param offset buffer有效数据偏移量
|
||||||
* @param codec 帧类型
|
* @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;
|
_buf = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +485,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Buffer::Ptr _buf;
|
toolkit::Buffer::Ptr _buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -496,7 +493,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
class FrameMerger {
|
class FrameMerger {
|
||||||
public:
|
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>;
|
using Ptr = std::shared_ptr<FrameMerger>;
|
||||||
enum {
|
enum {
|
||||||
none = 0,
|
none = 0,
|
||||||
@ -508,16 +505,16 @@ public:
|
|||||||
~FrameMerger() = default;
|
~FrameMerger() = default;
|
||||||
|
|
||||||
void clear();
|
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:
|
private:
|
||||||
bool willFlush(const Frame::Ptr &frame) const;
|
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:
|
private:
|
||||||
int _type;
|
int _type;
|
||||||
bool _have_decode_able_frame = false;
|
bool _have_decode_able_frame = false;
|
||||||
List<Frame::Ptr> _frame_cache;
|
toolkit::List<Frame::Ptr> _frame_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "G711.h"
|
#include "G711.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "SPSParser.h"
|
#include "SPSParser.h"
|
||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
|
@ -14,12 +14,12 @@
|
|||||||
#include "Frame.h"
|
#include "Frame.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
#include "Util/base64.h"
|
#include "Util/base64.h"
|
||||||
|
|
||||||
#define H264_TYPE(v) ((uint8_t)(v) & 0x1F)
|
#define H264_TYPE(v) ((uint8_t)(v) & 0x1F)
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
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);
|
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);
|
size_t prefixSize(const char *ptr, size_t len);
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ template<typename Parent>
|
|||||||
class H264FrameHelper : public Parent{
|
class H264FrameHelper : public Parent{
|
||||||
public:
|
public:
|
||||||
friend class FrameImp;
|
friend class FrameImp;
|
||||||
friend class ResourcePool_l<H264FrameHelper>;
|
friend class toolkit::ResourcePool_l<H264FrameHelper>;
|
||||||
using Ptr = std::shared_ptr<H264FrameHelper>;
|
using Ptr = std::shared_ptr<H264FrameHelper>;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -108,7 +108,7 @@ public:
|
|||||||
* @param sps_prefix_len 264头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
* @param sps_prefix_len 264头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||||
* @param pps_prefix_len 264头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
* @param pps_prefix_len 264头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||||
*/
|
*/
|
||||||
H264Track(const string &sps,const string &pps,int sps_prefix_len = 4,int pps_prefix_len = 4);
|
H264Track(const std::string &sps,const std::string &pps,int sps_prefix_len = 4,int pps_prefix_len = 4);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造h264类型的媒体
|
* 构造h264类型的媒体
|
||||||
@ -120,8 +120,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 返回不带0x00 00 00 01头的sps/pps
|
* 返回不带0x00 00 00 01头的sps/pps
|
||||||
*/
|
*/
|
||||||
const string &getSps() const;
|
const std::string &getSps() const;
|
||||||
const string &getPps() const;
|
const std::string &getPps() const;
|
||||||
|
|
||||||
bool ready() override;
|
bool ready() override;
|
||||||
CodecId getCodecId() const override;
|
CodecId getCodecId() const override;
|
||||||
@ -142,8 +142,8 @@ private:
|
|||||||
int _width = 0;
|
int _width = 0;
|
||||||
int _height = 0;
|
int _height = 0;
|
||||||
float _fps = 0;
|
float _fps = 0;
|
||||||
string _sps;
|
std::string _sps;
|
||||||
string _pps;
|
std::string _pps;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -10,7 +10,11 @@
|
|||||||
|
|
||||||
#include "Rtmp/utils.h"
|
#include "Rtmp/utils.h"
|
||||||
#include "H264Rtmp.h"
|
#include "H264Rtmp.h"
|
||||||
namespace mediakit{
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
|
namespace mediakit {
|
||||||
|
|
||||||
H264RtmpDecoder::H264RtmpDecoder() {
|
H264RtmpDecoder::H264RtmpDecoder() {
|
||||||
_h264frame = obtainFrame();
|
_h264frame = obtainFrame();
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "Extension/Track.h"
|
#include "Extension/Track.h"
|
||||||
#include "Util/ResourcePool.h"
|
#include "Util/ResourcePool.h"
|
||||||
#include "Extension/H264.h"
|
#include "Extension/H264.h"
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
/**
|
/**
|
||||||
@ -45,8 +44,8 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
H264Frame::Ptr _h264frame;
|
H264Frame::Ptr _h264frame;
|
||||||
string _sps;
|
std::string _sps;
|
||||||
string _pps;
|
std::string _pps;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "Util/ResourcePool.h"
|
#include "Util/ResourcePool.h"
|
||||||
#include "Extension/H264.h"
|
#include "Extension/H264.h"
|
||||||
#include "Common/Stamp.h"
|
#include "Common/Stamp.h"
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@
|
|||||||
#include "H265.h"
|
#include "H265.h"
|
||||||
#include "SPSParser.h"
|
#include "SPSParser.h"
|
||||||
|
|
||||||
namespace mediakit{
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
|
namespace mediakit {
|
||||||
|
|
||||||
bool getHEVCInfo(const char * vps, size_t vps_len,const char * sps,size_t sps_len,int &iVideoWidth, int &iVideoHeight, float &iVideoFps){
|
bool getHEVCInfo(const char * vps, size_t vps_len,const char * sps,size_t sps_len,int &iVideoWidth, int &iVideoHeight, float &iVideoFps){
|
||||||
T_GetBitContext tGetBitBuf;
|
T_GetBitContext tGetBitBuf;
|
||||||
|
@ -15,18 +15,18 @@
|
|||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
#include "Util/base64.h"
|
#include "Util/base64.h"
|
||||||
#include "H264.h"
|
#include "H264.h"
|
||||||
|
|
||||||
#define H265_TYPE(v) (((uint8_t)(v) >> 1) & 0x3f)
|
#define H265_TYPE(v) (((uint8_t)(v) >> 1) & 0x3f)
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
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>
|
template<typename Parent>
|
||||||
class H265FrameHelper : public Parent{
|
class H265FrameHelper : public Parent{
|
||||||
public:
|
public:
|
||||||
friend class FrameImp;
|
friend class FrameImp;
|
||||||
friend class ResourcePool_l<H265FrameHelper>;
|
friend class toolkit::ResourcePool_l<H265FrameHelper>;
|
||||||
using Ptr = std::shared_ptr<H265FrameHelper>;
|
using Ptr = std::shared_ptr<H265FrameHelper>;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -136,14 +136,14 @@ public:
|
|||||||
* @param sps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
* @param sps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||||
* @param pps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
* @param pps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||||
*/
|
*/
|
||||||
H265Track(const string &vps,const string &sps, const string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4);
|
H265Track(const std::string &vps,const std::string &sps, const std::string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回不带0x00 00 00 01头的vps/sps/pps
|
* 返回不带0x00 00 00 01头的vps/sps/pps
|
||||||
*/
|
*/
|
||||||
const string &getVps() const;
|
const std::string &getVps() const;
|
||||||
const string &getSps() const;
|
const std::string &getSps() const;
|
||||||
const string &getPps() const;
|
const std::string &getPps() const;
|
||||||
|
|
||||||
bool ready() override;
|
bool ready() override;
|
||||||
CodecId getCodecId() const override;
|
CodecId getCodecId() const override;
|
||||||
@ -164,9 +164,9 @@ private:
|
|||||||
int _width = 0;
|
int _width = 0;
|
||||||
int _height = 0;
|
int _height = 0;
|
||||||
float _fps = 0;
|
float _fps = 0;
|
||||||
string _vps;
|
std::string _vps;
|
||||||
string _sps;
|
std::string _sps;
|
||||||
string _pps;
|
std::string _pps;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
#include "mpeg4-hevc.h"
|
#include "mpeg4-hevc.h"
|
||||||
#endif//ENABLE_MP4
|
#endif//ENABLE_MP4
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
H265RtmpDecoder::H265RtmpDecoder() {
|
H265RtmpDecoder::H265RtmpDecoder() {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "Extension/Track.h"
|
#include "Extension/Track.h"
|
||||||
#include "Util/ResourcePool.h"
|
#include "Util/ResourcePool.h"
|
||||||
#include "Extension/H265.h"
|
#include "Extension/H265.h"
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
/**
|
/**
|
||||||
@ -79,9 +78,9 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool _got_config_frame = false;
|
bool _got_config_frame = false;
|
||||||
string _vps;
|
std::string _vps;
|
||||||
string _sps;
|
std::string _sps;
|
||||||
string _pps;
|
std::string _pps;
|
||||||
H265Track::Ptr _track;
|
H265Track::Ptr _track;
|
||||||
RtmpPacket::Ptr _rtmp_packet;
|
RtmpPacket::Ptr _rtmp_packet;
|
||||||
FrameMerger _merger{FrameMerger::mp4_nal_size};
|
FrameMerger _merger{FrameMerger::mp4_nal_size};
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
#include "Extension/H265.h"
|
#include "Extension/H265.h"
|
||||||
#include "Common/Stamp.h"
|
#include "Common/Stamp.h"
|
||||||
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "L16.h"
|
#include "L16.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "Opus.h"
|
#include "Opus.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "Frame.h"
|
#include "Frame.h"
|
||||||
#include "Util/RingBuffer.h"
|
#include "Util/RingBuffer.h"
|
||||||
#include "Rtsp/Rtsp.h"
|
#include "Rtsp/Rtsp.h"
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
@ -186,7 +185,7 @@ public:
|
|||||||
* 获取全部的Track
|
* 获取全部的Track
|
||||||
* @param trackReady 是否获取全部已经准备好的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
|
* 获取特定Track
|
||||||
|
@ -12,18 +12,18 @@
|
|||||||
#define ZLMEDIAKIT_FMP4MEDIASOURCE_H
|
#define ZLMEDIAKIT_FMP4MEDIASOURCE_H
|
||||||
|
|
||||||
#include "Common/MediaSource.h"
|
#include "Common/MediaSource.h"
|
||||||
using namespace toolkit;
|
|
||||||
#define FMP4_GOP_SIZE 512
|
#define FMP4_GOP_SIZE 512
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
//FMP4直播数据包
|
//FMP4直播数据包
|
||||||
class FMP4Packet : public BufferString{
|
class FMP4Packet : public toolkit::BufferString{
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<FMP4Packet>;
|
using Ptr = std::shared_ptr<FMP4Packet>;
|
||||||
|
|
||||||
template<typename ...ARGS>
|
template<typename ...ARGS>
|
||||||
FMP4Packet(ARGS && ...args) : BufferString(std::forward<ARGS>(args)...) {};
|
FMP4Packet(ARGS && ...args) : toolkit::BufferString(std::forward<ARGS>(args)...) {};
|
||||||
~FMP4Packet() override = default;
|
~FMP4Packet() override = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -31,15 +31,15 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
//FMP4直播源
|
//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:
|
public:
|
||||||
using Ptr = std::shared_ptr<FMP4MediaSource>;
|
using Ptr = std::shared_ptr<FMP4MediaSource>;
|
||||||
using RingDataType = std::shared_ptr<List<FMP4Packet::Ptr> >;
|
using RingDataType = std::shared_ptr<toolkit::List<FMP4Packet::Ptr> >;
|
||||||
using RingType = RingBuffer<RingDataType>;
|
using RingType = toolkit::RingBuffer<RingDataType>;
|
||||||
|
|
||||||
FMP4MediaSource(const string &vhost,
|
FMP4MediaSource(const std::string &vhost,
|
||||||
const string &app,
|
const std::string &app,
|
||||||
const string &stream_id,
|
const std::string &stream_id,
|
||||||
int ring_size = FMP4_GOP_SIZE) : MediaSource(FMP4_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {}
|
int ring_size = FMP4_GOP_SIZE) : MediaSource(FMP4_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {}
|
||||||
|
|
||||||
~FMP4MediaSource() override = default;
|
~FMP4MediaSource() override = default;
|
||||||
@ -54,7 +54,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 获取fmp4 init segment
|
* 获取fmp4 init segment
|
||||||
*/
|
*/
|
||||||
const string &getInitSegment() const{
|
const std::string &getInitSegment() const{
|
||||||
return _init_segment;
|
return _init_segment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ public:
|
|||||||
* 设置fmp4 init segment
|
* 设置fmp4 init segment
|
||||||
* @param str init segment
|
* @param str init segment
|
||||||
*/
|
*/
|
||||||
void setInitSegment(string str) {
|
void setInitSegment(std::string str) {
|
||||||
_init_segment = std::move(str);
|
_init_segment = std::move(str);
|
||||||
createRing();
|
createRing();
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void createRing(){
|
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) {
|
_ring = std::make_shared<RingType>(_ring_size, [weak_self](int size) {
|
||||||
auto strong_self = weak_self.lock();
|
auto strong_self = weak_self.lock();
|
||||||
if (!strong_self) {
|
if (!strong_self) {
|
||||||
@ -120,7 +120,7 @@ private:
|
|||||||
* @param packet_list 合并写缓存列队
|
* @param packet_list 合并写缓存列队
|
||||||
* @param key_pos 是否包含关键帧
|
* @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缓存
|
//如果不存在视频,那么就没有存在GOP缓存的意义,所以确保一直清空GOP缓存
|
||||||
_ring->write(std::move(packet_list), _have_video ? key_pos : true);
|
_ring->write(std::move(packet_list), _have_video ? key_pos : true);
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
bool _have_video = false;
|
bool _have_video = false;
|
||||||
int _ring_size;
|
int _ring_size;
|
||||||
string _init_segment;
|
std::string _init_segment;
|
||||||
RingType::Ptr _ring;
|
RingType::Ptr _ring;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ class FMP4MediaSourceMuxer : public MP4MuxerMemory, public MediaSourceEventInter
|
|||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<FMP4MediaSourceMuxer>;
|
using Ptr = std::shared_ptr<FMP4MediaSourceMuxer>;
|
||||||
|
|
||||||
FMP4MediaSourceMuxer(const string &vhost,
|
FMP4MediaSourceMuxer(const std::string &vhost,
|
||||||
const string &app,
|
const std::string &app,
|
||||||
const string &stream_id) {
|
const std::string &stream_id) {
|
||||||
_media_src = std::make_shared<FMP4MediaSource>(vhost, app, stream_id);
|
_media_src = std::make_shared<FMP4MediaSource>(vhost, app, stream_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
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()) {
|
if (string.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,10 @@
|
|||||||
#include "HlsParser.h"
|
#include "HlsParser.h"
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
#include "Common/Parser.h"
|
#include "Common/Parser.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
bool HlsParser::parse(const string &http_url, const string &m3u8) {
|
bool HlsParser::parse(const string &http_url, const string &m3u8) {
|
||||||
|
@ -14,12 +14,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
using namespace std;
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
//url地址
|
//url地址
|
||||||
string url;
|
std::string url;
|
||||||
//ts切片长度
|
//ts切片长度
|
||||||
float duration;
|
float duration;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class HlsParser {
|
|||||||
public:
|
public:
|
||||||
HlsParser(){}
|
HlsParser(){}
|
||||||
~HlsParser(){}
|
~HlsParser(){}
|
||||||
bool parse(const string &http_url,const string &m3u8);
|
bool parse(const std::string &http_url,const std::string &m3u8);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否存在#EXTM3U字段,是否为m3u8文件
|
* 是否存在#EXTM3U字段,是否为m3u8文件
|
||||||
@ -82,7 +82,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//解析出ts文件地址回调
|
//解析出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:
|
private:
|
||||||
bool _is_m3u8 = false;
|
bool _is_m3u8 = false;
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "HlsPlayer.h"
|
#include "HlsPlayer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller) {
|
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller) {
|
||||||
@ -27,8 +30,8 @@ void HlsPlayer::fetchIndexFile() {
|
|||||||
if (waitResponse()) {
|
if (waitResponse()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(*this)[kNetAdapter].empty()) {
|
if (!(*this)[Client::kNetAdapter].empty()) {
|
||||||
setNetAdapter((*this)[kNetAdapter]);
|
setNetAdapter((*this)[Client::kNetAdapter]);
|
||||||
}
|
}
|
||||||
setCompleteTimeout((*this)[Client::kTimeoutMS].as<int>());
|
setCompleteTimeout((*this)[Client::kTimeoutMS].as<int>());
|
||||||
setMethod("GET");
|
setMethod("GET");
|
||||||
@ -83,7 +86,7 @@ void HlsPlayer::fetchSegment() {
|
|||||||
strong_self->onPacket_l(data, len);
|
strong_self->onPacket_l(data, len);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!(*this)[kNetAdapter].empty()) {
|
if (!(*this)[Client::kNetAdapter].empty()) {
|
||||||
_http_ts_player->setNetAdapter((*this)[Client::kNetAdapter]);
|
_http_ts_player->setNetAdapter((*this)[Client::kNetAdapter]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
#include "HlsParser.h"
|
#include "HlsParser.h"
|
||||||
#include "Rtp/TSDecoder.h"
|
#include "Rtp/TSDecoder.h"
|
||||||
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class HlsDemuxer
|
class HlsDemuxer
|
||||||
@ -29,12 +27,12 @@ public:
|
|||||||
HlsDemuxer() = default;
|
HlsDemuxer() = default;
|
||||||
~HlsDemuxer() override { _timer = nullptr; }
|
~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 inputFrame(const Frame::Ptr &frame) override;
|
||||||
bool addTrack(const Track::Ptr &track) override { return _delegate.addTrack(track); }
|
bool addTrack(const Track::Ptr &track) override { return _delegate.addTrack(track); }
|
||||||
void addTrackCompleted() override { _delegate.addTrackCompleted(); }
|
void addTrackCompleted() override { _delegate.addTrackCompleted(); }
|
||||||
void resetTracks() override { ((MediaSink &)_delegate).resetTracks(); }
|
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:
|
private:
|
||||||
void onTick();
|
void onTick();
|
||||||
@ -44,22 +42,22 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int64_t _ticker_offset = 0;
|
int64_t _ticker_offset = 0;
|
||||||
Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
Stamp _stamp[2];
|
Stamp _stamp[2];
|
||||||
Timer::Ptr _timer;
|
toolkit::Timer::Ptr _timer;
|
||||||
MediaSinkDelegate _delegate;
|
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{
|
class HlsPlayer : public HttpClientImp , public PlayerBase , public HlsParser{
|
||||||
public:
|
public:
|
||||||
HlsPlayer(const EventPoller::Ptr &poller);
|
HlsPlayer(const toolkit::EventPoller::Ptr &poller);
|
||||||
~HlsPlayer() override = default;
|
~HlsPlayer() override = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始播放
|
* 开始播放
|
||||||
*/
|
*/
|
||||||
void play(const string &url) override;
|
void play(const std::string &url) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止播放
|
* 停止播放
|
||||||
@ -76,37 +74,37 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_segment> &ts_map) override;
|
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 onResponseBody(const char *buf,size_t size) override;
|
||||||
void onResponseCompleted(const SockException &e) override;
|
void onResponseCompleted(const toolkit::SockException &e) override;
|
||||||
bool onRedirectUrl(const string &url,bool temporary) override;
|
bool onRedirectUrl(const std::string &url,bool temporary) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void playDelay();
|
void playDelay();
|
||||||
float delaySecond();
|
float delaySecond();
|
||||||
void fetchSegment();
|
void fetchSegment();
|
||||||
void teardown_l(const SockException &ex);
|
void teardown_l(const toolkit::SockException &ex);
|
||||||
void fetchIndexFile();
|
void fetchIndexFile();
|
||||||
void onPacket_l(const char *data, size_t len);
|
void onPacket_l(const char *data, size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct UrlComp {
|
struct UrlComp {
|
||||||
//url忽略?后面的参数
|
//url忽略?后面的参数
|
||||||
bool operator()(const string& __x, const string& __y) const {
|
bool operator()(const std::string& __x, const std::string& __y) const {
|
||||||
return split(__x,"?")[0] < split(__y,"?")[0];
|
return toolkit::split(__x,"?")[0] < toolkit::split(__y,"?")[0];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _play_result = false;
|
bool _play_result = false;
|
||||||
int64_t _last_sequence = -1;
|
int64_t _last_sequence = -1;
|
||||||
string _m3u8;
|
std::string _m3u8;
|
||||||
string _play_url;
|
std::string _play_url;
|
||||||
Timer::Ptr _timer;
|
toolkit::Timer::Ptr _timer;
|
||||||
Timer::Ptr _timer_ts;
|
toolkit::Timer::Ptr _timer_ts;
|
||||||
list<ts_segment> _ts_list;
|
std::list<ts_segment> _ts_list;
|
||||||
list<string> _ts_url_sort;
|
std::list<std::string> _ts_url_sort;
|
||||||
set<string, UrlComp> _ts_url_cache;
|
std::set<std::string, UrlComp> _ts_url_cache;
|
||||||
HttpTSPlayer::Ptr _http_ts_player;
|
HttpTSPlayer::Ptr _http_ts_player;
|
||||||
TSSegment _segment;
|
TSSegment _segment;
|
||||||
};
|
};
|
||||||
@ -114,7 +112,7 @@ private:
|
|||||||
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {
|
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<HlsPlayerImp> Ptr;
|
typedef std::shared_ptr<HlsPlayerImp> Ptr;
|
||||||
HlsPlayerImp(const EventPoller::Ptr &poller = nullptr);
|
HlsPlayerImp(const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||||
~HlsPlayerImp() override = default;
|
~HlsPlayerImp() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -123,9 +121,9 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//// PlayerBase override////
|
//// PlayerBase override////
|
||||||
void onPlayResult(const SockException &ex) override;
|
void onPlayResult(const toolkit::SockException &ex) override;
|
||||||
vector<Track::Ptr> getTracks(bool ready = true) const override;
|
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||||
void onShutdown(const SockException &ex) override;
|
void onShutdown(const toolkit::SockException &ex) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//// TrackListener override////
|
//// TrackListener override////
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
#define ENABLE_MMAP
|
#define ENABLE_MMAP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
HttpStringBody::HttpStringBody(string str){
|
HttpStringBody::HttpStringBody(string str){
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
#include "Thread/WorkThreadPool.h"
|
#include "Thread/WorkThreadPool.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
#define MIN(a,b) ((a) < (b) ? (a) : (b) )
|
#define MIN(a,b) ((a) < (b) ? (a) : (b) )
|
||||||
#endif //MIN
|
#endif //MIN
|
||||||
@ -47,14 +44,14 @@ public:
|
|||||||
* @param size 请求大小
|
* @param size 请求大小
|
||||||
* @return 字节对象,如果读完了,那么请返回nullptr
|
* @return 字节对象,如果读完了,那么请返回nullptr
|
||||||
*/
|
*/
|
||||||
virtual Buffer::Ptr readData(size_t size) { return nullptr;};
|
virtual toolkit::Buffer::Ptr readData(size_t size) { return nullptr;};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步请求读取一定字节数,返回大小可能小于size
|
* 异步请求读取一定字节数,返回大小可能小于size
|
||||||
* @param size 请求大小
|
* @param size 请求大小
|
||||||
* @param cb 回调函数
|
* @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的方式读取文件,所以把读文件操作放在后台线程并不能提高性能
|
//由于unix和linux是通过mmap的方式读取文件,所以把读文件操作放在后台线程并不能提高性能
|
||||||
//反而会由于频繁的线程切换导致性能降低以及延时增加,所以我们默认同步获取文件内容
|
//反而会由于频繁的线程切换导致性能降低以及延时增加,所以我们默认同步获取文件内容
|
||||||
//(其实并没有读,拷贝文件数据时在内核态完成文件读)
|
//(其实并没有读,拷贝文件数据时在内核态完成文件读)
|
||||||
@ -63,20 +60,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string类型的content
|
* std::string类型的content
|
||||||
*/
|
*/
|
||||||
class HttpStringBody : public HttpBody{
|
class HttpStringBody : public HttpBody{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<HttpStringBody> Ptr;
|
typedef std::shared_ptr<HttpStringBody> Ptr;
|
||||||
HttpStringBody(string str);
|
HttpStringBody(std::string str);
|
||||||
~HttpStringBody() override = default;
|
~HttpStringBody() override = default;
|
||||||
|
|
||||||
ssize_t remainSize() override;
|
ssize_t remainSize() override;
|
||||||
Buffer::Ptr readData(size_t size) override ;
|
toolkit::Buffer::Ptr readData(size_t size) override ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t _offset = 0;
|
size_t _offset = 0;
|
||||||
mutable string _str;
|
mutable std::string _str;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,14 +82,14 @@ private:
|
|||||||
class HttpBufferBody : public HttpBody{
|
class HttpBufferBody : public HttpBody{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<HttpBufferBody> Ptr;
|
typedef std::shared_ptr<HttpBufferBody> Ptr;
|
||||||
HttpBufferBody(Buffer::Ptr buffer);
|
HttpBufferBody(toolkit::Buffer::Ptr buffer);
|
||||||
~HttpBufferBody() override = default;
|
~HttpBufferBody() override = default;
|
||||||
|
|
||||||
ssize_t remainSize() override;
|
ssize_t remainSize() override;
|
||||||
Buffer::Ptr readData(size_t size) override;
|
toolkit::Buffer::Ptr readData(size_t size) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Buffer::Ptr _buffer;
|
toolkit::Buffer::Ptr _buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,11 +107,11 @@ public:
|
|||||||
* @param use_mmap 是否使用mmap方式访问文件
|
* @param use_mmap 是否使用mmap方式访问文件
|
||||||
*/
|
*/
|
||||||
HttpFileBody(const std::shared_ptr<FILE> &fp, size_t offset, size_t max_size, bool use_mmap = true);
|
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;
|
~HttpFileBody() override = default;
|
||||||
|
|
||||||
ssize_t remainSize() override ;
|
ssize_t remainSize() override ;
|
||||||
Buffer::Ptr readData(size_t size) override;
|
toolkit::Buffer::Ptr readData(size_t size) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const std::shared_ptr<FILE> &fp,size_t offset,size_t max_size, bool use_mmap);
|
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;
|
size_t _offset = 0;
|
||||||
std::shared_ptr<FILE> _fp;
|
std::shared_ptr<FILE> _fp;
|
||||||
std::shared_ptr<char> _map_addr;
|
std::shared_ptr<char> _map_addr;
|
||||||
ResourcePool<BufferRaw> _pool;
|
toolkit::ResourcePool<toolkit::BufferRaw> _pool;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HttpArgs;
|
class HttpArgs;
|
||||||
@ -142,21 +139,21 @@ public:
|
|||||||
* @param filePath 文件路径
|
* @param filePath 文件路径
|
||||||
* @param boundary boundary字符串
|
* @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(){}
|
virtual ~HttpMultiFormBody(){}
|
||||||
ssize_t remainSize() override ;
|
ssize_t remainSize() override ;
|
||||||
Buffer::Ptr readData(size_t size) override;
|
toolkit::Buffer::Ptr readData(size_t size) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static string multiFormBodyPrefix(const HttpArgs &args,const string &boundary,const string &fileName);
|
static std::string multiFormBodyPrefix(const HttpArgs &args,const std::string &boundary,const std::string &fileName);
|
||||||
static string multiFormBodySuffix(const string &boundary);
|
static std::string multiFormBodySuffix(const std::string &boundary);
|
||||||
static string multiFormContentType(const string &boundary);
|
static std::string multiFormContentType(const std::string &boundary);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t _offset = 0;
|
size_t _offset = 0;
|
||||||
size_t _totalSize;
|
size_t _totalSize;
|
||||||
string _bodyPrefix;
|
std::string _bodyPrefix;
|
||||||
string _bodySuffix;
|
std::string _bodySuffix;
|
||||||
HttpFileBody::Ptr _fileBody;
|
HttpFileBody::Ptr _fileBody;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "HttpChunkedSplitter.h"
|
#include "HttpChunkedSplitter.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, size_t len) {
|
const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, size_t len) {
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
#include "HttpClient.h"
|
#include "HttpClient.h"
|
||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void HttpClient::sendRequest(const string &url) {
|
void HttpClient::sendRequest(const string &url) {
|
||||||
|
@ -25,18 +25,15 @@
|
|||||||
#include "strCoding.h"
|
#include "strCoding.h"
|
||||||
#include "HttpBody.h"
|
#include "HttpBody.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class HttpArgs : public map<string, variant, StrCaseCompare> {
|
class HttpArgs : public std::map<std::string, toolkit::variant, StrCaseCompare> {
|
||||||
public:
|
public:
|
||||||
HttpArgs() = default;
|
HttpArgs() = default;
|
||||||
~HttpArgs() = default;
|
~HttpArgs() = default;
|
||||||
|
|
||||||
string make() const {
|
std::string make() const {
|
||||||
string ret;
|
std::string ret;
|
||||||
for (auto &pr : *this) {
|
for (auto &pr : *this) {
|
||||||
ret.append(pr.first);
|
ret.append(pr.first);
|
||||||
ret.append("=");
|
ret.append("=");
|
||||||
@ -50,7 +47,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class HttpClient : public TcpClient, public HttpRequestSplitter {
|
class HttpClient : public toolkit::TcpClient, public HttpRequestSplitter {
|
||||||
public:
|
public:
|
||||||
using HttpHeader = StrCaseMap;
|
using HttpHeader = StrCaseMap;
|
||||||
using Ptr = std::shared_ptr<HttpClient>;
|
using Ptr = std::shared_ptr<HttpClient>;
|
||||||
@ -62,7 +59,7 @@ public:
|
|||||||
* 发送http[s]请求
|
* 发送http[s]请求
|
||||||
* @param url 请求url
|
* @param url 请求url
|
||||||
*/
|
*/
|
||||||
virtual void sendRequest(const string &url);
|
virtual void sendRequest(const std::string &url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置对象
|
* 重置对象
|
||||||
@ -73,7 +70,7 @@ public:
|
|||||||
* 设置http方法
|
* 设置http方法
|
||||||
* @param method GET/POST等
|
* @param method GET/POST等
|
||||||
*/
|
*/
|
||||||
void setMethod(string method);
|
void setMethod(std::string method);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 覆盖http头
|
* 覆盖http头
|
||||||
@ -81,13 +78,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setHeader(HttpHeader header);
|
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
|
* 设置http content
|
||||||
* @param body http content
|
* @param body http content
|
||||||
*/
|
*/
|
||||||
void setBody(string body);
|
void setBody(std::string body);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置http content
|
* 设置http content
|
||||||
@ -113,7 +110,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 获取请求url
|
* 获取请求url
|
||||||
*/
|
*/
|
||||||
const string &getUrl() const;
|
const std::string &getUrl() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否正在等待响应
|
* 判断是否正在等待响应
|
||||||
@ -150,7 +147,7 @@ protected:
|
|||||||
* @param status 状态码,譬如:200 OK
|
* @param status 状态码,譬如:200 OK
|
||||||
* @param headers http头
|
* @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数据
|
* 收到http conten数据
|
||||||
@ -162,7 +159,7 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* 接收http回复完毕,
|
* 接收http回复完毕,
|
||||||
*/
|
*/
|
||||||
virtual void onResponseCompleted(const SockException &ex) = 0;
|
virtual void onResponseCompleted(const toolkit::SockException &ex) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重定向事件
|
* 重定向事件
|
||||||
@ -170,7 +167,7 @@ protected:
|
|||||||
* @param temporary 是否为临时重定向
|
* @param temporary 是否为临时重定向
|
||||||
* @return 是否继续
|
* @return 是否继续
|
||||||
*/
|
*/
|
||||||
virtual bool onRedirectUrl(const string &url, bool temporary) { return true; };
|
virtual bool onRedirectUrl(const std::string &url, bool temporary) { return true; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//// HttpRequestSplitter override ////
|
//// HttpRequestSplitter override ////
|
||||||
@ -178,15 +175,15 @@ protected:
|
|||||||
void onRecvContent(const char *data, size_t len) override;
|
void onRecvContent(const char *data, size_t len) override;
|
||||||
|
|
||||||
//// TcpClient override ////
|
//// TcpClient override ////
|
||||||
void onConnect(const SockException &ex) override;
|
void onConnect(const toolkit::SockException &ex) override;
|
||||||
void onRecv(const Buffer::Ptr &pBuf) override;
|
void onRecv(const toolkit::Buffer::Ptr &pBuf) override;
|
||||||
void onErr(const SockException &ex) override;
|
void onErr(const toolkit::SockException &ex) override;
|
||||||
void onFlush() override;
|
void onFlush() override;
|
||||||
void onManager() override;
|
void onManager() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onResponseCompleted_l(const SockException &ex);
|
void onResponseCompleted_l(const toolkit::SockException &ex);
|
||||||
void onConnect_l(const SockException &ex);
|
void onConnect_l(const toolkit::SockException &ex);
|
||||||
void checkCookie(HttpHeader &headers);
|
void checkCookie(HttpHeader &headers);
|
||||||
void clearResponse();
|
void clearResponse();
|
||||||
|
|
||||||
@ -201,23 +198,23 @@ private:
|
|||||||
|
|
||||||
//for request args
|
//for request args
|
||||||
bool _is_https;
|
bool _is_https;
|
||||||
string _url;
|
std::string _url;
|
||||||
HttpHeader _user_set_header;
|
HttpHeader _user_set_header;
|
||||||
HttpBody::Ptr _body;
|
HttpBody::Ptr _body;
|
||||||
string _method;
|
std::string _method;
|
||||||
string _last_host;
|
std::string _last_host;
|
||||||
|
|
||||||
//for this request
|
//for this request
|
||||||
string _path;
|
std::string _path;
|
||||||
HttpHeader _header;
|
HttpHeader _header;
|
||||||
|
|
||||||
//for timeout
|
//for timeout
|
||||||
size_t _wait_header_ms = 10 * 1000;
|
size_t _wait_header_ms = 10 * 1000;
|
||||||
size_t _wait_body_ms = 10 * 1000;
|
size_t _wait_body_ms = 10 * 1000;
|
||||||
size_t _wait_complete_ms = 0;
|
size_t _wait_complete_ms = 0;
|
||||||
Ticker _wait_header;
|
toolkit::Ticker _wait_header;
|
||||||
Ticker _wait_body;
|
toolkit::Ticker _wait_body;
|
||||||
Ticker _wait_complete;
|
toolkit::Ticker _wait_complete;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "Http/HttpClientImp.h"
|
#include "Http/HttpClientImp.h"
|
||||||
|
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void HttpClientImp::onConnect(const SockException &ex) {
|
void HttpClientImp::onConnect(const SockException &ex) {
|
||||||
|
@ -13,17 +13,17 @@
|
|||||||
|
|
||||||
#include "HttpClient.h"
|
#include "HttpClient.h"
|
||||||
#include "Util/SSLBox.h"
|
#include "Util/SSLBox.h"
|
||||||
using namespace toolkit;
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class HttpClientImp : public TcpClientWithSSL<HttpClient> {
|
class HttpClientImp : public toolkit::TcpClientWithSSL<HttpClient> {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<HttpClientImp>;
|
using Ptr = std::shared_ptr<HttpClientImp>;
|
||||||
HttpClientImp() = default;
|
HttpClientImp() = default;
|
||||||
~HttpClientImp() override = default;
|
~HttpClientImp() override = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onConnect(const SockException &ex) override;
|
void onConnect(const toolkit::SockException &ex) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
#include "Common/Parser.h"
|
#include "Common/Parser.h"
|
||||||
#include "Util/onceToken.h"
|
#include "Util/onceToken.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
const char *getHttpStatusMessage(int status) {
|
const char *getHttpStatusMessage(int status) {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#define ZLMEDIAKIT_HTTPCONST_H
|
#define ZLMEDIAKIT_HTTPCONST_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ const char *getHttpStatusMessage(int status);
|
|||||||
* @param name 文件后缀,譬如html
|
* @param name 文件后缀,譬如html
|
||||||
* @return mime值,譬如text/html
|
* @return mime值,譬如text/html
|
||||||
*/
|
*/
|
||||||
const string &getHttpContentType(const char *name);
|
const std::string &getHttpContentType(const char *name);
|
||||||
|
|
||||||
}//mediakit
|
}//mediakit
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void HttpCookie::setPath(const string &path){
|
void HttpCookie::setPath(const string &path){
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
@ -31,19 +30,19 @@ public:
|
|||||||
HttpCookie(){}
|
HttpCookie(){}
|
||||||
~HttpCookie(){}
|
~HttpCookie(){}
|
||||||
|
|
||||||
void setPath(const string &path);
|
void setPath(const std::string &path);
|
||||||
void setHost(const string &host);
|
void setHost(const std::string &host);
|
||||||
void setExpires(const string &expires,const string &server_date);
|
void setExpires(const std::string &expires,const std::string &server_date);
|
||||||
void setKeyVal(const string &key,const string &val);
|
void setKeyVal(const std::string &key,const std::string &val);
|
||||||
operator bool ();
|
operator bool ();
|
||||||
|
|
||||||
const string &getKey() const ;
|
const std::string &getKey() const ;
|
||||||
const string &getVal() const ;
|
const std::string &getVal() const ;
|
||||||
private:
|
private:
|
||||||
string _host;
|
std::string _host;
|
||||||
string _path = "/";
|
std::string _path = "/";
|
||||||
string _key;
|
std::string _key;
|
||||||
string _val;
|
std::string _val;
|
||||||
time_t _expire = 0;
|
time_t _expire = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -56,12 +55,12 @@ public:
|
|||||||
~HttpCookieStorage(){}
|
~HttpCookieStorage(){}
|
||||||
static HttpCookieStorage &Instance();
|
static HttpCookieStorage &Instance();
|
||||||
void set(const HttpCookie::Ptr &cookie);
|
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:
|
private:
|
||||||
HttpCookieStorage(){};
|
HttpCookieStorage(){};
|
||||||
private:
|
private:
|
||||||
unordered_map<string/*host*/,map<string/*cookie path*/,map<string/*cookie_key*/,HttpCookie::Ptr> > > _all_cookie;
|
std::unordered_map<std::string/*host*/, std::map<std::string/*cookie path*/,std::map<std::string/*cookie_key*/, HttpCookie::Ptr> > > _all_cookie;
|
||||||
mutex _mtx_cookie;
|
std::mutex _mtx_cookie;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "HttpCookieManager.h"
|
#include "HttpCookieManager.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
//////////////////////////////HttpServerCookie////////////////////////////////////
|
//////////////////////////////HttpServerCookie////////////////////////////////////
|
||||||
|
@ -19,10 +19,6 @@
|
|||||||
#include "Network/Socket.h"
|
#include "Network/Socket.h"
|
||||||
#include "Common/Parser.h"
|
#include "Common/Parser.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
using namespace mediakit;
|
|
||||||
|
|
||||||
#define COOKIE_DEFAULT_LIFE (7 * 24 * 60 * 60)
|
#define COOKIE_DEFAULT_LIFE (7 * 24 * 60 * 60)
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
@ -32,7 +28,7 @@ class HttpCookieManager;
|
|||||||
/**
|
/**
|
||||||
* cookie对象,用于保存cookie的一些相关属性
|
* cookie对象,用于保存cookie的一些相关属性
|
||||||
*/
|
*/
|
||||||
class HttpServerCookie : public AnyStorage , public noncopyable{
|
class HttpServerCookie : public toolkit::AnyStorage , public toolkit::noncopyable{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<HttpServerCookie> Ptr;
|
typedef std::shared_ptr<HttpServerCookie> Ptr;
|
||||||
/**
|
/**
|
||||||
@ -45,9 +41,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HttpServerCookie(const std::shared_ptr<HttpCookieManager> &manager,
|
HttpServerCookie(const std::shared_ptr<HttpCookieManager> &manager,
|
||||||
const string &cookie_name,
|
const std::string &cookie_name,
|
||||||
const string &uid,
|
const std::string &uid,
|
||||||
const string &cookie,
|
const std::string &cookie,
|
||||||
uint64_t max_elapsed);
|
uint64_t max_elapsed);
|
||||||
~HttpServerCookie() ;
|
~HttpServerCookie() ;
|
||||||
|
|
||||||
@ -55,7 +51,7 @@ public:
|
|||||||
* 获取uid
|
* 获取uid
|
||||||
* @return uid
|
* @return uid
|
||||||
*/
|
*/
|
||||||
const string &getUid() const;
|
const std::string &getUid() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取http中Set-Cookie字段的值
|
* 获取http中Set-Cookie字段的值
|
||||||
@ -63,19 +59,19 @@ public:
|
|||||||
* @param path http访问路径
|
* @param path http访问路径
|
||||||
* @return 例如 MY_SESSION=XXXXXX;expires=Wed, Jun 12 2019 06:30:48 GMT;path=/index/files/
|
* @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随机字符串
|
* 获取cookie随机字符串
|
||||||
* @return cookie随机字符串
|
* @return cookie随机字符串
|
||||||
*/
|
*/
|
||||||
const string& getCookie() const;
|
const std::string& getCookie() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取该cookie名
|
* 获取该cookie名
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
const string& getCookieName() const;
|
const std::string& getCookieName() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新该cookie的过期时间,可以让此cookie不失效
|
* 更新该cookie的过期时间,可以让此cookie不失效
|
||||||
@ -92,16 +88,16 @@ public:
|
|||||||
* 获取区域锁
|
* 获取区域锁
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<lock_guard<recursive_mutex> > getLock();
|
std::shared_ptr<std::lock_guard<std::recursive_mutex> > getLock();
|
||||||
private:
|
private:
|
||||||
string cookieExpireTime() const ;
|
std::string cookieExpireTime() const ;
|
||||||
private:
|
private:
|
||||||
string _uid;
|
std::string _uid;
|
||||||
string _cookie_name;
|
std::string _cookie_name;
|
||||||
string _cookie_uuid;
|
std::string _cookie_uuid;
|
||||||
uint64_t _max_elapsed;
|
uint64_t _max_elapsed;
|
||||||
Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
recursive_mutex _mtx;
|
std::recursive_mutex _mtx;
|
||||||
std::weak_ptr<HttpCookieManager> _manager;
|
std::weak_ptr<HttpCookieManager> _manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,18 +113,18 @@ public:
|
|||||||
* 获取不碰撞的随机字符串
|
* 获取不碰撞的随机字符串
|
||||||
* @return 随机字符串
|
* @return 随机字符串
|
||||||
*/
|
*/
|
||||||
string obtain();
|
std::string obtain();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 释放随机字符串
|
* 释放随机字符串
|
||||||
* @param str 随机字符串
|
* @param str 随机字符串
|
||||||
*/
|
*/
|
||||||
void release(const string &str);
|
void release(const std::string &str);
|
||||||
private:
|
private:
|
||||||
string obtain_l();
|
std::string obtain_l();
|
||||||
private:
|
private:
|
||||||
//碰撞库
|
//碰撞库
|
||||||
unordered_set<string> _obtained;
|
std::unordered_set<std::string> _obtained;
|
||||||
//增长index,防止碰撞用
|
//增长index,防止碰撞用
|
||||||
int _index = 0;
|
int _index = 0;
|
||||||
};
|
};
|
||||||
@ -156,7 +152,7 @@ public:
|
|||||||
* @param max_elapsed 该cookie过期时间,单位秒
|
* @param max_elapsed 该cookie过期时间,单位秒
|
||||||
* @return 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对象
|
* 根据cookie随机字符串查找cookie对象
|
||||||
@ -164,7 +160,7 @@ public:
|
|||||||
* @param cookie cookie随机字符串
|
* @param cookie cookie随机字符串
|
||||||
* @return cookie对象,可以为nullptr
|
* @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对象
|
* 从http头中获取cookie对象
|
||||||
@ -172,7 +168,7 @@ public:
|
|||||||
* @param http_header http头
|
* @param http_header http头
|
||||||
* @return cookie对象
|
* @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
|
* 根据uid获取cookie
|
||||||
@ -180,7 +176,7 @@ public:
|
|||||||
* @param uid 用户id
|
* @param uid 用户id
|
||||||
* @return cookie对象
|
* @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,用户登出时使用
|
* 删除cookie,用户登出时使用
|
||||||
@ -197,7 +193,7 @@ private:
|
|||||||
* @param uid 用户id
|
* @param uid 用户id
|
||||||
* @param cookie cookie随机字符串
|
* @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对象时触发
|
* 析构cookie对象时触发
|
||||||
@ -205,7 +201,7 @@ private:
|
|||||||
* @param uid 用户id
|
* @param uid 用户id
|
||||||
* @param cookie cookie随机字符串
|
* @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,目的是实现某用户下最多登录若干个设备
|
* 获取某用户名下最先登录时的cookie,目的是实现某用户下最多登录若干个设备
|
||||||
@ -214,7 +210,7 @@ private:
|
|||||||
* @param max_client 最多登录的设备个数
|
* @param max_client 最多登录的设备个数
|
||||||
* @return 最早的cookie随机字符串
|
* @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
|
* 删除cookie
|
||||||
@ -222,12 +218,12 @@ private:
|
|||||||
* @param cookie cookie随机字符串
|
* @param cookie cookie随机字符串
|
||||||
* @return 成功true
|
* @return 成功true
|
||||||
*/
|
*/
|
||||||
bool delCookie(const string &cookie_name,const string &cookie);
|
bool delCookie(const std::string &cookie_name,const std::string &cookie);
|
||||||
private:
|
private:
|
||||||
unordered_map<string/*cookie_name*/,unordered_map<string/*cookie*/,HttpServerCookie::Ptr/*cookie_data*/> >_map_cookie;
|
std::unordered_map<std::string/*cookie_name*/,std::unordered_map<std::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;
|
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;
|
||||||
recursive_mutex _mtx_cookie;
|
std::recursive_mutex _mtx_cookie;
|
||||||
Timer::Ptr _timer;
|
toolkit::Timer::Ptr _timer;
|
||||||
RandStrGeneator _geneator;
|
RandStrGeneator _geneator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "Util/File.h"
|
#include "Util/File.h"
|
||||||
#include "Util/MD5.h"
|
#include "Util/MD5.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ namespace mediakit {
|
|||||||
class HttpDownloader : public HttpClientImp {
|
class HttpDownloader : public HttpClientImp {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<HttpDownloader>;
|
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() = default;
|
||||||
~HttpDownloader() override;
|
~HttpDownloader() override;
|
||||||
@ -29,9 +29,9 @@ public:
|
|||||||
* @param file_path 文件保存地址,置空则选择默认文件路径
|
* @param file_path 文件保存地址,置空则选择默认文件路径
|
||||||
* @param append 如果文件已经存在,是否断点续传方式下载
|
* @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);
|
setOnResult(cb);
|
||||||
startDownload(url, "", false);
|
startDownload(url, "", false);
|
||||||
}
|
}
|
||||||
@ -40,15 +40,15 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onResponseBody(const char *buf, size_t size) override;
|
void onResponseBody(const char *buf, size_t size) override;
|
||||||
void onResponseHeader(const string &status, const HttpHeader &headers) override;
|
void onResponseHeader(const std::string &status, const HttpHeader &headers) override;
|
||||||
void onResponseCompleted(const SockException &ex) override;
|
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void closeFile();
|
void closeFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE *_save_file = nullptr;
|
FILE *_save_file = nullptr;
|
||||||
string _file_path;
|
std::string _file_path;
|
||||||
onDownloadResult _on_result;
|
onDownloadResult _on_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
#include "Record/HlsMediaSource.h"
|
#include "Record/HlsMediaSource.h"
|
||||||
#include "Common/Parser.h"
|
#include "Common/Parser.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
// hls的播放cookie缓存时间默认60秒,
|
// hls的播放cookie缓存时间默认60秒,
|
||||||
|
@ -22,20 +22,20 @@ namespace mediakit {
|
|||||||
class HttpResponseInvokerImp{
|
class HttpResponseInvokerImp{
|
||||||
public:
|
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 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(){}
|
||||||
~HttpResponseInvokerImp(){}
|
~HttpResponseInvokerImp(){}
|
||||||
template<typename C>
|
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 HttpResponseInvokerLambda0 &lambda);
|
||||||
HttpResponseInvokerImp(const HttpResponseInvokerLambda1 &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 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();
|
operator bool();
|
||||||
private:
|
private:
|
||||||
HttpResponseInvokerLambda0 _lambad;
|
HttpResponseInvokerLambda0 _lambad;
|
||||||
@ -46,7 +46,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
class HttpFileManager {
|
class HttpFileManager {
|
||||||
public:
|
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 parser http请求
|
||||||
* @param cb 回调对象
|
* @param cb 回调对象
|
||||||
*/
|
*/
|
||||||
static void onAccessPath(TcpSession &sender, Parser &parser, const invoker &cb);
|
static void onAccessPath(toolkit::TcpSession &sender, Parser &parser, const invoker &cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取mime值
|
* 获取mime值
|
||||||
* @param name 文件后缀
|
* @param name 文件后缀
|
||||||
* @return mime值
|
* @return mime值
|
||||||
*/
|
*/
|
||||||
static const string &getContentType(const char *name);
|
static const std::string &getContentType(const char *name);
|
||||||
private:
|
private:
|
||||||
HttpFileManager() = delete;
|
HttpFileManager() = delete;
|
||||||
~HttpFileManager() = delete;
|
~HttpFileManager() = delete;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
//协议解析最大缓存1兆数据
|
//协议解析最大缓存1兆数据
|
||||||
static constexpr size_t kMaxCacheSize = 1 * 1024 * 1024;
|
static constexpr size_t kMaxCacheSize = 1 * 1024 * 1024;
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Network/Buffer.h"
|
#include "Network/Buffer.h"
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
@ -83,7 +81,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
ssize_t _content_len = 0;
|
ssize_t _content_len = 0;
|
||||||
size_t _remain_data_size = 0;
|
size_t _remain_data_size = 0;
|
||||||
BufferLikeString _remain_data;
|
toolkit::BufferLikeString _remain_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "HttpRequester.h"
|
#include "HttpRequester.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void HttpRequester::onResponseHeader(const string &status, const HttpHeader &headers) {
|
void HttpRequester::onResponseHeader(const string &status, const HttpHeader &headers) {
|
||||||
|
@ -18,22 +18,22 @@ namespace mediakit {
|
|||||||
class HttpRequester : public HttpClientImp {
|
class HttpRequester : public HttpClientImp {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<HttpRequester>;
|
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() = default;
|
||||||
~HttpRequester() override = default;
|
~HttpRequester() override = default;
|
||||||
|
|
||||||
void setOnResult(const HttpRequesterResult &onResult);
|
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;
|
void clear() override;
|
||||||
|
|
||||||
private:
|
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 onResponseBody(const char *buf, size_t size) override;
|
||||||
void onResponseCompleted(const SockException &ex) override;
|
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string _res_body;
|
std::string _res_body;
|
||||||
HttpRequesterResult _on_result;
|
HttpRequesterResult _on_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include "HttpConst.h"
|
#include "HttpConst.h"
|
||||||
#include "Util/base64.h"
|
#include "Util/base64.h"
|
||||||
#include "Util/SHA1.h"
|
#include "Util/SHA1.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
@ -22,12 +22,9 @@
|
|||||||
#include "TS/TSMediaSource.h"
|
#include "TS/TSMediaSource.h"
|
||||||
#include "FMP4/FMP4MediaSource.h"
|
#include "FMP4/FMP4MediaSource.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class HttpSession: public TcpSession,
|
class HttpSession: public toolkit::TcpSession,
|
||||||
public FlvMuxer,
|
public FlvMuxer,
|
||||||
public HttpRequestSplitter,
|
public HttpRequestSplitter,
|
||||||
public WebSocketSplitter {
|
public WebSocketSplitter {
|
||||||
@ -40,19 +37,19 @@ public:
|
|||||||
* @param accessPath 运行或禁止访问的根目录
|
* @param accessPath 运行或禁止访问的根目录
|
||||||
* @param cookieLifeSecond 鉴权cookie有效期
|
* @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;
|
~HttpSession() override;
|
||||||
|
|
||||||
void onRecv(const Buffer::Ptr &) override;
|
void onRecv(const toolkit::Buffer::Ptr &) override;
|
||||||
void onError(const SockException &err) override;
|
void onError(const toolkit::SockException &err) override;
|
||||||
void onManager() override;
|
void onManager() override;
|
||||||
static string urlDecode(const string &str);
|
static std::string urlDecode(const std::string &str);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//FlvMuxer override
|
//FlvMuxer override
|
||||||
void onWrite(const Buffer::Ptr &data, bool flush) override ;
|
void onWrite(const toolkit::Buffer::Ptr &data, bool flush) override ;
|
||||||
void onDetach() override;
|
void onDetach() override;
|
||||||
std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
||||||
|
|
||||||
@ -74,7 +71,7 @@ protected:
|
|||||||
size_t len,
|
size_t len,
|
||||||
size_t totalSize,
|
size_t totalSize,
|
||||||
size_t recvedSize){
|
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协议打包后回调
|
* 发送数据进行websocket协议打包后回调
|
||||||
* @param buffer websocket协议数据
|
* @param buffer websocket协议数据
|
||||||
*/
|
*/
|
||||||
void onWebSocketEncodeData(Buffer::Ptr buffer) override;
|
void onWebSocketEncodeData(toolkit::Buffer::Ptr buffer) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收到完整的一个webSocket数据包后回调
|
* 接收到完整的一个webSocket数据包后回调
|
||||||
@ -107,11 +104,11 @@ private:
|
|||||||
void Handle_Req_HEAD(ssize_t &content_len);
|
void Handle_Req_HEAD(ssize_t &content_len);
|
||||||
void Handle_Req_OPTIONS(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 checkLiveStreamFlv(const std::function<void()> &cb = nullptr);
|
||||||
bool checkLiveStreamTS(const function<void()> &cb = nullptr);
|
bool checkLiveStreamTS(const std::function<void()> &cb = nullptr);
|
||||||
bool checkLiveStreamFMP4(const function<void()> &fmp4_list = nullptr);
|
bool checkLiveStreamFMP4(const std::function<void()> &fmp4_list = nullptr);
|
||||||
|
|
||||||
bool checkWebSocket();
|
bool checkWebSocket();
|
||||||
bool emitHttpEvent(bool doInvoke);
|
bool emitHttpEvent(bool doInvoke);
|
||||||
@ -129,18 +126,17 @@ private:
|
|||||||
bool _live_over_websocket = false;
|
bool _live_over_websocket = false;
|
||||||
//消耗的总流量
|
//消耗的总流量
|
||||||
uint64_t _total_bytes_usage = 0;
|
uint64_t _total_bytes_usage = 0;
|
||||||
string _origin;
|
std::string _origin;
|
||||||
Parser _parser;
|
Parser _parser;
|
||||||
Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
MediaInfo _mediaInfo;
|
MediaInfo _mediaInfo;
|
||||||
TSMediaSource::RingType::RingReader::Ptr _ts_reader;
|
TSMediaSource::RingType::RingReader::Ptr _ts_reader;
|
||||||
FMP4MediaSource::RingType::RingReader::Ptr _fmp4_reader;
|
FMP4MediaSource::RingType::RingReader::Ptr _fmp4_reader;
|
||||||
//处理content数据的callback
|
//处理content数据的callback
|
||||||
function<bool (const char *data,size_t len) > _contentCallBack;
|
std::function<bool (const char *data,size_t len) > _contentCallBack;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using HttpsSession = toolkit::TcpSessionWithSSL<HttpSession>;
|
||||||
typedef TcpSessionWithSSL<HttpSession> HttpsSession;
|
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "HttpTSPlayer.h"
|
#include "HttpTSPlayer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts) {
|
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts) {
|
||||||
|
@ -15,17 +15,15 @@
|
|||||||
#include "Player/MediaPlayer.h"
|
#include "Player/MediaPlayer.h"
|
||||||
#include "Rtp/TSDecoder.h"
|
#include "Rtp/TSDecoder.h"
|
||||||
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
//http-ts播发器,未实现ts解复用
|
//http-ts播发器,未实现ts解复用
|
||||||
class HttpTSPlayer : public HttpClientImp {
|
class HttpTSPlayer : public HttpClientImp {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<HttpTSPlayer>;
|
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;
|
~HttpTSPlayer() override = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,9 +38,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
///HttpClient override///
|
///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 onResponseBody(const char *buf, size_t size) override;
|
||||||
void onResponseCompleted(const SockException &ex) override;
|
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -51,7 +49,7 @@ protected:
|
|||||||
virtual void onPacket(const char *data, size_t len);
|
virtual void onPacket(const char *data, size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void emitOnComplete(const SockException &ex);
|
void emitOnComplete(const toolkit::SockException &ex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _split_ts;
|
bool _split_ts;
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#include "TsPlayer.h"
|
#include "TsPlayer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {}
|
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {}
|
||||||
|
@ -14,18 +14,17 @@
|
|||||||
#include "HttpTSPlayer.h"
|
#include "HttpTSPlayer.h"
|
||||||
#include "Player/PlayerBase.h"
|
#include "Player/PlayerBase.h"
|
||||||
|
|
||||||
using namespace toolkit;
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class TsPlayer : public HttpTSPlayer , public PlayerBase {
|
class TsPlayer : public HttpTSPlayer , public PlayerBase {
|
||||||
public:
|
public:
|
||||||
TsPlayer(const EventPoller::Ptr &poller);
|
TsPlayer(const toolkit::EventPoller::Ptr &poller);
|
||||||
~TsPlayer() override = default;
|
~TsPlayer() override = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始播放
|
* 开始播放
|
||||||
*/
|
*/
|
||||||
void play(const string &url) override;
|
void play(const std::string &url) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止播放
|
* 停止播放
|
||||||
@ -34,7 +33,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onResponseBody(const char *buf, size_t size) override;
|
void onResponseBody(const char *buf, size_t size) override;
|
||||||
void onResponseCompleted(const SockException &ex) override;
|
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _play_result = true;
|
bool _play_result = true;
|
||||||
|
@ -14,15 +14,13 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include "TsPlayer.h"
|
#include "TsPlayer.h"
|
||||||
|
|
||||||
using namespace toolkit;
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
class TsPlayerImp : public PlayerImp<TsPlayer, PlayerBase>, private TrackListener {
|
class TsPlayerImp : public PlayerImp<TsPlayer, PlayerBase>, private TrackListener {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<TsPlayerImp>;
|
using Ptr = std::shared_ptr<TsPlayerImp>;
|
||||||
|
|
||||||
TsPlayerImp(const EventPoller::Ptr &poller = nullptr);
|
TsPlayerImp(const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||||
~TsPlayerImp() override = default;
|
~TsPlayerImp() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -31,9 +29,9 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//// PlayerBase override////
|
//// PlayerBase override////
|
||||||
void onPlayResult(const SockException &ex) override;
|
void onPlayResult(const toolkit::SockException &ex) override;
|
||||||
vector<Track::Ptr> getTracks(bool ready = true) const override;
|
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||||
void onShutdown(const SockException &ex) override;
|
void onShutdown(const toolkit::SockException &ex) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//// TrackListener override////
|
//// TrackListener override////
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user