| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cast/audio_receiver/audio_receiver.h" | 5 #include "media/cast/audio_receiver/audio_receiver.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "crypto/encryptor.h" | 10 #include "crypto/encryptor.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 ScheduleNextRtcpReport(); | 149 ScheduleNextRtcpReport(); |
| 150 ScheduleNextCastMessage(); | 150 ScheduleNextCastMessage(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void AudioReceiver::IncomingParsedRtpPacket(const uint8* payload_data, | 153 void AudioReceiver::IncomingParsedRtpPacket(const uint8* payload_data, |
| 154 size_t payload_size, | 154 size_t payload_size, |
| 155 const RtpCastHeader& rtp_header) { | 155 const RtpCastHeader& rtp_header) { |
| 156 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 156 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 157 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 157 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 158 | 158 |
| 159 cast_environment_->Logging()->InsertPacketEvent(now, kPacketReceived, | 159 cast_environment_->Logging()->InsertPacketEvent(now, kAudioPacketReceived, |
| 160 rtp_header.webrtc.header.timestamp, rtp_header.frame_id, | 160 rtp_header.webrtc.header.timestamp, rtp_header.frame_id, |
| 161 rtp_header.packet_id, rtp_header.max_packet_id, payload_size); | 161 rtp_header.packet_id, rtp_header.max_packet_id, payload_size); |
| 162 | 162 |
| 163 // TODO(pwestin): update this as video to refresh over time. | 163 // TODO(pwestin): update this as video to refresh over time. |
| 164 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 164 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 165 if (time_first_incoming_packet_.is_null()) { | 165 if (time_first_incoming_packet_.is_null()) { |
| 166 InitializeTimers(); | 166 InitializeTimers(); |
| 167 first_incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; | 167 first_incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; |
| 168 time_first_incoming_packet_ = now; | 168 time_first_incoming_packet_ = now; |
| 169 } | 169 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 bool rtcp_packet = Rtcp::IsRtcpPacket(packet, length); | 383 bool rtcp_packet = Rtcp::IsRtcpPacket(packet, length); |
| 384 if (!rtcp_packet) { | 384 if (!rtcp_packet) { |
| 385 rtp_receiver_->ReceivedPacket(packet, length); | 385 rtp_receiver_->ReceivedPacket(packet, length); |
| 386 } else { | 386 } else { |
| 387 rtcp_->IncomingRtcpPacket(packet, length); | 387 rtcp_->IncomingRtcpPacket(packet, length); |
| 388 } | 388 } |
| 389 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback); | 389 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback); |
| 390 } | 390 } |
| 391 | 391 |
| 392 void AudioReceiver::CastFeedback(const RtcpCastMessage& cast_message) { | 392 void AudioReceiver::CastFeedback(const RtcpCastMessage& cast_message) { |
| 393 // TODO(pwestin): add logging. | 393 RtcpReceiverLogMessage receiver_log; |
| 394 rtcp_->SendRtcpFromRtpReceiver(&cast_message, NULL); | 394 AudioRtcpRawMap audio_logs = |
| 395 cast_environment_->Logging()->GetAudioRtcpRawData(); |
| 396 |
| 397 while (!audio_logs.empty()) { |
| 398 AudioRtcpRawMap::iterator it = audio_logs.begin(); |
| 399 uint32 rtp_timestamp = it->first; |
| 400 std::pair<AudioRtcpRawMap::iterator, AudioRtcpRawMap::iterator> |
| 401 frame_range = audio_logs.equal_range(rtp_timestamp); |
| 402 |
| 403 RtcpReceiverFrameLogMessage frame_log(rtp_timestamp); |
| 404 |
| 405 AudioRtcpRawMap::const_iterator event_it = frame_range.first; |
| 406 for (; event_it != frame_range.second; ++event_it) { |
| 407 RtcpReceiverEventLogMessage event_log_message; |
| 408 event_log_message.type = event_it->second.type; |
| 409 event_log_message.event_timestamp = event_it->second.timestamp; |
| 410 event_log_message.delay_delta = event_it->second.delay_delta; |
| 411 event_log_message.packet_id = event_it->second.packet_id; |
| 412 frame_log.event_log_messages_.push_back(event_log_message); |
| 413 } |
| 414 receiver_log.push_back(frame_log); |
| 415 audio_logs.erase(rtp_timestamp); |
| 416 } |
| 417 |
| 418 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 419 cast_environment_->Logging()->InsertGenericEvent(now, kAudioAckSent, |
| 420 cast_message.ack_frame_id_); |
| 421 |
| 422 rtcp_->SendRtcpFromRtpReceiver(&cast_message, &receiver_log); |
| 395 } | 423 } |
| 396 | 424 |
| 397 base::TimeTicks AudioReceiver::GetPlayoutTime(base::TimeTicks now, | 425 base::TimeTicks AudioReceiver::GetPlayoutTime(base::TimeTicks now, |
| 398 uint32 rtp_timestamp) { | 426 uint32 rtp_timestamp) { |
| 399 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 427 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 400 // Senders time in ms when this frame was recorded. | 428 // Senders time in ms when this frame was recorded. |
| 401 // Note: the senders clock and our local clock might not be synced. | 429 // Note: the senders clock and our local clock might not be synced. |
| 402 base::TimeTicks rtp_timestamp_in_ticks; | 430 base::TimeTicks rtp_timestamp_in_ticks; |
| 403 base::TimeTicks playout_time; | 431 base::TimeTicks playout_time; |
| 404 if (time_offset_ == base::TimeDelta()) { | 432 if (time_offset_ == base::TimeDelta()) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 } | 531 } |
| 504 if (audio_decoder_) { | 532 if (audio_decoder_) { |
| 505 // Will only send a message if it is time. | 533 // Will only send a message if it is time. |
| 506 audio_decoder_->SendCastMessage(); | 534 audio_decoder_->SendCastMessage(); |
| 507 } | 535 } |
| 508 ScheduleNextCastMessage(); | 536 ScheduleNextCastMessage(); |
| 509 } | 537 } |
| 510 | 538 |
| 511 } // namespace cast | 539 } // namespace cast |
| 512 } // namespace media | 540 } // namespace media |
| OLD | NEW |