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

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

Issue 2113783002: Refactoring: Merge VideoSenderConfig and AudioSenderConfig. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mek's comment. Created 4 years, 5 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
« no previous file with comments | « media/cast/sender/audio_sender.h ('k') | media/cast/sender/audio_sender_unittest.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/sender/audio_sender.h" 5 #include "media/cast/sender/audio_sender.h"
6 6
7 #include <utility> 7 #include <utility>
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/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "media/cast/common/rtp_time.h" 13 #include "media/cast/common/rtp_time.h"
14 #include "media/cast/net/cast_transport_config.h" 14 #include "media/cast/net/cast_transport_config.h"
15 #include "media/cast/sender/audio_encoder.h" 15 #include "media/cast/sender/audio_encoder.h"
16 16
17 namespace media { 17 namespace media {
18 namespace cast { 18 namespace cast {
19 19
20 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, 20 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment,
21 const AudioSenderConfig& audio_config, 21 const FrameSenderConfig& audio_config,
22 const StatusChangeCallback& status_change_cb, 22 const StatusChangeCallback& status_change_cb,
23 CastTransport* const transport_sender) 23 CastTransport* const transport_sender)
24 : FrameSender(cast_environment, 24 : FrameSender(cast_environment,
25 true, 25 true,
26 transport_sender, 26 transport_sender,
27 audio_config.frequency, 27 audio_config.rtp_timebase,
28 audio_config.ssrc, 28 audio_config.sender_ssrc,
29 0, // |max_frame_rate_| is set after encoder initialization. 29 0, // |max_frame_rate_| is set after encoder initialization.
30 audio_config.min_playout_delay, 30 audio_config.min_playout_delay,
31 audio_config.max_playout_delay, 31 audio_config.max_playout_delay,
32 audio_config.animated_playout_delay, 32 audio_config.animated_playout_delay,
33 NewFixedCongestionControl(audio_config.bitrate)), 33 NewFixedCongestionControl(audio_config.max_bitrate)),
34 samples_in_encoder_(0), 34 samples_in_encoder_(0),
35 weak_factory_(this) { 35 weak_factory_(this) {
36 if (!audio_config.use_external_encoder) { 36 if (!audio_config.use_external_encoder) {
37 audio_encoder_.reset( 37 audio_encoder_.reset(new AudioEncoder(
38 new AudioEncoder(cast_environment, 38 cast_environment, audio_config.channels, audio_config.rtp_timebase,
39 audio_config.channels, 39 audio_config.max_bitrate, audio_config.codec,
40 audio_config.frequency, 40 base::Bind(&AudioSender::OnEncodedAudioFrame,
41 audio_config.bitrate, 41 weak_factory_.GetWeakPtr(), audio_config.max_bitrate)));
42 audio_config.codec,
43 base::Bind(&AudioSender::OnEncodedAudioFrame,
44 weak_factory_.GetWeakPtr(),
45 audio_config.bitrate)));
46 } 42 }
47 43
48 // AudioEncoder provides no operational status changes during normal use. 44 // AudioEncoder provides no operational status changes during normal use.
49 // Post a task now with its initialization result status to allow the client 45 // Post a task now with its initialization result status to allow the client
50 // to start sending frames. 46 // to start sending frames.
51 cast_environment_->PostTask( 47 cast_environment_->PostTask(
52 CastEnvironment::MAIN, 48 CastEnvironment::MAIN,
53 FROM_HERE, 49 FROM_HERE,
54 base::Bind(status_change_cb, 50 base::Bind(status_change_cb,
55 audio_encoder_ ? audio_encoder_->InitializationResult() : 51 audio_encoder_ ? audio_encoder_->InitializationResult() :
56 STATUS_INVALID_CONFIGURATION)); 52 STATUS_INVALID_CONFIGURATION));
57 53
58 // The number of samples per encoded audio frame depends on the codec and its 54 // The number of samples per encoded audio frame depends on the codec and its
59 // initialization parameters. Now that we have an encoder, we can calculate 55 // initialization parameters. Now that we have an encoder, we can calculate
60 // the maximum frame rate. 56 // the maximum frame rate.
61 max_frame_rate_ = 57 max_frame_rate_ =
62 audio_config.frequency / audio_encoder_->GetSamplesPerFrame(); 58 audio_config.rtp_timebase / audio_encoder_->GetSamplesPerFrame();
63 59
64 media::cast::CastTransportRtpConfig transport_config; 60 media::cast::CastTransportRtpConfig transport_config;
65 transport_config.ssrc = audio_config.ssrc; 61 transport_config.ssrc = audio_config.sender_ssrc;
66 transport_config.feedback_ssrc = audio_config.receiver_ssrc; 62 transport_config.feedback_ssrc = audio_config.receiver_ssrc;
67 transport_config.rtp_payload_type = audio_config.rtp_payload_type; 63 transport_config.rtp_payload_type = audio_config.rtp_payload_type;
68 transport_config.aes_key = audio_config.aes_key; 64 transport_config.aes_key = audio_config.aes_key;
69 transport_config.aes_iv_mask = audio_config.aes_iv_mask; 65 transport_config.aes_iv_mask = audio_config.aes_iv_mask;
70 66
71 transport_sender->InitializeAudio( 67 transport_sender->InitializeAudio(
72 transport_config, base::WrapUnique(new FrameSender::RtcpClient( 68 transport_config, base::WrapUnique(new FrameSender::RtcpClient(
73 weak_factory_.GetWeakPtr()))); 69 weak_factory_.GetWeakPtr())));
74 } 70 }
75 71
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 109 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
114 110
115 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; 111 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped;
116 DCHECK_GE(samples_in_encoder_, 0); 112 DCHECK_GE(samples_in_encoder_, 0);
117 113
118 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); 114 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame));
119 } 115 }
120 116
121 } // namespace cast 117 } // namespace cast
122 } // namespace media 118 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/sender/audio_sender.h ('k') | media/cast/sender/audio_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698