Adds "tts" permission for Input Tools & XKB extension.
[chromium-blink-merge.git] / media / audio / android / audio_record_input.h
blobf3ef519ed0af4d1ff7058cd2a3564bb7e96124d5
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 #ifndef MEDIA_AUDIO_ANDROID_AUDIO_RECORD_INPUT_H_
6 #define MEDIA_AUDIO_ANDROID_AUDIO_RECORD_INPUT_H_
8 #include "base/android/jni_android.h"
9 #include "base/threading/thread_checker.h"
10 #include "media/audio/audio_io.h"
11 #include "media/audio/audio_parameters.h"
13 namespace media {
15 class AudioBus;
16 class AudioManagerAndroid;
18 // Implements PCM audio input support for Android using the Java AudioRecord
19 // interface. Most of the work is done by its Java counterpart in
20 // AudioRecordInput.java. This class is created and lives on the Audio Manager
21 // thread but recorded audio buffers are delivered on a thread managed by
22 // the Java class.
24 // The Java class makes use of AudioEffect features which are first available
25 // in Jelly Bean. It should not be instantiated running against earlier SDKs.
26 class MEDIA_EXPORT AudioRecordInputStream : public AudioInputStream {
27 public:
28 AudioRecordInputStream(AudioManagerAndroid* manager,
29 const AudioParameters& params);
31 virtual ~AudioRecordInputStream();
33 // Implementation of AudioInputStream.
34 virtual bool Open() override;
35 virtual void Start(AudioInputCallback* callback) override;
36 virtual void Stop() override;
37 virtual void Close() override;
38 virtual double GetMaxVolume() override;
39 virtual void SetVolume(double volume) override;
40 virtual double GetVolume() override;
41 virtual bool SetAutomaticGainControl(bool enabled) override;
42 virtual bool GetAutomaticGainControl() override;
43 virtual bool IsMuted() override;
45 static bool RegisterAudioRecordInput(JNIEnv* env);
47 // Called from Java when data is available.
48 void OnData(JNIEnv* env, jobject obj, jint size, jint hardware_delay_bytes);
50 // Called from Java so that we can cache the address of the Java-managed
51 // |byte_buffer| in |direct_buffer_address_|.
52 void CacheDirectBufferAddress(JNIEnv* env, jobject obj, jobject byte_buffer);
54 private:
55 base::ThreadChecker thread_checker_;
56 AudioManagerAndroid* audio_manager_;
58 // Java AudioRecordInput instance.
59 base::android::ScopedJavaGlobalRef<jobject> j_audio_record_;
61 // This is the only member accessed by both the Audio Manager and Java
62 // threads. Explanations for why we do not require explicit synchronization
63 // are given in the implementation.
64 AudioInputCallback* callback_;
66 // Owned by j_audio_record_.
67 uint8* direct_buffer_address_;
69 scoped_ptr<media::AudioBus> audio_bus_;
70 int bytes_per_sample_;
72 DISALLOW_COPY_AND_ASSIGN(AudioRecordInputStream);
75 } // namespace media
77 #endif // MEDIA_AUDIO_ANDROID_AUDIO_RECORD_INPUT_H_