Chromium Code Reviews| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 foreign_socket_.get()); | 114 foreign_socket_.get()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool AudioSyncReader::PrepareForeignSocket( | 117 bool AudioSyncReader::PrepareForeignSocket( |
| 118 base::ProcessHandle process_handle, | 118 base::ProcessHandle process_handle, |
| 119 base::SyncSocket::TransitDescriptor* descriptor) { | 119 base::SyncSocket::TransitDescriptor* descriptor) { |
| 120 return foreign_socket_->PrepareTransitDescriptor(process_handle, descriptor); | 120 return foreign_socket_->PrepareTransitDescriptor(process_handle, descriptor); |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool AudioSyncReader::WaitUntilDataIsReady() { | 123 bool AudioSyncReader::WaitUntilDataIsReady() { |
| 124 base::TimeDelta timeout = maximum_wait_time_; | |
| 125 const base::TimeTicks start_time = base::TimeTicks::Now(); | 124 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 126 const base::TimeTicks finish_time = start_time + timeout; | |
| 127 | 125 |
| 128 // Check if data is ready and if not, wait a reasonable amount of time for it. | 126 // Check if data is ready and if not, wait a reasonable amount of time for it. |
| 129 // | 127 // |
| 130 // Data readiness is achieved via parallel counters, one on the renderer side | 128 // Data readiness is achieved via parallel counters, one on the renderer side |
| 131 // and one here. Every time a buffer is requested via UpdatePendingBytes(), | 129 // and one here. Every time a buffer is requested via UpdatePendingBytes(), |
| 132 // |buffer_index_| is incremented. Subsequently every time the renderer has a | 130 // |buffer_index_| is incremented. Subsequently every time the renderer has a |
| 133 // buffer ready it increments its counter and sends the counter value over the | 131 // buffer ready it increments its counter and sends the counter value over the |
| 134 // SyncSocket. Data is ready when |buffer_index_| matches the counter value | 132 // SyncSocket. Data is ready when |socket_| receive a counter value from |
| 135 // received from the renderer. | 133 // the renderer. |
| 136 // | 134 // |
| 137 // The counter values may temporarily become out of sync if the renderer is | 135 // The counter values can become out of sync if the renderer is |
| 138 // unable to deliver audio fast enough. It's assumed that the renderer will | 136 // unable to deliver audio fast enough. It's assumed that the renderer will |
| 139 // catch up at some point, which means discarding counter values read from the | 137 // automatically catch up at some point, and the browser should not wait for |
| 140 // SyncSocket which don't match our current buffer index. | 138 // the synchronization since it needs to feed the received audio data to |
| 141 size_t bytes_received = 0; | 139 // hardware ASAP. |
| 142 uint32 renderer_buffer_index = 0; | 140 uint32 renderer_buffer_index = 0; |
| 143 while (timeout.InMicroseconds() > 0) { | 141 size_t bytes_received = socket_->ReceiveWithTimeout( |
|
no longer working on chromium
2014/10/16 20:27:56
Dale, besides the buffer size issue, I think we st
DaleCurtis
2014/10/16 21:14:14
I don't understand what you're asking. The loop br
| |
| 144 bytes_received = socket_->ReceiveWithTimeout( | 142 &renderer_buffer_index, sizeof(renderer_buffer_index), |
| 145 &renderer_buffer_index, sizeof(renderer_buffer_index), timeout); | 143 maximum_wait_time_); |
| 146 if (bytes_received != sizeof(renderer_buffer_index)) { | 144 if (bytes_received != sizeof(renderer_buffer_index)) { |
| 147 bytes_received = 0; | 145 // Set |bytes_received| to 0 to indicate it is a timeout. |
| 148 break; | 146 bytes_received = 0; |
| 149 } | |
| 150 | |
| 151 if (renderer_buffer_index == buffer_index_) | |
| 152 break; | |
| 153 | |
| 154 // Reduce the timeout value as receives succeed, but aren't the right index. | |
| 155 timeout = finish_time - base::TimeTicks::Now(); | |
| 156 } | 147 } |
| 157 | 148 |
| 158 // Receive timed out or another error occurred. Receive can timeout if the | 149 // Receive timed out or another error occurred. Receive can timeout if the |
| 159 // renderer is unable to deliver audio data within the allotted time. | 150 // renderer is unable to deliver audio data within the allotted time. |
| 160 if (!bytes_received || renderer_buffer_index != buffer_index_) { | 151 if (!bytes_received) { |
| 161 DVLOG(2) << "AudioSyncReader::WaitUntilDataIsReady() timed out."; | 152 DVLOG(2) << "AudioSyncReader::WaitUntilDataIsReady() timed out."; |
| 162 | 153 |
| 163 base::TimeDelta time_since_start = base::TimeTicks::Now() - start_time; | 154 base::TimeDelta time_since_start = base::TimeTicks::Now() - start_time; |
| 164 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", | 155 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", |
| 165 time_since_start, | 156 time_since_start, |
| 166 base::TimeDelta::FromMilliseconds(1), | 157 base::TimeDelta::FromMilliseconds(1), |
| 167 base::TimeDelta::FromMilliseconds(1000), | 158 base::TimeDelta::FromMilliseconds(1000), |
| 168 50); | 159 50); |
| 169 return false; | 160 return false; |
| 170 } | 161 } |
| 171 | 162 |
| 172 return true; | 163 return true; |
| 173 } | 164 } |
| 174 | 165 |
| 175 } // namespace content | 166 } // namespace content |
| OLD | NEW |