2014-07-31 14:59:24 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-08-28 19:45:31 +02:00
|
|
|
#include <memory>
|
2018-09-04 16:11:58 +02:00
|
|
|
#include <vector>
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2019-05-23 13:21:12 +02:00
|
|
|
#include "absl/types/optional.h"
|
2018-08-28 19:45:31 +02:00
|
|
|
#include "api/array_view.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/include/module_common_types.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_video_header.h"
|
2014-07-31 14:59:24 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2018-10-23 12:03:01 +02:00
|
|
|
|
2016-12-05 02:26:44 -08:00
|
|
|
class RtpPacketToSend;
|
2014-07-31 14:59:24 +00:00
|
|
|
|
|
|
|
|
class RtpPacketizer {
|
|
|
|
|
public:
|
2018-08-28 19:45:31 +02:00
|
|
|
struct PayloadSizeLimits {
|
2018-09-07 10:57:26 +02:00
|
|
|
int max_payload_len = 1200;
|
|
|
|
|
int first_packet_reduction_len = 0;
|
|
|
|
|
int last_packet_reduction_len = 0;
|
2018-10-12 17:51:22 +02:00
|
|
|
// Reduction len for packet that is first & last at the same time.
|
|
|
|
|
int single_packet_reduction_len = 0;
|
2018-08-28 19:45:31 +02:00
|
|
|
};
|
2019-05-23 13:21:12 +02:00
|
|
|
|
|
|
|
|
// If type is not set, returns a raw packetizer.
|
2018-08-28 19:45:31 +02:00
|
|
|
static std::unique_ptr<RtpPacketizer> Create(
|
2019-05-23 13:21:12 +02:00
|
|
|
absl::optional<VideoCodecType> type,
|
2018-08-28 19:45:31 +02:00
|
|
|
rtc::ArrayView<const uint8_t> payload,
|
|
|
|
|
PayloadSizeLimits limits,
|
|
|
|
|
// Codec-specific details.
|
|
|
|
|
const RTPVideoHeader& rtp_video_header,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation);
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2018-08-28 19:45:31 +02:00
|
|
|
virtual ~RtpPacketizer() = default;
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2018-08-28 19:45:31 +02:00
|
|
|
// Returns number of remaining packets to produce by the packetizer.
|
|
|
|
|
virtual size_t NumPackets() const = 0;
|
2014-07-31 14:59:24 +00:00
|
|
|
|
|
|
|
|
// Get the next payload with payload header.
|
2016-12-05 02:26:44 -08:00
|
|
|
// Write payload and set marker bit of the |packet|.
|
|
|
|
|
// Returns true on success, false otherwise.
|
2017-05-23 09:34:21 -07:00
|
|
|
virtual bool NextPacket(RtpPacketToSend* packet) = 0;
|
2018-09-04 16:11:58 +02:00
|
|
|
|
|
|
|
|
// Split payload_len into sum of integers with respect to |limits|.
|
2018-09-07 10:57:26 +02:00
|
|
|
// Returns empty vector on failure.
|
|
|
|
|
static std::vector<int> SplitAboutEqually(int payload_len,
|
|
|
|
|
const PayloadSizeLimits& limits);
|
2014-07-31 14:59:24 +00:00
|
|
|
};
|
|
|
|
|
|
2016-06-02 02:43:32 -07:00
|
|
|
// TODO(sprang): Update the depacketizer to return a std::unqie_ptr with a copy
|
|
|
|
|
// of the parsed payload, rather than just a pointer into the incoming buffer.
|
|
|
|
|
// This way we can move some parsing out from the jitter buffer into here, and
|
|
|
|
|
// the jitter buffer can just store that pointer rather than doing a copy there.
|
2014-07-31 14:59:24 +00:00
|
|
|
class RtpDepacketizer {
|
|
|
|
|
public:
|
2014-09-29 08:00:22 +00:00
|
|
|
struct ParsedPayload {
|
2018-07-04 16:55:55 +02:00
|
|
|
RTPVideoHeader& video_header() { return video; }
|
|
|
|
|
const RTPVideoHeader& video_header() const { return video; }
|
2019-04-18 11:14:27 +02:00
|
|
|
|
2018-07-04 16:55:55 +02:00
|
|
|
RTPVideoHeader video;
|
|
|
|
|
|
2014-09-29 08:00:22 +00:00
|
|
|
const uint8_t* payload;
|
|
|
|
|
size_t payload_length;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-23 13:21:12 +02:00
|
|
|
// If type is not set, returns a raw depacketizer.
|
|
|
|
|
static RtpDepacketizer* Create(absl::optional<VideoCodecType> type);
|
2014-07-31 14:59:24 +00:00
|
|
|
|
|
|
|
|
virtual ~RtpDepacketizer() {}
|
|
|
|
|
|
2014-09-29 08:00:22 +00:00
|
|
|
// Parses the RTP payload, parsed result will be saved in |parsed_payload|.
|
|
|
|
|
virtual bool Parse(ParsedPayload* parsed_payload,
|
2014-07-31 14:59:24 +00:00
|
|
|
const uint8_t* payload_data,
|
|
|
|
|
size_t payload_data_length) = 0;
|
|
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H_
|