| OLD | NEW |
| 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 #include <stddef.h> | 10 #include <stddef.h> |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "media/audio/android/muteable_audio_output_stream.h" |
| 19 #include "media/audio/android/opensles_util.h" | 20 #include "media/audio/android/opensles_util.h" |
| 20 #include "media/audio/audio_io.h" | |
| 21 #include "media/base/audio_parameters.h" | 21 #include "media/base/audio_parameters.h" |
| 22 #include "media/base/audio_timestamp_helper.h" | 22 #include "media/base/audio_timestamp_helper.h" |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 class AudioManagerAndroid; | 26 class AudioManagerAndroid; |
| 27 | 27 |
| 28 // Implements PCM audio output support for Android using the OpenSLES API. | 28 // Implements PCM audio output support for Android using the OpenSLES API. |
| 29 // This class is created and lives on the Audio Manager thread but recorded | 29 // This class is created and lives on the Audio Manager thread but recorded |
| 30 // audio buffers are given to us from an internal OpenSLES audio thread. | 30 // audio buffers are given to us from an internal OpenSLES audio thread. |
| 31 // All public methods should be called on the Audio Manager thread. | 31 // All public methods should be called on the Audio Manager thread. |
| 32 class OpenSLESOutputStream : public AudioOutputStream { | 32 class OpenSLESOutputStream : public MuteableAudioOutputStream { |
| 33 public: | 33 public: |
| 34 static const int kMaxNumOfBuffersInQueue = 2; | 34 static const int kMaxNumOfBuffersInQueue = 2; |
| 35 | 35 |
| 36 OpenSLESOutputStream(AudioManagerAndroid* manager, | 36 OpenSLESOutputStream(AudioManagerAndroid* manager, |
| 37 const AudioParameters& params, | 37 const AudioParameters& params, |
| 38 SLint32 stream_type); | 38 SLint32 stream_type); |
| 39 | 39 |
| 40 ~OpenSLESOutputStream() override; | 40 ~OpenSLESOutputStream() override; |
| 41 | 41 |
| 42 // Implementation of AudioOutputStream. | 42 // Implementation of MuteableAudioOutputStream. |
| 43 bool Open() override; | 43 bool Open() override; |
| 44 void Close() override; | 44 void Close() override; |
| 45 void Start(AudioSourceCallback* callback) override; | 45 void Start(AudioSourceCallback* callback) override; |
| 46 void Stop() override; | 46 void Stop() override; |
| 47 void SetVolume(double volume) override; | 47 void SetVolume(double volume) override; |
| 48 void GetVolume(double* volume) override; | 48 void GetVolume(double* volume) override; |
| 49 | 49 |
| 50 // Set the value of |muted_|. It does not affect |volume_| which can be | 50 // Set the value of |muted_|. It does not affect |volume_| which can be |
| 51 // got by calling GetVolume(). See comments for |muted_| below. | 51 // got by calling GetVolume(). See comments for |muted_| below. |
| 52 void SetMute(bool muted); | 52 void SetMute(bool muted) override; |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 bool CreatePlayer(); | 55 bool CreatePlayer(); |
| 56 | 56 |
| 57 // Called from OpenSLES specific audio worker thread. | 57 // Called from OpenSLES specific audio worker thread. |
| 58 static void SimpleBufferQueueCallback( | 58 static void SimpleBufferQueueCallback( |
| 59 SLAndroidSimpleBufferQueueItf buffer_queue, | 59 SLAndroidSimpleBufferQueueItf buffer_queue, |
| 60 void* instance); | 60 void* instance); |
| 61 | 61 |
| 62 // Fills up one buffer by asking the registered source for data. | 62 // Fills up one buffer by asking the registered source for data. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 127 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
| 128 std::unique_ptr<AudioBus> audio_bus_; | 128 std::unique_ptr<AudioBus> audio_bus_; |
| 129 | 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); | 130 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 } // namespace media | 133 } // namespace media |
| 134 | 134 |
| 135 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ | 135 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ |
| OLD | NEW |