summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorenal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 20:16:49 +0000
committerenal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 20:16:49 +0000
commit7fb356f9b1f572a2f291a694c43de05c3ef8f3de (patch)
tree1624bb30586b92387fdf8e23d72ae9f7dc792117 /media
parentf41576fc2cac0d7d0f7f4602b07b596d667104f4 (diff)
downloadchromium_src-7fb356f9b1f572a2f291a694c43de05c3ef8f3de.zip
chromium_src-7fb356f9b1f572a2f291a694c43de05c3ef8f3de.tar.gz
chromium_src-7fb356f9b1f572a2f291a694c43de05c3ef8f3de.tar.bz2
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 Review URL: http://codereview.chromium.org/7755001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/audio_util.cc22
-rw-r--r--media/audio/audio_util.h4
2 files changed, 24 insertions, 2 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index fe5fb10..c45454a 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 in 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