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

Unified Diff: media/audio/linux/alsa_input.h

Issue 3299005: Implement audio recording for Linux via ALSA. (Closed)
Patch Set: . Created 10 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/audio/linux/alsa_input.cc » ('j') | media/audio/linux/alsa_util.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/linux/alsa_input.h
diff --git a/media/audio/linux/alsa_input.h b/media/audio/linux/alsa_input.h
new file mode 100644
index 0000000000000000000000000000000000000000..9a326e42eaa0aa602fa82457c42e6d8a276f3a2e
--- /dev/null
+++ b/media/audio/linux/alsa_input.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_LINUX_ALSA_INPUT_H_
+#define MEDIA_AUDIO_LINUX_ALSA_INPUT_H_
+
+#include <alsa/asoundlib.h>
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+#include "media/audio/audio_io.h"
+#include "media/audio/audio_parameters.h"
+
+class AlsaWrapper;
+
+// Provides an input stream for audio capture based on the ALSA PCM interface.
+// This object is not thread safe and all methods should be invoked in the
+// thread that created the object.
+class AlsaPcmInputStream : public AudioInputStream {
+ public:
+ // Pass this to the constructor if you want to attempt auto-selection
+ // of the audio recording device.
+ static const char* kAutoSelectDevice;
+
+ // Create a PCM Output stream for the ALSA device identified by
+ // |device_name|. If unsure of what to use for |device_name|, use
+ // |kAutoSelectDevice|.
+ AlsaPcmInputStream(const std::string& device_name,
+ const AudioParameters& params,
+ int samples_per_packet,
+ AlsaWrapper* wrapper);
+
+ // Implementation of AudioOutputStream.
+ virtual bool Open();
+ virtual void Start(AudioInputCallback* callback);
+ virtual void Stop();
+ virtual void Close();
+
+ private:
+ // Logs the error and invokes any registered callbacks.
+ void HandleError(const char* method, int error);
+
+ // Reads one or more packets of audio from the device, passes on to the
+ // registered callback and schedules the next read.
+ void ReadAudio();
+
+ // Recovers from any device errors if possible.
+ bool Recover(int error);
+
+ std::string device_name_;
+ AudioParameters params_;
+ int samples_per_packet_;
+ int bytes_per_packet_;
+ AlsaWrapper* wrapper_;
+ int packet_duration_ms_; // Length of each recorded packet in milliseconds.
+ AudioInputCallback* callback_; // Valid during a recording session.
+ base::Time next_read_time_; // Scheduled time for the next read callback.
+ snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device.
+ ScopedRunnableMethodFactory<AlsaPcmInputStream> task_factory_;
+ scoped_ptr<uint8> audio_packet_; // Data buffer used for reading audio data.
+
+ DISALLOW_COPY_AND_ASSIGN(AlsaPcmInputStream);
+};
+
+#endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_
« no previous file with comments | « no previous file | media/audio/linux/alsa_input.cc » ('j') | media/audio/linux/alsa_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698