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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 base::TimeDelta::FromMilliseconds(audio_config.rtp_max_delay_ms); | 90 base::TimeDelta::FromMilliseconds(audio_config.rtp_max_delay_ms); |
91 incoming_payload_callback_.reset(new LocalRtpAudioData(this)); | 91 incoming_payload_callback_.reset(new LocalRtpAudioData(this)); |
92 incoming_payload_feedback_.reset(new LocalRtpAudioFeedback(this)); | 92 incoming_payload_feedback_.reset(new LocalRtpAudioFeedback(this)); |
93 if (audio_config.use_external_decoder) { | 93 if (audio_config.use_external_decoder) { |
94 audio_buffer_.reset(new Framer(cast_environment->Clock(), | 94 audio_buffer_.reset(new Framer(cast_environment->Clock(), |
95 incoming_payload_feedback_.get(), | 95 incoming_payload_feedback_.get(), |
96 audio_config.incoming_ssrc, | 96 audio_config.incoming_ssrc, |
97 true, | 97 true, |
98 0)); | 98 0)); |
99 } else { | 99 } else { |
100 audio_decoder_ = new AudioDecoder(audio_config); | 100 audio_decoder_.reset(new AudioDecoder(audio_config)); |
101 } | 101 } |
102 if (audio_config.aes_iv_mask.size() == kAesKeySize && | 102 if (audio_config.aes_iv_mask.size() == kAesKeySize && |
103 audio_config.aes_key.size() == kAesKeySize) { | 103 audio_config.aes_key.size() == kAesKeySize) { |
104 iv_mask_ = audio_config.aes_iv_mask; | 104 iv_mask_ = audio_config.aes_iv_mask; |
105 crypto::SymmetricKey* key = crypto::SymmetricKey::Import( | 105 crypto::SymmetricKey* key = crypto::SymmetricKey::Import( |
106 crypto::SymmetricKey::AES, audio_config.aes_key); | 106 crypto::SymmetricKey::AES, audio_config.aes_key); |
107 decryptor_.reset(new crypto::Encryptor()); | 107 decryptor_.reset(new crypto::Encryptor()); |
108 decryptor_->Init(key, crypto::Encryptor::CTR, std::string()); | 108 decryptor_->Init(key, crypto::Encryptor::CTR, std::string()); |
109 } else if (audio_config.aes_iv_mask.size() != 0 || | 109 } else if (audio_config.aes_iv_mask.size() != 0 || |
110 audio_config.aes_key.size() != 0) { | 110 audio_config.aes_key.size() != 0) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 188 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
189 base::Bind(&AudioReceiver::GetEncodedAudioFrame, | 189 base::Bind(&AudioReceiver::GetEncodedAudioFrame, |
190 weak_factory_.GetWeakPtr(), callback)); | 190 weak_factory_.GetWeakPtr(), callback)); |
191 } | 191 } |
192 | 192 |
193 void AudioReceiver::GetRawAudioFrame(int number_of_10ms_blocks, | 193 void AudioReceiver::GetRawAudioFrame(int number_of_10ms_blocks, |
194 int desired_frequency, const AudioFrameDecodedCallback& callback) { | 194 int desired_frequency, const AudioFrameDecodedCallback& callback) { |
195 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 195 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
196 DCHECK(audio_decoder_) << "Invalid function call in this configuration"; | 196 DCHECK(audio_decoder_) << "Invalid function call in this configuration"; |
197 | 197 |
| 198 // TODO(pwestin): we can skip this function by posting direct to the decoder. |
198 cast_environment_->PostTask(CastEnvironment::AUDIO_DECODER, FROM_HERE, | 199 cast_environment_->PostTask(CastEnvironment::AUDIO_DECODER, FROM_HERE, |
199 base::Bind(&AudioReceiver::DecodeAudioFrameThread, | 200 base::Bind(&AudioReceiver::DecodeAudioFrameThread, |
200 base::Unretained(this), | 201 base::Unretained(this), |
201 number_of_10ms_blocks, | 202 number_of_10ms_blocks, |
202 desired_frequency, | 203 desired_frequency, |
203 callback)); | 204 callback)); |
204 } | 205 } |
205 | 206 |
206 void AudioReceiver::DecodeAudioFrameThread( | 207 void AudioReceiver::DecodeAudioFrameThread( |
207 int number_of_10ms_blocks, | 208 int number_of_10ms_blocks, |
208 int desired_frequency, | 209 int desired_frequency, |
209 const AudioFrameDecodedCallback callback) { | 210 const AudioFrameDecodedCallback callback) { |
210 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::AUDIO_DECODER)); | 211 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::AUDIO_DECODER)); |
211 // TODO(mikhal): Allow the application to allocate this memory. | 212 // TODO(mikhal): Allow the application to allocate this memory. |
212 scoped_ptr<PcmAudioFrame> audio_frame(new PcmAudioFrame()); | 213 scoped_ptr<PcmAudioFrame> audio_frame(new PcmAudioFrame()); |
213 | 214 |
214 uint32 rtp_timestamp = 0; | 215 uint32 rtp_timestamp = 0; |
215 if (!audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, | 216 if (!audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, |
216 desired_frequency, | 217 desired_frequency, |
217 audio_frame.get(), | 218 audio_frame.get(), |
218 &rtp_timestamp)) { | 219 &rtp_timestamp)) { |
| 220 // TODO(pwestin): This looks wrong, we would loose the pending call to |
| 221 // the application provided callback. |
219 return; | 222 return; |
220 } | 223 } |
221 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 224 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
222 base::TimeTicks playout_time; | 225 base::TimeTicks playout_time; |
223 playout_time = GetPlayoutTime(now, rtp_timestamp); | 226 playout_time = GetPlayoutTime(now, rtp_timestamp); |
224 base::TimeDelta diff = playout_time - now; | 227 base::TimeDelta diff = playout_time - now; |
225 | 228 |
226 cast_environment_->Logging()->InsertFrameEvent(kAudioPlayoutDelay, | 229 cast_environment_->Logging()->InsertFrameEvent(kAudioPlayoutDelay, |
227 rtp_timestamp, diff.InMilliseconds()); | 230 rtp_timestamp, diff.InMilliseconds()); |
228 | 231 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 437 |
435 void AudioReceiver::SendNextCastMessage() { | 438 void AudioReceiver::SendNextCastMessage() { |
436 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 439 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
437 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; | 440 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; |
438 audio_buffer_->SendCastMessage(); // Will only send a message if it is time. | 441 audio_buffer_->SendCastMessage(); // Will only send a message if it is time. |
439 ScheduleNextCastMessage(); | 442 ScheduleNextCastMessage(); |
440 } | 443 } |
441 | 444 |
442 } // namespace cast | 445 } // namespace cast |
443 } // namespace media | 446 } // namespace media |
OLD | NEW |