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

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

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Update new usages of AudioFrame::data_ Created 3 years, 6 months 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 | « no previous file | webrtc/audio/utility/audio_frame_operations.cc » ('j') | 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 { 15 namespace {
16 // Resample audio in |frame| to given sample rate preserving the 16 // Resample audio in |frame| to given sample rate preserving the
17 // channel count and place the result in |destination|. 17 // channel count and place the result in |destination|.
18 int Resample(const AudioFrame& frame, 18 int Resample(const AudioFrame& frame,
19 const int destination_sample_rate, 19 const int destination_sample_rate,
20 PushResampler<int16_t>* resampler, 20 PushResampler<int16_t>* resampler,
21 int16_t* destination) { 21 int16_t* destination) {
22 const int number_of_channels = static_cast<int>(frame.num_channels_); 22 const int number_of_channels = static_cast<int>(frame.num_channels_);
23 const int target_number_of_samples_per_channel = 23 const int target_number_of_samples_per_channel =
24 destination_sample_rate / 100; 24 destination_sample_rate / 100;
25 resampler->InitializeIfNeeded(frame.sample_rate_hz_, destination_sample_rate, 25 resampler->InitializeIfNeeded(frame.sample_rate_hz_, destination_sample_rate,
26 number_of_channels); 26 number_of_channels);
27 27
28 // TODO(yujo): make resampler take an AudioFrame, and add special case
29 // handling of muted frames.
28 return resampler->Resample( 30 return resampler->Resample(
29 frame.data_, frame.samples_per_channel_ * number_of_channels, destination, 31 frame.data(), frame.samples_per_channel_ * number_of_channels,
30 number_of_channels * target_number_of_samples_per_channel); 32 destination, number_of_channels * target_number_of_samples_per_channel);
31 } 33 }
32 } // namespace 34 } // namespace
33 35
34 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, 36 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport,
35 AudioProcessing* apm, 37 AudioProcessing* apm,
36 AudioMixer* mixer) 38 AudioMixer* mixer)
37 : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) { 39 : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) {
38 RTC_DCHECK(voe_audio_transport); 40 RTC_DCHECK(voe_audio_transport);
39 RTC_DCHECK(apm); 41 RTC_DCHECK(apm);
40 RTC_DCHECK(mixer); 42 RTC_DCHECK(mixer);
(...skipping 29 matching lines...) Expand all
70 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample); 72 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample);
71 RTC_DCHECK_GE(nChannels, 1); 73 RTC_DCHECK_GE(nChannels, 1);
72 RTC_DCHECK_LE(nChannels, 2); 74 RTC_DCHECK_LE(nChannels, 2);
73 RTC_DCHECK_GE( 75 RTC_DCHECK_GE(
74 samplesPerSec, 76 samplesPerSec,
75 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz)); 77 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz));
76 78
77 // 100 = 1 second / data duration (10 ms). 79 // 100 = 1 second / data duration (10 ms).
78 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); 80 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec);
79 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, 81 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels,
80 sizeof(AudioFrame::data_)); 82 AudioFrame::kMaxDataSizeBytes);
81 83
82 mixer_->Mix(nChannels, &mixed_frame_); 84 mixer_->Mix(nChannels, &mixed_frame_);
83 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_; 85 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_;
84 *ntp_time_ms = mixed_frame_.ntp_time_ms_; 86 *ntp_time_ms = mixed_frame_.ntp_time_ms_;
85 87
86 const auto error = apm_->ProcessReverseStream(&mixed_frame_); 88 const auto error = apm_->ProcessReverseStream(&mixed_frame_);
87 RTC_DCHECK_EQ(error, AudioProcessing::kNoError); 89 RTC_DCHECK_EQ(error, AudioProcessing::kNoError);
88 90
89 nSamplesOut = Resample(mixed_frame_, samplesPerSec, &resampler_, 91 nSamplesOut = Resample(mixed_frame_, samplesPerSec, &resampler_,
90 static_cast<int16_t*>(audioSamples)); 92 static_cast<int16_t*>(audioSamples));
(...skipping 22 matching lines...) Expand all
113 RTC_DCHECK_EQ(bits_per_sample, 16); 115 RTC_DCHECK_EQ(bits_per_sample, 16);
114 RTC_DCHECK_GE(number_of_channels, 1); 116 RTC_DCHECK_GE(number_of_channels, 1);
115 RTC_DCHECK_LE(number_of_channels, 2); 117 RTC_DCHECK_LE(number_of_channels, 2);
116 RTC_DCHECK_GE(sample_rate, AudioProcessing::NativeRate::kSampleRate8kHz); 118 RTC_DCHECK_GE(sample_rate, AudioProcessing::NativeRate::kSampleRate8kHz);
117 119
118 // 100 = 1 second / data duration (10 ms). 120 // 100 = 1 second / data duration (10 ms).
119 RTC_DCHECK_EQ(number_of_frames * 100, sample_rate); 121 RTC_DCHECK_EQ(number_of_frames * 100, sample_rate);
120 122
121 // 8 = bits per byte. 123 // 8 = bits per byte.
122 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, 124 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels,
123 sizeof(AudioFrame::data_)); 125 AudioFrame::kMaxDataSizeBytes);
124 mixer_->Mix(number_of_channels, &mixed_frame_); 126 mixer_->Mix(number_of_channels, &mixed_frame_);
125 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_; 127 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_;
126 *ntp_time_ms = mixed_frame_.ntp_time_ms_; 128 *ntp_time_ms = mixed_frame_.ntp_time_ms_;
127 129
128 const auto output_samples = Resample(mixed_frame_, sample_rate, &resampler_, 130 const auto output_samples = Resample(mixed_frame_, sample_rate, &resampler_,
129 static_cast<int16_t*>(audio_data)); 131 static_cast<int16_t*>(audio_data));
130 RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames); 132 RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames);
131 } 133 }
132 134
133 } // namespace webrtc 135 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/audio/utility/audio_frame_operations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698