| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 capture_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, rtp_header_length, | 82 if (!rtp_sender_->SendToNetwork(data_buffer, payload_length, |
| 83 capture_time_ms, storage, | 83 rtp_header_length, capture_time_ms, storage, |
| 84 RtpPacketSender::kLowPriority) == 0) { | 84 RtpPacketSender::kLowPriority)) { |
| 85 rtc::CritScope cs(&stats_crit_); | |
| 86 video_bitrate_.Update(payload_length + rtp_header_length, | |
| 87 clock_->TimeInMilliseconds()); | |
| 88 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | |
| 89 "Video::PacketNormal", "timestamp", capture_timestamp, | |
| 90 "seqnum", seq_num); | |
| 91 } else { | |
| 92 LOG(LS_WARNING) << "Failed to send video packet " << seq_num; | 85 LOG(LS_WARNING) << "Failed to send video packet " << seq_num; |
| 86 return; |
| 93 } | 87 } |
| 88 rtc::CritScope cs(&stats_crit_); |
| 89 video_bitrate_.Update(payload_length + rtp_header_length, |
| 90 clock_->TimeInMilliseconds()); |
| 91 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| 92 "Video::PacketNormal", "timestamp", capture_timestamp, |
| 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 capture_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) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 red_payload_type_, fec_payload_type_, next_fec_sequence_number, | 122 red_payload_type_, fec_payload_type_, next_fec_sequence_number, |
| 123 rtp_header_length); | 123 rtp_header_length); |
| 124 RTC_DCHECK_EQ(num_fec_packets, fec_packets.size()); | 124 RTC_DCHECK_EQ(num_fec_packets, fec_packets.size()); |
| 125 if (retransmission_settings_ & kRetransmitFECPackets) | 125 if (retransmission_settings_ & kRetransmitFECPackets) |
| 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) == 0) { | 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", capture_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 (RedPacket* fec_packet : fec_packets) { | 141 for (RedPacket* 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) == 0) { | 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", capture_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 delete fec_packet; | 155 delete fec_packet; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 const FecProtectionParams* key_params) { | 199 const FecProtectionParams* key_params) { |
| 200 rtc::CritScope cs(&crit_); | 200 rtc::CritScope cs(&crit_); |
| 201 RTC_DCHECK(delta_params); | 201 RTC_DCHECK(delta_params); |
| 202 RTC_DCHECK(key_params); | 202 RTC_DCHECK(key_params); |
| 203 if (fec_enabled_) { | 203 if (fec_enabled_) { |
| 204 delta_fec_params_ = *delta_params; | 204 delta_fec_params_ = *delta_params; |
| 205 key_fec_params_ = *key_params; | 205 key_fec_params_ = *key_params; |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 int32_t RTPSenderVideo::SendVideo(RtpVideoCodecTypes video_type, | 209 bool RTPSenderVideo::SendVideo(RtpVideoCodecTypes video_type, |
| 210 FrameType frame_type, | 210 FrameType frame_type, |
| 211 int8_t payload_type, | 211 int8_t payload_type, |
| 212 uint32_t capture_timestamp, | 212 uint32_t capture_timestamp, |
| 213 int64_t capture_time_ms, | 213 int64_t capture_time_ms, |
| 214 const uint8_t* payload_data, | 214 const uint8_t* payload_data, |
| 215 size_t payload_size, | 215 size_t payload_size, |
| 216 const RTPFragmentationHeader* fragmentation, | 216 const RTPFragmentationHeader* fragmentation, |
| 217 const RTPVideoHeader* video_header) { | 217 const RTPVideoHeader* video_header) { |
| 218 if (payload_size == 0) { | 218 if (payload_size == 0) |
| 219 return -1; | 219 return false; |
| 220 } | |
| 221 | 220 |
| 222 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( | 221 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( |
| 223 video_type, rtp_sender_->MaxDataPayloadLength(), | 222 video_type, rtp_sender_->MaxDataPayloadLength(), |
| 224 video_header ? &(video_header->codecHeader) : nullptr, frame_type)); | 223 video_header ? &(video_header->codecHeader) : nullptr, frame_type)); |
| 225 | 224 |
| 226 StorageType storage; | 225 StorageType storage; |
| 227 int red_payload_type; | 226 int red_payload_type; |
| 228 bool first_frame = first_frame_sent_(); | 227 bool first_frame = first_frame_sent_(); |
| 229 { | 228 { |
| 230 rtc::CritScope cs(&crit_); | 229 rtc::CritScope cs(&crit_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 255 packetizer->SetPayloadData(data, payload_bytes_to_send, frag); | 254 packetizer->SetPayloadData(data, payload_bytes_to_send, frag); |
| 256 | 255 |
| 257 bool first = true; | 256 bool first = true; |
| 258 bool last = false; | 257 bool last = false; |
| 259 while (!last) { | 258 while (!last) { |
| 260 uint8_t dataBuffer[IP_PACKET_SIZE] = {0}; | 259 uint8_t dataBuffer[IP_PACKET_SIZE] = {0}; |
| 261 size_t payload_bytes_in_packet = 0; | 260 size_t payload_bytes_in_packet = 0; |
| 262 | 261 |
| 263 if (!packetizer->NextPacket(&dataBuffer[rtp_header_length], | 262 if (!packetizer->NextPacket(&dataBuffer[rtp_header_length], |
| 264 &payload_bytes_in_packet, &last)) { | 263 &payload_bytes_in_packet, &last)) { |
| 265 return -1; | 264 return false; |
| 266 } | 265 } |
| 267 | 266 |
| 268 // Write RTP header. | 267 // Write RTP header. |
| 269 int32_t header_length = rtp_sender_->BuildRtpHeader( | 268 int32_t header_length = rtp_sender_->BuildRtpHeader( |
| 270 dataBuffer, payload_type, last, capture_timestamp, capture_time_ms); | 269 dataBuffer, payload_type, last, capture_timestamp, capture_time_ms); |
| 271 if (header_length <= 0) | 270 if (header_length <= 0) |
| 272 return -1; | 271 return false; |
| 273 | 272 |
| 274 // According to | 273 // According to |
| 275 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ | 274 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ |
| 276 // ts_126114v120700p.pdf Section 7.4.5: | 275 // ts_126114v120700p.pdf Section 7.4.5: |
| 277 // The MTSI client shall add the payload bytes as defined in this clause | 276 // The MTSI client shall add the payload bytes as defined in this clause |
| 278 // onto the last RTP packet in each group of packets which make up a key | 277 // onto the last RTP packet in each group of packets which make up a key |
| 279 // frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265 | 278 // frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265 |
| 280 // (HEVC)). The MTSI client may also add the payload bytes onto the last RTP | 279 // (HEVC)). The MTSI client may also add the payload bytes onto the last RTP |
| 281 // packet in each group of packets which make up another type of frame | 280 // packet in each group of packets which make up another type of frame |
| 282 // (e.g. a P-Frame) only if the current value is different from the previous | 281 // (e.g. a P-Frame) only if the current value is different from the previous |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 if (last) { | 316 if (last) { |
| 318 LOG(LS_INFO) | 317 LOG(LS_INFO) |
| 319 << "Sent last RTP packet of the first video frame (pre-pacer)"; | 318 << "Sent last RTP packet of the first video frame (pre-pacer)"; |
| 320 } | 319 } |
| 321 } | 320 } |
| 322 first = false; | 321 first = false; |
| 323 } | 322 } |
| 324 | 323 |
| 325 TRACE_EVENT_ASYNC_END1("webrtc", "Video", capture_time_ms, "timestamp", | 324 TRACE_EVENT_ASYNC_END1("webrtc", "Video", capture_time_ms, "timestamp", |
| 326 rtp_sender_->Timestamp()); | 325 rtp_sender_->Timestamp()); |
| 327 return 0; | 326 return true; |
| 328 } | 327 } |
| 329 | 328 |
| 330 uint32_t RTPSenderVideo::VideoBitrateSent() const { | 329 uint32_t RTPSenderVideo::VideoBitrateSent() const { |
| 331 rtc::CritScope cs(&stats_crit_); | 330 rtc::CritScope cs(&stats_crit_); |
| 332 return video_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 331 return video_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
| 333 } | 332 } |
| 334 | 333 |
| 335 uint32_t RTPSenderVideo::FecOverheadRate() const { | 334 uint32_t RTPSenderVideo::FecOverheadRate() const { |
| 336 rtc::CritScope cs(&stats_crit_); | 335 rtc::CritScope cs(&stats_crit_); |
| 337 return fec_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 336 return fec_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
| 338 } | 337 } |
| 339 | 338 |
| 340 int RTPSenderVideo::SelectiveRetransmissions() const { | 339 int RTPSenderVideo::SelectiveRetransmissions() const { |
| 341 rtc::CritScope cs(&crit_); | 340 rtc::CritScope cs(&crit_); |
| 342 return retransmission_settings_; | 341 return retransmission_settings_; |
| 343 } | 342 } |
| 344 | 343 |
| 345 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { | 344 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { |
| 346 rtc::CritScope cs(&crit_); | 345 rtc::CritScope cs(&crit_); |
| 347 retransmission_settings_ = settings; | 346 retransmission_settings_ = settings; |
| 348 } | 347 } |
| 349 | 348 |
| 350 } // namespace webrtc | 349 } // namespace webrtc |
| OLD | NEW |