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> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
16 #include "media/audio/audio_parameters.h" | 16 #include "media/audio/audio_parameters.h" |
17 | 17 |
18 class AlsaWrapper; | 18 class AlsaWrapper; |
19 class AudioManagerLinux; | |
19 | 20 |
20 // Provides an input stream for audio capture based on the ALSA PCM interface. | 21 // Provides an input stream for audio capture based on the ALSA PCM interface. |
21 // This object is not thread safe and all methods should be invoked in the | 22 // This object is not thread safe and all methods should be invoked in the |
22 // thread that created the object. | 23 // thread that created the object. |
23 class AlsaPcmInputStream : public AudioInputStream { | 24 class AlsaPcmInputStream : public AudioInputStream { |
24 public: | 25 public: |
25 // Pass this to the constructor if you want to attempt auto-selection | 26 // Pass this to the constructor if you want to attempt auto-selection |
26 // of the audio recording device. | 27 // of the audio recording device. |
27 static const char* kAutoSelectDevice; | 28 static const char* kAutoSelectDevice; |
28 | 29 |
29 // Create a PCM Output stream for the ALSA device identified by | 30 // Create a PCM Output stream for the ALSA device identified by |
30 // |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 |
31 // |kAutoSelectDevice|. | 32 // |kAutoSelectDevice|. |
32 AlsaPcmInputStream(const std::string& device_name, | 33 AlsaPcmInputStream(AudioManagerLinux* audio_manager, |
34 const std::string& device_name, | |
33 const AudioParameters& params, | 35 const AudioParameters& params, |
34 AlsaWrapper* wrapper); | 36 AlsaWrapper* wrapper); |
35 virtual ~AlsaPcmInputStream(); | 37 virtual ~AlsaPcmInputStream(); |
36 | 38 |
37 // Implementation of AudioOutputStream. | 39 // Implementation of AudioOutputStream. |
38 virtual bool Open() OVERRIDE; | 40 virtual bool Open() OVERRIDE; |
39 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 41 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
40 virtual void Stop() OVERRIDE; | 42 virtual void Stop() OVERRIDE; |
41 virtual void Close() OVERRIDE; | 43 virtual void Close() OVERRIDE; |
42 | 44 |
43 private: | 45 private: |
44 // Logs the error and invokes any registered callbacks. | 46 // Logs the error and invokes any registered callbacks. |
45 void HandleError(const char* method, int error); | 47 void HandleError(const char* method, int error); |
46 | 48 |
47 // Reads one or more packets of audio from the device, passes on to the | 49 // Reads one or more packets of audio from the device, passes on to the |
48 // registered callback and schedules the next read. | 50 // registered callback and schedules the next read. |
49 void ReadAudio(); | 51 void ReadAudio(); |
50 | 52 |
51 // Recovers from any device errors if possible. | 53 // Recovers from any device errors if possible. |
52 bool Recover(int error); | 54 bool Recover(int error); |
53 | 55 |
54 // Utility function for talking with the ALSA API. | 56 // Utility function for talking with the ALSA API. |
55 snd_pcm_sframes_t GetCurrentDelay(); | 57 snd_pcm_sframes_t GetCurrentDelay(); |
56 | 58 |
59 AudioManagerLinux* audio_manager_; | |
scherkus (not reviewing)
2011/12/09 22:47:30
document that this is not reffed?
tommi (sloooow) - chröme
2011/12/10 00:11:14
Done.
| |
57 std::string device_name_; | 60 std::string device_name_; |
58 AudioParameters params_; | 61 AudioParameters params_; |
59 int bytes_per_packet_; | 62 int bytes_per_packet_; |
60 AlsaWrapper* wrapper_; | 63 AlsaWrapper* wrapper_; |
61 int packet_duration_ms_; // Length of each recorded packet in milliseconds. | 64 int packet_duration_ms_; // Length of each recorded packet in milliseconds. |
62 AudioInputCallback* callback_; // Valid during a recording session. | 65 AudioInputCallback* callback_; // Valid during a recording session. |
63 base::Time next_read_time_; // Scheduled time for the next read callback. | 66 base::Time next_read_time_; // Scheduled time for the next read callback. |
64 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. | 67 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. |
65 base::WeakPtrFactory<AlsaPcmInputStream> weak_factory_; | 68 base::WeakPtrFactory<AlsaPcmInputStream> weak_factory_; |
66 scoped_array<uint8> audio_packet_; // Buffer used for reading audio data. | 69 scoped_array<uint8> audio_packet_; // Buffer used for reading audio data. |
67 bool read_callback_behind_schedule_; | 70 bool read_callback_behind_schedule_; |
68 | 71 |
69 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream); | 72 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream); |
70 }; | 73 }; |
71 | 74 |
72 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ | 75 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ |
OLD | NEW |