Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: media/audio/linux/alsa_input.h

Issue 4661001: Simplified AudioOutputStream interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #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 12 matching lines...) Expand all
23 public: 23 public:
24 // Pass this to the constructor if you want to attempt auto-selection 24 // Pass this to the constructor if you want to attempt auto-selection
25 // of the audio recording device. 25 // of the audio recording device.
26 static const char* kAutoSelectDevice; 26 static const char* kAutoSelectDevice;
27 27
28 // Create a PCM Output stream for the ALSA device identified by 28 // Create a PCM Output stream for the ALSA device identified by
29 // |device_name|. If unsure of what to use for |device_name|, use 29 // |device_name|. If unsure of what to use for |device_name|, use
30 // |kAutoSelectDevice|. 30 // |kAutoSelectDevice|.
31 AlsaPcmInputStream(const std::string& device_name, 31 AlsaPcmInputStream(const std::string& device_name,
32 const AudioParameters& params, 32 const AudioParameters& params,
33 int samples_per_packet,
34 AlsaWrapper* wrapper); 33 AlsaWrapper* wrapper);
35 virtual ~AlsaPcmInputStream(); 34 virtual ~AlsaPcmInputStream();
36 35
37 // Implementation of AudioOutputStream. 36 // Implementation of AudioOutputStream.
38 virtual bool Open(); 37 virtual bool Open();
39 virtual void Start(AudioInputCallback* callback); 38 virtual void Start(AudioInputCallback* callback);
40 virtual void Stop(); 39 virtual void Stop();
41 virtual void Close(); 40 virtual void Close();
42 41
43 private: 42 private:
44 // Logs the error and invokes any registered callbacks. 43 // Logs the error and invokes any registered callbacks.
45 void HandleError(const char* method, int error); 44 void HandleError(const char* method, int error);
46 45
47 // Reads one or more packets of audio from the device, passes on to the 46 // Reads one or more packets of audio from the device, passes on to the
48 // registered callback and schedules the next read. 47 // registered callback and schedules the next read.
49 void ReadAudio(); 48 void ReadAudio();
50 49
51 // Recovers from any device errors if possible. 50 // Recovers from any device errors if possible.
52 bool Recover(int error); 51 bool Recover(int error);
53 52
54 std::string device_name_; 53 std::string device_name_;
55 AudioParameters params_; 54 AudioParameters params_;
56 int samples_per_packet_;
57 int bytes_per_packet_; 55 int bytes_per_packet_;
58 AlsaWrapper* wrapper_; 56 AlsaWrapper* wrapper_;
59 int packet_duration_ms_; // Length of each recorded packet in milliseconds. 57 int packet_duration_ms_; // Length of each recorded packet in milliseconds.
60 AudioInputCallback* callback_; // Valid during a recording session. 58 AudioInputCallback* callback_; // Valid during a recording session.
61 base::Time next_read_time_; // Scheduled time for the next read callback. 59 base::Time next_read_time_; // Scheduled time for the next read callback.
62 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. 60 snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device.
63 ScopedRunnableMethodFactory<AlsaPcmInputStream> task_factory_; 61 ScopedRunnableMethodFactory<AlsaPcmInputStream> task_factory_;
64 scoped_ptr<uint8> audio_packet_; // Data buffer used for reading audio data. 62 scoped_ptr<uint8> audio_packet_; // Data buffer used for reading audio data.
65 63
66 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream); 64 DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream);
67 }; 65 };
68 66
69 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_ 67 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698