Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: content/browser/renderer_host/media/audio_sync_reader.cc

Issue 11348166: Always wait for DataReady() on Windows WaveOut. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typo. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/media/audio_sync_reader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/media/audio_sync_reader.h" 5 #include "content/browser/renderer_host/media/audio_sync_reader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
11 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "media/audio/audio_buffers_state.h" 12 #include "media/audio/audio_buffers_state.h"
13 #include "media/audio/audio_parameters.h" 13 #include "media/audio/audio_parameters.h"
14 #include "media/audio/shared_memory_util.h" 14 #include "media/audio/shared_memory_util.h"
15 15
16 #if defined(OS_WIN)
17 const int kMinIntervalBetweenReadCallsInMs = 10;
18 #endif
19
20 using media::AudioBus; 16 using media::AudioBus;
21 17
22 namespace content { 18 namespace content {
23 19
24 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory, 20 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory,
25 const media::AudioParameters& params, 21 const media::AudioParameters& params,
26 int input_channels) 22 int input_channels)
27 : shared_memory_(shared_memory), 23 : shared_memory_(shared_memory),
28 input_channels_(input_channels) { 24 input_channels_(input_channels) {
29 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size()); 25 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size());
(...skipping 26 matching lines...) Expand all
56 media::SetUnknownDataSize(shared_memory_, packet_size_); 52 media::SetUnknownDataSize(shared_memory_, packet_size_);
57 } 53 }
58 54
59 if (socket_.get()) { 55 if (socket_.get()) {
60 socket_->Send(&bytes, sizeof(bytes)); 56 socket_->Send(&bytes, sizeof(bytes));
61 } 57 }
62 } 58 }
63 59
64 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) { 60 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) {
65 #if defined(OS_WIN) 61 #if defined(OS_WIN)
66 // HACK: yield if reader is called too often. 62 // HACK: Yield if Read() is called too often. On older platforms which are
67 // Problem is lack of synchronization between host and renderer. We cannot be 63 // still using the WaveOut back end, we run into synchronization issues where
68 // sure if renderer already filled the buffer, and due to all the plugins we 64 // the renderer has not finished filling the shared memory when Read() is
69 // cannot change the API, so we yield if previous call was too recent. 65 // called. Reading too early will lead to clicks and pops. See issues:
70 // Optimization: if renderer is "new" one that writes length of data we can 66 // http://crbug.com/161307 and http://crbug.com/61022
scherkus (not reviewing) 2012/11/20 21:08:46 does it make sense to add a run-time check for XP?
DaleCurtis 2012/11/20 21:33:47 I thought about that, but there are cases where we
71 // stop yielding the moment length is written -- not ideal solution, 67 while (!DataReady()) {
72 // but better than nothing.
73 while (!DataReady() &&
74 ((base::Time::Now() - previous_call_time_).InMilliseconds() <
75 kMinIntervalBetweenReadCallsInMs)) {
76 base::PlatformThread::YieldCurrentThread(); 68 base::PlatformThread::YieldCurrentThread();
77 } 69 }
78 previous_call_time_ = base::Time::Now();
79 #endif 70 #endif
80 71
81 // Copy optional synchronized live audio input for consumption by renderer 72 // Copy optional synchronized live audio input for consumption by renderer
82 // process. 73 // process.
83 if (source && input_bus_.get()) { 74 if (source && input_bus_.get()) {
84 DCHECK_EQ(source->channels(), input_bus_->channels()); 75 DCHECK_EQ(source->channels(), input_bus_->channels());
85 DCHECK_LE(source->frames(), input_bus_->frames()); 76 DCHECK_LE(source->frames(), input_bus_->frames());
86 source->CopyTo(input_bus_.get()); 77 source->CopyTo(input_bus_.get());
87 } 78 }
88 79
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 base::FileDescriptor* foreign_handle) { 144 base::FileDescriptor* foreign_handle) {
154 foreign_handle->fd = foreign_socket_->handle(); 145 foreign_handle->fd = foreign_socket_->handle();
155 foreign_handle->auto_close = false; 146 foreign_handle->auto_close = false;
156 if (foreign_handle->fd != -1) 147 if (foreign_handle->fd != -1)
157 return true; 148 return true;
158 return false; 149 return false;
159 } 150 }
160 #endif 151 #endif
161 152
162 } // namespace content 153 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_sync_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698