1 /*
2  *  Copyright (c) 2014 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 MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
12 #define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
13 
14 #include <stdint.h>
15 
16 #include <memory>
17 #include <vector>
18 
19 #include "absl/types/optional.h"
20 #include "api/array_view.h"
21 #include "modules/rtp_rtcp/source/rtp_video_header.h"
22 
23 namespace webrtc {
24 
25 class RtpPacketToSend;
26 
27 class RtpPacketizer {
28  public:
29   struct PayloadSizeLimits {
30     int max_payload_len = 1200;
31     int first_packet_reduction_len = 0;
32     int last_packet_reduction_len = 0;
33     // Reduction len for packet that is first & last at the same time.
34     int single_packet_reduction_len = 0;
35   };
36 
37   // If type is not set, returns a raw packetizer.
38   static std::unique_ptr<RtpPacketizer> Create(
39       absl::optional<VideoCodecType> type,
40       rtc::ArrayView<const uint8_t> payload,
41       PayloadSizeLimits limits,
42       // Codec-specific details.
43       const RTPVideoHeader& rtp_video_header);
44 
45   virtual ~RtpPacketizer() = default;
46 
47   // Returns number of remaining packets to produce by the packetizer.
48   virtual size_t NumPackets() const = 0;
49 
50   // Get the next payload with payload header.
51   // Write payload and set marker bit of the |packet|.
52   // Returns true on success, false otherwise.
53   virtual bool NextPacket(RtpPacketToSend* packet) = 0;
54 
55   // Split payload_len into sum of integers with respect to |limits|.
56   // Returns empty vector on failure.
57   static std::vector<int> SplitAboutEqually(int payload_len,
58                                             const PayloadSizeLimits& limits);
59 };
60 }  // namespace webrtc
61 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
62