Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/app.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/app.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/app.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..900f661952a0e3ba0011db67d9cefe15f2bb2457 |
| --- /dev/null |
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/app.cc |
| @@ -0,0 +1,90 @@ |
| +/* |
| + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" |
| + |
| +#include "webrtc/base/checks.h" |
| +#include "webrtc/base/logging.h" |
| +#include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| +#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| + |
| +using webrtc::RTCPUtility::RtcpCommonHeader; |
| + |
| +namespace webrtc { |
| +namespace rtcp { |
| + |
| +// Application-Defined packet (APP) (RFC 3550). |
| +// |
| +// 0 1 2 3 |
| +// 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 |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// |V=2|P| subtype | PT=APP=204 | length | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 0 | SSRC/CSRC | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 4 | name (ASCII) | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 8 | application-dependent data ... |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +bool App::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { |
| + RTC_DCHECK(header.packet_type == kPacketType); |
| + |
| + sub_type_ = header.count_or_format; |
| + ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]); |
| + name_ = ByteReader<uint32_t>::ReadBigEndian(&payload[4]); |
| + data_.SetData(&payload[8], header.payload_size_bytes - 8); |
| + return true; |
| +} |
| + |
| +bool App::WithSubType(uint8_t subtype) { |
| + 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
|
| + LOG(LS_WARNING) << "Incorrect subtype " << subtype << " for APP packet."; |
| + return false; |
| + } |
| + sub_type_ = subtype; |
| + return true; |
| +} |
| + |
| +bool App::WithData(const uint8_t* data, size_t data_length) { |
| + RTC_DCHECK(data); |
| + if (data_length > kMaxDataSize) { |
| + LOG(LS_WARNING) << "App data size << " << data_length |
| + << "exceed maximum of " << kMaxDataSize << " bytes."; |
| + return false; |
| + } |
| + 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.
|
| + LOG(LS_WARNING) << "Data must be 32 bits aligned."; |
| + return false; |
| + } |
| + data_.SetData(data, data_length); |
| + return true; |
| +} |
| + |
| +bool App::Create(uint8_t* packet, |
| + size_t* index, |
| + size_t max_length, |
| + RtcpPacket::PacketReadyCallback* callback) const { |
| + while (*index + BlockLength() > max_length) { |
| + if (!OnBufferFull(packet, index, callback)) |
| + return false; |
| + } |
| + const size_t index_end = *index + BlockLength(); |
| + CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index); |
| + |
| + ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_); |
| + ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_); |
| + memcpy(&packet[*index + 8], data_.data(), data_.size()); |
| + *index += (8 + data_.size()); |
| + RTC_DCHECK_EQ(index_end, *index); |
| + return true; |
| +} |
| + |
| +} // namespace rtcp |
| +} // namespace webrtc |