rtmp_rs/protocol/
constants.rs

1//! RTMP protocol constants
2//!
3//! Reference: Adobe RTMP Specification (December 2012)
4//! Reference: RFC 7425 - Adobe's RTMP (Informational)
5
6/// RTMP version number (always 3 for standard RTMP)
7pub const RTMP_VERSION: u8 = 3;
8
9/// Default RTMP port
10pub const RTMP_PORT: u16 = 1935;
11
12/// Handshake packet sizes
13pub const HANDSHAKE_SIZE: usize = 1536;
14
15/// Default chunk size (per RTMP spec)
16pub const DEFAULT_CHUNK_SIZE: u32 = 128;
17
18/// Recommended chunk size for efficiency (reduces header overhead)
19pub const RECOMMENDED_CHUNK_SIZE: u32 = 4096;
20
21/// Maximum chunk size allowed
22pub const MAX_CHUNK_SIZE: u32 = 0xFFFFFF; // 16MB
23
24/// Maximum message size (sanity limit)
25pub const MAX_MESSAGE_SIZE: u32 = 16 * 1024 * 1024; // 16MB
26
27/// Extended timestamp threshold
28/// Timestamps >= this value require extended timestamp field
29pub const EXTENDED_TIMESTAMP_THRESHOLD: u32 = 0xFFFFFF;
30
31// ============================================================================
32// Chunk Stream IDs (CSID)
33// RTMP spec section 5.3.1.1
34// ============================================================================
35
36/// Protocol control messages (Set Chunk Size, Abort, etc.)
37pub const CSID_PROTOCOL_CONTROL: u32 = 2;
38
39/// Command messages (connect, createStream, etc.)
40pub const CSID_COMMAND: u32 = 3;
41
42/// Audio data
43pub const CSID_AUDIO: u32 = 4;
44
45/// Video data
46pub const CSID_VIDEO: u32 = 6;
47
48// ============================================================================
49// Message Type IDs
50// RTMP spec section 5.4
51// ============================================================================
52
53/// Set Chunk Size (1) - protocol control
54pub const MSG_SET_CHUNK_SIZE: u8 = 1;
55
56/// Abort Message (2) - protocol control
57pub const MSG_ABORT: u8 = 2;
58
59/// Acknowledgement (3) - protocol control
60pub const MSG_ACKNOWLEDGEMENT: u8 = 3;
61
62/// User Control Message (4) - protocol control
63pub const MSG_USER_CONTROL: u8 = 4;
64
65/// Window Acknowledgement Size (5) - protocol control
66pub const MSG_WINDOW_ACK_SIZE: u8 = 5;
67
68/// Set Peer Bandwidth (6) - protocol control
69pub const MSG_SET_PEER_BANDWIDTH: u8 = 6;
70
71/// Audio Message (8)
72pub const MSG_AUDIO: u8 = 8;
73
74/// Video Message (9)
75pub const MSG_VIDEO: u8 = 9;
76
77/// AMF3 Data Message (15) - @setDataFrame with AMF3
78pub const MSG_DATA_AMF3: u8 = 15;
79
80/// AMF3 Shared Object (16)
81pub const MSG_SHARED_OBJECT_AMF3: u8 = 16;
82
83/// AMF3 Command Message (17)
84pub const MSG_COMMAND_AMF3: u8 = 17;
85
86/// AMF0 Data Message (18) - @setDataFrame, onMetaData
87pub const MSG_DATA_AMF0: u8 = 18;
88
89/// AMF0 Shared Object (19)
90pub const MSG_SHARED_OBJECT_AMF0: u8 = 19;
91
92/// AMF0 Command Message (20) - connect, play, publish, etc.
93pub const MSG_COMMAND_AMF0: u8 = 20;
94
95/// Aggregate Message (22)
96pub const MSG_AGGREGATE: u8 = 22;
97
98// ============================================================================
99// User Control Event Types
100// RTMP spec section 5.4.1
101// ============================================================================
102
103/// Stream Begin - server sends when stream becomes functional
104pub const UC_STREAM_BEGIN: u16 = 0;
105
106/// Stream EOF - server sends when playback ends
107pub const UC_STREAM_EOF: u16 = 1;
108
109/// Stream Dry - no more data available
110pub const UC_STREAM_DRY: u16 = 2;
111
112/// Set Buffer Length - client tells server buffer size
113pub const UC_SET_BUFFER_LENGTH: u16 = 3;
114
115/// Stream Is Recorded - stream is recorded
116pub const UC_STREAM_IS_RECORDED: u16 = 4;
117
118/// Ping Request - server pings client
119pub const UC_PING_REQUEST: u16 = 6;
120
121/// Ping Response - client responds to ping
122pub const UC_PING_RESPONSE: u16 = 7;
123
124// ============================================================================
125// Peer Bandwidth Limit Types
126// RTMP spec section 5.4.5
127// ============================================================================
128
129/// Hard limit - peer should limit output to this bandwidth
130pub const BANDWIDTH_LIMIT_HARD: u8 = 0;
131
132/// Soft limit - peer can exceed if it has excess bandwidth
133pub const BANDWIDTH_LIMIT_SOFT: u8 = 1;
134
135/// Dynamic - can be hard or soft depending on prior state
136pub const BANDWIDTH_LIMIT_DYNAMIC: u8 = 2;
137
138// ============================================================================
139// Common Command Names
140// ============================================================================
141
142pub const CMD_CONNECT: &str = "connect";
143pub const CMD_CALL: &str = "call";
144pub const CMD_CLOSE: &str = "close";
145pub const CMD_CREATE_STREAM: &str = "createStream";
146pub const CMD_DELETE_STREAM: &str = "deleteStream";
147pub const CMD_PLAY: &str = "play";
148pub const CMD_PLAY2: &str = "play2";
149pub const CMD_PUBLISH: &str = "publish";
150pub const CMD_PAUSE: &str = "pause";
151pub const CMD_SEEK: &str = "seek";
152pub const CMD_RECEIVE_AUDIO: &str = "receiveAudio";
153pub const CMD_RECEIVE_VIDEO: &str = "receiveVideo";
154
155/// Internal response commands
156pub const CMD_RESULT: &str = "_result";
157pub const CMD_ERROR: &str = "_error";
158
159/// Status notification
160pub const CMD_ON_STATUS: &str = "onStatus";
161
162// OBS/Twitch extended commands
163pub const CMD_FC_PUBLISH: &str = "FCPublish";
164pub const CMD_FC_UNPUBLISH: &str = "FCUnpublish";
165pub const CMD_RELEASE_STREAM: &str = "releaseStream";
166pub const CMD_ON_FC_PUBLISH: &str = "onFCPublish";
167pub const CMD_ON_FC_UNPUBLISH: &str = "onFCUnpublish";
168
169// Data commands
170pub const CMD_SET_DATA_FRAME: &str = "@setDataFrame";
171pub const CMD_ON_METADATA: &str = "onMetaData";
172
173// ============================================================================
174// NetConnection Status Codes
175// ============================================================================
176
177pub const NC_CONNECT_SUCCESS: &str = "NetConnection.Connect.Success";
178pub const NC_CONNECT_REJECTED: &str = "NetConnection.Connect.Rejected";
179pub const NC_CONNECT_FAILED: &str = "NetConnection.Connect.Failed";
180pub const NC_CONNECT_CLOSED: &str = "NetConnection.Connect.Closed";
181
182// ============================================================================
183// NetStream Status Codes
184// ============================================================================
185
186pub const NS_PUBLISH_START: &str = "NetStream.Publish.Start";
187pub const NS_PUBLISH_BAD_NAME: &str = "NetStream.Publish.BadName";
188pub const NS_PLAY_START: &str = "NetStream.Play.Start";
189pub const NS_PLAY_RESET: &str = "NetStream.Play.Reset";
190pub const NS_PLAY_STOP: &str = "NetStream.Play.Stop";
191pub const NS_PLAY_STREAM_NOT_FOUND: &str = "NetStream.Play.StreamNotFound";
192pub const NS_PAUSE_NOTIFY: &str = "NetStream.Pause.Notify";
193pub const NS_UNPAUSE_NOTIFY: &str = "NetStream.Unpause.Notify";
194
195// ============================================================================
196// Default Server Settings
197// ============================================================================
198
199/// Default window acknowledgement size (2.5 MB)
200pub const DEFAULT_WINDOW_ACK_SIZE: u32 = 2_500_000;
201
202/// Default peer bandwidth (2.5 MB)
203pub const DEFAULT_PEER_BANDWIDTH: u32 = 2_500_000;
204
205/// Default buffer length in milliseconds
206pub const DEFAULT_BUFFER_LENGTH: u32 = 1000;
207
208// ============================================================================
209// Chunk Header Format Types (fmt field)
210// RTMP spec section 5.3.1.2
211// ============================================================================
212
213/// Type 0: Full header (11 bytes) - timestamp, length, type, stream ID
214pub const CHUNK_FMT_0: u8 = 0;
215
216/// Type 1: No stream ID (7 bytes) - timestamp delta, length, type
217pub const CHUNK_FMT_1: u8 = 1;
218
219/// Type 2: No stream ID, length, type (3 bytes) - timestamp delta only
220pub const CHUNK_FMT_2: u8 = 2;
221
222/// Type 3: No header (0 bytes) - use previous chunk's values
223pub const CHUNK_FMT_3: u8 = 3;