OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2015 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/app.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 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | |
17 | |
18 using webrtc::RTCPUtility::RtcpCommonHeader; | |
19 | |
20 namespace webrtc { | |
21 namespace rtcp { | |
22 | |
23 // Application-Defined packet (APP) (RFC 3550). | |
24 // | |
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 | |
27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
28 // |V=2|P| subtype | PT=APP=204 | length | | |
29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
30 // 0 | SSRC/CSRC | | |
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
32 // 4 | name (ASCII) | | |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
34 // 8 | application-dependent data ... | |
35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
36 bool App::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { | |
37 RTC_DCHECK(header.packet_type == kPacketType); | |
38 | |
39 sub_type_ = header.count_or_format; | |
40 ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]); | |
41 name_ = ByteReader<uint32_t>::ReadBigEndian(&payload[4]); | |
42 data_.SetData(&payload[8], header.payload_size_bytes - 8); | |
43 return true; | |
44 } | |
45 | |
46 bool App::WithSubType(uint8_t subtype) { | |
47 if (subtype > 0x1f) { | |
åsapersson
2015/11/17 15:31:36
Should we use RTC_DCHECK?
danilchap
2015/11/17 17:12:36
Done.
åsapersson
2015/11/18 10:36:55
Maybe RTC_DCHECK_LE(subtype, 0x1f);
danilchap
2015/11/18 11:15:54
Yes, got confused by RTC_DCHECK_EQ where it is com
| |
48 LOG(LS_WARNING) << "Incorrect subtype " << subtype << " for APP packet."; | |
49 return false; | |
50 } | |
51 sub_type_ = subtype; | |
52 return true; | |
53 } | |
54 | |
55 bool App::WithData(const uint8_t* data, size_t data_length) { | |
56 RTC_DCHECK(data); | |
57 if (data_length > kMaxDataSize) { | |
58 LOG(LS_WARNING) << "App data size << " << data_length | |
59 << "exceed maximum of " << kMaxDataSize << " bytes."; | |
60 return false; | |
61 } | |
62 if (data_length % 4 != 0) { | |
åsapersson
2015/11/17 15:31:36
Should we use RTC_DCHECK?
danilchap
2015/11/17 17:12:36
Done.
| |
63 LOG(LS_WARNING) << "Data must be 32 bits aligned."; | |
64 return false; | |
65 } | |
66 data_.SetData(data, data_length); | |
67 return true; | |
68 } | |
69 | |
70 bool App::Create(uint8_t* packet, | |
71 size_t* index, | |
72 size_t max_length, | |
73 RtcpPacket::PacketReadyCallback* callback) const { | |
74 while (*index + BlockLength() > max_length) { | |
75 if (!OnBufferFull(packet, index, callback)) | |
76 return false; | |
77 } | |
78 const size_t index_end = *index + BlockLength(); | |
79 CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index); | |
80 | |
81 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_); | |
82 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_); | |
83 memcpy(&packet[*index + 8], data_.data(), data_.size()); | |
84 *index += (8 + data_.size()); | |
85 RTC_DCHECK_EQ(index_end, *index); | |
86 return true; | |
87 } | |
88 | |
89 } // namespace rtcp | |
90 } // namespace webrtc | |
OLD | NEW |