OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/audio/android/audio_record_input.h" | 5 #include "media/audio/android/audio_record_input.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "jni/AudioRecordInput_jni.h" | 8 #include "jni/AudioRecordInput_jni.h" |
9 #include "media/audio/android/audio_manager_android.h" | 9 #include "media/audio/android/audio_manager_android.h" |
| 10 #include "media/base/audio_bus.h" |
10 | 11 |
11 namespace media { | 12 namespace media { |
12 | 13 |
13 AudioRecordInputStream::AudioRecordInputStream( | 14 AudioRecordInputStream::AudioRecordInputStream( |
14 AudioManagerAndroid* audio_manager, const AudioParameters& params) | 15 AudioManagerAndroid* audio_manager, |
| 16 const AudioParameters& params) |
15 : audio_manager_(audio_manager), | 17 : audio_manager_(audio_manager), |
16 callback_(NULL), | 18 callback_(NULL), |
17 direct_buffer_address_(NULL) { | 19 direct_buffer_address_(NULL), |
| 20 audio_bus_(media::AudioBus::Create(params)), |
| 21 bytes_per_sample_(params.bits_per_sample() / 8) { |
18 DVLOG(2) << __PRETTY_FUNCTION__; | 22 DVLOG(2) << __PRETTY_FUNCTION__; |
19 DCHECK(params.IsValid()); | 23 DCHECK(params.IsValid()); |
20 j_audio_record_.Reset( | 24 j_audio_record_.Reset( |
21 Java_AudioRecordInput_createAudioRecordInput( | 25 Java_AudioRecordInput_createAudioRecordInput( |
22 base::android::AttachCurrentThread(), | 26 base::android::AttachCurrentThread(), |
23 reinterpret_cast<intptr_t>(this), | 27 reinterpret_cast<intptr_t>(this), |
24 params.sample_rate(), | 28 params.sample_rate(), |
25 params.channels(), | 29 params.channels(), |
26 params.bits_per_sample(), | 30 params.bits_per_sample(), |
27 params.GetBytesPerBuffer(), | 31 params.GetBytesPerBuffer(), |
(...skipping 13 matching lines...) Expand all Loading... |
41 } | 45 } |
42 | 46 |
43 // static | 47 // static |
44 bool AudioRecordInputStream::RegisterAudioRecordInput(JNIEnv* env) { | 48 bool AudioRecordInputStream::RegisterAudioRecordInput(JNIEnv* env) { |
45 return RegisterNativesImpl(env); | 49 return RegisterNativesImpl(env); |
46 } | 50 } |
47 | 51 |
48 void AudioRecordInputStream::OnData(JNIEnv* env, jobject obj, jint size, | 52 void AudioRecordInputStream::OnData(JNIEnv* env, jobject obj, jint size, |
49 jint hardware_delay_bytes) { | 53 jint hardware_delay_bytes) { |
50 DCHECK(direct_buffer_address_); | 54 DCHECK(direct_buffer_address_); |
| 55 DCHECK_EQ(size, |
| 56 audio_bus_->frames() * audio_bus_->channels() * bytes_per_sample_); |
51 // Passing zero as the volume parameter indicates there is no access to a | 57 // Passing zero as the volume parameter indicates there is no access to a |
52 // hardware volume slider. | 58 // hardware volume slider. |
53 callback_->OnData(this, direct_buffer_address_, size, hardware_delay_bytes, | 59 audio_bus_->FromInterleaved( |
54 0.0); | 60 direct_buffer_address_, audio_bus_->frames(), bytes_per_sample_); |
| 61 callback_->OnData(this, audio_bus_.get(), hardware_delay_bytes, 0.0); |
55 } | 62 } |
56 | 63 |
57 bool AudioRecordInputStream::Open() { | 64 bool AudioRecordInputStream::Open() { |
58 DVLOG(2) << __PRETTY_FUNCTION__; | 65 DVLOG(2) << __PRETTY_FUNCTION__; |
59 DCHECK(thread_checker_.CalledOnValidThread()); | 66 DCHECK(thread_checker_.CalledOnValidThread()); |
60 return Java_AudioRecordInput_open( | 67 return Java_AudioRecordInput_open( |
61 base::android::AttachCurrentThread(), j_audio_record_.obj()); | 68 base::android::AttachCurrentThread(), j_audio_record_.obj()); |
62 } | 69 } |
63 | 70 |
64 void AudioRecordInputStream::Start(AudioInputCallback* callback) { | 71 void AudioRecordInputStream::Start(AudioInputCallback* callback) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 void AudioRecordInputStream::SetAutomaticGainControl(bool enabled) { | 128 void AudioRecordInputStream::SetAutomaticGainControl(bool enabled) { |
122 NOTIMPLEMENTED(); | 129 NOTIMPLEMENTED(); |
123 } | 130 } |
124 | 131 |
125 bool AudioRecordInputStream::GetAutomaticGainControl() { | 132 bool AudioRecordInputStream::GetAutomaticGainControl() { |
126 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
127 return false; | 134 return false; |
128 } | 135 } |
129 | 136 |
130 } // namespace media | 137 } // namespace media |
OLD | NEW |