OLD | NEW |
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 // VideoCaptureManager is used to open/close, start/stop as well as enumerate | 5 // VideoCaptureManager is used to open/close, start/stop as well as enumerate |
6 // available video capture devices. All functions are expected to be called from | 6 // available video capture devices. All functions are expected to be called from |
7 // the Browser::IO thread. VideoCaptureManager will open OS dependent instances | 7 // the Browser::IO thread. VideoCaptureManager will open OS dependent instances |
8 // of VideoCaptureDevice. A device can only be opened once. | 8 // of VideoCaptureDevice. A device can only be opened once. |
9 | 9 |
10 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 10 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
11 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 11 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 | 14 |
15 #include "base/lazy_instance.h" | |
16 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
17 #include "content/browser/renderer_host/media/media_stream_provider.h" | 16 #include "content/browser/renderer_host/media/media_stream_provider.h" |
18 #include "content/common/media/media_stream_options.h" | 17 #include "content/common/media/media_stream_options.h" |
19 #include "media/video/capture/video_capture_device.h" | 18 #include "media/video/capture/video_capture_device.h" |
20 #include "media/video/capture/video_capture_types.h" | 19 #include "media/video/capture/video_capture_types.h" |
21 | 20 |
22 namespace media_stream { | 21 namespace media_stream { |
23 | 22 |
24 // VideoCaptureManager opens/closes and start/stops video capture devices. | 23 // VideoCaptureManager opens/closes and start/stops video capture devices. |
25 class VideoCaptureManager : public MediaStreamProvider { | 24 class VideoCaptureManager : public MediaStreamProvider { |
26 public: | 25 public: |
27 // Calling |Start| of this id will open the first device, even though open has | 26 // Calling |Start| of this id will open the first device, even though open has |
28 // not been called. This is used to be able to use video capture devices | 27 // not been called. This is used to be able to use video capture devices |
29 // before MediaStream is implemented in Chrome and WebKit. | 28 // before MediaStream is implemented in Chrome and WebKit. |
30 enum { kStartOpenSessionId = 1 }; | 29 enum { kStartOpenSessionId = 1 }; |
31 | 30 |
32 // Called to get a pointer to the singleton. | 31 VideoCaptureManager(); |
33 static VideoCaptureManager* Get(); | 32 virtual ~VideoCaptureManager(); |
34 | 33 |
35 // Implements MediaStreamProvider. | 34 // Implements MediaStreamProvider. |
36 virtual void Register(MediaStreamProviderListener* listener); | 35 virtual void Register(MediaStreamProviderListener* listener); |
37 | 36 |
38 virtual void Unregister(); | 37 virtual void Unregister(); |
39 | 38 |
40 virtual void EnumerateDevices(); | 39 virtual void EnumerateDevices(); |
41 | 40 |
42 virtual int Open(const StreamDeviceInfo& device); | 41 virtual int Open(const StreamDeviceInfo& device); |
43 | 42 |
44 virtual void Close(int capture_session_id); | 43 virtual void Close(int capture_session_id); |
45 | 44 |
46 // Functions used to start and stop media flow. | 45 // Functions used to start and stop media flow. |
47 // Start allocates the device and no other application can use the device | 46 // Start allocates the device and no other application can use the device |
48 // before Stop is called. Captured video frames will be delivered to | 47 // before Stop is called. Captured video frames will be delivered to |
49 // video_capture_receiver. | 48 // video_capture_receiver. |
50 void Start(const media::VideoCaptureParams& capture_params, | 49 void Start(const media::VideoCaptureParams& capture_params, |
51 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 50 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
52 | 51 |
53 // Stops capture device referenced by |capture_session_id|. No more frames | 52 // Stops capture device referenced by |capture_session_id|. No more frames |
54 // will be delivered to the frame receiver, and |stopped_task| will be called. | 53 // will be delivered to the frame receiver, and |stopped_task| will be called. |
55 void Stop(const media::VideoCaptureSessionId& capture_session_id, | 54 void Stop(const media::VideoCaptureSessionId& capture_session_id, |
56 Task* stopped_task); | 55 Task* stopped_task); |
57 | 56 |
58 // A capture device error has occurred for |capture_session_id|. The device | 57 // A capture device error has occurred for |capture_session_id|. The device |
59 // won't stream any more captured frames. | 58 // won't stream any more captured frames. |
60 void Error(const media::VideoCaptureSessionId& capture_session_id); | 59 void Error(const media::VideoCaptureSessionId& capture_session_id); |
61 | 60 |
62 virtual ~VideoCaptureManager(); | |
63 | |
64 // Used by unit test to make sure a fake device is used instead of a real | 61 // Used by unit test to make sure a fake device is used instead of a real |
65 // video capture device. Due to timing requirements, the function must be | 62 // video capture device. Due to timing requirements, the function must be |
66 // called before EnumerateDevices and Open. | 63 // called before EnumerateDevices and Open. |
67 void UseFakeDevice(); | 64 void UseFakeDevice(); |
68 MessageLoop* GetMessageLoop(); | 65 MessageLoop* GetMessageLoop(); |
69 | 66 |
70 private: | 67 private: |
71 friend struct base::DefaultLazyInstanceTraits<VideoCaptureManager>; | |
72 | |
73 VideoCaptureManager(); | |
74 | |
75 // Called by the public functions, executed on vc_device_thread_. | 68 // Called by the public functions, executed on vc_device_thread_. |
76 void OnEnumerateDevices(); | 69 void OnEnumerateDevices(); |
77 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); | 70 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); |
78 void OnClose(int capture_session_id); | 71 void OnClose(int capture_session_id); |
79 void OnStart(const media::VideoCaptureParams capture_params, | 72 void OnStart(const media::VideoCaptureParams capture_params, |
80 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 73 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
81 void OnStop(const media::VideoCaptureSessionId capture_session_id, | 74 void OnStop(const media::VideoCaptureSessionId capture_session_id, |
82 Task* stopped_task); | 75 Task* stopped_task); |
83 | 76 |
84 // Executed on Browser::IO thread to call Listener. | 77 // Executed on Browser::IO thread to call Listener. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 bool use_fake_device_; | 110 bool use_fake_device_; |
118 | 111 |
119 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 112 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
120 }; | 113 }; |
121 | 114 |
122 } // namespace media_stream | 115 } // namespace media_stream |
123 | 116 |
124 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); | 117 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); |
125 | 118 |
126 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 119 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |