finish basic protocol utest, fix the bug of fmt11 length error.
正在显示
4 个修改的文件
包含
98 行增加
和
80 行删除
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "154" | 34 | +#define VERSION_REVISION "155" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
| @@ -50,13 +50,13 @@ reserved for usage with RTM Chunk Stream protocol. Protocol messages | @@ -50,13 +50,13 @@ reserved for usage with RTM Chunk Stream protocol. Protocol messages | ||
| 50 | with IDs 3-6 are reserved for usage of RTMP. Protocol message with ID | 50 | with IDs 3-6 are reserved for usage of RTMP. Protocol message with ID |
| 51 | 7 is used between edge server and origin server. | 51 | 7 is used between edge server and origin server. |
| 52 | */ | 52 | */ |
| 53 | -#define RTMP_MSG_SetChunkSize 0x01 | ||
| 54 | -#define RTMP_MSG_AbortMessage 0x02 | ||
| 55 | -#define RTMP_MSG_Acknowledgement 0x03 | ||
| 56 | -#define RTMP_MSG_UserControlMessage 0x04 | ||
| 57 | -#define RTMP_MSG_WindowAcknowledgementSize 0x05 | ||
| 58 | -#define RTMP_MSG_SetPeerBandwidth 0x06 | ||
| 59 | -#define RTMP_MSG_EdgeAndOriginServerCommand 0x07 | 53 | +#define RTMP_MSG_SetChunkSize 0x01 |
| 54 | +#define RTMP_MSG_AbortMessage 0x02 | ||
| 55 | +#define RTMP_MSG_Acknowledgement 0x03 | ||
| 56 | +#define RTMP_MSG_UserControlMessage 0x04 | ||
| 57 | +#define RTMP_MSG_WindowAcknowledgementSize 0x05 | ||
| 58 | +#define RTMP_MSG_SetPeerBandwidth 0x06 | ||
| 59 | +#define RTMP_MSG_EdgeAndOriginServerCommand 0x07 | ||
| 60 | /** | 60 | /** |
| 61 | 3. Types of messages | 61 | 3. Types of messages |
| 62 | The server and the client send messages over the network to | 62 | The server and the client send messages over the network to |
| @@ -76,8 +76,8 @@ contains related parameters. A client or a server can request Remote | @@ -76,8 +76,8 @@ contains related parameters. A client or a server can request Remote | ||
| 76 | Procedure Calls (RPC) over streams that are communicated using the | 76 | Procedure Calls (RPC) over streams that are communicated using the |
| 77 | command messages to the peer. | 77 | command messages to the peer. |
| 78 | */ | 78 | */ |
| 79 | -#define RTMP_MSG_AMF3CommandMessage 17 // 0x11 | ||
| 80 | -#define RTMP_MSG_AMF0CommandMessage 20 // 0x14 | 79 | +#define RTMP_MSG_AMF3CommandMessage 17 // 0x11 |
| 80 | +#define RTMP_MSG_AMF0CommandMessage 20 // 0x14 | ||
| 81 | /** | 81 | /** |
| 82 | 3.2. Data message | 82 | 3.2. Data message |
| 83 | The client or the server sends this message to send Metadata or any | 83 | The client or the server sends this message to send Metadata or any |
| @@ -86,8 +86,8 @@ data(audio, video etc.) like creation time, duration, theme and so | @@ -86,8 +86,8 @@ data(audio, video etc.) like creation time, duration, theme and so | ||
| 86 | on. These messages have been assigned message type value of 18 for | 86 | on. These messages have been assigned message type value of 18 for |
| 87 | AMF0 and message type value of 15 for AMF3. | 87 | AMF0 and message type value of 15 for AMF3. |
| 88 | */ | 88 | */ |
| 89 | -#define RTMP_MSG_AMF0DataMessage 18 // 0x12 | ||
| 90 | -#define RTMP_MSG_AMF3DataMessage 15 // 0x0F | 89 | +#define RTMP_MSG_AMF0DataMessage 18 // 0x12 |
| 90 | +#define RTMP_MSG_AMF3DataMessage 15 // 0x0F | ||
| 91 | /** | 91 | /** |
| 92 | 3.3. Shared object message | 92 | 3.3. Shared object message |
| 93 | A shared object is a Flash object (a collection of name value pairs) | 93 | A shared object is a Flash object (a collection of name value pairs) |
| @@ -96,14 +96,14 @@ so on. The message types kMsgContainer=19 for AMF0 and | @@ -96,14 +96,14 @@ so on. The message types kMsgContainer=19 for AMF0 and | ||
| 96 | kMsgContainerEx=16 for AMF3 are reserved for shared object events. | 96 | kMsgContainerEx=16 for AMF3 are reserved for shared object events. |
| 97 | Each message can contain multiple events. | 97 | Each message can contain multiple events. |
| 98 | */ | 98 | */ |
| 99 | -#define RTMP_MSG_AMF3SharedObject 16 // 0x10 | ||
| 100 | -#define RTMP_MSG_AMF0SharedObject 19 // 0x13 | 99 | +#define RTMP_MSG_AMF3SharedObject 16 // 0x10 |
| 100 | +#define RTMP_MSG_AMF0SharedObject 19 // 0x13 | ||
| 101 | /** | 101 | /** |
| 102 | 3.4. Audio message | 102 | 3.4. Audio message |
| 103 | The client or the server sends this message to send audio data to the | 103 | The client or the server sends this message to send audio data to the |
| 104 | peer. The message type value of 8 is reserved for audio messages. | 104 | peer. The message type value of 8 is reserved for audio messages. |
| 105 | */ | 105 | */ |
| 106 | -#define RTMP_MSG_AudioMessage 8 // 0x08 | 106 | +#define RTMP_MSG_AudioMessage 8 // 0x08 |
| 107 | /* * | 107 | /* * |
| 108 | 3.5. Video message | 108 | 3.5. Video message |
| 109 | The client or the server sends this message to send video data to the | 109 | The client or the server sends this message to send video data to the |
| @@ -112,14 +112,14 @@ These messages are large and can delay the sending of other type of | @@ -112,14 +112,14 @@ These messages are large and can delay the sending of other type of | ||
| 112 | messages. To avoid such a situation, the video message is assigned | 112 | messages. To avoid such a situation, the video message is assigned |
| 113 | the lowest priority. | 113 | the lowest priority. |
| 114 | */ | 114 | */ |
| 115 | -#define RTMP_MSG_VideoMessage 9 // 0x09 | 115 | +#define RTMP_MSG_VideoMessage 9 // 0x09 |
| 116 | /** | 116 | /** |
| 117 | 3.6. Aggregate message | 117 | 3.6. Aggregate message |
| 118 | An aggregate message is a single message that contains a list of submessages. | 118 | An aggregate message is a single message that contains a list of submessages. |
| 119 | The message type value of 22 is reserved for aggregate | 119 | The message type value of 22 is reserved for aggregate |
| 120 | messages. | 120 | messages. |
| 121 | */ | 121 | */ |
| 122 | -#define RTMP_MSG_AggregateMessage 22 // 0x16 | 122 | +#define RTMP_MSG_AggregateMessage 22 // 0x16 |
| 123 | 123 | ||
| 124 | /**************************************************************************** | 124 | /**************************************************************************** |
| 125 | ***************************************************************************** | 125 | ***************************************************************************** |
| @@ -133,21 +133,21 @@ messages. | @@ -133,21 +133,21 @@ messages. | ||
| 133 | // Chunks of Type 0 are 11 bytes long. This type MUST be used at the | 133 | // Chunks of Type 0 are 11 bytes long. This type MUST be used at the |
| 134 | // start of a chunk stream, and whenever the stream timestamp goes | 134 | // start of a chunk stream, and whenever the stream timestamp goes |
| 135 | // backward (e.g., because of a backward seek). | 135 | // backward (e.g., because of a backward seek). |
| 136 | -#define RTMP_FMT_TYPE0 0 | 136 | +#define RTMP_FMT_TYPE0 0 |
| 137 | // 6.1.2.2. Type 1 | 137 | // 6.1.2.2. Type 1 |
| 138 | // Chunks of Type 1 are 7 bytes long. The message stream ID is not | 138 | // Chunks of Type 1 are 7 bytes long. The message stream ID is not |
| 139 | // included; this chunk takes the same stream ID as the preceding chunk. | 139 | // included; this chunk takes the same stream ID as the preceding chunk. |
| 140 | // Streams with variable-sized messages (for example, many video | 140 | // Streams with variable-sized messages (for example, many video |
| 141 | // formats) SHOULD use this format for the first chunk of each new | 141 | // formats) SHOULD use this format for the first chunk of each new |
| 142 | // message after the first. | 142 | // message after the first. |
| 143 | -#define RTMP_FMT_TYPE1 1 | 143 | +#define RTMP_FMT_TYPE1 1 |
| 144 | // 6.1.2.3. Type 2 | 144 | // 6.1.2.3. Type 2 |
| 145 | // Chunks of Type 2 are 3 bytes long. Neither the stream ID nor the | 145 | // Chunks of Type 2 are 3 bytes long. Neither the stream ID nor the |
| 146 | // message length is included; this chunk has the same stream ID and | 146 | // message length is included; this chunk has the same stream ID and |
| 147 | // message length as the preceding chunk. Streams with constant-sized | 147 | // message length as the preceding chunk. Streams with constant-sized |
| 148 | // messages (for example, some audio and data formats) SHOULD use this | 148 | // messages (for example, some audio and data formats) SHOULD use this |
| 149 | // format for the first chunk of each message after the first. | 149 | // format for the first chunk of each message after the first. |
| 150 | -#define RTMP_FMT_TYPE2 2 | 150 | +#define RTMP_FMT_TYPE2 2 |
| 151 | // 6.1.2.4. Type 3 | 151 | // 6.1.2.4. Type 3 |
| 152 | // Chunks of Type 3 have no header. Stream ID, message length and | 152 | // Chunks of Type 3 have no header. Stream ID, message length and |
| 153 | // timestamp delta are not present; chunks of this type take values from | 153 | // timestamp delta are not present; chunks of this type take values from |
| @@ -162,7 +162,7 @@ messages. | @@ -162,7 +162,7 @@ messages. | ||
| 162 | // need for a chunk of type 2 to register the delta. If Type 3 chunk | 162 | // need for a chunk of type 2 to register the delta. If Type 3 chunk |
| 163 | // follows a Type 0 chunk, then timestamp delta for this Type 3 chunk is | 163 | // follows a Type 0 chunk, then timestamp delta for this Type 3 chunk is |
| 164 | // the same as the timestamp of Type 0 chunk. | 164 | // the same as the timestamp of Type 0 chunk. |
| 165 | -#define RTMP_FMT_TYPE3 3 | 165 | +#define RTMP_FMT_TYPE3 3 |
| 166 | 166 | ||
| 167 | /**************************************************************************** | 167 | /**************************************************************************** |
| 168 | ***************************************************************************** | 168 | ***************************************************************************** |
| @@ -177,9 +177,9 @@ messages. | @@ -177,9 +177,9 @@ messages. | ||
| 177 | * good for high-bit rate streaming. Chunk size is maintained | 177 | * good for high-bit rate streaming. Chunk size is maintained |
| 178 | * independently for each direction. | 178 | * independently for each direction. |
| 179 | */ | 179 | */ |
| 180 | -#define RTMP_DEFAULT_CHUNK_SIZE 128 | ||
| 181 | -#define RTMP_MIN_CHUNK_SIZE 128 | ||
| 182 | -#define RTMP_MAX_CHUNK_SIZE 65536 | 180 | +#define RTMP_DEFAULT_CHUNK_SIZE 128 |
| 181 | +#define RTMP_MIN_CHUNK_SIZE 128 | ||
| 182 | +#define RTMP_MAX_CHUNK_SIZE 65536 | ||
| 183 | 183 | ||
| 184 | /** | 184 | /** |
| 185 | * 6.1. Chunk Format | 185 | * 6.1. Chunk Format |
| @@ -192,7 +192,7 @@ messages. | @@ -192,7 +192,7 @@ messages. | ||
| 192 | * the normal timestamp field MUST NOT be used and MUST be set to | 192 | * the normal timestamp field MUST NOT be used and MUST be set to |
| 193 | * 0xffffff and the extended timestamp MUST be sent. | 193 | * 0xffffff and the extended timestamp MUST be sent. |
| 194 | */ | 194 | */ |
| 195 | -#define RTMP_EXTENDED_TIMESTAMP 0xFFFFFF | 195 | +#define RTMP_EXTENDED_TIMESTAMP 0xFFFFFF |
| 196 | 196 | ||
| 197 | /**************************************************************************** | 197 | /**************************************************************************** |
| 198 | ***************************************************************************** | 198 | ***************************************************************************** |
| @@ -200,22 +200,22 @@ messages. | @@ -200,22 +200,22 @@ messages. | ||
| 200 | /** | 200 | /** |
| 201 | * amf0 command message, command name macros | 201 | * amf0 command message, command name macros |
| 202 | */ | 202 | */ |
| 203 | -#define RTMP_AMF0_COMMAND_CONNECT "connect" | ||
| 204 | -#define RTMP_AMF0_COMMAND_CREATE_STREAM "createStream" | ||
| 205 | -#define RTMP_AMF0_COMMAND_CLOSE_STREAM "closeStream" | ||
| 206 | -#define RTMP_AMF0_COMMAND_PLAY "play" | ||
| 207 | -#define RTMP_AMF0_COMMAND_PAUSE "pause" | ||
| 208 | -#define RTMP_AMF0_COMMAND_ON_BW_DONE "onBWDone" | ||
| 209 | -#define RTMP_AMF0_COMMAND_ON_STATUS "onStatus" | ||
| 210 | -#define RTMP_AMF0_COMMAND_RESULT "_result" | ||
| 211 | -#define RTMP_AMF0_COMMAND_ERROR "_error" | ||
| 212 | -#define RTMP_AMF0_COMMAND_RELEASE_STREAM "releaseStream" | ||
| 213 | -#define RTMP_AMF0_COMMAND_FC_PUBLISH "FCPublish" | ||
| 214 | -#define RTMP_AMF0_COMMAND_UNPUBLISH "FCUnpublish" | ||
| 215 | -#define RTMP_AMF0_COMMAND_PUBLISH "publish" | ||
| 216 | -#define RTMP_AMF0_DATA_SAMPLE_ACCESS "|RtmpSampleAccess" | ||
| 217 | -#define RTMP_AMF0_DATA_SET_DATAFRAME "@setDataFrame" | ||
| 218 | -#define RTMP_AMF0_DATA_ON_METADATA "onMetaData" | 203 | +#define RTMP_AMF0_COMMAND_CONNECT "connect" |
| 204 | +#define RTMP_AMF0_COMMAND_CREATE_STREAM "createStream" | ||
| 205 | +#define RTMP_AMF0_COMMAND_CLOSE_STREAM "closeStream" | ||
| 206 | +#define RTMP_AMF0_COMMAND_PLAY "play" | ||
| 207 | +#define RTMP_AMF0_COMMAND_PAUSE "pause" | ||
| 208 | +#define RTMP_AMF0_COMMAND_ON_BW_DONE "onBWDone" | ||
| 209 | +#define RTMP_AMF0_COMMAND_ON_STATUS "onStatus" | ||
| 210 | +#define RTMP_AMF0_COMMAND_RESULT "_result" | ||
| 211 | +#define RTMP_AMF0_COMMAND_ERROR "_error" | ||
| 212 | +#define RTMP_AMF0_COMMAND_RELEASE_STREAM "releaseStream" | ||
| 213 | +#define RTMP_AMF0_COMMAND_FC_PUBLISH "FCPublish" | ||
| 214 | +#define RTMP_AMF0_COMMAND_UNPUBLISH "FCUnpublish" | ||
| 215 | +#define RTMP_AMF0_COMMAND_PUBLISH "publish" | ||
| 216 | +#define RTMP_AMF0_DATA_SAMPLE_ACCESS "|RtmpSampleAccess" | ||
| 217 | +#define RTMP_AMF0_DATA_SET_DATAFRAME "@setDataFrame" | ||
| 218 | +#define RTMP_AMF0_DATA_ON_METADATA "onMetaData" | ||
| 219 | 219 | ||
| 220 | /** | 220 | /** |
| 221 | * band width check method name, which will be invoked by client. | 221 | * band width check method name, which will be invoked by client. |
| @@ -223,28 +223,28 @@ messages. | @@ -223,28 +223,28 @@ messages. | ||
| 223 | * so ensure you set command name when you use it. | 223 | * so ensure you set command name when you use it. |
| 224 | */ | 224 | */ |
| 225 | // server play control | 225 | // server play control |
| 226 | -#define SRS_BW_CHECK_START_PLAY "onSrsBandCheckStartPlayBytes" | ||
| 227 | -#define SRS_BW_CHECK_STARTING_PLAY "onSrsBandCheckStartingPlayBytes" | ||
| 228 | -#define SRS_BW_CHECK_STOP_PLAY "onSrsBandCheckStopPlayBytes" | ||
| 229 | -#define SRS_BW_CHECK_STOPPED_PLAY "onSrsBandCheckStoppedPlayBytes" | 226 | +#define SRS_BW_CHECK_START_PLAY "onSrsBandCheckStartPlayBytes" |
| 227 | +#define SRS_BW_CHECK_STARTING_PLAY "onSrsBandCheckStartingPlayBytes" | ||
| 228 | +#define SRS_BW_CHECK_STOP_PLAY "onSrsBandCheckStopPlayBytes" | ||
| 229 | +#define SRS_BW_CHECK_STOPPED_PLAY "onSrsBandCheckStoppedPlayBytes" | ||
| 230 | 230 | ||
| 231 | // server publish control | 231 | // server publish control |
| 232 | -#define SRS_BW_CHECK_START_PUBLISH "onSrsBandCheckStartPublishBytes" | ||
| 233 | -#define SRS_BW_CHECK_STARTING_PUBLISH "onSrsBandCheckStartingPublishBytes" | ||
| 234 | -#define SRS_BW_CHECK_STOP_PUBLISH "onSrsBandCheckStopPublishBytes" | ||
| 235 | -#define SRS_BW_CHECK_STOPPED_PUBLISH "onSrsBandCheckStoppedPublishBytes" | 232 | +#define SRS_BW_CHECK_START_PUBLISH "onSrsBandCheckStartPublishBytes" |
| 233 | +#define SRS_BW_CHECK_STARTING_PUBLISH "onSrsBandCheckStartingPublishBytes" | ||
| 234 | +#define SRS_BW_CHECK_STOP_PUBLISH "onSrsBandCheckStopPublishBytes" | ||
| 235 | +#define SRS_BW_CHECK_STOPPED_PUBLISH "onSrsBandCheckStoppedPublishBytes" | ||
| 236 | 236 | ||
| 237 | // EOF control. | 237 | // EOF control. |
| 238 | -#define SRS_BW_CHECK_FINISHED "onSrsBandCheckFinished" | 238 | +#define SRS_BW_CHECK_FINISHED "onSrsBandCheckFinished" |
| 239 | // for flash, it will sendout a final call, | 239 | // for flash, it will sendout a final call, |
| 240 | // used to confirm got the report. | 240 | // used to confirm got the report. |
| 241 | // actually, client send out this packet and close the connection, | 241 | // actually, client send out this packet and close the connection, |
| 242 | // so server may cannot got this packet, ignore is ok. | 242 | // so server may cannot got this packet, ignore is ok. |
| 243 | -#define SRS_BW_CHECK_FLASH_FINAL "finalClientPacket" | 243 | +#define SRS_BW_CHECK_FLASH_FINAL "finalClientPacket" |
| 244 | 244 | ||
| 245 | // client only | 245 | // client only |
| 246 | -#define SRS_BW_CHECK_PLAYING "onSrsBandCheckPlaying" | ||
| 247 | -#define SRS_BW_CHECK_PUBLISHING "onSrsBandCheckPublishing" | 246 | +#define SRS_BW_CHECK_PLAYING "onSrsBandCheckPlaying" |
| 247 | +#define SRS_BW_CHECK_PUBLISHING "onSrsBandCheckPublishing" | ||
| 248 | 248 | ||
| 249 | /**************************************************************************** | 249 | /**************************************************************************** |
| 250 | ***************************************************************************** | 250 | ***************************************************************************** |
| @@ -253,38 +253,38 @@ messages. | @@ -253,38 +253,38 @@ messages. | ||
| 253 | * the chunk stream id used for some under-layer message, | 253 | * the chunk stream id used for some under-layer message, |
| 254 | * for example, the PC(protocol control) message. | 254 | * for example, the PC(protocol control) message. |
| 255 | */ | 255 | */ |
| 256 | -#define RTMP_CID_ProtocolControl 0x02 | 256 | +#define RTMP_CID_ProtocolControl 0x02 |
| 257 | /** | 257 | /** |
| 258 | * the AMF0/AMF3 command message, invoke method and return the result, over NetConnection. | 258 | * the AMF0/AMF3 command message, invoke method and return the result, over NetConnection. |
| 259 | * generally use 0x03. | 259 | * generally use 0x03. |
| 260 | */ | 260 | */ |
| 261 | -#define RTMP_CID_OverConnection 0x03 | 261 | +#define RTMP_CID_OverConnection 0x03 |
| 262 | /** | 262 | /** |
| 263 | * the AMF0/AMF3 command message, invoke method and return the result, over NetConnection, | 263 | * the AMF0/AMF3 command message, invoke method and return the result, over NetConnection, |
| 264 | * the midst state(we guess). | 264 | * the midst state(we guess). |
| 265 | * rarely used, e.g. onStatus(NetStream.Play.Reset). | 265 | * rarely used, e.g. onStatus(NetStream.Play.Reset). |
| 266 | */ | 266 | */ |
| 267 | -#define RTMP_CID_OverConnection2 0x04 | 267 | +#define RTMP_CID_OverConnection2 0x04 |
| 268 | /** | 268 | /** |
| 269 | * the stream message(amf0/amf3), over NetStream. | 269 | * the stream message(amf0/amf3), over NetStream. |
| 270 | * generally use 0x05. | 270 | * generally use 0x05. |
| 271 | */ | 271 | */ |
| 272 | -#define RTMP_CID_OverStream 0x05 | 272 | +#define RTMP_CID_OverStream 0x05 |
| 273 | /** | 273 | /** |
| 274 | * the stream message(amf0/amf3), over NetStream, the midst state(we guess). | 274 | * the stream message(amf0/amf3), over NetStream, the midst state(we guess). |
| 275 | * rarely used, e.g. play("mp4:mystram.f4v") | 275 | * rarely used, e.g. play("mp4:mystram.f4v") |
| 276 | */ | 276 | */ |
| 277 | -#define RTMP_CID_OverStream2 0x08 | 277 | +#define RTMP_CID_OverStream2 0x08 |
| 278 | /** | 278 | /** |
| 279 | * the stream message(video), over NetStream | 279 | * the stream message(video), over NetStream |
| 280 | * generally use 0x06. | 280 | * generally use 0x06. |
| 281 | */ | 281 | */ |
| 282 | -#define RTMP_CID_Video 0x06 | 282 | +#define RTMP_CID_Video 0x06 |
| 283 | /** | 283 | /** |
| 284 | * the stream message(audio), over NetStream. | 284 | * the stream message(audio), over NetStream. |
| 285 | * generally use 0x07. | 285 | * generally use 0x07. |
| 286 | */ | 286 | */ |
| 287 | -#define RTMP_CID_Audio 0x07 | 287 | +#define RTMP_CID_Audio 0x07 |
| 288 | 288 | ||
| 289 | /**************************************************************************** | 289 | /**************************************************************************** |
| 290 | ***************************************************************************** | 290 | ***************************************************************************** |
| @@ -935,11 +935,11 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -935,11 +935,11 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 935 | * (when first packet, the chunk->msg is NULL). | 935 | * (when first packet, the chunk->msg is NULL). |
| 936 | * the fmt maybe 0/1/2/3, the FMLE will send a 0xC4 for some audio packet. | 936 | * the fmt maybe 0/1/2/3, the FMLE will send a 0xC4 for some audio packet. |
| 937 | * the previous packet is: | 937 | * the previous packet is: |
| 938 | - * 04 // fmt=0, cid=4 | ||
| 939 | - * 00 00 1a // timestamp=26 | ||
| 940 | - * 00 00 9d // payload_length=157 | ||
| 941 | - * 08 // message_type=8(audio) | ||
| 942 | - * 01 00 00 00 // stream_id=1 | 938 | + * 04 // fmt=0, cid=4 |
| 939 | + * 00 00 1a // timestamp=26 | ||
| 940 | + * 00 00 9d // payload_length=157 | ||
| 941 | + * 08 // message_type=8(audio) | ||
| 942 | + * 01 00 00 00 // stream_id=1 | ||
| 943 | * the current packet maybe: | 943 | * the current packet maybe: |
| 944 | * c4 // fmt=3, cid=4 | 944 | * c4 // fmt=3, cid=4 |
| 945 | * it's ok, for the packet is audio, and timestamp delta is 26. | 945 | * it's ok, for the packet is audio, and timestamp delta is 26. |
| @@ -1013,6 +1013,11 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -1013,6 +1013,11 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 1013 | * 3bytes: payload length, fmt=0,1 | 1013 | * 3bytes: payload length, fmt=0,1 |
| 1014 | * 1bytes: message type, fmt=0,1 | 1014 | * 1bytes: message type, fmt=0,1 |
| 1015 | * 4bytes: stream id, fmt=0 | 1015 | * 4bytes: stream id, fmt=0 |
| 1016 | + * where: | ||
| 1017 | + * fmt=0, 0x0X | ||
| 1018 | + * fmt=1, 0x4X | ||
| 1019 | + * fmt=2, 0x8X | ||
| 1020 | + * fmt=3, 0xCX | ||
| 1016 | */ | 1021 | */ |
| 1017 | // see also: ngx_rtmp_recv | 1022 | // see also: ngx_rtmp_recv |
| 1018 | if (fmt <= RTMP_FMT_TYPE2) { | 1023 | if (fmt <= RTMP_FMT_TYPE2) { |
| @@ -1060,21 +1065,25 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -1060,21 +1065,25 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 1060 | } | 1065 | } |
| 1061 | 1066 | ||
| 1062 | if (fmt <= RTMP_FMT_TYPE1) { | 1067 | if (fmt <= RTMP_FMT_TYPE1) { |
| 1063 | - pp = (char*)&chunk->header.payload_length; | 1068 | + int32_t payload_length = 0; |
| 1069 | + pp = (char*)&payload_length; | ||
| 1064 | pp[2] = *p++; | 1070 | pp[2] = *p++; |
| 1065 | pp[1] = *p++; | 1071 | pp[1] = *p++; |
| 1066 | pp[0] = *p++; | 1072 | pp[0] = *p++; |
| 1067 | pp[3] = 0; | 1073 | pp[3] = 0; |
| 1068 | 1074 | ||
| 1069 | // if msg exists in cache, the size must not changed. | 1075 | // if msg exists in cache, the size must not changed. |
| 1070 | - if (chunk->msg->size > 0 && chunk->msg->size != chunk->header.payload_length) { | 1076 | + // always use the actual msg size, for the cache payload length can changed, |
| 1077 | + // for the fmt type1(stream_id not changed), user can change the payload length. | ||
| 1078 | + if (chunk->msg->size > 0 && chunk->header.payload_length != payload_length) { | ||
| 1071 | ret = ERROR_RTMP_PACKET_SIZE; | 1079 | ret = ERROR_RTMP_PACKET_SIZE; |
| 1072 | srs_error("msg exists in chunk cache, " | 1080 | srs_error("msg exists in chunk cache, " |
| 1073 | "size=%d cannot change to %d, ret=%d", | 1081 | "size=%d cannot change to %d, ret=%d", |
| 1074 | - chunk->msg->size, chunk->header.payload_length, ret); | 1082 | + chunk->header.payload_length, payload_length, ret); |
| 1075 | return ret; | 1083 | return ret; |
| 1076 | } | 1084 | } |
| 1077 | 1085 | ||
| 1086 | + chunk->header.payload_length = payload_length; | ||
| 1078 | chunk->header.message_type = *p++; | 1087 | chunk->header.message_type = *p++; |
| 1079 | 1088 | ||
| 1080 | if (fmt == RTMP_FMT_TYPE0) { | 1089 | if (fmt == RTMP_FMT_TYPE0) { |
| @@ -256,23 +256,27 @@ class SrsMessageHeader | @@ -256,23 +256,27 @@ class SrsMessageHeader | ||
| 256 | { | 256 | { |
| 257 | public: | 257 | public: |
| 258 | /** | 258 | /** |
| 259 | - * One byte field to represent the message type. A range of type IDs | ||
| 260 | - * (1-7) are reserved for protocol control messages. | 259 | + * 3bytes. |
| 260 | + * Three-byte field that contains a timestamp delta of the message. | ||
| 261 | + * The 4 bytes are packed in the big-endian order. | ||
| 262 | + * @remark, only used for decoding message from chunk stream. | ||
| 261 | */ | 263 | */ |
| 262 | - int8_t message_type; | 264 | + int32_t timestamp_delta; |
| 263 | /** | 265 | /** |
| 266 | + * 3bytes. | ||
| 264 | * Three-byte field that represents the size of the payload in bytes. | 267 | * Three-byte field that represents the size of the payload in bytes. |
| 265 | * It is set in big-endian format. | 268 | * It is set in big-endian format. |
| 266 | */ | 269 | */ |
| 267 | int32_t payload_length; | 270 | int32_t payload_length; |
| 268 | /** | 271 | /** |
| 269 | - * Three-byte field that contains a timestamp delta of the message. | ||
| 270 | - * The 4 bytes are packed in the big-endian order. | ||
| 271 | - * @remark, only used for decoding message from chunk stream. | 272 | + * 1byte. |
| 273 | + * One byte field to represent the message type. A range of type IDs | ||
| 274 | + * (1-7) are reserved for protocol control messages. | ||
| 272 | */ | 275 | */ |
| 273 | - int32_t timestamp_delta; | 276 | + int8_t message_type; |
| 274 | /** | 277 | /** |
| 275 | - * Three-byte field that identifies the stream of the message. These | 278 | + * 4bytes. |
| 279 | + * Four-byte field that identifies the stream of the message. These | ||
| 276 | * bytes are set in big-endian format. | 280 | * bytes are set in big-endian format. |
| 277 | */ | 281 | */ |
| 278 | int32_t stream_id; | 282 | int32_t stream_id; |
| @@ -379,12 +383,17 @@ public: | @@ -379,12 +383,17 @@ public: | ||
| 379 | // 4.2. Message Payload | 383 | // 4.2. Message Payload |
| 380 | public: | 384 | public: |
| 381 | /** | 385 | /** |
| 382 | - * The other part which is the payload is the actual data that is | ||
| 383 | - * contained in the message. For example, it could be some audio samples | ||
| 384 | - * or compressed video data. The payload format and interpretation are | ||
| 385 | - * beyond the scope of this document. | 386 | + * current message parsed size, |
| 387 | + * size <= header.payload_length | ||
| 388 | + * for the payload maybe sent in multiple chunks. | ||
| 386 | */ | 389 | */ |
| 387 | int32_t size; | 390 | int32_t size; |
| 391 | + /** | ||
| 392 | + * the payload of message, the SrsMessage never know about the detail of payload, | ||
| 393 | + * user must use SrsProtocol.decode_message to get concrete packet. | ||
| 394 | + * @remark, not all message payload can be decoded to packet. for example, | ||
| 395 | + * video/audio packet use raw bytes, no video/audio packet. | ||
| 396 | + */ | ||
| 388 | int8_t* payload; | 397 | int8_t* payload; |
| 389 | protected: | 398 | protected: |
| 390 | SrsMessage(); | 399 | SrsMessage(); |
此 diff 太大无法显示。
-
请 注册 或 登录 后发表评论