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