OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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_transport_proxy.h" | 11 #include "webrtc/audio/audio_transport_proxy.h" |
12 | 12 |
13 namespace webrtc { | 13 namespace webrtc { |
14 | 14 |
15 namespace { | |
16 // Resample audio in |frame| to given sample rate preserving the | |
17 // channel count and place the result in |destination|. | |
18 int Resample(const AudioFrame& frame, | |
the sun
2016/11/14 20:03:47
I'd find this order more intuitive:
source_frame,
aleloi
2016/11/15 16:56:54
I was trying to follow the style guide for paramet
the sun
2016/11/16 20:22:57
Uhm, ok. Thanks for educating me.
| |
19 const int target_sample_rate, | |
20 PushResampler<int16_t>* resampler, | |
21 int16_t* destination) { | |
22 const int frame_sample_rate = frame.sample_rate_hz_; | |
the sun
2016/11/14 20:03:46
Remove this local
aleloi
2016/11/15 16:56:54
Done.
| |
23 const int number_of_channels = frame.num_channels_; | |
24 const int target_number_of_samples_per_channel = target_sample_rate / 100; | |
25 resampler->InitializeIfNeeded(frame_sample_rate, target_sample_rate, | |
26 number_of_channels); | |
27 | |
28 return resampler->Resample( | |
29 frame.data_, frame.samples_per_channel_ * number_of_channels, | |
30 static_cast<int16_t*>(destination), | |
the sun
2016/11/14 20:03:47
cast not needed
aleloi
2016/11/15 16:56:54
Acknowledged.
| |
31 number_of_channels * target_number_of_samples_per_channel); | |
32 } | |
33 } // namespace | |
34 | |
15 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, | 35 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, |
16 AudioProcessing* apm, | 36 AudioProcessing* apm, |
17 AudioMixer* mixer) | 37 AudioMixer* mixer) |
18 : voe_audio_transport_(voe_audio_transport) { | 38 : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) { |
39 RTC_DCHECK(apm); | |
the sun
2016/11/14 20:03:46
nit: use same order as ctor init list
aleloi
2016/11/15 16:56:54
Done.
| |
40 RTC_DCHECK(mixer); | |
19 RTC_DCHECK(voe_audio_transport); | 41 RTC_DCHECK(voe_audio_transport); |
20 RTC_DCHECK(apm); | |
21 } | 42 } |
22 | 43 |
23 AudioTransportProxy::~AudioTransportProxy() {} | 44 AudioTransportProxy::~AudioTransportProxy() {} |
24 | 45 |
25 int32_t AudioTransportProxy::RecordedDataIsAvailable( | 46 int32_t AudioTransportProxy::RecordedDataIsAvailable( |
26 const void* audioSamples, | 47 const void* audioSamples, |
27 const size_t nSamples, | 48 const size_t nSamples, |
28 const size_t nBytesPerSample, | 49 const size_t nBytesPerSample, |
29 const size_t nChannels, | 50 const size_t nChannels, |
30 const uint32_t samplesPerSec, | 51 const uint32_t samplesPerSec, |
(...skipping 19 matching lines...) Expand all Loading... | |
50 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample); | 71 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample); |
51 RTC_DCHECK_GE(nChannels, 1u); | 72 RTC_DCHECK_GE(nChannels, 1u); |
52 RTC_DCHECK_LE(nChannels, 2u); | 73 RTC_DCHECK_LE(nChannels, 2u); |
53 RTC_DCHECK_GE( | 74 RTC_DCHECK_GE( |
54 samplesPerSec, | 75 samplesPerSec, |
55 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz)); | 76 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz)); |
56 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); | 77 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); |
57 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, | 78 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, |
58 sizeof(AudioFrame::data_)); | 79 sizeof(AudioFrame::data_)); |
59 | 80 |
60 // Pass call through to original audio transport instance. | 81 mixer_->Mix(static_cast<int>(nChannels), &frame_for_mixing_); |
the sun
2016/11/14 20:03:46
Cast should be unnecessary here.
| |
61 return voe_audio_transport_->NeedMorePlayData( | 82 *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; |
62 nSamples, nBytesPerSample, nChannels, samplesPerSec, audioSamples, | 83 *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; |
63 nSamplesOut, elapsed_time_ms, ntp_time_ms); | 84 |
85 const auto error = apm_->ProcessReverseStream(&frame_for_mixing_); | |
86 RTC_DCHECK_EQ(error, AudioProcessing::kNoError); | |
87 | |
88 nSamplesOut = Resample(frame_for_mixing_, samplesPerSec, &resampler_, | |
89 static_cast<int16_t*>(audioSamples)); | |
the sun
2016/11/14 20:03:46
DCHECK that nSamplesOut is nSamples?
aleloi
2016/11/15 16:56:54
Done.
| |
90 return 0; | |
64 } | 91 } |
65 | 92 |
66 void AudioTransportProxy::PushCaptureData(int voe_channel, | 93 void AudioTransportProxy::PushCaptureData(int voe_channel, |
67 const void* audio_data, | 94 const void* audio_data, |
68 int bits_per_sample, | 95 int bits_per_sample, |
69 int sample_rate, | 96 int sample_rate, |
70 size_t number_of_channels, | 97 size_t number_of_channels, |
71 size_t number_of_frames) { | 98 size_t number_of_frames) { |
72 // This is part of deprecated VoE interface operating on specific | 99 // This is part of deprecated VoE interface operating on specific |
73 // VoE channels. It should not be used. | 100 // VoE channels. It should not be used. |
74 RTC_NOTREACHED(); | 101 RTC_NOTREACHED(); |
75 } | 102 } |
76 | 103 |
77 void AudioTransportProxy::PullRenderData(int bits_per_sample, | 104 void AudioTransportProxy::PullRenderData(int bits_per_sample, |
78 int sample_rate, | 105 int sample_rate, |
79 size_t number_of_channels, | 106 size_t number_of_channels, |
80 size_t number_of_frames, | 107 size_t number_of_frames, |
81 void* audio_data, | 108 void* audio_data, |
82 int64_t* elapsed_time_ms, | 109 int64_t* elapsed_time_ms, |
83 int64_t* ntp_time_ms) { | 110 int64_t* ntp_time_ms) { |
84 RTC_DCHECK_EQ(static_cast<size_t>(bits_per_sample), 8 * sizeof(int16_t)); | 111 RTC_DCHECK_EQ(static_cast<size_t>(bits_per_sample), 8 * sizeof(int16_t)); |
the sun
2016/11/14 20:03:46
Heh, it's called int16 for a reason. http://en.cpp
aleloi
2016/11/15 16:56:54
I hoped it helped with reading the code. I added c
| |
85 RTC_DCHECK_GE(number_of_channels, 1u); | 112 RTC_DCHECK_GE(number_of_channels, 1u); |
86 RTC_DCHECK_LE(number_of_channels, 2u); | 113 RTC_DCHECK_LE(number_of_channels, 2u); |
87 RTC_DCHECK_GE(static_cast<int>(sample_rate), | 114 RTC_DCHECK_GE(static_cast<int>(sample_rate), |
88 AudioProcessing::NativeRate::kSampleRate8kHz); | 115 AudioProcessing::NativeRate::kSampleRate8kHz); |
89 RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate); | 116 RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate); |
90 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, | 117 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, |
91 sizeof(AudioFrame::data_)); | 118 sizeof(AudioFrame::data_)); |
92 voe_audio_transport_->PullRenderData( | 119 mixer_->Mix(number_of_channels, &frame_for_mixing_); |
93 bits_per_sample, sample_rate, number_of_channels, number_of_frames, | 120 *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; |
94 audio_data, elapsed_time_ms, ntp_time_ms); | 121 *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; |
122 | |
123 Resample(frame_for_mixing_, sample_rate, &resampler_, | |
the sun
2016/11/14 20:03:47
Check return value?
aleloi
2016/11/15 16:56:54
Done.
| |
124 static_cast<int16_t*>(audio_data)); | |
95 } | 125 } |
96 | 126 |
97 } // namespace webrtc | 127 } // namespace webrtc |
OLD | NEW |