| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 strncpy(payload->name, payload_name, RTP_PAYLOAD_NAME_SIZE - 1); | 69 strncpy(payload->name, payload_name, RTP_PAYLOAD_NAME_SIZE - 1); |
| 70 payload->typeSpecific.Video.videoCodecType = video_type; | 70 payload->typeSpecific.Video.videoCodecType = video_type; |
| 71 payload->audio = false; | 71 payload->audio = false; |
| 72 return payload; | 72 return payload; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void RTPSenderVideo::SendVideoPacket(uint8_t* data_buffer, | 75 void RTPSenderVideo::SendVideoPacket(uint8_t* data_buffer, |
| 76 size_t payload_length, | 76 size_t payload_length, |
| 77 size_t rtp_header_length, | 77 size_t rtp_header_length, |
| 78 uint16_t seq_num, | 78 uint16_t seq_num, |
| 79 uint32_t capture_timestamp, | 79 uint32_t rtp_timestamp, |
| 80 int64_t capture_time_ms, | 80 int64_t capture_time_ms, |
| 81 StorageType storage) { | 81 StorageType storage) { |
| 82 if (!rtp_sender_->SendToNetwork(data_buffer, payload_length, | 82 if (!rtp_sender_->SendToNetwork(data_buffer, payload_length, |
| 83 rtp_header_length, capture_time_ms, storage, | 83 rtp_header_length, capture_time_ms, storage, |
| 84 RtpPacketSender::kLowPriority)) { | 84 RtpPacketSender::kLowPriority)) { |
| 85 LOG(LS_WARNING) << "Failed to send video packet " << seq_num; | 85 LOG(LS_WARNING) << "Failed to send video packet " << seq_num; |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 rtc::CritScope cs(&stats_crit_); | 88 rtc::CritScope cs(&stats_crit_); |
| 89 video_bitrate_.Update(payload_length + rtp_header_length, | 89 video_bitrate_.Update(payload_length + rtp_header_length, |
| 90 clock_->TimeInMilliseconds()); | 90 clock_->TimeInMilliseconds()); |
| 91 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 91 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| 92 "Video::PacketNormal", "timestamp", capture_timestamp, | 92 "Video::PacketNormal", "timestamp", rtp_timestamp, |
| 93 "seqnum", seq_num); | 93 "seqnum", seq_num); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void RTPSenderVideo::SendVideoPacketAsRed(uint8_t* data_buffer, | 96 void RTPSenderVideo::SendVideoPacketAsRed(uint8_t* data_buffer, |
| 97 size_t payload_length, | 97 size_t payload_length, |
| 98 size_t rtp_header_length, | 98 size_t rtp_header_length, |
| 99 uint16_t media_seq_num, | 99 uint16_t media_seq_num, |
| 100 uint32_t capture_timestamp, | 100 uint32_t rtp_timestamp, |
| 101 int64_t capture_time_ms, | 101 int64_t capture_time_ms, |
| 102 StorageType media_packet_storage, | 102 StorageType media_packet_storage, |
| 103 bool protect) { | 103 bool protect) { |
| 104 std::unique_ptr<RedPacket> red_packet; | 104 std::unique_ptr<RedPacket> red_packet; |
| 105 std::vector<std::unique_ptr<RedPacket>> fec_packets; | 105 std::vector<std::unique_ptr<RedPacket>> fec_packets; |
| 106 StorageType fec_storage = kDontRetransmit; | 106 StorageType fec_storage = kDontRetransmit; |
| 107 uint16_t next_fec_sequence_number = 0; | 107 uint16_t next_fec_sequence_number = 0; |
| 108 { | 108 { |
| 109 // Only protect while creating RED and FEC packets, not when sending. | 109 // Only protect while creating RED and FEC packets, not when sending. |
| 110 rtc::CritScope cs(&crit_); | 110 rtc::CritScope cs(&crit_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 126 fec_storage = kAllowRetransmission; | 126 fec_storage = kAllowRetransmission; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 if (rtp_sender_->SendToNetwork( | 129 if (rtp_sender_->SendToNetwork( |
| 130 red_packet->data(), red_packet->length() - rtp_header_length, | 130 red_packet->data(), red_packet->length() - rtp_header_length, |
| 131 rtp_header_length, capture_time_ms, media_packet_storage, | 131 rtp_header_length, capture_time_ms, media_packet_storage, |
| 132 RtpPacketSender::kLowPriority)) { | 132 RtpPacketSender::kLowPriority)) { |
| 133 rtc::CritScope cs(&stats_crit_); | 133 rtc::CritScope cs(&stats_crit_); |
| 134 video_bitrate_.Update(red_packet->length(), clock_->TimeInMilliseconds()); | 134 video_bitrate_.Update(red_packet->length(), clock_->TimeInMilliseconds()); |
| 135 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 135 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| 136 "Video::PacketRed", "timestamp", capture_timestamp, | 136 "Video::PacketRed", "timestamp", rtp_timestamp, |
| 137 "seqnum", media_seq_num); | 137 "seqnum", media_seq_num); |
| 138 } else { | 138 } else { |
| 139 LOG(LS_WARNING) << "Failed to send RED packet " << media_seq_num; | 139 LOG(LS_WARNING) << "Failed to send RED packet " << media_seq_num; |
| 140 } | 140 } |
| 141 for (const auto& fec_packet : fec_packets) { | 141 for (const auto& fec_packet : fec_packets) { |
| 142 if (rtp_sender_->SendToNetwork( | 142 if (rtp_sender_->SendToNetwork( |
| 143 fec_packet->data(), fec_packet->length() - rtp_header_length, | 143 fec_packet->data(), fec_packet->length() - rtp_header_length, |
| 144 rtp_header_length, capture_time_ms, fec_storage, | 144 rtp_header_length, capture_time_ms, fec_storage, |
| 145 RtpPacketSender::kLowPriority)) { | 145 RtpPacketSender::kLowPriority)) { |
| 146 rtc::CritScope cs(&stats_crit_); | 146 rtc::CritScope cs(&stats_crit_); |
| 147 fec_bitrate_.Update(fec_packet->length(), clock_->TimeInMilliseconds()); | 147 fec_bitrate_.Update(fec_packet->length(), clock_->TimeInMilliseconds()); |
| 148 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 148 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| 149 "Video::PacketFec", "timestamp", capture_timestamp, | 149 "Video::PacketFec", "timestamp", rtp_timestamp, |
| 150 "seqnum", next_fec_sequence_number); | 150 "seqnum", next_fec_sequence_number); |
| 151 } else { | 151 } else { |
| 152 LOG(LS_WARNING) << "Failed to send FEC packet " | 152 LOG(LS_WARNING) << "Failed to send FEC packet " |
| 153 << next_fec_sequence_number; | 153 << next_fec_sequence_number; |
| 154 } | 154 } |
| 155 ++next_fec_sequence_number; | 155 ++next_fec_sequence_number; |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 void RTPSenderVideo::SetGenericFECStatus(bool enable, | 159 void RTPSenderVideo::SetGenericFECStatus(bool enable, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 RTC_DCHECK(key_params); | 201 RTC_DCHECK(key_params); |
| 202 if (fec_enabled_) { | 202 if (fec_enabled_) { |
| 203 delta_fec_params_ = *delta_params; | 203 delta_fec_params_ = *delta_params; |
| 204 key_fec_params_ = *key_params; | 204 key_fec_params_ = *key_params; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 bool RTPSenderVideo::SendVideo(RtpVideoCodecTypes video_type, | 208 bool RTPSenderVideo::SendVideo(RtpVideoCodecTypes video_type, |
| 209 FrameType frame_type, | 209 FrameType frame_type, |
| 210 int8_t payload_type, | 210 int8_t payload_type, |
| 211 uint32_t capture_timestamp, | 211 uint32_t rtp_timestamp, |
| 212 int64_t capture_time_ms, | 212 int64_t capture_time_ms, |
| 213 const uint8_t* payload_data, | 213 const uint8_t* payload_data, |
| 214 size_t payload_size, | 214 size_t payload_size, |
| 215 const RTPFragmentationHeader* fragmentation, | 215 const RTPFragmentationHeader* fragmentation, |
| 216 const RTPVideoHeader* video_header) { | 216 const RTPVideoHeader* video_header) { |
| 217 if (payload_size == 0) | 217 if (payload_size == 0) |
| 218 return false; | 218 return false; |
| 219 | 219 |
| 220 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( | 220 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( |
| 221 video_type, rtp_sender_->MaxDataPayloadLength(), | 221 video_type, rtp_sender_->MaxDataPayloadLength(), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 uint8_t dataBuffer[IP_PACKET_SIZE] = {0}; | 262 uint8_t dataBuffer[IP_PACKET_SIZE] = {0}; |
| 263 size_t payload_bytes_in_packet = 0; | 263 size_t payload_bytes_in_packet = 0; |
| 264 | 264 |
| 265 if (!packetizer->NextPacket(&dataBuffer[rtp_header_length], | 265 if (!packetizer->NextPacket(&dataBuffer[rtp_header_length], |
| 266 &payload_bytes_in_packet, &last)) { | 266 &payload_bytes_in_packet, &last)) { |
| 267 return false; | 267 return false; |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Write RTP header. | 270 // Write RTP header. |
| 271 int32_t header_length = rtp_sender_->BuildRtpHeader( | 271 int32_t header_length = rtp_sender_->BuildRtpHeader( |
| 272 dataBuffer, payload_type, last, capture_timestamp, capture_time_ms); | 272 dataBuffer, payload_type, last, rtp_timestamp, capture_time_ms); |
| 273 if (header_length <= 0) | 273 if (header_length <= 0) |
| 274 return false; | 274 return false; |
| 275 | 275 |
| 276 // According to | 276 // According to |
| 277 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ | 277 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ |
| 278 // ts_126114v120700p.pdf Section 7.4.5: | 278 // ts_126114v120700p.pdf Section 7.4.5: |
| 279 // The MTSI client shall add the payload bytes as defined in this clause | 279 // The MTSI client shall add the payload bytes as defined in this clause |
| 280 // onto the last RTP packet in each group of packets which make up a key | 280 // onto the last RTP packet in each group of packets which make up a key |
| 281 // frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265 | 281 // frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265 |
| 282 // (HEVC)). The MTSI client may also add the payload bytes onto the last RTP | 282 // (HEVC)). The MTSI client may also add the payload bytes onto the last RTP |
| (...skipping 13 matching lines...) Expand all Loading... |
| 296 size_t packetSize = payload_size + rtp_header_length; | 296 size_t packetSize = payload_size + rtp_header_length; |
| 297 RtpUtility::RtpHeaderParser rtp_parser(dataBuffer, packetSize); | 297 RtpUtility::RtpHeaderParser rtp_parser(dataBuffer, packetSize); |
| 298 RTPHeader rtp_header; | 298 RTPHeader rtp_header; |
| 299 rtp_parser.Parse(&rtp_header); | 299 rtp_parser.Parse(&rtp_header); |
| 300 rtp_sender_->UpdateVideoRotation(dataBuffer, packetSize, rtp_header, | 300 rtp_sender_->UpdateVideoRotation(dataBuffer, packetSize, rtp_header, |
| 301 video_header->rotation); | 301 video_header->rotation); |
| 302 } | 302 } |
| 303 if (red_payload_type != 0) { | 303 if (red_payload_type != 0) { |
| 304 SendVideoPacketAsRed(dataBuffer, payload_bytes_in_packet, | 304 SendVideoPacketAsRed(dataBuffer, payload_bytes_in_packet, |
| 305 rtp_header_length, rtp_sender_->SequenceNumber(), | 305 rtp_header_length, rtp_sender_->SequenceNumber(), |
| 306 capture_timestamp, capture_time_ms, storage, | 306 rtp_timestamp, capture_time_ms, storage, |
| 307 packetizer->GetProtectionType() == kProtectedPacket); | 307 packetizer->GetProtectionType() == kProtectedPacket); |
| 308 } else { | 308 } else { |
| 309 SendVideoPacket(dataBuffer, payload_bytes_in_packet, rtp_header_length, | 309 SendVideoPacket(dataBuffer, payload_bytes_in_packet, rtp_header_length, |
| 310 rtp_sender_->SequenceNumber(), capture_timestamp, | 310 rtp_sender_->SequenceNumber(), rtp_timestamp, |
| 311 capture_time_ms, storage); | 311 capture_time_ms, storage); |
| 312 } | 312 } |
| 313 | 313 |
| 314 if (first_frame) { | 314 if (first_frame) { |
| 315 if (first) { | 315 if (first) { |
| 316 LOG(LS_INFO) | 316 LOG(LS_INFO) |
| 317 << "Sent first RTP packet of the first video frame (pre-pacer)"; | 317 << "Sent first RTP packet of the first video frame (pre-pacer)"; |
| 318 } | 318 } |
| 319 if (last) { | 319 if (last) { |
| 320 LOG(LS_INFO) | 320 LOG(LS_INFO) |
| 321 << "Sent last RTP packet of the first video frame (pre-pacer)"; | 321 << "Sent last RTP packet of the first video frame (pre-pacer)"; |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 first = false; | 324 first = false; |
| 325 } | 325 } |
| 326 | 326 |
| 327 TRACE_EVENT_ASYNC_END1("webrtc", "Video", capture_time_ms, "timestamp", | 327 TRACE_EVENT_ASYNC_END1("webrtc", "Video", capture_time_ms, "timestamp", |
| 328 rtp_sender_->Timestamp()); | 328 rtp_timestamp); |
| 329 return true; | 329 return true; |
| 330 } | 330 } |
| 331 | 331 |
| 332 uint32_t RTPSenderVideo::VideoBitrateSent() const { | 332 uint32_t RTPSenderVideo::VideoBitrateSent() const { |
| 333 rtc::CritScope cs(&stats_crit_); | 333 rtc::CritScope cs(&stats_crit_); |
| 334 return video_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 334 return video_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
| 335 } | 335 } |
| 336 | 336 |
| 337 uint32_t RTPSenderVideo::FecOverheadRate() const { | 337 uint32_t RTPSenderVideo::FecOverheadRate() const { |
| 338 rtc::CritScope cs(&stats_crit_); | 338 rtc::CritScope cs(&stats_crit_); |
| 339 return fec_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 339 return fec_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
| 340 } | 340 } |
| 341 | 341 |
| 342 int RTPSenderVideo::SelectiveRetransmissions() const { | 342 int RTPSenderVideo::SelectiveRetransmissions() const { |
| 343 rtc::CritScope cs(&crit_); | 343 rtc::CritScope cs(&crit_); |
| 344 return retransmission_settings_; | 344 return retransmission_settings_; |
| 345 } | 345 } |
| 346 | 346 |
| 347 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { | 347 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { |
| 348 rtc::CritScope cs(&crit_); | 348 rtc::CritScope cs(&crit_); |
| 349 retransmission_settings_ = settings; | 349 retransmission_settings_ = settings; |
| 350 } | 350 } |
| 351 | 351 |
| 352 } // namespace webrtc | 352 } // namespace webrtc |
| OLD | NEW |