mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-22 00:42:22 +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:
@@ -24,6 +24,7 @@
|
||||
#include "Codec/H264Encoder.h"
|
||||
#endif //ENABLE_X264
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
#include "Util/util.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "Common/MultiMediaSourceMuxer.h"
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -48,7 +46,7 @@ class DevChannel : public MultiMediaSourceMuxer{
|
||||
public:
|
||||
typedef std::shared_ptr<DevChannel> Ptr;
|
||||
//fDuration<=0为直播,否则为点播
|
||||
DevChannel(const string &vhost, const string &app, const string &stream_id,
|
||||
DevChannel(const std::string &vhost, const std::string &app, const std::string &stream_id,
|
||||
float duration = 0, bool enable_hls = true, bool enable_mp4 = false);
|
||||
|
||||
~DevChannel() override ;
|
||||
@@ -126,7 +124,7 @@ private:
|
||||
std::shared_ptr<AACEncoder> _pAacEnc;
|
||||
std::shared_ptr<VideoInfo> _video;
|
||||
std::shared_ptr<AudioInfo> _audio;
|
||||
SmoothTicker _aTicker[2];
|
||||
toolkit::SmoothTicker _aTicker[2];
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "MediaSink.h"
|
||||
#include "Extension/AAC.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
bool MediaSink::addTrack(const Track::Ptr &track_in) {
|
||||
|
||||
@@ -17,9 +17,6 @@
|
||||
#include "Extension/Frame.h"
|
||||
#include "Extension/Track.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
class TrackListener {
|
||||
@@ -106,7 +103,7 @@ public:
|
||||
* 获取所有Track
|
||||
* @param trackReady 是否获取已经准备好的Track
|
||||
*/
|
||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
std::vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
|
||||
/**
|
||||
* 返回是否所有track已经准备完成
|
||||
@@ -154,10 +151,10 @@ private:
|
||||
private:
|
||||
bool _all_track_ready = false;
|
||||
size_t _max_track_size = 2;
|
||||
unordered_map<int, pair<Track::Ptr, bool/*got frame*/> > _track_map;
|
||||
unordered_map<int, List<Frame::Ptr> > _frame_unread;
|
||||
unordered_map<int, function<void()> > _track_ready_callback;
|
||||
Ticker _ticker;
|
||||
std::unordered_map<int, std::pair<Track::Ptr, bool/*got frame*/> > _track_map;
|
||||
std::unordered_map<int, toolkit::List<Frame::Ptr> > _frame_unread;
|
||||
std::unordered_map<int, std::function<void()> > _track_ready_callback;
|
||||
toolkit::Ticker _ticker;
|
||||
MuteAudioMaker::Ptr _mute_audio_maker;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "Util/util.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Network/TcpSession.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace toolkit {
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
#include "Extension/Track.h"
|
||||
#include "Record/Recorder.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace toolkit{
|
||||
class Session;
|
||||
}// namespace toolkit
|
||||
@@ -50,7 +47,7 @@ enum class MediaOriginType : uint8_t {
|
||||
rtc_push,
|
||||
};
|
||||
|
||||
string getOriginTypeString(MediaOriginType type);
|
||||
std::string getOriginTypeString(MediaOriginType type);
|
||||
|
||||
class MediaSource;
|
||||
class MediaSourceEvent{
|
||||
@@ -62,9 +59,9 @@ public:
|
||||
// 获取媒体源类型
|
||||
virtual MediaOriginType getOriginType(MediaSource &sender) const { return MediaOriginType::unknown; }
|
||||
// 获取媒体源url或者文件路径
|
||||
virtual string getOriginUrl(MediaSource &sender) const;
|
||||
virtual std::string getOriginUrl(MediaSource &sender) const;
|
||||
// 获取媒体源客户端相关信息
|
||||
virtual std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const { return nullptr; }
|
||||
virtual std::shared_ptr<toolkit::SockInfo> getOriginSock(MediaSource &sender) const { return nullptr; }
|
||||
|
||||
// 通知拖动进度条
|
||||
virtual bool seekTo(MediaSource &sender, uint32_t stamp) { return false; }
|
||||
@@ -83,18 +80,18 @@ public:
|
||||
|
||||
////////////////////////仅供MultiMediaSourceMuxer对象继承////////////////////////
|
||||
// 开启或关闭录制
|
||||
virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) { return false; };
|
||||
virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) { return false; };
|
||||
// 获取录制状态
|
||||
virtual bool isRecording(MediaSource &sender, Recorder::type type) { return false; };
|
||||
// 获取所有track相关信息
|
||||
virtual vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const { return vector<Track::Ptr>(); };
|
||||
virtual std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const { return std::vector<Track::Ptr>(); };
|
||||
// 开始发送ps-rtp
|
||||
virtual void startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb) { cb(0, SockException(Err_other, "not implemented"));};
|
||||
virtual void startSendRtp(MediaSource &sender, const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb) { cb(0, toolkit::SockException(toolkit::Err_other, "not implemented"));};
|
||||
// 停止发送ps-rtp
|
||||
virtual bool stopSendRtp(MediaSource &sender, const string &ssrc) {return false; }
|
||||
virtual bool stopSendRtp(MediaSource &sender, const std::string &ssrc) {return false; }
|
||||
|
||||
private:
|
||||
Timer::Ptr _async_close_timer;
|
||||
toolkit::Timer::Ptr _async_close_timer;
|
||||
};
|
||||
|
||||
//该对象用于拦截感兴趣的MediaSourceEvent事件
|
||||
@@ -107,8 +104,8 @@ public:
|
||||
std::shared_ptr<MediaSourceEvent> getDelegate() const;
|
||||
|
||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||
string getOriginUrl(MediaSource &sender) const override;
|
||||
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
std::string getOriginUrl(MediaSource &sender) const override;
|
||||
std::shared_ptr<toolkit::SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
|
||||
bool seekTo(MediaSource &sender, uint32_t stamp) override;
|
||||
bool pause(MediaSource &sender, bool pause) override;
|
||||
@@ -117,11 +114,11 @@ public:
|
||||
int totalReaderCount(MediaSource &sender) override;
|
||||
void onReaderChanged(MediaSource &sender, int size) override;
|
||||
void onRegist(MediaSource &sender, bool regist) override;
|
||||
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) override;
|
||||
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) override;
|
||||
bool isRecording(MediaSource &sender, Recorder::type type) override;
|
||||
vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
|
||||
void startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb) override;
|
||||
bool stopSendRtp(MediaSource &sender, const string &ssrc) override;
|
||||
std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
|
||||
void startSendRtp(MediaSource &sender, const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb) override;
|
||||
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
|
||||
|
||||
private:
|
||||
std::weak_ptr<MediaSourceEvent> _listener;
|
||||
@@ -134,18 +131,18 @@ class MediaInfo{
|
||||
public:
|
||||
~MediaInfo() {}
|
||||
MediaInfo() {}
|
||||
MediaInfo(const string &url) { parse(url); }
|
||||
void parse(const string &url);
|
||||
MediaInfo(const std::string &url) { parse(url); }
|
||||
void parse(const std::string &url);
|
||||
|
||||
public:
|
||||
string _full_url;
|
||||
string _schema;
|
||||
string _host;
|
||||
string _port;
|
||||
string _vhost;
|
||||
string _app;
|
||||
string _streamid;
|
||||
string _param_strs;
|
||||
std::string _full_url;
|
||||
std::string _schema;
|
||||
std::string _host;
|
||||
std::string _port;
|
||||
std::string _vhost;
|
||||
std::string _app;
|
||||
std::string _streamid;
|
||||
std::string _param_strs;
|
||||
};
|
||||
|
||||
class BytesSpeed {
|
||||
@@ -191,40 +188,40 @@ private:
|
||||
private:
|
||||
int _speed = 0;
|
||||
size_t _bytes = 0;
|
||||
Ticker _ticker;
|
||||
toolkit::Ticker _ticker;
|
||||
};
|
||||
|
||||
/**
|
||||
* 媒体源,任何rtsp/rtmp的直播流都源自该对象
|
||||
*/
|
||||
class MediaSource: public TrackSource, public enable_shared_from_this<MediaSource> {
|
||||
class MediaSource: public TrackSource, public std::enable_shared_from_this<MediaSource> {
|
||||
public:
|
||||
static MediaSource * const NullMediaSource;
|
||||
using Ptr = std::shared_ptr<MediaSource>;
|
||||
using StreamMap = unordered_map<string/*strema_id*/, weak_ptr<MediaSource> >;
|
||||
using AppStreamMap = unordered_map<string/*app*/, StreamMap>;
|
||||
using VhostAppStreamMap = unordered_map<string/*vhost*/, AppStreamMap>;
|
||||
using SchemaVhostAppStreamMap = unordered_map<string/*schema*/, VhostAppStreamMap>;
|
||||
using StreamMap = std::unordered_map<std::string/*strema_id*/, std::weak_ptr<MediaSource> >;
|
||||
using AppStreamMap = std::unordered_map<std::string/*app*/, StreamMap>;
|
||||
using VhostAppStreamMap = std::unordered_map<std::string/*vhost*/, AppStreamMap>;
|
||||
using SchemaVhostAppStreamMap = std::unordered_map<std::string/*schema*/, VhostAppStreamMap>;
|
||||
|
||||
MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id) ;
|
||||
MediaSource(const std::string &schema, const std::string &vhost, const std::string &app, const std::string &stream_id) ;
|
||||
virtual ~MediaSource();
|
||||
|
||||
////////////////获取MediaSource相关信息////////////////
|
||||
|
||||
// 获取协议类型
|
||||
const string& getSchema() const;
|
||||
const std::string& getSchema() const;
|
||||
// 虚拟主机
|
||||
const string& getVhost() const;
|
||||
const std::string& getVhost() const;
|
||||
// 应用名
|
||||
const string& getApp() const;
|
||||
const std::string& getApp() const;
|
||||
// 流id
|
||||
const string& getId() const;
|
||||
const std::string& getId() const;
|
||||
|
||||
//获取对象所有权
|
||||
std::shared_ptr<void> getOwnership();
|
||||
|
||||
// 获取所有Track
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||
|
||||
// 获取流当前时间戳
|
||||
virtual uint32_t getTimeStamp(TrackType type) { return 0; };
|
||||
@@ -253,9 +250,9 @@ public:
|
||||
// 获取媒体源类型
|
||||
MediaOriginType getOriginType() const;
|
||||
// 获取媒体源url或者文件路径
|
||||
string getOriginUrl() const;
|
||||
std::string getOriginUrl() const;
|
||||
// 获取媒体源客户端相关信息
|
||||
std::shared_ptr<SockInfo> getOriginSock() const;
|
||||
std::shared_ptr<toolkit::SockInfo> getOriginSock() const;
|
||||
|
||||
// 拖动进度条
|
||||
bool seekTo(uint32_t stamp);
|
||||
@@ -268,28 +265,28 @@ public:
|
||||
// 该流观看人数变化
|
||||
void onReaderChanged(int size);
|
||||
// 开启或关闭录制
|
||||
bool setupRecord(Recorder::type type, bool start, const string &custom_path, size_t max_second);
|
||||
bool setupRecord(Recorder::type type, bool start, const std::string &custom_path, size_t max_second);
|
||||
// 获取录制状态
|
||||
bool isRecording(Recorder::type type);
|
||||
// 开始发送ps-rtp
|
||||
void startSendRtp(const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb);
|
||||
void startSendRtp(const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb);
|
||||
// 停止发送ps-rtp
|
||||
bool stopSendRtp(const string &ssrc);
|
||||
bool stopSendRtp(const std::string &ssrc);
|
||||
|
||||
////////////////static方法,查找或生成MediaSource////////////////
|
||||
|
||||
// 同步查找流
|
||||
static Ptr find(const string &schema, const string &vhost, const string &app, const string &id, bool from_mp4 = false);
|
||||
static Ptr find(const std::string &schema, const std::string &vhost, const std::string &app, const std::string &id, bool from_mp4 = false);
|
||||
|
||||
// 忽略类型,同步查找流,可能返回rtmp/rtsp/hls类型
|
||||
static Ptr find(const string &vhost, const string &app, const string &stream_id, bool from_mp4 = false);
|
||||
static Ptr find(const std::string &vhost, const std::string &app, const std::string &stream_id, bool from_mp4 = false);
|
||||
|
||||
// 异步查找流
|
||||
static void findAsync(const MediaInfo &info, const std::shared_ptr<Session> &session, const function<void(const Ptr &src)> &cb);
|
||||
static void findAsync(const MediaInfo &info, const std::shared_ptr<toolkit::Session> &session, const std::function<void(const Ptr &src)> &cb);
|
||||
// 遍历所有流
|
||||
static void for_each_media(const function<void(const Ptr &src)> &cb, const string &schema = "", const string &vhost = "", const string &app = "", const string &stream = "");
|
||||
static void for_each_media(const std::function<void(const Ptr &src)> &cb, const std::string &schema = "", const std::string &vhost = "", const std::string &app = "", const std::string &stream = "");
|
||||
// 从mp4文件生成MediaSource
|
||||
static MediaSource::Ptr createFromMP4(const string &schema, const string &vhost, const string &app, const string &stream, const string &file_path = "", bool check_app = true);
|
||||
static MediaSource::Ptr createFromMP4(const std::string &schema, const std::string &vhost, const std::string &app, const std::string &stream, const std::string &file_path = "", bool check_app = true);
|
||||
|
||||
protected:
|
||||
//媒体注册
|
||||
@@ -305,16 +302,16 @@ protected:
|
||||
BytesSpeed _speed[TrackMax];
|
||||
|
||||
private:
|
||||
atomic_flag _owned { false };
|
||||
std::atomic_flag _owned { false };
|
||||
time_t _create_stamp;
|
||||
Ticker _ticker;
|
||||
string _schema;
|
||||
string _vhost;
|
||||
string _app;
|
||||
string _stream_id;
|
||||
toolkit::Ticker _ticker;
|
||||
std::string _schema;
|
||||
std::string _vhost;
|
||||
std::string _app;
|
||||
std::string _stream_id;
|
||||
std::weak_ptr<MediaSourceEvent> _listener;
|
||||
//对象个数统计
|
||||
ObjectStatistic<MediaSource> _statistic;
|
||||
toolkit::ObjectStatistic<MediaSource> _statistic;
|
||||
};
|
||||
|
||||
///缓存刷新策略类
|
||||
@@ -333,7 +330,7 @@ private:
|
||||
/// \tparam packet 包类型
|
||||
/// \tparam policy 刷新缓存策略
|
||||
/// \tparam packet_list 包缓存类型
|
||||
template<typename packet, typename policy = FlushPolicy, typename packet_list = List<std::shared_ptr<packet> > >
|
||||
template<typename packet, typename policy = FlushPolicy, typename packet_list = toolkit::List<std::shared_ptr<packet> > >
|
||||
class PacketCache {
|
||||
public:
|
||||
PacketCache(){
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#include "Common/config.h"
|
||||
#include "MultiMediaSourceMuxer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace toolkit {
|
||||
StatisticImp(mediakit::MultiMediaSourceMuxer);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
};
|
||||
|
||||
~MultiMediaSourceMuxer() override = default;
|
||||
MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec = 0.0,
|
||||
MultiMediaSourceMuxer(const std::string &vhost, const std::string &app, const std::string &stream, float dur_sec = 0.0,
|
||||
bool enable_rtsp = true, bool enable_rtmp = true, bool enable_hls = true, bool enable_mp4 = false);
|
||||
|
||||
/**
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
* @param custom_path 开启录制时,指定自定义路径
|
||||
* @return 是否设置成功
|
||||
*/
|
||||
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) override;
|
||||
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) override;
|
||||
|
||||
/**
|
||||
* 获取录制状态
|
||||
@@ -104,20 +104,20 @@ public:
|
||||
* @param is_udp 是否为udp
|
||||
* @param cb 启动成功或失败回调
|
||||
*/
|
||||
void startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function<void(uint16_t local_port, const SockException &ex)> &cb) override;
|
||||
void startSendRtp(MediaSource &sender, const std::string &dst_url, uint16_t dst_port, const std::string &ssrc, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb) override;
|
||||
|
||||
/**
|
||||
* 停止ps-rtp发送
|
||||
* @return 是否成功
|
||||
*/
|
||||
bool stopSendRtp(MediaSource &sender, const string &ssrc) override;
|
||||
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
|
||||
|
||||
/**
|
||||
* 获取所有Track
|
||||
* @param trackReady 是否筛选过滤未就绪的track
|
||||
* @return 所有Track
|
||||
*/
|
||||
vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
|
||||
std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
|
||||
|
||||
protected:
|
||||
/////////////////////////////////MediaSink override/////////////////////////////////
|
||||
@@ -142,13 +142,13 @@ protected:
|
||||
|
||||
private:
|
||||
bool _is_enable = false;
|
||||
Ticker _last_check;
|
||||
toolkit::Ticker _last_check;
|
||||
Stamp _stamp[2];
|
||||
std::weak_ptr<Listener> _track_listener;
|
||||
function<string()> _get_origin_url;
|
||||
std::function<std::string()> _get_origin_url;
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
mutex _rtp_sender_mtx;
|
||||
unordered_map<string, RtpSender::Ptr> _rtp_sender;
|
||||
std::mutex _rtp_sender_mtx;
|
||||
std::unordered_map<std::string, RtpSender::Ptr> _rtp_sender;
|
||||
#endif //ENABLE_RTPPROXY
|
||||
|
||||
#if defined(ENABLE_MP4)
|
||||
@@ -161,7 +161,7 @@ private:
|
||||
HlsRecorder::Ptr _hls;
|
||||
|
||||
//对象个数统计
|
||||
ObjectStatistic<MultiMediaSourceMuxer> _statistic;
|
||||
toolkit::ObjectStatistic<MultiMediaSourceMuxer> _statistic;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "Parser.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
string FindField(const char* buf, const char* start, const char *end ,size_t bufSize) {
|
||||
|
||||
@@ -15,26 +15,23 @@
|
||||
#include <string>
|
||||
#include "Util/util.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
string FindField(const char *buf, const char *start, const char *end, size_t bufSize = 0);
|
||||
std::string FindField(const char *buf, const char *start, const char *end, size_t bufSize = 0);
|
||||
|
||||
struct StrCaseCompare {
|
||||
bool operator()(const string &__x, const string &__y) const {
|
||||
bool operator()(const std::string &__x, const std::string &__y) const {
|
||||
return strcasecmp(__x.data(), __y.data()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
class StrCaseMap : public multimap<string, string, StrCaseCompare> {
|
||||
class StrCaseMap : public std::multimap<std::string, std::string, StrCaseCompare> {
|
||||
public:
|
||||
using Super = multimap<string, string, StrCaseCompare>;
|
||||
using Super = multimap<std::string, std::string, StrCaseCompare>;
|
||||
StrCaseMap() = default;
|
||||
~StrCaseMap() = default;
|
||||
|
||||
string &operator[](const string &k) {
|
||||
std::string &operator[](const std::string &k) {
|
||||
auto it = find(k);
|
||||
if (it == end()) {
|
||||
it = Super::emplace(k, "");
|
||||
@@ -43,7 +40,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
void emplace(const string &k, V &&v) {
|
||||
void emplace(const std::string &k, V &&v) {
|
||||
auto it = find(k);
|
||||
if (it != end()) {
|
||||
return;
|
||||
@@ -52,7 +49,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
void emplace_force(const string k, V &&v) {
|
||||
void emplace_force(const std::string k, V &&v) {
|
||||
Super::emplace(k, std::forward<V>(v));
|
||||
}
|
||||
};
|
||||
@@ -67,34 +64,34 @@ public:
|
||||
void Parse(const char *buf);
|
||||
|
||||
//获取命令字
|
||||
const string &Method() const;
|
||||
const std::string &Method() const;
|
||||
|
||||
//获取中间url,不包含?后面的参数
|
||||
const string &Url() const;
|
||||
const std::string &Url() const;
|
||||
|
||||
//获取中间url,包含?后面的参数
|
||||
string FullUrl() const;
|
||||
std::string FullUrl() const;
|
||||
|
||||
//获取命令协议名
|
||||
const string &Tail() const;
|
||||
const std::string &Tail() const;
|
||||
|
||||
//根据header key名,获取请求header value值
|
||||
const string &operator[](const char *name) const;
|
||||
const std::string &operator[](const char *name) const;
|
||||
|
||||
//获取http body或sdp
|
||||
const string &Content() const;
|
||||
const std::string &Content() const;
|
||||
|
||||
//清空,为了重用
|
||||
void Clear();
|
||||
|
||||
//获取?后面的参数
|
||||
const string &Params() const;
|
||||
const std::string &Params() const;
|
||||
|
||||
//重新设置url
|
||||
void setUrl(string url);
|
||||
void setUrl(std::string url);
|
||||
|
||||
//重新设置content
|
||||
void setContent(string content);
|
||||
void setContent(std::string content);
|
||||
|
||||
//获取header列表
|
||||
StrCaseMap &getHeader() const;
|
||||
@@ -103,15 +100,15 @@ public:
|
||||
StrCaseMap &getUrlArgs() const;
|
||||
|
||||
//解析?后面的参数
|
||||
static StrCaseMap parseArgs(const string &str, const char *pair_delim = "&", const char *key_delim = "=");
|
||||
static StrCaseMap parseArgs(const std::string &str, const char *pair_delim = "&", const char *key_delim = "=");
|
||||
|
||||
private:
|
||||
string _strMethod;
|
||||
string _strUrl;
|
||||
string _strTail;
|
||||
string _strContent;
|
||||
string _strNull;
|
||||
string _params;
|
||||
std::string _strMethod;
|
||||
std::string _strUrl;
|
||||
std::string _strTail;
|
||||
std::string _strContent;
|
||||
std::string _strNull;
|
||||
std::string _params;
|
||||
mutable StrCaseMap _mapHeaders;
|
||||
mutable StrCaseMap _mapUrlArgs;
|
||||
};
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#define MAX_CTS 500
|
||||
#define ABS(x) ((x) > 0 ? (x) : (-x))
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
int64_t DeltaStamp::deltaStamp(int64_t stamp) {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <set>
|
||||
#include <cstdint>
|
||||
#include "Util/TimeTicker.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -87,7 +86,7 @@ private:
|
||||
int64_t _last_dts_in = 0;
|
||||
int64_t _last_dts_out = 0;
|
||||
int64_t _last_pts_out = 0;
|
||||
SmoothTicker _ticker;
|
||||
toolkit::SmoothTicker _ticker;
|
||||
bool _playback = false;
|
||||
Stamp *_sync_master = nullptr;
|
||||
};
|
||||
@@ -111,7 +110,7 @@ private:
|
||||
size_t _frames_since_last_max_pts = 0;
|
||||
size_t _sorter_max_size = 0;
|
||||
size_t _count_sorter_max_size = 0;
|
||||
set<uint32_t> _pts_sorter;
|
||||
std::set<uint32_t> _pts_sorter;
|
||||
};
|
||||
|
||||
class NtpStamp {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "Util/onceToken.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "macros.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
//加载配置文件,如果配置文件不存在,那么会导出默认配置并生成配置文件
|
||||
@@ -34,93 +31,93 @@ bool loadIniConfig(const char *ini_path = nullptr);
|
||||
namespace Broadcast {
|
||||
|
||||
//注册或反注册MediaSource事件广播
|
||||
extern const string kBroadcastMediaChanged;
|
||||
extern const std::string kBroadcastMediaChanged;
|
||||
#define BroadcastMediaChangedArgs const bool &bRegist, MediaSource &sender
|
||||
|
||||
//录制mp4文件成功后广播
|
||||
extern const string kBroadcastRecordMP4;
|
||||
extern const std::string kBroadcastRecordMP4;
|
||||
#define BroadcastRecordMP4Args const RecordInfo &info
|
||||
|
||||
// 录制 ts 文件后广播
|
||||
extern const string kBroadcastRecordTs;
|
||||
extern const std::string kBroadcastRecordTs;
|
||||
#define BroadcastRecordTsArgs const RecordInfo &info
|
||||
|
||||
//收到http api请求广播
|
||||
extern const string kBroadcastHttpRequest;
|
||||
extern const std::string kBroadcastHttpRequest;
|
||||
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,SockInfo &sender
|
||||
|
||||
//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
|
||||
extern const string kBroadcastHttpAccess;
|
||||
#define BroadcastHttpAccessArgs const Parser &parser,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
|
||||
extern const std::string kBroadcastHttpAccess;
|
||||
#define BroadcastHttpAccessArgs const Parser &parser,const std::string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
|
||||
|
||||
//在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
|
||||
//在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
|
||||
extern const string kBroadcastHttpBeforeAccess;
|
||||
#define BroadcastHttpBeforeAccessArgs const Parser &parser,string &path,SockInfo &sender
|
||||
extern const std::string kBroadcastHttpBeforeAccess;
|
||||
#define BroadcastHttpBeforeAccessArgs const Parser &parser, std::string &path, SockInfo &sender
|
||||
|
||||
//该流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证
|
||||
extern const string kBroadcastOnGetRtspRealm;
|
||||
extern const std::string kBroadcastOnGetRtspRealm;
|
||||
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,SockInfo &sender
|
||||
|
||||
//请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
|
||||
//获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码
|
||||
extern const string kBroadcastOnRtspAuth;
|
||||
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const string &realm,const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,SockInfo &sender
|
||||
extern const std::string kBroadcastOnRtspAuth;
|
||||
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const std::string &realm,const std::string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,SockInfo &sender
|
||||
|
||||
//推流鉴权结果回调对象
|
||||
//如果errMessage为空则代表鉴权成功
|
||||
//enableHls: 是否允许转换hls
|
||||
//enableMP4: 是否运行MP4录制
|
||||
typedef std::function<void(const string &errMessage, bool enableHls, bool enableMP4)> PublishAuthInvoker;
|
||||
typedef std::function<void(const std::string &errMessage, bool enableHls, bool enableMP4)> PublishAuthInvoker;
|
||||
|
||||
//收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权
|
||||
extern const string kBroadcastMediaPublish;
|
||||
extern const std::string kBroadcastMediaPublish;
|
||||
#define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
|
||||
|
||||
//播放鉴权结果回调对象
|
||||
//如果errMessage为空则代表鉴权成功
|
||||
typedef std::function<void(const string &errMessage)> AuthInvoker;
|
||||
typedef std::function<void(const std::string &errMessage)> AuthInvoker;
|
||||
|
||||
//播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权
|
||||
extern const string kBroadcastMediaPlayed;
|
||||
extern const std::string kBroadcastMediaPlayed;
|
||||
#define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
||||
|
||||
//shell登录鉴权
|
||||
extern const string kBroadcastShellLogin;
|
||||
#define BroadcastShellLoginArgs const string &user_name,const string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
||||
extern const std::string kBroadcastShellLogin;
|
||||
#define BroadcastShellLoginArgs const std::string &user_name,const std::string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
||||
|
||||
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播
|
||||
extern const string kBroadcastFlowReport;
|
||||
extern const std::string kBroadcastFlowReport;
|
||||
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer, SockInfo &sender
|
||||
|
||||
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
||||
extern const string kBroadcastNotFoundStream;
|
||||
#define BroadcastNotFoundStreamArgs const MediaInfo &args,SockInfo &sender, const function<void()> &closePlayer
|
||||
extern const std::string kBroadcastNotFoundStream;
|
||||
#define BroadcastNotFoundStreamArgs const MediaInfo &args, SockInfo &sender, const std::function<void()> &closePlayer
|
||||
|
||||
//某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑
|
||||
extern const string kBroadcastStreamNoneReader;
|
||||
extern const std::string kBroadcastStreamNoneReader;
|
||||
#define BroadcastStreamNoneReaderArgs MediaSource &sender
|
||||
|
||||
//更新配置文件事件广播,执行loadIniConfig函数加载配置文件成功后会触发该广播
|
||||
extern const string kBroadcastReloadConfig;
|
||||
extern const std::string kBroadcastReloadConfig;
|
||||
#define BroadcastReloadConfigArgs void
|
||||
|
||||
#define ReloadConfigTag ((void *)(0xFF))
|
||||
#define RELOAD_KEY(arg,key) \
|
||||
do { \
|
||||
decltype(arg) arg##_tmp = mINI::Instance()[key]; \
|
||||
if (arg == arg##_tmp) { \
|
||||
return; \
|
||||
} \
|
||||
arg = arg##_tmp; \
|
||||
InfoL << "reload config:" << key << "=" << arg; \
|
||||
#define RELOAD_KEY(arg,key) \
|
||||
do { \
|
||||
decltype(arg) arg##_tmp = toolkit::mINI::Instance()[key]; \
|
||||
if (arg == arg##_tmp) { \
|
||||
return; \
|
||||
} \
|
||||
arg = arg##_tmp; \
|
||||
InfoL << "reload config:" << key << "=" << arg; \
|
||||
} while(0)
|
||||
|
||||
//监听某个配置发送变更
|
||||
#define LISTEN_RELOAD_KEY(arg, key, ...) \
|
||||
do { \
|
||||
static onceToken s_token_listen([](){ \
|
||||
NoticeCenter::Instance().addListener(ReloadConfigTag, \
|
||||
static toolkit::onceToken s_token_listen([](){ \
|
||||
toolkit::NoticeCenter::Instance().addListener(ReloadConfigTag, \
|
||||
Broadcast::kBroadcastReloadConfig,[](BroadcastReloadConfigArgs) { \
|
||||
__VA_ARGS__; \
|
||||
}); \
|
||||
@@ -128,23 +125,23 @@ extern const string kBroadcastReloadConfig;
|
||||
} while(0)
|
||||
|
||||
#define GET_CONFIG(type, arg, key) \
|
||||
static type arg = mINI::Instance()[key]; \
|
||||
static type arg = toolkit::mINI::Instance()[key]; \
|
||||
LISTEN_RELOAD_KEY(arg, key, { \
|
||||
RELOAD_KEY(arg, key); \
|
||||
});
|
||||
|
||||
#define GET_CONFIG_FUNC(type, arg, key, ...) \
|
||||
static type arg; \
|
||||
do { \
|
||||
static onceToken s_token_set([](){ \
|
||||
static auto lam = __VA_ARGS__ ; \
|
||||
static auto arg##_str = mINI::Instance()[key]; \
|
||||
arg = lam(arg##_str); \
|
||||
LISTEN_RELOAD_KEY(arg, key, { \
|
||||
RELOAD_KEY(arg##_str, key); \
|
||||
arg = lam(arg##_str); \
|
||||
}); \
|
||||
}); \
|
||||
#define GET_CONFIG_FUNC(type, arg, key, ...) \
|
||||
static type arg; \
|
||||
do { \
|
||||
static toolkit::onceToken s_token_set([](){ \
|
||||
static auto lam = __VA_ARGS__ ; \
|
||||
static auto arg##_str = toolkit::mINI::Instance()[key]; \
|
||||
arg = lam(arg##_str); \
|
||||
LISTEN_RELOAD_KEY(arg, key, { \
|
||||
RELOAD_KEY(arg##_str, key); \
|
||||
arg = lam(arg##_str); \
|
||||
}); \
|
||||
}); \
|
||||
} while(0)
|
||||
|
||||
} //namespace Broadcast
|
||||
@@ -152,168 +149,168 @@ extern const string kBroadcastReloadConfig;
|
||||
////////////通用配置///////////
|
||||
namespace General{
|
||||
//每个流媒体服务器的ID(GUID)
|
||||
extern const string kMediaServerId;
|
||||
extern const std::string kMediaServerId;
|
||||
//流量汇报事件流量阈值,单位KB,默认1MB
|
||||
extern const string kFlowThreshold;
|
||||
extern const std::string kFlowThreshold;
|
||||
//流无人观看并且超过若干时间后才触发kBroadcastStreamNoneReader事件
|
||||
//默认连续5秒无人观看然后触发kBroadcastStreamNoneReader事件
|
||||
extern const string kStreamNoneReaderDelayMS;
|
||||
extern const std::string kStreamNoneReaderDelayMS;
|
||||
//等待流注册超时时间,收到播放器后请求后,如果未找到相关流,服务器会等待一定时间,
|
||||
//如果在这个时间内,相关流注册上了,那么服务器会立即响应播放器播放成功,
|
||||
//否则会最多等待kMaxStreamWaitTimeMS毫秒,然后响应播放器播放失败
|
||||
extern const string kMaxStreamWaitTimeMS;
|
||||
extern const std::string kMaxStreamWaitTimeMS;
|
||||
//是否启动虚拟主机
|
||||
extern const string kEnableVhost;
|
||||
extern const std::string kEnableVhost;
|
||||
//拉流代理时是否添加静音音频
|
||||
extern const string kAddMuteAudio;
|
||||
extern const std::string kAddMuteAudio;
|
||||
//拉流代理时如果断流再重连成功是否删除前一次的媒体流数据,如果删除将重新开始,
|
||||
//如果不删除将会接着上一次的数据继续写(录制hls/mp4时会继续在前一个文件后面写)
|
||||
extern const string kResetWhenRePlay;
|
||||
extern const std::string kResetWhenRePlay;
|
||||
//是否默认推流时转换成hls,hook接口(on_publish)中可以覆盖该设置
|
||||
extern const string kPublishToHls ;
|
||||
extern const std::string kPublishToHls ;
|
||||
//是否默认推流时mp4录像,hook接口(on_publish)中可以覆盖该设置
|
||||
extern const string kPublishToMP4 ;
|
||||
extern const std::string kPublishToMP4 ;
|
||||
//合并写缓存大小(单位毫秒),合并写指服务器缓存一定的数据后才会一次性写入socket,这样能提高性能,但是会提高延时
|
||||
//开启后会同时关闭TCP_NODELAY并开启MSG_MORE
|
||||
extern const string kMergeWriteMS ;
|
||||
extern const std::string kMergeWriteMS ;
|
||||
//全局的时间戳覆盖开关,在转协议时,对frame进行时间戳覆盖
|
||||
extern const string kModifyStamp;
|
||||
extern const std::string kModifyStamp;
|
||||
//按需转协议的开关
|
||||
extern const string kHlsDemand;
|
||||
extern const string kRtspDemand;
|
||||
extern const string kRtmpDemand;
|
||||
extern const string kTSDemand;
|
||||
extern const string kFMP4Demand;
|
||||
extern const std::string kHlsDemand;
|
||||
extern const std::string kRtspDemand;
|
||||
extern const std::string kRtmpDemand;
|
||||
extern const std::string kTSDemand;
|
||||
extern const std::string kFMP4Demand;
|
||||
//转协议是否全局开启或忽略音频
|
||||
extern const string kEnableAudio;
|
||||
extern const std::string kEnableAudio;
|
||||
//最多等待未初始化的Track 10秒,超时之后会忽略未初始化的Track
|
||||
extern const string kWaitTrackReadyMS;
|
||||
extern const std::string kWaitTrackReadyMS;
|
||||
//如果直播流只有单Track,最多等待3秒,超时后未收到其他Track的数据,则认为是单Track
|
||||
//如果协议元数据有声明特定track数,那么无此等待时间
|
||||
extern const string kWaitAddTrackMS;
|
||||
extern const std::string kWaitAddTrackMS;
|
||||
//如果track未就绪,我们先缓存帧数据,但是有最大个数限制(100帧时大约4秒),防止内存溢出
|
||||
extern const string kUnreadyFrameCache;
|
||||
extern const std::string kUnreadyFrameCache;
|
||||
//推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
|
||||
//置0关闭此特性(推流断开会导致立即断开播放器)
|
||||
extern const string kContinuePushMS;
|
||||
extern const std::string kContinuePushMS;
|
||||
}//namespace General
|
||||
|
||||
|
||||
////////////HTTP配置///////////
|
||||
namespace Http {
|
||||
//http 文件发送缓存大小
|
||||
extern const string kSendBufSize;
|
||||
extern const std::string kSendBufSize;
|
||||
//http 最大请求字节数
|
||||
extern const string kMaxReqSize;
|
||||
extern const std::string kMaxReqSize;
|
||||
//http keep-alive秒数
|
||||
extern const string kKeepAliveSecond;
|
||||
extern const std::string kKeepAliveSecond;
|
||||
//http 字符编码
|
||||
extern const string kCharSet;
|
||||
extern const std::string kCharSet;
|
||||
//http 服务器根目录
|
||||
extern const string kRootPath;
|
||||
extern const std::string kRootPath;
|
||||
//http 服务器虚拟目录 虚拟目录名和文件路径使用","隔开,多个配置路径间用";"隔开,例如 path_d,d:/record;path_e,e:/record
|
||||
extern const string kVirtualPath;
|
||||
extern const std::string kVirtualPath;
|
||||
//http 404错误提示内容
|
||||
extern const string kNotFound;
|
||||
extern const std::string kNotFound;
|
||||
//是否显示文件夹菜单
|
||||
extern const string kDirMenu;
|
||||
extern const std::string kDirMenu;
|
||||
}//namespace Http
|
||||
|
||||
////////////SHELL配置///////////
|
||||
namespace Shell {
|
||||
extern const string kMaxReqSize;
|
||||
extern const std::string kMaxReqSize;
|
||||
} //namespace Shell
|
||||
|
||||
////////////RTSP服务器配置///////////
|
||||
namespace Rtsp {
|
||||
//是否优先base64方式认证?默认Md5方式认证
|
||||
extern const string kAuthBasic;
|
||||
extern const std::string kAuthBasic;
|
||||
//握手超时时间,默认15秒
|
||||
extern const string kHandshakeSecond;
|
||||
extern const std::string kHandshakeSecond;
|
||||
//维持链接超时时间,默认15秒
|
||||
extern const string kKeepAliveSecond;
|
||||
extern const std::string kKeepAliveSecond;
|
||||
|
||||
//rtsp拉流代理是否直接代理
|
||||
//直接代理后支持任意编码格式,但是会导致GOP缓存无法定位到I帧,可能会导致开播花屏
|
||||
//并且如果是tcp方式拉流,如果rtp大于mtu会导致无法使用udp方式代理
|
||||
//假定您的拉流源地址不是264或265或AAC,那么你可以使用直接代理的方式来支持rtsp代理
|
||||
//默认开启rtsp直接代理,rtmp由于没有这些问题,是强制开启直接代理的
|
||||
extern const string kDirectProxy;
|
||||
extern const std::string kDirectProxy;
|
||||
} //namespace Rtsp
|
||||
|
||||
////////////RTMP服务器配置///////////
|
||||
namespace Rtmp {
|
||||
//rtmp推流时间戳覆盖开关
|
||||
extern const string kModifyStamp;
|
||||
extern const std::string kModifyStamp;
|
||||
//握手超时时间,默认15秒
|
||||
extern const string kHandshakeSecond;
|
||||
extern const std::string kHandshakeSecond;
|
||||
//维持链接超时时间,默认15秒
|
||||
extern const string kKeepAliveSecond;
|
||||
extern const std::string kKeepAliveSecond;
|
||||
} //namespace RTMP
|
||||
|
||||
|
||||
////////////RTP配置///////////
|
||||
namespace Rtp {
|
||||
//RTP打包最大MTU,公网情况下更小
|
||||
extern const string kVideoMtuSize;
|
||||
extern const std::string kVideoMtuSize;
|
||||
//RTP打包最大MTU,公网情况下更小
|
||||
extern const string kAudioMtuSize;
|
||||
extern const std::string kAudioMtuSize;
|
||||
//rtp包最大长度限制, 单位KB
|
||||
extern const string kRtpMaxSize;
|
||||
extern const std::string kRtpMaxSize;
|
||||
} //namespace Rtsp
|
||||
|
||||
////////////组播配置///////////
|
||||
namespace MultiCast {
|
||||
//组播分配起始地址
|
||||
extern const string kAddrMin;
|
||||
extern const std::string kAddrMin;
|
||||
//组播分配截止地址
|
||||
extern const string kAddrMax;
|
||||
extern const std::string kAddrMax;
|
||||
//组播TTL
|
||||
extern const string kUdpTTL;
|
||||
extern const std::string kUdpTTL;
|
||||
} //namespace MultiCast
|
||||
|
||||
////////////录像配置///////////
|
||||
namespace Record {
|
||||
//查看录像的应用名称
|
||||
extern const string kAppName;
|
||||
extern const std::string kAppName;
|
||||
//每次流化MP4文件的时长,单位毫秒
|
||||
extern const string kSampleMS;
|
||||
extern const std::string kSampleMS;
|
||||
//MP4文件录制大小,默认一个小时
|
||||
extern const string kFileSecond;
|
||||
extern const std::string kFileSecond;
|
||||
//录制文件路径
|
||||
extern const string kFilePath;
|
||||
extern const std::string kFilePath;
|
||||
//mp4文件写缓存大小
|
||||
extern const string kFileBufSize;
|
||||
extern const std::string kFileBufSize;
|
||||
//mp4录制完成后是否进行二次关键帧索引写入头部
|
||||
extern const string kFastStart;
|
||||
extern const std::string kFastStart;
|
||||
//mp4文件是否重头循环读取
|
||||
extern const string kFileRepeat;
|
||||
extern const std::string kFileRepeat;
|
||||
} //namespace Record
|
||||
|
||||
////////////HLS相关配置///////////
|
||||
namespace Hls {
|
||||
//HLS切片时长,单位秒
|
||||
extern const string kSegmentDuration;
|
||||
extern const std::string kSegmentDuration;
|
||||
//m3u8文件中HLS切片个数,如果设置为0,则不删除切片,而是保存为点播
|
||||
extern const string kSegmentNum;
|
||||
extern const std::string kSegmentNum;
|
||||
//HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
|
||||
extern const string kSegmentRetain;
|
||||
extern const std::string kSegmentRetain;
|
||||
//HLS文件写缓存大小
|
||||
extern const string kFileBufSize;
|
||||
extern const std::string kFileBufSize;
|
||||
//录制文件路径
|
||||
extern const string kFilePath;
|
||||
extern const std::string kFilePath;
|
||||
// 是否广播 ts 切片完成通知
|
||||
extern const string kBroadcastRecordTs;
|
||||
extern const std::string kBroadcastRecordTs;
|
||||
//hls直播文件删除延时,单位秒
|
||||
extern const string kDeleteDelaySec;
|
||||
extern const std::string kDeleteDelaySec;
|
||||
} //namespace Hls
|
||||
|
||||
////////////Rtp代理相关配置///////////
|
||||
namespace RtpProxy {
|
||||
//rtp调试数据保存目录,置空则不生成
|
||||
extern const string kDumpDir;
|
||||
extern const std::string kDumpDir;
|
||||
//rtp接收超时时间
|
||||
extern const string kTimeoutSec;
|
||||
extern const std::string kTimeoutSec;
|
||||
} //namespace RtpProxy
|
||||
|
||||
/**
|
||||
@@ -323,26 +320,26 @@ extern const string kTimeoutSec;
|
||||
*/
|
||||
namespace Client {
|
||||
//指定网卡ip
|
||||
extern const string kNetAdapter;
|
||||
extern const std::string kNetAdapter;
|
||||
//设置rtp传输类型,可选项有0(tcp,默认)、1(udp)、2(组播)
|
||||
//设置方法:player[PlayerBase::kRtpType] = 0/1/2;
|
||||
extern const string kRtpType;
|
||||
extern const std::string kRtpType;
|
||||
//rtsp认证用户名
|
||||
extern const string kRtspUser;
|
||||
extern const std::string kRtspUser;
|
||||
//rtsp认证用用户密码,可以是明文也可以是md5,md5密码生成方式 md5(username:realm:password)
|
||||
extern const string kRtspPwd;
|
||||
extern const std::string kRtspPwd;
|
||||
//rtsp认证用用户密码是否为md5类型
|
||||
extern const string kRtspPwdIsMD5;
|
||||
extern const std::string kRtspPwdIsMD5;
|
||||
//握手超时时间,默认10,000 毫秒
|
||||
extern const string kTimeoutMS;
|
||||
extern const std::string kTimeoutMS;
|
||||
//rtp/rtmp包接收超时时间,默认5000秒
|
||||
extern const string kMediaTimeoutMS;
|
||||
extern const std::string kMediaTimeoutMS;
|
||||
//rtsp/rtmp心跳时间,默认5000毫秒
|
||||
extern const string kBeatIntervalMS;
|
||||
extern const std::string kBeatIntervalMS;
|
||||
//是否为性能测试模式,性能测试模式开启后不会解析rtp或rtmp包
|
||||
extern const string kBenchmarkMode;
|
||||
extern const std::string kBenchmarkMode;
|
||||
//播放器在触发播放成功事件时,是否等待所有track ready时再回调
|
||||
extern const string kWaitTrackReady;
|
||||
extern const std::string kWaitTrackReady;
|
||||
}
|
||||
} // namespace mediakit
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include "mpeg4-aac.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
#ifndef ENABLE_MP4
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
string makeAacConfig(const uint8_t *hex, size_t length);
|
||||
std::string makeAacConfig(const uint8_t *hex, size_t length);
|
||||
int getAacFrameLength(const uint8_t *hex, size_t length);
|
||||
int dumpAacConfig(const string &config, size_t length, uint8_t *out, size_t out_size);
|
||||
bool parseAacConfig(const string &config, int &samplerate, int &channels);
|
||||
int dumpAacConfig(const std::string &config, size_t length, uint8_t *out, size_t out_size);
|
||||
bool parseAacConfig(const std::string &config, int &samplerate, int &channels);
|
||||
|
||||
/**
|
||||
* aac音频通道
|
||||
@@ -39,12 +39,12 @@ public:
|
||||
* 构造aac类型的媒体
|
||||
* @param aac_cfg aac配置信息
|
||||
*/
|
||||
AACTrack(const string &aac_cfg);
|
||||
AACTrack(const std::string &aac_cfg);
|
||||
|
||||
/**
|
||||
* 获取aac 配置信息
|
||||
*/
|
||||
const string &getAacCfg() const;
|
||||
const std::string &getAacCfg() const;
|
||||
|
||||
bool ready() override;
|
||||
CodecId getCodecId() const override;
|
||||
@@ -60,7 +60,7 @@ private:
|
||||
bool inputFrame_l(const Frame::Ptr &frame);
|
||||
|
||||
private:
|
||||
string _cfg;
|
||||
std::string _cfg;
|
||||
int _channel = 0;
|
||||
int _sampleRate = 0;
|
||||
int _sampleBit = 16;
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
#include "AACRtmp.h"
|
||||
#include "Rtmp/Rtmp.h"
|
||||
|
||||
namespace mediakit{
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
static string getAacCfg(const RtmpPacket &thiz) {
|
||||
string ret;
|
||||
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
void onGetAAC(const char *data, size_t len, uint32_t stamp);
|
||||
|
||||
private:
|
||||
string _aac_cfg;
|
||||
std::string _aac_cfg;
|
||||
};
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
private:
|
||||
uint8_t _audio_flv_flags;
|
||||
AACTrack::Ptr _track;
|
||||
string _aac_cfg;
|
||||
std::string _aac_cfg;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -60,7 +60,7 @@ void AACRtpEncoder::makeAACRtp(const void *data, size_t len, bool mark, uint32_t
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AACRtpDecoder::AACRtpDecoder(const Track::Ptr &track) {
|
||||
auto aacTrack = dynamic_pointer_cast<AACTrack>(track);
|
||||
auto aacTrack = std::dynamic_pointer_cast<AACTrack>(track);
|
||||
if (!aacTrack || !aacTrack->ready()) {
|
||||
WarnL << "该aac track无效!";
|
||||
} else {
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
|
||||
private:
|
||||
uint32_t _last_dts = 0;
|
||||
string _aac_cfg;
|
||||
std::string _aac_cfg;
|
||||
FrameImp::Ptr _frame;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "CommonRtp.h"
|
||||
|
||||
using namespace mediakit;
|
||||
|
||||
CommonRtpDecoder::CommonRtpDecoder(CodecId codec, size_t max_frame_size ){
|
||||
_codec = codec;
|
||||
_max_frame_size = max_frame_size;
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "L16.h"
|
||||
#include "Common/Parser.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
|
||||
|
||||
@@ -17,9 +17,6 @@
|
||||
#include "Rtsp/RtpCodec.h"
|
||||
#include "Rtmp/RtmpCodec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
class Factory {
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
#include "Util/RingBuffer.h"
|
||||
#include "Network/Socket.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
typedef enum {
|
||||
@@ -53,7 +50,7 @@ typedef enum {
|
||||
/**
|
||||
* 字符串转媒体类型转
|
||||
*/
|
||||
TrackType getTrackType(const string &str);
|
||||
TrackType getTrackType(const std::string &str);
|
||||
|
||||
/**
|
||||
* 媒体类型转字符串
|
||||
@@ -65,7 +62,7 @@ const char* getTrackString(TrackType type);
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
CodecId getCodecId(const string &str);
|
||||
CodecId getCodecId(const std::string &str);
|
||||
|
||||
/**
|
||||
* 获取编码器名称
|
||||
@@ -106,7 +103,7 @@ public:
|
||||
/**
|
||||
* 帧类型的抽象接口
|
||||
*/
|
||||
class Frame : public Buffer, public CodecInfo {
|
||||
class Frame : public toolkit::Buffer, public CodecInfo {
|
||||
public:
|
||||
typedef std::shared_ptr<Frame> Ptr;
|
||||
virtual ~Frame(){}
|
||||
@@ -171,7 +168,7 @@ public:
|
||||
|
||||
private:
|
||||
//对象个数统计
|
||||
ObjectStatistic<Frame> _statistic;
|
||||
toolkit::ObjectStatistic<Frame> _statistic;
|
||||
};
|
||||
|
||||
class FrameImp : public Frame {
|
||||
@@ -233,14 +230,14 @@ public:
|
||||
uint32_t _dts = 0;
|
||||
uint32_t _pts = 0;
|
||||
size_t _prefix_size = 0;
|
||||
BufferLikeString _buffer;
|
||||
toolkit::BufferLikeString _buffer;
|
||||
|
||||
private:
|
||||
//对象个数统计
|
||||
ObjectStatistic<FrameImp> _statistic;
|
||||
toolkit::ObjectStatistic<FrameImp> _statistic;
|
||||
|
||||
protected:
|
||||
friend class ResourcePool_l<FrameImp>;
|
||||
friend class toolkit::ResourcePool_l<FrameImp>;
|
||||
FrameImp() = default;
|
||||
};
|
||||
|
||||
@@ -323,7 +320,7 @@ public:
|
||||
*/
|
||||
void addDelegate(const FrameWriterInterface::Ptr &delegate){
|
||||
//_delegates_write可能多线程同时操作
|
||||
lock_guard<mutex> lck(_mtx);
|
||||
std::lock_guard<std::mutex> lck(_mtx);
|
||||
_delegates_write.emplace(delegate.get(),delegate);
|
||||
_need_update = true;
|
||||
}
|
||||
@@ -333,7 +330,7 @@ public:
|
||||
*/
|
||||
void delDelegate(FrameWriterInterface *ptr){
|
||||
//_delegates_write可能多线程同时操作
|
||||
lock_guard<mutex> lck(_mtx);
|
||||
std::lock_guard<std::mutex> lck(_mtx);
|
||||
_delegates_write.erase(ptr);
|
||||
_need_update = true;
|
||||
}
|
||||
@@ -344,7 +341,7 @@ public:
|
||||
bool inputFrame(const Frame::Ptr &frame) override{
|
||||
if(_need_update){
|
||||
//发现代理列表发生变化了,这里同步一次
|
||||
lock_guard<mutex> lck(_mtx);
|
||||
std::lock_guard<std::mutex> lck(_mtx);
|
||||
_delegates_read = _delegates_write;
|
||||
_need_update = false;
|
||||
}
|
||||
@@ -366,9 +363,9 @@ public:
|
||||
return _delegates_write.size();
|
||||
}
|
||||
private:
|
||||
mutex _mtx;
|
||||
map<void *,FrameWriterInterface::Ptr> _delegates_read;
|
||||
map<void *,FrameWriterInterface::Ptr> _delegates_write;
|
||||
std::mutex _mtx;
|
||||
std::map<void *,FrameWriterInterface::Ptr> _delegates_read;
|
||||
std::map<void *,FrameWriterInterface::Ptr> _delegates_write;
|
||||
bool _need_update = false;
|
||||
};
|
||||
|
||||
@@ -463,7 +460,7 @@ public:
|
||||
* @param prefix 帧前缀长度
|
||||
* @param offset buffer有效数据偏移量
|
||||
*/
|
||||
FrameWrapper(const Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset) : Parent(buf->data() + offset, buf->size() - offset, dts, pts, prefix){
|
||||
FrameWrapper(const toolkit::Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset) : Parent(buf->data() + offset, buf->size() - offset, dts, pts, prefix){
|
||||
_buf = buf;
|
||||
}
|
||||
|
||||
@@ -476,7 +473,7 @@ public:
|
||||
* @param offset buffer有效数据偏移量
|
||||
* @param codec 帧类型
|
||||
*/
|
||||
FrameWrapper(const Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset, CodecId codec) : Parent(codec, buf->data() + offset, buf->size() - offset, dts, pts, prefix){
|
||||
FrameWrapper(const toolkit::Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset, CodecId codec) : Parent(codec, buf->data() + offset, buf->size() - offset, dts, pts, prefix){
|
||||
_buf = buf;
|
||||
}
|
||||
|
||||
@@ -488,7 +485,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Buffer::Ptr _buf;
|
||||
toolkit::Buffer::Ptr _buf;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -496,7 +493,7 @@ private:
|
||||
*/
|
||||
class FrameMerger {
|
||||
public:
|
||||
using onOutput = function<void(uint32_t dts, uint32_t pts, const Buffer::Ptr &buffer, bool have_key_frame)>;
|
||||
using onOutput = std::function<void(uint32_t dts, uint32_t pts, const toolkit::Buffer::Ptr &buffer, bool have_key_frame)>;
|
||||
using Ptr = std::shared_ptr<FrameMerger>;
|
||||
enum {
|
||||
none = 0,
|
||||
@@ -508,16 +505,16 @@ public:
|
||||
~FrameMerger() = default;
|
||||
|
||||
void clear();
|
||||
bool inputFrame(const Frame::Ptr &frame, const onOutput &cb, BufferLikeString *buffer = nullptr);
|
||||
bool inputFrame(const Frame::Ptr &frame, const onOutput &cb, toolkit::BufferLikeString *buffer = nullptr);
|
||||
|
||||
private:
|
||||
bool willFlush(const Frame::Ptr &frame) const;
|
||||
void doMerge(BufferLikeString &buffer, const Frame::Ptr &frame) const;
|
||||
void doMerge(toolkit::BufferLikeString &buffer, const Frame::Ptr &frame) const;
|
||||
|
||||
private:
|
||||
int _type;
|
||||
bool _have_decode_able_frame = false;
|
||||
List<Frame::Ptr> _frame_cache;
|
||||
toolkit::List<Frame::Ptr> _frame_cache;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "G711.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "SPSParser.h"
|
||||
#include "Util/logger.h"
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
#include "Frame.h"
|
||||
#include "Track.h"
|
||||
#include "Util/base64.h"
|
||||
|
||||
#define H264_TYPE(v) ((uint8_t)(v) & 0x1F)
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
bool getAVCInfo(const string &strSps,int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
|
||||
bool getAVCInfo(const std::string &strSps,int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
|
||||
void splitH264(const char *ptr, size_t len, size_t prefix, const std::function<void(const char *, size_t, size_t)> &cb);
|
||||
size_t prefixSize(const char *ptr, size_t len);
|
||||
|
||||
@@ -27,7 +27,7 @@ template<typename Parent>
|
||||
class H264FrameHelper : public Parent{
|
||||
public:
|
||||
friend class FrameImp;
|
||||
friend class ResourcePool_l<H264FrameHelper>;
|
||||
friend class toolkit::ResourcePool_l<H264FrameHelper>;
|
||||
using Ptr = std::shared_ptr<H264FrameHelper>;
|
||||
|
||||
enum {
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
* @param sps_prefix_len 264头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||
* @param pps_prefix_len 264头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||
*/
|
||||
H264Track(const string &sps,const string &pps,int sps_prefix_len = 4,int pps_prefix_len = 4);
|
||||
H264Track(const std::string &sps,const std::string &pps,int sps_prefix_len = 4,int pps_prefix_len = 4);
|
||||
|
||||
/**
|
||||
* 构造h264类型的媒体
|
||||
@@ -120,8 +120,8 @@ public:
|
||||
/**
|
||||
* 返回不带0x00 00 00 01头的sps/pps
|
||||
*/
|
||||
const string &getSps() const;
|
||||
const string &getPps() const;
|
||||
const std::string &getSps() const;
|
||||
const std::string &getPps() const;
|
||||
|
||||
bool ready() override;
|
||||
CodecId getCodecId() const override;
|
||||
@@ -142,8 +142,8 @@ private:
|
||||
int _width = 0;
|
||||
int _height = 0;
|
||||
float _fps = 0;
|
||||
string _sps;
|
||||
string _pps;
|
||||
std::string _sps;
|
||||
std::string _pps;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -10,7 +10,11 @@
|
||||
|
||||
#include "Rtmp/utils.h"
|
||||
#include "H264Rtmp.h"
|
||||
namespace mediakit{
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
H264RtmpDecoder::H264RtmpDecoder() {
|
||||
_h264frame = obtainFrame();
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "Extension/Track.h"
|
||||
#include "Util/ResourcePool.h"
|
||||
#include "Extension/H264.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
/**
|
||||
@@ -45,8 +44,8 @@ protected:
|
||||
|
||||
protected:
|
||||
H264Frame::Ptr _h264frame;
|
||||
string _sps;
|
||||
string _pps;
|
||||
std::string _sps;
|
||||
std::string _pps;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "Util/ResourcePool.h"
|
||||
#include "Extension/H264.h"
|
||||
#include "Common/Stamp.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
#include "H265.h"
|
||||
#include "SPSParser.h"
|
||||
|
||||
namespace mediakit{
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
bool getHEVCInfo(const char * vps, size_t vps_len,const char * sps,size_t sps_len,int &iVideoWidth, int &iVideoHeight, float &iVideoFps){
|
||||
T_GetBitContext tGetBitBuf;
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
#include "Track.h"
|
||||
#include "Util/base64.h"
|
||||
#include "H264.h"
|
||||
|
||||
#define H265_TYPE(v) (((uint8_t)(v) >> 1) & 0x3f)
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
bool getHEVCInfo(const string &strVps, const string &strSps, int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
|
||||
bool getHEVCInfo(const std::string &strVps, const std::string &strSps, int &iVideoWidth, int &iVideoHeight, float &iVideoFps);
|
||||
|
||||
template<typename Parent>
|
||||
class H265FrameHelper : public Parent{
|
||||
public:
|
||||
friend class FrameImp;
|
||||
friend class ResourcePool_l<H265FrameHelper>;
|
||||
friend class toolkit::ResourcePool_l<H265FrameHelper>;
|
||||
using Ptr = std::shared_ptr<H265FrameHelper>;
|
||||
|
||||
enum {
|
||||
@@ -136,14 +136,14 @@ public:
|
||||
* @param sps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||
* @param pps_prefix_len 265头长度,可以为3个或4个字节,一般为0x00 00 00 01
|
||||
*/
|
||||
H265Track(const string &vps,const string &sps, const string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4);
|
||||
H265Track(const std::string &vps,const std::string &sps, const std::string &pps,int vps_prefix_len = 4, int sps_prefix_len = 4, int pps_prefix_len = 4);
|
||||
|
||||
/**
|
||||
* 返回不带0x00 00 00 01头的vps/sps/pps
|
||||
*/
|
||||
const string &getVps() const;
|
||||
const string &getSps() const;
|
||||
const string &getPps() const;
|
||||
const std::string &getVps() const;
|
||||
const std::string &getSps() const;
|
||||
const std::string &getPps() const;
|
||||
|
||||
bool ready() override;
|
||||
CodecId getCodecId() const override;
|
||||
@@ -164,9 +164,9 @@ private:
|
||||
int _width = 0;
|
||||
int _height = 0;
|
||||
float _fps = 0;
|
||||
string _vps;
|
||||
string _sps;
|
||||
string _pps;
|
||||
std::string _vps;
|
||||
std::string _sps;
|
||||
std::string _pps;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include "mpeg4-hevc.h"
|
||||
#endif//ENABLE_MP4
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
H265RtmpDecoder::H265RtmpDecoder() {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "Extension/Track.h"
|
||||
#include "Util/ResourcePool.h"
|
||||
#include "Extension/H265.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
/**
|
||||
@@ -79,9 +78,9 @@ private:
|
||||
|
||||
private:
|
||||
bool _got_config_frame = false;
|
||||
string _vps;
|
||||
string _sps;
|
||||
string _pps;
|
||||
std::string _vps;
|
||||
std::string _sps;
|
||||
std::string _pps;
|
||||
H265Track::Ptr _track;
|
||||
RtmpPacket::Ptr _rtmp_packet;
|
||||
FrameMerger _merger{FrameMerger::mp4_nal_size};
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include "Extension/H265.h"
|
||||
#include "Common/Stamp.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "L16.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "Opus.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "Frame.h"
|
||||
#include "Util/RingBuffer.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
@@ -186,7 +185,7 @@ public:
|
||||
* 获取全部的Track
|
||||
* @param trackReady 是否获取全部已经准备好的Track
|
||||
*/
|
||||
virtual vector<Track::Ptr> getTracks(bool trackReady = true) const = 0;
|
||||
virtual std::vector<Track::Ptr> getTracks(bool trackReady = true) const = 0;
|
||||
|
||||
/**
|
||||
* 获取特定Track
|
||||
|
||||
@@ -12,18 +12,18 @@
|
||||
#define ZLMEDIAKIT_FMP4MEDIASOURCE_H
|
||||
|
||||
#include "Common/MediaSource.h"
|
||||
using namespace toolkit;
|
||||
|
||||
#define FMP4_GOP_SIZE 512
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
//FMP4直播数据包
|
||||
class FMP4Packet : public BufferString{
|
||||
class FMP4Packet : public toolkit::BufferString{
|
||||
public:
|
||||
using Ptr = std::shared_ptr<FMP4Packet>;
|
||||
|
||||
template<typename ...ARGS>
|
||||
FMP4Packet(ARGS && ...args) : BufferString(std::forward<ARGS>(args)...) {};
|
||||
FMP4Packet(ARGS && ...args) : toolkit::BufferString(std::forward<ARGS>(args)...) {};
|
||||
~FMP4Packet() override = default;
|
||||
|
||||
public:
|
||||
@@ -31,15 +31,15 @@ public:
|
||||
};
|
||||
|
||||
//FMP4直播源
|
||||
class FMP4MediaSource : public MediaSource, public RingDelegate<FMP4Packet::Ptr>, private PacketCache<FMP4Packet>{
|
||||
class FMP4MediaSource : public MediaSource, public toolkit::RingDelegate<FMP4Packet::Ptr>, private PacketCache<FMP4Packet>{
|
||||
public:
|
||||
using Ptr = std::shared_ptr<FMP4MediaSource>;
|
||||
using RingDataType = std::shared_ptr<List<FMP4Packet::Ptr> >;
|
||||
using RingType = RingBuffer<RingDataType>;
|
||||
using RingDataType = std::shared_ptr<toolkit::List<FMP4Packet::Ptr> >;
|
||||
using RingType = toolkit::RingBuffer<RingDataType>;
|
||||
|
||||
FMP4MediaSource(const string &vhost,
|
||||
const string &app,
|
||||
const string &stream_id,
|
||||
FMP4MediaSource(const std::string &vhost,
|
||||
const std::string &app,
|
||||
const std::string &stream_id,
|
||||
int ring_size = FMP4_GOP_SIZE) : MediaSource(FMP4_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {}
|
||||
|
||||
~FMP4MediaSource() override = default;
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
/**
|
||||
* 获取fmp4 init segment
|
||||
*/
|
||||
const string &getInitSegment() const{
|
||||
const std::string &getInitSegment() const{
|
||||
return _init_segment;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
* 设置fmp4 init segment
|
||||
* @param str init segment
|
||||
*/
|
||||
void setInitSegment(string str) {
|
||||
void setInitSegment(std::string str) {
|
||||
_init_segment = std::move(str);
|
||||
createRing();
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
|
||||
private:
|
||||
void createRing(){
|
||||
weak_ptr<FMP4MediaSource> weak_self = dynamic_pointer_cast<FMP4MediaSource>(shared_from_this());
|
||||
std::weak_ptr<FMP4MediaSource> weak_self = std::dynamic_pointer_cast<FMP4MediaSource>(shared_from_this());
|
||||
_ring = std::make_shared<RingType>(_ring_size, [weak_self](int size) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
@@ -120,7 +120,7 @@ private:
|
||||
* @param packet_list 合并写缓存列队
|
||||
* @param key_pos 是否包含关键帧
|
||||
*/
|
||||
void onFlush(std::shared_ptr<List<FMP4Packet::Ptr> > packet_list, bool key_pos) override {
|
||||
void onFlush(std::shared_ptr<toolkit::List<FMP4Packet::Ptr> > packet_list, bool key_pos) override {
|
||||
//如果不存在视频,那么就没有存在GOP缓存的意义,所以确保一直清空GOP缓存
|
||||
_ring->write(std::move(packet_list), _have_video ? key_pos : true);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ private:
|
||||
private:
|
||||
bool _have_video = false;
|
||||
int _ring_size;
|
||||
string _init_segment;
|
||||
std::string _init_segment;
|
||||
RingType::Ptr _ring;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ class FMP4MediaSourceMuxer : public MP4MuxerMemory, public MediaSourceEventInter
|
||||
public:
|
||||
using Ptr = std::shared_ptr<FMP4MediaSourceMuxer>;
|
||||
|
||||
FMP4MediaSourceMuxer(const string &vhost,
|
||||
const string &app,
|
||||
const string &stream_id) {
|
||||
FMP4MediaSourceMuxer(const std::string &vhost,
|
||||
const std::string &app,
|
||||
const std::string &stream_id) {
|
||||
_media_src = std::make_shared<FMP4MediaSource>(vhost, app, stream_id);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void onSegmentData(string string, uint32_t stamp, bool key_frame) override {
|
||||
void onSegmentData(std::string string, uint32_t stamp, bool key_frame) override {
|
||||
if (string.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
#include "HlsParser.h"
|
||||
#include "Util/util.h"
|
||||
#include "Common/Parser.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
bool HlsParser::parse(const string &http_url, const string &m3u8) {
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
typedef struct{
|
||||
//url地址
|
||||
string url;
|
||||
std::string url;
|
||||
//ts切片长度
|
||||
float duration;
|
||||
|
||||
@@ -38,7 +38,7 @@ class HlsParser {
|
||||
public:
|
||||
HlsParser(){}
|
||||
~HlsParser(){}
|
||||
bool parse(const string &http_url,const string &m3u8);
|
||||
bool parse(const std::string &http_url,const std::string &m3u8);
|
||||
|
||||
/**
|
||||
* 是否存在#EXTM3U字段,是否为m3u8文件
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
|
||||
protected:
|
||||
//解析出ts文件地址回调
|
||||
virtual void onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_segment> &ts_list) {};
|
||||
virtual void onParsed(bool is_m3u8_inner,int64_t sequence,const std::map<int,ts_segment> &ts_list) {};
|
||||
|
||||
private:
|
||||
bool _is_m3u8 = false;
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "HlsPlayer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller) {
|
||||
@@ -27,8 +30,8 @@ void HlsPlayer::fetchIndexFile() {
|
||||
if (waitResponse()) {
|
||||
return;
|
||||
}
|
||||
if (!(*this)[kNetAdapter].empty()) {
|
||||
setNetAdapter((*this)[kNetAdapter]);
|
||||
if (!(*this)[Client::kNetAdapter].empty()) {
|
||||
setNetAdapter((*this)[Client::kNetAdapter]);
|
||||
}
|
||||
setCompleteTimeout((*this)[Client::kTimeoutMS].as<int>());
|
||||
setMethod("GET");
|
||||
@@ -83,7 +86,7 @@ void HlsPlayer::fetchSegment() {
|
||||
strong_self->onPacket_l(data, len);
|
||||
});
|
||||
|
||||
if (!(*this)[kNetAdapter].empty()) {
|
||||
if (!(*this)[Client::kNetAdapter].empty()) {
|
||||
_http_ts_player->setNetAdapter((*this)[Client::kNetAdapter]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
#include "HlsParser.h"
|
||||
#include "Rtp/TSDecoder.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HlsDemuxer
|
||||
@@ -29,12 +27,12 @@ public:
|
||||
HlsDemuxer() = default;
|
||||
~HlsDemuxer() override { _timer = nullptr; }
|
||||
|
||||
void start(const EventPoller::Ptr &poller, TrackListener *listener);
|
||||
void start(const toolkit::EventPoller::Ptr &poller, TrackListener *listener);
|
||||
bool inputFrame(const Frame::Ptr &frame) override;
|
||||
bool addTrack(const Track::Ptr &track) override { return _delegate.addTrack(track); }
|
||||
void addTrackCompleted() override { _delegate.addTrackCompleted(); }
|
||||
void resetTracks() override { ((MediaSink &)_delegate).resetTracks(); }
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override { return _delegate.getTracks(ready); }
|
||||
std::vector<Track::Ptr> getTracks(bool ready = true) const override { return _delegate.getTracks(ready); }
|
||||
|
||||
private:
|
||||
void onTick();
|
||||
@@ -44,22 +42,22 @@ private:
|
||||
|
||||
private:
|
||||
int64_t _ticker_offset = 0;
|
||||
Ticker _ticker;
|
||||
toolkit::Ticker _ticker;
|
||||
Stamp _stamp[2];
|
||||
Timer::Ptr _timer;
|
||||
toolkit::Timer::Ptr _timer;
|
||||
MediaSinkDelegate _delegate;
|
||||
multimap<int64_t, Frame::Ptr> _frame_cache;
|
||||
std::multimap<int64_t, Frame::Ptr> _frame_cache;
|
||||
};
|
||||
|
||||
class HlsPlayer : public HttpClientImp , public PlayerBase , public HlsParser{
|
||||
public:
|
||||
HlsPlayer(const EventPoller::Ptr &poller);
|
||||
HlsPlayer(const toolkit::EventPoller::Ptr &poller);
|
||||
~HlsPlayer() override = default;
|
||||
|
||||
/**
|
||||
* 开始播放
|
||||
*/
|
||||
void play(const string &url) override;
|
||||
void play(const std::string &url) override;
|
||||
|
||||
/**
|
||||
* 停止播放
|
||||
@@ -76,37 +74,37 @@ protected:
|
||||
|
||||
private:
|
||||
void onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_segment> &ts_map) override;
|
||||
void onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseHeader(const std::string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,size_t size) override;
|
||||
void onResponseCompleted(const SockException &e) override;
|
||||
bool onRedirectUrl(const string &url,bool temporary) override;
|
||||
void onResponseCompleted(const toolkit::SockException &e) override;
|
||||
bool onRedirectUrl(const std::string &url,bool temporary) override;
|
||||
|
||||
private:
|
||||
void playDelay();
|
||||
float delaySecond();
|
||||
void fetchSegment();
|
||||
void teardown_l(const SockException &ex);
|
||||
void teardown_l(const toolkit::SockException &ex);
|
||||
void fetchIndexFile();
|
||||
void onPacket_l(const char *data, size_t len);
|
||||
|
||||
private:
|
||||
struct UrlComp {
|
||||
//url忽略?后面的参数
|
||||
bool operator()(const string& __x, const string& __y) const {
|
||||
return split(__x,"?")[0] < split(__y,"?")[0];
|
||||
bool operator()(const std::string& __x, const std::string& __y) const {
|
||||
return toolkit::split(__x,"?")[0] < toolkit::split(__y,"?")[0];
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
bool _play_result = false;
|
||||
int64_t _last_sequence = -1;
|
||||
string _m3u8;
|
||||
string _play_url;
|
||||
Timer::Ptr _timer;
|
||||
Timer::Ptr _timer_ts;
|
||||
list<ts_segment> _ts_list;
|
||||
list<string> _ts_url_sort;
|
||||
set<string, UrlComp> _ts_url_cache;
|
||||
std::string _m3u8;
|
||||
std::string _play_url;
|
||||
toolkit::Timer::Ptr _timer;
|
||||
toolkit::Timer::Ptr _timer_ts;
|
||||
std::list<ts_segment> _ts_list;
|
||||
std::list<std::string> _ts_url_sort;
|
||||
std::set<std::string, UrlComp> _ts_url_cache;
|
||||
HttpTSPlayer::Ptr _http_ts_player;
|
||||
TSSegment _segment;
|
||||
};
|
||||
@@ -114,7 +112,7 @@ private:
|
||||
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {
|
||||
public:
|
||||
typedef std::shared_ptr<HlsPlayerImp> Ptr;
|
||||
HlsPlayerImp(const EventPoller::Ptr &poller = nullptr);
|
||||
HlsPlayerImp(const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||
~HlsPlayerImp() override = default;
|
||||
|
||||
private:
|
||||
@@ -123,9 +121,9 @@ private:
|
||||
|
||||
private:
|
||||
//// PlayerBase override////
|
||||
void onPlayResult(const SockException &ex) override;
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||
void onShutdown(const SockException &ex) override;
|
||||
void onPlayResult(const toolkit::SockException &ex) override;
|
||||
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||
void onShutdown(const toolkit::SockException &ex) override;
|
||||
|
||||
private:
|
||||
//// TrackListener override////
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
#define ENABLE_MMAP
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
HttpStringBody::HttpStringBody(string str){
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
#include "Util/logger.h"
|
||||
#include "Thread/WorkThreadPool.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b) )
|
||||
#endif //MIN
|
||||
@@ -47,14 +44,14 @@ public:
|
||||
* @param size 请求大小
|
||||
* @return 字节对象,如果读完了,那么请返回nullptr
|
||||
*/
|
||||
virtual Buffer::Ptr readData(size_t size) { return nullptr;};
|
||||
virtual toolkit::Buffer::Ptr readData(size_t size) { return nullptr;};
|
||||
|
||||
/**
|
||||
* 异步请求读取一定字节数,返回大小可能小于size
|
||||
* @param size 请求大小
|
||||
* @param cb 回调函数
|
||||
*/
|
||||
virtual void readDataAsync(size_t size,const function<void(const Buffer::Ptr &buf)> &cb){
|
||||
virtual void readDataAsync(size_t size,const std::function<void(const toolkit::Buffer::Ptr &buf)> &cb){
|
||||
//由于unix和linux是通过mmap的方式读取文件,所以把读文件操作放在后台线程并不能提高性能
|
||||
//反而会由于频繁的线程切换导致性能降低以及延时增加,所以我们默认同步获取文件内容
|
||||
//(其实并没有读,拷贝文件数据时在内核态完成文件读)
|
||||
@@ -63,20 +60,20 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* string类型的content
|
||||
* std::string类型的content
|
||||
*/
|
||||
class HttpStringBody : public HttpBody{
|
||||
public:
|
||||
typedef std::shared_ptr<HttpStringBody> Ptr;
|
||||
HttpStringBody(string str);
|
||||
HttpStringBody(std::string str);
|
||||
~HttpStringBody() override = default;
|
||||
|
||||
ssize_t remainSize() override;
|
||||
Buffer::Ptr readData(size_t size) override ;
|
||||
toolkit::Buffer::Ptr readData(size_t size) override ;
|
||||
|
||||
private:
|
||||
size_t _offset = 0;
|
||||
mutable string _str;
|
||||
mutable std::string _str;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -85,14 +82,14 @@ private:
|
||||
class HttpBufferBody : public HttpBody{
|
||||
public:
|
||||
typedef std::shared_ptr<HttpBufferBody> Ptr;
|
||||
HttpBufferBody(Buffer::Ptr buffer);
|
||||
HttpBufferBody(toolkit::Buffer::Ptr buffer);
|
||||
~HttpBufferBody() override = default;
|
||||
|
||||
ssize_t remainSize() override;
|
||||
Buffer::Ptr readData(size_t size) override;
|
||||
toolkit::Buffer::Ptr readData(size_t size) override;
|
||||
|
||||
private:
|
||||
Buffer::Ptr _buffer;
|
||||
toolkit::Buffer::Ptr _buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -110,11 +107,11 @@ public:
|
||||
* @param use_mmap 是否使用mmap方式访问文件
|
||||
*/
|
||||
HttpFileBody(const std::shared_ptr<FILE> &fp, size_t offset, size_t max_size, bool use_mmap = true);
|
||||
HttpFileBody(const string &file_path, bool use_mmap = true);
|
||||
HttpFileBody(const std::string &file_path, bool use_mmap = true);
|
||||
~HttpFileBody() override = default;
|
||||
|
||||
ssize_t remainSize() override ;
|
||||
Buffer::Ptr readData(size_t size) override;
|
||||
toolkit::Buffer::Ptr readData(size_t size) override;
|
||||
|
||||
private:
|
||||
void init(const std::shared_ptr<FILE> &fp,size_t offset,size_t max_size, bool use_mmap);
|
||||
@@ -124,7 +121,7 @@ private:
|
||||
size_t _offset = 0;
|
||||
std::shared_ptr<FILE> _fp;
|
||||
std::shared_ptr<char> _map_addr;
|
||||
ResourcePool<BufferRaw> _pool;
|
||||
toolkit::ResourcePool<toolkit::BufferRaw> _pool;
|
||||
};
|
||||
|
||||
class HttpArgs;
|
||||
@@ -142,21 +139,21 @@ public:
|
||||
* @param filePath 文件路径
|
||||
* @param boundary boundary字符串
|
||||
*/
|
||||
HttpMultiFormBody(const HttpArgs &args,const string &filePath,const string &boundary = "0xKhTmLbOuNdArY");
|
||||
HttpMultiFormBody(const HttpArgs &args,const std::string &filePath,const std::string &boundary = "0xKhTmLbOuNdArY");
|
||||
virtual ~HttpMultiFormBody(){}
|
||||
ssize_t remainSize() override ;
|
||||
Buffer::Ptr readData(size_t size) override;
|
||||
toolkit::Buffer::Ptr readData(size_t size) override;
|
||||
|
||||
public:
|
||||
static string multiFormBodyPrefix(const HttpArgs &args,const string &boundary,const string &fileName);
|
||||
static string multiFormBodySuffix(const string &boundary);
|
||||
static string multiFormContentType(const string &boundary);
|
||||
static std::string multiFormBodyPrefix(const HttpArgs &args,const std::string &boundary,const std::string &fileName);
|
||||
static std::string multiFormBodySuffix(const std::string &boundary);
|
||||
static std::string multiFormContentType(const std::string &boundary);
|
||||
|
||||
private:
|
||||
size_t _offset = 0;
|
||||
size_t _totalSize;
|
||||
string _bodyPrefix;
|
||||
string _bodySuffix;
|
||||
std::string _bodyPrefix;
|
||||
std::string _bodySuffix;
|
||||
HttpFileBody::Ptr _fileBody;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <string.h>
|
||||
#include "HttpChunkedSplitter.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, size_t len) {
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include "HttpClient.h"
|
||||
#include "Common/config.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
void HttpClient::sendRequest(const string &url) {
|
||||
|
||||
@@ -25,18 +25,15 @@
|
||||
#include "strCoding.h"
|
||||
#include "HttpBody.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HttpArgs : public map<string, variant, StrCaseCompare> {
|
||||
class HttpArgs : public std::map<std::string, toolkit::variant, StrCaseCompare> {
|
||||
public:
|
||||
HttpArgs() = default;
|
||||
~HttpArgs() = default;
|
||||
|
||||
string make() const {
|
||||
string ret;
|
||||
std::string make() const {
|
||||
std::string ret;
|
||||
for (auto &pr : *this) {
|
||||
ret.append(pr.first);
|
||||
ret.append("=");
|
||||
@@ -50,7 +47,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class HttpClient : public TcpClient, public HttpRequestSplitter {
|
||||
class HttpClient : public toolkit::TcpClient, public HttpRequestSplitter {
|
||||
public:
|
||||
using HttpHeader = StrCaseMap;
|
||||
using Ptr = std::shared_ptr<HttpClient>;
|
||||
@@ -62,7 +59,7 @@ public:
|
||||
* 发送http[s]请求
|
||||
* @param url 请求url
|
||||
*/
|
||||
virtual void sendRequest(const string &url);
|
||||
virtual void sendRequest(const std::string &url);
|
||||
|
||||
/**
|
||||
* 重置对象
|
||||
@@ -73,7 +70,7 @@ public:
|
||||
* 设置http方法
|
||||
* @param method GET/POST等
|
||||
*/
|
||||
void setMethod(string method);
|
||||
void setMethod(std::string method);
|
||||
|
||||
/**
|
||||
* 覆盖http头
|
||||
@@ -81,13 +78,13 @@ public:
|
||||
*/
|
||||
void setHeader(HttpHeader header);
|
||||
|
||||
HttpClient &addHeader(string key, string val, bool force = false);
|
||||
HttpClient &addHeader(std::string key, std::string val, bool force = false);
|
||||
|
||||
/**
|
||||
* 设置http content
|
||||
* @param body http content
|
||||
*/
|
||||
void setBody(string body);
|
||||
void setBody(std::string body);
|
||||
|
||||
/**
|
||||
* 设置http content
|
||||
@@ -113,7 +110,7 @@ public:
|
||||
/**
|
||||
* 获取请求url
|
||||
*/
|
||||
const string &getUrl() const;
|
||||
const std::string &getUrl() const;
|
||||
|
||||
/**
|
||||
* 判断是否正在等待响应
|
||||
@@ -150,7 +147,7 @@ protected:
|
||||
* @param status 状态码,譬如:200 OK
|
||||
* @param headers http头
|
||||
*/
|
||||
virtual void onResponseHeader(const string &status, const HttpHeader &headers) = 0;
|
||||
virtual void onResponseHeader(const std::string &status, const HttpHeader &headers) = 0;
|
||||
|
||||
/**
|
||||
* 收到http conten数据
|
||||
@@ -162,7 +159,7 @@ protected:
|
||||
/**
|
||||
* 接收http回复完毕,
|
||||
*/
|
||||
virtual void onResponseCompleted(const SockException &ex) = 0;
|
||||
virtual void onResponseCompleted(const toolkit::SockException &ex) = 0;
|
||||
|
||||
/**
|
||||
* 重定向事件
|
||||
@@ -170,7 +167,7 @@ protected:
|
||||
* @param temporary 是否为临时重定向
|
||||
* @return 是否继续
|
||||
*/
|
||||
virtual bool onRedirectUrl(const string &url, bool temporary) { return true; };
|
||||
virtual bool onRedirectUrl(const std::string &url, bool temporary) { return true; };
|
||||
|
||||
protected:
|
||||
//// HttpRequestSplitter override ////
|
||||
@@ -178,15 +175,15 @@ protected:
|
||||
void onRecvContent(const char *data, size_t len) override;
|
||||
|
||||
//// TcpClient override ////
|
||||
void onConnect(const SockException &ex) override;
|
||||
void onRecv(const Buffer::Ptr &pBuf) override;
|
||||
void onErr(const SockException &ex) override;
|
||||
void onConnect(const toolkit::SockException &ex) override;
|
||||
void onRecv(const toolkit::Buffer::Ptr &pBuf) override;
|
||||
void onErr(const toolkit::SockException &ex) override;
|
||||
void onFlush() override;
|
||||
void onManager() override;
|
||||
|
||||
private:
|
||||
void onResponseCompleted_l(const SockException &ex);
|
||||
void onConnect_l(const SockException &ex);
|
||||
void onResponseCompleted_l(const toolkit::SockException &ex);
|
||||
void onConnect_l(const toolkit::SockException &ex);
|
||||
void checkCookie(HttpHeader &headers);
|
||||
void clearResponse();
|
||||
|
||||
@@ -201,23 +198,23 @@ private:
|
||||
|
||||
//for request args
|
||||
bool _is_https;
|
||||
string _url;
|
||||
std::string _url;
|
||||
HttpHeader _user_set_header;
|
||||
HttpBody::Ptr _body;
|
||||
string _method;
|
||||
string _last_host;
|
||||
std::string _method;
|
||||
std::string _last_host;
|
||||
|
||||
//for this request
|
||||
string _path;
|
||||
std::string _path;
|
||||
HttpHeader _header;
|
||||
|
||||
//for timeout
|
||||
size_t _wait_header_ms = 10 * 1000;
|
||||
size_t _wait_body_ms = 10 * 1000;
|
||||
size_t _wait_complete_ms = 0;
|
||||
Ticker _wait_header;
|
||||
Ticker _wait_body;
|
||||
Ticker _wait_complete;
|
||||
toolkit::Ticker _wait_header;
|
||||
toolkit::Ticker _wait_body;
|
||||
toolkit::Ticker _wait_complete;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "Http/HttpClientImp.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
void HttpClientImp::onConnect(const SockException &ex) {
|
||||
|
||||
@@ -13,17 +13,17 @@
|
||||
|
||||
#include "HttpClient.h"
|
||||
#include "Util/SSLBox.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HttpClientImp : public TcpClientWithSSL<HttpClient> {
|
||||
class HttpClientImp : public toolkit::TcpClientWithSSL<HttpClient> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<HttpClientImp>;
|
||||
HttpClientImp() = default;
|
||||
~HttpClientImp() override = default;
|
||||
|
||||
protected:
|
||||
void onConnect(const SockException &ex) override;
|
||||
void onConnect(const toolkit::SockException &ex) override;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include "Common/Parser.h"
|
||||
#include "Util/onceToken.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
const char *getHttpStatusMessage(int status) {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#define ZLMEDIAKIT_HTTPCONST_H
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
@@ -28,7 +27,7 @@ const char *getHttpStatusMessage(int status);
|
||||
* @param name 文件后缀,譬如html
|
||||
* @return mime值,譬如text/html
|
||||
*/
|
||||
const string &getHttpContentType(const char *name);
|
||||
const std::string &getHttpContentType(const char *name);
|
||||
|
||||
}//mediakit
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#endif
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
void HttpCookie::setPath(const string &path){
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -31,19 +30,19 @@ public:
|
||||
HttpCookie(){}
|
||||
~HttpCookie(){}
|
||||
|
||||
void setPath(const string &path);
|
||||
void setHost(const string &host);
|
||||
void setExpires(const string &expires,const string &server_date);
|
||||
void setKeyVal(const string &key,const string &val);
|
||||
void setPath(const std::string &path);
|
||||
void setHost(const std::string &host);
|
||||
void setExpires(const std::string &expires,const std::string &server_date);
|
||||
void setKeyVal(const std::string &key,const std::string &val);
|
||||
operator bool ();
|
||||
|
||||
const string &getKey() const ;
|
||||
const string &getVal() const ;
|
||||
const std::string &getKey() const ;
|
||||
const std::string &getVal() const ;
|
||||
private:
|
||||
string _host;
|
||||
string _path = "/";
|
||||
string _key;
|
||||
string _val;
|
||||
std::string _host;
|
||||
std::string _path = "/";
|
||||
std::string _key;
|
||||
std::string _val;
|
||||
time_t _expire = 0;
|
||||
};
|
||||
|
||||
@@ -56,12 +55,12 @@ public:
|
||||
~HttpCookieStorage(){}
|
||||
static HttpCookieStorage &Instance();
|
||||
void set(const HttpCookie::Ptr &cookie);
|
||||
vector<HttpCookie::Ptr> get(const string &host,const string &path);
|
||||
std::vector<HttpCookie::Ptr> get(const std::string &host,const std::string &path);
|
||||
private:
|
||||
HttpCookieStorage(){};
|
||||
private:
|
||||
unordered_map<string/*host*/,map<string/*cookie path*/,map<string/*cookie_key*/,HttpCookie::Ptr> > > _all_cookie;
|
||||
mutex _mtx_cookie;
|
||||
std::unordered_map<std::string/*host*/, std::map<std::string/*cookie path*/,std::map<std::string/*cookie_key*/, HttpCookie::Ptr> > > _all_cookie;
|
||||
std::mutex _mtx_cookie;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include "Common/config.h"
|
||||
#include "HttpCookieManager.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
//////////////////////////////HttpServerCookie////////////////////////////////////
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
#include "Network/Socket.h"
|
||||
#include "Common/Parser.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
#define COOKIE_DEFAULT_LIFE (7 * 24 * 60 * 60)
|
||||
|
||||
namespace mediakit {
|
||||
@@ -32,7 +28,7 @@ class HttpCookieManager;
|
||||
/**
|
||||
* cookie对象,用于保存cookie的一些相关属性
|
||||
*/
|
||||
class HttpServerCookie : public AnyStorage , public noncopyable{
|
||||
class HttpServerCookie : public toolkit::AnyStorage , public toolkit::noncopyable{
|
||||
public:
|
||||
typedef std::shared_ptr<HttpServerCookie> Ptr;
|
||||
/**
|
||||
@@ -45,9 +41,9 @@ public:
|
||||
*/
|
||||
|
||||
HttpServerCookie(const std::shared_ptr<HttpCookieManager> &manager,
|
||||
const string &cookie_name,
|
||||
const string &uid,
|
||||
const string &cookie,
|
||||
const std::string &cookie_name,
|
||||
const std::string &uid,
|
||||
const std::string &cookie,
|
||||
uint64_t max_elapsed);
|
||||
~HttpServerCookie() ;
|
||||
|
||||
@@ -55,7 +51,7 @@ public:
|
||||
* 获取uid
|
||||
* @return uid
|
||||
*/
|
||||
const string &getUid() const;
|
||||
const std::string &getUid() const;
|
||||
|
||||
/**
|
||||
* 获取http中Set-Cookie字段的值
|
||||
@@ -63,19 +59,19 @@ public:
|
||||
* @param path http访问路径
|
||||
* @return 例如 MY_SESSION=XXXXXX;expires=Wed, Jun 12 2019 06:30:48 GMT;path=/index/files/
|
||||
*/
|
||||
string getCookie(const string &path) const;
|
||||
std::string getCookie(const std::string &path) const;
|
||||
|
||||
/**
|
||||
* 获取cookie随机字符串
|
||||
* @return cookie随机字符串
|
||||
*/
|
||||
const string& getCookie() const;
|
||||
const std::string& getCookie() const;
|
||||
|
||||
/**
|
||||
* 获取该cookie名
|
||||
* @return
|
||||
*/
|
||||
const string& getCookieName() const;
|
||||
const std::string& getCookieName() const;
|
||||
|
||||
/**
|
||||
* 更新该cookie的过期时间,可以让此cookie不失效
|
||||
@@ -92,16 +88,16 @@ public:
|
||||
* 获取区域锁
|
||||
* @return
|
||||
*/
|
||||
std::shared_ptr<lock_guard<recursive_mutex> > getLock();
|
||||
std::shared_ptr<std::lock_guard<std::recursive_mutex> > getLock();
|
||||
private:
|
||||
string cookieExpireTime() const ;
|
||||
std::string cookieExpireTime() const ;
|
||||
private:
|
||||
string _uid;
|
||||
string _cookie_name;
|
||||
string _cookie_uuid;
|
||||
std::string _uid;
|
||||
std::string _cookie_name;
|
||||
std::string _cookie_uuid;
|
||||
uint64_t _max_elapsed;
|
||||
Ticker _ticker;
|
||||
recursive_mutex _mtx;
|
||||
toolkit::Ticker _ticker;
|
||||
std::recursive_mutex _mtx;
|
||||
std::weak_ptr<HttpCookieManager> _manager;
|
||||
};
|
||||
|
||||
@@ -117,18 +113,18 @@ public:
|
||||
* 获取不碰撞的随机字符串
|
||||
* @return 随机字符串
|
||||
*/
|
||||
string obtain();
|
||||
std::string obtain();
|
||||
|
||||
/**
|
||||
* 释放随机字符串
|
||||
* @param str 随机字符串
|
||||
*/
|
||||
void release(const string &str);
|
||||
void release(const std::string &str);
|
||||
private:
|
||||
string obtain_l();
|
||||
std::string obtain_l();
|
||||
private:
|
||||
//碰撞库
|
||||
unordered_set<string> _obtained;
|
||||
std::unordered_set<std::string> _obtained;
|
||||
//增长index,防止碰撞用
|
||||
int _index = 0;
|
||||
};
|
||||
@@ -156,7 +152,7 @@ public:
|
||||
* @param max_elapsed 该cookie过期时间,单位秒
|
||||
* @return cookie对象
|
||||
*/
|
||||
HttpServerCookie::Ptr addCookie(const string &cookie_name,const string &uid, uint64_t max_elapsed = COOKIE_DEFAULT_LIFE,int max_client = 1);
|
||||
HttpServerCookie::Ptr addCookie(const std::string &cookie_name,const std::string &uid, uint64_t max_elapsed = COOKIE_DEFAULT_LIFE,int max_client = 1);
|
||||
|
||||
/**
|
||||
* 根据cookie随机字符串查找cookie对象
|
||||
@@ -164,7 +160,7 @@ public:
|
||||
* @param cookie cookie随机字符串
|
||||
* @return cookie对象,可以为nullptr
|
||||
*/
|
||||
HttpServerCookie::Ptr getCookie(const string &cookie_name,const string &cookie);
|
||||
HttpServerCookie::Ptr getCookie(const std::string &cookie_name,const std::string &cookie);
|
||||
|
||||
/**
|
||||
* 从http头中获取cookie对象
|
||||
@@ -172,7 +168,7 @@ public:
|
||||
* @param http_header http头
|
||||
* @return cookie对象
|
||||
*/
|
||||
HttpServerCookie::Ptr getCookie(const string &cookie_name,const StrCaseMap &http_header);
|
||||
HttpServerCookie::Ptr getCookie(const std::string &cookie_name,const StrCaseMap &http_header);
|
||||
|
||||
/**
|
||||
* 根据uid获取cookie
|
||||
@@ -180,7 +176,7 @@ public:
|
||||
* @param uid 用户id
|
||||
* @return cookie对象
|
||||
*/
|
||||
HttpServerCookie::Ptr getCookieByUid(const string &cookie_name,const string &uid);
|
||||
HttpServerCookie::Ptr getCookieByUid(const std::string &cookie_name,const std::string &uid);
|
||||
|
||||
/**
|
||||
* 删除cookie,用户登出时使用
|
||||
@@ -197,7 +193,7 @@ private:
|
||||
* @param uid 用户id
|
||||
* @param cookie cookie随机字符串
|
||||
*/
|
||||
void onAddCookie(const string &cookie_name,const string &uid,const string &cookie);
|
||||
void onAddCookie(const std::string &cookie_name,const std::string &uid,const std::string &cookie);
|
||||
|
||||
/**
|
||||
* 析构cookie对象时触发
|
||||
@@ -205,7 +201,7 @@ private:
|
||||
* @param uid 用户id
|
||||
* @param cookie cookie随机字符串
|
||||
*/
|
||||
void onDelCookie(const string &cookie_name,const string &uid,const string &cookie);
|
||||
void onDelCookie(const std::string &cookie_name,const std::string &uid,const std::string &cookie);
|
||||
|
||||
/**
|
||||
* 获取某用户名下最先登录时的cookie,目的是实现某用户下最多登录若干个设备
|
||||
@@ -214,7 +210,7 @@ private:
|
||||
* @param max_client 最多登录的设备个数
|
||||
* @return 最早的cookie随机字符串
|
||||
*/
|
||||
string getOldestCookie(const string &cookie_name,const string &uid, int max_client = 1);
|
||||
std::string getOldestCookie(const std::string &cookie_name,const std::string &uid, int max_client = 1);
|
||||
|
||||
/**
|
||||
* 删除cookie
|
||||
@@ -222,12 +218,12 @@ private:
|
||||
* @param cookie cookie随机字符串
|
||||
* @return 成功true
|
||||
*/
|
||||
bool delCookie(const string &cookie_name,const string &cookie);
|
||||
bool delCookie(const std::string &cookie_name,const std::string &cookie);
|
||||
private:
|
||||
unordered_map<string/*cookie_name*/,unordered_map<string/*cookie*/,HttpServerCookie::Ptr/*cookie_data*/> >_map_cookie;
|
||||
unordered_map<string/*cookie_name*/,unordered_map<string/*uid*/,map<uint64_t/*cookie time stamp*/,string/*cookie*/> > >_map_uid_to_cookie;
|
||||
recursive_mutex _mtx_cookie;
|
||||
Timer::Ptr _timer;
|
||||
std::unordered_map<std::string/*cookie_name*/,std::unordered_map<std::string/*cookie*/,HttpServerCookie::Ptr/*cookie_data*/> >_map_cookie;
|
||||
std::unordered_map<std::string/*cookie_name*/,std::unordered_map<std::string/*uid*/,std::map<uint64_t/*cookie time stamp*/,std::string/*cookie*/> > >_map_uid_to_cookie;
|
||||
std::recursive_mutex _mtx_cookie;
|
||||
toolkit::Timer::Ptr _timer;
|
||||
RandStrGeneator _geneator;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "Util/File.h"
|
||||
#include "Util/MD5.h"
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace mediakit {
|
||||
class HttpDownloader : public HttpClientImp {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<HttpDownloader>;
|
||||
using onDownloadResult = std::function<void(const SockException &ex, const string &filePath)>;
|
||||
using onDownloadResult = std::function<void(const toolkit::SockException &ex, const std::string &filePath)>;
|
||||
|
||||
HttpDownloader() = default;
|
||||
~HttpDownloader() override;
|
||||
@@ -29,9 +29,9 @@ public:
|
||||
* @param file_path 文件保存地址,置空则选择默认文件路径
|
||||
* @param append 如果文件已经存在,是否断点续传方式下载
|
||||
*/
|
||||
void startDownload(const string &url, const string &file_path = "", bool append = false);
|
||||
void startDownload(const std::string &url, const std::string &file_path = "", bool append = false);
|
||||
|
||||
void startDownload(const string &url, const onDownloadResult &cb) {
|
||||
void startDownload(const std::string &url, const onDownloadResult &cb) {
|
||||
setOnResult(cb);
|
||||
startDownload(url, "", false);
|
||||
}
|
||||
@@ -40,15 +40,15 @@ public:
|
||||
|
||||
protected:
|
||||
void onResponseBody(const char *buf, size_t size) override;
|
||||
void onResponseHeader(const string &status, const HttpHeader &headers) override;
|
||||
void onResponseCompleted(const SockException &ex) override;
|
||||
void onResponseHeader(const std::string &status, const HttpHeader &headers) override;
|
||||
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||
|
||||
private:
|
||||
void closeFile();
|
||||
|
||||
private:
|
||||
FILE *_save_file = nullptr;
|
||||
string _file_path;
|
||||
std::string _file_path;
|
||||
onDownloadResult _on_result;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#include "Record/HlsMediaSource.h"
|
||||
#include "Common/Parser.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
// hls的播放cookie缓存时间默认60秒,
|
||||
|
||||
@@ -22,20 +22,20 @@ namespace mediakit {
|
||||
class HttpResponseInvokerImp{
|
||||
public:
|
||||
typedef std::function<void(int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body)> HttpResponseInvokerLambda0;
|
||||
typedef std::function<void(int code, const StrCaseMap &headerOut, const string &body)> HttpResponseInvokerLambda1;
|
||||
typedef std::function<void(int code, const StrCaseMap &headerOut, const std::string &body)> HttpResponseInvokerLambda1;
|
||||
|
||||
HttpResponseInvokerImp(){}
|
||||
~HttpResponseInvokerImp(){}
|
||||
template<typename C>
|
||||
HttpResponseInvokerImp(const C &c):HttpResponseInvokerImp(typename function_traits<C>::stl_function_type(c)) {}
|
||||
HttpResponseInvokerImp(const C &c):HttpResponseInvokerImp(typename toolkit::function_traits<C>::stl_function_type(c)) {}
|
||||
HttpResponseInvokerImp(const HttpResponseInvokerLambda0 &lambda);
|
||||
HttpResponseInvokerImp(const HttpResponseInvokerLambda1 &lambda);
|
||||
|
||||
void operator()(int code, const StrCaseMap &headerOut, const Buffer::Ptr &body) const;
|
||||
void operator()(int code, const StrCaseMap &headerOut, const toolkit::Buffer::Ptr &body) const;
|
||||
void operator()(int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body) const;
|
||||
void operator()(int code, const StrCaseMap &headerOut, const string &body) const;
|
||||
void operator()(int code, const StrCaseMap &headerOut, const std::string &body) const;
|
||||
|
||||
void responseFile(const StrCaseMap &requestHeader,const StrCaseMap &responseHeader,const string &filePath, bool use_mmap = true) const;
|
||||
void responseFile(const StrCaseMap &requestHeader,const StrCaseMap &responseHeader,const std::string &filePath, bool use_mmap = true) const;
|
||||
operator bool();
|
||||
private:
|
||||
HttpResponseInvokerLambda0 _lambad;
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
*/
|
||||
class HttpFileManager {
|
||||
public:
|
||||
typedef function<void(int code, const string &content_type, const StrCaseMap &responseHeader, const HttpBody::Ptr &body)> invoker;
|
||||
typedef std::function<void(int code, const std::string &content_type, const StrCaseMap &responseHeader, const HttpBody::Ptr &body)> invoker;
|
||||
|
||||
/**
|
||||
* 访问文件或文件夹
|
||||
@@ -54,14 +54,14 @@ public:
|
||||
* @param parser http请求
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
static void onAccessPath(TcpSession &sender, Parser &parser, const invoker &cb);
|
||||
static void onAccessPath(toolkit::TcpSession &sender, Parser &parser, const invoker &cb);
|
||||
|
||||
/**
|
||||
* 获取mime值
|
||||
* @param name 文件后缀
|
||||
* @return mime值
|
||||
*/
|
||||
static const string &getContentType(const char *name);
|
||||
static const std::string &getContentType(const char *name);
|
||||
private:
|
||||
HttpFileManager() = delete;
|
||||
~HttpFileManager() = delete;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "Util/logger.h"
|
||||
#include "Util/util.h"
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
//协议解析最大缓存1兆数据
|
||||
static constexpr size_t kMaxCacheSize = 1 * 1024 * 1024;
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
|
||||
#include <string>
|
||||
#include "Network/Buffer.h"
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -83,7 +81,7 @@ protected:
|
||||
private:
|
||||
ssize_t _content_len = 0;
|
||||
size_t _remain_data_size = 0;
|
||||
BufferLikeString _remain_data;
|
||||
toolkit::BufferLikeString _remain_data;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "HttpRequester.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
void HttpRequester::onResponseHeader(const string &status, const HttpHeader &headers) {
|
||||
|
||||
@@ -18,22 +18,22 @@ namespace mediakit {
|
||||
class HttpRequester : public HttpClientImp {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<HttpRequester>;
|
||||
using HttpRequesterResult = std::function<void(const SockException &ex, const Parser &response)>;
|
||||
using HttpRequesterResult = std::function<void(const toolkit::SockException &ex, const Parser &response)>;
|
||||
|
||||
HttpRequester() = default;
|
||||
~HttpRequester() override = default;
|
||||
|
||||
void setOnResult(const HttpRequesterResult &onResult);
|
||||
void startRequester(const string &url, const HttpRequesterResult &on_result, float timeout_sec = 10);
|
||||
void startRequester(const std::string &url, const HttpRequesterResult &on_result, float timeout_sec = 10);
|
||||
void clear() override;
|
||||
|
||||
private:
|
||||
void onResponseHeader(const string &status, const HttpHeader &headers) override;
|
||||
void onResponseHeader(const std::string &status, const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf, size_t size) override;
|
||||
void onResponseCompleted(const SockException &ex) override;
|
||||
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||
|
||||
private:
|
||||
string _res_body;
|
||||
std::string _res_body;
|
||||
HttpRequesterResult _on_result;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "HttpConst.h"
|
||||
#include "Util/base64.h"
|
||||
#include "Util/SHA1.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -22,12 +22,9 @@
|
||||
#include "TS/TSMediaSource.h"
|
||||
#include "FMP4/FMP4MediaSource.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HttpSession: public TcpSession,
|
||||
class HttpSession: public toolkit::TcpSession,
|
||||
public FlvMuxer,
|
||||
public HttpRequestSplitter,
|
||||
public WebSocketSplitter {
|
||||
@@ -40,19 +37,19 @@ public:
|
||||
* @param accessPath 运行或禁止访问的根目录
|
||||
* @param cookieLifeSecond 鉴权cookie有效期
|
||||
**/
|
||||
typedef std::function<void(const string &errMsg,const string &accessPath, int cookieLifeSecond)> HttpAccessPathInvoker;
|
||||
typedef std::function<void(const std::string &errMsg,const std::string &accessPath, int cookieLifeSecond)> HttpAccessPathInvoker;
|
||||
|
||||
HttpSession(const Socket::Ptr &pSock);
|
||||
HttpSession(const toolkit::Socket::Ptr &pSock);
|
||||
~HttpSession() override;
|
||||
|
||||
void onRecv(const Buffer::Ptr &) override;
|
||||
void onError(const SockException &err) override;
|
||||
void onRecv(const toolkit::Buffer::Ptr &) override;
|
||||
void onError(const toolkit::SockException &err) override;
|
||||
void onManager() override;
|
||||
static string urlDecode(const string &str);
|
||||
static std::string urlDecode(const std::string &str);
|
||||
|
||||
protected:
|
||||
//FlvMuxer override
|
||||
void onWrite(const Buffer::Ptr &data, bool flush) override ;
|
||||
void onWrite(const toolkit::Buffer::Ptr &data, bool flush) override ;
|
||||
void onDetach() override;
|
||||
std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
||||
|
||||
@@ -74,7 +71,7 @@ protected:
|
||||
size_t len,
|
||||
size_t totalSize,
|
||||
size_t recvedSize){
|
||||
shutdown(SockException(Err_shutdown,"http post content is too huge,default closed"));
|
||||
shutdown(toolkit::SockException(toolkit::Err_shutdown,"http post content is too huge,default closed"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +89,7 @@ protected:
|
||||
* 发送数据进行websocket协议打包后回调
|
||||
* @param buffer websocket协议数据
|
||||
*/
|
||||
void onWebSocketEncodeData(Buffer::Ptr buffer) override;
|
||||
void onWebSocketEncodeData(toolkit::Buffer::Ptr buffer) override;
|
||||
|
||||
/**
|
||||
* 接收到完整的一个webSocket数据包后回调
|
||||
@@ -107,11 +104,11 @@ private:
|
||||
void Handle_Req_HEAD(ssize_t &content_len);
|
||||
void Handle_Req_OPTIONS(ssize_t &content_len);
|
||||
|
||||
bool checkLiveStream(const string &schema, const string &url_suffix, const function<void(const MediaSource::Ptr &src)> &cb);
|
||||
bool checkLiveStream(const std::string &schema, const std::string &url_suffix, const std::function<void(const MediaSource::Ptr &src)> &cb);
|
||||
|
||||
bool checkLiveStreamFlv(const function<void()> &cb = nullptr);
|
||||
bool checkLiveStreamTS(const function<void()> &cb = nullptr);
|
||||
bool checkLiveStreamFMP4(const function<void()> &fmp4_list = nullptr);
|
||||
bool checkLiveStreamFlv(const std::function<void()> &cb = nullptr);
|
||||
bool checkLiveStreamTS(const std::function<void()> &cb = nullptr);
|
||||
bool checkLiveStreamFMP4(const std::function<void()> &fmp4_list = nullptr);
|
||||
|
||||
bool checkWebSocket();
|
||||
bool emitHttpEvent(bool doInvoke);
|
||||
@@ -129,18 +126,17 @@ private:
|
||||
bool _live_over_websocket = false;
|
||||
//消耗的总流量
|
||||
uint64_t _total_bytes_usage = 0;
|
||||
string _origin;
|
||||
std::string _origin;
|
||||
Parser _parser;
|
||||
Ticker _ticker;
|
||||
toolkit::Ticker _ticker;
|
||||
MediaInfo _mediaInfo;
|
||||
TSMediaSource::RingType::RingReader::Ptr _ts_reader;
|
||||
FMP4MediaSource::RingType::RingReader::Ptr _fmp4_reader;
|
||||
//处理content数据的callback
|
||||
function<bool (const char *data,size_t len) > _contentCallBack;
|
||||
std::function<bool (const char *data,size_t len) > _contentCallBack;
|
||||
};
|
||||
|
||||
|
||||
typedef TcpSessionWithSSL<HttpSession> HttpsSession;
|
||||
using HttpsSession = toolkit::TcpSessionWithSSL<HttpSession>;
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "HttpTSPlayer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts) {
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
#include "Player/MediaPlayer.h"
|
||||
#include "Rtp/TSDecoder.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
//http-ts播发器,未实现ts解复用
|
||||
class HttpTSPlayer : public HttpClientImp {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<HttpTSPlayer>;
|
||||
using onComplete = std::function<void(const SockException &)>;
|
||||
using onComplete = std::function<void(const toolkit::SockException &)>;
|
||||
|
||||
HttpTSPlayer(const EventPoller::Ptr &poller = nullptr, bool split_ts = true);
|
||||
HttpTSPlayer(const toolkit::EventPoller::Ptr &poller = nullptr, bool split_ts = true);
|
||||
~HttpTSPlayer() override = default;
|
||||
|
||||
/**
|
||||
@@ -40,9 +38,9 @@ public:
|
||||
|
||||
protected:
|
||||
///HttpClient override///
|
||||
void onResponseHeader(const string &status, const HttpHeader &header) override;
|
||||
void onResponseHeader(const std::string &status, const HttpHeader &header) override;
|
||||
void onResponseBody(const char *buf, size_t size) override;
|
||||
void onResponseCompleted(const SockException &ex) override;
|
||||
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -51,7 +49,7 @@ protected:
|
||||
virtual void onPacket(const char *data, size_t len);
|
||||
|
||||
private:
|
||||
void emitOnComplete(const SockException &ex);
|
||||
void emitOnComplete(const toolkit::SockException &ex);
|
||||
|
||||
private:
|
||||
bool _split_ts;
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "TsPlayer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {}
|
||||
|
||||
@@ -14,18 +14,17 @@
|
||||
#include "HttpTSPlayer.h"
|
||||
#include "Player/PlayerBase.h"
|
||||
|
||||
using namespace toolkit;
|
||||
namespace mediakit {
|
||||
|
||||
class TsPlayer : public HttpTSPlayer , public PlayerBase {
|
||||
public:
|
||||
TsPlayer(const EventPoller::Ptr &poller);
|
||||
TsPlayer(const toolkit::EventPoller::Ptr &poller);
|
||||
~TsPlayer() override = default;
|
||||
|
||||
/**
|
||||
* 开始播放
|
||||
*/
|
||||
void play(const string &url) override;
|
||||
void play(const std::string &url) override;
|
||||
|
||||
/**
|
||||
* 停止播放
|
||||
@@ -34,7 +33,7 @@ public:
|
||||
|
||||
protected:
|
||||
void onResponseBody(const char *buf, size_t size) override;
|
||||
void onResponseCompleted(const SockException &ex) override;
|
||||
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||
|
||||
private:
|
||||
bool _play_result = true;
|
||||
|
||||
@@ -14,15 +14,13 @@
|
||||
#include <unordered_set>
|
||||
#include "TsPlayer.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class TsPlayerImp : public PlayerImp<TsPlayer, PlayerBase>, private TrackListener {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<TsPlayerImp>;
|
||||
|
||||
TsPlayerImp(const EventPoller::Ptr &poller = nullptr);
|
||||
TsPlayerImp(const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||
~TsPlayerImp() override = default;
|
||||
|
||||
private:
|
||||
@@ -31,9 +29,9 @@ private:
|
||||
|
||||
private:
|
||||
//// PlayerBase override////
|
||||
void onPlayResult(const SockException &ex) override;
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||
void onShutdown(const SockException &ex) override;
|
||||
void onPlayResult(const toolkit::SockException &ex) override;
|
||||
std::vector<Track::Ptr> getTracks(bool ready = true) const override;
|
||||
void onShutdown(const toolkit::SockException &ex) override;
|
||||
|
||||
private:
|
||||
//// TrackListener override////
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include "TsPlayerImp.h"
|
||||
#include "HlsPlayer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
TsPlayerImp::TsPlayerImp(const EventPoller::Ptr &poller) : PlayerImp<TsPlayer, PlayerBase>(poller) {}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "Network/TcpClient.h"
|
||||
#include "HttpClientImp.h"
|
||||
#include "WebSocketSplitter.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
@@ -32,8 +31,9 @@ class HttpWsClient;
|
||||
template <typename ClientType,WebSocketHeader::Type DataType>
|
||||
class ClientTypeImp : public ClientType {
|
||||
public:
|
||||
typedef function<ssize_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
friend class HttpWsClient<ClientType,DataType>;
|
||||
friend class HttpWsClient<ClientType, DataType>;
|
||||
|
||||
using onBeforeSendCB = std::function<ssize_t(const toolkit::Buffer::Ptr &buf)>;
|
||||
|
||||
template<typename ...ArgsType>
|
||||
ClientTypeImp(ArgsType &&...args): ClientType(std::forward<ArgsType>(args)...){}
|
||||
@@ -43,7 +43,7 @@ protected:
|
||||
/**
|
||||
* 发送前拦截并打包为websocket协议
|
||||
*/
|
||||
ssize_t send(Buffer::Ptr buf) override{
|
||||
ssize_t send(toolkit::Buffer::Ptr buf) override{
|
||||
if(_beforeSendCB){
|
||||
return _beforeSendCB(buf);
|
||||
}
|
||||
@@ -70,11 +70,11 @@ private:
|
||||
template <typename ClientType,WebSocketHeader::Type DataType = WebSocketHeader::TEXT>
|
||||
class HttpWsClient : public HttpClientImp , public WebSocketSplitter{
|
||||
public:
|
||||
typedef shared_ptr<HttpWsClient> Ptr;
|
||||
typedef std::shared_ptr<HttpWsClient> Ptr;
|
||||
|
||||
HttpWsClient(const std::shared_ptr<ClientTypeImp<ClientType, DataType> > &delegate) : _weak_delegate(delegate),
|
||||
_delegate(*delegate) {
|
||||
_Sec_WebSocket_Key = encodeBase64(makeRandStr(16, false));
|
||||
_Sec_WebSocket_Key = encodeBase64(toolkit::makeRandStr(16, false));
|
||||
setPoller(_delegate.getPoller());
|
||||
}
|
||||
~HttpWsClient(){}
|
||||
@@ -84,10 +84,10 @@ public:
|
||||
* @param ws_url ws连接url
|
||||
* @param fTimeOutSec 超时时间
|
||||
*/
|
||||
void startWsClient(const string &ws_url, float fTimeOutSec) {
|
||||
string http_url = ws_url;
|
||||
replace(http_url, "ws://", "http://");
|
||||
replace(http_url, "wss://", "https://");
|
||||
void startWsClient(const std::string &ws_url, float fTimeOutSec) {
|
||||
std::string http_url = ws_url;
|
||||
toolkit::replace(http_url, "ws://", "http://");
|
||||
toolkit::replace(http_url, "wss://", "https://");
|
||||
setMethod("GET");
|
||||
addHeader("Upgrade", "websocket");
|
||||
addHeader("Connection", "Upgrade");
|
||||
@@ -120,27 +120,27 @@ protected:
|
||||
* @param status 状态码,譬如:200 OK
|
||||
* @param headers http头
|
||||
*/
|
||||
void onResponseHeader(const string &status,const HttpHeader &headers) override {
|
||||
void onResponseHeader(const std::string &status, const HttpHeader &headers) override {
|
||||
if(status == "101"){
|
||||
auto Sec_WebSocket_Accept = encodeBase64(SHA1::encode_bin(_Sec_WebSocket_Key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
|
||||
auto Sec_WebSocket_Accept = encodeBase64(toolkit::SHA1::encode_bin(_Sec_WebSocket_Key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
|
||||
if(Sec_WebSocket_Accept == const_cast<HttpHeader &>(headers)["Sec-WebSocket-Accept"]){
|
||||
//success
|
||||
onWebSocketException(SockException());
|
||||
onWebSocketException(toolkit::SockException());
|
||||
//防止ws服务器返回Content-Length
|
||||
const_cast<HttpHeader &>(headers).erase("Content-Length");
|
||||
return;
|
||||
}
|
||||
shutdown(SockException(Err_shutdown, StrPrinter << "Sec-WebSocket-Accept mismatch"));
|
||||
shutdown(toolkit::SockException(toolkit::Err_shutdown, StrPrinter << "Sec-WebSocket-Accept mismatch"));
|
||||
return;
|
||||
}
|
||||
|
||||
shutdown(SockException(Err_shutdown,StrPrinter << "bad http status code:" << status));
|
||||
shutdown(toolkit::SockException(toolkit::Err_shutdown,StrPrinter << "bad http status code:" << status));
|
||||
};
|
||||
|
||||
/**
|
||||
* 接收http回复完毕,
|
||||
*/
|
||||
void onResponseCompleted(const SockException &ex) override {}
|
||||
void onResponseCompleted(const toolkit::SockException &ex) override {}
|
||||
|
||||
/**
|
||||
* 接收websocket负载数据
|
||||
@@ -154,7 +154,7 @@ protected:
|
||||
|
||||
//TcpClient override
|
||||
|
||||
void onRecv(const Buffer::Ptr &buf) override {
|
||||
void onRecv(const toolkit::Buffer::Ptr &buf) override {
|
||||
auto strong_ref = _weak_delegate.lock();;
|
||||
HttpClientImp::onRecv(buf);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ protected:
|
||||
/**
|
||||
* tcp连接结果
|
||||
*/
|
||||
void onConnect(const SockException &ex) override {
|
||||
void onConnect(const toolkit::SockException &ex) override {
|
||||
auto strong_ref = _weak_delegate.lock();;
|
||||
if (ex) {
|
||||
//tcp连接失败,直接返回失败
|
||||
@@ -204,7 +204,7 @@ protected:
|
||||
/**
|
||||
* tcp连接断开
|
||||
*/
|
||||
void onErr(const SockException &ex) override {
|
||||
void onErr(const toolkit::SockException &ex) override {
|
||||
auto strong_ref = _weak_delegate.lock();;
|
||||
//tcp断开或者shutdown导致的断开
|
||||
onWebSocketException(ex);
|
||||
@@ -245,14 +245,14 @@ protected:
|
||||
case WebSocketHeader::CLOSE:{
|
||||
//服务器主动关闭
|
||||
WebSocketSplitter::encode(header,nullptr);
|
||||
shutdown(SockException(Err_eof,"websocket server close the connection"));
|
||||
shutdown(toolkit::SockException(toolkit::Err_eof,"websocket server close the connection"));
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketHeader::PING:{
|
||||
//心跳包
|
||||
header._opcode = WebSocketHeader::PONG;
|
||||
WebSocketSplitter::encode(header,std::make_shared<BufferString>(std::move(_payload_section)));
|
||||
WebSocketSplitter::encode(header,std::make_shared<toolkit::BufferString>(std::move(_payload_section)));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -294,17 +294,17 @@ protected:
|
||||
* @param ptr 数据指针
|
||||
* @param len 数据指针长度
|
||||
*/
|
||||
void onWebSocketEncodeData(Buffer::Ptr buffer) override{
|
||||
void onWebSocketEncodeData(toolkit::Buffer::Ptr buffer) override{
|
||||
HttpClientImp::send(std::move(buffer));
|
||||
}
|
||||
|
||||
private:
|
||||
void onWebSocketException(const SockException &ex){
|
||||
void onWebSocketException(const toolkit::SockException &ex){
|
||||
if(!ex){
|
||||
//websocket握手成功
|
||||
//此处截取TcpClient派生类发送的数据并进行websocket协议打包
|
||||
weak_ptr<HttpWsClient> weakSelf = dynamic_pointer_cast<HttpWsClient>(shared_from_this());
|
||||
_delegate.setOnBeforeSendCB([weakSelf](const Buffer::Ptr &buf){
|
||||
std::weak_ptr<HttpWsClient> weakSelf = std::dynamic_pointer_cast<HttpWsClient>(shared_from_this());
|
||||
_delegate.setOnBeforeSendCB([weakSelf](const toolkit::Buffer::Ptr &buf){
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if(strongSelf){
|
||||
WebSocketHeader header;
|
||||
@@ -343,12 +343,12 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
string _Sec_WebSocket_Key;
|
||||
function<void(const char *data, size_t len)> _onRecv;
|
||||
weak_ptr<ClientTypeImp<ClientType,DataType> > _weak_delegate;
|
||||
ClientTypeImp<ClientType,DataType> &_delegate;
|
||||
string _payload_section;
|
||||
string _payload_cache;
|
||||
std::string _Sec_WebSocket_Key;
|
||||
std::function<void(const char *data, size_t len)> _onRecv;
|
||||
std::weak_ptr<ClientTypeImp<ClientType, DataType>> _weak_delegate;
|
||||
ClientTypeImp<ClientType, DataType> &_delegate;
|
||||
std::string _payload_section;
|
||||
std::string _payload_cache;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -378,8 +378,8 @@ public:
|
||||
* @param timeout_sec 超时时间
|
||||
* @param local_port 本地监听端口,此处不起作用
|
||||
*/
|
||||
void startConnect(const string &host, uint16_t port, float timeout_sec = 3, uint16_t local_port = 0) override {
|
||||
string ws_url;
|
||||
void startConnect(const std::string &host, uint16_t port, float timeout_sec = 3, uint16_t local_port = 0) override {
|
||||
std::string ws_url;
|
||||
if (useWSS) {
|
||||
//加密的ws
|
||||
ws_url = StrPrinter << "wss://" + host << ":" << port << "/";
|
||||
@@ -390,9 +390,9 @@ public:
|
||||
startWebSocket(ws_url, timeout_sec);
|
||||
}
|
||||
|
||||
void startWebSocket(const string &ws_url,float fTimeOutSec = 3){
|
||||
_wsClient = std::make_shared<HttpWsClient<ClientType,DataType> >(static_pointer_cast<WebSocketClient>(this->shared_from_this()));
|
||||
_wsClient->setOnCreateSocket([this](const EventPoller::Ptr &){
|
||||
void startWebSocket(const std::string &ws_url, float fTimeOutSec = 3) {
|
||||
_wsClient = std::make_shared<HttpWsClient<ClientType, DataType> >(std::static_pointer_cast<WebSocketClient>(this->shared_from_this()));
|
||||
_wsClient->setOnCreateSocket([this](const toolkit::EventPoller::Ptr &){
|
||||
return this->createSocket();
|
||||
});
|
||||
_wsClient->startWsClient(ws_url,fTimeOutSec);
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
*/
|
||||
class SendInterceptor{
|
||||
public:
|
||||
typedef function<ssize_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
using onBeforeSendCB =std::function<ssize_t (const toolkit::Buffer::Ptr &buf)>;
|
||||
|
||||
SendInterceptor() = default;
|
||||
virtual ~SendInterceptor() = default;
|
||||
virtual void setOnBeforeSendCB(const onBeforeSendCB &cb) = 0;
|
||||
@@ -34,7 +35,7 @@ class TcpSessionTypeImp : public TcpSessionType, public SendInterceptor{
|
||||
public:
|
||||
typedef std::shared_ptr<TcpSessionTypeImp> Ptr;
|
||||
|
||||
TcpSessionTypeImp(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) :
|
||||
TcpSessionTypeImp(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock) :
|
||||
TcpSessionType(pSock), _identifier(parent.getIdentifier()) {}
|
||||
|
||||
~TcpSessionTypeImp() {}
|
||||
@@ -53,19 +54,19 @@ protected:
|
||||
* @param buf 需要截取的数据
|
||||
* @return 数据字节数
|
||||
*/
|
||||
ssize_t send(Buffer::Ptr buf) override {
|
||||
ssize_t send(toolkit::Buffer::Ptr buf) override {
|
||||
if (_beforeSendCB) {
|
||||
return _beforeSendCB(buf);
|
||||
}
|
||||
return TcpSessionType::send(std::move(buf));
|
||||
}
|
||||
|
||||
string getIdentifier() const override {
|
||||
std::string getIdentifier() const override {
|
||||
return _identifier;
|
||||
}
|
||||
|
||||
private:
|
||||
string _identifier;
|
||||
std::string _identifier;
|
||||
onBeforeSendCB _beforeSendCB;
|
||||
};
|
||||
|
||||
@@ -73,7 +74,7 @@ template <typename TcpSessionType>
|
||||
class TcpSessionCreator {
|
||||
public:
|
||||
//返回的TcpSession必须派生于SendInterceptor,可以返回null
|
||||
TcpSession::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock){
|
||||
toolkit::TcpSession::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
|
||||
return std::make_shared<TcpSessionTypeImp<TcpSessionType> >(header,parent,pSock);
|
||||
}
|
||||
};
|
||||
@@ -82,14 +83,14 @@ public:
|
||||
* 通过该模板类可以透明化WebSocket协议,
|
||||
* 用户只要实现WebSock协议下的具体业务协议,譬如基于WebSocket协议的Rtmp协议等
|
||||
*/
|
||||
template<typename Creator, typename HttpSessionType = HttpSession, WebSocketHeader::Type DataType = WebSocketHeader::TEXT>
|
||||
template<typename Creator, typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
|
||||
class WebSocketSessionBase : public HttpSessionType {
|
||||
public:
|
||||
WebSocketSessionBase(const Socket::Ptr &pSock) : HttpSessionType(pSock){}
|
||||
WebSocketSessionBase(const toolkit::Socket::Ptr &pSock) : HttpSessionType(pSock){}
|
||||
virtual ~WebSocketSessionBase(){}
|
||||
|
||||
//收到eof或其他导致脱离TcpServer事件的回调
|
||||
void onError(const SockException &err) override{
|
||||
void onError(const toolkit::SockException &err) override{
|
||||
HttpSessionType::onError(err);
|
||||
if(_session){
|
||||
_session->onError(err);
|
||||
@@ -104,9 +105,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void attachServer(const Server &server) override{
|
||||
void attachServer(const toolkit::Server &server) override{
|
||||
HttpSessionType::attachServer(server);
|
||||
_weak_server = const_cast<Server &>(server).shared_from_this();
|
||||
_weak_server = const_cast<toolkit::Server &>(server).shared_from_this();
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -115,7 +116,7 @@ protected:
|
||||
* @param header http头
|
||||
* @return true代表允许websocket连接,否则拒绝
|
||||
*/
|
||||
bool onWebSocketConnect(const Parser &header) override{
|
||||
bool onWebSocketConnect(const mediakit::Parser &header) override{
|
||||
//创建websocket session类
|
||||
_session = _creator(header, *this,HttpSessionType::getSock());
|
||||
if(!_session){
|
||||
@@ -128,16 +129,16 @@ protected:
|
||||
}
|
||||
|
||||
//此处截取数据并进行websocket协议打包
|
||||
weak_ptr<WebSocketSessionBase> weakSelf = dynamic_pointer_cast<WebSocketSessionBase>(HttpSessionType::shared_from_this());
|
||||
dynamic_pointer_cast<SendInterceptor>(_session)->setOnBeforeSendCB([weakSelf](const Buffer::Ptr &buf) {
|
||||
std::weak_ptr<WebSocketSessionBase> weakSelf = std::dynamic_pointer_cast<WebSocketSessionBase>(HttpSessionType::shared_from_this());
|
||||
std::dynamic_pointer_cast<SendInterceptor>(_session)->setOnBeforeSendCB([weakSelf](const toolkit::Buffer::Ptr &buf) {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (strongSelf) {
|
||||
WebSocketHeader header;
|
||||
mediakit::WebSocketHeader header;
|
||||
header._fin = true;
|
||||
header._reserved = 0;
|
||||
header._opcode = DataType;
|
||||
header._mask_flag = false;
|
||||
strongSelf->WebSocketSplitter::encode(header, buf);
|
||||
strongSelf->HttpSessionType::encode(header, buf);
|
||||
}
|
||||
return buf->size();
|
||||
});
|
||||
@@ -149,7 +150,7 @@ protected:
|
||||
/**
|
||||
* 开始收到一个webSocket数据包
|
||||
*/
|
||||
void onWebSocketDecodeHeader(const WebSocketHeader &packet) override{
|
||||
void onWebSocketDecodeHeader(const mediakit::WebSocketHeader &packet) override{
|
||||
//新包,原来的包残余数据清空掉
|
||||
_payload_section.clear();
|
||||
}
|
||||
@@ -157,7 +158,7 @@ protected:
|
||||
/**
|
||||
* 收到websocket数据包负载
|
||||
*/
|
||||
void onWebSocketDecodePayload(const WebSocketHeader &packet,const uint8_t *ptr,size_t len,size_t recved) override {
|
||||
void onWebSocketDecodePayload(const mediakit::WebSocketHeader &packet,const uint8_t *ptr,size_t len,size_t recved) override {
|
||||
_payload_section.append((char *)ptr,len);
|
||||
}
|
||||
|
||||
@@ -165,27 +166,27 @@ protected:
|
||||
* 接收到完整的一个webSocket数据包后回调
|
||||
* @param header 数据包包头
|
||||
*/
|
||||
void onWebSocketDecodeComplete(const WebSocketHeader &header_in) override {
|
||||
WebSocketHeader& header = const_cast<WebSocketHeader&>(header_in);
|
||||
void onWebSocketDecodeComplete(const mediakit::WebSocketHeader &header_in) override {
|
||||
auto header = const_cast<mediakit::WebSocketHeader&>(header_in);
|
||||
auto flag = header._mask_flag;
|
||||
header._mask_flag = false;
|
||||
|
||||
switch (header._opcode){
|
||||
case WebSocketHeader::CLOSE:{
|
||||
case mediakit::WebSocketHeader::CLOSE:{
|
||||
HttpSessionType::encode(header,nullptr);
|
||||
HttpSessionType::shutdown(SockException(Err_shutdown, "recv close request from client"));
|
||||
HttpSessionType::shutdown(toolkit::SockException(toolkit::Err_shutdown, "recv close request from client"));
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketHeader::PING:{
|
||||
header._opcode = WebSocketHeader::PONG;
|
||||
HttpSessionType::encode(header,std::make_shared<BufferString>(_payload_section));
|
||||
case mediakit::WebSocketHeader::PING:{
|
||||
header._opcode = mediakit::WebSocketHeader::PONG;
|
||||
HttpSessionType::encode(header,std::make_shared<toolkit::BufferString>(_payload_section));
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketHeader::CONTINUATION:
|
||||
case WebSocketHeader::TEXT:
|
||||
case WebSocketHeader::BINARY:{
|
||||
case mediakit::WebSocketHeader::CONTINUATION:
|
||||
case mediakit::WebSocketHeader::TEXT:
|
||||
case mediakit::WebSocketHeader::BINARY:{
|
||||
if (!header._fin) {
|
||||
//还有后续分片数据, 我们先缓存数据,所有分片收集完成才一次性输出
|
||||
_payload_cache.append(std::move(_payload_section));
|
||||
@@ -199,13 +200,13 @@ protected:
|
||||
//最后一个包
|
||||
if (_payload_cache.empty()) {
|
||||
//这个包是唯一个分片
|
||||
_session->onRecv(std::make_shared<WebSocketBuffer>(header._opcode, header._fin, std::move(_payload_section)));
|
||||
_session->onRecv(std::make_shared<mediakit::WebSocketBuffer>(header._opcode, header._fin, std::move(_payload_section)));
|
||||
break;
|
||||
}
|
||||
|
||||
//这个包由多个分片组成
|
||||
_payload_cache.append(std::move(_payload_section));
|
||||
_session->onRecv(std::make_shared<WebSocketBuffer>(header._opcode, header._fin, std::move(_payload_cache)));
|
||||
_session->onRecv(std::make_shared<mediakit::WebSocketBuffer>(header._opcode, header._fin, std::move(_payload_cache)));
|
||||
_payload_cache.clear();
|
||||
break;
|
||||
}
|
||||
@@ -219,23 +220,23 @@ protected:
|
||||
/**
|
||||
* 发送数据进行websocket协议打包后回调
|
||||
*/
|
||||
void onWebSocketEncodeData(Buffer::Ptr buffer) override{
|
||||
void onWebSocketEncodeData(toolkit::Buffer::Ptr buffer) override{
|
||||
HttpSessionType::send(std::move(buffer));
|
||||
}
|
||||
|
||||
private:
|
||||
string _payload_cache;
|
||||
string _payload_section;
|
||||
weak_ptr<Server> _weak_server;
|
||||
TcpSession::Ptr _session;
|
||||
std::string _payload_cache;
|
||||
std::string _payload_section;
|
||||
std::weak_ptr<toolkit::Server> _weak_server;
|
||||
toolkit::TcpSession::Ptr _session;
|
||||
Creator _creator;
|
||||
};
|
||||
|
||||
|
||||
template<typename TcpSessionType,typename HttpSessionType = HttpSession,WebSocketHeader::Type DataType = WebSocketHeader::TEXT>
|
||||
template<typename TcpSessionType,typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
|
||||
class WebSocketSession : public WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>{
|
||||
public:
|
||||
WebSocketSession(const Socket::Ptr &pSock) : WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>(pSock){}
|
||||
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>(pSock){}
|
||||
virtual ~WebSocketSession(){}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include "Util/logger.h"
|
||||
#include "Util/util.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "Network/Buffer.h"
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
//websocket组合包最大不得超过4MB(防止内存爆炸)
|
||||
#define MAX_WS_PACKET (4 * 1024 * 1024)
|
||||
@@ -61,17 +59,17 @@ public:
|
||||
Type _opcode;
|
||||
bool _mask_flag;
|
||||
size_t _payload_len;
|
||||
vector<uint8_t > _mask;
|
||||
std::vector<uint8_t > _mask;
|
||||
};
|
||||
|
||||
//websocket协议收到的字符串类型缓存,用户协议层获取该数据传输的方式
|
||||
class WebSocketBuffer : public BufferString {
|
||||
class WebSocketBuffer : public toolkit::BufferString {
|
||||
public:
|
||||
typedef std::shared_ptr<WebSocketBuffer> Ptr;
|
||||
|
||||
template<typename ...ARGS>
|
||||
WebSocketBuffer(WebSocketHeader::Type headType, bool fin, ARGS &&...args)
|
||||
: BufferString(std::forward<ARGS>(args)...), _fin(fin), _head_type(headType){}
|
||||
: toolkit::BufferString(std::forward<ARGS>(args)...), _fin(fin), _head_type(headType){}
|
||||
|
||||
~WebSocketBuffer() override {}
|
||||
|
||||
@@ -103,7 +101,7 @@ public:
|
||||
* @param header 数据头
|
||||
* @param buffer 负载数据
|
||||
*/
|
||||
void encode(const WebSocketHeader &header,const Buffer::Ptr &buffer);
|
||||
void encode(const WebSocketHeader &header,const toolkit::Buffer::Ptr &buffer);
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -132,7 +130,7 @@ protected:
|
||||
* @param ptr 数据指针
|
||||
* @param len 数据指针长度
|
||||
*/
|
||||
virtual void onWebSocketEncodeData(Buffer::Ptr buffer){};
|
||||
virtual void onWebSocketEncodeData(toolkit::Buffer::Ptr buffer){};
|
||||
|
||||
private:
|
||||
void onPayloadData(uint8_t *data, size_t len);
|
||||
@@ -141,7 +139,7 @@ private:
|
||||
bool _got_header = false;
|
||||
int _mask_offset = 0;
|
||||
size_t _payload_offset = 0;
|
||||
string _remain_data;
|
||||
std::string _remain_data;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <windows.h>
|
||||
#endif//defined(_WIN32)
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
//////////////////////////通用///////////////////////
|
||||
|
||||
@@ -14,17 +14,15 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class strCoding {
|
||||
public:
|
||||
static string UrlEncode(const string &str); //urlutf8 编码
|
||||
static string UrlDecode(const string &str); //urlutf8解码
|
||||
static std::string UrlEncode(const std::string &str); //urlutf8 编码
|
||||
static std::string UrlDecode(const std::string &str); //urlutf8解码
|
||||
#if defined(_WIN32)
|
||||
static string UTF8ToGB2312(const string &str);//utf_8转为gb2312
|
||||
static string GB2312ToUTF8(const string &str); //gb2312 转utf_8
|
||||
static std::string UTF8ToGB2312(const std::string &str);//utf_8转为gb2312
|
||||
static std::string GB2312ToUTF8(const std::string &str); //gb2312 转utf_8
|
||||
#endif//defined(_WIN32)
|
||||
private:
|
||||
strCoding(void);
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "MediaPlayer.h"
|
||||
#include "Rtmp/RtmpPlayerImp.h"
|
||||
#include "Rtsp/RtspPlayerImp.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "Rtsp/RtspPlayer.h"
|
||||
#include "Rtmp/RtmpPlayer.h"
|
||||
#include "Thread/TaskExecutor.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -25,16 +24,16 @@ class MediaPlayer : public PlayerImp<PlayerBase, PlayerBase> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<MediaPlayer>;
|
||||
|
||||
MediaPlayer(const EventPoller::Ptr &poller = nullptr);
|
||||
MediaPlayer(const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||
~MediaPlayer() override = default;
|
||||
|
||||
void play(const string &url) override;
|
||||
EventPoller::Ptr getPoller();
|
||||
void setOnCreateSocket(Socket::onCreateSocket cb);
|
||||
void play(const std::string &url) override;
|
||||
toolkit::EventPoller::Ptr getPoller();
|
||||
void setOnCreateSocket(toolkit::Socket::onCreateSocket cb);
|
||||
|
||||
private:
|
||||
EventPoller::Ptr _poller;
|
||||
Socket::onCreateSocket _on_create_socket;
|
||||
toolkit::EventPoller::Ptr _poller;
|
||||
toolkit::Socket::onCreateSocket _on_create_socket;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "Rtmp/RtmpPlayerImp.h"
|
||||
#include "Http/HlsPlayer.h"
|
||||
#include "Http/TsPlayerImp.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
@@ -61,10 +63,10 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller, const s
|
||||
}
|
||||
|
||||
PlayerBase::PlayerBase() {
|
||||
this->mINI::operator[](kTimeoutMS) = 10000;
|
||||
this->mINI::operator[](kMediaTimeoutMS) = 5000;
|
||||
this->mINI::operator[](kBeatIntervalMS) = 5000;
|
||||
this->mINI::operator[](kWaitTrackReady) = true;
|
||||
this->mINI::operator[](Client::kTimeoutMS) = 10000;
|
||||
this->mINI::operator[](Client::kMediaTimeoutMS) = 5000;
|
||||
this->mINI::operator[](Client::kBeatIntervalMS) = 5000;
|
||||
this->mINI::operator[](Client::kWaitTrackReady) = true;
|
||||
}
|
||||
|
||||
///////////////////////////DemuxerSink//////////////////////////////
|
||||
|
||||
@@ -23,16 +23,14 @@
|
||||
#include "Extension/Frame.h"
|
||||
#include "Extension/Track.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class PlayerBase : public TrackSource, public mINI {
|
||||
class PlayerBase : public TrackSource, public toolkit::mINI {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<PlayerBase>;
|
||||
using Event = std::function<void(const SockException &ex)>;
|
||||
using Event = std::function<void(const toolkit::SockException &ex)>;
|
||||
|
||||
static Ptr createPlayer(const EventPoller::Ptr &poller, const string &strUrl);
|
||||
static Ptr createPlayer(const toolkit::EventPoller::Ptr &poller, const std::string &strUrl);
|
||||
|
||||
PlayerBase();
|
||||
~PlayerBase() override = default;
|
||||
@@ -41,7 +39,7 @@ public:
|
||||
* 开始播放
|
||||
* @param url 视频url,支持rtsp/rtmp
|
||||
*/
|
||||
virtual void play(const string &url) {};
|
||||
virtual void play(const std::string &url) {};
|
||||
|
||||
/**
|
||||
* 暂停或恢复
|
||||
@@ -96,7 +94,7 @@ public:
|
||||
/**
|
||||
* 获取所有track
|
||||
*/
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override { return vector<Track::Ptr>(); };
|
||||
std::vector<Track::Ptr> getTracks(bool ready = true) const override { return std::vector<Track::Ptr>(); };
|
||||
|
||||
/**
|
||||
* 设置一个MediaSource,直接生产rtsp/rtmp代理
|
||||
@@ -116,12 +114,12 @@ public:
|
||||
/**
|
||||
* 设置播放恢复回调
|
||||
*/
|
||||
virtual void setOnResume(const function<void()> &cb) = 0;
|
||||
virtual void setOnResume(const std::function<void()> &cb) = 0;
|
||||
|
||||
protected:
|
||||
virtual void onResume() = 0;
|
||||
virtual void onShutdown(const SockException &ex) = 0;
|
||||
virtual void onPlayResult(const SockException &ex) = 0;
|
||||
virtual void onShutdown(const toolkit::SockException &ex) = 0;
|
||||
virtual void onPlayResult(const toolkit::SockException &ex) = 0;
|
||||
};
|
||||
|
||||
template<typename Parent, typename Delegate>
|
||||
@@ -133,7 +131,7 @@ public:
|
||||
PlayerImp(ArgsType &&...args) : Parent(std::forward<ArgsType>(args)...) {}
|
||||
~PlayerImp() override = default;
|
||||
|
||||
void play(const string &url) override {
|
||||
void play(const std::string &url) override {
|
||||
return _delegate ? _delegate->play(url) : Parent::play(url);
|
||||
}
|
||||
|
||||
@@ -173,12 +171,12 @@ public:
|
||||
return _delegate ? _delegate->seekTo(pos) : Parent::seekTo(pos);
|
||||
}
|
||||
|
||||
vector<Track::Ptr> getTracks(bool ready = true) const override {
|
||||
std::vector<Track::Ptr> getTracks(bool ready = true) const override {
|
||||
return _delegate ? _delegate->getTracks(ready) : Parent::getTracks(ready);
|
||||
}
|
||||
|
||||
std::shared_ptr<SockInfo> getSockInfo() const {
|
||||
return dynamic_pointer_cast<SockInfo>(_delegate);
|
||||
std::shared_ptr<toolkit::SockInfo> getSockInfo() const {
|
||||
return std::dynamic_pointer_cast<toolkit::SockInfo>(_delegate);
|
||||
}
|
||||
|
||||
void setMediaSource(const MediaSource::Ptr &src) override {
|
||||
@@ -188,21 +186,21 @@ public:
|
||||
_media_src = src;
|
||||
}
|
||||
|
||||
void setOnShutdown(const function<void(const SockException &)> &cb) override {
|
||||
void setOnShutdown(const std::function<void(const toolkit::SockException &)> &cb) override {
|
||||
if (_delegate) {
|
||||
_delegate->setOnShutdown(cb);
|
||||
}
|
||||
_on_shutdown = cb;
|
||||
}
|
||||
|
||||
void setOnPlayResult(const function<void(const SockException &ex)> &cb) override {
|
||||
void setOnPlayResult(const std::function<void(const toolkit::SockException &ex)> &cb) override {
|
||||
if (_delegate) {
|
||||
_delegate->setOnPlayResult(cb);
|
||||
}
|
||||
_on_play_result = cb;
|
||||
}
|
||||
|
||||
void setOnResume(const function<void()> &cb) override {
|
||||
void setOnResume(const std::function<void()> &cb) override {
|
||||
if (_delegate) {
|
||||
_delegate->setOnResume(cb);
|
||||
}
|
||||
@@ -210,14 +208,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void onShutdown(const SockException &ex) override {
|
||||
void onShutdown(const toolkit::SockException &ex) override {
|
||||
if (_on_shutdown) {
|
||||
_on_shutdown(ex);
|
||||
_on_shutdown = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void onPlayResult(const SockException &ex) override {
|
||||
void onPlayResult(const toolkit::SockException &ex) override {
|
||||
if (_on_play_result) {
|
||||
_on_play_result(ex);
|
||||
_on_play_result = nullptr;
|
||||
@@ -231,7 +229,7 @@ protected:
|
||||
}
|
||||
|
||||
protected:
|
||||
function<void()> _on_resume;
|
||||
std::function<void()> _on_resume;
|
||||
PlayerBase::Event _on_shutdown;
|
||||
PlayerBase::Event _on_play_result;
|
||||
MediaSource::Ptr _media_src;
|
||||
@@ -263,7 +261,7 @@ public:
|
||||
~Demuxer() override = default;
|
||||
|
||||
void setTrackListener(TrackListener *listener, bool wait_track_ready = false);
|
||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
std::vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
|
||||
protected:
|
||||
bool addTrack(const Track::Ptr &track) override;
|
||||
@@ -273,7 +271,7 @@ protected:
|
||||
private:
|
||||
MediaSink::Ptr _sink;
|
||||
TrackListener *_listener = nullptr;
|
||||
vector<Track::Ptr> _origin_track;
|
||||
std::vector<Track::Ptr> _origin_track;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "Extension/AAC.h"
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#include "Common/Device.h"
|
||||
#include "Player/MediaPlayer.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -26,9 +24,9 @@ public:
|
||||
|
||||
//如果retry_count<0,则一直重试播放;否则重试retry_count次数
|
||||
//默认一直重试
|
||||
PlayerProxy(const string &vhost, const string &app, const string &stream_id,
|
||||
PlayerProxy(const std::string &vhost, const std::string &app, const std::string &stream_id,
|
||||
bool enable_hls = true, bool enable_mp4 = false,
|
||||
int retry_count = -1, const EventPoller::Ptr &poller = nullptr);
|
||||
int retry_count = -1, const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||
|
||||
~PlayerProxy() override;
|
||||
|
||||
@@ -36,19 +34,19 @@ public:
|
||||
* 设置play结果回调,只触发一次;在play执行之前有效
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
void setPlayCallbackOnce(const function<void(const SockException &ex)> &cb);
|
||||
void setPlayCallbackOnce(const std::function<void(const toolkit::SockException &ex)> &cb);
|
||||
|
||||
/**
|
||||
* 设置主动关闭回调
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
void setOnClose(const function<void(const SockException &ex)> &cb);
|
||||
void setOnClose(const std::function<void(const toolkit::SockException &ex)> &cb);
|
||||
|
||||
/**
|
||||
* 开始拉流播放
|
||||
* @param strUrl
|
||||
*/
|
||||
void play(const string &strUrl) override;
|
||||
void play(const std::string &strUrl) override;
|
||||
|
||||
/**
|
||||
* 获取观看总人数
|
||||
@@ -60,10 +58,10 @@ private:
|
||||
bool close(MediaSource &sender,bool force) override;
|
||||
int totalReaderCount(MediaSource &sender) override;
|
||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||
string getOriginUrl(MediaSource &sender) const override;
|
||||
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
std::string getOriginUrl(MediaSource &sender) const override;
|
||||
std::shared_ptr<toolkit::SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
|
||||
void rePlay(const string &strUrl,int iFailedCnt);
|
||||
void rePlay(const std::string &strUrl,int iFailedCnt);
|
||||
void onPlaySuccess();
|
||||
void setDirectProxy();
|
||||
|
||||
@@ -71,13 +69,13 @@ private:
|
||||
bool _enable_hls;
|
||||
bool _enable_mp4;
|
||||
int _retry_count;
|
||||
string _vhost;
|
||||
string _app;
|
||||
string _stream_id;
|
||||
string _pull_url;
|
||||
Timer::Ptr _timer;
|
||||
function<void(const SockException &ex)> _on_close;
|
||||
function<void(const SockException &ex)> _on_play;
|
||||
std::string _vhost;
|
||||
std::string _app;
|
||||
std::string _stream_id;
|
||||
std::string _pull_url;
|
||||
toolkit::Timer::Ptr _timer;
|
||||
std::function<void(const toolkit::SockException &ex)> _on_close;
|
||||
std::function<void(const toolkit::SockException &ex)> _on_play;
|
||||
MultiMediaSourceMuxer::Ptr _muxer;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "MediaPusher.h"
|
||||
#include "PusherBase.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <string>
|
||||
#include "PusherBase.h"
|
||||
#include "Thread/TaskExecutor.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -23,25 +22,25 @@ class MediaPusher : public PusherImp<PusherBase,PusherBase> {
|
||||
public:
|
||||
typedef std::shared_ptr<MediaPusher> Ptr;
|
||||
|
||||
MediaPusher(const string &schema,
|
||||
const string &vhost,
|
||||
const string &app,
|
||||
const string &stream,
|
||||
const EventPoller::Ptr &poller = nullptr);
|
||||
MediaPusher(const std::string &schema,
|
||||
const std::string &vhost,
|
||||
const std::string &app,
|
||||
const std::string &stream,
|
||||
const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||
|
||||
MediaPusher(const MediaSource::Ptr &src,
|
||||
const EventPoller::Ptr &poller = nullptr);
|
||||
const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||
|
||||
virtual ~MediaPusher();
|
||||
|
||||
void publish(const string &url) override;
|
||||
EventPoller::Ptr getPoller();
|
||||
void setOnCreateSocket(Socket::onCreateSocket cb);
|
||||
void publish(const std::string &url) override;
|
||||
toolkit::EventPoller::Ptr getPoller();
|
||||
void setOnCreateSocket(toolkit::Socket::onCreateSocket cb);
|
||||
|
||||
private:
|
||||
std::weak_ptr<MediaSource> _src;
|
||||
EventPoller::Ptr _poller;
|
||||
Socket::onCreateSocket _on_create_socket;
|
||||
toolkit::EventPoller::Ptr _poller;
|
||||
toolkit::Socket::onCreateSocket _on_create_socket;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -14,43 +14,42 @@
|
||||
#include "Rtmp/RtmpPusher.h"
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace mediakit::Client;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
PusherBase::Ptr PusherBase::createPusher(const EventPoller::Ptr &poller,
|
||||
const MediaSource::Ptr &src,
|
||||
const string & strUrl) {
|
||||
const std::string & strUrl) {
|
||||
static auto releasePusher = [](PusherBase *ptr){
|
||||
onceToken token(nullptr,[&](){
|
||||
delete ptr;
|
||||
});
|
||||
ptr->teardown();
|
||||
};
|
||||
string prefix = FindField(strUrl.data(), NULL, "://");
|
||||
std::string prefix = FindField(strUrl.data(), NULL, "://");
|
||||
|
||||
if (strcasecmp("rtsps",prefix.data()) == 0) {
|
||||
return PusherBase::Ptr(new TcpClientWithSSL<RtspPusherImp>(poller,dynamic_pointer_cast<RtspMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new TcpClientWithSSL<RtspPusherImp>(poller, std::dynamic_pointer_cast<RtspMediaSource>(src)), releasePusher);
|
||||
}
|
||||
|
||||
if (strcasecmp("rtsp",prefix.data()) == 0) {
|
||||
return PusherBase::Ptr(new RtspPusherImp(poller,dynamic_pointer_cast<RtspMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new RtspPusherImp(poller, std::dynamic_pointer_cast<RtspMediaSource>(src)), releasePusher);
|
||||
}
|
||||
|
||||
if (strcasecmp("rtmps",prefix.data()) == 0) {
|
||||
return PusherBase::Ptr(new TcpClientWithSSL<RtmpPusherImp>(poller,dynamic_pointer_cast<RtmpMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new TcpClientWithSSL<RtmpPusherImp>(poller, std::dynamic_pointer_cast<RtmpMediaSource>(src)), releasePusher);
|
||||
}
|
||||
|
||||
if (strcasecmp("rtmp",prefix.data()) == 0) {
|
||||
return PusherBase::Ptr(new RtmpPusherImp(poller,dynamic_pointer_cast<RtmpMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new RtmpPusherImp(poller, std::dynamic_pointer_cast<RtmpMediaSource>(src)), releasePusher);
|
||||
}
|
||||
|
||||
return PusherBase::Ptr(new RtspPusherImp(poller,dynamic_pointer_cast<RtspMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new RtspPusherImp(poller, std::dynamic_pointer_cast<RtspMediaSource>(src)), releasePusher);
|
||||
}
|
||||
|
||||
PusherBase::PusherBase() {
|
||||
this->mINI::operator[](kTimeoutMS) = 10000;
|
||||
this->mINI::operator[](kBeatIntervalMS) = 5000;
|
||||
this->mINI::operator[](Client::kTimeoutMS) = 10000;
|
||||
this->mINI::operator[](Client::kBeatIntervalMS) = 5000;
|
||||
}
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -18,18 +18,17 @@
|
||||
#include "Network/Socket.h"
|
||||
#include "Util/mini.h"
|
||||
#include "Common/MediaSource.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class PusherBase : public mINI {
|
||||
class PusherBase : public toolkit::mINI {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<PusherBase>;
|
||||
using Event = std::function<void(const SockException &ex)>;
|
||||
using Event = std::function<void(const toolkit::SockException &ex)>;
|
||||
|
||||
static Ptr createPusher(const EventPoller::Ptr &poller,
|
||||
static Ptr createPusher(const toolkit::EventPoller::Ptr &poller,
|
||||
const MediaSource::Ptr &src,
|
||||
const string &strUrl);
|
||||
const std::string &strUrl);
|
||||
|
||||
PusherBase();
|
||||
virtual ~PusherBase() = default;
|
||||
@@ -38,7 +37,7 @@ public:
|
||||
* 开始推流
|
||||
* @param strUrl 视频url,支持rtsp/rtmp
|
||||
*/
|
||||
virtual void publish(const string &strUrl) {};
|
||||
virtual void publish(const std::string &strUrl) {};
|
||||
|
||||
/**
|
||||
* 中断推流
|
||||
@@ -56,8 +55,8 @@ public:
|
||||
virtual void setOnShutdown(const Event &cb) = 0;
|
||||
|
||||
protected:
|
||||
virtual void onShutdown(const SockException &ex) = 0;
|
||||
virtual void onPublishResult(const SockException &ex) = 0;
|
||||
virtual void onShutdown(const toolkit::SockException &ex) = 0;
|
||||
virtual void onPublishResult(const toolkit::SockException &ex) = 0;
|
||||
};
|
||||
|
||||
template<typename Parent, typename Delegate>
|
||||
@@ -73,7 +72,7 @@ public:
|
||||
* 开始推流
|
||||
* @param url 推流url,支持rtsp/rtmp
|
||||
*/
|
||||
void publish(const string &url) override {
|
||||
void publish(const std::string &url) override {
|
||||
return _delegate ? _delegate->publish(url) : Parent::publish(url);
|
||||
}
|
||||
|
||||
@@ -84,8 +83,8 @@ public:
|
||||
return _delegate ? _delegate->teardown() : Parent::teardown();
|
||||
}
|
||||
|
||||
std::shared_ptr<SockInfo> getSockInfo() const {
|
||||
return dynamic_pointer_cast<SockInfo>(_delegate);
|
||||
std::shared_ptr<toolkit::SockInfo> getSockInfo() const {
|
||||
return std::dynamic_pointer_cast<toolkit::SockInfo>(_delegate);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,14 +108,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void onShutdown(const SockException &ex) override {
|
||||
void onShutdown(const toolkit::SockException &ex) override {
|
||||
if (_on_shutdown) {
|
||||
_on_shutdown(ex);
|
||||
_on_shutdown = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void onPublishResult(const SockException &ex) override {
|
||||
void onPublishResult(const toolkit::SockException &ex) override {
|
||||
if (_on_publish) {
|
||||
_on_publish(ex);
|
||||
_on_publish = nullptr;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "PusherProxy.h"
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
#include "Pusher/MediaPusher.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class PusherProxy : public MediaPusher, public std::enable_shared_from_this<PusherProxy> {
|
||||
@@ -25,37 +22,37 @@ public:
|
||||
|
||||
// 如果retry_count<0,则一直重试播放;否则重试retry_count次数
|
||||
// 默认一直重试,创建此对象时候,需要外部保证MediaSource存在
|
||||
PusherProxy(const MediaSource::Ptr &src, int retry_count = -1, const EventPoller::Ptr &poller = nullptr);
|
||||
PusherProxy(const MediaSource::Ptr &src, int retry_count = -1, const toolkit::EventPoller::Ptr &poller = nullptr);
|
||||
~PusherProxy() override;
|
||||
|
||||
/**
|
||||
* 设置push结果回调,只触发一次;在publish执行之前有效
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
void setPushCallbackOnce(const function<void(const SockException &ex)> &cb);
|
||||
void setPushCallbackOnce(const std::function<void(const toolkit::SockException &ex)> &cb);
|
||||
|
||||
/**
|
||||
* 设置主动关闭回调
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
void setOnClose(const function<void(const SockException &ex)> &cb);
|
||||
void setOnClose(const std::function<void(const toolkit::SockException &ex)> &cb);
|
||||
|
||||
/**
|
||||
* 开始拉流播放
|
||||
* @param dstUrl 目标推流地址
|
||||
*/
|
||||
void publish(const string& dstUrl) override;
|
||||
void publish(const std::string& dstUrl) override;
|
||||
|
||||
private:
|
||||
// 重推逻辑函数
|
||||
void rePublish(const string &dstUrl, int iFailedCnt);
|
||||
void rePublish(const std::string &dstUrl, int iFailedCnt);
|
||||
|
||||
private:
|
||||
int _retry_count;
|
||||
Timer::Ptr _timer;
|
||||
toolkit::Timer::Ptr _timer;
|
||||
std::weak_ptr<MediaSource> _weak_src;
|
||||
function<void(const SockException &ex)> _on_close;
|
||||
function<void(const SockException &ex)> _on_publish;
|
||||
std::function<void(const toolkit::SockException &ex)> _on_close;
|
||||
std::function<void(const toolkit::SockException &ex)> _on_publish;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
*/
|
||||
|
||||
#include "HlsMaker.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
HlsMaker::HlsMaker(float seg_duration, uint32_t seg_number) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "Util/File.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/logger.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -56,7 +55,7 @@ protected:
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
virtual string onOpenSegment(uint64_t index) = 0;
|
||||
virtual std::string onOpenSegment(uint64_t index) = 0;
|
||||
|
||||
/**
|
||||
* 删除ts切片文件回调
|
||||
@@ -114,8 +113,8 @@ private:
|
||||
uint32_t _last_timestamp = 0;
|
||||
uint32_t _last_seg_timestamp = 0;
|
||||
uint64_t _file_index = 0;
|
||||
string _last_file_name;
|
||||
std::deque<tuple<int,string> > _seg_dur_list;
|
||||
std::string _last_file_name;
|
||||
std::deque<std::tuple<int,std::string> > _seg_dur_list;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Util/util.h"
|
||||
#include "Util/uv_errno.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@@ -17,14 +17,12 @@
|
||||
#include "HlsMaker.h"
|
||||
#include "HlsMediaSource.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HlsMakerImp : public HlsMaker{
|
||||
public:
|
||||
HlsMakerImp(const string &m3u8_file,
|
||||
const string ¶ms,
|
||||
HlsMakerImp(const std::string &m3u8_file,
|
||||
const std::string ¶ms,
|
||||
uint32_t bufSize = 64 * 1024,
|
||||
float seg_duration = 5,
|
||||
uint32_t seg_number = 3);
|
||||
@@ -37,7 +35,7 @@ public:
|
||||
* @param app 应用名
|
||||
* @param stream_id 流id
|
||||
*/
|
||||
void setMediaSource(const string &vhost, const string &app, const string &stream_id);
|
||||
void setMediaSource(const std::string &vhost, const std::string &app, const std::string &stream_id);
|
||||
|
||||
/**
|
||||
* 获取MediaSource
|
||||
@@ -52,26 +50,26 @@ public:
|
||||
void clearCache(bool immediately = true);
|
||||
|
||||
protected:
|
||||
string onOpenSegment(uint64_t index) override ;
|
||||
std::string onOpenSegment(uint64_t index) override ;
|
||||
void onDelSegment(uint64_t index) override;
|
||||
void onWriteSegment(const char *data, size_t len) override;
|
||||
void onWriteHls(const char *data, size_t len) override;
|
||||
void onFlushLastSegment(uint32_t duration_ms) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<FILE> makeFile(const string &file,bool setbuf = false);
|
||||
std::shared_ptr<FILE> makeFile(const std::string &file,bool setbuf = false);
|
||||
|
||||
private:
|
||||
int _buf_size;
|
||||
string _params;
|
||||
string _path_hls;
|
||||
string _path_prefix;
|
||||
std::string _params;
|
||||
std::string _path_hls;
|
||||
std::string _path_prefix;
|
||||
RecordInfo _info;
|
||||
std::shared_ptr<FILE> _file;
|
||||
std::shared_ptr<char> _file_buf;
|
||||
HlsMediaSource::Ptr _media_src;
|
||||
EventPoller::Ptr _poller;
|
||||
map<uint64_t/*index*/,string/*file_path*/> _segment_file_paths;
|
||||
toolkit::EventPoller::Ptr _poller;
|
||||
std::map<uint64_t/*index*/,std::string/*file_path*/> _segment_file_paths;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "HlsMediaSource.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
HlsCookieData::HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockInfo> &sock_info) {
|
||||
@@ -21,7 +23,7 @@ HlsCookieData::HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockIn
|
||||
|
||||
void HlsCookieData::addReaderCount(){
|
||||
if(!*_added){
|
||||
auto src = dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
|
||||
auto src = std::dynamic_pointer_cast<HlsMediaSource>(MediaSource::find(HLS_SCHEMA,_info._vhost,_info._app,_info._streamid));
|
||||
if(src){
|
||||
*_added = true;
|
||||
_ring_reader = src->getRing()->attach(EventPollerPool::Instance().getPoller());
|
||||
|
||||
@@ -14,14 +14,17 @@
|
||||
#include <atomic>
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "Common/MediaSource.h"
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
class HlsMediaSource : public MediaSource {
|
||||
public:
|
||||
friend class HlsCookieData;
|
||||
typedef RingBuffer<string> RingType;
|
||||
typedef std::shared_ptr<HlsMediaSource> Ptr;
|
||||
HlsMediaSource(const string &vhost, const string &app, const string &stream_id) : MediaSource(HLS_SCHEMA, vhost, app, stream_id){}
|
||||
|
||||
using RingType = toolkit::RingBuffer<std::string>;
|
||||
using Ptr = std::shared_ptr<HlsMediaSource>;
|
||||
|
||||
HlsMediaSource(const std::string &vhost, const std::string &app, const std::string &stream_id) : MediaSource(HLS_SCHEMA, vhost, app, stream_id){}
|
||||
~HlsMediaSource() override = default;
|
||||
|
||||
/**
|
||||
@@ -45,7 +48,7 @@ public:
|
||||
void registHls(bool file_created){
|
||||
if (!_is_regist) {
|
||||
_is_regist = true;
|
||||
weak_ptr<HlsMediaSource> weakSelf = dynamic_pointer_cast<HlsMediaSource>(shared_from_this());
|
||||
std::weak_ptr<HlsMediaSource> weakSelf = std::dynamic_pointer_cast<HlsMediaSource>(shared_from_this());
|
||||
auto lam = [weakSelf](int size) {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
@@ -65,17 +68,17 @@ public:
|
||||
//m3u8文件生成,发送给播放器
|
||||
decltype(_list_cb) copy;
|
||||
{
|
||||
lock_guard<mutex> lck(_mtx_cb);
|
||||
std::lock_guard<std::mutex> lck(_mtx_cb);
|
||||
copy.swap(_list_cb);
|
||||
}
|
||||
copy.for_each([](const function<void()> &cb) {
|
||||
copy.for_each([](const std::function<void()> &cb) {
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
void waitForFile(function<void()> cb) {
|
||||
void waitForFile(std::function<void()> cb) {
|
||||
//等待生成m3u8文件
|
||||
lock_guard<mutex> lck(_mtx_cb);
|
||||
std::lock_guard<std::mutex> lck(_mtx_cb);
|
||||
_list_cb.emplace_back(std::move(cb));
|
||||
}
|
||||
|
||||
@@ -86,14 +89,14 @@ public:
|
||||
private:
|
||||
bool _is_regist = false;
|
||||
RingType::Ptr _ring;
|
||||
mutex _mtx_cb;
|
||||
List<function<void()> > _list_cb;
|
||||
std::mutex _mtx_cb;
|
||||
toolkit::List<std::function<void()> > _list_cb;
|
||||
};
|
||||
|
||||
class HlsCookieData{
|
||||
public:
|
||||
typedef std::shared_ptr<HlsCookieData> Ptr;
|
||||
HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockInfo> &sock_info);
|
||||
HlsCookieData(const MediaInfo &info, const std::shared_ptr<toolkit::SockInfo> &sock_info);
|
||||
~HlsCookieData();
|
||||
void addByteUsage(size_t bytes);
|
||||
|
||||
@@ -101,14 +104,13 @@ private:
|
||||
void addReaderCount();
|
||||
|
||||
private:
|
||||
atomic<uint64_t> _bytes {0};
|
||||
std::atomic<uint64_t> _bytes {0};
|
||||
MediaInfo _info;
|
||||
std::shared_ptr<bool> _added;
|
||||
Ticker _ticker;
|
||||
std::shared_ptr<SockInfo> _sock_info;
|
||||
toolkit::Ticker _ticker;
|
||||
std::shared_ptr<toolkit::SockInfo> _sock_info;
|
||||
HlsMediaSource::RingType::RingReader::Ptr _ring_reader;
|
||||
};
|
||||
|
||||
|
||||
}//namespace mediakit
|
||||
#endif //ZLMEDIAKIT_HLSMEDIASOURCE_H
|
||||
|
||||
@@ -20,7 +20,7 @@ class HlsRecorder : public MediaSourceEventInterceptor, public MpegMuxer, public
|
||||
public:
|
||||
using Ptr = std::shared_ptr<HlsRecorder>;
|
||||
|
||||
HlsRecorder(const string &m3u8_file, const string ¶ms) : MpegMuxer(false) {
|
||||
HlsRecorder(const std::string &m3u8_file, const std::string ¶ms) : MpegMuxer(false) {
|
||||
GET_CONFIG(uint32_t, hlsNum, Hls::kSegmentNum);
|
||||
GET_CONFIG(uint32_t, hlsBufSize, Hls::kFileBufSize);
|
||||
GET_CONFIG(float, hlsDuration, Hls::kSegmentDuration);
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
|
||||
~HlsRecorder() = default;
|
||||
|
||||
void setMediaSource(const string &vhost, const string &app, const string &stream_id) {
|
||||
void setMediaSource(const std::string &vhost, const std::string &app, const std::string &stream_id) {
|
||||
_hls->setMediaSource(vhost, app, stream_id);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void onWrite(std::shared_ptr<Buffer> buffer, uint32_t timestamp, bool key_pos) override {
|
||||
void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint32_t timestamp, bool key_pos) override {
|
||||
if (!buffer) {
|
||||
_hls->inputData(nullptr, 0, timestamp, key_pos);
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "Common/config.h"
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
static struct mov_buffer_t s_io = {
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include "mov-buffer.h"
|
||||
#include "mov-format.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
//mp4文件IO的抽象接口类
|
||||
@@ -124,7 +122,7 @@ public:
|
||||
/**
|
||||
* 获取并清空文件缓存
|
||||
*/
|
||||
string getAndClearMemory();
|
||||
std::string getAndClearMemory();
|
||||
|
||||
protected:
|
||||
uint64_t onTell() override;
|
||||
@@ -134,7 +132,7 @@ protected:
|
||||
|
||||
private:
|
||||
uint64_t _offset = 0;
|
||||
string _memory;
|
||||
std::string _memory;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user