OLD | NEW |
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/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "media/cast/common/rtp_time.h" | 12 #include "media/cast/common/rtp_time.h" |
13 #include "media/cast/net/cast_transport_config.h" | 13 #include "media/cast/net/cast_transport_config.h" |
14 #include "media/cast/sender/audio_encoder.h" | 14 #include "media/cast/sender/audio_encoder.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 namespace cast { | 17 namespace cast { |
18 | 18 |
19 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 19 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
20 const FrameSenderConfig& audio_config, | 20 const FrameSenderConfig& audio_config, |
21 const StatusChangeCallback& status_change_cb, | 21 const StatusChangeCallback& status_change_cb, |
22 CastTransport* const transport_sender) | 22 CastTransport* const transport_sender) |
23 : FrameSender(cast_environment, | 23 : FrameSender(cast_environment, |
24 transport_sender, | 24 transport_sender, |
25 audio_config, | 25 audio_config, |
26 NewFixedCongestionControl(audio_config.max_bitrate)), | 26 NewFixedCongestionControl(audio_config.max_bitrate)), |
27 samples_in_encoder_(0), | 27 samples_in_encoder_(0) { |
28 weak_factory_(this) { | |
29 if (!audio_config.use_external_encoder) { | 28 if (!audio_config.use_external_encoder) { |
30 audio_encoder_.reset(new AudioEncoder( | 29 audio_encoder_.reset(new AudioEncoder( |
31 cast_environment, audio_config.channels, audio_config.rtp_timebase, | 30 cast_environment, audio_config.channels, audio_config.rtp_timebase, |
32 audio_config.max_bitrate, audio_config.codec, | 31 audio_config.max_bitrate, audio_config.codec, |
33 base::Bind(&AudioSender::OnEncodedAudioFrame, | 32 base::Bind(&AudioSender::OnEncodedAudioFrame, AsWeakPtr(), |
34 weak_factory_.GetWeakPtr(), audio_config.max_bitrate))); | 33 audio_config.max_bitrate))); |
35 } | 34 } |
36 | 35 |
37 // AudioEncoder provides no operational status changes during normal use. | 36 // AudioEncoder provides no operational status changes during normal use. |
38 // Post a task now with its initialization result status to allow the client | 37 // Post a task now with its initialization result status to allow the client |
39 // to start sending frames. | 38 // to start sending frames. |
40 cast_environment_->PostTask( | 39 cast_environment_->PostTask( |
41 CastEnvironment::MAIN, | 40 CastEnvironment::MAIN, |
42 FROM_HERE, | 41 FROM_HERE, |
43 base::Bind(status_change_cb, | 42 base::Bind(status_change_cb, |
44 audio_encoder_ ? audio_encoder_->InitializationResult() : | 43 audio_encoder_ ? audio_encoder_->InitializationResult() : |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 90 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
92 | 91 |
93 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; | 92 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; |
94 DCHECK_GE(samples_in_encoder_, 0); | 93 DCHECK_GE(samples_in_encoder_, 0); |
95 | 94 |
96 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); | 95 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); |
97 } | 96 } |
98 | 97 |
99 } // namespace cast | 98 } // namespace cast |
100 } // namespace media | 99 } // namespace media |
OLD | NEW |