Module rml_rtmp::chunk_io[][src]

Expand description

This module contains structs for the serialization and deserialization of RTMP chunks, as described in section 5.3 of the official RTMP specification.

The RTMP chunk format is complicated, and heavily relies on information from previously sent and received chunks. Due to this it is important that every inbound RTMP chunk is deserialized in the order it was received, and every outbound RTMP chunk is sent in the order it was received. It also means that a new ChunkSerializer or ChunkDeserializer cannot be introduced mid-stream, as chances are it will cause errors (either locally or on the connected peer).

Inbound bytes that are part of RTMP chunks are deserialized into MessagePayloads. These are data structures that contain information about the RTMP message that the chunk contained, such as timestamp, type id, the message stream id, etc…

Outbound RTMP message payloads are serialized into outbound Packets. These are a thin wrapper around the bytes representing the RTMP chunk that was created, but also creates information on if the packet is allowed to be dropped or not. Video and Audio data can uaually be marked as able to be dropped in case bandwidth limitations are encountered between the client and the server. Any packet that is not marked as being able to be dropped should not be dropped, as that is a pretty sure way to cause deserialization errors with the peer.

Inbound and outbound binary data relies on the bytes crate to provide input and output buffers with minimal allocations.

Examples

let input1 = MessagePayload {
    timestamp: RtmpTimestamp::new(55),
    message_stream_id: 1,
    type_id: 15,
    data: Bytes::from(vec![1, 2, 3, 4, 5, 6]),
};

let mut serializer = ChunkSerializer::new();
let packet1 = serializer.serialize(&input1, false, false).unwrap();

let mut deserializer = ChunkDeserializer::new();
let output1 = deserializer.get_next_message(&packet1.bytes).unwrap().unwrap();

assert_eq!(output1, input1);

Structs

ChunkDeserializationError

Data for when an error occurs while attempting to deserialize a RTMP chunk

ChunkDeserializer

Allows deserializing bytes representing RTMP chunks into RTMP message payloads.

ChunkSerializationError

Data for when an error occurs while attempting to serialize an RTMP message into RTMP chunks.

ChunkSerializer

Allows serializing RTMP messages into RTMP chunks.

Packet

An outbound data packet containing the at least one RTMP chunk with a single RTMP message. The packet can be flagged as droppable because video and audio packets may be allowed to be dropped if there is not enough bandwidth for the current bitrate. This allows live video to be kept in real time and to prevent getting backed up when redistributing live video when the network conditions don’t allow the current bitrate.

Enums

ChunkDeserializationErrorKind

An enumeration defining all the possible errors that could occur while deserializing RTMP chunks.

ChunkSerializationErrorKind

An enumeration defining all the possible errors that could occur while serializing RTMP messages into RTMP chunks.