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

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 2607203002: [Mojo Video Capture] Retire buffers when Android Chromium goes to the background (Closed)
Patch Set: Support reused buffer ids in Controller Created 3 years, 10 months 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
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/video_capture_manager.h" 5 #include "content/browser/renderer_host/media/video_capture_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Phase 1: When first created (in GetOrCreateDeviceEntry()), this consists of 171 // Phase 1: When first created (in GetOrCreateDeviceEntry()), this consists of
172 // only the |video_capture_controller|. Clients can already connect to the 172 // only the |video_capture_controller|. Clients can already connect to the
173 // controller, but there is no |buffer_pool| or |video_capture_device| present. 173 // controller, but there is no |buffer_pool| or |video_capture_device| present.
174 // Phase 2: When a request to "start" the entry comes in (via 174 // Phase 2: When a request to "start" the entry comes in (via
175 // HandleQueuedStartRequest()), |buffer_pool| is created and creation of 175 // HandleQueuedStartRequest()), |buffer_pool| is created and creation of
176 // |video_capture_device| is scheduled to run asynchronously on the Device 176 // |video_capture_device| is scheduled to run asynchronously on the Device
177 // Thread. 177 // Thread.
178 // Phase 3: As soon as the creation of the VideoCaptureDevice is complete, this 178 // Phase 3: As soon as the creation of the VideoCaptureDevice is complete, this
179 // newly created VideoCaptureDevice instance is connected to the 179 // newly created VideoCaptureDevice instance is connected to the
180 // VideoCaptureController via SetConsumerFeedbackObserver(). Furthermore, the 180 // VideoCaptureController via SetConsumerFeedbackObserver(). Furthermore, the
181 // |buffer_pool| is connected to the |video_capture_controller| as a 181 // |buffer_pool| is moved to the |video_capture_controller| as a
182 // FrameBufferPool via SetFrameBufferPool(). 182 // FrameBufferPool via SetFrameBufferPool().
183 // Phase 4: This phase can only be reached on Android. When the application goes 183 // Phase 4: This phase can only be reached on Android. When the application goes
184 // to the background, the |video_capture_device| is asynchronously stopped and 184 // to the background, the |video_capture_device| is asynchronously stopped and
185 // released on the Device Thread. The existing |buffer_pool| is kept alive, and 185 // released on the Device Thread. When the application is resumed, we
186 // all clients of |video_capture_controller| stay connected. When the 186 // transition to Phase 2.
187 // application is resumed, we transition to Phase 2, except that the existing
188 // |buffer_pool| get reused instead of creating a new one.
189 struct VideoCaptureManager::DeviceEntry { 187 struct VideoCaptureManager::DeviceEntry {
190 public: 188 public:
191 DeviceEntry(MediaStreamType stream_type, 189 DeviceEntry(MediaStreamType stream_type,
192 const std::string& id, 190 const std::string& id,
193 const media::VideoCaptureParams& params); 191 const media::VideoCaptureParams& params);
194 ~DeviceEntry(); 192 ~DeviceEntry();
195 std::unique_ptr<media::VideoCaptureDevice::Client> CreateDeviceClient(); 193 std::unique_ptr<media::VideoCaptureDevice::Client> CreateDeviceClient();
196 std::unique_ptr<media::FrameBufferPool> CreateFrameBufferPool(); 194 std::unique_ptr<media::FrameBufferPool> CreateFrameBufferPool();
197 195
198 const int serial_id; 196 const int serial_id;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 DCHECK(video_capture_device == nullptr); 274 DCHECK(video_capture_device == nullptr);
277 } 275 }
278 276
279 std::unique_ptr<media::VideoCaptureDevice::Client> 277 std::unique_ptr<media::VideoCaptureDevice::Client>
280 VideoCaptureManager::DeviceEntry::CreateDeviceClient() { 278 VideoCaptureManager::DeviceEntry::CreateDeviceClient() {
281 DCHECK_CURRENTLY_ON(BrowserThread::IO); 279 DCHECK_CURRENTLY_ON(BrowserThread::IO);
282 280
283 const int max_buffers = stream_type == MEDIA_TAB_VIDEO_CAPTURE 281 const int max_buffers = stream_type == MEDIA_TAB_VIDEO_CAPTURE
284 ? kMaxNumberOfBuffersForTabCapture 282 ? kMaxNumberOfBuffersForTabCapture
285 : kMaxNumberOfBuffers; 283 : kMaxNumberOfBuffers;
286 if (!buffer_pool) { 284 buffer_pool = new media::VideoCaptureBufferPoolImpl(
287 buffer_pool = new media::VideoCaptureBufferPoolImpl( 285 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(),
288 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), 286 max_buffers);
289 max_buffers);
290 }
291 287
292 return base::MakeUnique<media::VideoCaptureDeviceClient>( 288 return base::MakeUnique<media::VideoCaptureDeviceClient>(
293 base::MakeUnique<VideoFrameReceiverOnIOThread>( 289 base::MakeUnique<VideoFrameReceiverOnIOThread>(
294 video_capture_controller.GetWeakPtrForIOThread()), 290 video_capture_controller.GetWeakPtrForIOThread()),
295 buffer_pool, 291 buffer_pool,
296 base::Bind( 292 base::Bind(
297 &CreateGpuJpegDecoder, 293 &CreateGpuJpegDecoder,
298 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, 294 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame,
299 video_capture_controller.GetWeakPtrForIOThread()))); 295 video_capture_controller.GetWeakPtrForIOThread())));
300 } 296 }
301 297
302 std::unique_ptr<media::FrameBufferPool> 298 std::unique_ptr<media::FrameBufferPool>
303 VideoCaptureManager::DeviceEntry::CreateFrameBufferPool() { 299 VideoCaptureManager::DeviceEntry::CreateFrameBufferPool() {
304 DCHECK_CURRENTLY_ON(BrowserThread::IO); 300 DCHECK_CURRENTLY_ON(BrowserThread::IO);
305 DCHECK(buffer_pool); 301 DCHECK(buffer_pool);
306 return base::MakeUnique<BufferPoolFrameBufferPool>(buffer_pool); 302 return base::MakeUnique<BufferPoolFrameBufferPool>(std::move(buffer_pool));
307 } 303 }
308 304
309 VideoCaptureManager::DeviceInfo::DeviceInfo() = default; 305 VideoCaptureManager::DeviceInfo::DeviceInfo() = default;
310 306
311 VideoCaptureManager::DeviceInfo::DeviceInfo( 307 VideoCaptureManager::DeviceInfo::DeviceInfo(
312 media::VideoCaptureDeviceDescriptor descriptor) 308 media::VideoCaptureDeviceDescriptor descriptor)
313 : descriptor(descriptor) {} 309 : descriptor(descriptor) {}
314 310
315 VideoCaptureManager::DeviceInfo::DeviceInfo( 311 VideoCaptureManager::DeviceInfo::DeviceInfo(
316 const VideoCaptureManager::DeviceInfo& other) = default; 312 const VideoCaptureManager::DeviceInfo& other) = default;
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 if (!device_in_queue) { 1338 if (!device_in_queue) {
1343 // Session ID is only valid for Screen capture. So we can fake it to 1339 // Session ID is only valid for Screen capture. So we can fake it to
1344 // resume video capture devices here. 1340 // resume video capture devices here.
1345 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); 1341 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters);
1346 } 1342 }
1347 } 1343 }
1348 } 1344 }
1349 #endif // defined(OS_ANDROID) 1345 #endif // defined(OS_ANDROID)
1350 1346
1351 } // namespace content 1347 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698