summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/audio_output_controller.cc4
-rw-r--r--media/audio/audio_output_controller.h4
-rw-r--r--media/audio/audio_output_device.cc3
-rw-r--r--media/audio/audio_output_device_unittest.cc2
-rw-r--r--media/audio/audio_util.cc59
-rw-r--r--media/audio/audio_util.h15
-rw-r--r--media/audio/shared_memory_util.cc70
-rw-r--r--media/audio/shared_memory_util.h39
8 files changed, 115 insertions, 81 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc
index 60dd285..69b7797 100644
--- a/media/audio/audio_output_controller.cc
+++ b/media/audio/audio_output_controller.cc
@@ -11,6 +11,7 @@
#include "base/threading/platform_thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/time.h"
+#include "media/audio/shared_memory_util.h"
using base::Time;
using base::TimeDelta;
@@ -18,9 +19,6 @@ using base::WaitableEvent;
namespace media {
-// Signal a pause in low-latency mode.
-const int AudioOutputController::kPauseMark = -1;
-
// Polling-related constants.
const int AudioOutputController::kPollNumAttempts = 3;
const int AudioOutputController::kPollPauseInMilliseconds = 3;
diff --git a/media/audio/audio_output_controller.h b/media/audio/audio_output_controller.h
index a8857a2..03b0959 100644
--- a/media/audio/audio_output_controller.h
+++ b/media/audio/audio_output_controller.h
@@ -68,10 +68,6 @@ class MEDIA_EXPORT AudioOutputController
: public base::RefCountedThreadSafe<AudioOutputController>,
public AudioOutputStream::AudioSourceCallback {
public:
- // Value sent by the controller to the renderer in low-latency mode
- // indicating that the stream is paused.
- static const int kPauseMark;
-
// An event handler that receives events from the AudioOutputController. The
// following methods are called on the audio manager thread.
class MEDIA_EXPORT EventHandler {
diff --git a/media/audio/audio_output_device.cc b/media/audio/audio_output_device.cc
index 994fa40..da86f97 100644
--- a/media/audio/audio_output_device.cc
+++ b/media/audio/audio_output_device.cc
@@ -10,6 +10,7 @@
#include "base/time.h"
#include "media/audio/audio_output_controller.h"
#include "media/audio/audio_util.h"
+#include "media/audio/shared_memory_util.h"
namespace media {
@@ -253,7 +254,7 @@ void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() {
// Called whenever we receive notifications about pending data.
void AudioOutputDevice::AudioThreadCallback::Process(int pending_data) {
- if (pending_data == AudioOutputController::kPauseMark) {
+ if (pending_data == kPauseMark) {
memset(shared_memory_.memory(), 0, memory_length_);
SetActualDataSizeInBytes(&shared_memory_, memory_length_, 0);
return;
diff --git a/media/audio/audio_output_device_unittest.cc b/media/audio/audio_output_device_unittest.cc
index 152e958..14a7a35 100644
--- a/media/audio/audio_output_device_unittest.cc
+++ b/media/audio/audio_output_device_unittest.cc
@@ -11,8 +11,8 @@
#include "base/sync_socket.h"
#include "base/test/test_timeouts.h"
#include "media/audio/audio_output_device.h"
-#include "media/audio/audio_util.h"
#include "media/audio/sample_rates.h"
+#include "media/audio/shared_memory_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index d54f277..1dabae9 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -12,16 +12,15 @@
// that a lot of the functions can be simplified and made more elegant. Revisit
// after other audio cleanup is done. (crbug.com/120319)
+#include "media/audio/audio_util.h"
+
#include <algorithm>
#include <limits>
-#include "base/atomicops.h"
#include "base/basictypes.h"
#include "base/logging.h"
-#include "base/shared_memory.h"
#include "base/time.h"
#include "media/audio/audio_parameters.h"
-#include "media/audio/audio_util.h"
#include "media/base/audio_bus.h"
#if defined(OS_MACOSX)
@@ -36,10 +35,6 @@
#include "media/base/media_switches.h"
#endif
-using base::subtle::Atomic32;
-
-const uint32 kUnknownDataSize = static_cast<uint32>(-1);
-
namespace media {
// TODO(fbarchard): Convert to intrinsics for better efficiency.
@@ -483,56 +478,6 @@ size_t GetHighLatencyOutputBufferSize(int sample_rate) {
return samples;
}
-// When transferring data in the shared memory, first word is size of data
-// in bytes. Actual data starts immediately after it.
-
-uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) {
- // Need to reserve extra 4 bytes for size of data.
- return packet_size + sizeof(Atomic32);
-}
-
-uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) {
- return shared_memory_created_size - sizeof(Atomic32);
-}
-
-uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory,
- uint32 shared_memory_size) {
- char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
- DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
-
- // Actual data size stored at the end of the buffer.
- uint32 actual_data_size =
- base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
- return std::min(actual_data_size, shared_memory_size);
-}
-
-void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
- uint32 shared_memory_size,
- uint32 actual_data_size) {
- char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
- DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
-
- // Set actual data size at the end of the buffer.
- base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr),
- actual_data_size);
-}
-
-void SetUnknownDataSize(base::SharedMemory* shared_memory,
- uint32 shared_memory_size) {
- SetActualDataSizeInBytes(shared_memory, shared_memory_size, kUnknownDataSize);
-}
-
-bool IsUnknownDataSize(base::SharedMemory* shared_memory,
- uint32 shared_memory_size) {
- char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
- DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
-
- // Actual data size stored at the end of the buffer.
- uint32 actual_data_size =
- base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
- return actual_data_size == kUnknownDataSize;
-}
-
#if defined(OS_WIN)
bool IsWASAPISupported() {
diff --git a/media/audio/audio_util.h b/media/audio/audio_util.h
index d25fdf9..b329be1 100644
--- a/media/audio/audio_util.h
+++ b/media/audio/audio_util.h
@@ -111,21 +111,6 @@ MEDIA_EXPORT ChannelLayout GetAudioInputHardwareChannelLayout(
// conjunction with AUDIO_PCM_LINEAR.
MEDIA_EXPORT size_t GetHighLatencyOutputBufferSize(int sample_rate);
-// Functions that handle data buffer passed between processes in the shared
-// memory. Called on both IPC sides.
-
-MEDIA_EXPORT uint32 TotalSharedMemorySizeInBytes(uint32 packet_size);
-MEDIA_EXPORT uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size);
-MEDIA_EXPORT uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory,
- uint32 shared_memory_size);
-MEDIA_EXPORT void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
- uint32 shared_memory_size,
- uint32 actual_data_size);
-MEDIA_EXPORT void SetUnknownDataSize(base::SharedMemory* shared_memory,
- uint32 shared_memory_size);
-MEDIA_EXPORT bool IsUnknownDataSize(base::SharedMemory* shared_memory,
- uint32 shared_memory_size);
-
#if defined(OS_WIN)
// Does Windows support WASAPI? We are checking in lot of places, and
diff --git a/media/audio/shared_memory_util.cc b/media/audio/shared_memory_util.cc
new file mode 100644
index 0000000..d79f54d
--- /dev/null
+++ b/media/audio/shared_memory_util.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 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.
+
+#include "media/audio/shared_memory_util.h"
+
+#include "base/atomicops.h"
+#include "base/logging.h"
+
+using base::subtle::Atomic32;
+
+static const uint32 kUnknownDataSize = static_cast<uint32>(-1);
+
+namespace media {
+
+uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) {
+ // Need to reserve extra 4 bytes for size of data.
+ return packet_size + sizeof(Atomic32);
+}
+
+uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) {
+ return shared_memory_created_size - sizeof(Atomic32);
+}
+
+uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size) {
+ char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
+ DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
+
+ // Actual data size stored at the end of the buffer.
+ uint32 actual_data_size =
+ base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
+ return std::min(actual_data_size, shared_memory_size);
+}
+
+void SetActualDataSizeInBytes(void* shared_memory_ptr,
+ uint32 shared_memory_size,
+ uint32 actual_data_size) {
+ char* ptr = static_cast<char*>(shared_memory_ptr) + shared_memory_size;
+ DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
+
+ // Set actual data size at the end of the buffer.
+ base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr),
+ actual_data_size);
+}
+
+void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size,
+ uint32 actual_data_size) {
+ SetActualDataSizeInBytes(shared_memory->memory(),
+ shared_memory_size, actual_data_size);
+}
+
+void SetUnknownDataSize(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size) {
+ SetActualDataSizeInBytes(shared_memory, shared_memory_size, kUnknownDataSize);
+}
+
+bool IsUnknownDataSize(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size) {
+ char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
+ DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
+
+ // Actual data size stored at the end of the buffer.
+ uint32 actual_data_size =
+ base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
+ return actual_data_size == kUnknownDataSize;
+}
+
+} // namespace media
diff --git a/media/audio/shared_memory_util.h b/media/audio/shared_memory_util.h
new file mode 100644
index 0000000..1255b92
--- /dev/null
+++ b/media/audio/shared_memory_util.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2012 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_SHARED_MEMORY_UTIL_H_
+#define MEDIA_AUDIO_SHARED_MEMORY_UTIL_H_
+
+#include "base/basictypes.h"
+#include "base/shared_memory.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// Value sent by the controller to the renderer in low-latency mode
+// indicating that the stream is paused.
+enum { kPauseMark = -1 };
+
+// Functions that handle data buffer passed between processes in the shared
+// memory. Called on both IPC sides. These are necessary because the shared
+// memory has a layout: the last word in the block is the data size in bytes.
+
+MEDIA_EXPORT uint32 TotalSharedMemorySizeInBytes(uint32 packet_size);
+MEDIA_EXPORT uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size);
+MEDIA_EXPORT uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size);
+MEDIA_EXPORT void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size,
+ uint32 actual_data_size);
+MEDIA_EXPORT void SetActualDataSizeInBytes(void* shared_memory_ptr,
+ uint32 shared_memory_size,
+ uint32 actual_data_size);
+MEDIA_EXPORT void SetUnknownDataSize(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size);
+MEDIA_EXPORT bool IsUnknownDataSize(base::SharedMemory* shared_memory,
+ uint32 shared_memory_size);
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_SHARED_MEMORY_UTIL_H_