finish basic protocol utest, fix the bug of fmt11 length error.
正在显示
4 个修改的文件
包含
34 行增加
和
16 行删除
| @@ -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" |
| @@ -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 太大无法显示。
-
请 注册 或 登录 后发表评论