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 "media/cast/audio_receiver/audio_decoder.h" | 10 #include "media/cast/audio_receiver/audio_decoder.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 audio_decoder_ = new AudioDecoder(audio_config); | 100 audio_decoder_ = new AudioDecoder(audio_config); |
101 } | 101 } |
102 rtp_receiver_.reset(new RtpReceiver(cast_environment->Clock(), | 102 rtp_receiver_.reset(new RtpReceiver(cast_environment->Clock(), |
103 &audio_config, | 103 &audio_config, |
104 NULL, | 104 NULL, |
105 incoming_payload_callback_.get())); | 105 incoming_payload_callback_.get())); |
106 rtp_audio_receiver_statistics_.reset( | 106 rtp_audio_receiver_statistics_.reset( |
107 new LocalRtpReceiverStatistics(rtp_receiver_.get())); | 107 new LocalRtpReceiverStatistics(rtp_receiver_.get())); |
108 base::TimeDelta rtcp_interval_delta = | 108 base::TimeDelta rtcp_interval_delta = |
109 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval); | 109 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval); |
110 rtcp_.reset(new Rtcp(cast_environment->Clock(), | 110 rtcp_.reset(new Rtcp(cast_environment, |
111 NULL, | 111 NULL, |
112 packet_sender, | 112 packet_sender, |
113 NULL, | 113 NULL, |
114 rtp_audio_receiver_statistics_.get(), | 114 rtp_audio_receiver_statistics_.get(), |
115 audio_config.rtcp_mode, | 115 audio_config.rtcp_mode, |
116 rtcp_interval_delta, | 116 rtcp_interval_delta, |
117 false, | 117 false, |
118 audio_config.feedback_ssrc, | 118 audio_config.feedback_ssrc, |
119 audio_config.rtcp_c_name)); | 119 audio_config.rtcp_c_name)); |
120 rtcp_->SetRemoteSSRC(audio_config.incoming_ssrc); | 120 rtcp_->SetRemoteSSRC(audio_config.incoming_ssrc); |
121 ScheduleNextRtcpReport(); | 121 ScheduleNextRtcpReport(); |
122 ScheduleNextCastMessage(); | 122 ScheduleNextCastMessage(); |
123 } | 123 } |
124 | 124 |
125 AudioReceiver::~AudioReceiver() {} | 125 AudioReceiver::~AudioReceiver() {} |
126 | 126 |
127 void AudioReceiver::IncomingParsedRtpPacket(const uint8* payload_data, | 127 void AudioReceiver::IncomingParsedRtpPacket(const uint8* payload_data, |
128 size_t payload_size, | 128 size_t payload_size, |
129 const RtpCastHeader& rtp_header) { | 129 const RtpCastHeader& rtp_header) { |
| 130 cast_environment_->Logging()->InsertPacketEvent(kPacketReceived, |
| 131 rtp_header.webrtc.header.timestamp, rtp_header.frame_id, |
| 132 rtp_header.packet_id, rtp_header.max_packet_id, payload_size); |
| 133 |
130 // TODO(pwestin): update this as video to refresh over time. | 134 // TODO(pwestin): update this as video to refresh over time. |
131 if (time_first_incoming_packet_.is_null()) { | 135 if (time_first_incoming_packet_.is_null()) { |
132 first_incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; | 136 first_incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; |
133 time_first_incoming_packet_ = cast_environment_->Clock()->NowTicks(); | 137 time_first_incoming_packet_ = cast_environment_->Clock()->NowTicks(); |
134 } | 138 } |
135 | 139 |
136 if (audio_decoder_) { | 140 if (audio_decoder_) { |
137 DCHECK(!audio_buffer_) << "Invalid internal state"; | 141 DCHECK(!audio_buffer_) << "Invalid internal state"; |
138 audio_decoder_->IncomingParsedRtpPacket(payload_data, payload_size, | 142 audio_decoder_->IncomingParsedRtpPacket(payload_data, payload_size, |
139 rtp_header); | 143 rtp_header); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 uint32 rtp_timestamp = 0; | 180 uint32 rtp_timestamp = 0; |
177 if (!audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, | 181 if (!audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, |
178 desired_frequency, | 182 desired_frequency, |
179 audio_frame.get(), | 183 audio_frame.get(), |
180 &rtp_timestamp)) { | 184 &rtp_timestamp)) { |
181 return; | 185 return; |
182 } | 186 } |
183 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 187 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
184 base::TimeTicks playout_time; | 188 base::TimeTicks playout_time; |
185 playout_time = GetPlayoutTime(now, rtp_timestamp); | 189 playout_time = GetPlayoutTime(now, rtp_timestamp); |
| 190 base::TimeDelta diff = playout_time - now; |
| 191 |
| 192 cast_environment_->Logging()->InsertFrameEvent(kAudioPlayoutDelay, |
| 193 rtp_timestamp, diff.InMilliseconds()); |
186 | 194 |
187 // Frame is ready - Send back to the main thread. | 195 // Frame is ready - Send back to the main thread. |
188 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 196 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
189 base::Bind(callback, | 197 base::Bind(callback, |
190 base::Passed(&audio_frame), playout_time)); | 198 base::Passed(&audio_frame), playout_time)); |
191 } | 199 } |
192 | 200 |
193 void AudioReceiver::PlayoutTimeout() { | 201 void AudioReceiver::PlayoutTimeout() { |
194 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; | 202 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; |
195 if (queued_encoded_callbacks_.empty()) { | 203 if (queued_encoded_callbacks_.empty()) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 357 } |
350 | 358 |
351 void AudioReceiver::SendNextCastMessage() { | 359 void AudioReceiver::SendNextCastMessage() { |
352 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; | 360 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; |
353 audio_buffer_->SendCastMessage(); // Will only send a message if it is time. | 361 audio_buffer_->SendCastMessage(); // Will only send a message if it is time. |
354 ScheduleNextCastMessage(); | 362 ScheduleNextCastMessage(); |
355 } | 363 } |
356 | 364 |
357 } // namespace cast | 365 } // namespace cast |
358 } // namespace media | 366 } // namespace media |
OLD | NEW |