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

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

Issue 138843011: Cast: Adding helper crypto classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile issues Created 6 years, 10 months 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 | Annotate | Revision Log
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/video_receiver/video_receiver.h" 5 #include "media/cast/video_receiver/video_receiver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "crypto/encryptor.h"
13 #include "crypto/symmetric_key.h"
14 #include "media/cast/cast_defines.h" 12 #include "media/cast/cast_defines.h"
15 #include "media/cast/framer/framer.h" 13 #include "media/cast/framer/framer.h"
16 #include "media/cast/rtcp/rtcp_sender.h" 14 #include "media/cast/rtcp/rtcp_sender.h"
17 #include "media/cast/video_receiver/video_decoder.h" 15 #include "media/cast/video_receiver/video_decoder.h"
18 16
19 namespace media { 17 namespace media {
20 namespace cast { 18 namespace cast {
21 19
22 const int64 kMinSchedulingDelayMs = 1; 20 const int64 kMinSchedulingDelayMs = 1;
23 21
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 target_delay_delta_( 91 target_delay_delta_(
94 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), 92 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)),
95 frame_delay_(base::TimeDelta::FromMilliseconds( 93 frame_delay_(base::TimeDelta::FromMilliseconds(
96 1000 / video_config.max_frame_rate)), 94 1000 / video_config.max_frame_rate)),
97 incoming_payload_callback_(new LocalRtpVideoData(this)), 95 incoming_payload_callback_(new LocalRtpVideoData(this)),
98 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)), 96 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)),
99 rtp_receiver_(cast_environment_->Clock(), NULL, &video_config, 97 rtp_receiver_(cast_environment_->Clock(), NULL, &video_config,
100 incoming_payload_callback_.get()), 98 incoming_payload_callback_.get()),
101 rtp_video_receiver_statistics_( 99 rtp_video_receiver_statistics_(
102 new LocalRtpReceiverStatistics(&rtp_receiver_)), 100 new LocalRtpReceiverStatistics(&rtp_receiver_)),
101 decryptor_(),
103 time_incoming_packet_updated_(false), 102 time_incoming_packet_updated_(false),
104 incoming_rtp_timestamp_(0), 103 incoming_rtp_timestamp_(0),
105 weak_factory_(this) { 104 weak_factory_(this) {
106 int max_unacked_frames = video_config.rtp_max_delay_ms * 105 int max_unacked_frames = video_config.rtp_max_delay_ms *
107 video_config.max_frame_rate / 1000; 106 video_config.max_frame_rate / 1000;
108 DCHECK(max_unacked_frames) << "Invalid argument"; 107 DCHECK(max_unacked_frames) << "Invalid argument";
109 108
110 if (video_config.aes_iv_mask.size() == kAesKeySize && 109 decryptor_.Initialize(video_config.aes_key, video_config.aes_iv_mask);
111 video_config.aes_key.size() == kAesKeySize) {
112 iv_mask_ = video_config.aes_iv_mask;
113 decryption_key_.reset(crypto::SymmetricKey::Import(
114 crypto::SymmetricKey::AES, video_config.aes_key));
115 decryptor_.reset(new crypto::Encryptor());
116 decryptor_->Init(decryption_key_.get(),
117 crypto::Encryptor::CTR,
118 std::string());
119 } else if (video_config.aes_iv_mask.size() != 0 ||
120 video_config.aes_key.size() != 0) {
121 DCHECK(false) << "Invalid crypto configuration";
122 }
123
124 framer_.reset(new Framer(cast_environment->Clock(), 110 framer_.reset(new Framer(cast_environment->Clock(),
125 incoming_payload_feedback_.get(), 111 incoming_payload_feedback_.get(),
126 video_config.incoming_ssrc, 112 video_config.incoming_ssrc,
127 video_config.decoder_faster_than_max_frame_rate, 113 video_config.decoder_faster_than_max_frame_rate,
128 max_unacked_frames)); 114 max_unacked_frames));
129 if (!video_config.use_external_decoder) { 115 if (!video_config.use_external_decoder) {
130 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); 116 video_decoder_.reset(new VideoDecoder(video_config, cast_environment));
131 } 117 }
132 118
133 rtcp_.reset(new Rtcp( 119 rtcp_.reset(new Rtcp(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // This will happen if we decide to decode but not show a frame. 170 // This will happen if we decide to decode but not show a frame.
185 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, 171 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
186 base::Bind(&VideoReceiver::GetRawVideoFrame, base::Unretained(this), 172 base::Bind(&VideoReceiver::GetRawVideoFrame, base::Unretained(this),
187 frame_decoded_callback)); 173 frame_decoded_callback));
188 } 174 }
189 } 175 }
190 176
191 bool VideoReceiver::DecryptVideoFrame( 177 bool VideoReceiver::DecryptVideoFrame(
192 scoped_ptr<transport::EncodedVideoFrame>* video_frame) { 178 scoped_ptr<transport::EncodedVideoFrame>* video_frame) {
193 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 179 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
194 DCHECK(decryptor_) << "Invalid state";
195 180
196 if (!decryptor_->SetCounter(GetAesNonce((*video_frame)->frame_id, 181 if (!decryptor_.initialized())
197 iv_mask_))) {
198 NOTREACHED() << "Failed to set counter";
199 return false; 182 return false;
200 } 183
201 std::string decrypted_video_data; 184 std::string decrypted_video_data;
202 if (!decryptor_->Decrypt((*video_frame)->data, &decrypted_video_data)) { 185 if (!decryptor_.Decrypt((*video_frame)->frame_id,
203 VLOG(1) << "Decryption error"; 186 (*video_frame)->data,
187 &decrypted_video_data)) {
204 // Give up on this frame, release it from jitter buffer. 188 // Give up on this frame, release it from jitter buffer.
205 framer_->ReleaseFrame((*video_frame)->frame_id); 189 framer_->ReleaseFrame((*video_frame)->frame_id);
206 return false; 190 return false;
207 } 191 }
208 (*video_frame)->data.swap(decrypted_video_data); 192 (*video_frame)->data.swap(decrypted_video_data);
209 return true; 193 return true;
210 } 194 }
211 195
212 // Called from the main cast thread. 196 // Called from the main cast thread.
213 void VideoReceiver::GetEncodedVideoFrame( 197 void VideoReceiver::GetEncodedVideoFrame(
214 const VideoFrameEncodedCallback& callback) { 198 const VideoFrameEncodedCallback& callback) {
215 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 199 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
216 scoped_ptr<transport::EncodedVideoFrame> encoded_frame( 200 scoped_ptr<transport::EncodedVideoFrame> encoded_frame(
217 new transport::EncodedVideoFrame()); 201 new transport::EncodedVideoFrame());
218 uint32 rtp_timestamp = 0; 202 uint32 rtp_timestamp = 0;
219 bool next_frame = false; 203 bool next_frame = false;
220 204
221 if (!framer_->GetEncodedVideoFrame(encoded_frame.get(), &rtp_timestamp, 205 if (!framer_->GetEncodedVideoFrame(encoded_frame.get(), &rtp_timestamp,
222 &next_frame)) { 206 &next_frame)) {
223 // We have no video frames. Wait for new packet(s). 207 // We have no video frames. Wait for new packet(s).
224 queued_encoded_callbacks_.push_back(callback); 208 queued_encoded_callbacks_.push_back(callback);
225 return; 209 return;
226 } 210 }
227 211
228 if (decryptor_ && !DecryptVideoFrame(&encoded_frame)) { 212 if (decryptor_.initialized() && !DecryptVideoFrame(&encoded_frame)) {
229 // Logging already done. 213 // Logging already done.
230 queued_encoded_callbacks_.push_back(callback); 214 queued_encoded_callbacks_.push_back(callback);
231 return; 215 return;
232 } 216 }
233 217
234 base::TimeTicks render_time; 218 base::TimeTicks render_time;
235 if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame, 219 if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame,
236 &render_time)) { 220 &render_time)) {
237 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, 221 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
238 base::Bind(callback, base::Passed(&encoded_frame), render_time)); 222 base::Bind(callback, base::Passed(&encoded_frame), render_time));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // We have no video frames. Wait for new packet(s). 297 // We have no video frames. Wait for new packet(s).
314 // Since the application can post multiple VideoFrameEncodedCallback and 298 // Since the application can post multiple VideoFrameEncodedCallback and
315 // we only check the next frame to play out we might have multiple timeout 299 // we only check the next frame to play out we might have multiple timeout
316 // events firing after each other; however this should be a rare event. 300 // events firing after each other; however this should be a rare event.
317 VLOG(1) << "Failed to retrieved a complete frame at this point in time"; 301 VLOG(1) << "Failed to retrieved a complete frame at this point in time";
318 return; 302 return;
319 } 303 }
320 VLOG(1) << "PlayoutTimeout retrieved frame " 304 VLOG(1) << "PlayoutTimeout retrieved frame "
321 << static_cast<int>(encoded_frame->frame_id); 305 << static_cast<int>(encoded_frame->frame_id);
322 306
323 if (decryptor_ && !DecryptVideoFrame(&encoded_frame)) { 307 if (decryptor_.initialized() && !DecryptVideoFrame(&encoded_frame)) {
324 // Logging already done. 308 // Logging already done.
325 return; 309 return;
326 } 310 }
327 311
328 base::TimeTicks render_time; 312 base::TimeTicks render_time;
329 if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame, 313 if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame,
330 &render_time)) { 314 &render_time)) {
331 if (!queued_encoded_callbacks_.empty()) { 315 if (!queued_encoded_callbacks_.empty()) {
332 VideoFrameEncodedCallback callback = queued_encoded_callbacks_.front(); 316 VideoFrameEncodedCallback callback = queued_encoded_callbacks_.front();
333 queued_encoded_callbacks_.pop_front(); 317 queued_encoded_callbacks_.pop_front();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 493 }
510 494
511 void VideoReceiver::SendNextRtcpReport() { 495 void VideoReceiver::SendNextRtcpReport() {
512 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 496 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
513 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); 497 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL);
514 ScheduleNextRtcpReport(); 498 ScheduleNextRtcpReport();
515 } 499 }
516 500
517 } // namespace cast 501 } // namespace cast
518 } // namespace media 502 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/video_receiver/video_receiver.h ('k') | media/cast/video_receiver/video_receiver.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698