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

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: comments 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 call 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 // 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.
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. During
Ami GONE FROM CHROMIUM 2014/01/08 22:41:10 That seems like a great tradeoff to me in terms of
Alpha Left Google 2014/01/08 22:57:05 A tradeoff would be to have UseDevice return a med
28 : public base::RefCountedThreadSafe<VideoCaptureImplManager> { 39 // destruction |destruction_cb| is called. This mechanism is used
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 {
29 public: 68 public:
30 VideoCaptureImplManager(); 69 VideoCaptureImplManager();
70 virtual ~VideoCaptureImplManager();
31 71
32 // Called by video capture client |handler| to add device referenced 72 // Returns a video capture device referenced by |id|.
33 // by |id| to VideoCaptureImplManager's list of opened device list. 73 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 74
45 // Make all existing VideoCaptureImpl instances stop/resume delivering 75 // Make all existing VideoCaptureImpl instances stop/resume delivering
46 // video frames to their clients, depends on flag |suspend|. 76 // video frames to their clients, depends on flag |suspend|.
47 virtual void SuspendDevices(bool suspend); 77 void SuspendDevices(bool suspend);
48 78
49 VideoCaptureMessageFilter* video_capture_message_filter() const { 79 VideoCaptureMessageFilter* video_capture_message_filter() const {
50 return filter_.get(); 80 return filter_.get();
51 } 81 }
52 82
53 protected: 83 protected:
54 virtual ~VideoCaptureImplManager(); 84 virtual VideoCaptureImpl* CreateVideoCaptureImpl(
Ami GONE FROM CHROMIUM 2014/01/08 22:41:10 Comment this is protected for testing (mock).
Alpha Left Google 2014/01/08 22:57:05 Done.
85 media::VideoCaptureSessionId id,
86 VideoCaptureMessageFilter* filter) const;
55 87
56 private: 88 private:
57 friend class base::RefCountedThreadSafe<VideoCaptureImplManager>; 89 void UnrefDevice(media::VideoCaptureSessionId id);
58 90
59 struct Device { 91 // The int is used to count clients of the corresponding VideoCaptureImpl.
60 Device(VideoCaptureImpl* device, 92 typedef std::map<media::VideoCaptureSessionId,
61 media::VideoCapture::EventHandler* handler); 93 std::pair<int, linked_ptr<VideoCaptureImpl> > >
62 ~Device(); 94 VideoCaptureDeviceMap;
95 VideoCaptureDeviceMap devices_;
63 96
64 VideoCaptureImpl* vc; 97 scoped_refptr<VideoCaptureMessageFilter> filter_;
65 std::list<media::VideoCapture::EventHandler*> clients;
66 };
67 98
68 void FreeDevice(VideoCaptureImpl* vc); 99 // Following two members are bound to the render thread.
69 100 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_;
70 typedef std::map<media::VideoCaptureSessionId, Device*> Devices; 101 base::ThreadChecker thread_checker_;
71 Devices devices_;
72 base::Lock lock_;
73 scoped_refptr<VideoCaptureMessageFilter> filter_;
74 base::Thread thread_;
75 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
76 102
77 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); 103 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager);
78 }; 104 };
79 105
80 } // namespace content 106 } // namespace content
81 107
82 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ 108 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698