Skip to content

Instantly share code, notes, and snippets.

@suzp1984
Created March 14, 2024 01:32
Show Gist options
  • Save suzp1984/dfe2a5d0ddccbc554be19904d913f8c5 to your computer and use it in GitHub Desktop.
Save suzp1984/dfe2a5d0ddccbc554be19904d913f8c5 to your computer and use it in GitHub Desktop.
SRS: recv RTMP message
/**
* https://rtmp.veriskope.com/docs/spec/#531chunk-format
*/
srs_error_t SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
{
srs_error_t err = srs_success;
// chunk stream basic header.
char fmt = 0;
int cid = 0;
if ((err = read_basic_header(fmt, cid)) != srs_success) {
return srs_error_wrap(err, "read basic header");
}
// the cid must not negative.
srs_assert(cid >= 0);
// get the cached chunk stream.
SrsChunkStream* chunk = NULL;
// use chunk stream cache to get the chunk info.
if (cid < SRS_PERF_CHUNK_STREAM_CACHE) {
// already init, use it direclty
chunk = cs_cache[cid];
} else {
// chunk stream cache miss, use map.
if (chunk_streams.find(cid) == chunk_streams.end()) {
chunk = chunk_streams[cid] = new SrsChunkStream(cid);
// set the perfer cid of chunk,
// which will copy to the message received.
chunk->header.perfer_cid = cid;
} else {
chunk = chunk_streams[cid];
}
}
// chunk stream message header
if ((err = read_message_header(chunk, fmt)) != srs_success) {
return srs_error_wrap(err, "read message header");
}
// read msg payload from chunk stream.
SrsCommonMessage* msg = NULL;
if ((err = read_message_payload(chunk, &msg)) != srs_success) {
return srs_error_wrap(err, "read message payload");
}
// not got an entire RTMP message, try next chunk.
if (!msg) {
return err;
}
*pmsg = msg;
return err;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment