Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: media/cast/audio_sender/audio_sender.cc

Issue 62843002: Cast: Added support for AES-CTR crypto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync TOT Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cast/audio_sender/audio_sender.h ('k') | media/cast/audio_sender/audio_sender.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_sender/audio_sender.h" 5 #include "media/cast/audio_sender/audio_sender.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"
11 #include "crypto/symmetric_key.h"
10 #include "media/cast/audio_sender/audio_encoder.h" 12 #include "media/cast/audio_sender/audio_encoder.h"
11 #include "media/cast/rtcp/rtcp.h" 13 #include "media/cast/rtcp/rtcp.h"
12 #include "media/cast/rtp_sender/rtp_sender.h" 14 #include "media/cast/rtp_sender/rtp_sender.h"
13 15
14 namespace media { 16 namespace media {
15 namespace cast { 17 namespace cast {
16 18
17 const int64 kMinSchedulingDelayMs = 1; 19 const int64 kMinSchedulingDelayMs = 1;
18 20
19 class LocalRtcpAudioSenderFeedback : public RtcpSenderFeedback { 21 class LocalRtcpAudioSenderFeedback : public RtcpSenderFeedback {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 paced_packet_sender, 66 paced_packet_sender,
65 rtp_audio_sender_statistics_.get(), 67 rtp_audio_sender_statistics_.get(),
66 NULL, 68 NULL,
67 audio_config.rtcp_mode, 69 audio_config.rtcp_mode,
68 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval), 70 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval),
69 audio_config.sender_ssrc, 71 audio_config.sender_ssrc,
70 audio_config.incoming_feedback_ssrc, 72 audio_config.incoming_feedback_ssrc,
71 audio_config.rtcp_c_name), 73 audio_config.rtcp_c_name),
72 initialized_(false), 74 initialized_(false),
73 weak_factory_(this) { 75 weak_factory_(this) {
76 if (audio_config.aes_iv_mask.size() == kAesKeySize &&
77 audio_config.aes_key.size() == kAesKeySize) {
78 iv_mask_ = audio_config.aes_iv_mask;
79 crypto::SymmetricKey* key = crypto::SymmetricKey::Import(
80 crypto::SymmetricKey::AES, audio_config.aes_key);
81 encryptor_.reset(new crypto::Encryptor());
82 encryptor_->Init(key, crypto::Encryptor::CTR, std::string());
83 } else if (audio_config.aes_iv_mask.size() != 0 ||
84 audio_config.aes_key.size() != 0) {
85 DCHECK(false) << "Invalid crypto configuration";
86 }
74 if (!audio_config.use_external_encoder) { 87 if (!audio_config.use_external_encoder) {
75 audio_encoder_ = new AudioEncoder( 88 audio_encoder_ = new AudioEncoder(
76 cast_environment, audio_config, 89 cast_environment, audio_config,
77 base::Bind(&AudioSender::SendEncodedAudioFrame, 90 base::Bind(&AudioSender::SendEncodedAudioFrame,
78 weak_factory_.GetWeakPtr())); 91 weak_factory_.GetWeakPtr()));
79 } 92 }
80 } 93 }
81 94
82 AudioSender::~AudioSender() {} 95 AudioSender::~AudioSender() {}
83 96
(...skipping 11 matching lines...) Expand all
95 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 108 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
96 DCHECK(audio_encoder_.get()) << "Invalid internal state"; 109 DCHECK(audio_encoder_.get()) << "Invalid internal state";
97 audio_encoder_->InsertAudio(audio_bus, recorded_time, done_callback); 110 audio_encoder_->InsertAudio(audio_bus, recorded_time, done_callback);
98 } 111 }
99 112
100 void AudioSender::InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame, 113 void AudioSender::InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame,
101 const base::TimeTicks& recorded_time, 114 const base::TimeTicks& recorded_time,
102 const base::Closure callback) { 115 const base::Closure callback) {
103 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 116 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
104 DCHECK(audio_encoder_.get() == NULL) << "Invalid internal state"; 117 DCHECK(audio_encoder_.get() == NULL) << "Invalid internal state";
105 rtp_sender_.IncomingEncodedAudioFrame(audio_frame, recorded_time); 118
119 if (encryptor_) {
120 EncodedAudioFrame encrypted_frame;
121 if (!EncryptAudioFrame(*audio_frame, &encrypted_frame)) {
122 // Logging already done.
123 return;
124 }
125 rtp_sender_.IncomingEncodedAudioFrame(&encrypted_frame, recorded_time);
126 } else {
127 rtp_sender_.IncomingEncodedAudioFrame(audio_frame, recorded_time);
128 }
106 callback.Run(); 129 callback.Run();
107 } 130 }
108 131
109 void AudioSender::SendEncodedAudioFrame( 132 void AudioSender::SendEncodedAudioFrame(
110 scoped_ptr<EncodedAudioFrame> audio_frame, 133 scoped_ptr<EncodedAudioFrame> audio_frame,
111 const base::TimeTicks& recorded_time) { 134 const base::TimeTicks& recorded_time) {
112 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 135 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
113 InitializeTimers(); 136 InitializeTimers();
114 rtp_sender_.IncomingEncodedAudioFrame(audio_frame.get(), recorded_time); 137 if (encryptor_) {
138 EncodedAudioFrame encrypted_frame;
139 if (!EncryptAudioFrame(*audio_frame.get(), &encrypted_frame)) {
140 // Logging already done.
141 return;
142 }
143 rtp_sender_.IncomingEncodedAudioFrame(&encrypted_frame, recorded_time);
144 } else {
145 rtp_sender_.IncomingEncodedAudioFrame(audio_frame.get(), recorded_time);
146 }
147 }
148
149 bool AudioSender::EncryptAudioFrame(const EncodedAudioFrame& audio_frame,
150 EncodedAudioFrame* encrypted_frame) {
151 DCHECK(encryptor_) << "Invalid state";
152
153 if (!encryptor_->SetCounter(GetAesNonce(audio_frame.frame_id, iv_mask_))) {
154 NOTREACHED() << "Failed to set counter";
155 return false;
156 }
157 if (!encryptor_->Encrypt(audio_frame.data, &encrypted_frame->data)) {
158 NOTREACHED() << "Encrypt error";
159 return false;
160 }
161 encrypted_frame->codec = audio_frame.codec;
162 encrypted_frame->frame_id = audio_frame.frame_id;
163 encrypted_frame->samples = audio_frame.samples;
164 return true;
115 } 165 }
116 166
117 void AudioSender::ResendPackets( 167 void AudioSender::ResendPackets(
118 const MissingFramesAndPacketsMap& missing_frames_and_packets) { 168 const MissingFramesAndPacketsMap& missing_frames_and_packets) {
119 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 169 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
120 rtp_sender_.ResendPackets(missing_frames_and_packets); 170 rtp_sender_.ResendPackets(missing_frames_and_packets);
121 } 171 }
122 172
123 void AudioSender::IncomingRtcpPacket(const uint8* packet, size_t length, 173 void AudioSender::IncomingRtcpPacket(const uint8* packet, size_t length,
124 const base::Closure callback) { 174 const base::Closure callback) {
(...skipping 16 matching lines...) Expand all
141 } 191 }
142 192
143 void AudioSender::SendRtcpReport() { 193 void AudioSender::SendRtcpReport() {
144 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 194 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
145 rtcp_.SendRtcpFromRtpSender(NULL); // TODO(pwestin): add logging. 195 rtcp_.SendRtcpFromRtpSender(NULL); // TODO(pwestin): add logging.
146 ScheduleNextRtcpReport(); 196 ScheduleNextRtcpReport();
147 } 197 }
148 198
149 } // namespace cast 199 } // namespace cast
150 } // namespace media 200 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/audio_sender/audio_sender.h ('k') | media/cast/audio_sender/audio_sender.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698