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

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: Nit 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
« no previous file with comments | « media/audio/android/opensles_input.cc ('k') | media/audio/android/opensles_output.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/synchronization/lock.h"
13 #include "base/threading/thread_checker.h"
12 #include "media/audio/android/opensles_util.h" 14 #include "media/audio/android/opensles_util.h"
13 #include "media/audio/audio_io.h" 15 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_parameters.h" 16 #include "media/audio/audio_parameters.h"
15 17
16 namespace media { 18 namespace media {
17 19
18 class AudioManagerAndroid; 20 class AudioManagerAndroid;
19 21
20 // Implements PCM audio output support for Android using the OpenSLES API. 22 // Implements PCM audio output support for Android using the OpenSLES API.
23 // This class is created and lives on the Audio Manager thread but recorded
24 // audio buffers are given to us from an internal OpenSLES audio thread.
25 // All public methods should be called on the Audio Manager thread.
21 class OpenSLESOutputStream : public AudioOutputStream { 26 class OpenSLESOutputStream : public AudioOutputStream {
22 public: 27 public:
23 static const int kNumOfQueuesInBuffer = 2; 28 static const int kMaxNumOfBuffersInQueue = 2;
24 29
25 OpenSLESOutputStream(AudioManagerAndroid* manager, 30 OpenSLESOutputStream(AudioManagerAndroid* manager,
26 const AudioParameters& params); 31 const AudioParameters& params);
27 32
28 virtual ~OpenSLESOutputStream(); 33 virtual ~OpenSLESOutputStream();
29 34
30 // Implementation of AudioOutputStream. 35 // Implementation of AudioOutputStream.
31 virtual bool Open() OVERRIDE; 36 virtual bool Open() OVERRIDE;
32 virtual void Close() OVERRIDE; 37 virtual void Close() OVERRIDE;
33 virtual void Start(AudioSourceCallback* callback) OVERRIDE; 38 virtual void Start(AudioSourceCallback* callback) OVERRIDE;
34 virtual void Stop() OVERRIDE; 39 virtual void Stop() OVERRIDE;
35 virtual void SetVolume(double volume) OVERRIDE; 40 virtual void SetVolume(double volume) OVERRIDE;
36 virtual void GetVolume(double* volume) OVERRIDE; 41 virtual void GetVolume(double* volume) OVERRIDE;
37 42
38 private: 43 private:
39 bool CreatePlayer(); 44 bool CreatePlayer();
40 45
46 // Called from OpenSLES specific audio worker thread.
41 static void SimpleBufferQueueCallback( 47 static void SimpleBufferQueueCallback(
42 SLAndroidSimpleBufferQueueItf buffer_queue, void* instance); 48 SLAndroidSimpleBufferQueueItf buffer_queue,
49 void* instance);
43 50
51 // Fills up one buffer by asking the registered source for data.
52 // Called from OpenSLES specific audio worker thread.
44 void FillBufferQueue(); 53 void FillBufferQueue();
45 54
55 // Called from the audio manager thread.
56 void FillBufferQueueNoLock();
57
46 // Called in Open(); 58 // Called in Open();
47 void SetupAudioBuffer(); 59 void SetupAudioBuffer();
48 60
49 // Called in Close(); 61 // Called in Close();
50 void ReleaseAudioBuffer(); 62 void ReleaseAudioBuffer();
51 63
52 // If OpenSLES reports an error this function handles it and passes it to 64 // If OpenSLES reports an error this function handles it and passes it to
53 // the attached AudioOutputCallback::OnError(). 65 // the attached AudioOutputCallback::OnError().
54 void HandleError(SLresult error); 66 void HandleError(SLresult error);
55 67
68 base::ThreadChecker thread_checker_;
69
70 // Protects |callback_|, |active_buffer_index_|, |audio_data_|,
71 // |buffer_size_bytes_| and |simple_buffer_queue_|.
72 base::Lock lock_;
73
56 AudioManagerAndroid* audio_manager_; 74 AudioManagerAndroid* audio_manager_;
57 75
58 AudioSourceCallback* callback_; 76 AudioSourceCallback* callback_;
59 77
60 // Shared engine interfaces for the app. 78 // Shared engine interfaces for the app.
61 media::ScopedSLObjectItf engine_object_; 79 media::ScopedSLObjectItf engine_object_;
62 media::ScopedSLObjectItf player_object_; 80 media::ScopedSLObjectItf player_object_;
63 media::ScopedSLObjectItf output_mixer_; 81 media::ScopedSLObjectItf output_mixer_;
64 82
65 SLPlayItf player_; 83 SLPlayItf player_;
66 84
67 // Buffer queue recorder interface. 85 // Buffer queue recorder interface.
68 SLAndroidSimpleBufferQueueItf simple_buffer_queue_; 86 SLAndroidSimpleBufferQueueItf simple_buffer_queue_;
69 87
70 SLDataFormat_PCM format_; 88 SLDataFormat_PCM format_;
71 89
72 // Audio buffer arrays that are allocated in the constructor. 90 // Audio buffers that are allocated in the constructor based on
73 uint8* audio_data_[kNumOfQueuesInBuffer]; 91 // info from audio parameters.
92 uint8* audio_data_[kMaxNumOfBuffersInQueue];
74 93
75 int active_queue_; 94 int active_buffer_index_;
76 size_t buffer_size_bytes_; 95 size_t buffer_size_bytes_;
77 96
78 bool started_; 97 bool started_;
79 98
80 // Volume level from 0 to 1. 99 // Volume level from 0 to 1.
81 float volume_; 100 float volume_;
82 101
83 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 102 // Container for retrieving data from AudioSourceCallback::OnMoreData().
84 scoped_ptr<AudioBus> audio_bus_; 103 scoped_ptr<AudioBus> audio_bus_;
85 104
86 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); 105 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream);
87 }; 106 };
88 107
89 } // namespace media 108 } // namespace media
90 109
91 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ 110 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
OLDNEW
« no previous file with comments | « media/audio/android/opensles_input.cc ('k') | media/audio/android/opensles_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698