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 |
11 #include "webrtc/video/rtp_stream_receiver.h" | 11 #include "webrtc/video/rtp_stream_receiver.h" |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
19 #include "webrtc/config.h" | 19 #include "webrtc/config.h" |
20 #include "webrtc/media/base/mediaconstants.h" | 20 #include "webrtc/media/base/mediaconstants.h" |
21 #include "webrtc/modules/pacing/packet_router.h" | 21 #include "webrtc/modules/pacing/packet_router.h" |
22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
23 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 23 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
24 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
26 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 26 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
27 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 27 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
28 #include "webrtc/modules/rtp_rtcp/include/ulpfec_receiver.h" | 28 #include "webrtc/modules/rtp_rtcp/include/ulpfec_receiver.h" |
| 29 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 30 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
29 #include "webrtc/modules/video_coding/frame_object.h" | 31 #include "webrtc/modules/video_coding/frame_object.h" |
30 #include "webrtc/modules/video_coding/h264_sprop_parameter_sets.h" | 32 #include "webrtc/modules/video_coding/h264_sprop_parameter_sets.h" |
31 #include "webrtc/modules/video_coding/h264_sps_pps_tracker.h" | 33 #include "webrtc/modules/video_coding/h264_sps_pps_tracker.h" |
32 #include "webrtc/modules/video_coding/packet_buffer.h" | 34 #include "webrtc/modules/video_coding/packet_buffer.h" |
33 #include "webrtc/modules/video_coding/video_coding_impl.h" | 35 #include "webrtc/modules/video_coding/video_coding_impl.h" |
34 #include "webrtc/system_wrappers/include/field_trial.h" | 36 #include "webrtc/system_wrappers/include/field_trial.h" |
35 #include "webrtc/system_wrappers/include/metrics.h" | 37 #include "webrtc/system_wrappers/include/metrics.h" |
36 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" | 38 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" |
37 #include "webrtc/system_wrappers/include/trace.h" | 39 #include "webrtc/system_wrappers/include/trace.h" |
38 #include "webrtc/video/receive_statistics_proxy.h" | 40 #include "webrtc/video/receive_statistics_proxy.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 const size_t channels, | 311 const size_t channels, |
310 const uint32_t rate) { | 312 const uint32_t rate) { |
311 RTC_NOTREACHED(); | 313 RTC_NOTREACHED(); |
312 return 0; | 314 return 0; |
313 } | 315 } |
314 | 316 |
315 void RtpStreamReceiver::OnIncomingSSRCChanged(const uint32_t ssrc) { | 317 void RtpStreamReceiver::OnIncomingSSRCChanged(const uint32_t ssrc) { |
316 rtp_rtcp_->SetRemoteSSRC(ssrc); | 318 rtp_rtcp_->SetRemoteSSRC(ssrc); |
317 } | 319 } |
318 | 320 |
319 bool RtpStreamReceiver::DeliverRtp(const uint8_t* rtp_packet, | 321 void RtpStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) { |
320 size_t rtp_packet_length, | |
321 const PacketTime& packet_time) { | |
322 { | 322 { |
323 rtc::CritScope lock(&receive_cs_); | 323 rtc::CritScope lock(&receive_cs_); |
324 if (!receiving_) { | 324 if (!receiving_) { |
325 return false; | 325 return; |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 RTPHeader header; | |
330 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, | |
331 &header)) { | |
332 return false; | |
333 } | |
334 int64_t arrival_time_ms; | |
335 int64_t now_ms = clock_->TimeInMilliseconds(); | 329 int64_t now_ms = clock_->TimeInMilliseconds(); |
336 if (packet_time.timestamp != -1) | |
337 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | |
338 else | |
339 arrival_time_ms = now_ms; | |
340 | 330 |
341 { | 331 { |
342 // Periodically log the RTP header of incoming packets. | 332 // Periodically log the RTP header of incoming packets. |
343 rtc::CritScope lock(&receive_cs_); | 333 rtc::CritScope lock(&receive_cs_); |
344 if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) { | 334 if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) { |
345 std::stringstream ss; | 335 std::stringstream ss; |
346 ss << "Packet received on SSRC: " << header.ssrc << " with payload type: " | 336 ss << "Packet received on SSRC: " << packet.Ssrc() |
347 << static_cast<int>(header.payloadType) << ", timestamp: " | 337 << " with payload type: " << static_cast<int>(packet.PayloadType()) |
348 << header.timestamp << ", sequence number: " << header.sequenceNumber | 338 << ", timestamp: " << packet.Timestamp() |
349 << ", arrival time: " << arrival_time_ms; | 339 << ", sequence number: " << packet.SequenceNumber() |
350 if (header.extension.hasTransmissionTimeOffset) | 340 << ", arrival time: " << packet.arrival_time_ms(); |
351 ss << ", toffset: " << header.extension.transmissionTimeOffset; | 341 int32_t time_offset; |
352 if (header.extension.hasAbsoluteSendTime) | 342 if (packet.GetExtension<TransmissionOffset>(&time_offset)) { |
353 ss << ", abs send time: " << header.extension.absoluteSendTime; | 343 ss << ", toffset: " << time_offset; |
| 344 } |
| 345 uint32_t send_time; |
| 346 if (packet.GetExtension<AbsoluteSendTime>(&send_time)) { |
| 347 ss << ", abs send time: " << send_time; |
| 348 } |
354 LOG(LS_INFO) << ss.str(); | 349 LOG(LS_INFO) << ss.str(); |
355 last_packet_log_ms_ = now_ms; | 350 last_packet_log_ms_ = now_ms; |
356 } | 351 } |
357 } | 352 } |
358 | 353 |
| 354 // TODO(nisse): Delete use of GetHeader, but needs refactoring of |
| 355 // ReceivePacket and IncomingPacket methods below. |
| 356 RTPHeader header; |
| 357 packet.GetHeader(&header); |
| 358 |
359 header.payload_type_frequency = kVideoPayloadTypeFrequency; | 359 header.payload_type_frequency = kVideoPayloadTypeFrequency; |
360 | 360 |
361 bool in_order = IsPacketInOrder(header); | 361 bool in_order = IsPacketInOrder(header); |
362 rtp_payload_registry_.SetIncomingPayloadType(header); | 362 rtp_payload_registry_.SetIncomingPayloadType(header); |
363 bool ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order); | 363 ReceivePacket(packet.data(), packet.size(), header, in_order); |
364 // Update receive statistics after ReceivePacket. | 364 // Update receive statistics after ReceivePacket. |
365 // Receive statistics will be reset if the payload type changes (make sure | 365 // Receive statistics will be reset if the payload type changes (make sure |
366 // that the first packet is included in the stats). | 366 // that the first packet is included in the stats). |
367 rtp_receive_statistics_->IncomingPacket( | 367 rtp_receive_statistics_->IncomingPacket( |
368 header, rtp_packet_length, IsPacketRetransmitted(header, in_order)); | 368 header, packet.size(), IsPacketRetransmitted(header, in_order)); |
369 return ret; | |
370 } | 369 } |
371 | 370 |
372 int32_t RtpStreamReceiver::RequestKeyFrame() { | 371 int32_t RtpStreamReceiver::RequestKeyFrame() { |
373 return rtp_rtcp_->RequestKeyFrame(); | 372 return rtp_rtcp_->RequestKeyFrame(); |
374 } | 373 } |
375 | 374 |
376 int32_t RtpStreamReceiver::SliceLossIndicationRequest( | 375 int32_t RtpStreamReceiver::SliceLossIndicationRequest( |
377 const uint64_t picture_id) { | 376 const uint64_t picture_id) { |
378 return rtp_rtcp_->SendRTCPSliceLossIndication( | 377 return rtp_rtcp_->SendRTCPSliceLossIndication( |
379 static_cast<uint8_t>(picture_id)); | 378 static_cast<uint8_t>(picture_id)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); | 416 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); |
418 } | 417 } |
419 complete_frame_callback_->OnCompleteFrame(std::move(frame)); | 418 complete_frame_callback_->OnCompleteFrame(std::move(frame)); |
420 } | 419 } |
421 | 420 |
422 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 421 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
423 if (jitter_buffer_experiment_) | 422 if (jitter_buffer_experiment_) |
424 nack_module_->UpdateRtt(max_rtt_ms); | 423 nack_module_->UpdateRtt(max_rtt_ms); |
425 } | 424 } |
426 | 425 |
| 426 // TODO(nisse): Drop return value. |
427 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, | 427 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, |
428 size_t packet_length, | 428 size_t packet_length, |
429 const RTPHeader& header, | 429 const RTPHeader& header, |
430 bool in_order) { | 430 bool in_order) { |
431 if (rtp_payload_registry_.IsEncapsulated(header)) { | 431 if (rtp_payload_registry_.IsEncapsulated(header)) { |
432 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); | 432 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); |
433 } | 433 } |
434 const uint8_t* payload = packet + header.headerLength; | 434 const uint8_t* payload = packet + header.headerLength; |
435 assert(packet_length >= header.headerLength); | 435 assert(packet_length >= header.headerLength); |
436 size_t payload_length = packet_length - header.headerLength; | 436 size_t payload_length = packet_length - header.headerLength; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 return; | 668 return; |
669 | 669 |
670 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) | 670 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) |
671 return; | 671 return; |
672 | 672 |
673 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), | 673 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), |
674 sprop_decoder.pps_nalu()); | 674 sprop_decoder.pps_nalu()); |
675 } | 675 } |
676 | 676 |
677 } // namespace webrtc | 677 } // namespace webrtc |
OLD | NEW |