blob: f945d24b0a823006a15151c28031a67c4fa6228d [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
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020014#include <memory>
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000015#include <string>
Danil Chapovalov376e1142018-09-04 16:11:58 +020016#include <vector>
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000017
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020018#include "api/array_view.h"
Niels Möller520ca4e2018-06-04 11:14:38 +020019#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#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.org2ec56062014-07-31 14:59:24 +000023
24namespace webrtc {
danilchape545e5d2016-12-05 02:26:44 -080025class RtpPacketToSend;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000026
27class RtpPacketizer {
28 public:
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020029 struct PayloadSizeLimits {
30 size_t max_payload_len = 1200;
31 size_t last_packet_reduction_len = 0;
32 };
33 static std::unique_ptr<RtpPacketizer> Create(
34 VideoCodecType type,
35 rtc::ArrayView<const uint8_t> payload,
36 PayloadSizeLimits limits,
37 // Codec-specific details.
38 const RTPVideoHeader& rtp_video_header,
39 FrameType frame_type,
40 const RTPFragmentationHeader* fragmentation);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000041
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020042 virtual ~RtpPacketizer() = default;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000043
Danil Chapovalovf7f8a1f2018-08-28 19:45:31 +020044 // Returns number of remaining packets to produce by the packetizer.
45 virtual size_t NumPackets() const = 0;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000046
47 // Get the next payload with payload header.
danilchape545e5d2016-12-05 02:26:44 -080048 // Write payload and set marker bit of the |packet|.
danilchape545e5d2016-12-05 02:26:44 -080049 // Returns true on success, false otherwise.
ilnik7a3006b2017-05-23 09:34:21 -070050 virtual bool NextPacket(RtpPacketToSend* packet) = 0;
Danil Chapovalov376e1142018-09-04 16:11:58 +020051
52 // Split payload_len into sum of integers with respect to |limits|.
53 static std::vector<size_t> SplitAboutEqually(size_t payload_len,
54 const PayloadSizeLimits& limits);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000055};
56
sprang52033d62016-06-02 02:43:32 -070057// TODO(sprang): Update the depacketizer to return a std::unqie_ptr with a copy
58// of the parsed payload, rather than just a pointer into the incoming buffer.
59// This way we can move some parsing out from the jitter buffer into here, and
60// the jitter buffer can just store that pointer rather than doing a copy there.
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000061class RtpDepacketizer {
62 public:
pbos@webrtc.org730d2702014-09-29 08:00:22 +000063 struct ParsedPayload {
philipel011dc642018-07-04 16:55:55 +020064 RTPVideoHeader& video_header() { return video; }
65 const RTPVideoHeader& video_header() const { return video; }
66 RTPVideoHeader video;
67
pbos@webrtc.org730d2702014-09-29 08:00:22 +000068 const uint8_t* payload;
69 size_t payload_length;
pbos@webrtc.orgd42a3ad2014-11-07 11:02:12 +000070 FrameType frame_type;
pbos@webrtc.org730d2702014-09-29 08:00:22 +000071 };
72
Niels Möller520ca4e2018-06-04 11:14:38 +020073 static RtpDepacketizer* Create(VideoCodecType type);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000074
75 virtual ~RtpDepacketizer() {}
76
pbos@webrtc.org730d2702014-09-29 08:00:22 +000077 // Parses the RTP payload, parsed result will be saved in |parsed_payload|.
78 virtual bool Parse(ParsedPayload* parsed_payload,
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000079 const uint8_t* payload_data,
80 size_t payload_data_length) = 0;
81};
82} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020083#endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_