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

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: Fix typo! Created 8 years 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') | media/audio/audio_io.h » ('j') | 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"
12 #include "media/audio/audio_buffers_state.h" 11 #include "media/audio/audio_buffers_state.h"
13 #include "media/audio/audio_parameters.h" 12 #include "media/audio/audio_parameters.h"
14 #include "media/audio/shared_memory_util.h" 13 #include "media/audio/shared_memory_util.h"
15 14
16 #if defined(OS_WIN)
17 const int kMinIntervalBetweenReadCallsInMs = 10;
18 #endif
19
20 using media::AudioBus; 15 using media::AudioBus;
21 16
22 namespace content { 17 namespace content {
23 18
24 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory, 19 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory,
25 const media::AudioParameters& params, 20 const media::AudioParameters& params,
26 int input_channels) 21 int input_channels)
27 : shared_memory_(shared_memory), 22 : shared_memory_(shared_memory),
28 input_channels_(input_channels) { 23 input_channels_(input_channels) {
29 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size()); 24 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size());
(...skipping 25 matching lines...) Expand all
55 // can find out if data became available. 50 // can find out if data became available.
56 media::SetUnknownDataSize(shared_memory_, packet_size_); 51 media::SetUnknownDataSize(shared_memory_, packet_size_);
57 } 52 }
58 53
59 if (socket_.get()) { 54 if (socket_.get()) {
60 socket_->Send(&bytes, sizeof(bytes)); 55 socket_->Send(&bytes, sizeof(bytes));
61 } 56 }
62 } 57 }
63 58
64 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) { 59 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) {
65 #if defined(OS_WIN)
66 // HACK: yield if reader is called too often.
67 // Problem is lack of synchronization between host and renderer. We cannot be
68 // sure if renderer already filled the buffer, and due to all the plugins we
69 // cannot change the API, so we yield if previous call was too recent.
70 // Optimization: if renderer is "new" one that writes length of data we can
71 // stop yielding the moment length is written -- not ideal solution,
72 // but better than nothing.
73 while (!DataReady() &&
74 ((base::Time::Now() - previous_call_time_).InMilliseconds() <
75 kMinIntervalBetweenReadCallsInMs)) {
76 base::PlatformThread::YieldCurrentThread();
77 }
78 previous_call_time_ = base::Time::Now();
79 #endif
80
81 // Copy optional synchronized live audio input for consumption by renderer 60 // Copy optional synchronized live audio input for consumption by renderer
82 // process. 61 // process.
83 if (source && input_bus_.get()) { 62 if (source && input_bus_.get()) {
84 DCHECK_EQ(source->channels(), input_bus_->channels()); 63 DCHECK_EQ(source->channels(), input_bus_->channels());
85 DCHECK_LE(source->frames(), input_bus_->frames()); 64 DCHECK_LE(source->frames(), input_bus_->frames());
86 source->CopyTo(input_bus_.get()); 65 source->CopyTo(input_bus_.get());
87 } 66 }
88 67
89 // Retrieve the actual number of bytes available from the shared memory. If 68 // Retrieve the actual number of bytes available from the shared memory. If
90 // the renderer has not completed rendering this value will be invalid (still 69 // the renderer has not completed rendering this value will be invalid (still
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 base::FileDescriptor* foreign_handle) { 132 base::FileDescriptor* foreign_handle) {
154 foreign_handle->fd = foreign_socket_->handle(); 133 foreign_handle->fd = foreign_socket_->handle();
155 foreign_handle->auto_close = false; 134 foreign_handle->auto_close = false;
156 if (foreign_handle->fd != -1) 135 if (foreign_handle->fd != -1)
157 return true; 136 return true;
158 return false; 137 return false;
159 } 138 }
160 #endif 139 #endif
161 140
162 } // namespace content 141 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_sync_reader.h ('k') | media/audio/audio_io.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698