blob: e702270f45efc1f973c8e9870ed7eb03ff6a693c [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
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000014#include <string>
15
Niels Möller520ca4e2018-06-04 11:14:38 +020016#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/include/module_common_types.h"
18#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19#include "rtc_base/constructormagic.h"
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000020
21namespace webrtc {
danilchape545e5d2016-12-05 02:26:44 -080022class RtpPacketToSend;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000023
24class RtpPacketizer {
25 public:
Niels Möller520ca4e2018-06-04 11:14:38 +020026 static RtpPacketizer* Create(VideoCodecType type,
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000027 size_t max_payload_len,
ilnik7a3006b2017-05-23 09:34:21 -070028 size_t last_packet_reduction_len,
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000029 const RTPVideoTypeHeader* rtp_type_header,
30 FrameType frame_type);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000031
32 virtual ~RtpPacketizer() {}
33
ilnik7a3006b2017-05-23 09:34:21 -070034 // Returns total number of packets which would be produced by the packetizer.
35 virtual size_t SetPayloadData(
36 const uint8_t* payload_data,
37 size_t payload_size,
38 const RTPFragmentationHeader* fragmentation) = 0;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000039
40 // Get the next payload with payload header.
danilchape545e5d2016-12-05 02:26:44 -080041 // Write payload and set marker bit of the |packet|.
danilchape545e5d2016-12-05 02:26:44 -080042 // Returns true on success, false otherwise.
ilnik7a3006b2017-05-23 09:34:21 -070043 virtual bool NextPacket(RtpPacketToSend* packet) = 0;
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000044
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000045 virtual std::string ToString() = 0;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000046};
47
sprang52033d62016-06-02 02:43:32 -070048// TODO(sprang): Update the depacketizer to return a std::unqie_ptr with a copy
49// of the parsed payload, rather than just a pointer into the incoming buffer.
50// This way we can move some parsing out from the jitter buffer into here, and
51// the jitter buffer can just store that pointer rather than doing a copy there.
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000052class RtpDepacketizer {
53 public:
pbos@webrtc.org730d2702014-09-29 08:00:22 +000054 struct ParsedPayload {
pbos@webrtc.org730d2702014-09-29 08:00:22 +000055 const uint8_t* payload;
56 size_t payload_length;
pbos@webrtc.orgd42a3ad2014-11-07 11:02:12 +000057 FrameType frame_type;
philipelcb96ad82018-07-02 14:41:58 +020058 RTPVideoHeader& video_header() { return type.Video; }
59 const RTPVideoHeader& video_header() const { return type.Video; }
pbos@webrtc.orgd42a3ad2014-11-07 11:02:12 +000060 RTPTypeHeader type;
pbos@webrtc.org730d2702014-09-29 08:00:22 +000061 };
62
Niels Möller520ca4e2018-06-04 11:14:38 +020063 static RtpDepacketizer* Create(VideoCodecType type);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000064
65 virtual ~RtpDepacketizer() {}
66
pbos@webrtc.org730d2702014-09-29 08:00:22 +000067 // Parses the RTP payload, parsed result will be saved in |parsed_payload|.
68 virtual bool Parse(ParsedPayload* parsed_payload,
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000069 const uint8_t* payload_data,
70 size_t payload_data_length) = 0;
71};
72} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020073#endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_