• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_SLI_H_
13 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_SLI_H_
14 
15 #include <vector>
16 
17 #include "webrtc/base/basictypes.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/psfb.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
20 
21 namespace webrtc {
22 namespace rtcp {
23 
24 // Slice loss indication (SLI) (RFC 4585).
25 class Sli : public Psfb {
26  public:
27   static const uint8_t kFeedbackMessageType = 2;
28   class Macroblocks {
29    public:
30     static const size_t kLength = 4;
Macroblocks()31     Macroblocks() : item_(0) {}
32     Macroblocks(uint8_t picture_id, uint16_t first, uint16_t number);
~Macroblocks()33     ~Macroblocks() {}
34 
35     void Parse(const uint8_t* buffer);
36     void Create(uint8_t* buffer) const;
37 
first()38     uint16_t first() const { return item_ >> 19; }
number()39     uint16_t number() const { return (item_ >> 6) & 0x1fff; }
picture_id()40     uint8_t picture_id() const { return (item_ & 0x3f); }
41 
42    private:
43     uint32_t item_;
44   };
45 
Sli()46   Sli() {}
~Sli()47   virtual ~Sli() {}
48 
49   // Parse assumes header is already parsed and validated.
50   bool Parse(const RTCPUtility::RtcpCommonHeader& header,
51              const uint8_t* payload);  // Size of the payload is in the header.
52 
53   void WithPictureId(uint8_t picture_id,
54                      uint16_t first_macroblock = 0,
55                      uint16_t number_macroblocks = 0x1fff) {
56     items_.push_back(
57         Macroblocks(picture_id, first_macroblock, number_macroblocks));
58   }
59 
macroblocks()60   const std::vector<Macroblocks>& macroblocks() const { return items_; }
61 
62  protected:
63   bool Create(uint8_t* packet,
64               size_t* index,
65               size_t max_length,
66               RtcpPacket::PacketReadyCallback* callback) const override;
67 
68  private:
BlockLength()69   size_t BlockLength() const override {
70     return RtcpPacket::kHeaderLength + Psfb::kCommonFeedbackLength +
71            items_.size() * Macroblocks::kLength;
72   }
73 
74   std::vector<Macroblocks> items_;
75 
76   RTC_DISALLOW_COPY_AND_ASSIGN(Sli);
77 };
78 
79 }  // namespace rtcp
80 }  // namespace webrtc
81 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_SLI_H_
82