Index: media/cast/audio_sender/audio_sender.cc |
diff --git a/media/cast/audio_sender/audio_sender.cc b/media/cast/audio_sender/audio_sender.cc |
index 33623e9daf0570015c2c149ed049e52487c10545..72bb32b9fcb161896e08f432181668992443e08f 100644 |
--- a/media/cast/audio_sender/audio_sender.cc |
+++ b/media/cast/audio_sender/audio_sender.cc |
@@ -35,16 +35,27 @@ AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
audio_config.rtcp_c_name, |
true), |
num_aggressive_rtcp_reports_sent_(0), |
- cast_initialization_cb_(STATUS_AUDIO_UNINITIALIZED), |
+ cast_initialization_status_(STATUS_AUDIO_UNINITIALIZED), |
weak_factory_(this) { |
rtcp_.SetCastReceiverEventHistorySize(kReceiverRtcpEventHistorySize); |
+ if (!encryptor_.Initialize(audio_config.rtp_config.aes_key, |
+ audio_config.rtp_config.aes_iv_mask)) { |
+ // Leave cast_initialization_status_ set to UNINITIALIZED to indicate |
+ // failure. |
+ return; |
+ } |
+ DVLOG(1) << (audio_config.rtp_config.aes_key.empty() ? "Not using" : "Using") |
+ << " audio frame data encryption."; |
if (!audio_config.use_external_encoder) { |
audio_encoder_.reset( |
new AudioEncoder(cast_environment, |
audio_config, |
base::Bind(&AudioSender::SendEncodedAudioFrame, |
weak_factory_.GetWeakPtr()))); |
- cast_initialization_cb_ = audio_encoder_->InitializationResult(); |
+ cast_initialization_status_ = audio_encoder_->InitializationResult(); |
+ } else { |
+ NOTREACHED(); // No support for external audio encoding. |
+ cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; |
} |
media::cast::transport::CastTransportAudioConfig transport_config; |
@@ -64,6 +75,10 @@ AudioSender::~AudioSender() {} |
void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, |
const base::TimeTicks& recorded_time) { |
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
+ if (cast_initialization_status_ != STATUS_AUDIO_INITIALIZED) { |
+ NOTREACHED(); |
+ return; |
+ } |
DCHECK(audio_encoder_.get()) << "Invalid internal state"; |
audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); |
} |
@@ -71,6 +86,20 @@ void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, |
void AudioSender::SendEncodedAudioFrame( |
scoped_ptr<transport::EncodedFrame> audio_frame) { |
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
+ |
+ // If using encryption, encrypt the frame data now. |
+ if (encryptor_.initialized()) { |
+ std::string encrypted_data; |
+ if (!encryptor_.Encrypt(audio_frame->frame_id, |
+ audio_frame->data, |
+ &encrypted_data)) { |
+ LOG(ERROR) << "Encryption failed. Not sending frame with ID " |
+ << audio_frame->frame_id; |
+ return; |
+ } |
+ audio_frame->data.swap(encrypted_data); |
+ } |
+ |
DCHECK(!audio_frame->reference_time.is_null()); |
rtp_timestamp_helper_.StoreLatestTime(audio_frame->reference_time, |
audio_frame->rtp_timestamp); |