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" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // | 137 // |
138 // The counter values may temporarily become out of sync if the renderer is | 138 // The counter values may temporarily become out of sync if the renderer is |
139 // unable to deliver audio fast enough. It's assumed that the renderer will | 139 // unable to deliver audio fast enough. It's assumed that the renderer will |
140 // catch up at some point, which means discarding counter values read from the | 140 // catch up at some point, which means discarding counter values read from the |
141 // SyncSocket which don't match our current buffer index. | 141 // SyncSocket which don't match our current buffer index. |
142 size_t bytes_received = 0; | 142 size_t bytes_received = 0; |
143 uint32 renderer_buffer_index = 0; | 143 uint32 renderer_buffer_index = 0; |
144 while (timeout.InMicroseconds() > 0) { | 144 while (timeout.InMicroseconds() > 0) { |
145 bytes_received = socket_->ReceiveWithTimeout( | 145 bytes_received = socket_->ReceiveWithTimeout( |
146 &renderer_buffer_index, sizeof(renderer_buffer_index), timeout); | 146 &renderer_buffer_index, sizeof(renderer_buffer_index), timeout); |
147 if (!bytes_received) | 147 if (bytes_received != sizeof(renderer_buffer_index)) { |
| 148 bytes_received = 0; |
148 break; | 149 break; |
| 150 } |
149 | 151 |
150 DCHECK_EQ(bytes_received, sizeof(renderer_buffer_index)); | |
151 if (renderer_buffer_index == buffer_index_) | 152 if (renderer_buffer_index == buffer_index_) |
152 break; | 153 break; |
153 | 154 |
154 // Reduce the timeout value as receives succeed, but aren't the right index. | 155 // Reduce the timeout value as receives succeed, but aren't the right index. |
155 timeout = finish_time - base::TimeTicks::Now(); | 156 timeout = finish_time - base::TimeTicks::Now(); |
156 } | 157 } |
157 | 158 |
158 // Receive timed out or another error occurred. Receive can timeout if the | 159 // Receive timed out or another error occurred. Receive can timeout if the |
159 // renderer is unable to deliver audio data within the allotted time. | 160 // renderer is unable to deliver audio data within the allotted time. |
160 if (!bytes_received || renderer_buffer_index != buffer_index_) { | 161 if (!bytes_received || renderer_buffer_index != buffer_index_) { |
161 DVLOG(2) << "AudioSyncReader::WaitUntilDataIsReady() timed out."; | 162 DVLOG(2) << "AudioSyncReader::WaitUntilDataIsReady() timed out."; |
162 | 163 |
163 base::TimeDelta time_since_start = base::TimeTicks::Now() - start_time; | 164 base::TimeDelta time_since_start = base::TimeTicks::Now() - start_time; |
164 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", | 165 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", |
165 time_since_start, | 166 time_since_start, |
166 base::TimeDelta::FromMilliseconds(1), | 167 base::TimeDelta::FromMilliseconds(1), |
167 base::TimeDelta::FromMilliseconds(1000), | 168 base::TimeDelta::FromMilliseconds(1000), |
168 50); | 169 50); |
169 return false; | 170 return false; |
170 } | 171 } |
171 | 172 |
172 return true; | 173 return true; |
173 } | 174 } |
174 | 175 |
175 } // namespace content | 176 } // namespace content |
OLD | NEW |