Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / media / audio / android / audio_record_input.cc
blob583239d6502fa9ab41221b9d7c89ddebe305d8ed
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
3 // found in the LICENSE file.
5 #include "media/audio/android/audio_record_input.h"
7 #include "base/logging.h"
8 #include "jni/AudioRecordInput_jni.h"
9 #include "media/audio/android/audio_manager_android.h"
11 namespace media {
13 AudioRecordInputStream::AudioRecordInputStream(
14 AudioManagerAndroid* audio_manager, const AudioParameters& params)
15 : audio_manager_(audio_manager),
16 callback_(NULL),
17 direct_buffer_address_(NULL) {
18 DVLOG(2) << __PRETTY_FUNCTION__;
19 DCHECK(params.IsValid());
20 j_audio_record_.Reset(
21 Java_AudioRecordInput_createAudioRecordInput(
22 base::android::AttachCurrentThread(),
23 reinterpret_cast<intptr_t>(this),
24 params.sample_rate(),
25 params.channels(),
26 params.bits_per_sample(),
27 params.GetBytesPerBuffer(),
28 params.effects() & AudioParameters::ECHO_CANCELLER));
31 AudioRecordInputStream::~AudioRecordInputStream() {
32 DVLOG(2) << __PRETTY_FUNCTION__;
33 DCHECK(thread_checker_.CalledOnValidThread());
36 void AudioRecordInputStream::CacheDirectBufferAddress(JNIEnv* env, jobject obj,
37 jobject byte_buffer) {
38 DCHECK(thread_checker_.CalledOnValidThread());
39 direct_buffer_address_ = static_cast<uint8*>(
40 env->GetDirectBufferAddress(byte_buffer));
43 // static
44 bool AudioRecordInputStream::RegisterAudioRecordInput(JNIEnv* env) {
45 return RegisterNativesImpl(env);
48 void AudioRecordInputStream::OnData(JNIEnv* env, jobject obj, jint size,
49 jint hardware_delay_bytes) {
50 DCHECK(direct_buffer_address_);
51 // Passing zero as the volume parameter indicates there is no access to a
52 // hardware volume slider.
53 callback_->OnData(this, direct_buffer_address_, size, hardware_delay_bytes,
54 0.0);
57 bool AudioRecordInputStream::Open() {
58 DVLOG(2) << __PRETTY_FUNCTION__;
59 DCHECK(thread_checker_.CalledOnValidThread());
60 return Java_AudioRecordInput_open(
61 base::android::AttachCurrentThread(), j_audio_record_.obj());
64 void AudioRecordInputStream::Start(AudioInputCallback* callback) {
65 DVLOG(2) << __PRETTY_FUNCTION__;
66 DCHECK(thread_checker_.CalledOnValidThread());
67 DCHECK(callback);
69 if (callback_) {
70 // Start() was already called.
71 DCHECK_EQ(callback_, callback);
72 return;
74 // The Java thread has not yet started, so we are free to set |callback_|.
75 callback_ = callback;
77 Java_AudioRecordInput_start(
78 base::android::AttachCurrentThread(), j_audio_record_.obj());
81 void AudioRecordInputStream::Stop() {
82 DVLOG(2) << __PRETTY_FUNCTION__;
83 DCHECK(thread_checker_.CalledOnValidThread());
84 if (!callback_) {
85 // Start() was never called, or Stop() was already called.
86 return;
89 Java_AudioRecordInput_stop(
90 base::android::AttachCurrentThread(), j_audio_record_.obj());
92 // The Java thread must have been stopped at this point, so we are free to
93 // clear |callback_|.
94 callback_ = NULL;
97 void AudioRecordInputStream::Close() {
98 DVLOG(2) << __PRETTY_FUNCTION__;
99 DCHECK(thread_checker_.CalledOnValidThread());
100 Stop();
101 DCHECK(!callback_);
102 Java_AudioRecordInput_close(
103 base::android::AttachCurrentThread(), j_audio_record_.obj());
104 audio_manager_->ReleaseInputStream(this);
107 double AudioRecordInputStream::GetMaxVolume() {
108 NOTIMPLEMENTED();
109 return 0.0;
112 void AudioRecordInputStream::SetVolume(double volume) {
113 NOTIMPLEMENTED();
116 double AudioRecordInputStream::GetVolume() {
117 NOTIMPLEMENTED();
118 return 0.0;
121 void AudioRecordInputStream::SetAutomaticGainControl(bool enabled) {
122 NOTIMPLEMENTED();
125 bool AudioRecordInputStream::GetAutomaticGainControl() {
126 NOTIMPLEMENTED();
127 return false;
130 } // namespace media