OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/voice_engine/channel.h" | 11 #include "webrtc/voice_engine/channel.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <utility> |
14 | 15 |
15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/format_macros.h" | 17 #include "webrtc/base/format_macros.h" |
17 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/thread_checker.h" | 19 #include "webrtc/base/thread_checker.h" |
19 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
20 #include "webrtc/common.h" | 21 #include "webrtc/common.h" |
21 #include "webrtc/config.h" | 22 #include "webrtc/config.h" |
22 #include "webrtc/modules/audio_device/include/audio_device.h" | 23 #include "webrtc/modules/audio_device/include/audio_device.h" |
23 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 24 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 ChannelState::State state = channel_state_.Get(); | 554 ChannelState::State state = channel_state_.Get(); |
554 | 555 |
555 if (state.rx_apm_is_enabled) { | 556 if (state.rx_apm_is_enabled) { |
556 int err = rx_audioproc_->ProcessStream(audioFrame); | 557 int err = rx_audioproc_->ProcessStream(audioFrame); |
557 if (err) { | 558 if (err) { |
558 LOG(LS_ERROR) << "ProcessStream() error: " << err; | 559 LOG(LS_ERROR) << "ProcessStream() error: " << err; |
559 assert(false); | 560 assert(false); |
560 } | 561 } |
561 } | 562 } |
562 | 563 |
| 564 { |
| 565 // Pass the audio buffers to an optional sink callback, before applying |
| 566 // scaling/panning, as that applies to the mix operation. |
| 567 // External recipients of the audio (e.g. via AudioTrack), will do their |
| 568 // own mixing/dynamic processing. |
| 569 CriticalSectionScoped cs(&_callbackCritSect); |
| 570 if (audio_sink_) { |
| 571 AudioSink::Data data(reinterpret_cast<uint8_t*>(&audioFrame->data_[0]), |
| 572 audioFrame->samples_per_channel_, |
| 573 audioFrame->sample_rate_hz_, |
| 574 audioFrame->num_channels_, audioFrame->timestamp_); |
| 575 audio_sink_->OnData(data); |
| 576 } |
| 577 } |
| 578 |
563 float output_gain = 1.0f; | 579 float output_gain = 1.0f; |
564 float left_pan = 1.0f; | 580 float left_pan = 1.0f; |
565 float right_pan = 1.0f; | 581 float right_pan = 1.0f; |
566 { | 582 { |
567 CriticalSectionScoped cs(&volume_settings_critsect_); | 583 CriticalSectionScoped cs(&volume_settings_critsect_); |
568 output_gain = _outputGain; | 584 output_gain = _outputGain; |
569 left_pan = _panLeft; | 585 left_pan = _panLeft; |
570 right_pan= _panRight; | 586 right_pan= _panRight; |
571 } | 587 } |
572 | 588 |
(...skipping 28 matching lines...) Expand all Loading... |
601 MixAudioWithFile(*audioFrame, audioFrame->sample_rate_hz_); | 617 MixAudioWithFile(*audioFrame, audioFrame->sample_rate_hz_); |
602 } | 618 } |
603 | 619 |
604 // External media | 620 // External media |
605 if (_outputExternalMedia) | 621 if (_outputExternalMedia) |
606 { | 622 { |
607 CriticalSectionScoped cs(&_callbackCritSect); | 623 CriticalSectionScoped cs(&_callbackCritSect); |
608 const bool isStereo = (audioFrame->num_channels_ == 2); | 624 const bool isStereo = (audioFrame->num_channels_ == 2); |
609 if (_outputExternalMediaCallbackPtr) | 625 if (_outputExternalMediaCallbackPtr) |
610 { | 626 { |
611 _outputExternalMediaCallbackPtr->Process( | 627 _outputExternalMediaCallbackPtr->Process( |
612 _channelId, | 628 _channelId, |
613 kPlaybackPerChannel, | 629 kPlaybackPerChannel, |
614 (int16_t*)audioFrame->data_, | 630 (int16_t*)audioFrame->data_, |
615 audioFrame->samples_per_channel_, | 631 audioFrame->samples_per_channel_, |
616 audioFrame->sample_rate_hz_, | 632 audioFrame->sample_rate_hz_, |
617 isStereo); | 633 isStereo); |
618 } | 634 } |
619 } | 635 } |
620 | 636 |
621 // Record playout if enabled | 637 // Record playout if enabled |
622 { | 638 { |
623 CriticalSectionScoped cs(&_fileCritSect); | 639 CriticalSectionScoped cs(&_fileCritSect); |
624 | 640 |
625 if (_outputFileRecording && _outputFileRecorderPtr) | 641 if (_outputFileRecording && _outputFileRecorderPtr) |
626 { | 642 { |
627 _outputFileRecorderPtr->RecordAudioToFile(*audioFrame); | 643 _outputFileRecorderPtr->RecordAudioToFile(*audioFrame); |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 } | 1181 } |
1166 | 1182 |
1167 int32_t | 1183 int32_t |
1168 Channel::UpdateLocalTimeStamp() | 1184 Channel::UpdateLocalTimeStamp() |
1169 { | 1185 { |
1170 | 1186 |
1171 _timeStamp += static_cast<uint32_t>(_audioFrame.samples_per_channel_); | 1187 _timeStamp += static_cast<uint32_t>(_audioFrame.samples_per_channel_); |
1172 return 0; | 1188 return 0; |
1173 } | 1189 } |
1174 | 1190 |
| 1191 void Channel::SetSink(rtc::scoped_ptr<AudioSink> sink) { |
| 1192 CriticalSectionScoped cs(&_callbackCritSect); |
| 1193 audio_sink_ = std::move(sink); |
| 1194 } |
| 1195 |
1175 int32_t | 1196 int32_t |
1176 Channel::StartPlayout() | 1197 Channel::StartPlayout() |
1177 { | 1198 { |
1178 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), | 1199 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
1179 "Channel::StartPlayout()"); | 1200 "Channel::StartPlayout()"); |
1180 if (channel_state_.Get().playing) | 1201 if (channel_state_.Get().playing) |
1181 { | 1202 { |
1182 return 0; | 1203 return 0; |
1183 } | 1204 } |
1184 | 1205 |
(...skipping 2901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4086 int64_t min_rtt = 0; | 4107 int64_t min_rtt = 0; |
4087 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) | 4108 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) |
4088 != 0) { | 4109 != 0) { |
4089 return 0; | 4110 return 0; |
4090 } | 4111 } |
4091 return rtt; | 4112 return rtt; |
4092 } | 4113 } |
4093 | 4114 |
4094 } // namespace voe | 4115 } // namespace voe |
4095 } // namespace webrtc | 4116 } // namespace webrtc |
OLD | NEW |