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

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

Issue 275022: Move Alsa device opening into the audio thread, and add in support for multi-channel audio. (Closed)
Patch Set: Fix up the unittests since we not only downmix for a very small set of channels. Created 11 years, 2 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_output.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/linux/alsa_output.h
diff --git a/media/audio/linux/alsa_output.h b/media/audio/linux/alsa_output.h
index 409b1582aa8e04dec28f091d5ad9ebbb9af8f450..5bdaa1b2958fda35b399b987943250465d18261a 100644
--- a/media/audio/linux/alsa_output.h
+++ b/media/audio/linux/alsa_output.h
@@ -46,18 +46,27 @@ class AlsaPcmOutputStream :
public AudioOutputStream,
public base::RefCountedThreadSafe<AlsaPcmOutputStream> {
public:
- // Set to "default" which should avoid locking the sound device and allow
- // ALSA to multiplex sound from different processes that want to write PCM
- // data.
+ // String for the generic "default" ALSA device that has the highest
+ // compatibility and chance of working.
static const char kDefaultDevice[];
+ // Pass this to the AlsaPcmOutputStream if you want to attempt auto-selection
+ // of the audio device.
+ static const char kAutoSelectDevice[];
+
+ // Prefix for device names to enable ALSA library resampling.
+ static const char kPlugPrefix[];
+
+ // The minimum latency that is accepted by the device.
+ static const int kMinLatencyMicros;
+
// Create a PCM Output stream for the ALSA device identified by
// |device_name|. The AlsaPcmOutputStream uses |wrapper| to communicate with
// the alsa libraries, allowing for dependency injection during testing. All
// requesting of data, and writing to the alsa device will be done on
// |message_loop|.
//
- // If unsure of what to use for |device_name|, use |kDefaultDevice|.
+ // If unsure of what to use for |device_name|, use |kAutoSelectDevice|.
AlsaPcmOutputStream(const std::string& device_name,
AudioManager::Format format,
int channels,
@@ -78,10 +87,14 @@ class AlsaPcmOutputStream :
private:
friend class AlsaPcmOutputStreamTest;
+ FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect);
+ FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_FallbackDevices);
+ FRIEND_TEST(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail);
FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket);
FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_StopStream);
FRIEND_TEST(AlsaPcmOutputStreamTest, BufferPacket_UnfinishedPacket);
FRIEND_TEST(AlsaPcmOutputStreamTest, ConstructedState);
+ FRIEND_TEST(AlsaPcmOutputStreamTest, LatencyFloor);
FRIEND_TEST(AlsaPcmOutputStreamTest, OpenClose);
FRIEND_TEST(AlsaPcmOutputStreamTest, PcmOpenFailed);
FRIEND_TEST(AlsaPcmOutputStreamTest, PcmSetParamsFailed);
@@ -121,7 +134,7 @@ class AlsaPcmOutputStream :
friend std::ostream& ::operator<<(std::ostream& os, InternalState);
// Various tasks that complete actions started in the public API.
- void FinishOpen(snd_pcm_t* playback_handle, size_t packet_size);
+ void OpenTask(size_t packet_size);
void StartTask();
void CloseTask();
@@ -137,9 +150,17 @@ class AlsaPcmOutputStream :
int bytes_per_frame);
static int64 FramesToMicros(int frames, int sample_rate);
static int64 FramesToMillis(int frames, int sample_rate);
+ std::string FindDeviceForChannels(int channels);
+ snd_pcm_t* OpenDevice(const std::string& device_name,
+ int channels,
+ unsigned int latency);
bool CloseDevice(snd_pcm_t* handle);
snd_pcm_sframes_t GetAvailableFrames();
+ // Attempts to find the best matching linux audio device for the given number
+ // of channels. This function will set |device_name_| and |should_downmix_|.
+ snd_pcm_t* AutoSelectDevice(unsigned int latency);
+
// Thread-asserting accessors for member variables.
AudioManagerLinux* manager();
@@ -192,13 +213,20 @@ class AlsaPcmOutputStream :
// Configuration constants from the constructor. Referenceable by all threads
// since they are constants.
- const std::string device_name_;
+ const std::string requested_device_name_;
const snd_pcm_format_t pcm_format_;
const int channels_;
const int sample_rate_;
const int bytes_per_sample_;
const int bytes_per_frame_;
+ // Device configuration data. Populated after OpenTask() completes.
+ std::string device_name_;
+ bool should_downmix_;
+ int latency_micros_;
+ int micros_per_packet_;
+ int bytes_per_output_frame_;
+
// Flag indicating the code should stop reading from the data source or
// writing to the ALSA device. This is set because the device has entered
// an unrecoverable error state, or the ClosedTask() has executed.
« no previous file with comments | « no previous file | media/audio/linux/alsa_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698