diff --git a/src/projects/providers/rtmp/chunk/rtmp_export_chunk.cpp b/src/projects/providers/rtmp/chunk/rtmp_export_chunk.cpp index 8bf32c055..2638ea4b9 100644 --- a/src/projects/providers/rtmp/chunk/rtmp_export_chunk.cpp +++ b/src/projects/providers/rtmp/chunk/rtmp_export_chunk.cpp @@ -61,7 +61,7 @@ std::shared_ptr RtmpExportChunk::GetStream(uint32_t chunk_stream_i // - Type3는 확장 헤더 확인 못함 - 이전 정보를 기반으로 이후에 확인 // - 압축 헤더 : 프레임이 정상 적으로 않나오는 상황에서 헤더 압축 사용하면 타임스템프 전달이 정상적으로 않됨 //==================================================================================================== -std::shared_ptr RtmpExportChunk::GetChunkHeader(std::shared_ptr &stream, const std::shared_ptr &message_header) +std::shared_ptr RtmpExportChunk::GetChunkHeader(std::shared_ptr &stream, const std::shared_ptr &message_header) { auto chunk_header = std::make_shared(); @@ -119,7 +119,7 @@ std::shared_ptr RtmpExportChunk::GetChunkHeader(std::shared_ptr //==================================================================================================== // Export 스트림 //==================================================================================================== -std::shared_ptr> RtmpExportChunk::ExportStreamData(std::shared_ptr &message_header, const uint8_t *chunk_data, size_t chunk_size) +std::shared_ptr> RtmpExportChunk::ExportStreamData(const std::shared_ptr &message_header, const uint8_t *chunk_data, size_t chunk_size) { int buffer_size = 0; int export_size = 0; diff --git a/src/projects/providers/rtmp/chunk/rtmp_export_chunk.h b/src/projects/providers/rtmp/chunk/rtmp_export_chunk.h index 8224ca330..bb4a6fe65 100644 --- a/src/projects/providers/rtmp/chunk/rtmp_export_chunk.h +++ b/src/projects/providers/rtmp/chunk/rtmp_export_chunk.h @@ -24,7 +24,7 @@ public : timestamp_delta = 0; } public : - std::shared_ptr message_header; + std::shared_ptr message_header; uint32_t timestamp_delta; }; @@ -39,19 +39,15 @@ class RtmpExportChunk : public RtmpMuxUtil ~RtmpExportChunk() override; public: - std::shared_ptr> ExportStreamData(std::shared_ptr &message_header, const uint8_t *chunk_data, size_t chunk_size); + std::shared_ptr> ExportStreamData(const std::shared_ptr &message_header, const uint8_t *chunk_data, size_t chunk_size); private: void Destroy(); std::shared_ptr GetStream(uint32_t chunk_stream_id); - std::shared_ptr GetChunkHeader(std::shared_ptr &stream, const std::shared_ptr &message_header); + std::shared_ptr GetChunkHeader(std::shared_ptr &stream, const std::shared_ptr &message_header); private: std::map> _stream_map; bool _compress_header; int _chunk_size; }; - - - - diff --git a/src/projects/providers/rtmp/chunk/rtmp_mux_util.h b/src/projects/providers/rtmp/chunk/rtmp_mux_util.h index ed396c3fe..099096b7e 100644 --- a/src/projects/providers/rtmp/chunk/rtmp_mux_util.h +++ b/src/projects/providers/rtmp/chunk/rtmp_mux_util.h @@ -6,55 +6,44 @@ // Copyright (c) 2018 AirenSoft. All rights reserved. // //============================================================================== - #pragma once #include "rtmp_datastructure.h" -#pragma pack(1) -//==================================================================================================== -// Mux 메시지 헤더 -//==================================================================================================== + struct RtmpMuxMessageHeader { public: - RtmpMuxMessageHeader() - : chunk_stream_id(0), - timestamp(0), - type_id(RtmpMessageTypeID::UNKNOWN), - stream_id(0), - body_size(0) + RtmpMuxMessageHeader() = default; + RtmpMuxMessageHeader(uint32_t chunk_stream_id, uint32_t timestamp, RtmpMessageTypeID type_id, uint32_t stream_id, uint32_t body_size) + : chunk_stream_id(chunk_stream_id), + timestamp(timestamp), + type_id(type_id), + stream_id(stream_id), + body_size(body_size) { } - RtmpMuxMessageHeader(uint32_t chunk_stream_id_, - uint32_t timestamp_, - RtmpMessageTypeID type_id_, - uint32_t stream_id_, - uint32_t body_size_) + static std::shared_ptr Create( + uint32_t chunk_stream_id, + RtmpMessageTypeID type_id = RtmpMessageTypeID::AMF0_COMMAND, + uint32_t stream_id = 0, + uint32_t body_size = 0) { - this->chunk_stream_id = chunk_stream_id_; - this->timestamp = timestamp_; - this->type_id = type_id_; - this->stream_id = stream_id_; - this->body_size = body_size_; + return std::make_shared(chunk_stream_id, 0, type_id, stream_id, body_size); } -public: - uint32_t chunk_stream_id; - uint32_t timestamp; - RtmpMessageTypeID type_id; - uint32_t stream_id; - uint32_t body_size; + uint32_t chunk_stream_id = 0; + uint32_t timestamp = 0; + RtmpMessageTypeID type_id = RtmpMessageTypeID::UNKNOWN; + uint32_t stream_id = 0; + uint32_t body_size = 0; }; -#pragma pack() class RtmpMuxUtil { public: - RtmpMuxUtil() = default; virtual ~RtmpMuxUtil() = default; -public: static uint8_t ReadInt8(const void *data); static uint16_t ReadInt16(const void *data); static uint32_t ReadInt24(const void *data); @@ -71,8 +60,8 @@ class RtmpMuxUtil static int GetBasicHeaderSizeByChunkStreamID(uint32_t chunk_stream_id) noexcept; static int GetChunkHeaderSize(RtmpMessageHeaderType chunk_type, uint32_t chunk_stream_id, int basic_header_size, void *raw_data, int raw_data_size); // ret:길이, ret<=0:실패 - static std::shared_ptr GetChunkHeader(void *raw_data, int raw_data_size, int &chunk_header_size, bool &extend_type); // ret<=0:실패, ret>0:처리길이 - static int GetChunkData(int chunk_size, void *raw_data, int raw_data_size, int chunk_data_size, void *chunk_data, bool extend_type); // ret=> 0:실패, 1:처리길이 + static std::shared_ptr GetChunkHeader(void *raw_data, int raw_data_size, int &chunk_header_size, bool &extend_type); // ret<=0:실패, ret>0:처리길이 + static int GetChunkData(int chunk_size, void *raw_data, int raw_data_size, int chunk_data_size, void *chunk_data, bool extend_type); // ret=> 0:실패, 1:처리길이 static int GetChunkBasicHeaderRaw(RtmpMessageHeaderType chunk_type, uint32_t chunk_stream_id, void *raw_data); static int GetChunkHeaderRaw(std::shared_ptr &chunk_header, void *raw_data, bool extend_type); diff --git a/src/projects/providers/rtmp/rtmp_stream.cpp b/src/projects/providers/rtmp/rtmp_stream.cpp index 95248d567..171c1f8a9 100644 --- a/src/projects/providers/rtmp/rtmp_stream.cpp +++ b/src/projects/providers/rtmp/rtmp_stream.cpp @@ -1135,12 +1135,7 @@ namespace pvd // ping response == event type (16 bits) + timestamp (32 bits) auto body = std::make_shared>(2 + 4); auto write_buffer = body->data(); - auto message_header = std::make_shared( - chunk_stream_id, - 0, - RtmpMessageTypeID::USER_CONTROL, - message_stream_id, - 6); + auto message_header = RtmpMuxMessageHeader::Create(chunk_stream_id, RtmpMessageTypeID::USER_CONTROL, message_stream_id, 6); *(reinterpret_cast(write_buffer)) = ov::HostToBE16(RTMP_UCMID_PINGRESPONSE); write_buffer += sizeof(uint16_t); @@ -2061,16 +2056,14 @@ namespace pvd bool RtmpStream::SendHandshake(const std::shared_ptr &data) { uint8_t s0 = 0; - uint8_t s1[RTMP_HANDSHAKE_PACKET_SIZE] = { - 0, - }; - uint8_t s2[RTMP_HANDSHAKE_PACKET_SIZE] = { - 0, - }; + uint8_t s1[RTMP_HANDSHAKE_PACKET_SIZE]{}; + uint8_t s2[RTMP_HANDSHAKE_PACKET_SIZE]{}; s0 = RTMP_HANDSHAKE_VERSION; + RtmpHandshake::MakeS1(s1); RtmpHandshake::MakeS2(data->GetDataAs() + sizeof(uint8_t), s2); + _handshake_state = RtmpHandshakeState::C1; // OM-1629 - Elemental Encoder @@ -2093,11 +2086,8 @@ namespace pvd bool RtmpStream::SendUserControlMessage(uint16_t message, std::shared_ptr> &data) { - auto message_header = std::make_shared(RTMP_CHUNK_STREAM_ID_URGENT, - 0, - RtmpMessageTypeID::USER_CONTROL, - 0, - data->size() + 2); + auto message_header = RtmpMuxMessageHeader::Create( + RTMP_CHUNK_STREAM_ID_URGENT, RtmpMessageTypeID::USER_CONTROL, 0, data->size() + 2); data->insert(data->begin(), 0); data->insert(data->begin(), 0); @@ -2109,11 +2099,8 @@ namespace pvd bool RtmpStream::SendWindowAcknowledgementSize(uint32_t size) { auto body = std::make_shared>(sizeof(int)); - auto message_header = std::make_shared(RTMP_CHUNK_STREAM_ID_URGENT, - 0, - RtmpMessageTypeID::WINDOW_ACKNOWLEDGEMENT_SIZE, - _rtmp_stream_id, - body->size()); + auto message_header = RtmpMuxMessageHeader::Create( + RTMP_CHUNK_STREAM_ID_URGENT, RtmpMessageTypeID::WINDOW_ACKNOWLEDGEMENT_SIZE, _rtmp_stream_id, body->size()); RtmpMuxUtil::WriteInt32(body->data(), size); @@ -2123,11 +2110,8 @@ namespace pvd bool RtmpStream::SendAcknowledgementSize(uint32_t acknowledgement_traffic) { auto body = std::make_shared>(sizeof(int)); - auto message_header = std::make_shared(RTMP_CHUNK_STREAM_ID_URGENT, - 0, - RtmpMessageTypeID::ACKNOWLEDGEMENT, - 0, - body->size()); + auto message_header = RtmpMuxMessageHeader::Create( + RTMP_CHUNK_STREAM_ID_URGENT, RtmpMessageTypeID::ACKNOWLEDGEMENT, 0, body->size()); RtmpMuxUtil::WriteInt32(body->data(), acknowledgement_traffic); @@ -2137,11 +2121,8 @@ namespace pvd bool RtmpStream::SendSetPeerBandwidth(uint32_t bandwidth) { auto body = std::make_shared>(5); - auto message_header = std::make_shared(RTMP_CHUNK_STREAM_ID_URGENT, - 0, - RtmpMessageTypeID::SET_PEER_BANDWIDTH, - _rtmp_stream_id, - body->size()); + auto message_header = RtmpMuxMessageHeader::Create( + RTMP_CHUNK_STREAM_ID_URGENT, RtmpMessageTypeID::SET_PEER_BANDWIDTH, _rtmp_stream_id, body->size()); RtmpMuxUtil::WriteInt32(body->data(), bandwidth); RtmpMuxUtil::WriteInt8(body->data() + 4, 2); @@ -2188,11 +2169,8 @@ namespace pvd bool RtmpStream::SendAmfConnectResult(uint32_t chunk_stream_id, double transaction_id, double object_encoding) { - auto message_header = std::make_shared(chunk_stream_id, - 0, - RtmpMessageTypeID::AMF0_COMMAND, - 0, - 0); + auto message_header = RtmpMuxMessageHeader::Create(chunk_stream_id); + AmfDocument document; // _result @@ -2229,11 +2207,9 @@ namespace pvd bool RtmpStream::SendAmfOnFCPublish(uint32_t chunk_stream_id, uint32_t stream_id, double client_id) { - auto message_header = std::make_shared(chunk_stream_id, - 0, - RtmpMessageTypeID::AMF0_COMMAND, - _rtmp_stream_id, - 0); + auto message_header = RtmpMuxMessageHeader::Create( + chunk_stream_id, RtmpMessageTypeID::AMF0_COMMAND, _rtmp_stream_id); + AmfDocument document; document.AppendProperty(RTMP_CMD_NAME_ONFCPUBLISH); @@ -2254,11 +2230,8 @@ namespace pvd bool RtmpStream::SendAmfCreateStreamResult(uint32_t chunk_stream_id, double transaction_id) { - auto message_header = std::make_shared(chunk_stream_id, - 0, - RtmpMessageTypeID::AMF0_COMMAND, - 0, - 0); + auto message_header = RtmpMuxMessageHeader::Create(chunk_stream_id); + AmfDocument document; // 스트림ID 정하기 @@ -2279,11 +2252,7 @@ namespace pvd const char *description, double client_id) { - auto message_header = std::make_shared(chunk_stream_id, - 0, - RtmpMessageTypeID::AMF0_COMMAND, - stream_id, - 0); + auto message_header = RtmpMuxMessageHeader::Create(chunk_stream_id, RtmpMessageTypeID::AMF0_COMMAND, stream_id); AmfDocument document; document.AppendProperty(RTMP_CMD_NAME_ONSTATUS);