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

Side by Side Diff: media/audio/alsa/alsa_output.h

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Changes based on comments Created 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // Creates an output stream based on the ALSA PCM interface. 5 // Creates an output stream based on the ALSA PCM interface.
6 // 6 //
7 // On device write failure, the stream will move itself to an invalid state. 7 // On device write failure, the stream will move itself to an invalid state.
8 // No more data will be pulled from the data source, or written to the device. 8 // No more data will be pulled from the data source, or written to the device.
9 // All calls to public API functions will either no-op themselves, or return an 9 // All calls to public API functions will either no-op themselves, or return an
10 // error if possible. Specifically, If the stream is in an error state, Open() 10 // error if possible. Specifically, If the stream is in an error state, Open()
(...skipping 16 matching lines...) Expand all
27 #include <memory> 27 #include <memory>
28 #include <string> 28 #include <string>
29 29
30 #include "base/compiler_specific.h" 30 #include "base/compiler_specific.h"
31 #include "base/gtest_prod_util.h" 31 #include "base/gtest_prod_util.h"
32 #include "base/macros.h" 32 #include "base/macros.h"
33 #include "base/memory/ref_counted.h" 33 #include "base/memory/ref_counted.h"
34 #include "base/memory/weak_ptr.h" 34 #include "base/memory/weak_ptr.h"
35 #include "base/single_thread_task_runner.h" 35 #include "base/single_thread_task_runner.h"
36 #include "base/threading/non_thread_safe.h" 36 #include "base/threading/non_thread_safe.h"
37 #include "base/time/tick_clock.h"
37 #include "base/time/time.h" 38 #include "base/time/time.h"
38 #include "media/audio/audio_io.h" 39 #include "media/audio/audio_io.h"
39 #include "media/base/audio_parameters.h" 40 #include "media/base/audio_parameters.h"
40 41
41 namespace media { 42 namespace media {
42 43
43 class AlsaWrapper; 44 class AlsaWrapper;
44 class AudioManagerBase; 45 class AudioManagerBase;
45 class ChannelMixer; 46 class ChannelMixer;
46 class SeekableBuffer; 47 class SeekableBuffer;
(...skipping 30 matching lines...) Expand all
77 ~AlsaPcmOutputStream() override; 78 ~AlsaPcmOutputStream() override;
78 79
79 // Implementation of AudioOutputStream. 80 // Implementation of AudioOutputStream.
80 bool Open() override; 81 bool Open() override;
81 void Close() override; 82 void Close() override;
82 void Start(AudioSourceCallback* callback) override; 83 void Start(AudioSourceCallback* callback) override;
83 void Stop() override; 84 void Stop() override;
84 void SetVolume(double volume) override; 85 void SetVolume(double volume) override;
85 void GetVolume(double* volume) override; 86 void GetVolume(double* volume) override;
86 87
88 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
89
87 private: 90 private:
88 friend class AlsaPcmOutputStreamTest; 91 friend class AlsaPcmOutputStreamTest;
89 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, 92 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest,
90 AutoSelectDevice_DeviceSelect); 93 AutoSelectDevice_DeviceSelect);
91 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, 94 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest,
92 AutoSelectDevice_FallbackDevices); 95 AutoSelectDevice_FallbackDevices);
93 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail); 96 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail);
94 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket); 97 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket);
95 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_Negative); 98 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_Negative);
96 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_StopStream); 99 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_StopStream);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 InternalState state(); 148 InternalState state();
146 149
147 // API for Proxying calls to the AudioSourceCallback provided during 150 // API for Proxying calls to the AudioSourceCallback provided during
148 // Start(). 151 // Start().
149 // 152 //
150 // TODO(ajwong): This is necessary because the ownership semantics for the 153 // TODO(ajwong): This is necessary because the ownership semantics for the
151 // |source_callback_| object are incorrect in AudioRenderHost. The callback 154 // |source_callback_| object are incorrect in AudioRenderHost. The callback
152 // is passed into the output stream, but ownership is not transfered which 155 // is passed into the output stream, but ownership is not transfered which
153 // requires a synchronization on access of the |source_callback_| to avoid 156 // requires a synchronization on access of the |source_callback_| to avoid
154 // using a deleted callback. 157 // using a deleted callback.
155 int RunDataCallback(AudioBus* audio_bus, uint32_t total_bytes_delay); 158 int RunDataCallback(base::TimeTicks target_playout_time, AudioBus* audio_bus);
156 void RunErrorCallback(int code); 159 void RunErrorCallback(int code);
157 160
158 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to 161 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to
159 // release ownership of the currently registered callback. 162 // release ownership of the currently registered callback.
160 void set_source_callback(AudioSourceCallback* callback); 163 void set_source_callback(AudioSourceCallback* callback);
161 164
162 // Configuration constants from the constructor. Referenceable by all threads 165 // Configuration constants from the constructor. Referenceable by all threads
163 // since they are constants. 166 // since they are constants.
164 const std::string requested_device_name_; 167 const std::string requested_device_name_;
165 const snd_pcm_format_t pcm_format_; 168 const snd_pcm_format_t pcm_format_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 204
202 AudioSourceCallback* source_callback_; 205 AudioSourceCallback* source_callback_;
203 206
204 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 207 // Container for retrieving data from AudioSourceCallback::OnMoreData().
205 std::unique_ptr<AudioBus> audio_bus_; 208 std::unique_ptr<AudioBus> audio_bus_;
206 209
207 // Channel mixer and temporary bus for the final mixed channel data. 210 // Channel mixer and temporary bus for the final mixed channel data.
208 std::unique_ptr<ChannelMixer> channel_mixer_; 211 std::unique_ptr<ChannelMixer> channel_mixer_;
209 std::unique_ptr<AudioBus> mixed_audio_bus_; 212 std::unique_ptr<AudioBus> mixed_audio_bus_;
210 213
214 std::unique_ptr<base::TickClock> tick_clock_;
215
211 // Allows us to run tasks on the AlsaPcmOutputStream instance which are 216 // Allows us to run tasks on the AlsaPcmOutputStream instance which are
212 // bound by its lifetime. 217 // bound by its lifetime.
213 // NOTE: Weak pointers must be invalidated before all other member variables. 218 // NOTE: Weak pointers must be invalidated before all other member variables.
214 base::WeakPtrFactory<AlsaPcmOutputStream> weak_factory_; 219 base::WeakPtrFactory<AlsaPcmOutputStream> weak_factory_;
215 220
216 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); 221 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream);
217 }; 222 };
218 223
219 MEDIA_EXPORT std::ostream& operator<<(std::ostream& os, 224 MEDIA_EXPORT std::ostream& operator<<(std::ostream& os,
220 AlsaPcmOutputStream::InternalState); 225 AlsaPcmOutputStream::InternalState);
221 226
222 }; // namespace media 227 }; // namespace media
223 228
224 #endif // MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ 229 #endif // MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698