summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcrogers@google.com <crogers@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-02 20:39:46 +0000
committercrogers@google.com <crogers@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-02 20:39:46 +0000
commitfd346b76799059213d36109a799bc029f3a2ed1d (patch)
tree4cda0fd2c340889ed453ecdc398f7eb61d4834b0
parenta64673a1e41968a08c53a1a1986ec123977f5674 (diff)
downloadchromium_src-fd346b76799059213d36109a799bc029f3a2ed1d.zip
chromium_src-fd346b76799059213d36109a799bc029f3a2ed1d.tar.gz
chromium_src-fd346b76799059213d36109a799bc029f3a2ed1d.tar.bz2
Revert 99236 - 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. This breaks the Web Audio API completely on Mac OS X, and hoses audio for ALL applications, requiring reboot. BUG=http://code.google.com/p/chromium/issues/detail?id=61022 Review URL: http://codereview.chromium.org/7755001 TBR=scherkus@chromium.org Review URL: http://codereview.chromium.org/7831050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99446 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/media/audio_sync_reader.cc22
-rw-r--r--content/browser/renderer_host/media/audio_sync_reader.h2
-rw-r--r--media/audio/audio_util.cc22
-rw-r--r--media/audio/audio_util.h4
4 files changed, 4 insertions, 46 deletions
diff --git a/content/browser/renderer_host/media/audio_sync_reader.cc b/content/browser/renderer_host/media/audio_sync_reader.cc
index ad3e6f9..e8de9f9 100644
--- a/content/browser/renderer_host/media/audio_sync_reader.cc
+++ b/content/browser/renderer_host/media/audio_sync_reader.cc
@@ -8,12 +8,9 @@
#include "base/process_util.h"
#include "base/shared_memory.h"
-#include "base/threading/platform_thread.h"
#include "media/audio/audio_buffers_state.h"
#include "media/audio/audio_util.h"
-const int kMinIntervalBetweenReadCalls = 10;
-
AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory)
: shared_memory_(shared_memory) {
}
@@ -29,19 +26,6 @@ void AudioSyncReader::UpdatePendingBytes(uint32 bytes) {
uint32 AudioSyncReader::Read(void* data, uint32 size) {
uint32 max_size = media::PacketSizeSizeInBytes(
shared_memory_->created_size());
-
- // HACK: yield if reader is called too often.
- // Problem is lack of synchronization between host and renderer. We cannot be
- // sure if renderer already filled the buffer, and due to all the plugins we
- // cannot change the API, so we yield if previous call was too recent.
- // Optimization: if renderer is "new" one that writes length of data we can
- // stop yielding the moment length is written -- not ideal solution,
- // but better than nothing.
- while (media::IsUnknownDataSize(shared_memory_, max_size) &&
- ((base::Time::Now() - previous_call_time_).InMilliseconds() <
- kMinIntervalBetweenReadCalls)) {
- base::PlatformThread::YieldCurrentThread();
- }
uint32 read_size = std::min(media::GetActualDataSizeInBytes(shared_memory_,
max_size),
size);
@@ -56,11 +40,9 @@ uint32 AudioSyncReader::Read(void* data, uint32 size) {
// Zero out the entire buffer.
memset(shared_memory_->memory(), 0, max_size);
- // Store unknown length of data into buffer, in case renderer does not store
- // the length itself. It also helps in decision if we need to yield.
- media::SetUnknownDataSize(shared_memory_, max_size);
+ // Store max length of data into buffer, in case client does not do that.
+ media::SetActualDataSizeInBytes(shared_memory_, max_size, max_size);
- previous_call_time_ = base::Time::Now();
return read_size;
}
diff --git a/content/browser/renderer_host/media/audio_sync_reader.h b/content/browser/renderer_host/media/audio_sync_reader.h
index ad27b86..acb064d 100644
--- a/content/browser/renderer_host/media/audio_sync_reader.h
+++ b/content/browser/renderer_host/media/audio_sync_reader.h
@@ -9,7 +9,6 @@
#include "base/file_descriptor_posix.h"
#include "base/process.h"
#include "base/sync_socket.h"
-#include "base/time.h"
#include "media/audio/audio_output_controller.h"
namespace base {
@@ -41,7 +40,6 @@ class AudioSyncReader : public media::AudioOutputController::SyncReader {
private:
base::SharedMemory* shared_memory_;
- base::Time previous_call_time_;
// A pair of SyncSocket for transmitting audio data.
scoped_ptr<base::SyncSocket> socket_;
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index c45454a..fe5fb10 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -21,8 +21,6 @@
using base::subtle::Atomic32;
-const uint32 kUnknownDataSize = static_cast<uint32>(-1);
-
namespace media {
// TODO(fbarchard): Convert to intrinsics for better efficiency.
@@ -259,7 +257,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 at the end of the buffer.
+ // Actual data size stored in the beginning 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);
@@ -271,25 +269,9 @@ 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 at the end of the buffer.
+ // Set actual data size in the beginning 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 e9452b2..ff8f2f0 100644
--- a/media/audio/audio_util.h
+++ b/media/audio/audio_util.h
@@ -92,10 +92,6 @@ 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