OLD | NEW |
---|---|
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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/trace_event/trace_event.h" | |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "content/browser/renderer_host/media/media_stream_manager.h" | 15 #include "content/browser/renderer_host/media/media_stream_manager.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
17 | 18 |
18 using media::AudioBus; | 19 using media::AudioBus; |
19 using media::AudioOutputBuffer; | 20 using media::AudioOutputBuffer; |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 foreign_socket_.get()); | 158 foreign_socket_.get()); |
158 } | 159 } |
159 | 160 |
160 bool AudioSyncReader::PrepareForeignSocket( | 161 bool AudioSyncReader::PrepareForeignSocket( |
161 base::ProcessHandle process_handle, | 162 base::ProcessHandle process_handle, |
162 base::SyncSocket::TransitDescriptor* descriptor) { | 163 base::SyncSocket::TransitDescriptor* descriptor) { |
163 return foreign_socket_->PrepareTransitDescriptor(process_handle, descriptor); | 164 return foreign_socket_->PrepareTransitDescriptor(process_handle, descriptor); |
164 } | 165 } |
165 | 166 |
166 bool AudioSyncReader::WaitUntilDataIsReady() { | 167 bool AudioSyncReader::WaitUntilDataIsReady() { |
168 TRACE_EVENT0("audio", "AudioSyncReader::WaitUntilDataIsReady"); | |
167 base::TimeDelta timeout = maximum_wait_time_; | 169 base::TimeDelta timeout = maximum_wait_time_; |
168 const base::TimeTicks start_time = base::TimeTicks::Now(); | 170 const base::TimeTicks start_time = base::TimeTicks::Now(); |
169 const base::TimeTicks finish_time = start_time + timeout; | 171 const base::TimeTicks finish_time = start_time + timeout; |
170 | 172 |
171 // Check if data is ready and if not, wait a reasonable amount of time for it. | 173 // Check if data is ready and if not, wait a reasonable amount of time for it. |
172 // | 174 // |
173 // Data readiness is achieved via parallel counters, one on the renderer side | 175 // Data readiness is achieved via parallel counters, one on the renderer side |
174 // and one here. Every time a buffer is requested via UpdatePendingBytes(), | 176 // and one here. Every time a buffer is requested via UpdatePendingBytes(), |
175 // |buffer_index_| is incremented. Subsequently every time the renderer has a | 177 // |buffer_index_| is incremented. Subsequently every time the renderer has a |
176 // buffer ready it increments its counter and sends the counter value over the | 178 // buffer ready it increments its counter and sends the counter value over the |
(...skipping 17 matching lines...) Expand all Loading... | |
194 if (renderer_buffer_index == buffer_index_) | 196 if (renderer_buffer_index == buffer_index_) |
195 break; | 197 break; |
196 | 198 |
197 // Reduce the timeout value as receives succeed, but aren't the right index. | 199 // Reduce the timeout value as receives succeed, but aren't the right index. |
198 timeout = finish_time - base::TimeTicks::Now(); | 200 timeout = finish_time - base::TimeTicks::Now(); |
199 } | 201 } |
200 | 202 |
201 // Receive timed out or another error occurred. Receive can timeout if the | 203 // Receive timed out or another error occurred. Receive can timeout if the |
202 // renderer is unable to deliver audio data within the allotted time. | 204 // renderer is unable to deliver audio data within the allotted time. |
203 if (!bytes_received || renderer_buffer_index != buffer_index_) { | 205 if (!bytes_received || renderer_buffer_index != buffer_index_) { |
204 DVLOG(2) << "AudioSyncReader::WaitUntilDataIsReady() timed out."; | 206 TRACE_EVENT_INSTANT0("audio", "AudioSyncReader::Read timed out", |
DaleCurtis
2016/08/19 16:49:00
Be neat if we could make this show up in a red col
o1ka
2016/08/23 07:16:00
Would be really cool, but looks like they don't ha
| |
207 TRACE_EVENT_SCOPE_THREAD); | |
205 | 208 |
206 base::TimeDelta time_since_start = base::TimeTicks::Now() - start_time; | 209 base::TimeDelta time_since_start = base::TimeTicks::Now() - start_time; |
207 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", | 210 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", |
208 time_since_start, | 211 time_since_start, |
209 base::TimeDelta::FromMilliseconds(1), | 212 base::TimeDelta::FromMilliseconds(1), |
210 base::TimeDelta::FromMilliseconds(1000), | 213 base::TimeDelta::FromMilliseconds(1000), |
211 50); | 214 50); |
212 return false; | 215 return false; |
213 } | 216 } |
214 | 217 |
215 return true; | 218 return true; |
216 } | 219 } |
217 | 220 |
218 } // namespace content | 221 } // namespace content |
OLD | NEW |