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

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

Issue 1583233007: [rtp_rtcp] rtcp::Rpsi moved into own file (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 months 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
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
18 18
19 using webrtc::RTCPUtility::PT_APP; 19 using webrtc::RTCPUtility::PT_APP;
20 using webrtc::RTCPUtility::PT_IJ; 20 using webrtc::RTCPUtility::PT_IJ;
21 using webrtc::RTCPUtility::PT_PSFB;
22 using webrtc::RTCPUtility::PT_RTPFB; 21 using webrtc::RTCPUtility::PT_RTPFB;
23 using webrtc::RTCPUtility::PT_SDES; 22 using webrtc::RTCPUtility::PT_SDES;
24 using webrtc::RTCPUtility::PT_SR; 23 using webrtc::RTCPUtility::PT_SR;
25 24
26 using webrtc::RTCPUtility::RTCPPacketAPP; 25 using webrtc::RTCPUtility::RTCPPacketAPP;
27 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI;
28 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; 26 using webrtc::RTCPUtility::RTCPPacketReportBlockItem;
29 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; 27 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK;
30 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; 28 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem;
31 using webrtc::RTCPUtility::RTCPPacketSR; 29 using webrtc::RTCPUtility::RTCPPacketSR;
32 30
33 namespace webrtc { 31 namespace webrtc {
34 namespace rtcp { 32 namespace rtcp {
35 namespace { 33 namespace {
36 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { 34 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) {
37 buffer[(*offset)++] = value; 35 buffer[(*offset)++] = value;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 it != chunks.end(); ++it) { 133 it != chunks.end(); ++it) {
136 AssignUWord32(buffer, pos, (*it).ssrc); 134 AssignUWord32(buffer, pos, (*it).ssrc);
137 AssignUWord8(buffer, pos, kSdesItemType); 135 AssignUWord8(buffer, pos, kSdesItemType);
138 AssignUWord8(buffer, pos, (*it).name.length()); 136 AssignUWord8(buffer, pos, (*it).name.length());
139 memcpy(buffer + *pos, (*it).name.data(), (*it).name.length()); 137 memcpy(buffer + *pos, (*it).name.data(), (*it).name.length());
140 *pos += (*it).name.length(); 138 *pos += (*it).name.length();
141 memset(buffer + *pos, 0, (*it).null_octets); 139 memset(buffer + *pos, 0, (*it).null_octets);
142 *pos += (*it).null_octets; 140 *pos += (*it).null_octets;
143 } 141 }
144 } 142 }
145
146 // Reference picture selection indication (RPSI) (RFC 4585).
147 //
148 // FCI:
149 //
150 // 0 1 2 3
151 // 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
152 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 // | PB |0| Payload Type| Native RPSI bit string |
154 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155 // | defined per codec ... | Padding (0) |
156 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
157
158 void CreateRpsi(const RTCPPacketPSFBRPSI& rpsi,
159 uint8_t padding_bytes,
160 uint8_t* buffer,
161 size_t* pos) {
162 // Native bit string should be a multiple of 8 bits.
163 assert(rpsi.NumberOfValidBits % 8 == 0);
164 AssignUWord32(buffer, pos, rpsi.SenderSSRC);
165 AssignUWord32(buffer, pos, rpsi.MediaSSRC);
166 AssignUWord8(buffer, pos, padding_bytes * 8);
167 AssignUWord8(buffer, pos, rpsi.PayloadType);
168 memcpy(buffer + *pos, rpsi.NativeBitString, rpsi.NumberOfValidBits / 8);
169 *pos += rpsi.NumberOfValidBits / 8;
170 memset(buffer + *pos, 0, padding_bytes);
171 *pos += padding_bytes;
172 }
173 } // namespace 143 } // namespace
174 144
175 void RtcpPacket::Append(RtcpPacket* packet) { 145 void RtcpPacket::Append(RtcpPacket* packet) {
176 assert(packet); 146 assert(packet);
177 appended_packets_.push_back(packet); 147 appended_packets_.push_back(packet);
178 } 148 }
179 149
180 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { 150 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const {
181 size_t length = 0; 151 size_t length = 0;
182 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); 152 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // Header (4 bytes). 298 // Header (4 bytes).
329 // Chunk: 299 // Chunk:
330 // SSRC/CSRC (4 bytes) | CNAME (1 byte) | length (1 byte) | name | padding. 300 // SSRC/CSRC (4 bytes) | CNAME (1 byte) | length (1 byte) | name | padding.
331 size_t length = kHeaderLength; 301 size_t length = kHeaderLength;
332 for (const Chunk& chunk : chunks_) 302 for (const Chunk& chunk : chunks_)
333 length += 6 + chunk.name.length() + chunk.null_octets; 303 length += 6 + chunk.name.length() + chunk.null_octets;
334 assert(length % 4 == 0); 304 assert(length % 4 == 0);
335 return length; 305 return length;
336 } 306 }
337 307
338 bool Rpsi::Create(uint8_t* packet,
339 size_t* index,
340 size_t max_length,
341 RtcpPacket::PacketReadyCallback* callback) const {
342 assert(rpsi_.NumberOfValidBits > 0);
343 while (*index + BlockLength() > max_length) {
344 if (!OnBufferFull(packet, index, callback))
345 return false;
346 }
347 const uint8_t kFmt = 3;
348 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index);
349 CreateRpsi(rpsi_, padding_bytes_, packet, index);
350 return true;
351 }
352
353 void Rpsi::WithPictureId(uint64_t picture_id) {
354 const uint32_t kPidBits = 7;
355 const uint64_t k7MsbZeroMask = 0x1ffffffffffffffULL;
356 uint8_t required_bytes = 0;
357 uint64_t shifted_pid = picture_id;
358 do {
359 ++required_bytes;
360 shifted_pid = (shifted_pid >> kPidBits) & k7MsbZeroMask;
361 } while (shifted_pid > 0);
362
363 // Convert picture id to native bit string (natively defined by the video
364 // codec).
365 int pos = 0;
366 for (int i = required_bytes - 1; i > 0; i--) {
367 rpsi_.NativeBitString[pos++] =
368 0x80 | static_cast<uint8_t>(picture_id >> (i * kPidBits));
369 }
370 rpsi_.NativeBitString[pos++] = static_cast<uint8_t>(picture_id & 0x7f);
371 rpsi_.NumberOfValidBits = pos * 8;
372
373 // Calculate padding bytes (to reach next 32-bit boundary, 1, 2 or 3 bytes).
374 padding_bytes_ = 4 - ((2 + required_bytes) % 4);
375 if (padding_bytes_ == 4) {
376 padding_bytes_ = 0;
377 }
378 }
379
380 RawPacket::RawPacket(size_t buffer_length) 308 RawPacket::RawPacket(size_t buffer_length)
381 : buffer_length_(buffer_length), length_(0) { 309 : buffer_length_(buffer_length), length_(0) {
382 buffer_.reset(new uint8_t[buffer_length]); 310 buffer_.reset(new uint8_t[buffer_length]);
383 } 311 }
384 312
385 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) 313 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length)
386 : buffer_length_(packet_length), length_(packet_length) { 314 : buffer_length_(packet_length), length_(packet_length) {
387 buffer_.reset(new uint8_t[packet_length]); 315 buffer_.reset(new uint8_t[packet_length]);
388 memcpy(buffer_.get(), packet, packet_length); 316 memcpy(buffer_.get(), packet, packet_length);
389 } 317 }
(...skipping 14 matching lines...) Expand all
404 return length_; 332 return length_;
405 } 333 }
406 334
407 void RawPacket::SetLength(size_t length) { 335 void RawPacket::SetLength(size_t length) {
408 assert(length <= buffer_length_); 336 assert(length <= buffer_length_);
409 length_ = length; 337 length_ = length;
410 } 338 }
411 339
412 } // namespace rtcp 340 } // namespace rtcp
413 } // namespace webrtc 341 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698