diff options
author | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 02:35:48 +0000 |
---|---|---|
committer | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 02:35:48 +0000 |
commit | cc2e7541eff6b7155d444bdec2d0f0aae6eadedd (patch) | |
tree | dbc97db24bd1f3124903cd292c794013c8257984 /media | |
parent | d6eaa3fb36a5940e0f196e024cacb42f278c6b5c (diff) | |
download | chromium_src-cc2e7541eff6b7155d444bdec2d0f0aae6eadedd.zip chromium_src-cc2e7541eff6b7155d444bdec2d0f0aae6eadedd.tar.gz chromium_src-cc2e7541eff6b7155d444bdec2d0f0aae6eadedd.tar.bz2 |
Windows-only change -- issue is worst on Windows because of pre-buffering. On Linux problem is much milder, and on Mac we cannot yield high-priority audio thread...
Very short-term change: while working on proper long-term solution,
workaround for race condition that causes clicks and bad audio stream.
Yield if reader was called too quickly after previous call, as there
are good chances renderer thread did not fill the buffer yet.
BUG=http://code.google.com/p/chromium/issues/detail?id=61022
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=99236
Review URL: http://codereview.chromium.org/7755001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101231 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_util.cc | 22 | ||||
-rw-r--r-- | media/audio/audio_util.h | 4 |
2 files changed, 24 insertions, 2 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc index fe5fb10..2b790d8 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -21,6 +21,8 @@ using base::subtle::Atomic32; +const uint32 kUnknownDataSize = static_cast<uint32>(-1); + namespace media { // TODO(fbarchard): Convert to intrinsics for better efficiency. @@ -257,7 +259,7 @@ uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory, char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size; DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3); - // Actual data size stored in the beginning of the buffer. + // 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); @@ -269,9 +271,25 @@ void SetActualDataSizeInBytes(base::SharedMemory* shared_memory, char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size; DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3); - // Set actual data size in the beginning of the buffer. + // 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; +} + } // namespace media diff --git a/media/audio/audio_util.h b/media/audio/audio_util.h index ff8f2f0..e9452b2 100644 --- a/media/audio/audio_util.h +++ b/media/audio/audio_util.h @@ -92,6 +92,10 @@ MEDIA_EXPORT uint32 GetActualDataSizeInBytes(base::SharedMemory* shared_memory, 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); } // namespace media |