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

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

Issue 8589018: Close video capture devices on the device thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes based on review by wjia. Created 9 years, 1 month 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
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/stl_util.h" 10 #include "base/stl_util.h"
9 #include "content/browser/renderer_host/media/video_capture_controller.h" 11 #include "content/browser/renderer_host/media/video_capture_controller.h"
10 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 12 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
11 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
12 #include "media/video/capture/fake_video_capture_device.h" 14 #include "media/video/capture/fake_video_capture_device.h"
13 #include "media/video/capture/video_capture_device.h" 15 #include "media/video/capture/video_capture_device.h"
14 16
15 using content::BrowserThread; 17 using content::BrowserThread;
16 18
(...skipping 21 matching lines...) Expand all
38 40
39 VideoCaptureManager::VideoCaptureManager() 41 VideoCaptureManager::VideoCaptureManager()
40 : vc_device_thread_("VideoCaptureManagerThread"), 42 : vc_device_thread_("VideoCaptureManagerThread"),
41 listener_(NULL), 43 listener_(NULL),
42 new_capture_session_id_(kFirstSessionId), 44 new_capture_session_id_(kFirstSessionId),
43 use_fake_device_(false) { 45 use_fake_device_(false) {
44 vc_device_thread_.Start(); 46 vc_device_thread_.Start();
45 } 47 }
46 48
47 VideoCaptureManager::~VideoCaptureManager() { 49 VideoCaptureManager::~VideoCaptureManager() {
48 vc_device_thread_.Stop();
49 // TODO(mflodman) Remove this temporary solution when shut-down issue is 50 // TODO(mflodman) Remove this temporary solution when shut-down issue is
50 // resolved, i.e. all code below this comment. 51 // resolved, i.e. all code below this comment.
51 // Temporary solution: close all open devices and delete them, after the 52 // Temporary solution: close all open devices and delete them, after the
52 // thread is stopped. 53 // thread is stopped.
53 DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!"; 54 DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!";
54 for (VideoCaptureDevices::iterator it = devices_.begin(); 55 listener_ = NULL;
55 it != devices_.end(); 56 // The devices must be stopped on the device thread to avoid threading issues
56 ++it) { 57 // in native device code.
57 it->second->DeAllocate(); 58 vc_device_thread_.message_loop()->PostTask(
58 delete it->second; 59 FROM_HERE,
59 } 60 base::Bind(&VideoCaptureManager::TerminateOnDeviceThread,
60 STLDeleteValues(&controllers_); 61 base::Unretained(this)));
62 vc_device_thread_.Stop();
61 } 63 }
62 64
63 void VideoCaptureManager::Register(MediaStreamProviderListener* listener) { 65 void VideoCaptureManager::Register(MediaStreamProviderListener* listener) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
65 DCHECK(!listener_); 67 DCHECK(!listener_);
66 listener_ = listener; 68 listener_ = listener;
67 } 69 }
68 70
69 void VideoCaptureManager::Unregister() { 71 void VideoCaptureManager::Unregister() {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 OnOpen(capture_session_id, device); 497 OnOpen(capture_session_id, device);
496 498
497 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); 499 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id);
498 if (dit != devices_.end()) { 500 if (dit != devices_.end()) {
499 return dit->second; 501 return dit->second;
500 } 502 }
501 } 503 }
502 return NULL; 504 return NULL;
503 } 505 }
504 506
507 void VideoCaptureManager::TerminateOnDeviceThread() {
508 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_);
518 }
519
505 } // namespace media_stream 520 } // namespace media_stream
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698