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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.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
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h"
12
13 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
14
15 using webrtc::RTCPUtility::PT_PSFB;
16 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI;
17
18 namespace webrtc {
19 namespace rtcp {
20 namespace {
21 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) {
22 buffer[(*offset)++] = value;
23 }
24
25 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) {
26 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value);
27 *offset += 4;
28 }
29
30 // Reference picture selection indication (RPSI) (RFC 4585).
31 //
32 // FCI:
33 //
34 // 0 1 2 3
35 // 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
36 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 // | PB |0| Payload Type| Native RPSI bit string |
38 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 // | defined per codec ... | Padding (0) |
40 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 void CreateRpsi(const RTCPPacketPSFBRPSI& rpsi,
42 uint8_t padding_bytes,
43 uint8_t* buffer,
44 size_t* pos) {
45 // Native bit string should be a multiple of 8 bits.
46 assert(rpsi.NumberOfValidBits % 8 == 0);
47 AssignUWord32(buffer, pos, rpsi.SenderSSRC);
48 AssignUWord32(buffer, pos, rpsi.MediaSSRC);
49 AssignUWord8(buffer, pos, padding_bytes * 8);
50 AssignUWord8(buffer, pos, rpsi.PayloadType);
51 memcpy(buffer + *pos, rpsi.NativeBitString, rpsi.NumberOfValidBits / 8);
52 *pos += rpsi.NumberOfValidBits / 8;
53 memset(buffer + *pos, 0, padding_bytes);
54 *pos += padding_bytes;
55 }
56 } // namespace
57
58 bool Rpsi::Create(uint8_t* packet,
59 size_t* index,
60 size_t max_length,
61 RtcpPacket::PacketReadyCallback* callback) const {
62 assert(rpsi_.NumberOfValidBits > 0);
63 while (*index + BlockLength() > max_length) {
64 if (!OnBufferFull(packet, index, callback))
65 return false;
66 }
67 const uint8_t kFmt = 3;
68 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index);
69 CreateRpsi(rpsi_, padding_bytes_, packet, index);
70 return true;
71 }
72
73 void Rpsi::WithPictureId(uint64_t picture_id) {
74 const uint32_t kPidBits = 7;
75 const uint64_t k7MsbZeroMask = 0x1ffffffffffffffULL;
76 uint8_t required_bytes = 0;
77 uint64_t shifted_pid = picture_id;
78 do {
79 ++required_bytes;
80 shifted_pid = (shifted_pid >> kPidBits) & k7MsbZeroMask;
81 } while (shifted_pid > 0);
82
83 // Convert picture id to native bit string (natively defined by the video
84 // codec).
85 int pos = 0;
86 for (int i = required_bytes - 1; i > 0; i--) {
87 rpsi_.NativeBitString[pos++] =
88 0x80 | static_cast<uint8_t>(picture_id >> (i * kPidBits));
89 }
90 rpsi_.NativeBitString[pos++] = static_cast<uint8_t>(picture_id & 0x7f);
91 rpsi_.NumberOfValidBits = pos * 8;
92
93 // Calculate padding bytes (to reach next 32-bit boundary, 1, 2 or 3 bytes).
94 padding_bytes_ = 4 - ((2 + required_bytes) % 4);
95 if (padding_bytes_ == 4) {
96 padding_bytes_ = 0;
97 }
98 }
99
100
101 } // namespace rtcp
102 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698