| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 16 | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 17 using webrtc::RTCPUtility::RtcpCommonHeader; | |
| 18 | 17 |
| 19 namespace webrtc { | 18 namespace webrtc { |
| 20 namespace rtcp { | 19 namespace rtcp { |
| 21 // Source Description (SDES) (RFC 3550). | 20 // Source Description (SDES) (RFC 3550). |
| 22 // | 21 // |
| 23 // 0 1 2 3 | 22 // 0 1 2 3 |
| 24 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | 23 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 24 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 // header |V=2|P| SC | PT=SDES=202 | length | | 25 // header |V=2|P| SC | PT=SDES=202 | length | |
| 27 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | 26 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 53 size_t chunk_payload_size = 4 + 1 + 1 + chunk.cname.size(); | 52 size_t chunk_payload_size = 4 + 1 + 1 + chunk.cname.size(); |
| 54 size_t padding_size = 4 - (chunk_payload_size % 4); // Minimum 1. | 53 size_t padding_size = 4 - (chunk_payload_size % 4); // Minimum 1. |
| 55 return chunk_payload_size + padding_size; | 54 return chunk_payload_size + padding_size; |
| 56 } | 55 } |
| 57 } // namespace | 56 } // namespace |
| 58 | 57 |
| 59 Sdes::Sdes() : block_length_(RtcpPacket::kHeaderLength) {} | 58 Sdes::Sdes() : block_length_(RtcpPacket::kHeaderLength) {} |
| 60 | 59 |
| 61 Sdes::~Sdes() {} | 60 Sdes::~Sdes() {} |
| 62 | 61 |
| 63 bool Sdes::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { | 62 bool Sdes::Parse(const CommonHeader& packet) { |
| 64 RTC_CHECK(header.packet_type == kPacketType); | 63 RTC_DCHECK(packet.type() == kPacketType); |
| 65 | 64 |
| 66 uint8_t number_of_chunks = header.count_or_format; | 65 uint8_t number_of_chunks = packet.count(); |
| 67 std::vector<Chunk> chunks; // Read chunk into temporary array, so that in | 66 std::vector<Chunk> chunks; // Read chunk into temporary array, so that in |
| 68 // case of an error original array would stay | 67 // case of an error original array would stay |
| 69 // unchanged. | 68 // unchanged. |
| 70 size_t block_length = kHeaderLength; | 69 size_t block_length = kHeaderLength; |
| 71 | 70 |
| 72 if (header.payload_size_bytes % 4 != 0) { | 71 if (packet.payload_size_bytes() % 4 != 0) { |
| 73 LOG(LS_WARNING) << "Invalid payload size " << header.payload_size_bytes | 72 LOG(LS_WARNING) << "Invalid payload size " << packet.payload_size_bytes() |
| 74 << " bytes for a valid Sdes packet. Size should be" | 73 << " bytes for a valid Sdes packet. Size should be" |
| 75 " multiple of 4 bytes"; | 74 " multiple of 4 bytes"; |
| 76 } | 75 } |
| 77 const uint8_t* const payload_end = payload + header.payload_size_bytes; | 76 const uint8_t* const payload_end = |
| 78 const uint8_t* looking_at = payload; | 77 packet.payload() + packet.payload_size_bytes(); |
| 78 const uint8_t* looking_at = packet.payload(); |
| 79 chunks.resize(number_of_chunks); | 79 chunks.resize(number_of_chunks); |
| 80 for (size_t i = 0; i < number_of_chunks;) { | 80 for (size_t i = 0; i < number_of_chunks;) { |
| 81 // Each chunk consumes at least 8 bytes. | 81 // Each chunk consumes at least 8 bytes. |
| 82 if (payload_end - looking_at < 8) { | 82 if (payload_end - looking_at < 8) { |
| 83 LOG(LS_WARNING) << "Not enough space left for chunk #" << (i + 1); | 83 LOG(LS_WARNING) << "Not enough space left for chunk #" << (i + 1); |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 chunks[i].ssrc = ByteReader<uint32_t>::ReadBigEndian(looking_at); | 86 chunks[i].ssrc = ByteReader<uint32_t>::ReadBigEndian(looking_at); |
| 87 looking_at += sizeof(uint32_t); | 87 looking_at += sizeof(uint32_t); |
| 88 bool cname_found = false; | 88 bool cname_found = false; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 const int kPadding = 0; | 177 const int kPadding = 0; |
| 178 memset(packet + *index, kPadding, padding_size); | 178 memset(packet + *index, kPadding, padding_size); |
| 179 *index += padding_size; | 179 *index += padding_size; |
| 180 } | 180 } |
| 181 | 181 |
| 182 RTC_CHECK_EQ(*index, index_end); | 182 RTC_CHECK_EQ(*index, index_end); |
| 183 return true; | 183 return true; |
| 184 } | 184 } |
| 185 } // namespace rtcp | 185 } // namespace rtcp |
| 186 } // namespace webrtc | 186 } // namespace webrtc |
| OLD | NEW |