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

Side by Side Diff: webrtc/modules/audio_device/android/opensles_player.cc

Issue 1305983003: Convert some more things to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Support Android's C89 mode Created 5 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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/modules/audio_device/android/opensles_player.h" 11 #include "webrtc/modules/audio_device/android/opensles_player.h"
12 12
13 #include <android/log.h> 13 #include <android/log.h>
14 14
15 #include "webrtc/base/arraysize.h" 15 #include "webrtc/base/arraysize.h"
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/format_macros.h"
17 #include "webrtc/modules/audio_device/android/audio_manager.h" 18 #include "webrtc/modules/audio_device/android/audio_manager.h"
18 #include "webrtc/modules/audio_device/android/fine_audio_buffer.h" 19 #include "webrtc/modules/audio_device/android/fine_audio_buffer.h"
19 20
20 #define TAG "OpenSLESPlayer" 21 #define TAG "OpenSLESPlayer"
21 #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__) 22 #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
22 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) 23 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
23 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) 24 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
24 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__) 25 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
25 #define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) 26 #define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
26 27
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 const int sample_rate_hz = audio_parameters_.sample_rate(); 176 const int sample_rate_hz = audio_parameters_.sample_rate();
176 ALOGD("SetPlayoutSampleRate(%d)", sample_rate_hz); 177 ALOGD("SetPlayoutSampleRate(%d)", sample_rate_hz);
177 audio_device_buffer_->SetPlayoutSampleRate(sample_rate_hz); 178 audio_device_buffer_->SetPlayoutSampleRate(sample_rate_hz);
178 const int channels = audio_parameters_.channels(); 179 const int channels = audio_parameters_.channels();
179 ALOGD("SetPlayoutChannels(%d)", channels); 180 ALOGD("SetPlayoutChannels(%d)", channels);
180 audio_device_buffer_->SetPlayoutChannels(channels); 181 audio_device_buffer_->SetPlayoutChannels(channels);
181 CHECK(audio_device_buffer_); 182 CHECK(audio_device_buffer_);
182 AllocateDataBuffers(); 183 AllocateDataBuffers();
183 } 184 }
184 185
185 SLDataFormat_PCM OpenSLESPlayer::CreatePCMConfiguration(int channels, 186 SLDataFormat_PCM OpenSLESPlayer::CreatePCMConfiguration(
186 int sample_rate, 187 int channels,
187 int bits_per_sample) { 188 int sample_rate,
189 size_t bits_per_sample) {
188 ALOGD("CreatePCMConfiguration"); 190 ALOGD("CreatePCMConfiguration");
189 CHECK_EQ(bits_per_sample, SL_PCMSAMPLEFORMAT_FIXED_16); 191 CHECK_EQ(bits_per_sample, SL_PCMSAMPLEFORMAT_FIXED_16);
190 SLDataFormat_PCM format; 192 SLDataFormat_PCM format;
191 format.formatType = SL_DATAFORMAT_PCM; 193 format.formatType = SL_DATAFORMAT_PCM;
192 format.numChannels = static_cast<SLuint32>(channels); 194 format.numChannels = static_cast<SLuint32>(channels);
193 // Note that, the unit of sample rate is actually in milliHertz and not Hertz. 195 // Note that, the unit of sample rate is actually in milliHertz and not Hertz.
194 switch (sample_rate) { 196 switch (sample_rate) {
195 case 8000: 197 case 8000:
196 format.samplesPerSec = SL_SAMPLINGRATE_8; 198 format.samplesPerSec = SL_SAMPLINGRATE_8;
197 break; 199 break;
(...skipping 26 matching lines...) Expand all
224 CHECK(false) << "Unsupported number of channels: " << format.numChannels; 226 CHECK(false) << "Unsupported number of channels: " << format.numChannels;
225 return format; 227 return format;
226 } 228 }
227 229
228 void OpenSLESPlayer::AllocateDataBuffers() { 230 void OpenSLESPlayer::AllocateDataBuffers() {
229 ALOGD("AllocateDataBuffers"); 231 ALOGD("AllocateDataBuffers");
230 DCHECK(thread_checker_.CalledOnValidThread()); 232 DCHECK(thread_checker_.CalledOnValidThread());
231 DCHECK(!simple_buffer_queue_); 233 DCHECK(!simple_buffer_queue_);
232 CHECK(audio_device_buffer_); 234 CHECK(audio_device_buffer_);
233 bytes_per_buffer_ = audio_parameters_.GetBytesPerBuffer(); 235 bytes_per_buffer_ = audio_parameters_.GetBytesPerBuffer();
234 ALOGD("native buffer size: %d", bytes_per_buffer_); 236 ALOGD("native buffer size: %" PRIuS, bytes_per_buffer_);
235 // Create a modified audio buffer class which allows us to ask for any number 237 // Create a modified audio buffer class which allows us to ask for any number
236 // of samples (and not only multiple of 10ms) to match the native OpenSL ES 238 // of samples (and not only multiple of 10ms) to match the native OpenSL ES
237 // buffer size. 239 // buffer size.
238 fine_buffer_.reset(new FineAudioBuffer(audio_device_buffer_, 240 fine_buffer_.reset(new FineAudioBuffer(audio_device_buffer_,
239 bytes_per_buffer_, 241 bytes_per_buffer_,
240 audio_parameters_.sample_rate())); 242 audio_parameters_.sample_rate()));
241 // Each buffer must be of this size to avoid unnecessary memcpy while caching 243 // Each buffer must be of this size to avoid unnecessary memcpy while caching
242 // data between successive callbacks. 244 // data between successive callbacks.
243 const int required_buffer_size = fine_buffer_->RequiredBufferSizeBytes(); 245 const size_t required_buffer_size = fine_buffer_->RequiredBufferSizeBytes();
244 ALOGD("required buffer size: %d", required_buffer_size); 246 ALOGD("required buffer size: %" PRIuS, required_buffer_size);
245 for (int i = 0; i < kNumOfOpenSLESBuffers; ++i) { 247 for (int i = 0; i < kNumOfOpenSLESBuffers; ++i) {
246 audio_buffers_[i].reset(new SLint8[required_buffer_size]); 248 audio_buffers_[i].reset(new SLint8[required_buffer_size]);
247 } 249 }
248 } 250 }
249 251
250 bool OpenSLESPlayer::CreateEngine() { 252 bool OpenSLESPlayer::CreateEngine() {
251 ALOGD("CreateEngine"); 253 ALOGD("CreateEngine");
252 DCHECK(thread_checker_.CalledOnValidThread()); 254 DCHECK(thread_checker_.CalledOnValidThread());
253 if (engine_object_.Get()) 255 if (engine_object_.Get())
254 return true; 256 return true;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 DCHECK(player_); 435 DCHECK(player_);
434 SLuint32 state; 436 SLuint32 state;
435 SLresult err = (*player_)->GetPlayState(player_, &state); 437 SLresult err = (*player_)->GetPlayState(player_, &state);
436 if (SL_RESULT_SUCCESS != err) { 438 if (SL_RESULT_SUCCESS != err) {
437 ALOGE("GetPlayState failed: %d", err); 439 ALOGE("GetPlayState failed: %d", err);
438 } 440 }
439 return state; 441 return state;
440 } 442 }
441 443
442 } // namespace webrtc 444 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/android/opensles_player.h ('k') | webrtc/modules/audio_device/include/audio_device_defines.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698