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

Side by Side Diff: media/cast/audio_sender/audio_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, 6 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/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 "media/cast/audio_sender/audio_encoder.h" 10 #include "media/cast/audio_sender/audio_encoder.h"
(...skipping 17 matching lines...) Expand all
28 transport_sender_, 28 transport_sender_,
29 NULL, // paced sender. 29 NULL, // paced sender.
30 NULL, 30 NULL,
31 audio_config.rtcp_mode, 31 audio_config.rtcp_mode,
32 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval), 32 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval),
33 audio_config.rtp_config.ssrc, 33 audio_config.rtp_config.ssrc,
34 audio_config.incoming_feedback_ssrc, 34 audio_config.incoming_feedback_ssrc,
35 audio_config.rtcp_c_name, 35 audio_config.rtcp_c_name,
36 true), 36 true),
37 num_aggressive_rtcp_reports_sent_(0), 37 num_aggressive_rtcp_reports_sent_(0),
38 cast_initialization_cb_(STATUS_AUDIO_UNINITIALIZED), 38 cast_initialization_status_(STATUS_AUDIO_UNINITIALIZED),
39 weak_factory_(this) { 39 weak_factory_(this) {
40 rtcp_.SetCastReceiverEventHistorySize(kReceiverRtcpEventHistorySize); 40 rtcp_.SetCastReceiverEventHistorySize(kReceiverRtcpEventHistorySize);
41 if (!encryptor_.Initialize(audio_config.rtp_config.aes_key,
42 audio_config.rtp_config.aes_iv_mask)) {
43 // Leave cast_initialization_status_ set to UNINITIALIZED to indicate
44 // failure.
45 return;
46 }
47 DVLOG(1) << (audio_config.rtp_config.aes_key.empty() ? "Not using" : "Using")
48 << " audio frame data encryption.";
41 if (!audio_config.use_external_encoder) { 49 if (!audio_config.use_external_encoder) {
42 audio_encoder_.reset( 50 audio_encoder_.reset(
43 new AudioEncoder(cast_environment, 51 new AudioEncoder(cast_environment,
44 audio_config, 52 audio_config,
45 base::Bind(&AudioSender::SendEncodedAudioFrame, 53 base::Bind(&AudioSender::SendEncodedAudioFrame,
46 weak_factory_.GetWeakPtr()))); 54 weak_factory_.GetWeakPtr())));
47 cast_initialization_cb_ = audio_encoder_->InitializationResult(); 55 cast_initialization_status_ = audio_encoder_->InitializationResult();
56 } else {
57 NOTREACHED(); // No support for external audio encoding.
58 cast_initialization_status_ = STATUS_AUDIO_INITIALIZED;
48 } 59 }
49 60
50 media::cast::transport::CastTransportAudioConfig transport_config; 61 media::cast::transport::CastTransportAudioConfig transport_config;
51 transport_config.codec = audio_config.codec; 62 transport_config.codec = audio_config.codec;
52 transport_config.rtp.config = audio_config.rtp_config; 63 transport_config.rtp.config = audio_config.rtp_config;
53 transport_config.frequency = audio_config.frequency; 64 transport_config.frequency = audio_config.frequency;
54 transport_config.channels = audio_config.channels; 65 transport_config.channels = audio_config.channels;
55 transport_config.rtp.max_outstanding_frames = 66 transport_config.rtp.max_outstanding_frames =
56 audio_config.rtp_config.max_delay_ms / 100 + 1; 67 audio_config.rtp_config.max_delay_ms / 100 + 1;
57 transport_sender_->InitializeAudio(transport_config); 68 transport_sender_->InitializeAudio(transport_config);
58 69
59 memset(frame_id_to_rtp_timestamp_, 0, sizeof(frame_id_to_rtp_timestamp_)); 70 memset(frame_id_to_rtp_timestamp_, 0, sizeof(frame_id_to_rtp_timestamp_));
60 } 71 }
61 72
62 AudioSender::~AudioSender() {} 73 AudioSender::~AudioSender() {}
63 74
64 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, 75 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus,
65 const base::TimeTicks& recorded_time) { 76 const base::TimeTicks& recorded_time) {
66 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 77 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
78 if (cast_initialization_status_ != STATUS_AUDIO_INITIALIZED) {
79 NOTREACHED();
80 return;
81 }
67 DCHECK(audio_encoder_.get()) << "Invalid internal state"; 82 DCHECK(audio_encoder_.get()) << "Invalid internal state";
68 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); 83 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time);
69 } 84 }
70 85
71 void AudioSender::SendEncodedAudioFrame( 86 void AudioSender::SendEncodedAudioFrame(
72 scoped_ptr<transport::EncodedFrame> audio_frame) { 87 scoped_ptr<transport::EncodedFrame> audio_frame) {
73 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 88 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
89
90 // If using encryption, encrypt the frame data now.
91 if (encryptor_.initialized()) {
92 std::string encrypted_data;
93 if (!encryptor_.Encrypt(audio_frame->frame_id,
94 audio_frame->data,
95 &encrypted_data)) {
96 LOG(ERROR) << "Encryption failed. Not sending frame with ID "
97 << audio_frame->frame_id;
98 return;
99 }
100 audio_frame->data.swap(encrypted_data);
101 }
102
74 DCHECK(!audio_frame->reference_time.is_null()); 103 DCHECK(!audio_frame->reference_time.is_null());
75 rtp_timestamp_helper_.StoreLatestTime(audio_frame->reference_time, 104 rtp_timestamp_helper_.StoreLatestTime(audio_frame->reference_time,
76 audio_frame->rtp_timestamp); 105 audio_frame->rtp_timestamp);
77 106
78 // At the start of the session, it's important to send reports before each 107 // At the start of the session, it's important to send reports before each
79 // frame so that the receiver can properly compute playout times. The reason 108 // frame so that the receiver can properly compute playout times. The reason
80 // more than one report is sent is because transmission is not guaranteed, 109 // more than one report is sent is because transmission is not guaranteed,
81 // only best effort, so we send enough that one should almost certainly get 110 // only best effort, so we send enough that one should almost certainly get
82 // through. 111 // through.
83 if (num_aggressive_rtcp_reports_sent_ < kNumAggressiveReportsSentAtStart) { 112 if (num_aggressive_rtcp_reports_sent_ < kNumAggressiveReportsSentAtStart) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 uint32 acked_frame_id = static_cast<uint32>(cast_feedback.ack_frame_id_); 188 uint32 acked_frame_id = static_cast<uint32>(cast_feedback.ack_frame_id_);
160 VLOG(2) << "Received audio ACK: " << acked_frame_id; 189 VLOG(2) << "Received audio ACK: " << acked_frame_id;
161 cast_environment_->Logging()->InsertFrameEvent( 190 cast_environment_->Logging()->InsertFrameEvent(
162 cast_environment_->Clock()->NowTicks(), 191 cast_environment_->Clock()->NowTicks(),
163 FRAME_ACK_RECEIVED, AUDIO_EVENT, 192 FRAME_ACK_RECEIVED, AUDIO_EVENT,
164 frame_id_to_rtp_timestamp_[acked_frame_id & 0xff], acked_frame_id); 193 frame_id_to_rtp_timestamp_[acked_frame_id & 0xff], acked_frame_id);
165 } 194 }
166 195
167 } // namespace cast 196 } // namespace cast
168 } // namespace media 197 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698