| 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" | |
| 20 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/task_queue.h" | |
| 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 20 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
| 23 #include "webrtc/modules/pacing/paced_sender.h" | 21 #include "webrtc/modules/pacing/paced_sender.h" |
| 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 25 #include "webrtc/voice_engine/channel_proxy.h" | 23 #include "webrtc/voice_engine/channel_proxy.h" |
| 26 #include "webrtc/voice_engine/include/voe_audio_processing.h" | 24 #include "webrtc/voice_engine/include/voe_audio_processing.h" |
| 27 #include "webrtc/voice_engine/include/voe_codec.h" | 25 #include "webrtc/voice_engine/include/voe_codec.h" |
| 28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 26 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
| 29 #include "webrtc/voice_engine/include/voe_volume_control.h" | 27 #include "webrtc/voice_engine/include/voe_volume_control.h" |
| 30 #include "webrtc/voice_engine/voice_engine_impl.h" | 28 #include "webrtc/voice_engine/voice_engine_impl.h" |
| 31 | 29 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 54 // TODO(solenberg): Encoder config. | 52 // TODO(solenberg): Encoder config. |
| 55 ss << ", cng_payload_type: " << cng_payload_type; | 53 ss << ", cng_payload_type: " << cng_payload_type; |
| 56 ss << '}'; | 54 ss << '}'; |
| 57 return ss.str(); | 55 return ss.str(); |
| 58 } | 56 } |
| 59 | 57 |
| 60 namespace internal { | 58 namespace internal { |
| 61 AudioSendStream::AudioSendStream( | 59 AudioSendStream::AudioSendStream( |
| 62 const webrtc::AudioSendStream::Config& config, | 60 const webrtc::AudioSendStream::Config& config, |
| 63 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 61 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 64 rtc::TaskQueue* worker_queue, | |
| 65 CongestionController* congestion_controller, | 62 CongestionController* congestion_controller, |
| 66 BitrateAllocator* bitrate_allocator) | 63 BitrateAllocator* bitrate_allocator) |
| 67 : worker_queue_(worker_queue), | 64 : config_(config), |
| 68 config_(config), | |
| 69 audio_state_(audio_state), | 65 audio_state_(audio_state), |
| 70 bitrate_allocator_(bitrate_allocator) { | 66 bitrate_allocator_(bitrate_allocator) { |
| 71 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 67 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); |
| 72 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 68 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
| 73 RTC_DCHECK(audio_state_.get()); | 69 RTC_DCHECK(audio_state_.get()); |
| 74 RTC_DCHECK(congestion_controller); | 70 RTC_DCHECK(congestion_controller); |
| 75 | 71 |
| 76 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 72 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
| 77 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 73 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
| 78 channel_proxy_->RegisterSenderCongestionControlObjects( | 74 channel_proxy_->RegisterSenderCongestionControlObjects( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 106 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 102 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 107 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 103 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
| 108 channel_proxy_->DeRegisterExternalTransport(); | 104 channel_proxy_->DeRegisterExternalTransport(); |
| 109 channel_proxy_->ResetCongestionControlObjects(); | 105 channel_proxy_->ResetCongestionControlObjects(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 void AudioSendStream::Start() { | 108 void AudioSendStream::Start() { |
| 113 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 109 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 114 if (config_.min_bitrate_kbps != -1 && config_.max_bitrate_kbps != -1) { | 110 if (config_.min_bitrate_kbps != -1 && config_.max_bitrate_kbps != -1) { |
| 115 RTC_DCHECK_GE(config_.max_bitrate_kbps, config_.min_bitrate_kbps); | 111 RTC_DCHECK_GE(config_.max_bitrate_kbps, config_.min_bitrate_kbps); |
| 116 rtc::Event thread_sync_event(false /* manual_reset */, false); | 112 bitrate_allocator_->AddObserver(this, config_.min_bitrate_kbps * 1000, |
| 117 worker_queue_->PostTask([this, &thread_sync_event] { | 113 config_.max_bitrate_kbps * 1000, 0, true); |
| 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); | |
| 123 } | 114 } |
| 124 | 115 |
| 125 ScopedVoEInterface<VoEBase> base(voice_engine()); | 116 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 126 int error = base->StartSend(config_.voe_channel_id); | 117 int error = base->StartSend(config_.voe_channel_id); |
| 127 if (error != 0) { | 118 if (error != 0) { |
| 128 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; | 119 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; |
| 129 } | 120 } |
| 130 } | 121 } |
| 131 | 122 |
| 132 void AudioSendStream::Stop() { | 123 void AudioSendStream::Stop() { |
| 133 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 124 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 134 rtc::Event thread_sync_event(false /* manual_reset */, false); | 125 bitrate_allocator_->RemoveObserver(this); |
| 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 | |
| 141 ScopedVoEInterface<VoEBase> base(voice_engine()); | 126 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 142 int error = base->StopSend(config_.voe_channel_id); | 127 int error = base->StopSend(config_.voe_channel_id); |
| 143 if (error != 0) { | 128 if (error != 0) { |
| 144 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; | 129 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; |
| 145 } | 130 } |
| 146 } | 131 } |
| 147 | 132 |
| 148 bool AudioSendStream::SendTelephoneEvent(int payload_type, int event, | 133 bool AudioSendStream::SendTelephoneEvent(int payload_type, int event, |
| 149 int duration_ms) { | 134 int duration_ms) { |
| 150 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 135 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 262 |
| 278 VoiceEngine* AudioSendStream::voice_engine() const { | 263 VoiceEngine* AudioSendStream::voice_engine() const { |
| 279 internal::AudioState* audio_state = | 264 internal::AudioState* audio_state = |
| 280 static_cast<internal::AudioState*>(audio_state_.get()); | 265 static_cast<internal::AudioState*>(audio_state_.get()); |
| 281 VoiceEngine* voice_engine = audio_state->voice_engine(); | 266 VoiceEngine* voice_engine = audio_state->voice_engine(); |
| 282 RTC_DCHECK(voice_engine); | 267 RTC_DCHECK(voice_engine); |
| 283 return voice_engine; | 268 return voice_engine; |
| 284 } | 269 } |
| 285 } // namespace internal | 270 } // namespace internal |
| 286 } // namespace webrtc | 271 } // namespace webrtc |
| OLD | NEW |