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

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

Issue 23296008: Adding audio unit tests for Android (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebased Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ 5 #ifndef MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
6 #define MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ 6 #define MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
7 7
8 #include <SLES/OpenSLES.h> 8 #include <SLES/OpenSLES.h>
9 #include <SLES/OpenSLES_Android.h> 9 #include <SLES/OpenSLES_Android.h>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/threading/thread_checker.h"
12 #include "media/audio/android/opensles_util.h" 13 #include "media/audio/android/opensles_util.h"
13 #include "media/audio/audio_io.h" 14 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_parameters.h" 15 #include "media/audio/audio_parameters.h"
15 16
16 namespace media { 17 namespace media {
17 18
18 class AudioManagerAndroid; 19 class AudioManagerAndroid;
19 20
20 // Implements PCM audio output support for Android using the OpenSLES API. 21 // Implements PCM audio output support for Android using the OpenSLES API.
22 // This class is created and lives on the Audio Manager thread but recorded
23 // audio buffers are given to us from an internal OpenSLES audio thread.
24 // All public methods should be called on the Audio Manager thread.
21 class OpenSLESOutputStream : public AudioOutputStream { 25 class OpenSLESOutputStream : public AudioOutputStream {
22 public: 26 public:
23 static const int kNumOfQueuesInBuffer = 2; 27 static const int kMaxNumOfBuffersInQueue = 2;
24 28
25 OpenSLESOutputStream(AudioManagerAndroid* manager, 29 OpenSLESOutputStream(AudioManagerAndroid* manager,
26 const AudioParameters& params); 30 const AudioParameters& params);
27 31
28 virtual ~OpenSLESOutputStream(); 32 virtual ~OpenSLESOutputStream();
29 33
30 // Implementation of AudioOutputStream. 34 // Implementation of AudioOutputStream.
31 virtual bool Open() OVERRIDE; 35 virtual bool Open() OVERRIDE;
32 virtual void Close() OVERRIDE; 36 virtual void Close() OVERRIDE;
33 virtual void Start(AudioSourceCallback* callback) OVERRIDE; 37 virtual void Start(AudioSourceCallback* callback) OVERRIDE;
34 virtual void Stop() OVERRIDE; 38 virtual void Stop() OVERRIDE;
35 virtual void SetVolume(double volume) OVERRIDE; 39 virtual void SetVolume(double volume) OVERRIDE;
36 virtual void GetVolume(double* volume) OVERRIDE; 40 virtual void GetVolume(double* volume) OVERRIDE;
37 41
38 private: 42 private:
39 bool CreatePlayer(); 43 bool CreatePlayer();
40 44
45 // Called from OpenSLES specific audio worker thread.
41 static void SimpleBufferQueueCallback( 46 static void SimpleBufferQueueCallback(
42 SLAndroidSimpleBufferQueueItf buffer_queue, void* instance); 47 SLAndroidSimpleBufferQueueItf buffer_queue, void* instance);
43 48
49 // Fills up one buffer by asking the registered source for data.
50 // Called from OpenSLES specific audio worker thread.
44 void FillBufferQueue(); 51 void FillBufferQueue();
45 52
53 // Called from the audio manager thread.
54 void FillBufferQueueNoLock();
55
46 // Called in Open(); 56 // Called in Open();
47 void SetupAudioBuffer(); 57 void SetupAudioBuffer();
48 58
49 // Called in Close(); 59 // Called in Close();
50 void ReleaseAudioBuffer(); 60 void ReleaseAudioBuffer();
51 61
52 // If OpenSLES reports an error this function handles it and passes it to 62 // If OpenSLES reports an error this function handles it and passes it to
53 // the attached AudioOutputCallback::OnError(). 63 // the attached AudioOutputCallback::OnError().
54 void HandleError(SLresult error); 64 void HandleError(SLresult error);
55 65
66 base::ThreadChecker thread_checker_;
67
68 // TODO(henrika): add comments....
tommi (sloooow) - chröme 2013/09/03 12:15:09 ping
henrika (OOO until Aug 14) 2013/09/03 12:48:32 Done.
69 base::Lock lock_;
70
56 AudioManagerAndroid* audio_manager_; 71 AudioManagerAndroid* audio_manager_;
57 72
58 AudioSourceCallback* callback_; 73 AudioSourceCallback* callback_;
59 74
60 // Shared engine interfaces for the app. 75 // Shared engine interfaces for the app.
61 media::ScopedSLObjectItf engine_object_; 76 media::ScopedSLObjectItf engine_object_;
62 media::ScopedSLObjectItf player_object_; 77 media::ScopedSLObjectItf player_object_;
63 media::ScopedSLObjectItf output_mixer_; 78 media::ScopedSLObjectItf output_mixer_;
64 79
65 SLPlayItf player_; 80 SLPlayItf player_;
66 81
67 // Buffer queue recorder interface. 82 // Buffer queue recorder interface.
68 SLAndroidSimpleBufferQueueItf simple_buffer_queue_; 83 SLAndroidSimpleBufferQueueItf simple_buffer_queue_;
69 84
70 SLDataFormat_PCM format_; 85 SLDataFormat_PCM format_;
71 86
72 // Audio buffer arrays that are allocated in the constructor. 87 // Audio buffers that are allocated in the constructor based on
73 uint8* audio_data_[kNumOfQueuesInBuffer]; 88 // info from audio parameters.
89 uint8* audio_data_[kMaxNumOfBuffersInQueue];
74 90
75 int active_queue_; 91 int active_buffer_;
tommi (sloooow) - chröme 2013/09/03 12:15:09 nit: active_buffer_index_
henrika (OOO until Aug 14) 2013/09/03 12:48:32 Done.
76 size_t buffer_size_bytes_; 92 size_t buffer_size_bytes_;
77 93
78 bool started_; 94 bool started_;
79 95
80 // Volume level from 0 to 1. 96 // Volume level from 0 to 1.
81 float volume_; 97 float volume_;
82 98
83 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 99 // Container for retrieving data from AudioSourceCallback::OnMoreData().
84 scoped_ptr<AudioBus> audio_bus_; 100 scoped_ptr<AudioBus> audio_bus_;
85 101
86 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); 102 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream);
87 }; 103 };
88 104
89 } // namespace media 105 } // namespace media
90 106
91 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ 107 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698