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

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

Issue 109413004: Cast:Adding cast_transport_config and cleaning up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 11 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 "crypto/encryptor.h" 10 #include "crypto/encryptor.h"
11 #include "crypto/symmetric_key.h" 11 #include "crypto/symmetric_key.h"
12 #include "media/cast/audio_sender/audio_encoder.h" 12 #include "media/cast/audio_sender/audio_encoder.h"
13 #include "media/cast/cast_environment.h"
14 #include "media/cast/rtcp/rtcp.h" 13 #include "media/cast/rtcp/rtcp.h"
15 #include "media/cast/transport/rtp_sender/rtp_sender.h" 14 #include "media/cast/transport/rtp_sender/rtp_sender.h"
16 15
17 namespace media { 16 namespace media {
18 namespace cast { 17 namespace cast {
19 18
20 const int64 kMinSchedulingDelayMs = 1; 19 const int64 kMinSchedulingDelayMs = 1;
21 20
22 class LocalRtcpAudioSenderFeedback : public RtcpSenderFeedback { 21 class LocalRtcpAudioSenderFeedback : public RtcpSenderFeedback {
23 public: 22 public:
(...skipping 27 matching lines...) Expand all
51 50
52 private: 51 private:
53 transport::RtpSender* rtp_sender_; 52 transport::RtpSender* rtp_sender_;
54 }; 53 };
55 54
56 AudioSender::AudioSender( 55 AudioSender::AudioSender(
57 scoped_refptr<CastEnvironment> cast_environment, 56 scoped_refptr<CastEnvironment> cast_environment,
58 const AudioSenderConfig& audio_config, 57 const AudioSenderConfig& audio_config,
59 transport::PacedPacketSender* const paced_packet_sender) 58 transport::PacedPacketSender* const paced_packet_sender)
60 : cast_environment_(cast_environment), 59 : cast_environment_(cast_environment),
61 rtp_sender_(cast_environment, &audio_config, NULL, 60 rtp_sender_(cast_environment->Clock(), &audio_config, NULL,
62 paced_packet_sender), 61 paced_packet_sender),
63 rtcp_feedback_(new LocalRtcpAudioSenderFeedback(this)), 62 rtcp_feedback_(new LocalRtcpAudioSenderFeedback(this)),
64 rtp_audio_sender_statistics_( 63 rtp_audio_sender_statistics_(
65 new LocalRtpSenderStatistics(&rtp_sender_)), 64 new LocalRtpSenderStatistics(&rtp_sender_)),
66 rtcp_(cast_environment, 65 rtcp_(cast_environment,
67 rtcp_feedback_.get(), 66 rtcp_feedback_.get(),
68 paced_packet_sender, 67 paced_packet_sender,
69 rtp_audio_sender_statistics_.get(), 68 rtp_audio_sender_statistics_.get(),
70 NULL, 69 NULL,
71 audio_config.rtcp_mode, 70 audio_config.rtcp_mode,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 111 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
113 DCHECK(audio_encoder_.get()) << "Invalid internal state"; 112 DCHECK(audio_encoder_.get()) << "Invalid internal state";
114 // TODO(mikhal): Resolve calculation of the audio rtp_timestamp for logging. 113 // TODO(mikhal): Resolve calculation of the audio rtp_timestamp for logging.
115 // This is a tmp solution to allow the code to build. 114 // This is a tmp solution to allow the code to build.
116 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); 115 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
117 cast_environment_->Logging()->InsertFrameEvent(now, kAudioFrameReceived, 116 cast_environment_->Logging()->InsertFrameEvent(now, kAudioFrameReceived,
118 GetVideoRtpTimestamp(recorded_time), kFrameIdUnknown); 117 GetVideoRtpTimestamp(recorded_time), kFrameIdUnknown);
119 audio_encoder_->InsertAudio(audio_bus, recorded_time, done_callback); 118 audio_encoder_->InsertAudio(audio_bus, recorded_time, done_callback);
120 } 119 }
121 120
122 void AudioSender::InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame, 121 void AudioSender::InsertCodedAudioFrame(
123 const base::TimeTicks& recorded_time, 122 const transport::EncodedAudioFrame* audio_frame,
124 const base::Closure callback) { 123 const base::TimeTicks& recorded_time,
124 const base::Closure callback) {
125 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 125 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
126 DCHECK(audio_encoder_.get() == NULL) << "Invalid internal state"; 126 DCHECK(audio_encoder_.get() == NULL) << "Invalid internal state";
127 127
128 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); 128 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
129 cast_environment_->Logging()->InsertFrameEvent(now, kAudioFrameReceived, 129 cast_environment_->Logging()->InsertFrameEvent(now, kAudioFrameReceived,
130 GetVideoRtpTimestamp(recorded_time), kFrameIdUnknown); 130 GetVideoRtpTimestamp(recorded_time), kFrameIdUnknown);
131 131
132 if (encryptor_) { 132 if (encryptor_) {
133 EncodedAudioFrame encrypted_frame; 133 transport::EncodedAudioFrame encrypted_frame;
134 if (!EncryptAudioFrame(*audio_frame, &encrypted_frame)) { 134 if (!EncryptAudioFrame(*audio_frame, &encrypted_frame)) {
135 // Logging already done. 135 // Logging already done.
136 return; 136 return;
137 } 137 }
138 rtp_sender_.IncomingEncodedAudioFrame(&encrypted_frame, recorded_time); 138 rtp_sender_.IncomingEncodedAudioFrame(&encrypted_frame, recorded_time);
139 } else { 139 } else {
140 rtp_sender_.IncomingEncodedAudioFrame(audio_frame, recorded_time); 140 rtp_sender_.IncomingEncodedAudioFrame(audio_frame, recorded_time);
141 } 141 }
142 callback.Run(); 142 callback.Run();
143 } 143 }
144 144
145 void AudioSender::SendEncodedAudioFrame( 145 void AudioSender::SendEncodedAudioFrame(
146 scoped_ptr<EncodedAudioFrame> audio_frame, 146 scoped_ptr<transport::EncodedAudioFrame> audio_frame,
147 const base::TimeTicks& recorded_time) { 147 const base::TimeTicks& recorded_time) {
148 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 148 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
149 InitializeTimers(); 149 InitializeTimers();
150 if (encryptor_) { 150 if (encryptor_) {
151 EncodedAudioFrame encrypted_frame; 151 transport::EncodedAudioFrame encrypted_frame;
152 if (!EncryptAudioFrame(*audio_frame.get(), &encrypted_frame)) { 152 if (!EncryptAudioFrame(*audio_frame.get(), &encrypted_frame)) {
153 // Logging already done. 153 // Logging already done.
154 return; 154 return;
155 } 155 }
156 rtp_sender_.IncomingEncodedAudioFrame(&encrypted_frame, recorded_time); 156 rtp_sender_.IncomingEncodedAudioFrame(&encrypted_frame, recorded_time);
157 } else { 157 } else {
158 rtp_sender_.IncomingEncodedAudioFrame(audio_frame.get(), recorded_time); 158 rtp_sender_.IncomingEncodedAudioFrame(audio_frame.get(), recorded_time);
159 } 159 }
160 } 160 }
161 161
162 bool AudioSender::EncryptAudioFrame(const EncodedAudioFrame& audio_frame, 162 bool AudioSender::EncryptAudioFrame(
163 EncodedAudioFrame* encrypted_frame) { 163 const transport::EncodedAudioFrame& audio_frame,
164 transport::EncodedAudioFrame* encrypted_frame) {
164 DCHECK(encryptor_) << "Invalid state"; 165 DCHECK(encryptor_) << "Invalid state";
165 166
166 if (!encryptor_->SetCounter(GetAesNonce(audio_frame.frame_id, iv_mask_))) { 167 if (!encryptor_->SetCounter(GetAesNonce(audio_frame.frame_id, iv_mask_))) {
167 NOTREACHED() << "Failed to set counter"; 168 NOTREACHED() << "Failed to set counter";
168 return false; 169 return false;
169 } 170 }
170 if (!encryptor_->Encrypt(audio_frame.data, &encrypted_frame->data)) { 171 if (!encryptor_->Encrypt(audio_frame.data, &encrypted_frame->data)) {
171 NOTREACHED() << "Encrypt error"; 172 NOTREACHED() << "Encrypt error";
172 return false; 173 return false;
173 } 174 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 void AudioSender::SendRtcpReport() { 207 void AudioSender::SendRtcpReport() {
207 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 208 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
208 // We don't send audio logging messages since all captured audio frames will 209 // We don't send audio logging messages since all captured audio frames will
209 // be sent. 210 // be sent.
210 rtcp_.SendRtcpFromRtpSender(NULL); 211 rtcp_.SendRtcpFromRtpSender(NULL);
211 ScheduleNextRtcpReport(); 212 ScheduleNextRtcpReport();
212 } 213 }
213 214
214 } // namespace cast 215 } // namespace cast
215 } // namespace media 216 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/audio_sender/audio_sender.h ('k') | media/cast/audio_sender/audio_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698