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

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

Issue 9320070: Re-added OnChannelClosing in MediaStreamDispatcherHost to close open media devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified according to chat with wjia. Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 29 matching lines...) Expand all
40 40
41 VideoCaptureManager::VideoCaptureManager() 41 VideoCaptureManager::VideoCaptureManager()
42 : vc_device_thread_("VideoCaptureManagerThread"), 42 : vc_device_thread_("VideoCaptureManagerThread"),
43 listener_(NULL), 43 listener_(NULL),
44 new_capture_session_id_(kFirstSessionId), 44 new_capture_session_id_(kFirstSessionId),
45 use_fake_device_(false) { 45 use_fake_device_(false) {
46 vc_device_thread_.Start(); 46 vc_device_thread_.Start();
47 } 47 }
48 48
49 VideoCaptureManager::~VideoCaptureManager() { 49 VideoCaptureManager::~VideoCaptureManager() {
50 // TODO(mflodman) Remove this temporary solution when shut-down issue is 50 DCHECK(devices_.empty());
51 // resolved, i.e. all code below this comment. 51
52 // Temporary solution: close all open devices and delete them, after the 52 // TODO(mflodman) Remove this temporary solution when all controllers are
53 // thread is stopped. 53 // guaranteed to be deleted before the destructor is called.
54 DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!";
55 listener_ = NULL; 54 listener_ = NULL;
56 // The devices must be stopped on the device thread to avoid threading issues
57 // in native device code.
58 vc_device_thread_.message_loop()->PostTask( 55 vc_device_thread_.message_loop()->PostTask(
mflodman_chromium_OOO 2012/02/10 13:24:41 There is a case when |controllers_| won't be empty
59 FROM_HERE, 56 FROM_HERE,
60 base::Bind(&VideoCaptureManager::TerminateOnDeviceThread, 57 base::Bind(&VideoCaptureManager::TerminateOnDeviceThread,
61 base::Unretained(this))); 58 base::Unretained(this)));
62 vc_device_thread_.Stop(); 59 vc_device_thread_.Stop();
63 } 60 }
64 61
65 void VideoCaptureManager::Register(MediaStreamProviderListener* listener) { 62 void VideoCaptureManager::Register(MediaStreamProviderListener* listener) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
67 DCHECK(!listener_); 64 DCHECK(!listener_);
68 listener_ = listener; 65 listener_ = listener;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 189 }
193 190
194 devices_[capture_session_id] = video_capture_device; 191 devices_[capture_session_id] = video_capture_device;
195 PostOnOpened(capture_session_id); 192 PostOnOpened(capture_session_id);
196 } 193 }
197 194
198 void VideoCaptureManager::OnClose(int capture_session_id) { 195 void VideoCaptureManager::OnClose(int capture_session_id) {
199 DCHECK(IsOnCaptureDeviceThread()); 196 DCHECK(IsOnCaptureDeviceThread());
200 197
201 media::VideoCaptureDevice* video_capture_device = NULL; 198 media::VideoCaptureDevice* video_capture_device = NULL;
202 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); 199 VideoCaptureDevices::iterator device_it = devices_.find(capture_session_id);
203 if (it != devices_.end()) { 200 if (device_it != devices_.end()) {
204 video_capture_device = it->second; 201 video_capture_device = device_it->second;
205 devices_.erase(it); 202 devices_.erase(device_it);
203 if (!DeviceInUse(video_capture_device)) {
204 // No other users of this device, deallocate (if not done already) and
205 // delete the device. No need to take care of the controller, that is done
206 // by |OnStop|.
207 video_capture_device->DeAllocate();
208 delete video_capture_device;
209 }
206 } 210 }
207 if (video_capture_device && !DeviceInUse(video_capture_device)) {
208 // Deallocate (if not done already) and delete the device.
209 video_capture_device->DeAllocate();
210 delete video_capture_device;
211 }
212
213 PostOnClosed(capture_session_id); 211 PostOnClosed(capture_session_id);
214 } 212 }
215 213
216 void VideoCaptureManager::OnStart( 214 void VideoCaptureManager::OnStart(
217 const media::VideoCaptureParams capture_params, 215 const media::VideoCaptureParams capture_params,
218 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { 216 media::VideoCaptureDevice::EventHandler* video_capture_receiver) {
219 DCHECK(IsOnCaptureDeviceThread()); 217 DCHECK(IsOnCaptureDeviceThread());
220 DCHECK(video_capture_receiver != NULL); 218 DCHECK(video_capture_receiver != NULL);
221 219
222 media::VideoCaptureDevice* video_capture_device = 220 media::VideoCaptureDevice* video_capture_device =
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); 497 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id);
500 if (dit != devices_.end()) { 498 if (dit != devices_.end()) {
501 return dit->second; 499 return dit->second;
502 } 500 }
503 } 501 }
504 return NULL; 502 return NULL;
505 } 503 }
506 504
507 void VideoCaptureManager::TerminateOnDeviceThread() { 505 void VideoCaptureManager::TerminateOnDeviceThread() {
508 DCHECK(IsOnCaptureDeviceThread()); 506 DCHECK(IsOnCaptureDeviceThread());
509
510 std::set<media::VideoCaptureDevice*> devices_to_delete;
511 for (VideoCaptureDevices::iterator it = devices_.begin();
512 it != devices_.end(); ++it) {
513 it->second->DeAllocate();
514 devices_to_delete.insert(it->second);
515 }
516 STLDeleteElements(&devices_to_delete);
517 STLDeleteValues(&controllers_); 507 STLDeleteValues(&controllers_);
518 } 508 }
519 509
520 } // namespace media_stream 510 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698