OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/audio/audio_send_stream.h" | 11 #include "webrtc/audio/audio_send_stream.h" |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "webrtc/audio/audio_state.h" | 15 #include "webrtc/audio/audio_state.h" |
16 #include "webrtc/audio/conversion.h" | 16 #include "webrtc/audio/conversion.h" |
17 #include "webrtc/audio/scoped_voe_interface.h" | 17 #include "webrtc/audio/scoped_voe_interface.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/event.h" |
19 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/task_queue.h" |
20 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
21 #include "webrtc/modules/pacing/paced_sender.h" | 23 #include "webrtc/modules/pacing/paced_sender.h" |
22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
23 #include "webrtc/voice_engine/channel_proxy.h" | 25 #include "webrtc/voice_engine/channel_proxy.h" |
24 #include "webrtc/voice_engine/include/voe_audio_processing.h" | 26 #include "webrtc/voice_engine/include/voe_audio_processing.h" |
25 #include "webrtc/voice_engine/include/voe_codec.h" | 27 #include "webrtc/voice_engine/include/voe_codec.h" |
26 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
27 #include "webrtc/voice_engine/include/voe_volume_control.h" | 29 #include "webrtc/voice_engine/include/voe_volume_control.h" |
28 #include "webrtc/voice_engine/voice_engine_impl.h" | 30 #include "webrtc/voice_engine/voice_engine_impl.h" |
29 | 31 |
(...skipping 22 matching lines...) Expand all Loading... |
52 // TODO(solenberg): Encoder config. | 54 // TODO(solenberg): Encoder config. |
53 ss << ", cng_payload_type: " << cng_payload_type; | 55 ss << ", cng_payload_type: " << cng_payload_type; |
54 ss << '}'; | 56 ss << '}'; |
55 return ss.str(); | 57 return ss.str(); |
56 } | 58 } |
57 | 59 |
58 namespace internal { | 60 namespace internal { |
59 AudioSendStream::AudioSendStream( | 61 AudioSendStream::AudioSendStream( |
60 const webrtc::AudioSendStream::Config& config, | 62 const webrtc::AudioSendStream::Config& config, |
61 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 63 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 64 rtc::TaskQueue* worker_queue, |
62 CongestionController* congestion_controller, | 65 CongestionController* congestion_controller, |
63 BitrateAllocator* bitrate_allocator) | 66 BitrateAllocator* bitrate_allocator) |
64 : config_(config), | 67 : worker_queue_(worker_queue), |
| 68 config_(config), |
65 audio_state_(audio_state), | 69 audio_state_(audio_state), |
66 bitrate_allocator_(bitrate_allocator) { | 70 bitrate_allocator_(bitrate_allocator) { |
67 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 71 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); |
68 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 72 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
69 RTC_DCHECK(audio_state_.get()); | 73 RTC_DCHECK(audio_state_.get()); |
70 RTC_DCHECK(congestion_controller); | 74 RTC_DCHECK(congestion_controller); |
71 | 75 |
72 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 76 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
73 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 77 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
74 channel_proxy_->RegisterSenderCongestionControlObjects( | 78 channel_proxy_->RegisterSenderCongestionControlObjects( |
(...skipping 27 matching lines...) Expand all Loading... |
102 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 106 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
103 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 107 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
104 channel_proxy_->DeRegisterExternalTransport(); | 108 channel_proxy_->DeRegisterExternalTransport(); |
105 channel_proxy_->ResetCongestionControlObjects(); | 109 channel_proxy_->ResetCongestionControlObjects(); |
106 } | 110 } |
107 | 111 |
108 void AudioSendStream::Start() { | 112 void AudioSendStream::Start() { |
109 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 113 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
110 if (config_.min_bitrate_kbps != -1 && config_.max_bitrate_kbps != -1) { | 114 if (config_.min_bitrate_kbps != -1 && config_.max_bitrate_kbps != -1) { |
111 RTC_DCHECK_GE(config_.max_bitrate_kbps, config_.min_bitrate_kbps); | 115 RTC_DCHECK_GE(config_.max_bitrate_kbps, config_.min_bitrate_kbps); |
112 bitrate_allocator_->AddObserver(this, config_.min_bitrate_kbps * 1000, | 116 rtc::Event thread_sync_event(false /* manual_reset */, false); |
113 config_.max_bitrate_kbps * 1000, 0, true); | 117 worker_queue_->PostTask([this, &thread_sync_event] { |
| 118 bitrate_allocator_->AddObserver(this, config_.min_bitrate_kbps * 1000, |
| 119 config_.max_bitrate_kbps * 1000, 0, true); |
| 120 thread_sync_event.Set(); |
| 121 }); |
| 122 thread_sync_event.Wait(rtc::Event::kForever); |
114 } | 123 } |
115 | 124 |
116 ScopedVoEInterface<VoEBase> base(voice_engine()); | 125 ScopedVoEInterface<VoEBase> base(voice_engine()); |
117 int error = base->StartSend(config_.voe_channel_id); | 126 int error = base->StartSend(config_.voe_channel_id); |
118 if (error != 0) { | 127 if (error != 0) { |
119 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; | 128 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; |
120 } | 129 } |
121 } | 130 } |
122 | 131 |
123 void AudioSendStream::Stop() { | 132 void AudioSendStream::Stop() { |
124 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 133 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
125 bitrate_allocator_->RemoveObserver(this); | 134 rtc::Event thread_sync_event(false /* manual_reset */, false); |
| 135 worker_queue_->PostTask([this, &thread_sync_event] { |
| 136 bitrate_allocator_->RemoveObserver(this); |
| 137 thread_sync_event.Set(); |
| 138 }); |
| 139 thread_sync_event.Wait(rtc::Event::kForever); |
| 140 |
126 ScopedVoEInterface<VoEBase> base(voice_engine()); | 141 ScopedVoEInterface<VoEBase> base(voice_engine()); |
127 int error = base->StopSend(config_.voe_channel_id); | 142 int error = base->StopSend(config_.voe_channel_id); |
128 if (error != 0) { | 143 if (error != 0) { |
129 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; | 144 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; |
130 } | 145 } |
131 } | 146 } |
132 | 147 |
133 bool AudioSendStream::SendTelephoneEvent(int payload_type, int event, | 148 bool AudioSendStream::SendTelephoneEvent(int payload_type, int event, |
134 int duration_ms) { | 149 int duration_ms) { |
135 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 150 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 277 |
263 VoiceEngine* AudioSendStream::voice_engine() const { | 278 VoiceEngine* AudioSendStream::voice_engine() const { |
264 internal::AudioState* audio_state = | 279 internal::AudioState* audio_state = |
265 static_cast<internal::AudioState*>(audio_state_.get()); | 280 static_cast<internal::AudioState*>(audio_state_.get()); |
266 VoiceEngine* voice_engine = audio_state->voice_engine(); | 281 VoiceEngine* voice_engine = audio_state->voice_engine(); |
267 RTC_DCHECK(voice_engine); | 282 RTC_DCHECK(voice_engine); |
268 return voice_engine; | 283 return voice_engine; |
269 } | 284 } |
270 } // namespace internal | 285 } // namespace internal |
271 } // namespace webrtc | 286 } // namespace webrtc |
OLD | NEW |