OLD | NEW |
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 manages video capture devices in renderer process. |
6 // The video capture clients use AddDevice() to get a pointer to | 6 // The video capture clients use AddDevice() to get a pointer to |
7 // video capture device. VideoCaputreImplManager supports multiple clients | 7 // video capture device. VideoCaputreImplManager supports multiple clients |
8 // accessing same device. | 8 // accessing same device. |
9 | 9 |
10 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 10 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
11 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 11 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
12 | 12 |
13 #include <list> | 13 #include <list> |
14 #include <map> | 14 #include <map> |
15 | 15 |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
18 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
19 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
20 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
21 #include "media/video/capture/video_capture.h" | 20 #include "media/video/capture/video_capture.h" |
22 #include "media/video/encoded_video_source.h" | |
23 | 21 |
24 namespace content { | 22 namespace content { |
25 | 23 |
26 class RtcEncodingVideoCapturerFactory; | |
27 class VideoCaptureImpl; | 24 class VideoCaptureImpl; |
28 class VideoCaptureMessageFilter; | 25 class VideoCaptureMessageFilter; |
29 | 26 |
30 class CONTENT_EXPORT VideoCaptureImplManager | 27 class CONTENT_EXPORT VideoCaptureImplManager |
31 : public base::RefCountedThreadSafe<VideoCaptureImplManager> { | 28 : public base::RefCountedThreadSafe<VideoCaptureImplManager> { |
32 public: | 29 public: |
33 VideoCaptureImplManager(); | 30 VideoCaptureImplManager(); |
34 | 31 |
35 // Called by video capture client |handler| to add device referenced | 32 // Called by video capture client |handler| to add device referenced |
36 // by |id| to VideoCaptureImplManager's list of opened device list. | 33 // by |id| to VideoCaptureImplManager's list of opened device list. |
37 // A pointer to VideoCapture is returned to client so that client can | 34 // A pointer to VideoCapture is returned to client so that client can |
38 // operate on that pointer, such as StartCaptrue, StopCapture. | 35 // operate on that pointer, such as StartCaptrue, StopCapture. |
39 virtual media::VideoCapture* AddDevice( | 36 virtual media::VideoCapture* AddDevice( |
40 media::VideoCaptureSessionId id, | 37 media::VideoCaptureSessionId id, |
41 media::VideoCapture::EventHandler* handler); | 38 media::VideoCapture::EventHandler* handler); |
42 | 39 |
43 // Called by video capture client |handler| to remove device referenced | 40 // Called by video capture client |handler| to remove device referenced |
44 // by |id| from VideoCaptureImplManager's list of opened device list. | 41 // by |id| from VideoCaptureImplManager's list of opened device list. |
45 virtual void RemoveDevice(media::VideoCaptureSessionId id, | 42 virtual void RemoveDevice(media::VideoCaptureSessionId id, |
46 media::VideoCapture::EventHandler* handler); | 43 media::VideoCapture::EventHandler* handler); |
47 | 44 |
48 // Make all existing VideoCaptureImpl instances stop/resume delivering | 45 // Make all existing VideoCaptureImpl instances stop/resume delivering |
49 // video frames to their clients, depends on flag |suspend|. | 46 // video frames to their clients, depends on flag |suspend|. |
50 virtual void SuspendDevices(bool suspend); | 47 virtual void SuspendDevices(bool suspend); |
51 | 48 |
52 VideoCaptureMessageFilter* video_capture_message_filter() const { | 49 VideoCaptureMessageFilter* video_capture_message_filter() const { |
53 return filter_.get(); | 50 return filter_.get(); |
54 } | 51 } |
55 | 52 |
56 void set_encoding_capturer_factory(base::WeakPtr< | |
57 RtcEncodingVideoCapturerFactory> encoding_capturer_factory) { | |
58 encoding_capturer_factory_ = encoding_capturer_factory; | |
59 } | |
60 | |
61 protected: | 53 protected: |
62 virtual ~VideoCaptureImplManager(); | 54 virtual ~VideoCaptureImplManager(); |
63 | 55 |
64 private: | 56 private: |
65 friend class base::RefCountedThreadSafe<VideoCaptureImplManager>; | 57 friend class base::RefCountedThreadSafe<VideoCaptureImplManager>; |
66 | 58 |
67 struct Device { | 59 struct Device { |
68 Device(VideoCaptureImpl* device, | 60 Device(VideoCaptureImpl* device, |
69 media::VideoCapture::EventHandler* handler); | 61 media::VideoCapture::EventHandler* handler); |
70 ~Device(); | 62 ~Device(); |
71 | 63 |
72 VideoCaptureImpl* vc; | 64 VideoCaptureImpl* vc; |
73 std::list<media::VideoCapture::EventHandler*> clients; | 65 std::list<media::VideoCapture::EventHandler*> clients; |
74 }; | 66 }; |
75 | 67 |
76 void FreeDevice(VideoCaptureImpl* vc); | 68 void FreeDevice(VideoCaptureImpl* vc); |
77 | 69 |
78 typedef std::map<media::VideoCaptureSessionId, Device*> Devices; | 70 typedef std::map<media::VideoCaptureSessionId, Device*> Devices; |
79 Devices devices_; | 71 Devices devices_; |
80 base::Lock lock_; | 72 base::Lock lock_; |
81 scoped_refptr<VideoCaptureMessageFilter> filter_; | 73 scoped_refptr<VideoCaptureMessageFilter> filter_; |
82 base::Thread thread_; | 74 base::Thread thread_; |
83 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 75 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
84 | 76 |
85 // The encoding capturer factory is created by MediaStreamDependencyFactory | |
86 // and owned by its PeerConnectionFactory. It is passed to the manager | |
87 // as a weak pointer at CreatePeerConnectionFactory time because the | |
88 // PeerConnectionFactory may be released earlier than the manager. | |
89 base::WeakPtr<RtcEncodingVideoCapturerFactory> encoding_capturer_factory_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); | 77 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); |
92 }; | 78 }; |
93 | 79 |
94 } // namespace content | 80 } // namespace content |
95 | 81 |
96 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 82 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
OLD | NEW |