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 |
(...skipping 48 matching lines...) Loading... |
59 MediaCallback(AgcManagerDirect* direct, AudioProcessing* audioproc, | 59 MediaCallback(AgcManagerDirect* direct, AudioProcessing* audioproc, |
60 CriticalSectionWrapper* crit) | 60 CriticalSectionWrapper* crit) |
61 : direct_(direct), | 61 : direct_(direct), |
62 audioproc_(audioproc), | 62 audioproc_(audioproc), |
63 crit_(crit), | 63 crit_(crit), |
64 frame_() { | 64 frame_() { |
65 } | 65 } |
66 | 66 |
67 protected: | 67 protected: |
68 virtual void Process(const int channel, const ProcessingTypes type, | 68 virtual void Process(const int channel, const ProcessingTypes type, |
69 int16_t audio[], const int samples_per_channel, | 69 int16_t audio[], const size_t samples_per_channel, |
70 const int sample_rate_hz, const bool is_stereo) { | 70 const int sample_rate_hz, const bool is_stereo) { |
71 CriticalSectionScoped cs(crit_); | 71 CriticalSectionScoped cs(crit_); |
72 if (direct_->capture_muted()) { | 72 if (direct_->capture_muted()) { |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 // Extract the first channel. | 76 // Extract the first channel. |
77 const int kMaxSampleRateHz = 48000; | 77 const int kMaxSampleRateHz = 48000; |
78 const int kMaxSamplesPerChannel = kMaxSampleRateHz / 100; | 78 const int kMaxSamplesPerChannel = kMaxSampleRateHz / 100; |
79 assert(samples_per_channel < kMaxSamplesPerChannel && | 79 assert(samples_per_channel < kMaxSamplesPerChannel && |
80 sample_rate_hz < kMaxSampleRateHz); | 80 sample_rate_hz < kMaxSampleRateHz); |
81 int16_t mono[kMaxSamplesPerChannel]; | 81 int16_t mono[kMaxSamplesPerChannel]; |
82 int16_t* mono_ptr = audio; | 82 int16_t* mono_ptr = audio; |
83 if (is_stereo) { | 83 if (is_stereo) { |
84 for (int n = 0; n < samples_per_channel; n++) { | 84 for (size_t n = 0; n < samples_per_channel; n++) { |
85 mono[n] = audio[n * 2]; | 85 mono[n] = audio[n * 2]; |
86 } | 86 } |
87 mono_ptr = mono; | 87 mono_ptr = mono; |
88 } | 88 } |
89 | 89 |
90 direct_->Process(mono_ptr, samples_per_channel, sample_rate_hz); | 90 direct_->Process(mono_ptr, samples_per_channel, sample_rate_hz); |
91 | 91 |
92 // TODO(ajm): It's unfortunate we have to memcpy to this frame here, but | 92 // TODO(ajm): It's unfortunate we have to memcpy to this frame here, but |
93 // it's needed for use with AudioProcessing. | 93 // it's needed for use with AudioProcessing. |
94 frame_.num_channels_ = is_stereo ? 2 : 1; | 94 frame_.num_channels_ = is_stereo ? 2 : 1; |
95 frame_.samples_per_channel_ = samples_per_channel; | 95 frame_.samples_per_channel_ = samples_per_channel; |
96 frame_.sample_rate_hz_ = sample_rate_hz; | 96 frame_.sample_rate_hz_ = sample_rate_hz; |
97 const int length_samples = frame_.num_channels_ * samples_per_channel; | 97 const size_t length_samples = frame_.num_channels_ * samples_per_channel; |
98 memcpy(frame_.data_, audio, length_samples * sizeof(int16_t)); | 98 memcpy(frame_.data_, audio, length_samples * sizeof(int16_t)); |
99 | 99 |
100 // Apply compression to the audio. | 100 // Apply compression to the audio. |
101 if (audioproc_->ProcessStream(&frame_) != 0) { | 101 if (audioproc_->ProcessStream(&frame_) != 0) { |
102 LOG_FERR0(LS_ERROR, ProcessStream); | 102 LOG_FERR0(LS_ERROR, ProcessStream); |
103 } | 103 } |
104 | 104 |
105 // Copy the compressed audio back to voice engine's array. | 105 // Copy the compressed audio back to voice engine's array. |
106 memcpy(audio, frame_.data_, length_samples * sizeof(int16_t)); | 106 memcpy(audio, frame_.data_, length_samples * sizeof(int16_t)); |
107 } | 107 } |
108 | 108 |
109 private: | 109 private: |
110 AgcManagerDirect* direct_; | 110 AgcManagerDirect* direct_; |
111 AudioProcessing* audioproc_; | 111 AudioProcessing* audioproc_; |
112 CriticalSectionWrapper* crit_; | 112 CriticalSectionWrapper* crit_; |
113 AudioFrame frame_; | 113 AudioFrame frame_; |
114 }; | 114 }; |
115 | 115 |
116 class PreprocCallback : public VoEMediaProcess { | 116 class PreprocCallback : public VoEMediaProcess { |
117 public: | 117 public: |
118 PreprocCallback(AgcManagerDirect* direct, CriticalSectionWrapper* crit) | 118 PreprocCallback(AgcManagerDirect* direct, CriticalSectionWrapper* crit) |
119 : direct_(direct), | 119 : direct_(direct), |
120 crit_(crit) { | 120 crit_(crit) { |
121 } | 121 } |
122 | 122 |
123 protected: | 123 protected: |
124 virtual void Process(const int channel, const ProcessingTypes type, | 124 virtual void Process(const int channel, const ProcessingTypes type, |
125 int16_t audio[], const int samples_per_channel, | 125 int16_t audio[], const size_t samples_per_channel, |
126 const int sample_rate_hz, const bool is_stereo) { | 126 const int sample_rate_hz, const bool is_stereo) { |
127 CriticalSectionScoped cs(crit_); | 127 CriticalSectionScoped cs(crit_); |
128 if (direct_->capture_muted()) { | 128 if (direct_->capture_muted()) { |
129 return; | 129 return; |
130 } | 130 } |
131 direct_->AnalyzePreProcess(audio, is_stereo ? 2 : 1, samples_per_channel); | 131 direct_->AnalyzePreProcess(audio, is_stereo ? 2 : 1, samples_per_channel); |
132 } | 132 } |
133 | 133 |
134 private: | 134 private: |
135 AgcManagerDirect* direct_; | 135 AgcManagerDirect* direct_; |
(...skipping 110 matching lines...) Loading... |
246 } | 246 } |
247 if (media_->DeRegisterExternalMediaProcessing(0, | 247 if (media_->DeRegisterExternalMediaProcessing(0, |
248 kRecordingPreprocessing) != 0) { | 248 kRecordingPreprocessing) != 0) { |
249 LOG(LS_ERROR) << "Failed to deregister preproc callback"; | 249 LOG(LS_ERROR) << "Failed to deregister preproc callback"; |
250 err = -1; | 250 err = -1; |
251 } | 251 } |
252 return err; | 252 return err; |
253 } | 253 } |
254 | 254 |
255 } // namespace webrtc | 255 } // namespace webrtc |
OLD | NEW |