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_H264_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2016-06-02 02:43:32 -07:00
|
|
|
#include <deque>
|
2016-12-05 02:26:44 -08:00
|
|
|
#include <memory>
|
2014-07-31 14:59:24 +00:00
|
|
|
#include <queue>
|
|
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "api/array_view.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_format.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
|
|
|
|
#include "modules/video_coding/codecs/h264/include/h264_globals.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/buffer.h"
|
2014-07-31 14:59:24 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class RtpPacketizerH264 : public RtpPacketizer {
|
|
|
|
|
public:
|
|
|
|
|
// Initialize with payload from encoder.
|
|
|
|
|
// The payload_data must be exactly one encoded H264 frame.
|
2018-09-12 10:23:15 +02:00
|
|
|
RtpPacketizerH264(rtc::ArrayView<const uint8_t> payload,
|
|
|
|
|
PayloadSizeLimits limits,
|
2020-07-10 10:21:49 +02:00
|
|
|
H264PacketizationMode packetization_mode);
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2018-02-07 09:38:31 +01:00
|
|
|
~RtpPacketizerH264() override;
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
RtpPacketizerH264(const RtpPacketizerH264&) = delete;
|
|
|
|
|
RtpPacketizerH264& operator=(const RtpPacketizerH264&) = delete;
|
|
|
|
|
|
2018-08-28 19:45:31 +02:00
|
|
|
size_t NumPackets() const override;
|
2014-07-31 14:59:24 +00:00
|
|
|
|
|
|
|
|
// Get the next payload with H264 payload header.
|
2021-07-28 23:57:33 +02:00
|
|
|
// Write payload and set marker bit of the `packet`.
|
2016-12-05 02:26:44 -08:00
|
|
|
// Returns true on success, false otherwise.
|
2017-05-23 09:34:21 -07:00
|
|
|
bool NextPacket(RtpPacketToSend* rtp_packet) override;
|
2014-07-31 14:59:24 +00:00
|
|
|
|
|
|
|
|
private:
|
2016-06-02 02:43:32 -07:00
|
|
|
// A packet unit (H264 packet), to be put into an RTP packet:
|
|
|
|
|
// If a NAL unit is too large for an RTP packet, this packet unit will
|
|
|
|
|
// represent a FU-A packet of a single fragment of the NAL unit.
|
|
|
|
|
// If a NAL unit is small enough to fit within a single RTP packet, this
|
|
|
|
|
// packet unit may represent a single NAL unit or a STAP-A packet, of which
|
|
|
|
|
// there may be multiple in a single RTP packet (if so, aggregated = true).
|
|
|
|
|
struct PacketUnit {
|
2019-10-15 15:12:35 +02:00
|
|
|
PacketUnit(rtc::ArrayView<const uint8_t> source_fragment,
|
2016-06-02 02:43:32 -07:00
|
|
|
bool first_fragment,
|
|
|
|
|
bool last_fragment,
|
|
|
|
|
bool aggregated,
|
|
|
|
|
uint8_t header)
|
|
|
|
|
: source_fragment(source_fragment),
|
2014-07-31 14:59:24 +00:00
|
|
|
first_fragment(first_fragment),
|
|
|
|
|
last_fragment(last_fragment),
|
|
|
|
|
aggregated(aggregated),
|
|
|
|
|
header(header) {}
|
|
|
|
|
|
2019-10-15 15:12:35 +02:00
|
|
|
rtc::ArrayView<const uint8_t> source_fragment;
|
2014-07-31 14:59:24 +00:00
|
|
|
bool first_fragment;
|
|
|
|
|
bool last_fragment;
|
|
|
|
|
bool aggregated;
|
|
|
|
|
uint8_t header;
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-12 10:23:15 +02:00
|
|
|
bool GeneratePackets(H264PacketizationMode packetization_mode);
|
2018-09-25 11:40:44 +02:00
|
|
|
bool PacketizeFuA(size_t fragment_index);
|
2016-06-02 02:43:32 -07:00
|
|
|
size_t PacketizeStapA(size_t fragment_index);
|
2018-03-15 15:46:17 +01:00
|
|
|
bool PacketizeSingleNalu(size_t fragment_index);
|
2018-09-25 11:40:44 +02:00
|
|
|
|
|
|
|
|
void NextAggregatePacket(RtpPacketToSend* rtp_packet);
|
2016-12-05 02:26:44 -08:00
|
|
|
void NextFragmentPacket(RtpPacketToSend* rtp_packet);
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2018-09-25 11:40:44 +02:00
|
|
|
const PayloadSizeLimits limits_;
|
2017-05-23 09:34:21 -07:00
|
|
|
size_t num_packets_left_;
|
2019-10-15 15:12:35 +02:00
|
|
|
std::deque<rtc::ArrayView<const uint8_t>> input_fragments_;
|
2016-06-02 02:43:32 -07:00
|
|
|
std::queue<PacketUnit> packets_;
|
2014-07-31 14:59:24 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_
|