[Mediaserver]mini_Mediaserver_1-코드설명/code description-process_complete_message()(1-6)

type이름/Name의미/Description
1Set Chunk Sizechunk_size_in_ 변경. 기본 128 → 더 큰 값으로 /
Change chunk_size_in_. Default 128 → to a larger value
3Acknowledgement클라이언트가 전송한 데이터양을 알림 / Notify the amount of data sent by the client
4User ControlPing/Pong, 스트림 제어 / stream control
5Window Ack SizeAck 보낼 용량 설정. (5MB) /
Set ACK sending capacity. (5MB)
8Audio Data오디오 프레임 데이터(payload)/
Audio frame data (payload)
9Video Data비디오 프레임 H264 데이터(payload) /
Video frame H264 data (payload)
18AMF0 DataonMetaData, @setDataFrame 등 메타 정보 / meta information
20AMF0 Commandconnect, publish, play 같은 명 / Commands like connect, publish, and play

✔️ 핑퐁제어 / Ping pong control

— cur_msg_type_ == 4 은 Ping Pong 스트림제어에 대한 부분입니다.
cur_msg_type_ == 4 is the part regarding Ping Pong stream control.

— ping요청이 들어왔을떄 응답을 구성하는 부분입니다.
This is the part that configures the response when a ping request is received.

— pong = [헤더 (Header)] + [타입 식별자 (Type)] + [실제 데이터 (Payload)]
pong = [Header] + [Type Identifier] + [Actual Data (Payload)]

std::vector<uint8_t> pong;
pong.push_back(0x02);
pong.insert(pong.end(), {0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x04});
pong.insert(pong.end(), {0x00, 0x00, 0x00, 0x00});
pong.insert(pong.end(), {0x00, 0x07}); // Pong
pong.insert(pong.end(), payload_buf_.begin() + 2, payload_buf_.begin() + 6);
asio::write(socket_, asio::buffer(pong));
std::cout << "[Server] Pong sent\n";

— 패킷 구조도 / packet structure diagram

바이트 그룹 / byte group역할 / role설명/Description
0x02상태/버전 플래그
Status/Version Flags
전체 패킷의 초기 상태 또는 버전 지정
Specifying the initial state or version of the entire packet
{0x00, ..., 0x04}메시지 헤더
message header
메시지의 크기, 길이, 전송 경로 등 구조적 정보를 정의
Defines structural information such as message size, length, and transmission path.
{0x00, x00, x00, x00}예비/패딩 필드
Spare/Padded Field
미래 확장이나 데이터 정렬을 위한 공간
Space for future expansion or data alignment
{0x00, 0x07}메시지 타입
Message Type
Pong 응답선언
Pong response declaration
(payload_buf...실제 데이터
Payload
Ping을 받았을 때 요청받은 본문 데이터를 그대로 반사(Echo)하여 포함
When a ping is received, the requested body data is reflected (echoed) and included as is.

— payload_buf_.begin() + 2과 payload_buf_.begin() + 6

1)payload_buf_begin() = [0],payload_buf_begin() + 2 = [2],payload_buf_begin() + 6 = [6]

2) 하지만 [6]은 포함안됩니다.
However, [6] is not included.

3) payload 배열의 세 번째 바이트부터 여섯 번째 바이트 직전까지의 데이터를 가져와서 pong 버퍼에 붙입니다.
It retrieves data from the payload array from the third byte up to just before the sixth byte and appends it to the pong buffer.

4) 그럼 값들은 다음과 같습니다.
Then the values ​​are as follows.

# 전체 배열 / full array

{ 0x02,0x00, [0x00, 0x00, 0x00, 0x00,] 0x06, 0x04,0x00, 0x00, 0x00, 0x00,0x00, 0x07 }

# pong.insert(pong.end(), payload_buf_.begin() + 2, payload_buf_.begin() + 6);
# poing.insert(pong.end(),start, end); --> start부터 end까지  / From start to end
# 바로 위의 코드가 실행될떄 pong에 추가되는 배열
# Array added to pong when the code immediately above is executed

[0x00, 0x00, 0x00, 0x00,]

✔️ AMF0 Command

— 나중에 따로 설명합니다.
This will be explained separately later.

else if (cur_msg_type_ == 20) {
        handle_command();
}

✔️ Audio Data

— flv_write.cpp에서 따로 설명합니다.
This is explained separately in flv_write.cpp.

✔️ Video Data

— flv_write.cpp에서 따로 설명합니다.
This is explained separately in flv_write.cpp.

— 페이로드에 담기는 모든 것은 바이트(0~255의 숫자 값) 입니다.
Everything contained in the payload is a byte (numerical value from 0 to 255).

— 이런 숫자들은 프로토콜에 따라 영상파일로 파싱됩니다.
These numbers are parsed into an image file according to the protocol.

else if (cur_msg_type_ == 9) {
        if (payload_buf_.size() >= 1 && (payload_buf_[0] & 0x0F) == 7) {
            flv_writer_->write_tag(0x09, cur_msg_timestamp_, payload_buf_);
        }
}

Leave a Reply