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

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

Issue 2436033002: Replace AudioConferenceMixer with AudioMixer. (Closed)
Patch Set: Consistent thread checker, errcode handling in RecStream. 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
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 = 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,
31 const uint32_t totalDelayMS, 51 const uint32_t totalDelayMS,
32 const int32_t clockDrift, 52 const int32_t clockDrift,
33 const uint32_t currentMicLevel, 53 const uint32_t currentMicLevel,
34 const bool keyPressed, 54 const bool keyPressed,
35 uint32_t& newMicLevel) { 55 uint32_t& newMicLevel) {
36 // Pass call through to original audio transport instance. 56 // Pass call through to original audio transport instance.
37 return voe_audio_transport_->RecordedDataIsAvailable( 57 return voe_audio_transport_->RecordedDataIsAvailable(
38 audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec, 58 audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec,
39 totalDelayMS, clockDrift, currentMicLevel, keyPressed, newMicLevel); 59 totalDelayMS, clockDrift, currentMicLevel, keyPressed, newMicLevel);
40 } 60 }
41 61
42 int32_t AudioTransportProxy::NeedMorePlayData(const size_t nSamples, 62 int32_t AudioTransportProxy::NeedMorePlayData(const size_t nSamples,
43 const size_t nBytesPerSample, 63 const size_t nBytesPerSample,
44 const size_t nChannels, 64 const size_t nChannels,
45 const uint32_t samplesPerSec, 65 const uint32_t samplesPerSec,
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 // 2 = bytes in sample.
71 RTC_DCHECK_EQ(2 * nChannels, nBytesPerSample);
the sun 2016/11/16 20:22:58 Here I think sizeof(int16_t) made the code more re
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));
77
78 // 100 = 1 second / data duration.
56 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); 79 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec);
57 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, 80 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels,
58 sizeof(AudioFrame::data_)); 81 sizeof(AudioFrame::data_));
59 82
60 // Pass call through to original audio transport instance. 83 mixer_->Mix(nChannels, &mixed_frame_);
61 return voe_audio_transport_->NeedMorePlayData( 84 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_;
62 nSamples, nBytesPerSample, nChannels, samplesPerSec, audioSamples, 85 *ntp_time_ms = mixed_frame_.ntp_time_ms_;
63 nSamplesOut, elapsed_time_ms, ntp_time_ms); 86
87 const auto error = apm_->ProcessReverseStream(&mixed_frame_);
88 RTC_DCHECK_EQ(error, AudioProcessing::kNoError);
89
90 nSamplesOut = Resample(mixed_frame_, samplesPerSec, &resampler_,
91 static_cast<int16_t*>(audioSamples));
92 RTC_DCHECK_EQ(nSamplesOut, nChannels * nSamples);
93 return 0;
64 } 94 }
65 95
66 void AudioTransportProxy::PushCaptureData(int voe_channel, 96 void AudioTransportProxy::PushCaptureData(int voe_channel,
67 const void* audio_data, 97 const void* audio_data,
68 int bits_per_sample, 98 int bits_per_sample,
69 int sample_rate, 99 int sample_rate,
70 size_t number_of_channels, 100 size_t number_of_channels,
71 size_t number_of_frames) { 101 size_t number_of_frames) {
72 // This is part of deprecated VoE interface operating on specific 102 // This is part of deprecated VoE interface operating on specific
73 // VoE channels. It should not be used. 103 // VoE channels. It should not be used.
74 RTC_NOTREACHED(); 104 RTC_NOTREACHED();
75 } 105 }
76 106
77 void AudioTransportProxy::PullRenderData(int bits_per_sample, 107 void AudioTransportProxy::PullRenderData(int bits_per_sample,
78 int sample_rate, 108 int sample_rate,
79 size_t number_of_channels, 109 size_t number_of_channels,
80 size_t number_of_frames, 110 size_t number_of_frames,
81 void* audio_data, 111 void* audio_data,
82 int64_t* elapsed_time_ms, 112 int64_t* elapsed_time_ms,
83 int64_t* ntp_time_ms) { 113 int64_t* ntp_time_ms) {
84 RTC_DCHECK_EQ(static_cast<size_t>(bits_per_sample), 8 * sizeof(int16_t)); 114 // 8 * 2 = bits per byte * bytes in sample.
the sun 2016/11/16 20:22:57 Sorry for not being clear. I thought you could jus
aleloi 2016/11/17 18:12:26 Ah, of course...
115 RTC_DCHECK_EQ(static_cast<size_t>(bits_per_sample), 8 * 2);
85 RTC_DCHECK_GE(number_of_channels, 1u); 116 RTC_DCHECK_GE(number_of_channels, 1u);
86 RTC_DCHECK_LE(number_of_channels, 2u); 117 RTC_DCHECK_LE(number_of_channels, 2u);
87 RTC_DCHECK_GE(static_cast<int>(sample_rate), 118 RTC_DCHECK_GE(static_cast<int>(sample_rate),
88 AudioProcessing::NativeRate::kSampleRate8kHz); 119 AudioProcessing::NativeRate::kSampleRate8kHz);
120
121 // 100 = 1 second / data duration.
the sun 2016/11/16 20:22:57 1 s / 10 ms ?
aleloi 2016/11/17 18:12:26 Acknowledged.
89 RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate); 122 RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate);
123
124 // 8 = bits per byte.
90 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, 125 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels,
91 sizeof(AudioFrame::data_)); 126 sizeof(AudioFrame::data_));
92 voe_audio_transport_->PullRenderData( 127 mixer_->Mix(number_of_channels, &mixed_frame_);
93 bits_per_sample, sample_rate, number_of_channels, number_of_frames, 128 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_;
94 audio_data, elapsed_time_ms, ntp_time_ms); 129 *ntp_time_ms = mixed_frame_.ntp_time_ms_;
130
131 const auto output_samples = Resample(mixed_frame_, sample_rate, &resampler_,
132 static_cast<int16_t*>(audio_data));
133 RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames);
95 } 134 }
96 135
97 } // namespace webrtc 136 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698