mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-04 18:17:34 +08:00
大幅提升接收推流性能以及降低内存占用
This commit is contained in:
@@ -21,23 +21,24 @@
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "Network/Socket.h"
|
||||
#include "Util/ResourcePool.h"
|
||||
#include "Http/HttpRequestSplitter.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpProtocol {
|
||||
class RtmpProtocol : public HttpRequestSplitter{
|
||||
public:
|
||||
RtmpProtocol();
|
||||
virtual ~RtmpProtocol();
|
||||
|
||||
void onParseRtmp(const char *data, int size);
|
||||
void onParseRtmp(const char *data, uint64_t size);
|
||||
//作为客户端发送c0c1,等待s0s1s2并且回调
|
||||
void startClientSession(const function<void()> &cb);
|
||||
|
||||
protected:
|
||||
virtual void onSendRawData(const Buffer::Ptr &buffer) = 0;
|
||||
virtual void onSendRawData(Buffer::Ptr buffer) = 0;
|
||||
virtual void onRtmpChunk(RtmpPacket &chunk_data) = 0;
|
||||
virtual void onStreamBegin(uint32_t stream_index){
|
||||
_stream_index = stream_index;
|
||||
@@ -45,6 +46,11 @@ protected:
|
||||
virtual void onStreamEof(uint32_t stream_index){};
|
||||
virtual void onStreamDry(uint32_t stream_index){};
|
||||
|
||||
protected:
|
||||
//// HttpRequestSplitter override ////
|
||||
int64_t onRecvHeader(const char *data,uint64_t len) override { return 0; }
|
||||
const char *onSearchPacketTail(const char *data,uint64_t len) override;
|
||||
|
||||
protected:
|
||||
void reset();
|
||||
BufferRaw::Ptr obtainBuffer();
|
||||
@@ -66,20 +72,20 @@ protected:
|
||||
void sendRtmp(uint8_t type, uint32_t stream_index, const Buffer::Ptr &buffer, uint32_t stamp, int chunk_id);
|
||||
|
||||
private:
|
||||
void handle_S0S1S2(const function<void()> &func);
|
||||
void handle_C0C1();
|
||||
void handle_C1_simple();
|
||||
void handle_C1_simple(const char *data);
|
||||
#ifdef ENABLE_OPENSSL
|
||||
void handle_C1_complex();
|
||||
void handle_C1_complex(const char *data);
|
||||
string get_C1_digest(const uint8_t *ptr,char **digestPos);
|
||||
string get_C1_key(const uint8_t *ptr);
|
||||
void check_C1_Digest(const string &digest,const string &data);
|
||||
void send_complex_S0S1S2(int schemeType,const string &digest);
|
||||
#endif //ENABLE_OPENSSL
|
||||
|
||||
void handle_C2();
|
||||
void handle_rtmp();
|
||||
void handle_rtmpChunk(RtmpPacket &chunk_data);
|
||||
const char* handle_S0S1S2(const char *data, uint64_t len, const function<void()> &func);
|
||||
const char* handle_C0C1(const char *data, uint64_t len);
|
||||
const char* handle_C2(const char *data, uint64_t len);
|
||||
const char* handle_rtmp(const char *data, uint64_t len);
|
||||
void handle_chunk(RtmpPacket &chunk_data);
|
||||
|
||||
protected:
|
||||
int _send_req_id = 0;
|
||||
@@ -100,8 +106,7 @@ private:
|
||||
uint32_t _bandwidth = 2500000;
|
||||
uint8_t _band_limit_type = 2;
|
||||
//////////Rtmp parser//////////
|
||||
string _recv_data_buf;
|
||||
function<void()> _next_step_func;
|
||||
function<const char * (const char *data, uint64_t len)> _next_step_func;
|
||||
////////////Chunk////////////
|
||||
unordered_map<int, RtmpPacket> _map_chunk_data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user