Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet.cc

Issue 1439553003: [rtp_rtcp] rtcp::Sdes cleaned and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // | inter-arrival jitter | 184 // | inter-arrival jitter |
185 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 185 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
186 186
187 void CreateIj(const std::vector<uint32_t>& ij_items, 187 void CreateIj(const std::vector<uint32_t>& ij_items,
188 uint8_t* buffer, 188 uint8_t* buffer,
189 size_t* pos) { 189 size_t* pos) {
190 for (uint32_t item : ij_items) 190 for (uint32_t item : ij_items)
191 AssignUWord32(buffer, pos, item); 191 AssignUWord32(buffer, pos, item);
192 } 192 }
193 193
194 // Source Description (SDES) (RFC 3550).
195 //
196 // 0 1 2 3
197 // 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
198 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
199 // header |V=2|P| SC | PT=SDES=202 | length |
200 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
201 // chunk | SSRC/CSRC_1 |
202 // 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
203 // | SDES items |
204 // | ... |
205 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
206 // chunk | SSRC/CSRC_2 |
207 // 2 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
208 // | SDES items |
209 // | ... |
210 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
211 //
212 // Canonical End-Point Identifier SDES Item (CNAME)
213 //
214 // 0 1 2 3
215 // 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
216 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217 // | CNAME=1 | length | user and domain name ...
218 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219
220 void CreateSdes(const std::vector<Sdes::Chunk>& chunks,
221 uint8_t* buffer,
222 size_t* pos) {
223 const uint8_t kSdesItemType = 1;
224 for (std::vector<Sdes::Chunk>::const_iterator it = chunks.begin();
225 it != chunks.end(); ++it) {
226 AssignUWord32(buffer, pos, (*it).ssrc);
227 AssignUWord8(buffer, pos, kSdesItemType);
228 AssignUWord8(buffer, pos, (*it).name.length());
229 memcpy(buffer + *pos, (*it).name.data(), (*it).name.length());
230 *pos += (*it).name.length();
231 memset(buffer + *pos, 0, (*it).null_octets);
232 *pos += (*it).null_octets;
233 }
234 }
235
236 // Bye packet (BYE) (RFC 3550). 194 // Bye packet (BYE) (RFC 3550).
237 // 195 //
238 // 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 196 // 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
239 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 197 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240 // |V=2|P| SC | PT=BYE=203 | length | 198 // |V=2|P| SC | PT=BYE=203 | length |
241 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 199 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242 // | SSRC/CSRC | 200 // | SSRC/CSRC |
243 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 201 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244 // : ... : 202 // : ... :
245 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ 203 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 784
827 bool Ij::WithJitterItem(uint32_t jitter) { 785 bool Ij::WithJitterItem(uint32_t jitter) {
828 if (ij_items_.size() >= kMaxNumberOfIjItems) { 786 if (ij_items_.size() >= kMaxNumberOfIjItems) {
829 LOG(LS_WARNING) << "Max inter-arrival jitter items reached."; 787 LOG(LS_WARNING) << "Max inter-arrival jitter items reached.";
830 return false; 788 return false;
831 } 789 }
832 ij_items_.push_back(jitter); 790 ij_items_.push_back(jitter);
833 return true; 791 return true;
834 } 792 }
835 793
836 bool Sdes::Create(uint8_t* packet,
837 size_t* index,
838 size_t max_length,
839 RtcpPacket::PacketReadyCallback* callback) const {
840 assert(!chunks_.empty());
841 while (*index + BlockLength() > max_length) {
842 if (!OnBufferFull(packet, index, callback))
843 return false;
844 }
845 CreateHeader(chunks_.size(), PT_SDES, HeaderLength(), packet, index);
846 CreateSdes(chunks_, packet, index);
847 return true;
848 }
849
850 bool Sdes::WithCName(uint32_t ssrc, const std::string& cname) {
851 assert(cname.length() <= 0xff);
852 if (chunks_.size() >= kMaxNumberOfChunks) {
853 LOG(LS_WARNING) << "Max SDES chunks reached.";
854 return false;
855 }
856 // In each chunk, the list of items must be terminated by one or more null
857 // octets. The next chunk must start on a 32-bit boundary.
858 // CNAME (1 byte) | length (1 byte) | name | padding.
859 int null_octets = 4 - ((2 + cname.length()) % 4);
860 Chunk chunk;
861 chunk.ssrc = ssrc;
862 chunk.name = cname;
863 chunk.null_octets = null_octets;
864 chunks_.push_back(chunk);
865 return true;
866 }
867
868 size_t Sdes::BlockLength() const {
869 // Header (4 bytes).
870 // Chunk:
871 // SSRC/CSRC (4 bytes) | CNAME (1 byte) | length (1 byte) | name | padding.
872 size_t length = kHeaderLength;
873 for (const Chunk& chunk : chunks_)
874 length += 6 + chunk.name.length() + chunk.null_octets;
875 assert(length % 4 == 0);
876 return length;
877 }
878
879 bool Bye::Create(uint8_t* packet, 794 bool Bye::Create(uint8_t* packet,
880 size_t* index, 795 size_t* index,
881 size_t max_length, 796 size_t max_length,
882 RtcpPacket::PacketReadyCallback* callback) const { 797 RtcpPacket::PacketReadyCallback* callback) const {
883 while (*index + BlockLength() > max_length) { 798 while (*index + BlockLength() > max_length) {
884 if (!OnBufferFull(packet, index, callback)) 799 if (!OnBufferFull(packet, index, callback))
885 return false; 800 return false;
886 } 801 }
887 size_t length = HeaderLength(); 802 size_t length = HeaderLength();
888 CreateHeader(length, PT_BYE, length, packet, index); 803 CreateHeader(length, PT_BYE, length, packet, index);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 return length_; 1135 return length_;
1221 } 1136 }
1222 1137
1223 void RawPacket::SetLength(size_t length) { 1138 void RawPacket::SetLength(size_t length) {
1224 assert(length <= buffer_length_); 1139 assert(length <= buffer_length_);
1225 length_ = length; 1140 length_ = length;
1226 } 1141 }
1227 1142
1228 } // namespace rtcp 1143 } // namespace rtcp
1229 } // namespace webrtc 1144 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698