Merge branch 'ZLMediaKit:master' into master
This commit is contained in:
commit
34425df1c7
|
|
@ -1 +1 @@
|
||||||
Subproject commit b11582c38e8dbbb8d93ca9ce33c9a0b0cd58f59a
|
Subproject commit 273592b6ba39babe6407021ffc089bfe7328e447
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include "JemallocUtil.h"
|
#include "JemallocUtil.h"
|
||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
#ifdef USE_JEMALLOC
|
#ifdef USE_JEMALLOC
|
||||||
|
#include <array>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <jemalloc/jemalloc.h>
|
#include <jemalloc/jemalloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ template <typename SessionType>
|
||||||
class SessionCreator {
|
class SessionCreator {
|
||||||
public:
|
public:
|
||||||
//返回的Session必须派生于SendInterceptor,可以返回null
|
//返回的Session必须派生于SendInterceptor,可以返回null
|
||||||
toolkit::Session::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
|
toolkit::Session::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock, mediakit::WebSocketHeader::Type &data_type){
|
||||||
return std::make_shared<SessionTypeImp<SessionType> >(header,parent,pSock);
|
return std::make_shared<SessionTypeImp<SessionType> >(header,parent,pSock);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -128,7 +128,8 @@ protected:
|
||||||
*/
|
*/
|
||||||
bool onWebSocketConnect(const mediakit::Parser &header) override{
|
bool onWebSocketConnect(const mediakit::Parser &header) override{
|
||||||
//创建websocket session类
|
//创建websocket session类
|
||||||
_session = _creator(header, *this, HttpSessionType::getSock());
|
auto data_type = DataType;
|
||||||
|
_session = _creator(header, *this, HttpSessionType::getSock(), data_type);
|
||||||
if (!_session) {
|
if (!_session) {
|
||||||
// 此url不允许创建websocket连接
|
// 此url不允许创建websocket连接
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -140,13 +141,13 @@ protected:
|
||||||
|
|
||||||
//此处截取数据并进行websocket协议打包
|
//此处截取数据并进行websocket协议打包
|
||||||
std::weak_ptr<WebSocketSessionBase> weakSelf = std::static_pointer_cast<WebSocketSessionBase>(HttpSessionType::shared_from_this());
|
std::weak_ptr<WebSocketSessionBase> weakSelf = std::static_pointer_cast<WebSocketSessionBase>(HttpSessionType::shared_from_this());
|
||||||
std::dynamic_pointer_cast<SendInterceptor>(_session)->setOnBeforeSendCB([weakSelf](const toolkit::Buffer::Ptr &buf) {
|
std::dynamic_pointer_cast<SendInterceptor>(_session)->setOnBeforeSendCB([weakSelf, data_type](const toolkit::Buffer::Ptr &buf) {
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if (strongSelf) {
|
if (strongSelf) {
|
||||||
mediakit::WebSocketHeader header;
|
mediakit::WebSocketHeader header;
|
||||||
header._fin = true;
|
header._fin = true;
|
||||||
header._reserved = 0;
|
header._reserved = 0;
|
||||||
header._opcode = DataType;
|
header._opcode = data_type;
|
||||||
header._mask_flag = false;
|
header._mask_flag = false;
|
||||||
strongSelf->HttpSessionType::encode(header, buf);
|
strongSelf->HttpSessionType::encode(header, buf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_
|
||||||
if (local_port == 0) {
|
if (local_port == 0) {
|
||||||
//随机端口,rtp端口采用偶数
|
//随机端口,rtp端口采用偶数
|
||||||
auto pair = std::make_pair(rtp_socket, rtcp_socket);
|
auto pair = std::make_pair(rtp_socket, rtcp_socket);
|
||||||
makeSockPair(pair, local_ip, re_use_port, TcpMode::NONE == tcp_mode);
|
makeSockPair(pair, local_ip, re_use_port);
|
||||||
local_port = rtp_socket->get_local_port();
|
local_port = rtp_socket->get_local_port();
|
||||||
} else if (!rtp_socket->bindUdpSock(local_port, local_ip, re_use_port)) {
|
} else if (!rtp_socket->bindUdpSock(local_port, local_ip, re_use_port)) {
|
||||||
//用户指定端口
|
//用户指定端口
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,11 @@ public:
|
||||||
*/
|
*/
|
||||||
struct EchoSessionCreator {
|
struct EchoSessionCreator {
|
||||||
//返回的Session必须派生于SendInterceptor,可以返回null(拒绝连接)
|
//返回的Session必须派生于SendInterceptor,可以返回null(拒绝连接)
|
||||||
Session::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) {
|
Session::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock, mediakit::WebSocketHeader::Type &type) {
|
||||||
// return nullptr;
|
// return nullptr;
|
||||||
if (header.url() == "/") {
|
if (header.url() == "/") {
|
||||||
|
// 可以指定传输方式
|
||||||
|
// type = mediakit::WebSocketHeader::BINARY;
|
||||||
return std::make_shared<SessionTypeImp<EchoSession> >(header, parent, pSock);
|
return std::make_shared<SessionTypeImp<EchoSession> >(header, parent, pSock);
|
||||||
}
|
}
|
||||||
return std::make_shared<SessionTypeImp<EchoSessionWithUrl> >(header, parent, pSock);
|
return std::make_shared<SessionTypeImp<EchoSessionWithUrl> >(header, parent, pSock);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue