Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: webrtc/audio/audio_transport_proxy.cc

Issue 2436033002: Replace AudioConferenceMixer with AudioMixer. (Closed)
Patch Set: Added mock mixer, merged audio state tests. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/audio/audio_transport_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
19 const int destination_sample_rate,
20 PushResampler<int16_t>* resampler,
21 int16_t* destination) {
22 const int number_of_channels = static_cast<int>(frame.num_channels_);
23 const int target_number_of_samples_per_channel =
24 destination_sample_rate / 100;
25 resampler->InitializeIfNeeded(frame.sample_rate_hz_, destination_sample_rate,
26 number_of_channels);
27
28 return resampler->Resample(
29 frame.data_, frame.samples_per_channel_ * number_of_channels, destination,
30 number_of_channels * target_number_of_samples_per_channel);
31 }
32 } // namespace
33
15 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, 34 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport,
16 AudioProcessing* apm, 35 AudioProcessing* apm,
17 AudioMixer* mixer) 36 AudioMixer* mixer)
18 : voe_audio_transport_(voe_audio_transport) { 37 : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) {
19 RTC_DCHECK(voe_audio_transport); 38 RTC_DCHECK(voe_audio_transport);
20 RTC_DCHECK(apm); 39 RTC_DCHECK(apm);
40 RTC_DCHECK(mixer);
21 } 41 }
22 42
23 AudioTransportProxy::~AudioTransportProxy() {} 43 AudioTransportProxy::~AudioTransportProxy() {}
24 44
25 int32_t AudioTransportProxy::RecordedDataIsAvailable( 45 int32_t AudioTransportProxy::RecordedDataIsAvailable(
26 const void* audioSamples, 46 const void* audioSamples,
27 const size_t nSamples, 47 const size_t nSamples,
28 const size_t nBytesPerSample, 48 const size_t nBytesPerSample,
29 const size_t nChannels, 49 const size_t nChannels,
30 const uint32_t samplesPerSec, 50 const uint32_t samplesPerSec,
(...skipping 15 matching lines...) Expand all
46 void* audioSamples, 66 void* audioSamples,
47 size_t& nSamplesOut, 67 size_t& nSamplesOut,
48 int64_t* elapsed_time_ms, 68 int64_t* elapsed_time_ms,
49 int64_t* ntp_time_ms) { 69 int64_t* ntp_time_ms) {
50 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample); 70 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample);
51 RTC_DCHECK_GE(nChannels, 1u); 71 RTC_DCHECK_GE(nChannels, 1u);
52 RTC_DCHECK_LE(nChannels, 2u); 72 RTC_DCHECK_LE(nChannels, 2u);
53 RTC_DCHECK_GE( 73 RTC_DCHECK_GE(
54 samplesPerSec, 74 samplesPerSec,
55 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz)); 75 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz));
76
77 // 100 = 1 second / data duration (10 ms).
56 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); 78 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec);
57 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, 79 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels,
58 sizeof(AudioFrame::data_)); 80 sizeof(AudioFrame::data_));
59 81
60 // Pass call through to original audio transport instance. 82 mixer_->Mix(nChannels, &mixed_frame_);
61 return voe_audio_transport_->NeedMorePlayData( 83 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_;
62 nSamples, nBytesPerSample, nChannels, samplesPerSec, audioSamples, 84 *ntp_time_ms = mixed_frame_.ntp_time_ms_;
63 nSamplesOut, elapsed_time_ms, ntp_time_ms); 85
86 const auto error = apm_->ProcessReverseStream(&mixed_frame_);
87 RTC_DCHECK_EQ(error, AudioProcessing::kNoError);
88
89 nSamplesOut = Resample(mixed_frame_, samplesPerSec, &resampler_,
90 static_cast<int16_t*>(audioSamples));
91 RTC_DCHECK_EQ(nSamplesOut, nChannels * nSamples);
92 return 0;
64 } 93 }
65 94
66 void AudioTransportProxy::PushCaptureData(int voe_channel, 95 void AudioTransportProxy::PushCaptureData(int voe_channel,
67 const void* audio_data, 96 const void* audio_data,
68 int bits_per_sample, 97 int bits_per_sample,
69 int sample_rate, 98 int sample_rate,
70 size_t number_of_channels, 99 size_t number_of_channels,
71 size_t number_of_frames) { 100 size_t number_of_frames) {
72 // This is part of deprecated VoE interface operating on specific 101 // This is part of deprecated VoE interface operating on specific
73 // VoE channels. It should not be used. 102 // VoE channels. It should not be used.
74 RTC_NOTREACHED(); 103 RTC_NOTREACHED();
75 } 104 }
76 105
77 void AudioTransportProxy::PullRenderData(int bits_per_sample, 106 void AudioTransportProxy::PullRenderData(int bits_per_sample,
78 int sample_rate, 107 int sample_rate,
79 size_t number_of_channels, 108 size_t number_of_channels,
80 size_t number_of_frames, 109 size_t number_of_frames,
81 void* audio_data, 110 void* audio_data,
82 int64_t* elapsed_time_ms, 111 int64_t* elapsed_time_ms,
83 int64_t* ntp_time_ms) { 112 int64_t* ntp_time_ms) {
84 RTC_DCHECK_EQ(static_cast<size_t>(bits_per_sample), 8 * sizeof(int16_t)); 113 RTC_DCHECK_EQ(static_cast<size_t>(bits_per_sample), 16);
85 RTC_DCHECK_GE(number_of_channels, 1u); 114 RTC_DCHECK_GE(number_of_channels, 1u);
86 RTC_DCHECK_LE(number_of_channels, 2u); 115 RTC_DCHECK_LE(number_of_channels, 2u);
87 RTC_DCHECK_GE(static_cast<int>(sample_rate), 116 RTC_DCHECK_GE(static_cast<int>(sample_rate),
88 AudioProcessing::NativeRate::kSampleRate8kHz); 117 AudioProcessing::NativeRate::kSampleRate8kHz);
118
119 // 100 = 1 second / data duration (10 ms).
89 RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate); 120 RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate);
121
122 // 8 = bits per byte.
90 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, 123 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels,
91 sizeof(AudioFrame::data_)); 124 sizeof(AudioFrame::data_));
92 voe_audio_transport_->PullRenderData( 125 mixer_->Mix(number_of_channels, &mixed_frame_);
93 bits_per_sample, sample_rate, number_of_channels, number_of_frames, 126 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_;
94 audio_data, elapsed_time_ms, ntp_time_ms); 127 *ntp_time_ms = mixed_frame_.ntp_time_ms_;
128
129 const auto output_samples = Resample(mixed_frame_, sample_rate, &resampler_,
130 static_cast<int16_t*>(audio_data));
131 RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames);
95 } 132 }
96 133
97 } // namespace webrtc 134 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/audio/audio_transport_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698