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

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

Issue 1551893002: [rtp_rtcp] rtcp::Sli packet moved into own file and got Parse function (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) 2015 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/pli.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.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 16
16 using webrtc::RTCPUtility::RtcpCommonHeader; 17 using webrtc::RTCPUtility::RtcpCommonHeader;
17 18
18 namespace webrtc { 19 namespace webrtc {
19 namespace rtcp { 20 namespace rtcp {
20
21 // RFC 4585: Feedback format. 21 // RFC 4585: Feedback format.
22 // 22 //
23 // Common packet format: 23 // Common packet format:
24 // 24 //
25 // 0 1 2 3 25 // 0 1 2 3
26 // 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 26 // 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
27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 // |V=2|P| FMT | PT | length | 28 // |V=2|P| FMT | PT | length |
29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 // | SSRC of packet sender | 30 // | SSRC of packet sender |
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 // | SSRC of media source | 32 // | SSRC of media source |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 // : Feedback Control Information (FCI) : 34 // : Feedback Control Information (FCI) :
35 // : : 35 // : :
36 //
37 // Slice loss indication (SLI) (RFC 4585).
38 // FCI:
39 // 0 1 2 3
40 // 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
41 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 // | First | Number | PictureID |
43 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 Sli::Macroblocks::Macroblocks(uint8_t picture_id,
45 uint16_t first,
46 uint16_t number) {
47 RTC_DCHECK_LE(first, 0x1fff);
48 RTC_DCHECK_LE(number, 0x1fff);
49 RTC_DCHECK_LE(picture_id, 0x3f);
50 item_ = (first << 19) | (number << 6) | picture_id;
51 }
36 52
37 // 53 void Sli::Macroblocks::Parse(const uint8_t* buffer) {
38 // Picture loss indication (PLI) (RFC 4585). 54 item_ = ByteReader<uint32_t>::ReadBigEndian(buffer);
39 // FCI: no feedback control information. 55 }
40 bool Pli::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { 56
57 void Sli::Macroblocks::Create(uint8_t* buffer) const {
58 ByteWriter<uint32_t>::WriteBigEndian(buffer, item_);
59 }
60
61 bool Sli::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
41 RTC_DCHECK(header.packet_type == kPacketType); 62 RTC_DCHECK(header.packet_type == kPacketType);
42 RTC_DCHECK(header.count_or_format == kFeedbackMessageType); 63 RTC_DCHECK(header.count_or_format == kFeedbackMessageType);
43 64
44 if (header.payload_size_bytes < kCommonFeedbackLength) { 65 if (header.payload_size_bytes <
45 LOG(LS_WARNING) << "Packet is too small to be a valid PLI packet"; 66 kCommonFeedbackLength + Macroblocks::kLength) {
67 LOG(LS_WARNING) << "Packet is too small to be a valid SLI packet";
46 return false; 68 return false;
47 } 69 }
48 70
71 size_t number_of_items =
72 (header.payload_size_bytes - kCommonFeedbackLength) /
73 Macroblocks::kLength;
74
49 ParseCommonFeedback(payload); 75 ParseCommonFeedback(payload);
76 items_.resize(number_of_items);
77
78 const uint8_t* next_item = payload + kCommonFeedbackLength;
79 for (Macroblocks& item : items_) {
80 item.Parse(next_item);
81 next_item += Macroblocks::kLength;
82 }
83
50 return true; 84 return true;
51 } 85 }
52 86
53 bool Pli::Create(uint8_t* packet, 87 bool Sli::Create(uint8_t* packet,
54 size_t* index, 88 size_t* index,
55 size_t max_length, 89 size_t max_length,
56 RtcpPacket::PacketReadyCallback* callback) const { 90 RtcpPacket::PacketReadyCallback* callback) const {
91 RTC_DCHECK(!items_.empty());
57 while (*index + BlockLength() > max_length) { 92 while (*index + BlockLength() > max_length) {
58 if (!OnBufferFull(packet, index, callback)) 93 if (!OnBufferFull(packet, index, callback))
59 return false; 94 return false;
60 } 95 }
61
62 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet, 96 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
63 index); 97 index);
64 CreateCommonFeedback(packet + *index); 98 CreateCommonFeedback(packet + *index);
65 *index += kCommonFeedbackLength; 99 *index += kCommonFeedbackLength;
100 for (const Macroblocks& item : items_) {
101 item.Create(packet + *index);
102 *index += Macroblocks::kLength;
103 }
66 return true; 104 return true;
67 } 105 }
68 106
69 } // namespace rtcp 107 } // namespace rtcp
70 } // namespace webrtc 108 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/sli_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698