2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-24 17:16:59 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-29 14:27:38 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2016-04-27 01:19:58 -07:00
|
|
|
#include <memory>
|
2015-04-14 21:28:08 +02:00
|
|
|
#include <vector>
|
2016-10-02 10:54:29 -07:00
|
|
|
#include <utility>
|
2015-04-14 21:28:08 +02:00
|
|
|
|
|
|
|
|
#include "webrtc/base/checks.h"
|
2015-10-28 16:39:33 +01:00
|
|
|
#include "webrtc/base/logging.h"
|
2015-10-20 23:00:48 -07:00
|
|
|
#include "webrtc/base/trace_event.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
2015-03-17 16:42:49 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
|
2013-05-29 14:27:38 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/producer_fec.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h"
|
2015-07-31 06:10:09 -07:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h"
|
2016-10-02 10:54:29 -07:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2016-07-28 15:19:10 -07:00
|
|
|
|
2016-09-13 03:23:29 -07:00
|
|
|
namespace {
|
|
|
|
|
constexpr size_t kRedForFecHeaderLength = 1;
|
2016-10-02 10:54:29 -07:00
|
|
|
|
|
|
|
|
void BuildRedPayload(const RtpPacketToSend& media_packet,
|
|
|
|
|
RtpPacketToSend* red_packet) {
|
|
|
|
|
uint8_t* red_payload = red_packet->AllocatePayload(
|
|
|
|
|
kRedForFecHeaderLength + media_packet.payload_size());
|
|
|
|
|
RTC_DCHECK(red_payload);
|
|
|
|
|
red_payload[0] = media_packet.PayloadType();
|
|
|
|
|
memcpy(&red_payload[kRedForFecHeaderLength], media_packet.payload(),
|
|
|
|
|
media_packet.payload_size());
|
|
|
|
|
}
|
2016-09-13 03:23:29 -07:00
|
|
|
} // namespace
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-08-09 07:43:25 -07:00
|
|
|
RTPSenderVideo::RTPSenderVideo(Clock* clock, RTPSender* rtp_sender)
|
2016-07-28 15:19:10 -07:00
|
|
|
: rtp_sender_(rtp_sender),
|
2016-07-13 09:11:28 -07:00
|
|
|
clock_(clock),
|
|
|
|
|
fec_bitrate_(1000, RateStatistics::kBpsScale),
|
2016-07-28 15:19:10 -07:00
|
|
|
video_bitrate_(1000, RateStatistics::kBpsScale) {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-07-28 15:19:10 -07:00
|
|
|
RTPSenderVideo::~RTPSenderVideo() {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-07-28 15:19:10 -07:00
|
|
|
void RTPSenderVideo::SetVideoCodecType(RtpVideoCodecTypes video_type) {
|
|
|
|
|
video_type_ = video_type;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-12 11:05:55 +00:00
|
|
|
RtpVideoCodecTypes RTPSenderVideo::VideoCodecType() const {
|
2016-07-28 15:19:10 -07:00
|
|
|
return video_type_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-14 21:28:08 +02:00
|
|
|
// Static.
|
|
|
|
|
RtpUtility::Payload* RTPSenderVideo::CreateVideoPayload(
|
2016-07-28 15:19:10 -07:00
|
|
|
const char payload_name[RTP_PAYLOAD_NAME_SIZE],
|
|
|
|
|
int8_t payload_type) {
|
|
|
|
|
RtpVideoCodecTypes video_type = kRtpVideoGeneric;
|
|
|
|
|
if (RtpUtility::StringCompare(payload_name, "VP8", 3)) {
|
|
|
|
|
video_type = kRtpVideoVp8;
|
|
|
|
|
} else if (RtpUtility::StringCompare(payload_name, "VP9", 3)) {
|
|
|
|
|
video_type = kRtpVideoVp9;
|
|
|
|
|
} else if (RtpUtility::StringCompare(payload_name, "H264", 4)) {
|
|
|
|
|
video_type = kRtpVideoH264;
|
|
|
|
|
} else if (RtpUtility::StringCompare(payload_name, "I420", 4)) {
|
|
|
|
|
video_type = kRtpVideoGeneric;
|
2012-01-20 06:59:06 +00:00
|
|
|
} else {
|
2016-07-28 15:19:10 -07:00
|
|
|
video_type = kRtpVideoGeneric;
|
2012-01-20 06:59:06 +00:00
|
|
|
}
|
2015-04-14 21:28:08 +02:00
|
|
|
RtpUtility::Payload* payload = new RtpUtility::Payload();
|
2012-01-24 17:16:59 +00:00
|
|
|
payload->name[RTP_PAYLOAD_NAME_SIZE - 1] = 0;
|
2016-07-28 15:19:10 -07:00
|
|
|
strncpy(payload->name, payload_name, RTP_PAYLOAD_NAME_SIZE - 1);
|
|
|
|
|
payload->typeSpecific.Video.videoCodecType = video_type;
|
2012-01-20 06:59:06 +00:00
|
|
|
payload->audio = false;
|
2015-04-14 21:28:08 +02:00
|
|
|
return payload;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 10:54:29 -07:00
|
|
|
void RTPSenderVideo::SendVideoPacket(std::unique_ptr<RtpPacketToSend> packet,
|
2015-04-14 21:28:08 +02:00
|
|
|
StorageType storage) {
|
2016-10-02 10:54:29 -07:00
|
|
|
// Remember some values about the packet before sending it away.
|
|
|
|
|
size_t packet_size = packet->size();
|
|
|
|
|
uint16_t seq_num = packet->SequenceNumber();
|
|
|
|
|
uint32_t rtp_timestamp = packet->Timestamp();
|
|
|
|
|
if (!rtp_sender_->SendToNetwork(std::move(packet), storage,
|
2016-08-02 17:46:41 -07:00
|
|
|
RtpPacketSender::kLowPriority)) {
|
2015-04-14 21:28:08 +02:00
|
|
|
LOG(LS_WARNING) << "Failed to send video packet " << seq_num;
|
2016-08-02 17:46:41 -07:00
|
|
|
return;
|
2015-04-14 21:28:08 +02:00
|
|
|
}
|
2016-08-02 17:46:41 -07:00
|
|
|
rtc::CritScope cs(&stats_crit_);
|
2016-10-02 10:54:29 -07:00
|
|
|
video_bitrate_.Update(packet_size, clock_->TimeInMilliseconds());
|
2016-08-02 17:46:41 -07:00
|
|
|
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
|
2016-08-22 03:39:23 -07:00
|
|
|
"Video::PacketNormal", "timestamp", rtp_timestamp,
|
2016-08-02 17:46:41 -07:00
|
|
|
"seqnum", seq_num);
|
2015-04-14 21:28:08 +02:00
|
|
|
}
|
2012-03-20 22:10:56 +00:00
|
|
|
|
2016-10-02 10:54:29 -07:00
|
|
|
void RTPSenderVideo::SendVideoPacketAsRed(
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> media_packet,
|
|
|
|
|
StorageType media_packet_storage,
|
|
|
|
|
bool protect) {
|
|
|
|
|
uint32_t rtp_timestamp = media_packet->Timestamp();
|
|
|
|
|
uint16_t media_seq_num = media_packet->SequenceNumber();
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> red_packet(
|
|
|
|
|
new RtpPacketToSend(*media_packet));
|
|
|
|
|
BuildRedPayload(*media_packet, red_packet.get());
|
|
|
|
|
|
2016-08-10 00:51:50 -07:00
|
|
|
std::vector<std::unique_ptr<RedPacket>> fec_packets;
|
2015-04-14 21:28:08 +02:00
|
|
|
StorageType fec_storage = kDontRetransmit;
|
|
|
|
|
{
|
|
|
|
|
// Only protect while creating RED and FEC packets, not when sending.
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2016-10-02 10:54:29 -07:00
|
|
|
red_packet->SetPayloadType(red_payload_type_);
|
2012-04-11 07:42:25 +00:00
|
|
|
if (protect) {
|
2016-10-02 10:54:29 -07:00
|
|
|
producer_fec_.AddRtpPacketAndGenerateFec(media_packet->data(),
|
|
|
|
|
media_packet->payload_size(),
|
|
|
|
|
media_packet->headers_size());
|
2015-03-31 15:07:16 +02:00
|
|
|
}
|
2015-04-14 21:28:08 +02:00
|
|
|
uint16_t num_fec_packets = producer_fec_.NumAvailableFecPackets();
|
|
|
|
|
if (num_fec_packets > 0) {
|
2016-10-02 10:54:29 -07:00
|
|
|
uint16_t first_fec_sequence_number =
|
2016-07-28 15:19:10 -07:00
|
|
|
rtp_sender_->AllocateSequenceNumber(num_fec_packets);
|
2016-10-04 10:57:36 +02:00
|
|
|
fec_packets = producer_fec_.GetUlpfecPacketsAsRed(
|
2016-10-02 10:54:29 -07:00
|
|
|
red_payload_type_, fec_payload_type_, first_fec_sequence_number,
|
|
|
|
|
media_packet->headers_size());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK_EQ(num_fec_packets, fec_packets.size());
|
2016-07-28 15:19:10 -07:00
|
|
|
if (retransmission_settings_ & kRetransmitFECPackets)
|
2015-04-14 21:28:08 +02:00
|
|
|
fec_storage = kAllowRetransmission;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-02 10:54:29 -07:00
|
|
|
// Send |red_packet| instead of |packet| for allocated sequence number.
|
|
|
|
|
size_t red_packet_size = red_packet->size();
|
|
|
|
|
if (rtp_sender_->SendToNetwork(std::move(red_packet), media_packet_storage,
|
|
|
|
|
RtpPacketSender::kLowPriority)) {
|
2016-07-13 09:11:28 -07:00
|
|
|
rtc::CritScope cs(&stats_crit_);
|
2016-10-02 10:54:29 -07:00
|
|
|
video_bitrate_.Update(red_packet_size, clock_->TimeInMilliseconds());
|
2015-04-14 21:28:08 +02:00
|
|
|
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
|
2016-08-22 03:39:23 -07:00
|
|
|
"Video::PacketRed", "timestamp", rtp_timestamp,
|
2015-04-14 21:28:08 +02:00
|
|
|
"seqnum", media_seq_num);
|
|
|
|
|
} else {
|
|
|
|
|
LOG(LS_WARNING) << "Failed to send RED packet " << media_seq_num;
|
|
|
|
|
}
|
2016-08-10 00:51:50 -07:00
|
|
|
for (const auto& fec_packet : fec_packets) {
|
2016-10-02 10:54:29 -07:00
|
|
|
// TODO(danilchap): Make producer_fec_ generate RtpPacketToSend to avoid
|
|
|
|
|
// reparsing them.
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> rtp_packet(
|
|
|
|
|
new RtpPacketToSend(*media_packet));
|
|
|
|
|
RTC_CHECK(rtp_packet->Parse(fec_packet->data(), fec_packet->length()));
|
|
|
|
|
rtp_packet->set_capture_time_ms(media_packet->capture_time_ms());
|
|
|
|
|
uint16_t fec_sequence_number = rtp_packet->SequenceNumber();
|
|
|
|
|
if (rtp_sender_->SendToNetwork(std::move(rtp_packet), fec_storage,
|
|
|
|
|
RtpPacketSender::kLowPriority)) {
|
2016-07-13 09:11:28 -07:00
|
|
|
rtc::CritScope cs(&stats_crit_);
|
|
|
|
|
fec_bitrate_.Update(fec_packet->length(), clock_->TimeInMilliseconds());
|
2015-02-16 12:06:00 +00:00
|
|
|
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
|
2016-08-22 03:39:23 -07:00
|
|
|
"Video::PacketFec", "timestamp", rtp_timestamp,
|
2016-10-02 10:54:29 -07:00
|
|
|
"seqnum", fec_sequence_number);
|
2015-04-14 21:28:08 +02:00
|
|
|
} else {
|
2016-10-02 10:54:29 -07:00
|
|
|
LOG(LS_WARNING) << "Failed to send FEC packet " << fec_sequence_number;
|
2011-10-27 16:08:29 +00:00
|
|
|
}
|
2012-03-20 22:10:56 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-28 15:19:10 -07:00
|
|
|
void RTPSenderVideo::SetGenericFECStatus(bool enable,
|
|
|
|
|
uint8_t payload_type_red,
|
|
|
|
|
uint8_t payload_type_fec) {
|
|
|
|
|
RTC_DCHECK(!enable || payload_type_red > 0);
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2015-12-08 09:10:43 +01:00
|
|
|
fec_enabled_ = enable;
|
2016-07-28 15:19:10 -07:00
|
|
|
red_payload_type_ = payload_type_red;
|
|
|
|
|
fec_payload_type_ = payload_type_fec;
|
|
|
|
|
delta_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom};
|
|
|
|
|
key_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom};
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-15 02:54:47 -08:00
|
|
|
void RTPSenderVideo::GenericFECStatus(bool* enable,
|
2016-07-28 15:19:10 -07:00
|
|
|
uint8_t* payload_type_red,
|
|
|
|
|
uint8_t* payload_type_fec) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2015-12-15 02:54:47 -08:00
|
|
|
*enable = fec_enabled_;
|
2016-07-28 15:19:10 -07:00
|
|
|
*payload_type_red = red_payload_type_;
|
|
|
|
|
*payload_type_fec = fec_payload_type_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-13 03:23:29 -07:00
|
|
|
size_t RTPSenderVideo::FecPacketOverhead() const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2016-06-03 00:16:45 -07:00
|
|
|
size_t overhead = 0;
|
|
|
|
|
if (red_payload_type_ != 0) {
|
2014-09-12 11:05:55 +00:00
|
|
|
// Overhead is FEC headers plus RED for FEC header plus anything in RTP
|
|
|
|
|
// header beyond the 12 bytes base header (CSRC list, extensions...)
|
|
|
|
|
// This reason for the header extensions to be included here is that
|
|
|
|
|
// from an FEC viewpoint, they are part of the payload to be protected.
|
|
|
|
|
// (The base RTP header is already protected by the FEC header.)
|
2016-09-13 03:23:29 -07:00
|
|
|
return producer_fec_.MaxPacketOverhead() + kRedForFecHeaderLength +
|
2016-07-28 15:19:10 -07:00
|
|
|
(rtp_sender_->RtpHeaderLength() - kRtpHeaderSize);
|
2014-09-12 11:05:55 +00:00
|
|
|
}
|
2016-06-03 00:16:45 -07:00
|
|
|
if (fec_enabled_)
|
2016-09-13 03:23:29 -07:00
|
|
|
overhead += producer_fec_.MaxPacketOverhead();
|
2016-06-03 00:16:45 -07:00
|
|
|
return overhead;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-14 21:28:08 +02:00
|
|
|
void RTPSenderVideo::SetFecParameters(const FecProtectionParams* delta_params,
|
|
|
|
|
const FecProtectionParams* key_params) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(delta_params);
|
|
|
|
|
RTC_DCHECK(key_params);
|
2016-06-03 00:16:45 -07:00
|
|
|
if (fec_enabled_) {
|
|
|
|
|
delta_fec_params_ = *delta_params;
|
|
|
|
|
key_fec_params_ = *key_params;
|
|
|
|
|
}
|
2011-07-15 21:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-02 17:46:41 -07:00
|
|
|
bool RTPSenderVideo::SendVideo(RtpVideoCodecTypes video_type,
|
|
|
|
|
FrameType frame_type,
|
|
|
|
|
int8_t payload_type,
|
2016-08-22 03:39:23 -07:00
|
|
|
uint32_t rtp_timestamp,
|
2016-08-02 17:46:41 -07:00
|
|
|
int64_t capture_time_ms,
|
|
|
|
|
const uint8_t* payload_data,
|
|
|
|
|
size_t payload_size,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation,
|
|
|
|
|
const RTPVideoHeader* video_header) {
|
|
|
|
|
if (payload_size == 0)
|
|
|
|
|
return false;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-10-02 10:54:29 -07:00
|
|
|
// Create header that will be reused in all packets.
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> rtp_header = rtp_sender_->AllocatePacket();
|
|
|
|
|
rtp_header->SetPayloadType(payload_type);
|
|
|
|
|
rtp_header->SetTimestamp(rtp_timestamp);
|
|
|
|
|
rtp_header->set_capture_time_ms(capture_time_ms);
|
|
|
|
|
// According to
|
|
|
|
|
// http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
|
|
|
|
|
// ts_126114v120700p.pdf Section 7.4.5:
|
|
|
|
|
// The MTSI client shall add the payload bytes as defined in this clause
|
|
|
|
|
// onto the last RTP packet in each group of packets which make up a key
|
|
|
|
|
// frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265
|
|
|
|
|
// (HEVC)). The MTSI client may also add the payload bytes onto the last RTP
|
|
|
|
|
// packet in each group of packets which make up another type of frame
|
|
|
|
|
// (e.g. a P-Frame) only if the current value is different from the previous
|
|
|
|
|
// value sent.
|
|
|
|
|
// Here we are adding it to every packet of every frame at this point.
|
2016-10-25 03:12:28 -07:00
|
|
|
if (video_header && video_header->rotation != kVideoRotation_0)
|
2016-10-02 10:54:29 -07:00
|
|
|
rtp_header->SetExtension<VideoOrientation>(video_header->rotation);
|
|
|
|
|
|
|
|
|
|
size_t packet_capacity = rtp_sender_->MaxPayloadLength() -
|
|
|
|
|
FecPacketOverhead() -
|
|
|
|
|
(rtp_sender_->RtxStatus() ? kRtxHeaderSize : 0);
|
|
|
|
|
RTC_DCHECK_LE(packet_capacity, rtp_header->capacity());
|
|
|
|
|
RTC_DCHECK_GT(packet_capacity, rtp_header->headers_size());
|
|
|
|
|
size_t max_data_payload_length = packet_capacity - rtp_header->headers_size();
|
|
|
|
|
|
2016-04-27 01:19:58 -07:00
|
|
|
std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create(
|
2016-10-02 10:54:29 -07:00
|
|
|
video_type, max_data_payload_length,
|
2016-07-28 15:19:10 -07:00
|
|
|
video_header ? &(video_header->codecHeader) : nullptr, frame_type));
|
2015-04-14 21:28:08 +02:00
|
|
|
|
2015-10-08 11:44:14 +02:00
|
|
|
StorageType storage;
|
2016-06-03 00:16:45 -07:00
|
|
|
int red_payload_type;
|
2016-04-07 15:36:45 -07:00
|
|
|
bool first_frame = first_frame_sent_();
|
2015-04-14 21:28:08 +02:00
|
|
|
{
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2015-04-14 21:28:08 +02:00
|
|
|
FecProtectionParams* fec_params =
|
2016-07-28 15:19:10 -07:00
|
|
|
frame_type == kVideoFrameKey ? &key_fec_params_ : &delta_fec_params_;
|
2016-10-04 14:27:56 +02:00
|
|
|
producer_fec_.SetFecParameters(fec_params);
|
2016-07-28 15:19:10 -07:00
|
|
|
storage = packetizer->GetStorageType(retransmission_settings_);
|
2016-06-03 00:16:45 -07:00
|
|
|
red_payload_type = red_payload_type_;
|
2014-07-31 14:59:24 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-09-12 11:05:55 +00:00
|
|
|
// TODO(changbin): we currently don't support to configure the codec to
|
|
|
|
|
// output multiple partitions for VP8. Should remove below check after the
|
|
|
|
|
// issue is fixed.
|
|
|
|
|
const RTPFragmentationHeader* frag =
|
2016-07-28 15:19:10 -07:00
|
|
|
(video_type == kRtpVideoVp8) ? NULL : fragmentation;
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2016-10-02 10:54:29 -07:00
|
|
|
packetizer->SetPayloadData(payload_data, payload_size, frag);
|
2014-07-31 14:59:24 +00:00
|
|
|
|
2016-04-07 15:36:45 -07:00
|
|
|
bool first = true;
|
2014-09-12 11:05:55 +00:00
|
|
|
bool last = false;
|
2014-07-31 14:59:24 +00:00
|
|
|
while (!last) {
|
2016-10-02 10:54:29 -07:00
|
|
|
std::unique_ptr<RtpPacketToSend> packet(new RtpPacketToSend(*rtp_header));
|
|
|
|
|
uint8_t* payload = packet->AllocatePayload(max_data_payload_length);
|
|
|
|
|
RTC_DCHECK(payload);
|
2016-06-08 00:24:21 -07:00
|
|
|
|
2016-10-02 10:54:29 -07:00
|
|
|
size_t payload_bytes_in_packet = 0;
|
|
|
|
|
if (!packetizer->NextPacket(payload, &payload_bytes_in_packet, &last))
|
2016-08-02 17:46:41 -07:00
|
|
|
return false;
|
2016-04-07 15:36:45 -07:00
|
|
|
|
2016-10-02 10:54:29 -07:00
|
|
|
packet->SetPayloadSize(payload_bytes_in_packet);
|
|
|
|
|
packet->SetMarker(last);
|
|
|
|
|
if (!rtp_sender_->AssignSequenceNumber(packet.get()))
|
2016-08-02 17:46:41 -07:00
|
|
|
return false;
|
2016-06-08 00:24:21 -07:00
|
|
|
|
2016-06-03 00:16:45 -07:00
|
|
|
if (red_payload_type != 0) {
|
2016-10-02 10:54:29 -07:00
|
|
|
SendVideoPacketAsRed(std::move(packet), storage,
|
2015-04-14 21:28:08 +02:00
|
|
|
packetizer->GetProtectionType() == kProtectedPacket);
|
|
|
|
|
} else {
|
2016-10-02 10:54:29 -07:00
|
|
|
SendVideoPacket(std::move(packet), storage);
|
2014-07-31 14:59:24 +00:00
|
|
|
}
|
2016-04-07 15:36:45 -07:00
|
|
|
|
|
|
|
|
if (first_frame) {
|
|
|
|
|
if (first) {
|
|
|
|
|
LOG(LS_INFO)
|
|
|
|
|
<< "Sent first RTP packet of the first video frame (pre-pacer)";
|
|
|
|
|
}
|
|
|
|
|
if (last) {
|
|
|
|
|
LOG(LS_INFO)
|
|
|
|
|
<< "Sent last RTP packet of the first video frame (pre-pacer)";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
first = false;
|
2014-07-31 14:59:24 +00:00
|
|
|
}
|
2014-09-12 11:05:55 +00:00
|
|
|
|
2016-07-28 15:19:10 -07:00
|
|
|
TRACE_EVENT_ASYNC_END1("webrtc", "Video", capture_time_ms, "timestamp",
|
2016-08-22 03:39:23 -07:00
|
|
|
rtp_timestamp);
|
2016-08-02 17:46:41 -07:00
|
|
|
return true;
|
2015-04-14 21:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
uint32_t RTPSenderVideo::VideoBitrateSent() const {
|
2016-07-13 09:11:28 -07:00
|
|
|
rtc::CritScope cs(&stats_crit_);
|
|
|
|
|
return video_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0);
|
2011-10-27 16:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
uint32_t RTPSenderVideo::FecOverheadRate() const {
|
2016-07-13 09:11:28 -07:00
|
|
|
rtc::CritScope cs(&stats_crit_);
|
|
|
|
|
return fec_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0);
|
2011-10-14 14:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-22 12:52:41 +00:00
|
|
|
int RTPSenderVideo::SelectiveRetransmissions() const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2016-07-28 15:19:10 -07:00
|
|
|
return retransmission_settings_;
|
2011-12-22 12:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-14 21:28:08 +02:00
|
|
|
void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
2016-07-28 15:19:10 -07:00
|
|
|
retransmission_settings_ = settings;
|
2011-12-22 12:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|