LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtcp_packet - app.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 39 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_packet/common_header.h"
      17             : 
      18             : namespace webrtc {
      19             : namespace rtcp {
      20             : constexpr uint8_t App::kPacketType;
      21             : constexpr size_t App::kMaxDataSize;
      22             : // Application-Defined packet (APP) (RFC 3550).
      23             : //
      24             : //     0                   1                   2                   3
      25             : //     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             : //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      27             : //    |V=2|P| subtype |   PT=APP=204  |             length            |
      28             : //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      29             : //  0 |                           SSRC/CSRC                           |
      30             : //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      31             : //  4 |                          name (ASCII)                         |
      32             : //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      33             : //  8 |                   application-dependent data                ...
      34             : //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      35           0 : bool App::Parse(const CommonHeader& packet) {
      36           0 :   RTC_DCHECK_EQ(packet.type(), kPacketType);
      37           0 :   if (packet.payload_size_bytes() < kAppBaseLength) {
      38           0 :     LOG(LS_WARNING) << "Packet is too small to be a valid APP packet";
      39           0 :     return false;
      40             :   }
      41           0 :   if (packet.payload_size_bytes() % 4 != 0) {
      42           0 :     LOG(LS_WARNING)
      43           0 :         << "Packet payload must be 32 bits aligned to make a valid APP packet";
      44           0 :     return false;
      45             :   }
      46           0 :   sub_type_ = packet.fmt();
      47           0 :   ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&packet.payload()[0]);
      48           0 :   name_ = ByteReader<uint32_t>::ReadBigEndian(&packet.payload()[4]);
      49           0 :   data_.SetData(packet.payload() + kAppBaseLength,
      50           0 :                 packet.payload_size_bytes() - kAppBaseLength);
      51           0 :   return true;
      52             : }
      53             : 
      54           0 : void App::SetSubType(uint8_t subtype) {
      55           0 :   RTC_DCHECK_LE(subtype, 0x1f);
      56           0 :   sub_type_ = subtype;
      57           0 : }
      58             : 
      59           0 : void App::SetData(const uint8_t* data, size_t data_length) {
      60           0 :   RTC_DCHECK(data);
      61           0 :   RTC_DCHECK_EQ(data_length % 4, 0) << "Data must be 32 bits aligned.";
      62           0 :   RTC_DCHECK_LE(data_length, kMaxDataSize) << "App data size " << data_length
      63           0 :                                            << " exceed maximum of "
      64           0 :                                            << kMaxDataSize << " bytes.";
      65           0 :   data_.SetData(data, data_length);
      66           0 : }
      67             : 
      68           0 : bool App::Create(uint8_t* packet,
      69             :                  size_t* index,
      70             :                  size_t max_length,
      71             :                  RtcpPacket::PacketReadyCallback* callback) const {
      72           0 :   while (*index + BlockLength() > max_length) {
      73           0 :     if (!OnBufferFull(packet, index, callback))
      74           0 :       return false;
      75             :   }
      76           0 :   const size_t index_end = *index + BlockLength();
      77           0 :   CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index);
      78             : 
      79           0 :   ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_);
      80           0 :   ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_);
      81           0 :   memcpy(&packet[*index + 8], data_.data(), data_.size());
      82           0 :   *index += (8 + data_.size());
      83           0 :   RTC_DCHECK_EQ(index_end, *index);
      84           0 :   return true;
      85             : }
      86             : 
      87             : }  // namespace rtcp
      88             : }  // namespace webrtc

Generated by: LCOV version 1.13