refine recv message header, add comments, remove the fresh_packet variable which…
… duplicated with first_chunk
正在显示
1 个修改的文件
包含
9 行增加
和
9 行删除
| @@ -952,7 +952,8 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -952,7 +952,8 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 952 | * so we must update the timestamp even fmt=3 for first packet. | 952 | * so we must update the timestamp even fmt=3 for first packet. |
| 953 | */ | 953 | */ |
| 954 | // fresh packet used to update the timestamp even fmt=3 for first packet. | 954 | // fresh packet used to update the timestamp even fmt=3 for first packet. |
| 955 | - bool is_fresh_packet = !chunk->msg; | 955 | + // fresh packet always means the chunk is the first one of message. |
| 956 | + bool is_first_chunk_of_msg = !chunk->msg; | ||
| 956 | 957 | ||
| 957 | // but, we can ensure that when a chunk stream is fresh, | 958 | // but, we can ensure that when a chunk stream is fresh, |
| 958 | // the fmt must be 0, a new stream. | 959 | // the fmt must be 0, a new stream. |
| @@ -986,9 +987,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -986,9 +987,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 986 | } | 987 | } |
| 987 | 988 | ||
| 988 | // create msg when new chunk stream start | 989 | // create msg when new chunk stream start |
| 989 | - bool is_first_chunk_of_msg = false; | ||
| 990 | if (!chunk->msg) { | 990 | if (!chunk->msg) { |
| 991 | - is_first_chunk_of_msg = true; | ||
| 992 | chunk->msg = new SrsCommonMessage(); | 991 | chunk->msg = new SrsCommonMessage(); |
| 993 | srs_verbose("create message for new chunk, fmt=%d, cid=%d", fmt, chunk->cid); | 992 | srs_verbose("create message for new chunk, fmt=%d, cid=%d", fmt, chunk->cid); |
| 994 | } | 993 | } |
| @@ -1072,10 +1071,11 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -1072,10 +1071,11 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 1072 | pp[0] = *p++; | 1071 | pp[0] = *p++; |
| 1073 | pp[3] = 0; | 1072 | pp[3] = 0; |
| 1074 | 1073 | ||
| 1075 | - // if msg exists in cache, the size must not changed. | ||
| 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) { | 1074 | + // for a message, if msg exists in cache, the size must not changed. |
| 1075 | + // always use the actual msg size to compare, for the cache payload length can changed, | ||
| 1076 | + // for the fmt type1(stream_id not changed), user can change the payload | ||
| 1077 | + // length(it's not allowed in the continue chunks). | ||
| 1078 | + if (!is_first_chunk_of_msg && chunk->header.payload_length != payload_length) { | ||
| 1079 | ret = ERROR_RTMP_PACKET_SIZE; | 1079 | ret = ERROR_RTMP_PACKET_SIZE; |
| 1080 | srs_error("msg exists in chunk cache, " | 1080 | srs_error("msg exists in chunk cache, " |
| 1081 | "size=%d cannot change to %d, ret=%d", | 1081 | "size=%d cannot change to %d, ret=%d", |
| @@ -1105,8 +1105,8 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | @@ -1105,8 +1105,8 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz | ||
| 1105 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp); | 1105 | fmt, mh_size, chunk->extended_timestamp, chunk->header.timestamp); |
| 1106 | } | 1106 | } |
| 1107 | } else { | 1107 | } else { |
| 1108 | - // update the timestamp even fmt=3 for first stream | ||
| 1109 | - if (is_fresh_packet && !chunk->extended_timestamp) { | 1108 | + // update the timestamp even fmt=3 for first chunk packet |
| 1109 | + if (is_first_chunk_of_msg && !chunk->extended_timestamp) { | ||
| 1110 | chunk->header.timestamp += chunk->header.timestamp_delta; | 1110 | chunk->header.timestamp += chunk->header.timestamp_delta; |
| 1111 | } | 1111 | } |
| 1112 | srs_verbose("header read completed. fmt=%d, size=%d, ext_time=%d", | 1112 | srs_verbose("header read completed. fmt=%d, size=%d, ext_time=%d", |
-
请 注册 或 登录 后发表评论