| 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 // On L+, we want to use floating point output for better fidelity. | 24 // On L+, we want to use floating point output for better fidelity. |
| 25 #if __ANDROID_API__ < 21 | 25 #if __ANDROID_API__ < 21 |
| 26 #define SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT ((SLuint32)0x00000001) | 26 #define SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT ((SLuint32)0x00000001) |
| 27 #define SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT ((SLuint32)0x00000002) | 27 #define SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT ((SLuint32)0x00000002) |
| 28 #define SL_ANDROID_PCM_REPRESENTATION_FLOAT ((SLuint32)0x00000003) | 28 #define SL_ANDROID_PCM_REPRESENTATION_FLOAT ((SLuint32)0x00000003) |
| 29 #define SL_ANDROID_DATAFORMAT_PCM_EX ((SLuint32)0x00000004) | 29 #define SL_ANDROID_DATAFORMAT_PCM_EX ((SLuint32)0x00000004) |
| 30 | 30 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 namespace media { | 43 namespace media { |
| 44 | 44 |
| 45 class AudioManagerAndroid; | 45 class AudioManagerAndroid; |
| 46 | 46 |
| 47 // Implements PCM audio output support for Android using the OpenSLES API. | 47 // Implements PCM audio output support for Android using the OpenSLES API. |
| 48 // This class is created and lives on the Audio Manager thread but recorded | 48 // This class is created and lives on the Audio Manager thread but recorded |
| 49 // audio buffers are given to us from an internal OpenSLES audio thread. | 49 // audio buffers are given to us from an internal OpenSLES audio thread. |
| 50 // All public methods should be called on the Audio Manager thread. | 50 // All public methods should be called on the Audio Manager thread. |
| 51 class OpenSLESOutputStream : public AudioOutputStream { | 51 class OpenSLESOutputStream : public MuteableAudioOutputStream { |
| 52 public: | 52 public: |
| 53 static const int kMaxNumOfBuffersInQueue = 2; | 53 static const int kMaxNumOfBuffersInQueue = 2; |
| 54 | 54 |
| 55 OpenSLESOutputStream(AudioManagerAndroid* manager, | 55 OpenSLESOutputStream(AudioManagerAndroid* manager, |
| 56 const AudioParameters& params, | 56 const AudioParameters& params, |
| 57 SLint32 stream_type); | 57 SLint32 stream_type); |
| 58 | 58 |
| 59 ~OpenSLESOutputStream() override; | 59 ~OpenSLESOutputStream() override; |
| 60 | 60 |
| 61 // Implementation of AudioOutputStream. | 61 // Implementation of MuteableAudioOutputStream. |
| 62 bool Open() override; | 62 bool Open() override; |
| 63 void Close() override; | 63 void Close() override; |
| 64 void Start(AudioSourceCallback* callback) override; | 64 void Start(AudioSourceCallback* callback) override; |
| 65 void Stop() override; | 65 void Stop() override; |
| 66 void SetVolume(double volume) override; | 66 void SetVolume(double volume) override; |
| 67 void GetVolume(double* volume) override; | 67 void GetVolume(double* volume) override; |
| 68 | 68 |
| 69 // Set the value of |muted_|. It does not affect |volume_| which can be | 69 // Set the value of |muted_|. It does not affect |volume_| which can be |
| 70 // got by calling GetVolume(). See comments for |muted_| below. | 70 // got by calling GetVolume(). See comments for |muted_| below. |
| 71 void SetMute(bool muted); | 71 void SetMute(bool muted) override; |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 bool CreatePlayer(); | 74 bool CreatePlayer(); |
| 75 | 75 |
| 76 // Called from OpenSLES specific audio worker thread. | 76 // Called from OpenSLES specific audio worker thread. |
| 77 static void SimpleBufferQueueCallback( | 77 static void SimpleBufferQueueCallback( |
| 78 SLAndroidSimpleBufferQueueItf buffer_queue, | 78 SLAndroidSimpleBufferQueueItf buffer_queue, |
| 79 void* instance); | 79 void* instance); |
| 80 | 80 |
| 81 // Fills up one buffer by asking the registered source for data. | 81 // Fills up one buffer by asking the registered source for data. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 153 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
| 154 std::unique_ptr<AudioBus> audio_bus_; | 154 std::unique_ptr<AudioBus> audio_bus_; |
| 155 | 155 |
| 156 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); | 156 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 } // namespace media | 159 } // namespace media |
| 160 | 160 |
| 161 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ | 161 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ |
| OLD | NEW |