summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authordalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-20 22:19:33 +0000
committerdalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-20 22:19:33 +0000
commit9a499a01f4e66080673c8a08496e9c3b488c3fdf (patch)
tree44fc9d9d220404f59c0cd709183c062357f475dd /media
parentb6c1d7cd9f79ed599e0fef24569fee1b955693ce (diff)
downloadchromium_src-9a499a01f4e66080673c8a08496e9c3b488c3fdf.zip
chromium_src-9a499a01f4e66080673c8a08496e9c3b488c3fdf.tar.gz
chromium_src-9a499a01f4e66080673c8a08496e9c3b488c3fdf.tar.bz2
Introduce shared_memory_support media target for PPAPI.
Allows PPAPI to directly utilize shared memory utility code instead of duplicating it and CHECK'ing for equivalency. Required to eventually convert PPAPI to using an AudioBus and floats in PPB_Audio_Shared::Run(). http://crbug.com/114700 BUG=123203 TEST=unittests Review URL: https://chromiumcodereview.appspot.com/10826296 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-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
-rw-r--r--media/base/channel_layout.cc2
-rw-r--r--media/base/channel_layout.h6
-rw-r--r--media/media.gyp30
-rw-r--r--media/media_untrusted.gyp44
-rw-r--r--media/shared_memory_support.gypi23
13 files changed, 207 insertions, 94 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_
diff --git a/media/base/channel_layout.cc b/media/base/channel_layout.cc
index f65828d..8bf02ea 100644
--- a/media/base/channel_layout.cc
+++ b/media/base/channel_layout.cc
@@ -23,7 +23,6 @@ static const int kLayoutToChannels[] = {
8, // CHANNEL_LAYOUT_7POINT1_WIDE
2}; // CHANNEL_LAYOUT_STEREO_DOWNMIX
-#if defined(OS_MACOSX) || defined(USE_PULSEAUDIO)
const int kChannelOrderings[CHANNEL_LAYOUT_MAX][CHANNELS_MAX] = {
// FL | FR | FC | LFE | BL | BR | FLofC | FRofC | BC | SL | SR | StL | StR
@@ -80,7 +79,6 @@ const int kChannelOrderings[CHANNEL_LAYOUT_MAX][CHANNELS_MAX] = {
// FL | FR | FC | LFE | BL | BR | FLofC | FRofC | BC | SL | SR | StL | StR
};
-#endif
int ChannelLayoutToChannelCount(ChannelLayout layout) {
return kLayoutToChannels[layout];
diff --git a/media/base/channel_layout.h b/media/base/channel_layout.h
index ac10661..9e88420 100644
--- a/media/base/channel_layout.h
+++ b/media/base/channel_layout.h
@@ -5,7 +5,6 @@
#ifndef MEDIA_BASE_CHANNEL_LAYOUT_H_
#define MEDIA_BASE_CHANNEL_LAYOUT_H_
-#include "build/build_config.h"
#include "media/base/media_export.h"
enum ChannelLayout {
@@ -78,15 +77,14 @@ enum Channels {
CHANNELS_MAX
};
-#if defined(OS_MACOSX) || defined(USE_PULSEAUDIO)
// The channel orderings for each layout as specified by FFmpeg.
// Values represent the index of each channel in each layout. For example, the
// left side surround sound channel in FFmpeg's 5.1 layout is in the 5th
// position (because the order is L, R, C, LFE, LS, RS), so
// kChannelOrderings[CHANNEL_LAYOUT_5POINT1][SIDE_LEFT] = 4;
// Values of -1 mean the channel at that index is not used for that layout.
-extern const int kChannelOrderings[CHANNEL_LAYOUT_MAX][CHANNELS_MAX];
-#endif
+MEDIA_EXPORT extern const int
+kChannelOrderings[CHANNEL_LAYOUT_MAX][CHANNELS_MAX];
// Returns the number of channels in a given ChannelLayout.
MEDIA_EXPORT int ChannelLayoutToChannelCount(ChannelLayout layout);
diff --git a/media/media.gyp b/media/media.gyp
index 17e3c39..94f5227 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -12,6 +12,27 @@
},
'targets': [
{
+ # Minimal target for NaCl and other renderer side media clients which only
+ # need to send audio data across the shared memory to the browser process.
+ 'target_name': 'shared_memory_support',
+ 'type': '<(component)',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ ],
+ 'defines': [
+ 'MEDIA_IMPLEMENTATION',
+ ],
+ 'include_dirs': [
+ '..',
+ ],
+ 'includes': [
+ 'shared_memory_support.gypi',
+ ],
+ 'sources': [
+ '<@(shared_memory_support_sources)',
+ ],
+ },
+ {
'target_name': 'media',
'type': '<(component)',
'dependencies': [
@@ -19,6 +40,7 @@
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../build/temp_gyp/googleurl.gyp:googleurl',
'../crypto/crypto.gyp:crypto',
+ 'shared_memory_support',
'../ui/ui.gyp:ui',
'yuv_convert',
],
@@ -73,8 +95,6 @@
'audio/audio_output_mixer.h',
'audio/audio_output_proxy.cc',
'audio/audio_output_proxy.h',
- 'audio/audio_parameters.cc',
- 'audio/audio_parameters.h',
'audio/audio_util.cc',
'audio/audio_util.h',
'audio/cross_process_notification.cc',
@@ -137,8 +157,6 @@
'audio/win/waveout_output_win.h',
'base/android/media_jni_registrar.cc',
'base/android/media_jni_registrar.h',
- 'base/audio_bus.cc',
- 'base/audio_bus.h',
'base/audio_decoder.cc',
'base/audio_decoder.h',
'base/audio_decoder_config.cc',
@@ -157,8 +175,6 @@
'base/buffers.h',
'base/byte_queue.cc',
'base/byte_queue.h',
- 'base/channel_layout.cc',
- 'base/channel_layout.h',
'base/clock.cc',
'base/clock.h',
'base/data_buffer.cc',
@@ -181,7 +197,6 @@
'base/filter_collection.h',
'base/media.h',
'base/media_android.cc',
- 'base/media_export.h',
'base/media_log.cc',
'base/media_log.h',
'base/media_log_event.h',
@@ -671,6 +686,7 @@
'dependencies': [
'media',
'media_test_support',
+ 'shared_memory_support',
'yuv_convert',
'../base/base.gyp:base',
'../base/base.gyp:base_i18n',
diff --git a/media/media_untrusted.gyp b/media/media_untrusted.gyp
new file mode 100644
index 0000000..4abbe56
--- /dev/null
+++ b/media/media_untrusted.gyp
@@ -0,0 +1,44 @@
+# 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.
+
+{
+ 'variables': {
+ 'chromium_code': 1,
+ },
+ 'includes': [
+ '../native_client/build/untrusted.gypi',
+ ],
+ 'conditions': [
+ ['disable_nacl==0 and disable_nacl_untrusted==0', {
+ 'targets': [
+ {
+ 'target_name': 'shared_memory_support_untrusted',
+ 'type': 'none',
+ 'variables': {
+ 'nacl_untrusted_build': 1,
+ 'nlib_target': 'libshared_memory_support_untrusted.a',
+ 'build_glibc': 0,
+ 'build_newlib': 1,
+ },
+ 'dependencies': [
+ '../native_client/tools.gyp:prep_toolchain',
+ '../base/base_untrusted.gyp:base_untrusted',
+ ],
+ 'defines': [
+ 'MEDIA_IMPLEMENTATION',
+ ],
+ 'include_dirs': [
+ '..',
+ ],
+ 'includes': [
+ 'shared_memory_support.gypi',
+ ],
+ 'sources': [
+ '<@(shared_memory_support_sources)',
+ ],
+ },
+ ],
+ }],
+ ],
+}
diff --git a/media/shared_memory_support.gypi b/media/shared_memory_support.gypi
new file mode 100644
index 0000000..f91edf5
--- /dev/null
+++ b/media/shared_memory_support.gypi
@@ -0,0 +1,23 @@
+# 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.
+
+{
+ 'variables': {
+ 'chromium_code': 1,
+ # These are defined here because we need to build this library both for
+ # the general media pipeline and again for the untrusted NaCl target.
+ 'shared_memory_support_sources': [
+ 'audio/audio_parameters.cc',
+ 'audio/audio_parameters.h',
+ 'audio/shared_memory_util.cc',
+ 'audio/shared_memory_util.h',
+ 'base/audio_bus.cc',
+ 'base/audio_bus.h',
+ 'base/channel_layout.cc',
+ 'base/channel_layout.h',
+ 'base/limits.h',
+ 'base/media_export.h',
+ ],
+ },
+}