diff options
author | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-20 23:51:13 +0000 |
---|---|---|
committer | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-20 23:51:13 +0000 |
commit | ab17025f9e68b3e4ac6156e5b668e5bfba7901fc (patch) | |
tree | d5b2c90d896b74120a42f332f6dd4486db60481c /media | |
parent | db26138ce3cd2ac975f01a93dcd278049707abbd (diff) | |
download | chromium_src-ab17025f9e68b3e4ac6156e5b668e5bfba7901fc.zip chromium_src-ab17025f9e68b3e4ac6156e5b668e5bfba7901fc.tar.gz chromium_src-ab17025f9e68b3e4ac6156e5b668e5bfba7901fc.tar.bz2 |
Revert 152406 - 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
TBR=dalecurtis@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10837350
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152431 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_output_controller.cc | 4 | ||||
-rw-r--r-- | media/audio/audio_output_controller.h | 4 | ||||
-rw-r--r-- | media/audio/audio_output_device.cc | 3 | ||||
-rw-r--r-- | media/audio/audio_output_device_unittest.cc | 2 | ||||
-rw-r--r-- | media/audio/audio_util.cc | 59 | ||||
-rw-r--r-- | media/audio/audio_util.h | 15 | ||||
-rw-r--r-- | media/audio/shared_memory_util.cc | 70 | ||||
-rw-r--r-- | media/audio/shared_memory_util.h | 39 | ||||
-rw-r--r-- | media/base/channel_layout.cc | 2 | ||||
-rw-r--r-- | media/base/channel_layout.h | 6 | ||||
-rw-r--r-- | media/media.gyp | 30 | ||||
-rw-r--r-- | media/media_untrusted.gyp | 44 | ||||
-rw-r--r-- | media/shared_memory_support.gypi | 23 |
13 files changed, 94 insertions, 207 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index 69b7797..60dd285 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -11,7 +11,6 @@ #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; @@ -19,6 +18,9 @@ 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 03b0959..a8857a2 100644 --- a/media/audio/audio_output_controller.h +++ b/media/audio/audio_output_controller.h @@ -68,6 +68,10 @@ 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 da86f97..994fa40 100644 --- a/media/audio/audio_output_device.cc +++ b/media/audio/audio_output_device.cc @@ -10,7 +10,6 @@ #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 { @@ -254,7 +253,7 @@ void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { // Called whenever we receive notifications about pending data. void AudioOutputDevice::AudioThreadCallback::Process(int pending_data) { - if (pending_data == kPauseMark) { + if (pending_data == AudioOutputController::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 14a7a35..152e958 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 1dabae9..d54f277 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -12,15 +12,16 @@ // 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) @@ -35,6 +36,10 @@ #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. @@ -478,6 +483,56 @@ 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 b329be1..d25fdf9 100644 --- a/media/audio/audio_util.h +++ b/media/audio/audio_util.h @@ -111,6 +111,21 @@ 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 deleted file mode 100644 index d79f54d..0000000 --- a/media/audio/shared_memory_util.cc +++ /dev/null @@ -1,70 +0,0 @@ -// 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 deleted file mode 100644 index 1255b92..0000000 --- a/media/audio/shared_memory_util.h +++ /dev/null @@ -1,39 +0,0 @@ -// 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 8bf02ea..f65828d 100644 --- a/media/base/channel_layout.cc +++ b/media/base/channel_layout.cc @@ -23,6 +23,7 @@ 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 @@ -79,6 +80,7 @@ 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 9e88420..ac10661 100644 --- a/media/base/channel_layout.h +++ b/media/base/channel_layout.h @@ -5,6 +5,7 @@ #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 { @@ -77,14 +78,15 @@ 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. -MEDIA_EXPORT extern const int -kChannelOrderings[CHANNEL_LAYOUT_MAX][CHANNELS_MAX]; +extern const int kChannelOrderings[CHANNEL_LAYOUT_MAX][CHANNELS_MAX]; +#endif // 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 94f5227..17e3c39 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -12,27 +12,6 @@ }, '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': [ @@ -40,7 +19,6 @@ '../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', ], @@ -95,6 +73,8 @@ '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', @@ -157,6 +137,8 @@ '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', @@ -175,6 +157,8 @@ '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', @@ -197,6 +181,7 @@ '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', @@ -686,7 +671,6 @@ '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 deleted file mode 100644 index 4abbe56..0000000 --- a/media/media_untrusted.gyp +++ /dev/null @@ -1,44 +0,0 @@ -# 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 deleted file mode 100644 index f91edf5..0000000 --- a/media/shared_memory_support.gypi +++ /dev/null @@ -1,23 +0,0 @@ -# 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', - ], - }, -} |