blob: 1d9c1429a8da24e5c0b07f0dcaee8f13752b6016 [file] [log] [blame]
stefan@webrtc.org2ec56062014-07-31 14:59:24 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
12#define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020016#include <memory>
Danil Chapovalov376e1142018-09-04 16:11:58 +020017#include <vector>
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000018
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +020019#include "absl/types/optional.h"
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020020#include "api/array_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/include/module_common_types.h"
Yves Gerey988cc082018-10-23 12:03:01 +020022#include "modules/rtp_rtcp/source/rtp_video_header.h"
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000023
24namespace webrtc {
Yves Gerey988cc082018-10-23 12:03:01 +020025
danilchape545e5d2016-12-05 02:26:44 -080026class RtpPacketToSend;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000027
28class RtpPacketizer {
29 public:
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020030 struct PayloadSizeLimits {
Danil Chapovalovfa5ec8d2018-09-07 10:57:26 +020031 int max_payload_len = 1200;
32 int first_packet_reduction_len = 0;
33 int last_packet_reduction_len = 0;
Danil Chapovalovfcebe0e2018-10-12 17:51:22 +020034 // Reduction len for packet that is first & last at the same time.
35 int single_packet_reduction_len = 0;
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020036 };
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +020037
38 // If type is not set, returns a raw packetizer.
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020039 static std::unique_ptr<RtpPacketizer> Create(
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +020040 absl::optional<VideoCodecType> type,
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020041 rtc::ArrayView<const uint8_t> payload,
42 PayloadSizeLimits limits,
43 // Codec-specific details.
44 const RTPVideoHeader& rtp_video_header,
Niels Möller87e2d782019-03-07 10:18:23 +010045 VideoFrameType frame_type,
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020046 const RTPFragmentationHeader* fragmentation);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000047
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020048 virtual ~RtpPacketizer() = default;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000049
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020050 // Returns number of remaining packets to produce by the packetizer.
51 virtual size_t NumPackets() const = 0;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000052
53 // Get the next payload with payload header.
danilchape545e5d2016-12-05 02:26:44 -080054 // Write payload and set marker bit of the |packet|.
danilchape545e5d2016-12-05 02:26:44 -080055 // Returns true on success, false otherwise.
ilnik7a3006b2017-05-23 09:34:21 -070056 virtual bool NextPacket(RtpPacketToSend* packet) = 0;
Danil Chapovalov376e1142018-09-04 16:11:58 +020057
58 // Split payload_len into sum of integers with respect to |limits|.
Danil Chapovalovfa5ec8d2018-09-07 10:57:26 +020059 // Returns empty vector on failure.
60 static std::vector<int> SplitAboutEqually(int payload_len,
61 const PayloadSizeLimits& limits);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000062};
63
sprang52033d62016-06-02 02:43:32 -070064// TODO(sprang): Update the depacketizer to return a std::unqie_ptr with a copy
65// of the parsed payload, rather than just a pointer into the incoming buffer.
66// This way we can move some parsing out from the jitter buffer into here, and
67// the jitter buffer can just store that pointer rather than doing a copy there.
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000068class RtpDepacketizer {
69 public:
pbos@webrtc.org730d2702014-09-29 08:00:22 +000070 struct ParsedPayload {
philipel011dc642018-07-04 16:55:55 +020071 RTPVideoHeader& video_header() { return video; }
72 const RTPVideoHeader& video_header() const { return video; }
Niels Möller58fa7162019-04-18 11:14:27 +020073
74 // TODO(bugs.webrtc.org/10397): These are temporary accessors, to enable
75 // move of the frame_type member to inside RTPVideoHeader, without breaking
76 // downstream code.
Niels Möllerabbc50e2019-04-24 09:41:16 +020077 VideoFrameType FrameType() const { return video_header().frame_type; }
78 void SetFrameType(VideoFrameType type) { video_header().frame_type = type; }
Niels Möller58fa7162019-04-18 11:14:27 +020079
philipel011dc642018-07-04 16:55:55 +020080 RTPVideoHeader video;
81
pbos@webrtc.org730d2702014-09-29 08:00:22 +000082 const uint8_t* payload;
83 size_t payload_length;
pbos@webrtc.org730d2702014-09-29 08:00:22 +000084 };
85
Mirta Dvornicicfe68daa2019-05-23 13:21:12 +020086 // If type is not set, returns a raw depacketizer.
87 static RtpDepacketizer* Create(absl::optional<VideoCodecType> type);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000088
89 virtual ~RtpDepacketizer() {}
90
pbos@webrtc.org730d2702014-09-29 08:00:22 +000091 // Parses the RTP payload, parsed result will be saved in |parsed_payload|.
92 virtual bool Parse(ParsedPayload* parsed_payload,
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000093 const uint8_t* payload_data,
94 size_t payload_data_length) = 0;
95};
96} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020097#endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_