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

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
(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/sli.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h"
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16
17 using webrtc::RTCPUtility::RtcpCommonHeader;
18
19 namespace webrtc {
20 namespace rtcp {
21 const uint8_t Sli::kFeedbackMessageType;
22
23 // RFC 4585: Feedback format.
24 //
25 // Common packet format:
26 //
27 // 0 1 2 3
28 // 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
29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 // |V=2|P| FMT | PT | length |
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 // | SSRC of packet sender |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 // | SSRC of media source |
35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 // : Feedback Control Information (FCI) :
37 // : :
38 //
39 // Slice loss indication (SLI) (RFC 4585).
40 // FCI:
41 // 0 1 2 3
42 // 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
43 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 // | First | Number | PictureID |
45 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 Sli::Macroblocks::Macroblocks(uint8_t picture_id,
47 uint16_t first,
48 uint16_t count) {
åsapersson 2016/01/11 12:13:54 call count -> number?
danilchap 2016/01/11 15:36:32 Done.
49 RTC_DCHECK_LE(first, 0x1fff);
50 RTC_DCHECK_LE(count, 0x1fff);
51 RTC_DCHECK_LE(picture_id, 0x3d);
åsapersson 2016/01/11 12:13:54 3d -> 3f?
danilchap 2016/01/11 15:36:32 Done.
52 item_ = (first << 19) | (count << 6) | picture_id;
53 }
54 void Sli::Macroblocks::Parse(const uint8_t* buffer) {
55 item_ = ByteReader<uint32_t>::ReadBigEndian(buffer);
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) {
62 RTC_DCHECK_EQ(header.packet_type, kPacketType);
63 RTC_DCHECK_EQ(header.count_or_format, kFeedbackMessageType);
64
65 if (header.payload_size_bytes <
66 kCommonFeedbackLength + Macroblocks::kLength) {
67 LOG(LS_WARNING) << "Packet is too small to be a valid SLI packet";
68 return false;
69 }
70
71 size_t macroblocks_number =
åsapersson 2016/01/11 12:13:54 maybe items?
danilchap 2016/01/11 15:36:32 Done.
åsapersson 2016/01/12 12:35:26 maybe just items or num_items, number_of_items
danilchap 2016/01/12 12:56:35 Done. number_of_items is obviously more clear name
72 (header.payload_size_bytes - kCommonFeedbackLength) /
73 Macroblocks::kLength;
74
75 ParseCommonFeedback(payload);
76 macroblocks_.resize(macroblocks_number);
77
78 const uint8_t* next_fci_field = payload + kCommonFeedbackLength;
79 for (Macroblocks& block : macroblocks_) {
80 block.Parse(next_fci_field);
81 next_fci_field += Macroblocks::kLength;
82 }
83
84 return true;
85 }
86
87 bool Sli::Create(uint8_t* packet,
88 size_t* index,
89 size_t max_length,
90 RtcpPacket::PacketReadyCallback* callback) const {
91 RTC_DCHECK(!macroblocks_.empty());
åsapersson 2016/01/11 12:13:54 use RTC_CHECK here?
danilchap 2016/01/11 15:36:32 Done, but isn't it better to send invalid sli pack
åsapersson 2016/01/12 12:35:26 Ok, RTC_DCHECK might be better.
danilchap 2016/01/12 12:56:35 Reverted.
92 while (*index + BlockLength() > max_length) {
93 if (!OnBufferFull(packet, index, callback))
94 return false;
95 }
96 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
97 index);
98 CreateCommonFeedback(packet + *index);
99 *index += kCommonFeedbackLength;
100 for (const Macroblocks& mb : macroblocks_) {
101 mb.Create(packet + *index);
102 *index += Macroblocks::kLength;
103 }
104 return true;
105 }
106
107 } // namespace rtcp
108 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698