From 2bd0e1ce43c89be10c2f6342827151e151a7e0f7 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 22 May 2020 18:14:15 +0800 Subject: [PATCH] Kernel: Buffer supports little-endian --- trunk/src/app/srs_app_rtc_conn.cpp | 17 +++++ trunk/src/app/srs_app_rtc_conn.hpp | 12 +++ trunk/src/kernel/srs_kernel_buffer.cpp | 102 +++++++++++++++++++++++++ trunk/src/kernel/srs_kernel_buffer.hpp | 8 ++ 4 files changed, 139 insertions(+) diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index 0b4ce7645..ddf4c01fa 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -2226,11 +2226,18 @@ srs_error_t SrsRtcSession::start_publish() break; } } + // FIXME: err process. if ((err = publisher_->initialize(video_ssrc, audio_ssrc, twcc_ext_id, req)) != srs_success) { return srs_error_wrap(err, "rtc publisher init"); } + if (_srs_rtc_hijacker) { + if ((err = _srs_rtc_hijacker->on_start_publish(this, publisher_, req)) != srs_success) { + return srs_error_wrap(err, "on start publish"); + } + } + return err; } @@ -2319,3 +2326,13 @@ srs_error_t SrsRtcSession::on_binding_request(SrsStunPacket* r) return err; } +ISrsRtcHijacker::ISrsRtcHijacker() +{ +} + +ISrsRtcHijacker::~ISrsRtcHijacker() +{ +} + +ISrsRtcHijacker* _srs_rtc_hijacker = NULL; + diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index 8b39c00bd..3bb8060dc 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -391,5 +391,17 @@ private: srs_error_t on_binding_request(SrsStunPacket* r); }; +class ISrsRtcHijacker +{ +public: + ISrsRtcHijacker(); + virtual ~ISrsRtcHijacker(); +public: + // When start publisher by RTC. + virtual srs_error_t on_start_publish(SrsRtcSession* session, SrsRtcPublisher* publisher, SrsRequest* req) = 0; +}; + +extern ISrsRtcHijacker* _srs_rtc_hijacker; + #endif diff --git a/trunk/src/kernel/srs_kernel_buffer.cpp b/trunk/src/kernel/srs_kernel_buffer.cpp index ced0f776e..255357878 100644 --- a/trunk/src/kernel/srs_kernel_buffer.cpp +++ b/trunk/src/kernel/srs_kernel_buffer.cpp @@ -128,6 +128,18 @@ int16_t SrsBuffer::read_2bytes() return value; } +int16_t SrsBuffer::read_le2bytes() +{ + srs_assert(require(2)); + + int16_t value; + char* pp = (char*)&value; + pp[0] = *p++; + pp[1] = *p++; + + return value; +} + int32_t SrsBuffer::read_3bytes() { srs_assert(require(3)); @@ -141,6 +153,19 @@ int32_t SrsBuffer::read_3bytes() return value; } +int32_t SrsBuffer::read_le3bytes() +{ + srs_assert(require(3)); + + int32_t value = 0x00; + char* pp = (char*)&value; + pp[0] = *p++; + pp[1] = *p++; + pp[2] = *p++; + + return value; +} + int32_t SrsBuffer::read_4bytes() { srs_assert(require(4)); @@ -155,6 +180,20 @@ int32_t SrsBuffer::read_4bytes() return value; } +int32_t SrsBuffer::read_le4bytes() +{ + srs_assert(require(4)); + + int32_t value; + char* pp = (char*)&value; + pp[0] = *p++; + pp[1] = *p++; + pp[2] = *p++; + pp[3] = *p++; + + return value; +} + int64_t SrsBuffer::read_8bytes() { srs_assert(require(8)); @@ -173,6 +212,24 @@ int64_t SrsBuffer::read_8bytes() return value; } +int64_t SrsBuffer::read_le8bytes() +{ + srs_assert(require(8)); + + int64_t value; + char* pp = (char*)&value; + pp[0] = *p++; + pp[1] = *p++; + pp[2] = *p++; + pp[3] = *p++; + pp[4] = *p++; + pp[5] = *p++; + pp[6] = *p++; + pp[7] = *p++; + + return value; +} + string SrsBuffer::read_string(int len) { srs_assert(require(len)); @@ -210,6 +267,15 @@ void SrsBuffer::write_2bytes(int16_t value) *p++ = pp[0]; } +void SrsBuffer::write_le2bytes(int16_t value) +{ + srs_assert(require(2)); + + char* pp = (char*)&value; + *p++ = pp[0]; + *p++ = pp[1]; +} + void SrsBuffer::write_4bytes(int32_t value) { srs_assert(require(4)); @@ -221,6 +287,17 @@ void SrsBuffer::write_4bytes(int32_t value) *p++ = pp[0]; } +void SrsBuffer::write_le4bytes(int32_t value) +{ + srs_assert(require(4)); + + char* pp = (char*)&value; + *p++ = pp[0]; + *p++ = pp[1]; + *p++ = pp[2]; + *p++ = pp[3]; +} + void SrsBuffer::write_3bytes(int32_t value) { srs_assert(require(3)); @@ -231,6 +308,16 @@ void SrsBuffer::write_3bytes(int32_t value) *p++ = pp[0]; } +void SrsBuffer::write_le3bytes(int32_t value) +{ + srs_assert(require(3)); + + char* pp = (char*)&value; + *p++ = pp[0]; + *p++ = pp[1]; + *p++ = pp[2]; +} + void SrsBuffer::write_8bytes(int64_t value) { srs_assert(require(8)); @@ -246,6 +333,21 @@ void SrsBuffer::write_8bytes(int64_t value) *p++ = pp[0]; } +void SrsBuffer::write_le8bytes(int64_t value) +{ + srs_assert(require(8)); + + char* pp = (char*)&value; + *p++ = pp[0]; + *p++ = pp[1]; + *p++ = pp[2]; + *p++ = pp[3]; + *p++ = pp[4]; + *p++ = pp[5]; + *p++ = pp[6]; + *p++ = pp[7]; +} + void SrsBuffer::write_string(string value) { srs_assert(require((int)value.length())); diff --git a/trunk/src/kernel/srs_kernel_buffer.hpp b/trunk/src/kernel/srs_kernel_buffer.hpp index f2f73bf70..6a3b4c7f3 100644 --- a/trunk/src/kernel/srs_kernel_buffer.hpp +++ b/trunk/src/kernel/srs_kernel_buffer.hpp @@ -136,12 +136,16 @@ public: int8_t read_1bytes(); // Read 2bytes int from buffer. int16_t read_2bytes(); + int16_t read_le2bytes(); // Read 3bytes int from buffer. int32_t read_3bytes(); + int32_t read_le3bytes(); // Read 4bytes int from buffer. int32_t read_4bytes(); + int32_t read_le4bytes(); // Read 8bytes int from buffer. int64_t read_8bytes(); + int64_t read_le8bytes(); // Read string from buffer, length specifies by param len. std::string read_string(int len); // Read bytes from buffer, length specifies by param len. @@ -151,12 +155,16 @@ public: void write_1bytes(int8_t value); // Write 2bytes int to buffer. void write_2bytes(int16_t value); + void write_le2bytes(int16_t value); // Write 4bytes int to buffer. void write_4bytes(int32_t value); + void write_le4bytes(int32_t value); // Write 3bytes int to buffer. void write_3bytes(int32_t value); + void write_le3bytes(int32_t value); // Write 8bytes int to buffer. void write_8bytes(int64_t value); + void write_le8bytes(int64_t value); // Write string to buffer void write_string(std::string value); // Write bytes to buffer