diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 06:39:06 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 06:39:06 +0000 |
commit | f6eeded10a75632e1bc5ecaad9be46553c4ab908 (patch) | |
tree | 8a400e987cd72f1a4b799ce086f3d4169d87b0e9 /media/audio/linux | |
parent | 29a984ff619eb0bdd27bc612bed55f6146cce4fe (diff) | |
download | chromium_src-f6eeded10a75632e1bc5ecaad9be46553c4ab908.zip chromium_src-f6eeded10a75632e1bc5ecaad9be46553c4ab908.tar.gz chromium_src-f6eeded10a75632e1bc5ecaad9be46553c4ab908.tar.bz2 |
Remove size_t from audio IPC code.
The change got to this size because I had to modify the surrounding code (I didn't want to just cast at the last minute).
Review URL: http://codereview.chromium.org/577006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38192 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/linux')
-rw-r--r-- | media/audio/linux/alsa_output.cc | 66 | ||||
-rw-r--r-- | media/audio/linux/alsa_output.h | 57 | ||||
-rw-r--r-- | media/audio/linux/alsa_output_unittest.cc | 14 |
3 files changed, 68 insertions, 69 deletions
diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc index d878a74..8971ca6 100644 --- a/media/audio/linux/alsa_output.cc +++ b/media/audio/linux/alsa_output.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. // @@ -86,12 +86,12 @@ // Amount of time to wait if we've exhausted the data source. This is to avoid // busy looping. -static const int kNoDataSleepMilliseconds = 10; +static const uint32 kNoDataSleepMilliseconds = 10; // According to the linux nanosleep manpage, nanosleep on linux can miss the // deadline by up to 10ms because the kernel timeslice is 10ms. Give a 2x // buffer to compensate for the timeslice, and any additional slowdowns. -static const int kSleepErrorMilliseconds = 20; +static const uint32 kSleepErrorMilliseconds = 20; // Set to 0 during debugging if you want error messages due to underrun // events or other recoverable errors. @@ -107,14 +107,14 @@ const char AlsaPcmOutputStream::kPlugPrefix[] = "plug:"; // Since we expect to only be able to wake up with a resolution of // kSleepErrorMilliseconds, double that for our minimum required latency. -const int AlsaPcmOutputStream::kMinLatencyMicros = +const uint32 AlsaPcmOutputStream::kMinLatencyMicros = kSleepErrorMilliseconds * 2 * 1000; namespace { // ALSA is currently limited to 48Khz. // TODO(fbarchard): Resample audio from higher frequency to 48000. -const int kMaxSampleRate = 48000; +const uint32 kMaxSampleRate = 48000; snd_pcm_format_t BitsToFormat(char bits_per_sample) { switch (bits_per_sample) { @@ -152,7 +152,7 @@ snd_pcm_format_t BitsToFormat(char bits_per_sample) { // TODO(ajwong): The source data should have enough info to tell us if we want // surround41 versus surround51, etc., instead of needing us to guess base don // channel number. Fix API to pass that data down. -const char* GuessSpecificDeviceName(int channels) { +const char* GuessSpecificDeviceName(uint32 channels) { switch (channels) { case 8: return "surround71"; @@ -177,10 +177,10 @@ const char* GuessSpecificDeviceName(int channels) { // Reorder PCM from AAC layout to Alsa layout. // TODO(fbarchard): Switch layout when ffmpeg is updated. template<class Format> -static void Swizzle50Layout(Format* b, size_t filled) { - static const int kNumSurroundChannels = 5; +static void Swizzle50Layout(Format* b, uint32 filled) { + static const uint32 kNumSurroundChannels = 5; Format aac[kNumSurroundChannels]; - for (size_t i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { + for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { memcpy(aac, b, sizeof(aac)); b[0] = aac[1]; // L b[1] = aac[2]; // R @@ -191,10 +191,10 @@ static void Swizzle50Layout(Format* b, size_t filled) { } template<class Format> -static void Swizzle51Layout(Format* b, size_t filled) { - static const int kNumSurroundChannels = 6; +static void Swizzle51Layout(Format* b, uint32 filled) { + static const uint32 kNumSurroundChannels = 6; Format aac[kNumSurroundChannels]; - for (size_t i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { + for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { memcpy(aac, b, sizeof(aac)); b[0] = aac[1]; // L b[1] = aac[2]; // R @@ -235,9 +235,9 @@ std::ostream& operator<<(std::ostream& os, AlsaPcmOutputStream::AlsaPcmOutputStream(const std::string& device_name, AudioManager::Format format, - int channels, - int sample_rate, - int bits_per_sample, + uint32 channels, + uint32 sample_rate, + uint32 bits_per_sample, AlsaWrapper* wrapper, AudioManagerLinux* manager, MessageLoop* message_loop) @@ -287,7 +287,7 @@ AlsaPcmOutputStream::~AlsaPcmOutputStream() { // where the stream is not always stopped and closed, causing this to fail. } -bool AlsaPcmOutputStream::Open(size_t packet_size) { +bool AlsaPcmOutputStream::Open(uint32 packet_size) { DCHECK_EQ(MessageLoop::current(), client_thread_loop_); DCHECK_EQ(0U, packet_size % bytes_per_frame_) @@ -371,7 +371,7 @@ void AlsaPcmOutputStream::GetVolume(double* volume) { *volume = shared_data_.volume(); } -void AlsaPcmOutputStream::OpenTask(size_t packet_size) { +void AlsaPcmOutputStream::OpenTask(uint32 packet_size) { DCHECK_EQ(MessageLoop::current(), message_loop_); // Initialize the configuration variables. @@ -434,8 +434,8 @@ void AlsaPcmOutputStream::StartTask() { // the maximum number of full packets that can fit into the buffer. // // TODO(ajwong): Handle EAGAIN. - const int num_preroll = latency_micros_ / micros_per_packet_; - for (int i = 0; i < num_preroll; ++i) { + const uint32 num_preroll = latency_micros_ / micros_per_packet_; + for (uint32 i = 0; i < num_preroll; ++i) { BufferPacket(packet_.get()); WritePacket(packet_.get()); } @@ -621,12 +621,12 @@ void AlsaPcmOutputStream::ScheduleNextWrite(Packet* current_packet) { // Calculate when we should have enough buffer for another packet of data. // Make sure to take into consideration down-mixing. - int frames_leftover = + uint32 frames_leftover = FramesInPacket(*current_packet, bytes_per_output_frame_); - int frames_avail_wanted = + uint32 frames_avail_wanted = (frames_leftover > 0) ? frames_leftover : frames_per_packet_; - int frames_until_empty_enough = frames_avail_wanted - GetAvailableFrames(); - int next_fill_time_ms = + uint32 frames_until_empty_enough = frames_avail_wanted - GetAvailableFrames(); + uint32 next_fill_time_ms = FramesToMillis(frames_until_empty_enough, sample_rate_); // Adjust for timer resolution issues. @@ -659,20 +659,20 @@ void AlsaPcmOutputStream::ScheduleNextWrite(Packet* current_packet) { } } -snd_pcm_sframes_t AlsaPcmOutputStream::FramesInPacket(const Packet& packet, - int bytes_per_frame) { +uint32 AlsaPcmOutputStream::FramesInPacket(const Packet& packet, + uint32 bytes_per_frame) { return (packet.size - packet.used) / bytes_per_frame; } -int64 AlsaPcmOutputStream::FramesToMicros(int frames, int sample_rate) { +uint32 AlsaPcmOutputStream::FramesToMicros(uint32 frames, uint32 sample_rate) { return frames * base::Time::kMicrosecondsPerSecond / sample_rate; } -int64 AlsaPcmOutputStream::FramesToMillis(int frames, int sample_rate) { +uint32 AlsaPcmOutputStream::FramesToMillis(uint32 frames, uint32 sample_rate) { return frames * base::Time::kMillisecondsPerSecond / sample_rate; } -std::string AlsaPcmOutputStream::FindDeviceForChannels(int channels) { +std::string AlsaPcmOutputStream::FindDeviceForChannels(uint32 channels) { // Constants specified by the ALSA API for device hints. static const int kGetAllDevices = -1; static const char kPcmInterfaceName[] = "pcm"; @@ -721,7 +721,7 @@ std::string AlsaPcmOutputStream::FindDeviceForChannels(int channels) { } snd_pcm_t* AlsaPcmOutputStream::OpenDevice(const std::string& device_name, - int channels, + uint32 channels, unsigned int latency) { snd_pcm_t* handle = NULL; int error = wrapper_->PcmOpen(&handle, device_name.c_str(), @@ -822,7 +822,7 @@ snd_pcm_t* AlsaPcmOutputStream::AutoSelectDevice(unsigned int latency) { // downmixing. // // TODO(ajwong): We need a SupportsFolding() function. - int default_channels = channels_; + uint32 default_channels = channels_; if (default_channels >= 5 && default_channels <= 6) { should_downmix_ = true; default_channels = 2; @@ -921,10 +921,10 @@ void AlsaPcmOutputStream::SharedData::set_volume(float v) { volume_ = v; } -size_t AlsaPcmOutputStream::SharedData::OnMoreData(AudioOutputStream* stream, +uint32 AlsaPcmOutputStream::SharedData::OnMoreData(AudioOutputStream* stream, void* dest, - size_t max_size, - int pending_bytes) { + uint32 max_size, + uint32 pending_bytes) { AutoLock l(lock_); if (source_callback_) { return source_callback_->OnMoreData(stream, dest, max_size, pending_bytes); diff --git a/media/audio/linux/alsa_output.h b/media/audio/linux/alsa_output.h index 8aa0af3..240076a 100644 --- a/media/audio/linux/alsa_output.h +++ b/media/audio/linux/alsa_output.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. // @@ -58,7 +58,7 @@ class AlsaPcmOutputStream : static const char kPlugPrefix[]; // The minimum latency that is accepted by the device. - static const int kMinLatencyMicros; + static const uint32 kMinLatencyMicros; // Create a PCM Output stream for the ALSA device identified by // |device_name|. The AlsaPcmOutputStream uses |wrapper| to communicate with @@ -69,15 +69,15 @@ class AlsaPcmOutputStream : // If unsure of what to use for |device_name|, use |kAutoSelectDevice|. AlsaPcmOutputStream(const std::string& device_name, AudioManager::Format format, - int channels, - int sample_rate, - int bits_per_sample, + uint32 channels, + uint32 sample_rate, + uint32 bits_per_sample, AlsaWrapper* wrapper, AudioManagerLinux* manager, MessageLoop* message_loop); // Implementation of AudioOutputStream. - virtual bool Open(size_t packet_size); + virtual bool Open(uint32 packet_size); virtual void Close(); virtual void Start(AudioSourceCallback* callback); virtual void Stop(); @@ -112,15 +112,15 @@ class AlsaPcmOutputStream : // TODO(ajwong): There are now about 3 buffer/packet implementations. Factor // them out. struct Packet { - explicit Packet(int new_capacity) + explicit Packet(uint32 new_capacity) : capacity(new_capacity), size(0), used(0), buffer(new char[capacity]) { } - size_t capacity; - size_t size; - size_t used; + uint32 capacity; + uint32 size; + uint32 used; scoped_array<char> buffer; }; @@ -136,7 +136,7 @@ class AlsaPcmOutputStream : friend std::ostream& ::operator<<(std::ostream& os, InternalState); // Various tasks that complete actions started in the public API. - void OpenTask(size_t packet_size); + void OpenTask(uint32 packet_size); void StartTask(); void CloseTask(); @@ -148,20 +148,19 @@ class AlsaPcmOutputStream : void ScheduleNextWrite(Packet* current_packet); // Utility functions for talking with the ALSA API. - static snd_pcm_sframes_t FramesInPacket(const Packet& packet, - 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); + static uint32 FramesInPacket(const Packet& packet, uint32 bytes_per_frame); + static uint32 FramesToMicros(uint32 frames, uint32 sample_rate); + static uint32 FramesToMillis(uint32 frames, uint32 sample_rate); + std::string FindDeviceForChannels(uint32 channels); snd_pcm_t* OpenDevice(const std::string& device_name, - int channels, - unsigned int latency); + uint32 channels, + uint32 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); + snd_pcm_t* AutoSelectDevice(uint32 latency); // Thread-asserting accessors for member variables. AudioManagerLinux* manager(); @@ -191,8 +190,8 @@ class AlsaPcmOutputStream : // is passed into the output stream, but ownership is not transfered which // requires a synchronization on access of the |source_callback_| to avoid // using a deleted callback. - size_t OnMoreData(AudioOutputStream* stream, void* dest, - size_t max_size, int pending_bytes); + uint32 OnMoreData(AudioOutputStream* stream, void* dest, + uint32 max_size, uint32 pending_bytes); void OnClose(AudioOutputStream* stream); void OnError(AudioOutputStream* stream, int code); @@ -217,17 +216,17 @@ class AlsaPcmOutputStream : // since they are constants. 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_; + const uint32 channels_; + const uint32 sample_rate_; + const uint32 bytes_per_sample_; + const uint32 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_; + uint32 latency_micros_; + uint32 micros_per_packet_; + uint32 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 @@ -246,7 +245,7 @@ class AlsaPcmOutputStream : snd_pcm_t* playback_handle_; scoped_ptr<Packet> packet_; - int frames_per_packet_; + uint32 frames_per_packet_; // Used to check which message loop is allowed to call the public APIs. MessageLoop* client_thread_loop_; diff --git a/media/audio/linux/alsa_output_unittest.cc b/media/audio/linux/alsa_output_unittest.cc index b426301..3dcc610 100644 --- a/media/audio/linux/alsa_output_unittest.cc +++ b/media/audio/linux/alsa_output_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -53,8 +53,8 @@ class MockAlsaWrapper : public AlsaWrapper { class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { public: - MOCK_METHOD4(OnMoreData, size_t(AudioOutputStream* stream, void* dest, - size_t max_size, int pending_bytes)); + MOCK_METHOD4(OnMoreData, uint32(AudioOutputStream* stream, void* dest, + uint32 max_size, uint32 pending_bytes)); MOCK_METHOD1(OnClose, void(AudioOutputStream* stream)); MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code)); }; @@ -112,8 +112,8 @@ class AlsaPcmOutputStreamTest : public testing::Test { static const AudioManager::Format kTestFormat; static const char kTestDeviceName[]; static const char kDummyMessage[]; - static const int kTestFramesPerPacket; - static const size_t kTestPacketSize; + static const uint32 kTestFramesPerPacket; + static const uint32 kTestPacketSize; static const int kTestFailedErrno; static snd_pcm_t* const kFakeHandle; @@ -147,8 +147,8 @@ const AudioManager::Format AlsaPcmOutputStreamTest::kTestFormat = AudioManager::AUDIO_PCM_LINEAR; const char AlsaPcmOutputStreamTest::kTestDeviceName[] = "TestDevice"; const char AlsaPcmOutputStreamTest::kDummyMessage[] = "dummy"; -const int AlsaPcmOutputStreamTest::kTestFramesPerPacket = 1000; -const size_t AlsaPcmOutputStreamTest::kTestPacketSize = +const uint32 AlsaPcmOutputStreamTest::kTestFramesPerPacket = 1000; +const uint32 AlsaPcmOutputStreamTest::kTestPacketSize = AlsaPcmOutputStreamTest::kTestFramesPerPacket * AlsaPcmOutputStreamTest::kTestBytesPerFrame; const int AlsaPcmOutputStreamTest::kTestFailedErrno = -EACCES; |