Home | History | Annotate | Download | only in rtcp_packet
      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 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_
     12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_
     13 
     14 #include "webrtc/base/buffer.h"
     15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
     16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
     17 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
     18 
     19 namespace webrtc {
     20 namespace rtcp {
     21 
     22 class App : public RtcpPacket {
     23  public:
     24   static const uint8_t kPacketType = 204;
     25   // 28 bytes for UDP header
     26   // 12 bytes for RTCP app header
     27   static const size_t kMaxDataSize = IP_PACKET_SIZE - 12 - 28;
     28   App() : sub_type_(0), ssrc_(0), name_(0) {}
     29 
     30   virtual ~App() {}
     31 
     32   // Parse assumes header is already parsed and validated.
     33   bool Parse(const RTCPUtility::RtcpCommonHeader& header,
     34              const uint8_t* payload);  // Size of the payload is in the header.
     35 
     36   void From(uint32_t ssrc) { ssrc_ = ssrc; }
     37   void WithSubType(uint8_t subtype);
     38   void WithName(uint32_t name) { name_ = name; }
     39   void WithData(const uint8_t* data, size_t data_length);
     40 
     41   uint8_t sub_type() const { return sub_type_; }
     42   uint32_t ssrc() const { return ssrc_; }
     43   uint32_t name() const { return name_; }
     44   size_t data_size() const { return data_.size(); }
     45   const uint8_t* data() const { return data_.data(); }
     46 
     47  protected:
     48   bool Create(uint8_t* packet,
     49               size_t* index,
     50               size_t max_length,
     51               RtcpPacket::PacketReadyCallback* callback) const override;
     52 
     53  private:
     54   size_t BlockLength() const override { return 12 + data_.size(); }
     55 
     56   uint8_t sub_type_;
     57   uint32_t ssrc_;
     58   uint32_t name_;
     59   rtc::Buffer data_;
     60 
     61   RTC_DISALLOW_COPY_AND_ASSIGN(App);
     62 };
     63 
     64 }  // namespace rtcp
     65 }  // namespace webrtc
     66 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_
     67