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 #include <utility> | |
14 | 15 |
15 #include "webrtc/audio/audio_state.h" | 16 #include "webrtc/audio/audio_state.h" |
16 #include "webrtc/audio/conversion.h" | 17 #include "webrtc/audio/conversion.h" |
17 #include "webrtc/audio/scoped_voe_interface.h" | 18 #include "webrtc/audio/scoped_voe_interface.h" |
18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/event.h" | 20 #include "webrtc/base/event.h" |
20 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
21 #include "webrtc/base/task_queue.h" | 22 #include "webrtc/base/task_queue.h" |
22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
23 #include "webrtc/modules/pacing/paced_sender.h" | 24 #include "webrtc/modules/pacing/paced_sender.h" |
(...skipping 10 matching lines...) Loading... | |
34 namespace { | 35 namespace { |
35 | 36 |
36 constexpr char kOpusCodecName[] = "opus"; | 37 constexpr char kOpusCodecName[] = "opus"; |
37 | 38 |
38 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { | 39 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { |
39 return (_stricmp(codec.plname, ref_name) == 0); | 40 return (_stricmp(codec.plname, ref_name) == 0); |
40 } | 41 } |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 namespace internal { | 44 namespace internal { |
45 | |
46 class AudioSendStream::AdaptCodecTask : public rtc::QueuedTask { | |
47 public: | |
48 AdaptCodecTask(rtc::WeakPtr<AudioSendStream> send_stream, | |
49 int64_t adapt_codec_interval_ms) | |
50 : send_stream_(std::move(send_stream)), | |
51 adapt_codec_interval_ms_(adapt_codec_interval_ms) {} | |
52 | |
53 private: | |
54 bool Run() override { | |
55 if (send_stream_) { | |
ossu
2016/12/20 13:58:09
I'm not too well versed in the TaskQueue, but I ex
michaelt
2016/12/20 15:13:03
You are right.
Done
I think a fast turn-around b
| |
56 send_stream_->AdaptCodec(); | |
57 } | |
58 rtc::TaskQueue::Current()->PostDelayedTask( | |
59 std::unique_ptr<rtc::QueuedTask>(this), adapt_codec_interval_ms_); | |
60 return false; | |
61 } | |
62 | |
63 rtc::WeakPtr<AudioSendStream> send_stream_; | |
64 int64_t adapt_codec_interval_ms_; | |
65 }; | |
66 | |
44 AudioSendStream::AudioSendStream( | 67 AudioSendStream::AudioSendStream( |
45 const webrtc::AudioSendStream::Config& config, | 68 const webrtc::AudioSendStream::Config& config, |
46 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 69 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
47 rtc::TaskQueue* worker_queue, | 70 rtc::TaskQueue* worker_queue, |
48 PacketRouter* packet_router, | 71 PacketRouter* packet_router, |
49 CongestionController* congestion_controller, | 72 CongestionController* congestion_controller, |
50 BitrateAllocator* bitrate_allocator, | 73 BitrateAllocator* bitrate_allocator, |
51 RtcEventLog* event_log, | 74 RtcEventLog* event_log, |
52 RtcpRttStats* rtcp_rtt_stats) | 75 RtcpRttStats* rtcp_rtt_stats) |
53 : worker_queue_(worker_queue), | 76 : worker_queue_(worker_queue), |
(...skipping 44 matching lines...) Loading... | |
98 channel_proxy_->SetRtcEventLog(nullptr); | 121 channel_proxy_->SetRtcEventLog(nullptr); |
99 channel_proxy_->SetRtcpRttStats(nullptr); | 122 channel_proxy_->SetRtcpRttStats(nullptr); |
100 } | 123 } |
101 | 124 |
102 void AudioSendStream::Start() { | 125 void AudioSendStream::Start() { |
103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 126 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
104 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { | 127 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { |
105 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); | 128 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); |
106 rtc::Event thread_sync_event(false /* manual_reset */, false); | 129 rtc::Event thread_sync_event(false /* manual_reset */, false); |
107 worker_queue_->PostTask([this, &thread_sync_event] { | 130 worker_queue_->PostTask([this, &thread_sync_event] { |
131 weak_ptr_factory_.reset(new rtc::WeakPtrFactory<AudioSendStream>(this)); | |
132 | |
133 // Starts adapt codec task, which calls AdaptCodec on a timely base. | |
134 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>( | |
135 new AdaptCodecTask(weak_ptr_factory_->GetWeakPtr(), | |
136 config_.adapt_codec_interval_ms))); | |
137 | |
108 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps, | 138 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps, |
109 config_.max_bitrate_bps, 0, true); | 139 config_.max_bitrate_bps, 0, true); |
110 thread_sync_event.Set(); | 140 thread_sync_event.Set(); |
111 }); | 141 }); |
112 thread_sync_event.Wait(rtc::Event::kForever); | 142 thread_sync_event.Wait(rtc::Event::kForever); |
113 } | 143 } |
114 | 144 |
115 ScopedVoEInterface<VoEBase> base(voice_engine()); | 145 ScopedVoEInterface<VoEBase> base(voice_engine()); |
116 int error = base->StartSend(config_.voe_channel_id); | 146 int error = base->StartSend(config_.voe_channel_id); |
117 if (error != 0) { | 147 if (error != 0) { |
118 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; | 148 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; |
119 } | 149 } |
120 } | 150 } |
121 | 151 |
122 void AudioSendStream::Stop() { | 152 void AudioSendStream::Stop() { |
123 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 153 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
124 rtc::Event thread_sync_event(false /* manual_reset */, false); | 154 rtc::Event thread_sync_event(false /* manual_reset */, false); |
125 worker_queue_->PostTask([this, &thread_sync_event] { | 155 worker_queue_->PostTask([this, &thread_sync_event] { |
126 bitrate_allocator_->RemoveObserver(this); | 156 bitrate_allocator_->RemoveObserver(this); |
157 weak_ptr_factory_.reset(nullptr); | |
127 thread_sync_event.Set(); | 158 thread_sync_event.Set(); |
128 }); | 159 }); |
129 thread_sync_event.Wait(rtc::Event::kForever); | 160 thread_sync_event.Wait(rtc::Event::kForever); |
130 | 161 |
131 ScopedVoEInterface<VoEBase> base(voice_engine()); | 162 ScopedVoEInterface<VoEBase> base(voice_engine()); |
132 int error = base->StopSend(config_.voe_channel_id); | 163 int error = base->StopSend(config_.voe_channel_id); |
133 if (error != 0) { | 164 if (error != 0) { |
134 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; | 165 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; |
135 } | 166 } |
136 } | 167 } |
(...skipping 242 matching lines...) Loading... | |
379 // interaction between VAD and Opus FEC. | 410 // interaction between VAD and Opus FEC. |
380 if (codec->SetVADStatus(channel, true) != 0) { | 411 if (codec->SetVADStatus(channel, true) != 0) { |
381 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); | 412 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); |
382 return false; | 413 return false; |
383 } | 414 } |
384 } | 415 } |
385 } | 416 } |
386 return true; | 417 return true; |
387 } | 418 } |
388 | 419 |
420 void AudioSendStream::AdaptCodec() { | |
421 RTC_DCHECK_RUN_ON(worker_queue_); | |
422 channel_proxy_->AdaptCodec(); | |
423 } | |
424 | |
389 } // namespace internal | 425 } // namespace internal |
390 } // namespace webrtc | 426 } // namespace webrtc |
OLD | NEW |