stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_ |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 13 | |
Danil Chapovalov | f7f8a1f | 2018-08-28 19:45:31 +0200 | [diff] [blame] | 14 | #include <memory> |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 15 | #include <string> |
Danil Chapovalov | 376e114 | 2018-09-04 16:11:58 +0200 | [diff] [blame] | 16 | #include <vector> |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 17 | |
Danil Chapovalov | f7f8a1f | 2018-08-28 19:45:31 +0200 | [diff] [blame] | 18 | #include "api/array_view.h" |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 19 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/include/module_common_types.h" |
| 21 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 22 | #include "rtc_base/constructormagic.h" |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
danilchap | e545e5d | 2016-12-05 02:26:44 -0800 | [diff] [blame] | 25 | class RtpPacketToSend; |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 26 | |
| 27 | class RtpPacketizer { |
| 28 | public: |
Danil Chapovalov | f7f8a1f | 2018-08-28 19:45:31 +0200 | [diff] [blame] | 29 | struct PayloadSizeLimits { |
Danil Chapovalov | fa5ec8d | 2018-09-07 10:57:26 +0200 | [diff] [blame] | 30 | int max_payload_len = 1200; |
| 31 | int first_packet_reduction_len = 0; |
| 32 | int last_packet_reduction_len = 0; |
Danil Chapovalov | fcebe0e | 2018-10-12 17:51:22 +0200 | [diff] [blame^] | 33 | // Reduction len for packet that is first & last at the same time. |
| 34 | int single_packet_reduction_len = 0; |
Danil Chapovalov | f7f8a1f | 2018-08-28 19:45:31 +0200 | [diff] [blame] | 35 | }; |
| 36 | static std::unique_ptr<RtpPacketizer> Create( |
| 37 | VideoCodecType type, |
| 38 | rtc::ArrayView<const uint8_t> payload, |
| 39 | PayloadSizeLimits limits, |
| 40 | // Codec-specific details. |
| 41 | const RTPVideoHeader& rtp_video_header, |
| 42 | FrameType frame_type, |
| 43 | const RTPFragmentationHeader* fragmentation); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 44 | |
Danil Chapovalov | f7f8a1f | 2018-08-28 19:45:31 +0200 | [diff] [blame] | 45 | virtual ~RtpPacketizer() = default; |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 46 | |
Danil Chapovalov | f7f8a1f | 2018-08-28 19:45:31 +0200 | [diff] [blame] | 47 | // Returns number of remaining packets to produce by the packetizer. |
| 48 | virtual size_t NumPackets() const = 0; |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 49 | |
| 50 | // Get the next payload with payload header. |
danilchap | e545e5d | 2016-12-05 02:26:44 -0800 | [diff] [blame] | 51 | // Write payload and set marker bit of the |packet|. |
danilchap | e545e5d | 2016-12-05 02:26:44 -0800 | [diff] [blame] | 52 | // Returns true on success, false otherwise. |
ilnik | 7a3006b | 2017-05-23 09:34:21 -0700 | [diff] [blame] | 53 | virtual bool NextPacket(RtpPacketToSend* packet) = 0; |
Danil Chapovalov | 376e114 | 2018-09-04 16:11:58 +0200 | [diff] [blame] | 54 | |
| 55 | // Split payload_len into sum of integers with respect to |limits|. |
Danil Chapovalov | fa5ec8d | 2018-09-07 10:57:26 +0200 | [diff] [blame] | 56 | // Returns empty vector on failure. |
| 57 | static std::vector<int> SplitAboutEqually(int payload_len, |
| 58 | const PayloadSizeLimits& limits); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
sprang | 52033d6 | 2016-06-02 02:43:32 -0700 | [diff] [blame] | 61 | // TODO(sprang): Update the depacketizer to return a std::unqie_ptr with a copy |
| 62 | // of the parsed payload, rather than just a pointer into the incoming buffer. |
| 63 | // This way we can move some parsing out from the jitter buffer into here, and |
| 64 | // the jitter buffer can just store that pointer rather than doing a copy there. |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 65 | class RtpDepacketizer { |
| 66 | public: |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 67 | struct ParsedPayload { |
philipel | 011dc64 | 2018-07-04 16:55:55 +0200 | [diff] [blame] | 68 | RTPVideoHeader& video_header() { return video; } |
| 69 | const RTPVideoHeader& video_header() const { return video; } |
| 70 | RTPVideoHeader video; |
| 71 | |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 72 | const uint8_t* payload; |
| 73 | size_t payload_length; |
pbos@webrtc.org | d42a3ad | 2014-11-07 11:02:12 +0000 | [diff] [blame] | 74 | FrameType frame_type; |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 77 | static RtpDepacketizer* Create(VideoCodecType type); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 78 | |
| 79 | virtual ~RtpDepacketizer() {} |
| 80 | |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 81 | // Parses the RTP payload, parsed result will be saved in |parsed_payload|. |
| 82 | virtual bool Parse(ParsedPayload* parsed_payload, |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 83 | const uint8_t* payload_data, |
| 84 | size_t payload_data_length) = 0; |
| 85 | }; |
| 86 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 87 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_ |