2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-09 13:14:04 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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_SENDER_VIDEO_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-04 07:23:56 -07:00
|
|
|
#include <map>
|
2016-10-02 10:54:29 -07:00
|
|
|
#include <memory>
|
2012-01-20 06:59:06 +00:00
|
|
|
|
2018-06-14 12:59:38 +02:00
|
|
|
#include "absl/types/optional.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "common_types.h" // NOLINT(build/include)
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/flexfec_sender.h"
|
|
|
|
|
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_sender.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_utility.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/ulpfec_generator.h"
|
|
|
|
|
#include "rtc_base/criticalsection.h"
|
|
|
|
|
#include "rtc_base/onetimeevent.h"
|
|
|
|
|
#include "rtc_base/rate_statistics.h"
|
|
|
|
|
#include "rtc_base/sequenced_task_checker.h"
|
|
|
|
|
#include "rtc_base/thread_annotations.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2017-09-04 07:23:56 -07:00
|
|
|
class RtpPacketizer;
|
2016-10-02 10:54:29 -07:00
|
|
|
class RtpPacketToSend;
|
2012-01-20 06:59:06 +00:00
|
|
|
|
2014-09-12 11:05:55 +00:00
|
|
|
class RTPSenderVideo {
|
|
|
|
|
public:
|
2017-09-04 07:23:56 -07:00
|
|
|
static constexpr int64_t kTLRateWindowSizeMs = 2500;
|
|
|
|
|
|
2016-11-10 05:04:48 -08:00
|
|
|
RTPSenderVideo(Clock* clock,
|
|
|
|
|
RTPSender* rtpSender,
|
|
|
|
|
FlexfecSender* flexfec_sender);
|
2014-09-12 11:05:55 +00:00
|
|
|
virtual ~RTPSenderVideo();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-06-04 11:14:38 +02:00
|
|
|
virtual enum VideoCodecType VideoCodecType() const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-04-14 21:28:08 +02:00
|
|
|
static RtpUtility::Payload* CreateVideoPayload(
|
2016-07-28 15:19:10 -07:00
|
|
|
const char payload_name[RTP_PAYLOAD_NAME_SIZE],
|
|
|
|
|
int8_t payload_type);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-06-04 11:14:38 +02:00
|
|
|
bool SendVideo(enum VideoCodecType video_type,
|
2016-08-02 17:46:41 -07:00
|
|
|
FrameType frame_type,
|
|
|
|
|
int8_t payload_type,
|
|
|
|
|
uint32_t capture_timestamp,
|
|
|
|
|
int64_t capture_time_ms,
|
|
|
|
|
const uint8_t* payload_data,
|
|
|
|
|
size_t payload_size,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation,
|
2017-09-04 07:23:56 -07:00
|
|
|
const RTPVideoHeader* video_header,
|
|
|
|
|
int64_t expected_retransmission_time_ms);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-06-04 11:14:38 +02:00
|
|
|
void SetVideoCodecType(enum VideoCodecType type);
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2016-11-07 03:05:06 -08:00
|
|
|
// ULPFEC.
|
|
|
|
|
void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type);
|
|
|
|
|
void GetUlpfecConfig(int* red_payload_type, int* ulpfec_payload_type) const;
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2016-11-14 05:14:50 -08:00
|
|
|
// FlexFEC/ULPFEC.
|
2016-11-07 03:36:05 -08:00
|
|
|
void SetFecParameters(const FecProtectionParams& delta_params,
|
|
|
|
|
const FecProtectionParams& key_params);
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2016-11-14 05:14:50 -08:00
|
|
|
// FlexFEC.
|
2018-06-14 12:59:38 +02:00
|
|
|
absl::optional<uint32_t> FlexfecSsrc() const;
|
2016-11-14 05:14:50 -08:00
|
|
|
|
2014-09-12 11:05:55 +00:00
|
|
|
uint32_t VideoBitrateSent() const;
|
|
|
|
|
uint32_t FecOverheadRate() const;
|
|
|
|
|
|
|
|
|
|
int SelectiveRetransmissions() const;
|
2015-04-14 21:28:08 +02:00
|
|
|
void SetSelectiveRetransmissions(uint8_t settings);
|
|
|
|
|
|
2017-09-04 07:23:56 -07:00
|
|
|
protected:
|
|
|
|
|
static uint8_t GetTemporalId(const RTPVideoHeader& header);
|
|
|
|
|
StorageType GetStorageType(uint8_t temporal_id,
|
|
|
|
|
int32_t retransmission_settings,
|
|
|
|
|
int64_t expected_retransmission_time_ms);
|
|
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
private:
|
2017-09-04 07:23:56 -07:00
|
|
|
struct TemporalLayerStats {
|
|
|
|
|
TemporalLayerStats()
|
|
|
|
|
: frame_rate_fp1000s(kTLRateWindowSizeMs, 1000 * 1000),
|
|
|
|
|
last_frame_time_ms(0) {}
|
|
|
|
|
// Frame rate, in frames per 1000 seconds. This essentially turns the fps
|
|
|
|
|
// value into a fixed point value with three decimals. Improves precision at
|
|
|
|
|
// low frame rates.
|
|
|
|
|
RateStatistics frame_rate_fp1000s;
|
|
|
|
|
int64_t last_frame_time_ms;
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
size_t CalculateFecPacketOverhead() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2016-11-11 02:27:35 -08:00
|
|
|
|
2016-10-02 10:54:29 -07:00
|
|
|
void SendVideoPacket(std::unique_ptr<RtpPacketToSend> packet,
|
2015-04-14 21:28:08 +02:00
|
|
|
StorageType storage);
|
|
|
|
|
|
2016-11-10 05:01:11 -08:00
|
|
|
void SendVideoPacketAsRedMaybeWithUlpfec(
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> media_packet,
|
|
|
|
|
StorageType media_packet_storage,
|
|
|
|
|
bool protect_media_packet);
|
|
|
|
|
|
|
|
|
|
// TODO(brandtr): Remove the FlexFEC functions when FlexfecSender has been
|
|
|
|
|
// moved to PacedSender.
|
|
|
|
|
void SendVideoPacketWithFlexfec(std::unique_ptr<RtpPacketToSend> media_packet,
|
|
|
|
|
StorageType media_packet_storage,
|
|
|
|
|
bool protect_media_packet);
|
2015-04-14 21:28:08 +02:00
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
bool red_enabled() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
|
2016-11-07 03:05:06 -08:00
|
|
|
return red_payload_type_ >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
bool ulpfec_enabled() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
|
2016-11-07 03:05:06 -08:00
|
|
|
return ulpfec_payload_type_ >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-10 05:01:11 -08:00
|
|
|
bool flexfec_enabled() const { return flexfec_sender_ != nullptr; }
|
|
|
|
|
|
2017-09-04 07:23:56 -07:00
|
|
|
bool UpdateConditionalRetransmit(uint8_t temporal_id,
|
|
|
|
|
int64_t expected_retransmission_time_ms)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(stats_crit_);
|
2017-09-04 07:23:56 -07:00
|
|
|
|
2016-08-09 07:43:25 -07:00
|
|
|
RTPSender* const rtp_sender_;
|
2016-07-13 09:11:28 -07:00
|
|
|
Clock* const clock_;
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2015-04-14 21:28:08 +02:00
|
|
|
// Should never be held when calling out of this class.
|
2016-07-13 09:11:28 -07:00
|
|
|
rtc::CriticalSection crit_;
|
2015-04-14 21:28:08 +02:00
|
|
|
|
2018-06-04 11:14:38 +02:00
|
|
|
enum VideoCodecType video_type_;
|
2017-09-07 07:53:45 -07:00
|
|
|
int32_t retransmission_settings_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
VideoRotation last_rotation_ RTC_GUARDED_BY(crit_);
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2016-11-07 03:05:06 -08:00
|
|
|
// RED/ULPFEC.
|
2017-09-07 07:53:45 -07:00
|
|
|
int red_payload_type_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
int ulpfec_payload_type_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
UlpfecGenerator ulpfec_generator_ RTC_GUARDED_BY(crit_);
|
2016-11-10 05:01:11 -08:00
|
|
|
|
|
|
|
|
// FlexFEC.
|
|
|
|
|
FlexfecSender* const flexfec_sender_;
|
|
|
|
|
|
|
|
|
|
// FEC parameters, applicable to either ULPFEC or FlexFEC.
|
2017-09-07 07:53:45 -07:00
|
|
|
FecProtectionParams delta_fec_params_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
FecProtectionParams key_fec_params_ RTC_GUARDED_BY(crit_);
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2016-07-13 09:11:28 -07:00
|
|
|
rtc::CriticalSection stats_crit_;
|
2014-09-12 11:05:55 +00:00
|
|
|
// Bitrate used for FEC payload, RED headers, RTP headers for FEC packets
|
|
|
|
|
// and any padding overhead.
|
2017-09-07 07:53:45 -07:00
|
|
|
RateStatistics fec_bitrate_ RTC_GUARDED_BY(stats_crit_);
|
2016-07-13 09:11:28 -07:00
|
|
|
// Bitrate used for video payload and RTP headers.
|
2017-09-07 07:53:45 -07:00
|
|
|
RateStatistics video_bitrate_ RTC_GUARDED_BY(stats_crit_);
|
2017-09-04 07:23:56 -07:00
|
|
|
|
|
|
|
|
std::map<int, TemporalLayerStats> frame_stats_by_temporal_layer_
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_GUARDED_BY(stats_crit_);
|
2017-09-04 07:23:56 -07:00
|
|
|
|
2016-04-07 15:36:45 -07:00
|
|
|
OneTimeEvent first_frame_sent_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2016-07-28 15:19:10 -07:00
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_H_
|