OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 #ifdef HAVE_WEBRTC_VOICE | 11 #ifdef HAVE_WEBRTC_VOICE |
12 | 12 |
13 #include "webrtc/media/engine/webrtcvoiceengine.h" | 13 #include "webrtc/media/engine/webrtcvoiceengine.h" |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 #include <cstdio> | 16 #include <cstdio> |
17 #include <functional> | 17 #include <functional> |
18 #include <string> | 18 #include <string> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "webrtc/api/call/audio_sink.h" | 21 #include "webrtc/api/call/audio_sink.h" |
22 #include "webrtc/base/arraysize.h" | 22 #include "webrtc/base/arraysize.h" |
23 #include "webrtc/base/base64.h" | 23 #include "webrtc/base/base64.h" |
24 #include "webrtc/base/byteorder.h" | 24 #include "webrtc/base/byteorder.h" |
25 #include "webrtc/base/common.h" | 25 #include "webrtc/base/common.h" |
26 #include "webrtc/base/constructormagic.h" | 26 #include "webrtc/base/constructormagic.h" |
27 #include "webrtc/base/helpers.h" | 27 #include "webrtc/base/helpers.h" |
28 #include "webrtc/base/logging.h" | 28 #include "webrtc/base/logging.h" |
| 29 #include "webrtc/base/race_checker.h" |
29 #include "webrtc/base/stringencode.h" | 30 #include "webrtc/base/stringencode.h" |
30 #include "webrtc/base/stringutils.h" | 31 #include "webrtc/base/stringutils.h" |
31 #include "webrtc/base/trace_event.h" | 32 #include "webrtc/base/trace_event.h" |
32 #include "webrtc/media/base/audiosource.h" | 33 #include "webrtc/media/base/audiosource.h" |
33 #include "webrtc/media/base/mediaconstants.h" | 34 #include "webrtc/media/base/mediaconstants.h" |
34 #include "webrtc/media/base/streamparams.h" | 35 #include "webrtc/media/base/streamparams.h" |
35 #include "webrtc/media/engine/payload_type_mapper.h" | 36 #include "webrtc/media/engine/payload_type_mapper.h" |
36 #include "webrtc/media/engine/webrtcmediaengine.h" | 37 #include "webrtc/media/engine/webrtcmediaengine.h" |
37 #include "webrtc/media/engine/webrtcvoe.h" | 38 #include "webrtc/media/engine/webrtcvoe.h" |
38 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | 39 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 webrtc::Call* call, | 1149 webrtc::Call* call, |
1149 webrtc::Transport* send_transport) | 1150 webrtc::Transport* send_transport) |
1150 : voe_audio_transport_(voe_audio_transport), | 1151 : voe_audio_transport_(voe_audio_transport), |
1151 call_(call), | 1152 call_(call), |
1152 config_(send_transport), | 1153 config_(send_transport), |
1153 rtp_parameters_(CreateRtpParametersWithOneEncoding()) { | 1154 rtp_parameters_(CreateRtpParametersWithOneEncoding()) { |
1154 RTC_DCHECK_GE(ch, 0); | 1155 RTC_DCHECK_GE(ch, 0); |
1155 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: | 1156 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: |
1156 // RTC_DCHECK(voe_audio_transport); | 1157 // RTC_DCHECK(voe_audio_transport); |
1157 RTC_DCHECK(call); | 1158 RTC_DCHECK(call); |
1158 audio_capture_thread_checker_.DetachFromThread(); | |
1159 config_.rtp.ssrc = ssrc; | 1159 config_.rtp.ssrc = ssrc; |
1160 config_.rtp.c_name = c_name; | 1160 config_.rtp.c_name = c_name; |
1161 config_.voe_channel_id = ch; | 1161 config_.voe_channel_id = ch; |
1162 config_.rtp.extensions = extensions; | 1162 config_.rtp.extensions = extensions; |
1163 RecreateAudioSendStream(send_codec_spec); | 1163 RecreateAudioSendStream(send_codec_spec); |
1164 } | 1164 } |
1165 | 1165 |
1166 ~WebRtcAudioSendStream() override { | 1166 ~WebRtcAudioSendStream() override { |
1167 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1167 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1168 ClearSource(); | 1168 ClearSource(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 UpdateSendState(); | 1263 UpdateSendState(); |
1264 } | 1264 } |
1265 | 1265 |
1266 // AudioSource::Sink implementation. | 1266 // AudioSource::Sink implementation. |
1267 // This method is called on the audio thread. | 1267 // This method is called on the audio thread. |
1268 void OnData(const void* audio_data, | 1268 void OnData(const void* audio_data, |
1269 int bits_per_sample, | 1269 int bits_per_sample, |
1270 int sample_rate, | 1270 int sample_rate, |
1271 size_t number_of_channels, | 1271 size_t number_of_channels, |
1272 size_t number_of_frames) override { | 1272 size_t number_of_frames) override { |
1273 RTC_DCHECK(audio_capture_thread_checker_.CalledOnValidThread()); | 1273 RTC_CHECK_RUNS_SERIALIZED(&audio_capture_race_checker_); |
1274 RTC_DCHECK(voe_audio_transport_); | 1274 RTC_DCHECK(voe_audio_transport_); |
1275 voe_audio_transport_->PushCaptureData(config_.voe_channel_id, audio_data, | 1275 voe_audio_transport_->PushCaptureData(config_.voe_channel_id, audio_data, |
1276 bits_per_sample, sample_rate, | 1276 bits_per_sample, sample_rate, |
1277 number_of_channels, number_of_frames); | 1277 number_of_channels, number_of_frames); |
1278 } | 1278 } |
1279 | 1279 |
1280 // Callback from the |source_| when it is going away. In case Start() has | 1280 // Callback from the |source_| when it is going away. In case Start() has |
1281 // never been called, this callback won't be triggered. | 1281 // never been called, this callback won't be triggered. |
1282 void OnClose() override { | 1282 void OnClose() override { |
1283 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1283 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
(...skipping 26 matching lines...) Expand all Loading... |
1310 RTC_DCHECK(stream_); | 1310 RTC_DCHECK(stream_); |
1311 RTC_DCHECK_EQ(1UL, rtp_parameters_.encodings.size()); | 1311 RTC_DCHECK_EQ(1UL, rtp_parameters_.encodings.size()); |
1312 if (send_ && source_ != nullptr && rtp_parameters_.encodings[0].active) { | 1312 if (send_ && source_ != nullptr && rtp_parameters_.encodings[0].active) { |
1313 stream_->Start(); | 1313 stream_->Start(); |
1314 } else { // !send || source_ = nullptr | 1314 } else { // !send || source_ = nullptr |
1315 stream_->Stop(); | 1315 stream_->Stop(); |
1316 } | 1316 } |
1317 } | 1317 } |
1318 | 1318 |
1319 rtc::ThreadChecker worker_thread_checker_; | 1319 rtc::ThreadChecker worker_thread_checker_; |
1320 rtc::ThreadChecker audio_capture_thread_checker_; | 1320 rtc::RaceChecker audio_capture_race_checker_; |
1321 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; | 1321 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; |
1322 webrtc::Call* call_ = nullptr; | 1322 webrtc::Call* call_ = nullptr; |
1323 webrtc::AudioSendStream::Config config_; | 1323 webrtc::AudioSendStream::Config config_; |
1324 // The stream is owned by WebRtcAudioSendStream and may be reallocated if | 1324 // The stream is owned by WebRtcAudioSendStream and may be reallocated if |
1325 // configuration changes. | 1325 // configuration changes. |
1326 webrtc::AudioSendStream* stream_ = nullptr; | 1326 webrtc::AudioSendStream* stream_ = nullptr; |
1327 | 1327 |
1328 // Raw pointer to AudioSource owned by LocalAudioTrackHandler. | 1328 // Raw pointer to AudioSource owned by LocalAudioTrackHandler. |
1329 // PeerConnection will make sure invalidating the pointer before the object | 1329 // PeerConnection will make sure invalidating the pointer before the object |
1330 // goes away. | 1330 // goes away. |
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2661 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2661 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2662 const auto it = send_streams_.find(ssrc); | 2662 const auto it = send_streams_.find(ssrc); |
2663 if (it != send_streams_.end()) { | 2663 if (it != send_streams_.end()) { |
2664 return it->second->channel(); | 2664 return it->second->channel(); |
2665 } | 2665 } |
2666 return -1; | 2666 return -1; |
2667 } | 2667 } |
2668 } // namespace cricket | 2668 } // namespace cricket |
2669 | 2669 |
2670 #endif // HAVE_WEBRTC_VOICE | 2670 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |