| 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 uint8_t* data = new uint8_t[packet.sizeBytes]; | 270 uint8_t* data = new uint8_t[packet.sizeBytes]; |
| 271 memcpy(data, packet.dataPtr, packet.sizeBytes); | 271 memcpy(data, packet.dataPtr, packet.sizeBytes); |
| 272 packet.dataPtr = data; | 272 packet.dataPtr = data; |
| 273 } | 273 } |
| 274 | 274 |
| 275 packet_buffer_->InsertPacket(&packet); | 275 packet_buffer_->InsertPacket(&packet); |
| 276 return 0; | 276 return 0; |
| 277 } | 277 } |
| 278 | 278 |
| 279 // TODO(nisse): Try to delete this method. Obstacles: It is used by | 279 // TODO(nisse): Try to delete this method. Obstacles: It is used by |
| 280 // ParseAndHandleEncapsulatingHeader, for handling Rtx packets. And | 280 // ParseAndHandleEncapsulatingHeader, for handling Rtx packets, and |
| 281 // it's part of the RtpData interface which we implement. | 281 // for callbacks from |ulpfec_receiver_|. |
| 282 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, | 282 void RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, |
| 283 size_t rtp_packet_length) { | 283 size_t rtp_packet_length) { |
| 284 RTPHeader header; | 284 RTPHeader header; |
| 285 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { | 285 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { |
| 286 return false; | 286 return; |
| 287 } | 287 } |
| 288 header.payload_type_frequency = kVideoPayloadTypeFrequency; | 288 header.payload_type_frequency = kVideoPayloadTypeFrequency; |
| 289 bool in_order = IsPacketInOrder(header); | 289 bool in_order = IsPacketInOrder(header); |
| 290 return ReceivePacket(rtp_packet, rtp_packet_length, header, in_order); | 290 ReceivePacket(rtp_packet, rtp_packet_length, header, in_order); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // TODO(pbos): Remove as soon as audio can handle a changing payload type | 293 // TODO(pbos): Remove as soon as audio can handle a changing payload type |
| 294 // without this callback. | 294 // without this callback. |
| 295 int32_t RtpStreamReceiver::OnInitializeDecoder( | 295 int32_t RtpStreamReceiver::OnInitializeDecoder( |
| 296 const int8_t payload_type, | 296 const int8_t payload_type, |
| 297 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | 297 const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
| 298 const int frequency, | 298 const int frequency, |
| 299 const size_t channels, | 299 const size_t channels, |
| 300 const uint32_t rate) { | 300 const uint32_t rate) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 421 } |
| 422 | 422 |
| 423 rtc::Optional<int64_t> RtpStreamReceiver::LastReceivedPacketMs() const { | 423 rtc::Optional<int64_t> RtpStreamReceiver::LastReceivedPacketMs() const { |
| 424 return packet_buffer_->LastReceivedPacketMs(); | 424 return packet_buffer_->LastReceivedPacketMs(); |
| 425 } | 425 } |
| 426 | 426 |
| 427 rtc::Optional<int64_t> RtpStreamReceiver::LastReceivedKeyframePacketMs() const { | 427 rtc::Optional<int64_t> RtpStreamReceiver::LastReceivedKeyframePacketMs() const { |
| 428 return packet_buffer_->LastReceivedKeyframePacketMs(); | 428 return packet_buffer_->LastReceivedKeyframePacketMs(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 // TODO(nisse): Drop return value. | 431 void RtpStreamReceiver::ReceivePacket(const uint8_t* packet, |
| 432 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, | |
| 433 size_t packet_length, | 432 size_t packet_length, |
| 434 const RTPHeader& header, | 433 const RTPHeader& header, |
| 435 bool in_order) { | 434 bool in_order) { |
| 436 if (rtp_payload_registry_.IsEncapsulated(header)) { | 435 if (rtp_payload_registry_.IsEncapsulated(header)) { |
| 437 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); | 436 ParseAndHandleEncapsulatingHeader(packet, packet_length, header); |
| 437 return; |
| 438 } | 438 } |
| 439 const uint8_t* payload = packet + header.headerLength; | 439 const uint8_t* payload = packet + header.headerLength; |
| 440 assert(packet_length >= header.headerLength); | 440 assert(packet_length >= header.headerLength); |
| 441 size_t payload_length = packet_length - header.headerLength; | 441 size_t payload_length = packet_length - header.headerLength; |
| 442 PayloadUnion payload_specific; | 442 PayloadUnion payload_specific; |
| 443 if (!rtp_payload_registry_.GetPayloadSpecifics(header.payloadType, | 443 if (!rtp_payload_registry_.GetPayloadSpecifics(header.payloadType, |
| 444 &payload_specific)) { | 444 &payload_specific)) { |
| 445 return false; | 445 return; |
| 446 } | 446 } |
| 447 return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length, | 447 rtp_receiver_->IncomingRtpPacket(header, payload, payload_length, |
| 448 payload_specific, in_order); | 448 payload_specific, in_order); |
| 449 } | 449 } |
| 450 | 450 |
| 451 bool RtpStreamReceiver::ParseAndHandleEncapsulatingHeader( | 451 void RtpStreamReceiver::ParseAndHandleEncapsulatingHeader( |
| 452 const uint8_t* packet, size_t packet_length, const RTPHeader& header) { | 452 const uint8_t* packet, size_t packet_length, const RTPHeader& header) { |
| 453 if (rtp_payload_registry_.IsRed(header)) { | 453 if (rtp_payload_registry_.IsRed(header)) { |
| 454 int8_t ulpfec_pt = rtp_payload_registry_.ulpfec_payload_type(); | 454 int8_t ulpfec_pt = rtp_payload_registry_.ulpfec_payload_type(); |
| 455 if (packet[header.headerLength] == ulpfec_pt) { | 455 if (packet[header.headerLength] == ulpfec_pt) { |
| 456 rtp_receive_statistics_->FecPacketReceived(header, packet_length); | 456 rtp_receive_statistics_->FecPacketReceived(header, packet_length); |
| 457 // Notify video_receiver about received FEC packets to avoid NACKing these | 457 // Notify video_receiver about received FEC packets to avoid NACKing these |
| 458 // packets. | 458 // packets. |
| 459 NotifyReceiverOfFecPacket(header); | 459 NotifyReceiverOfFecPacket(header); |
| 460 } | 460 } |
| 461 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length, | 461 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length, |
| 462 ulpfec_pt) != 0) { | 462 ulpfec_pt) != 0) { |
| 463 return false; | 463 return; |
| 464 } | 464 } |
| 465 return ulpfec_receiver_->ProcessReceivedFec() == 0; | 465 ulpfec_receiver_->ProcessReceivedFec(); |
| 466 } else if (rtp_payload_registry_.IsRtx(header)) { | 466 } else if (rtp_payload_registry_.IsRtx(header)) { |
| 467 if (header.headerLength + header.paddingLength == packet_length) { | 467 if (header.headerLength + header.paddingLength == packet_length) { |
| 468 // This is an empty packet and should be silently dropped before trying to | 468 // This is an empty packet and should be silently dropped before trying to |
| 469 // parse the RTX header. | 469 // parse the RTX header. |
| 470 return true; | 470 return; |
| 471 } | 471 } |
| 472 // Remove the RTX header and parse the original RTP header. | 472 // Remove the RTX header and parse the original RTP header. |
| 473 if (packet_length < header.headerLength) | 473 if (packet_length < header.headerLength) |
| 474 return false; | 474 return; |
| 475 if (packet_length > sizeof(restored_packet_)) | 475 if (packet_length > sizeof(restored_packet_)) |
| 476 return false; | 476 return; |
| 477 rtc::CritScope lock(&receive_cs_); | 477 rtc::CritScope lock(&receive_cs_); |
| 478 if (restored_packet_in_use_) { | 478 if (restored_packet_in_use_) { |
| 479 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet."; | 479 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet."; |
| 480 return false; | 480 return; |
| 481 } | 481 } |
| 482 if (!rtp_payload_registry_.RestoreOriginalPacket( | 482 if (!rtp_payload_registry_.RestoreOriginalPacket( |
| 483 restored_packet_, packet, &packet_length, rtp_receiver_->SSRC(), | 483 restored_packet_, packet, &packet_length, rtp_receiver_->SSRC(), |
| 484 header)) { | 484 header)) { |
| 485 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header ssrc: " | 485 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header ssrc: " |
| 486 << header.ssrc << " payload type: " | 486 << header.ssrc << " payload type: " |
| 487 << static_cast<int>(header.payloadType); | 487 << static_cast<int>(header.payloadType); |
| 488 return false; | 488 return; |
| 489 } | 489 } |
| 490 restored_packet_in_use_ = true; | 490 restored_packet_in_use_ = true; |
| 491 bool ret = OnRecoveredPacket(restored_packet_, packet_length); | 491 OnRecoveredPacket(restored_packet_, packet_length); |
| 492 restored_packet_in_use_ = false; | 492 restored_packet_in_use_ = false; |
| 493 return ret; | |
| 494 } | 493 } |
| 495 return false; | |
| 496 } | 494 } |
| 497 | 495 |
| 498 void RtpStreamReceiver::NotifyReceiverOfFecPacket(const RTPHeader& header) { | 496 void RtpStreamReceiver::NotifyReceiverOfFecPacket(const RTPHeader& header) { |
| 499 int8_t last_media_payload_type = | 497 int8_t last_media_payload_type = |
| 500 rtp_payload_registry_.last_received_media_payload_type(); | 498 rtp_payload_registry_.last_received_media_payload_type(); |
| 501 if (last_media_payload_type < 0) { | 499 if (last_media_payload_type < 0) { |
| 502 LOG(LS_WARNING) << "Failed to get last media payload type."; | 500 LOG(LS_WARNING) << "Failed to get last media payload type."; |
| 503 return; | 501 return; |
| 504 } | 502 } |
| 505 // Fake an empty media packet. | 503 // Fake an empty media packet. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 return; | 674 return; |
| 677 | 675 |
| 678 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) | 676 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) |
| 679 return; | 677 return; |
| 680 | 678 |
| 681 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), | 679 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), |
| 682 sprop_decoder.pps_nalu()); | 680 sprop_decoder.pps_nalu()); |
| 683 } | 681 } |
| 684 | 682 |
| 685 } // namespace webrtc | 683 } // namespace webrtc |
| OLD | NEW |