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

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

Issue 2793123003: Enable float audio output on L+ Android devices. (Closed)
Patch Set: Use __ANDROID_API__. Created 3 years, 8 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 | « no previous file | 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 #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/opensles_util.h" 19 #include "media/audio/android/opensles_util.h"
20 #include "media/audio/audio_io.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.
25 #if __ANDROID_API__ < 21
26 #define SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT ((SLuint32)0x00000001)
27 #define SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT ((SLuint32)0x00000002)
28 #define SL_ANDROID_PCM_REPRESENTATION_FLOAT ((SLuint32)0x00000003)
29 #define SL_ANDROID_DATAFORMAT_PCM_EX ((SLuint32)0x00000004)
30
31 typedef struct SLAndroidDataFormat_PCM_EX_ {
32 SLuint32 formatType;
33 SLuint32 numChannels;
34 SLuint32 sampleRate;
35 SLuint32 bitsPerSample;
36 SLuint32 containerSize;
37 SLuint32 channelMask;
38 SLuint32 endianness;
39 SLuint32 representation;
40 } SLAndroidDataFormat_PCM_EX;
41 #endif
42
24 namespace media { 43 namespace media {
25 44
26 class AudioManagerAndroid; 45 class AudioManagerAndroid;
27 46
28 // Implements PCM audio output support for Android using the OpenSLES API. 47 // 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 48 // 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. 49 // audio buffers are given to us from an internal OpenSLES audio thread.
31 // All public methods should be called on the Audio Manager thread. 50 // All public methods should be called on the Audio Manager thread.
32 class OpenSLESOutputStream : public AudioOutputStream { 51 class OpenSLESOutputStream : public AudioOutputStream {
33 public: 52 public:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 media::ScopedSLObjectItf engine_object_; 113 media::ScopedSLObjectItf engine_object_;
95 media::ScopedSLObjectItf player_object_; 114 media::ScopedSLObjectItf player_object_;
96 media::ScopedSLObjectItf output_mixer_; 115 media::ScopedSLObjectItf output_mixer_;
97 116
98 SLPlayItf player_; 117 SLPlayItf player_;
99 118
100 // Buffer queue recorder interface. 119 // Buffer queue recorder interface.
101 SLAndroidSimpleBufferQueueItf simple_buffer_queue_; 120 SLAndroidSimpleBufferQueueItf simple_buffer_queue_;
102 121
103 SLDataFormat_PCM format_; 122 SLDataFormat_PCM format_;
123 SLAndroidDataFormat_PCM_EX float_format_;
104 124
105 // Audio buffers that are allocated during Open() based on parameters given 125 // Audio buffers that are allocated during Open() based on parameters given
106 // during construction. 126 // during construction.
107 uint8_t* audio_data_[kMaxNumOfBuffersInQueue]; 127 uint8_t* audio_data_[kMaxNumOfBuffersInQueue];
108 128
109 int active_buffer_index_; 129 int active_buffer_index_;
110 int bytes_per_frame_;
111 size_t buffer_size_bytes_;
112 130
113 bool started_; 131 bool started_;
114 132
115 // Volume control coming from hardware. It overrides |volume_| when it's 133 // Volume control coming from hardware. It overrides |volume_| when it's
116 // true. Otherwise, use |volume_| for scaling. 134 // true. Otherwise, use |volume_| for scaling.
117 // This is needed because platform voice volume never goes to zero in 135 // This is needed because platform voice volume never goes to zero in
118 // COMMUNICATION mode on Android. 136 // COMMUNICATION mode on Android.
119 bool muted_; 137 bool muted_;
120 138
121 // Volume level from 0 to 1. 139 // Volume level from 0 to 1.
122 float volume_; 140 float volume_;
123 141
124 int samples_per_second_; 142 int samples_per_second_;
125 143
144 // On Android 5.0+ we can output directly to float instead of in integer.
145 bool have_float_output_;
146
147 int bytes_per_frame_;
148 size_t buffer_size_bytes_;
149
126 // Used to calculate the delay value for each OnMoreData() call. 150 // Used to calculate the delay value for each OnMoreData() call.
127 AudioTimestampHelper delay_calculator_; 151 AudioTimestampHelper delay_calculator_;
128 152
129 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 153 // Container for retrieving data from AudioSourceCallback::OnMoreData().
130 std::unique_ptr<AudioBus> audio_bus_; 154 std::unique_ptr<AudioBus> audio_bus_;
131 155
132 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); 156 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream);
133 }; 157 };
134 158
135 } // namespace media 159 } // namespace media
136 160
137 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ 161 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/android/opensles_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698