Index: media/audio/android/audio_track_output_android.h |
diff --git a/media/audio/android/audio_track_output_android.h b/media/audio/android/audio_track_output_android.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cca446f09634f2180f90146608ce25f910e3631a |
--- /dev/null |
+++ b/media/audio/android/audio_track_output_android.h |
@@ -0,0 +1,98 @@ |
+// Copyright (c) 2011 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_AUDIO_TRACK_OUTPUT_ANDROID_H_ |
+#define MEDIA_AUDIO_AUDIO_TRACK_OUTPUT_ANDROID_H_ |
+ |
+#include <jni.h> |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/timer.h" |
+#include "media/audio/audio_io.h" |
+#include "media/audio/audio_parameters.h" |
+ |
+class AudioManagerAndroid; |
+ |
+// Implements PCM audio output support for Android using the AudioTrack API. |
+class AudioTrackOutputStream : public AudioOutputStream { |
+ public: |
+ enum Status { |
+ IDLE, |
+ OPENED, |
+ PLAYING, |
+ INVALID |
+ }; |
+ |
+ class StreamBuffer { |
scherkus (not reviewing)
2011/11/29 20:00:28
nit: forward declare this class before where you u
michaelbai
2011/11/30 17:20:34
As it is used with scoped_ptr<>, forward declare w
scherkus (not reviewing)
2011/12/01 17:24:13
scoped_ptr<> only needs the full definition of the
michaelbai
2011/12/01 18:58:06
Great! It worked, don't know what happen last time
|
+ public: |
+ explicit StreamBuffer(uint32 buffer_size); |
+ |
+ uint32 ReadStream(uint8* dest, uint32 max_size); |
+ void ResetBuffer(uint32 data_size); |
+ uint8* GetWritableBuffer(); |
+ const uint8* ReadBuffer(); |
+ void AdvancePosition(uint32 advance); |
+ |
+ uint32 buffer_size() { return buffer_size_; } |
+ uint32 data_len() { return data_size_ - current_; } |
+ |
+ private: |
+ scoped_array<uint8> buffer_; |
+ uint32 buffer_size_; |
+ uint32 data_size_; |
+ uint32 current_; |
+ }; |
+ |
+ AudioTrackOutputStream(AudioManagerAndroid* manager, |
+ const AudioParameters& params); |
+ |
+ virtual ~AudioTrackOutputStream(); |
+ |
+ // Implementation of AudioOutputStream. |
+ virtual bool Open(); |
scherkus (not reviewing)
2011/11/29 20:00:28
OVERRIDE
michaelbai
2011/11/30 17:20:34
Done.
|
+ virtual void Close(); |
+ virtual void Start(AudioSourceCallback* callback); |
+ virtual void Stop(); |
+ virtual void SetVolume(double volume); |
+ virtual void GetVolume(double* volume); |
+ |
+ AudioSourceCallback* source_callback() { return source_callback_; } |
scherkus (not reviewing)
2011/11/29 20:00:28
why do these methods need to be exposed?
michaelbai
2011/11/30 17:20:34
It seemed no one actually use it, removed
|
+ |
+ void set_source_callback(AudioSourceCallback* callback) { |
+ source_callback_ = callback; |
+ } |
+ |
+ static AudioOutputStream* MakeStream(AudioManagerAndroid* manager, |
+ const AudioParameters& params); |
+ |
+ private: |
+ // Helper methods to invoke Java methods on |j_audio_track_|. |
+ void CallVoidMethod(std::string method_name); |
+ |
+ // Get the value of static field. |
+ jint GetStaticIntField(std::string class_name, std::string field_name); |
+ |
+ // Feed more data to AudioTrack. |
+ void FillAudioBufferTask(); |
+ |
+ AudioSourceCallback* source_callback_; |
+ AudioManagerAndroid* manager_; |
+ AudioParameters params_; |
+ scoped_ptr<StreamBuffer> data_buffer_; |
+ Status status_; |
+ double volume_; |
+ int buffer_size_; |
+ |
+ // Java AudioTrack class and instance. |
+ jclass j_class_; |
+ jobject j_audio_track_; |
+ |
+ base::RepeatingTimer<AudioTrackOutputStream> timer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AudioTrackOutputStream); |
+}; |
+ |
+#endif // MEDIA_AUDIO_AUDIO_TRACK_OUTPUT_ANDROID_H_ |