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

Unified Diff: media/audio/android/opensles_input.h

Issue 9655023: Adding input and output audio backend to Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased && addressed qinmin's comments Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/android/opensles_input.h
diff --git a/media/audio/android/opensles_input.h b/media/audio/android/opensles_input.h
new file mode 100644
index 0000000000000000000000000000000000000000..29dd2c09f2ecb5a13c36ecc67ba0faa658c389c9
--- /dev/null
+++ b/media/audio/android/opensles_input.h
@@ -0,0 +1,76 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_
+#define MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_
+
+#include "base/compiler_specific.h"
+#include "media/audio/audio_io.h"
+#include "media/audio/audio_parameters.h"
+#include "media/audio/android/opensles_util.h"
+#include <SLES/OpenSLES_Android.h>
+
+class AudioManagerAndroid;
+
+// Implements PCM audio input support for Android using the OpenSLES API.
+class OpenSLESInputStream : public AudioInputStream {
+ public:
+ static const int kNumOfQueuesInBuffer = 2;
+
+ OpenSLESInputStream(AudioManagerAndroid* manager,
+ const AudioParameters& params);
+
+ virtual ~OpenSLESInputStream();
+
+ // Implementation of AudioInputStream.
+ virtual bool Open() OVERRIDE;
+ virtual void Start(AudioInputCallback* callback) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual double GetMaxVolume() OVERRIDE;
+ virtual void SetVolume(double volume) OVERRIDE;
+ virtual double GetVolume() OVERRIDE;
+ virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
+ virtual bool GetAutomaticGainControl() OVERRIDE;
+
+ private:
+ bool CreateRecorder();
+
+ static void SimpleBufferQueueCallback(
+ SLAndroidSimpleBufferQueueItf buffer_queue, void* instance);
+
+ void ReadBufferQueue();
+
+ // If OpenSLES reports an error this function handles it and passes it to
+ // the attached AudioInputCallback::OnError().
+ void HandleError(SLresult error);
+
+ AudioManagerAndroid* audio_manager_;
+
+ AudioInputCallback* callback_;
+
+ // Shared engine interfaces for the app.
+ media::ScopedSLObjectItf recorder_object_;
+ media::ScopedSLObjectItf engine_object_;
+
+ SLRecordItf recorder_;
+
+ // Buffer queue recorder interface.
+ SLAndroidSimpleBufferQueueItf simple_buffer_queue_;
+
+ SLDataFormat_PCM format_;
+
+ // Audio buffers that are allocated in the constructor based on
+ // info from audio parameters.
+ uint8* audio_data_[kNumOfQueuesInBuffer];
+
+ int active_queue_;
+ int buffer_size_bytes_;
+
+ bool started_;
+
+ DISALLOW_COPY_AND_ASSIGN(OpenSLESInputStream);
+};
+
+#endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_

Powered by Google App Engine
This is Rietveld 408576698