1 /*
2  *  Copyright (c) 2011 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  * This file contains the declaration of the VP8 packetizer class.
13  * A packetizer object is created for each encoded video frame. The
14  * constructor is called with the payload data and size,
15  * together with the fragmentation information and a packetizer mode
16  * of choice. Alternatively, if no fragmentation info is available, the
17  * second constructor can be used with only payload data and size; in that
18  * case the mode kEqualSize is used.
19  *
20  * After creating the packetizer, the method NextPacket is called
21  * repeatedly to get all packets for the frame. The method returns
22  * false as long as there are more packets left to fetch.
23  */
24 
25 #ifndef MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
26 #define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
27 
28 #include <stddef.h>
29 
30 #include <cstdint>
31 #include <vector>
32 
33 #include "absl/container/inlined_vector.h"
34 #include "api/array_view.h"
35 #include "modules/rtp_rtcp/source/rtp_format.h"
36 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
37 #include "modules/video_coding/codecs/vp8/include/vp8_globals.h"
38 #include "rtc_base/constructor_magic.h"
39 
40 namespace webrtc {
41 
42 // Packetizer for VP8.
43 class RtpPacketizerVp8 : public RtpPacketizer {
44  public:
45   // Initialize with payload from encoder.
46   // The payload_data must be exactly one encoded VP8 frame.
47   RtpPacketizerVp8(rtc::ArrayView<const uint8_t> payload,
48                    PayloadSizeLimits limits,
49                    const RTPVideoHeaderVP8& hdr_info);
50 
51   ~RtpPacketizerVp8() override;
52 
53   size_t NumPackets() const override;
54 
55   // Get the next payload with VP8 payload header.
56   // Write payload and set marker bit of the |packet|.
57   // Returns true on success, false otherwise.
58   bool NextPacket(RtpPacketToSend* packet) override;
59 
60  private:
61   // VP8 header can use up to 6 bytes.
62   using RawHeader = absl::InlinedVector<uint8_t, 6>;
63   static RawHeader BuildHeader(const RTPVideoHeaderVP8& header);
64 
65   RawHeader hdr_;
66   rtc::ArrayView<const uint8_t> remaining_payload_;
67   std::vector<int> payload_sizes_;
68   std::vector<int>::const_iterator current_packet_;
69 
70   RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerVp8);
71 };
72 
73 }  // namespace webrtc
74 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
75