OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_LINUX_ALSA_INPUT_H_ | 5 #ifndef MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ |
6 #define MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ | 6 #define MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ |
7 | 7 |
8 #include <alsa/asoundlib.h> | 8 #include <alsa/asoundlib.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // Create a PCM Output stream for the ALSA device identified by | 30 // Create a PCM Output stream for the ALSA device identified by |
31 // |device_name|. If unsure of what to use for |device_name|, use | 31 // |device_name|. If unsure of what to use for |device_name|, use |
32 // |kAutoSelectDevice|. | 32 // |kAutoSelectDevice|. |
33 AlsaPcmInputStream(AudioManagerLinux* audio_manager, | 33 AlsaPcmInputStream(AudioManagerLinux* audio_manager, |
34 const std::string& device_name, | 34 const std::string& device_name, |
35 const AudioParameters& params, | 35 const AudioParameters& params, |
36 AlsaWrapper* wrapper); | 36 AlsaWrapper* wrapper); |
37 virtual ~AlsaPcmInputStream(); | 37 virtual ~AlsaPcmInputStream(); |
38 | 38 |
39 // Implementation of AudioOutputStream. | 39 // Implementation of AudioInputStream. |
40 virtual bool Open() OVERRIDE; | 40 virtual bool Open() OVERRIDE; |
41 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 41 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
42 virtual void Stop() OVERRIDE; | 42 virtual void Stop() OVERRIDE; |
43 virtual void Close() OVERRIDE; | 43 virtual void Close() OVERRIDE; |
| 44 virtual double GetMaxVolume() OVERRIDE; |
| 45 virtual void SetVolume(double volume) OVERRIDE; |
| 46 virtual double GetVolume() OVERRIDE; |
44 | 47 |
45 private: | 48 private: |
46 // Logs the error and invokes any registered callbacks. | 49 // Logs the error and invokes any registered callbacks. |
47 void HandleError(const char* method, int error); | 50 void HandleError(const char* method, int error); |
48 | 51 |
49 // Reads one or more packets of audio from the device, passes on to the | 52 // Reads one or more packets of audio from the device, passes on to the |
50 // registered callback and schedules the next read. | 53 // registered callback and schedules the next read. |
51 void ReadAudio(); | 54 void ReadAudio(); |
52 | 55 |
53 // Recovers from any device errors if possible. | 56 // Recovers from any device errors if possible. |
54 bool Recover(int error); | 57 bool Recover(int error); |
55 | 58 |
56 // Utility function for talking with the ALSA API. | 59 // Utility function for talking with the ALSA API. |
57 snd_pcm_sframes_t GetCurrentDelay(); | 60 snd_pcm_sframes_t GetCurrentDelay(); |
58 | 61 |
59 // Non-refcounted pointer back to the audio manager. | 62 // Non-refcounted pointer back to the audio manager. |
60 // The AudioManager indirectly holds on to stream objects, so we don't | 63 // The AudioManager indirectly holds on to stream objects, so we don't |
61 // want circular references. Additionally, stream objects live on the audio | 64 // want circular references. Additionally, stream objects live on the audio |
62 // thread, which is owned by the audio manager and we don't want to addref | 65 // thread, which is owned by the audio manager and we don't want to addref |
63 // the manager from that thread. | 66 // the manager from that thread. |
64 AudioManagerLinux* audio_manager_; | 67 AudioManagerLinux* audio_manager_; |
65 std::string device_name_; | 68 std::string device_name_; |
66 AudioParameters params_; | 69 AudioParameters params_; |
67 int bytes_per_packet_; | 70 int bytes_per_packet_; |
68 AlsaWrapper* wrapper_; | 71 AlsaWrapper* wrapper_; |
69 int packet_duration_ms_; // Length of each recorded packet in milliseconds. | 72 int packet_duration_ms_; // Length of each recorded packet in milliseconds. |
70 AudioInputCallback* callback_; // Valid during a recording session. | 73 AudioInputCallback* callback_; // Valid during a recording session. |
71 base::Time next_read_time_; // Scheduled time for the next read callback. | 74 base::Time next_read_time_; // Scheduled time for the next read callback. |
72 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. | 75 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. |
| 76 snd_mixer_t* mixer_handle_; // Handle to the ALSA microphone mixer. |
| 77 snd_mixer_elem_t* mixer_element_handle_; // Handle to the capture element. |
73 base::WeakPtrFactory<AlsaPcmInputStream> weak_factory_; | 78 base::WeakPtrFactory<AlsaPcmInputStream> weak_factory_; |
74 scoped_array<uint8> audio_packet_; // Buffer used for reading audio data. | 79 scoped_array<uint8> audio_packet_; // Buffer used for reading audio data. |
75 bool read_callback_behind_schedule_; | 80 bool read_callback_behind_schedule_; |
76 | 81 |
77 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream); | 82 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream); |
78 }; | 83 }; |
79 | 84 |
80 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ | 85 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ |
OLD | NEW |