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

Side by Side Diff: media/audio/android/audio_track_output_android.h

Issue 8718014: Upstream: Media implementation for Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #ifndef MEDIA_AUDIO_AUDIO_TRACK_OUTPUT_ANDROID_H_
6 #define MEDIA_AUDIO_AUDIO_TRACK_OUTPUT_ANDROID_H_
7
8 #include <jni.h>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/timer.h"
14 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_parameters.h"
16
17 class AudioManagerAndroid;
18
19 // Implements PCM audio output support for Android using the AudioTrack API.
20 class AudioTrackOutputStream : public AudioOutputStream {
21 public:
22 enum Status {
23 IDLE,
24 OPENED,
25 PLAYING,
26 INVALID
27 };
28
29 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
30 public:
31 explicit StreamBuffer(uint32 buffer_size);
32
33 uint32 ReadStream(uint8* dest, uint32 max_size);
34 void ResetBuffer(uint32 data_size);
35 uint8* GetWritableBuffer();
36 const uint8* ReadBuffer();
37 void AdvancePosition(uint32 advance);
38
39 uint32 buffer_size() { return buffer_size_; }
40 uint32 data_len() { return data_size_ - current_; }
41
42 private:
43 scoped_array<uint8> buffer_;
44 uint32 buffer_size_;
45 uint32 data_size_;
46 uint32 current_;
47 };
48
49 AudioTrackOutputStream(AudioManagerAndroid* manager,
50 const AudioParameters& params);
51
52 virtual ~AudioTrackOutputStream();
53
54 // Implementation of AudioOutputStream.
55 virtual bool Open();
scherkus (not reviewing) 2011/11/29 20:00:28 OVERRIDE
michaelbai 2011/11/30 17:20:34 Done.
56 virtual void Close();
57 virtual void Start(AudioSourceCallback* callback);
58 virtual void Stop();
59 virtual void SetVolume(double volume);
60 virtual void GetVolume(double* volume);
61
62 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
63
64 void set_source_callback(AudioSourceCallback* callback) {
65 source_callback_ = callback;
66 }
67
68 static AudioOutputStream* MakeStream(AudioManagerAndroid* manager,
69 const AudioParameters& params);
70
71 private:
72 // Helper methods to invoke Java methods on |j_audio_track_|.
73 void CallVoidMethod(std::string method_name);
74
75 // Get the value of static field.
76 jint GetStaticIntField(std::string class_name, std::string field_name);
77
78 // Feed more data to AudioTrack.
79 void FillAudioBufferTask();
80
81 AudioSourceCallback* source_callback_;
82 AudioManagerAndroid* manager_;
83 AudioParameters params_;
84 scoped_ptr<StreamBuffer> data_buffer_;
85 Status status_;
86 double volume_;
87 int buffer_size_;
88
89 // Java AudioTrack class and instance.
90 jclass j_class_;
91 jobject j_audio_track_;
92
93 base::RepeatingTimer<AudioTrackOutputStream> timer_;
94
95 DISALLOW_COPY_AND_ASSIGN(AudioTrackOutputStream);
96 };
97
98 #endif // MEDIA_AUDIO_AUDIO_TRACK_OUTPUT_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698