| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // | 68 // |
| 69 // If unsure of what to use for |device_name|, use |kAutoSelectDevice|. | 69 // If unsure of what to use for |device_name|, use |kAutoSelectDevice|. |
| 70 AlsaPcmOutputStream(const std::string& device_name, | 70 AlsaPcmOutputStream(const std::string& device_name, |
| 71 AudioManager::Format format, | 71 AudioManager::Format format, |
| 72 int channels, | 72 int channels, |
| 73 int sample_rate, | 73 int sample_rate, |
| 74 int bits_per_sample, | 74 int bits_per_sample, |
| 75 AlsaWrapper* wrapper, | 75 AlsaWrapper* wrapper, |
| 76 AudioManagerLinux* manager, | 76 AudioManagerLinux* manager, |
| 77 MessageLoop* message_loop); | 77 MessageLoop* message_loop); |
| 78 virtual ~AlsaPcmOutputStream(); | |
| 79 | 78 |
| 80 // Implementation of AudioOutputStream. | 79 // Implementation of AudioOutputStream. |
| 81 virtual bool Open(size_t packet_size); | 80 virtual bool Open(size_t packet_size); |
| 82 virtual void Close(); | 81 virtual void Close(); |
| 83 virtual void Start(AudioSourceCallback* callback); | 82 virtual void Start(AudioSourceCallback* callback); |
| 84 virtual void Stop(); | 83 virtual void Stop(); |
| 85 virtual void SetVolume(double left_level, double right_level); | 84 virtual void SetVolume(double left_level, double right_level); |
| 86 virtual void GetVolume(double* left_level, double* right_level); | 85 virtual void GetVolume(double* left_level, double* right_level); |
| 87 | 86 |
| 88 private: | 87 private: |
| 88 friend class base::RefCountedThreadSafe<AlsaPcmOutputStream>; |
| 89 friend class AlsaPcmOutputStreamTest; | 89 friend class AlsaPcmOutputStreamTest; |
| 90 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect); | 90 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect); |
| 91 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_FallbackDevices); | 91 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_FallbackDevices); |
| 92 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail); | 92 FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail); |
| 93 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket); | 93 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket); |
| 94 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_StopStream); | 94 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_StopStream); |
| 95 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_UnfinishedPacket); | 95 FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_UnfinishedPacket); |
| 96 FRIEND_TEST(AlsaPcmOutputStreamTest, ConstructedState); | 96 FRIEND_TEST(AlsaPcmOutputStreamTest, ConstructedState); |
| 97 FRIEND_TEST(AlsaPcmOutputStreamTest, LatencyFloor); | 97 FRIEND_TEST(AlsaPcmOutputStreamTest, LatencyFloor); |
| 98 FRIEND_TEST(AlsaPcmOutputStreamTest, OpenClose); | 98 FRIEND_TEST(AlsaPcmOutputStreamTest, OpenClose); |
| 99 FRIEND_TEST(AlsaPcmOutputStreamTest, PcmOpenFailed); | 99 FRIEND_TEST(AlsaPcmOutputStreamTest, PcmOpenFailed); |
| 100 FRIEND_TEST(AlsaPcmOutputStreamTest, PcmSetParamsFailed); | 100 FRIEND_TEST(AlsaPcmOutputStreamTest, PcmSetParamsFailed); |
| 101 FRIEND_TEST(AlsaPcmOutputStreamTest, ScheduleNextWrite); | 101 FRIEND_TEST(AlsaPcmOutputStreamTest, ScheduleNextWrite); |
| 102 FRIEND_TEST(AlsaPcmOutputStreamTest, ScheduleNextWrite_StopStream); | 102 FRIEND_TEST(AlsaPcmOutputStreamTest, ScheduleNextWrite_StopStream); |
| 103 FRIEND_TEST(AlsaPcmOutputStreamTest, StartStop); | 103 FRIEND_TEST(AlsaPcmOutputStreamTest, StartStop); |
| 104 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_FinishedPacket); | 104 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_FinishedPacket); |
| 105 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_NormalPacket); | 105 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_NormalPacket); |
| 106 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_StopStream); | 106 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_StopStream); |
| 107 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_WriteFails); | 107 FRIEND_TEST(AlsaPcmOutputStreamTest, WritePacket_WriteFails); |
| 108 | 108 |
| 109 virtual ~AlsaPcmOutputStream(); |
| 110 |
| 109 // In-memory buffer to hold sound samples before pushing to the sound device. | 111 // In-memory buffer to hold sound samples before pushing to the sound device. |
| 110 // TODO(ajwong): There are now about 3 buffer/packet implementations. Factor | 112 // TODO(ajwong): There are now about 3 buffer/packet implementations. Factor |
| 111 // them out. | 113 // them out. |
| 112 struct Packet { | 114 struct Packet { |
| 113 explicit Packet(int new_capacity) | 115 explicit Packet(int new_capacity) |
| 114 : capacity(new_capacity), | 116 : capacity(new_capacity), |
| 115 size(0), | 117 size(0), |
| 116 used(0), | 118 used(0), |
| 117 buffer(new char[capacity]) { | 119 buffer(new char[capacity]) { |
| 118 } | 120 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 MessageLoop* client_thread_loop_; | 252 MessageLoop* client_thread_loop_; |
| 251 | 253 |
| 252 // The message loop responsible for querying the data source, and writing to | 254 // The message loop responsible for querying the data source, and writing to |
| 253 // the output device. | 255 // the output device. |
| 254 MessageLoop* message_loop_; | 256 MessageLoop* message_loop_; |
| 255 | 257 |
| 256 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); | 258 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); |
| 257 }; | 259 }; |
| 258 | 260 |
| 259 #endif // MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ | 261 #endif // MEDIA_AUDIO_LINUX_ALSA_OUTPUT_H_ |
| OLD | NEW |