[Mediaserver]mini_Mediaserver_1-코드설명/code description-read_chunk_data()(1-5)

👉🏻 msg_len만큼 다 받아서 완성된 RTMP 메시지 하나를 msg_type별로 분기 처리하는 함수 입니다.
This is a function that receives msg_len and processes a completed RTMP message by branching according to msg_type.

👉🏻 전체 데이터 흐름 요약 (방송/스트리밍 관점)
Summary of Overall Data Flow (Broadcast/Streaming Perspective)

단계/Stage주체/Subject일어나는 일 (개념) /
Things that happen (concept)
기술적 표현 (데이터 상태) /
Technical representation (data state)
1. 캡처 및 변환 (Capture and Transform)카메라/마이크(Camera/Microphone)아날로그 신호(실제 빛/소리)를 디지털 데이터(숫자)로 변환합니다.(Converts analog signals (actual light/sound) into digital data (numbers).)디지털 비트(Digital Bits)
2. 압축 (Encoding)인코더 (Encoder)사람이 감지하기 어려운 중복 정보(예: 연속된 배경 색상)를 제거하여 데이터 크기를 획기적으로 줄입니다.(Significantly reduces data size by removing redundant information that is difficult for humans to detect (e.g., continuous background colors).)스트림 데이터 (Stream Data)
3. 전송 및 포장(Transport and Packaging)프로토콜/네트워크
(Protocol/Network)
이 압축된 데이터를 시간 순서대로 쪼개고, 손실되거나 순서가 꼬이는 것을 막기 위해 ‘봉투(패킷)’에 넣어 전송합니다.(This compressed data is split into chronological chunks and sent in ‘envelopes (packets)’ to prevent loss or out-of-order transmission.)패킷(Packet)
4. 수신 및 역압축
(Reception and inverse compression)
디코더 (Decoder)도착한 패킷들을 모으고, 순서를 맞추며, 압축을 풀어 원래의 데이터를 복원합니다.(It collects incoming packets, rearranges them, and decompresses them to restore the original data.)디지털 비트 복원(digital bit restoration)
5. 디스플레이(display)모니터/스피커(Monitor/Speaker)디지털 비트를 전기적 아날로그 신호로 다시 변환하여 시각적, 청각적 결과물로 출력합니다.
(It converts digital bits back into electrical analog signals and outputs them as visual and auditory results.)
아날로그 신호(analog signal)

👉🏻 코드설명 / Code Description

✔️ 이 함수가 반복해서 함수가 실행될 때 더 받아야할 데이터양 계산하기
Calculate the amount of additional data to receive when this function is executed repeatedly

    // 아직 더 받아야할 데이터 양,payload_bytes_read_ += to_read;
    uint32_t remaining = cur_msg_len_ - payload_bytes_read_;
    // 이 번에 요청한 데이터 양
    // The amount of data requested this time
    uint32_t to_read = std::min(remaining, chunk_size_in_);

✔️ 영상 프레임하나 다 받은 경우
In the case where an entire video frame has been received

— 받아야할 데이터양이 0인경우
When the amount of data to be received is 0

if (to_read == 0) {
   // msg_type별로 분기 처리하는 함수
   // Function to handle branching based on msg_type
   process_complete_message();

   //fmt,cs_id 추출,데이터 받기 다시 실행
   // Extract fmt, cs_id, retrieve data, run again
   read_chunk_header(); 
   return;
}

✔️ read_chunk_data() 함수에서 payload_buf_에 데이터 전달됩니다.
Data is passed to payload_buf_ in the read_chunk_data() function.

    asio::async_read(socket_, asio::buffer(payload_buf_.data() + offset, to_read),
        //bytes_read는 asio가 콜백 부를 때 채워주는 값,asio가 전달하는 인자.
        //bytes_read is the value that asio fills when calling the callback, an argument passed by asio.
        [this, self, to_read](std::error_code ec, std::size_t bytes_read) { ...}

✔️ 설정된 데이터 5MB를 다 받은 경우 ack보내기
Send ack when all 5MB of configured data has been received

if (bytes_received_ - last_ack_sent_ >= ack_window_size_) {
    // obs에 받응 용량 정보 전송
    // Send received capacity information to OBS
    send_acknowledgement();
}

✔️ 데이터크기 만큼 데이터를 다 받았다면 무비 파일로 파싱하기
If you have received all the data up to the data size, parse it into a movie file.

 if (payload_bytes_read_ >= cur_msg_len_) {
    // FLV 쓰거나 AMF 파싱
    // Use FLV or parse AMF
    process_complete_message();
 }

✔️ 더 받아야할데이터가 있다면 다시 반복해서 실행
If there is more data to receive, repeat the execution.

read_chunk_data();

Leave a Reply