OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 14 matching lines...) Expand all Loading... |
25 // introducing race conditions between tasks posted to the internal | 25 // introducing race conditions between tasks posted to the internal |
26 // message_loop, and the thread calling the public APIs. | 26 // message_loop, and the thread calling the public APIs. |
27 | 27 |
28 #ifndef MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ | 28 #ifndef MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ |
29 #define MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ | 29 #define MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ |
30 | 30 |
31 #include <alsa/asoundlib.h> | 31 #include <alsa/asoundlib.h> |
32 | 32 |
33 #include <string> | 33 #include <string> |
34 | 34 |
| 35 #include "base/gtest_prod_util.h" |
35 #include "base/lock.h" | 36 #include "base/lock.h" |
36 #include "base/ref_counted.h" | 37 #include "base/ref_counted.h" |
37 #include "base/scoped_ptr.h" | 38 #include "base/scoped_ptr.h" |
38 #include "base/thread.h" | 39 #include "base/thread.h" |
39 #include "media/audio/audio_io.h" | 40 #include "media/audio/audio_io.h" |
40 #include "testing/gtest/include/gtest/gtest_prod.h" | |
41 | 41 |
42 namespace media { | 42 namespace media { |
43 class SeekableBuffer; | 43 class SeekableBuffer; |
44 }; // namespace media | 44 }; // namespace media |
45 | 45 |
46 class AlsaWrapper; | 46 class AlsaWrapper; |
47 class AudioManagerLinux; | 47 class AudioManagerLinux; |
48 | 48 |
49 class AlsaPcmOutputStream : | 49 class AlsaPcmOutputStream : |
50 public AudioOutputStream, | 50 public AudioOutputStream, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 virtual bool Open(uint32 packet_size); | 84 virtual bool Open(uint32 packet_size); |
85 virtual void Close(); | 85 virtual void Close(); |
86 virtual void Start(AudioSourceCallback* callback); | 86 virtual void Start(AudioSourceCallback* callback); |
87 virtual void Stop(); | 87 virtual void Stop(); |
88 virtual void SetVolume(double volume); | 88 virtual void SetVolume(double volume); |
89 virtual void GetVolume(double* volume); | 89 virtual void GetVolume(double* volume); |
90 | 90 |
91 private: | 91 private: |
92 friend class base::RefCountedThreadSafe<AlsaPcmOutputStream>; | 92 friend class base::RefCountedThreadSafe<AlsaPcmOutputStream>; |
93 friend class AlsaPcmOutputStreamTest; | 93 friend class AlsaPcmOutputStreamTest; |
94 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect); | 94 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, |
95 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_FallbackDevices); | 95 AutoSelectDevice_DeviceSelect); |
96 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail); | 96 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, |
97 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket); | 97 AutoSelectDevice_FallbackDevices); |
98 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_Negative); | 98 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail); |
99 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_StopStream); | 99 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket); |
100 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_Underrun); | 100 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_Negative); |
101 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_FullBuffer); | 101 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_StopStream); |
102 FRIEND_TEST(AlsaPcmOutputStreamTest, ConstructedState); | 102 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_Underrun); |
103 FRIEND_TEST(AlsaPcmOutputStreamTest, LatencyFloor); | 103 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, BufferPacket_FullBuffer); |
104 FRIEND_TEST(AlsaPcmOutputStreamTest, OpenClose); | 104 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, ConstructedState); |
105 FRIEND_TEST(AlsaPcmOutputStreamTest, PcmOpenFailed); | 105 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, LatencyFloor); |
106 FRIEND_TEST(AlsaPcmOutputStreamTest, PcmSetParamsFailed); | 106 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, OpenClose); |
107 FRIEND_TEST(AlsaPcmOutputStreamTest, ScheduleNextWrite); | 107 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, PcmOpenFailed); |
108 FRIEND_TEST(AlsaPcmOutputStreamTest, ScheduleNextWrite_StopStream); | 108 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, PcmSetParamsFailed); |
109 FRIEND_TEST(AlsaPcmOutputStreamTest, StartStop); | 109 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, ScheduleNextWrite); |
110 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_FinishedPacket); | 110 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, |
111 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_NormalPacket); | 111 ScheduleNextWrite_StopStream); |
112 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_StopStream); | 112 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, StartStop); |
113 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_WriteFails); | 113 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, WritePacket_FinishedPacket); |
| 114 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, WritePacket_NormalPacket); |
| 115 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, WritePacket_StopStream); |
| 116 FRIEND_TEST_ALL_PREFIXES(AlsaPcmOutputStreamTest, WritePacket_WriteFails); |
114 | 117 |
115 virtual ~AlsaPcmOutputStream(); | 118 virtual ~AlsaPcmOutputStream(); |
116 | 119 |
117 // Flags indicating the state of the stream. | 120 // Flags indicating the state of the stream. |
118 enum InternalState { | 121 enum InternalState { |
119 kInError = 0, | 122 kInError = 0, |
120 kCreated, | 123 kCreated, |
121 kIsOpened, | 124 kIsOpened, |
122 kIsPlaying, | 125 kIsPlaying, |
123 kIsStopped, | 126 kIsStopped, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 MessageLoop* client_thread_loop_; | 245 MessageLoop* client_thread_loop_; |
243 | 246 |
244 // The message loop responsible for querying the data source, and writing to | 247 // The message loop responsible for querying the data source, and writing to |
245 // the output device. | 248 // the output device. |
246 MessageLoop* message_loop_; | 249 MessageLoop* message_loop_; |
247 | 250 |
248 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); | 251 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); |
249 }; | 252 }; |
250 | 253 |
251 #endif // MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ | 254 #endif // MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ |
OLD | NEW |