| OLD | NEW |
| 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_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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 virtual void Stop() OVERRIDE; | 44 virtual void Stop() OVERRIDE; |
| 45 virtual void Close() OVERRIDE; | 45 virtual void Close() OVERRIDE; |
| 46 virtual double GetMaxVolume() OVERRIDE; | 46 virtual double GetMaxVolume() OVERRIDE; |
| 47 virtual void SetVolume(double volume) OVERRIDE; | 47 virtual void SetVolume(double volume) OVERRIDE; |
| 48 virtual double GetVolume() OVERRIDE; | 48 virtual double GetVolume() OVERRIDE; |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // Logs the error and invokes any registered callbacks. | 51 // Logs the error and invokes any registered callbacks. |
| 52 void HandleError(const char* method, int error); | 52 void HandleError(const char* method, int error); |
| 53 | 53 |
| 54 // Reads one or more packets of audio from the device, passes on to the | 54 // Reads one or more buffers of audio from the device, passes on to the |
| 55 // registered callback and schedules the next read. | 55 // registered callback and schedules the next read. |
| 56 void ReadAudio(); | 56 void ReadAudio(); |
| 57 | 57 |
| 58 // Recovers from any device errors if possible. | 58 // Recovers from any device errors if possible. |
| 59 bool Recover(int error); | 59 bool Recover(int error); |
| 60 | 60 |
| 61 // Utility function for talking with the ALSA API. | 61 // Utility function for talking with the ALSA API. |
| 62 snd_pcm_sframes_t GetCurrentDelay(); | 62 snd_pcm_sframes_t GetCurrentDelay(); |
| 63 | 63 |
| 64 // Non-refcounted pointer back to the audio manager. | 64 // Non-refcounted pointer back to the audio manager. |
| 65 // The AudioManager indirectly holds on to stream objects, so we don't | 65 // The AudioManager indirectly holds on to stream objects, so we don't |
| 66 // want circular references. Additionally, stream objects live on the audio | 66 // want circular references. Additionally, stream objects live on the audio |
| 67 // thread, which is owned by the audio manager and we don't want to addref | 67 // thread, which is owned by the audio manager and we don't want to addref |
| 68 // the manager from that thread. | 68 // the manager from that thread. |
| 69 AudioManagerLinux* audio_manager_; | 69 AudioManagerLinux* audio_manager_; |
| 70 std::string device_name_; | 70 std::string device_name_; |
| 71 AudioParameters params_; | 71 AudioParameters params_; |
| 72 int bytes_per_packet_; | 72 int bytes_per_buffer_; |
| 73 AlsaWrapper* wrapper_; | 73 AlsaWrapper* wrapper_; |
| 74 int packet_duration_ms_; // Length of each recorded packet in milliseconds. | 74 int buffer_duration_ms_; // Length of each recorded buffer in milliseconds. |
| 75 AudioInputCallback* callback_; // Valid during a recording session. | 75 AudioInputCallback* callback_; // Valid during a recording session. |
| 76 base::Time next_read_time_; // Scheduled time for the next read callback. | 76 base::Time next_read_time_; // Scheduled time for the next read callback. |
| 77 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. | 77 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. |
| 78 snd_mixer_t* mixer_handle_; // Handle to the ALSA microphone mixer. | 78 snd_mixer_t* mixer_handle_; // Handle to the ALSA microphone mixer. |
| 79 snd_mixer_elem_t* mixer_element_handle_; // Handle to the capture element. | 79 snd_mixer_elem_t* mixer_element_handle_; // Handle to the capture element. |
| 80 base::WeakPtrFactory<AlsaPcmInputStream> weak_factory_; | 80 base::WeakPtrFactory<AlsaPcmInputStream> weak_factory_; |
| 81 scoped_array<uint8> audio_packet_; // Buffer used for reading audio data. | 81 scoped_array<uint8> audio_buffer_; // Buffer used for reading audio data. |
| 82 bool read_callback_behind_schedule_; | 82 bool read_callback_behind_schedule_; |
| 83 | 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream); | 84 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ | 87 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ |
| OLD | NEW |