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

Unified Diff: media/cast/video_sender/video_sender.cc

Issue 314593002: [Cast] Cleanup: Remove TransportXXXXXSender, an unnecessary layer of indirection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restored/Improved CastSenderImpl VLOGging. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: media/cast/video_sender/video_sender.cc
diff --git a/media/cast/video_sender/video_sender.cc b/media/cast/video_sender/video_sender.cc
index 57b8ea729915b9d21b04736bd96833ef5610ee04..21c68f48c55cb26e2938bb08566db3875d08ddcb 100644
--- a/media/cast/video_sender/video_sender.cc
+++ b/media/cast/video_sender/video_sender.cc
@@ -28,7 +28,6 @@ VideoSender::VideoSender(
const VideoSenderConfig& video_config,
const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb,
- const CastInitializationCallback& cast_initialization_cb,
transport::CastTransportSender* const transport_sender)
: rtp_max_delay_(base::TimeDelta::FromMilliseconds(
video_config.rtp_config.max_delay_ms)),
@@ -48,6 +47,7 @@ VideoSender::VideoSender(
video_config.max_bitrate,
video_config.min_bitrate,
video_config.start_bitrate),
+ cast_initialization_status_(STATUS_VIDEO_UNINITIALIZED),
initialized_(false),
active_session_(false),
weak_factory_(this) {
@@ -56,7 +56,14 @@ VideoSender::VideoSender(
max_frame_rate_ / 1000);
VLOG(1) << "max_unacked_frames " << static_cast<int>(max_unacked_frames_);
DCHECK_GT(max_unacked_frames_, 0) << "Invalid argument";
-
+ if (!encryptor_.Initialize(video_config.rtp_config.aes_key,
+ video_config.rtp_config.aes_iv_mask)) {
+ // Leave cast_initialization_status_ set to UNINITIALIZED to indicate
+ // failure.
+ return;
+ }
+ DVLOG(1) << (video_config.rtp_config.aes_key.empty() ? "Not using" : "Using")
+ << " video frame data encryption.";
if (video_config.use_external_encoder) {
video_encoder_.reset(new ExternalVideoEncoder(cast_environment,
video_config,
@@ -66,7 +73,7 @@ VideoSender::VideoSender(
video_encoder_.reset(new VideoEncoderImpl(
cast_environment, video_config, max_unacked_frames_));
}
-
+ cast_initialization_status_ = STATUS_VIDEO_INITIALIZED;
media::cast::transport::CastTransportVideoConfig transport_config;
transport_config.codec = video_config.codec;
@@ -88,13 +95,6 @@ VideoSender::VideoSender(
false));
rtcp_->SetCastReceiverEventHistorySize(kReceiverRtcpEventHistorySize);
- // TODO(pwestin): pass cast_initialization_cb to |video_encoder_|
- // and remove this call.
- cast_environment_->PostTask(
- CastEnvironment::MAIN,
- FROM_HERE,
- base::Bind(cast_initialization_cb, STATUS_VIDEO_INITIALIZED));
-
memset(frame_id_to_rtp_timestamp_, 0, sizeof(frame_id_to_rtp_timestamp_));
}
@@ -114,6 +114,10 @@ void VideoSender::InsertRawVideoFrame(
const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& capture_time) {
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+ if (cast_initialization_status_ != STATUS_VIDEO_INITIALIZED) {
+ NOTREACHED();
+ return;
+ }
DCHECK(video_encoder_.get()) << "Invalid state";
RtpTimestamp rtp_timestamp = GetVideoRtpTimestamp(capture_time);
@@ -136,7 +140,7 @@ void VideoSender::InsertRawVideoFrame(
if (video_encoder_->EncodeVideoFrame(
video_frame,
capture_time,
- base::Bind(&VideoSender::SendEncodedVideoFrameMainThread,
+ base::Bind(&VideoSender::SendEncodedVideoFrame,
weak_factory_.GetWeakPtr(),
current_requested_bitrate_))) {
frames_in_encoder_++;
@@ -144,7 +148,7 @@ void VideoSender::InsertRawVideoFrame(
}
}
-void VideoSender::SendEncodedVideoFrameMainThread(
+void VideoSender::SendEncodedVideoFrame(
int requested_bitrate_before_encode,
scoped_ptr<transport::EncodedFrame> encoded_frame) {
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
@@ -171,6 +175,20 @@ void VideoSender::SendEncodedVideoFrameMainThread(
frame_id_to_rtp_timestamp_[frame_id & 0xff] = encoded_frame->rtp_timestamp;
last_sent_frame_id_ = static_cast<int>(encoded_frame->frame_id);
+
+ // If using encryption, encrypt the frame data now.
+ if (encryptor_.initialized()) {
+ std::string encrypted_data;
+ if (!encryptor_.Encrypt(encoded_frame->frame_id,
+ encoded_frame->data,
+ &encrypted_data)) {
+ LOG(ERROR) << "Encryption failed. Not sending frame with ID "
+ << encoded_frame->frame_id;
+ return;
+ }
+ encoded_frame->data.swap(encrypted_data);
+ }
+
DCHECK(!encoded_frame->reference_time.is_null());
rtp_timestamp_helper_.StoreLatestTime(encoded_frame->reference_time,
encoded_frame->rtp_timestamp);

Powered by Google App Engine
This is Rietveld 408576698