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

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

Issue 135683002: Revert 244074 "Eliminate video capture thread in renderer" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 owns VideoCaptureImpl objects. Clients who 5 // VideoCaptureImplManager manages video capture devices in renderer process.
6 // want access to a video capture device call UseDevice() to get a handle 6 // The video capture clients use AddDevice() to get a pointer to
7 // to VideoCaptureImpl. 7 // video capture device. VideoCaputreImplManager supports multiple clients
8 // 8 // accessing same device.
9 // THREADING
10 //
11 // VideoCaptureImplManager lives only on the render thread. All methods
12 // must be called on this thread.
13 //
14 // The handle returned by UseDevice() is thread-safe. It ensures
15 // destruction is handled on the render thread.
16 9
17 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ 10 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
18 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ 11 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
19 12
13 #include <list>
20 #include <map> 14 #include <map>
21 15
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"
26 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/threading/thread.h"
27 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
28 #include "base/threading/thread_checker.h"
29 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
30 #include "media/video/capture/video_capture.h" 20 #include "media/video/capture/video_capture.h"
31 21
32 namespace content { 22 namespace content {
33 23
34 class VideoCaptureImpl; 24 class VideoCaptureImpl;
35 class VideoCaptureImplManager;
36 class VideoCaptureMessageFilter; 25 class VideoCaptureMessageFilter;
37 26
38 // Thread-safe wrapper for a media::VideoCapture object. During 27 class CONTENT_EXPORT VideoCaptureImplManager
39 // destruction |destruction_cb| is called. This mechanism is used 28 : public base::RefCountedThreadSafe<VideoCaptureImplManager> {
40 // by VideoCaptureImplManager to ensure de-initialization and
41 // destruction of the media::VideoCapture object happens on the render
42 // thread.
43 class CONTENT_EXPORT VideoCaptureHandle : media::VideoCapture {
44 public:
45 virtual ~VideoCaptureHandle();
46
47 // media::VideoCapture implementations.
48 virtual void StartCapture(
49 EventHandler* handler,
50 const media::VideoCaptureParams& params) OVERRIDE;
51 virtual void StopCapture(EventHandler* handler) OVERRIDE;
52 virtual bool CaptureStarted() OVERRIDE;
53 virtual int CaptureFrameRate() OVERRIDE;
54
55 private:
56 friend class VideoCaptureImplManager;
57
58 VideoCaptureHandle(media::VideoCapture* impl,
59 base::Closure destruction_cb);
60
61 media::VideoCapture* impl_;
62 base::Closure destruction_cb_;
63
64 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHandle);
65 };
66
67 class CONTENT_EXPORT VideoCaptureImplManager {
68 public: 29 public:
69 VideoCaptureImplManager(); 30 VideoCaptureImplManager();
70 virtual ~VideoCaptureImplManager();
71 31
72 // Returns a video capture device referenced by |id|. 32 // Called by video capture client |handler| to add device referenced
73 scoped_ptr<VideoCaptureHandle> UseDevice(media::VideoCaptureSessionId id); 33 // by |id| to VideoCaptureImplManager's list of opened device list.
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);
74 44
75 // Make all existing VideoCaptureImpl instances stop/resume delivering 45 // Make all existing VideoCaptureImpl instances stop/resume delivering
76 // video frames to their clients, depends on flag |suspend|. 46 // video frames to their clients, depends on flag |suspend|.
77 void SuspendDevices(bool suspend); 47 virtual void SuspendDevices(bool suspend);
78 48
79 VideoCaptureMessageFilter* video_capture_message_filter() const { 49 VideoCaptureMessageFilter* video_capture_message_filter() const {
80 return filter_.get(); 50 return filter_.get();
81 } 51 }
82 52
83 protected: 53 protected:
84 // Used in tests to inject a mock VideoCaptureImpl. 54 virtual ~VideoCaptureImplManager();
85 virtual VideoCaptureImpl* CreateVideoCaptureImpl(
86 media::VideoCaptureSessionId id,
87 VideoCaptureMessageFilter* filter) const;
88 55
89 private: 56 private:
90 void UnrefDevice(media::VideoCaptureSessionId id); 57 friend class base::RefCountedThreadSafe<VideoCaptureImplManager>;
91 58
92 // The int is used to count clients of the corresponding VideoCaptureImpl. 59 struct Device {
93 typedef std::map<media::VideoCaptureSessionId, 60 Device(VideoCaptureImpl* device,
94 std::pair<int, linked_ptr<VideoCaptureImpl> > > 61 media::VideoCapture::EventHandler* handler);
95 VideoCaptureDeviceMap; 62 ~Device();
96 VideoCaptureDeviceMap devices_;
97 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_;
98 scoped_refptr<VideoCaptureMessageFilter> filter_; 73 scoped_refptr<VideoCaptureMessageFilter> filter_;
99 74 base::Thread thread_;
100 // Following two members are bound to the render thread. 75 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
101 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_;
102 base::ThreadChecker thread_checker_;
103 76
104 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); 77 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager);
105 }; 78 };
106 79
107 } // namespace content 80 } // namespace content
108 81
109 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ 82 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
OLDNEW
« no previous file with comments | « trunk/src/content/renderer/media/video_capture_impl.cc ('k') | trunk/src/content/renderer/media/video_capture_impl_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698