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

Side by Side Diff: content/renderer/media/video_capture_impl_manager.h

Issue 120893002: Eliminate video capture thread in renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile warning Created 6 years, 11 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) 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 // VideoCaptureImplManager manages video capture devices in renderer process. 5 // VideoCaptureImplManager owns VideoCaptureImpl objects. Clients who
6 // The video capture clients use AddDevice() to get a pointer to 6 // want access to a video capture device calls UseDevice() to get a handle
7 // video capture device. VideoCaputreImplManager supports multiple clients 7 // to VideoCaptureImpl.
8 // accessing same device. 8 //
9 // THREADING
10 //
11 // This object lives only on the render thread. All methods must be called
12 // on this thread.
13 //
14 // The handle returned by UseDevice() is thread-safe. It ensures
15 // destruction handles on the render thread.
Jói 2013/12/27 13:34:35 destruction handles on -> destruction is handled o
Alpha Left Google 2013/12/27 21:30:01 Done.
9 16
10 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ 17 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
11 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ 18 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
12 19
13 #include <list>
14 #include <map> 20 #include <map>
15 21
22 #include "base/callback.h"
23 #include "base/memory/linked_ptr.h"
24 #include "base/memory/scoped_ptr.h"
25 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop_proxy.h" 26 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/threading/thread.h"
18 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
28 #include "base/threading/thread_checker.h"
19 #include "content/common/content_export.h" 29 #include "content/common/content_export.h"
20 #include "media/video/capture/video_capture.h" 30 #include "media/video/capture/video_capture.h"
21 31
22 namespace content { 32 namespace content {
23 33
24 class VideoCaptureImpl; 34 class VideoCaptureImpl;
35 class VideoCaptureImplManager;
25 class VideoCaptureMessageFilter; 36 class VideoCaptureMessageFilter;
26 37
27 class CONTENT_EXPORT VideoCaptureImplManager 38 // Thread-safe wrapper for a media::VideoCapture object. This class
28 : public base::RefCountedThreadSafe<VideoCaptureImplManager> { 39 // ensures refcounting is done on the render thread.
40 class CONTENT_EXPORT VideoCaptureHandle : media::VideoCapture {
41 public:
42 virtual ~VideoCaptureHandle();
43
44 // media::VideoCapture implementations.
45 virtual void StartCapture(
46 EventHandler* handler,
47 const media::VideoCaptureParams& params) OVERRIDE;
48 virtual void StopCapture(EventHandler* handler) OVERRIDE;
49 virtual bool CaptureStarted() OVERRIDE;
50 virtual int CaptureFrameRate() OVERRIDE;
51
52 private:
53 friend class VideoCaptureImplManager;
54
55 VideoCaptureHandle(media::VideoCapture* impl,
56 base::Closure destruction_cb);
57
58 media::VideoCapture* impl_;
59 base::Closure destruction_cb_;
60
61 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHandle);
62 };
63
64 class CONTENT_EXPORT VideoCaptureImplManager {
29 public: 65 public:
30 VideoCaptureImplManager(); 66 VideoCaptureImplManager();
67 virtual ~VideoCaptureImplManager();
31 68
32 // Called by video capture client |handler| to add device referenced 69 // Returns a video capture device referenced by |id|.
33 // by |id| to VideoCaptureImplManager's list of opened device list. 70 scoped_ptr<VideoCaptureHandle> UseDevice(media::VideoCaptureSessionId id);
34 // A pointer to VideoCapture is returned to client so that client can
35 // operate on that pointer, such as StartCaptrue, StopCapture.
36 virtual media::VideoCapture* AddDevice(
37 media::VideoCaptureSessionId id,
38 media::VideoCapture::EventHandler* handler);
39
40 // Called by video capture client |handler| to remove device referenced
41 // by |id| from VideoCaptureImplManager's list of opened device list.
42 virtual void RemoveDevice(media::VideoCaptureSessionId id,
43 media::VideoCapture::EventHandler* handler);
44 71
45 // Make all existing VideoCaptureImpl instances stop/resume delivering 72 // Make all existing VideoCaptureImpl instances stop/resume delivering
46 // video frames to their clients, depends on flag |suspend|. 73 // video frames to their clients, depends on flag |suspend|.
47 virtual void SuspendDevices(bool suspend); 74 void SuspendDevices(bool suspend);
48 75
49 VideoCaptureMessageFilter* video_capture_message_filter() const { 76 VideoCaptureMessageFilter* video_capture_message_filter() const {
50 return filter_.get(); 77 return filter_.get();
51 } 78 }
52 79
53 protected: 80 private:
54 virtual ~VideoCaptureImplManager(); 81 void UnrefDevice(media::VideoCaptureSessionId id);
55 82
56 private: 83 typedef std::map<media::VideoCaptureSessionId,
57 friend class base::RefCountedThreadSafe<VideoCaptureImplManager>; 84 linked_ptr<VideoCaptureImpl> > VideoCaptureDeviceMap;
85 VideoCaptureDeviceMap devices_;
86 std::map<media::VideoCaptureSessionId, int> use_count_;
58 87
59 struct Device {
60 Device(VideoCaptureImpl* device,
61 media::VideoCapture::EventHandler* handler);
62 ~Device();
63
64 VideoCaptureImpl* vc;
65 std::list<media::VideoCapture::EventHandler*> clients;
66 };
67
68 void FreeDevice(VideoCaptureImpl* vc);
69
70 typedef std::map<media::VideoCaptureSessionId, Device*> Devices;
71 Devices devices_;
72 base::Lock lock_;
73 scoped_refptr<VideoCaptureMessageFilter> filter_; 88 scoped_refptr<VideoCaptureMessageFilter> filter_;
74 base::Thread thread_; 89 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_;
75 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 90 base::ThreadChecker thread_checker_;
76 91
77 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); 92 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager);
78 }; 93 };
79 94
80 } // namespace content 95 } // namespace content
81 96
82 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ 97 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698