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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 socket_->Close(); | 108 socket_->Close(); |
109 } | 109 } |
110 | 110 |
111 bool AudioSyncReader::Init() { | 111 bool AudioSyncReader::Init() { |
112 socket_.reset(new base::CancelableSyncSocket()); | 112 socket_.reset(new base::CancelableSyncSocket()); |
113 foreign_socket_.reset(new base::CancelableSyncSocket()); | 113 foreign_socket_.reset(new base::CancelableSyncSocket()); |
114 return base::CancelableSyncSocket::CreatePair(socket_.get(), | 114 return base::CancelableSyncSocket::CreatePair(socket_.get(), |
115 foreign_socket_.get()); | 115 foreign_socket_.get()); |
116 } | 116 } |
117 | 117 |
118 #if defined(OS_WIN) | 118 bool AudioSyncReader::PrepareForeignSocket( |
119 bool AudioSyncReader::PrepareForeignSocketHandle( | |
120 base::ProcessHandle process_handle, | 119 base::ProcessHandle process_handle, |
121 base::SyncSocket::Handle* foreign_handle) { | 120 base::SyncSocket::TransitDescriptor* descriptor) { |
122 ::DuplicateHandle(GetCurrentProcess(), foreign_socket_->handle(), | 121 return foreign_socket_->PrepareTransitDescriptor(process_handle, descriptor); |
123 process_handle, foreign_handle, | |
124 0, FALSE, DUPLICATE_SAME_ACCESS); | |
125 return (*foreign_handle != 0); | |
126 } | 122 } |
127 #else | |
128 bool AudioSyncReader::PrepareForeignSocketHandle( | |
129 base::ProcessHandle process_handle, | |
130 base::FileDescriptor* foreign_handle) { | |
131 foreign_handle->fd = foreign_socket_->handle(); | |
132 foreign_handle->auto_close = false; | |
133 return (foreign_handle->fd != -1); | |
134 } | |
135 #endif | |
136 | 123 |
137 bool AudioSyncReader::WaitUntilDataIsReady() { | 124 bool AudioSyncReader::WaitUntilDataIsReady() { |
138 base::TimeDelta timeout = maximum_wait_time_; | 125 base::TimeDelta timeout = maximum_wait_time_; |
139 const base::TimeTicks start_time = base::TimeTicks::Now(); | 126 const base::TimeTicks start_time = base::TimeTicks::Now(); |
140 const base::TimeTicks finish_time = start_time + timeout; | 127 const base::TimeTicks finish_time = start_time + timeout; |
141 | 128 |
142 // Check if data is ready and if not, wait a reasonable amount of time for it. | 129 // Check if data is ready and if not, wait a reasonable amount of time for it. |
143 // | 130 // |
144 // Data readiness is achieved via parallel counters, one on the renderer side | 131 // Data readiness is achieved via parallel counters, one on the renderer side |
145 // and one here. Every time a buffer is requested via UpdatePendingBytes(), | 132 // and one here. Every time a buffer is requested via UpdatePendingBytes(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 base::TimeDelta::FromMilliseconds(1), | 166 base::TimeDelta::FromMilliseconds(1), |
180 base::TimeDelta::FromMilliseconds(1000), | 167 base::TimeDelta::FromMilliseconds(1000), |
181 50); | 168 50); |
182 return false; | 169 return false; |
183 } | 170 } |
184 | 171 |
185 return true; | 172 return true; |
186 } | 173 } |
187 | 174 |
188 } // namespace content | 175 } // namespace content |
OLD | NEW |