Chromium Code Reviews| 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" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "content/browser/renderer_host/media/media_stream_provider.h" | 17 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 18 #include "content/common/media/media_stream_options.h" | |
| 18 #include "media/video/capture/video_capture_device.h" | 19 #include "media/video/capture/video_capture_device.h" |
| 19 #include "media/video/capture/video_capture_types.h" | 20 #include "media/video/capture/video_capture_types.h" |
| 20 | 21 |
| 21 namespace media_stream { | 22 namespace media_stream { |
| 22 | 23 |
| 23 // VideoCaptureManager opens/closes and start/stops video capture devices. | 24 // VideoCaptureManager opens/closes and start/stops video capture devices. |
| 24 class VideoCaptureManager : public MediaStreamProvider { | 25 class VideoCaptureManager : public MediaStreamProvider { |
| 25 public: | 26 public: |
| 26 // Calling |Start| of this id will open the first device, even though open has | 27 // Calling |Start| of this id will open the first device, even though open has |
| 27 // not been called. This is used to be able to use video capture devices | 28 // not been called. This is used to be able to use video capture devices |
| 28 // before MediaStream is implemented in Chrome and WebKit. | 29 // before MediaStream is implemented in Chrome and WebKit. |
| 29 enum { kStartOpenSessionId = 1 }; | 30 enum { kStartOpenSessionId = 1 }; |
| 30 | 31 |
| 31 // Called to get a pointer to the singleton | 32 // Called to get a pointer to the singleton |
| 32 static VideoCaptureManager* Get(); | 33 static VideoCaptureManager* Get(); |
| 33 | 34 |
| 34 // Implements MediaStreamProvider. | 35 // Implements MediaStreamProvider. |
| 35 virtual bool Register(MediaStreamProviderListener* listener); | 36 virtual void Register(MediaStreamProviderListener* listener); |
| 36 | 37 |
| 37 virtual void Unregister(); | 38 virtual void Unregister(); |
| 38 | 39 |
| 39 virtual void EnumerateDevices(); | 40 virtual void EnumerateDevices(); |
| 40 | 41 |
| 41 virtual MediaCaptureSessionId Open(const MediaCaptureDeviceInfo& device); | 42 virtual int Open(const StreamDeviceInfo& device); |
| 42 | 43 |
| 43 virtual void Close(MediaCaptureSessionId capture_session_id); | 44 virtual void Close(int capture_session_id); |
| 44 | 45 |
| 45 // Functions used to start and stop media flow. | 46 // Functions used to start and stop media flow. |
| 46 // Start allocates the device and no other application can use the device | 47 // Start allocates the device and no other application can use the device |
| 47 // before Stop is called. Captured video frames will be delivered to | 48 // before Stop is called. Captured video frames will be delivered to |
| 48 // video_capture_receiver. | 49 // video_capture_receiver. |
| 49 void Start(const media::VideoCaptureParams& capture_params, | 50 void Start(const media::VideoCaptureParams& capture_params, |
| 50 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 51 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| 51 | 52 |
| 52 // Stops capture device referenced by |capture_session_id|. No more frames | 53 // Stops capture device referenced by |capture_session_id|. No more frames |
| 53 // will be delivered to the frame receiver, and |stopped_task| will be called. | 54 // will be delivered to the frame receiver, and |stopped_task| will be called. |
| 54 void Stop(const media::VideoCaptureSessionId capture_session_id, | 55 void Stop(const media::VideoCaptureSessionId capture_session_id, |
| 55 Task* stopped_task); | 56 Task* stopped_task); |
| 56 | 57 |
| 58 // A capture device error has occurred for |capture_sessions_id|. The device | |
|
John Knottenbelt
2011/06/16 15:20:43
nit: capture_session_id
mflodman1
2011/06/20 19:48:03
Done.
| |
| 59 // won't stream any more captured frames. | |
| 60 void Error(const media::VideoCaptureSessionId capture_session_id); | |
|
scherkus (not reviewing)
2011/06/17 03:03:52
const-ref ?
mflodman1
2011/06/20 19:48:03
Done.
I'd prefer to remove this typedef and just u
| |
| 61 | |
| 57 virtual ~VideoCaptureManager(); | 62 virtual ~VideoCaptureManager(); |
| 58 | 63 |
| 59 // Used by unit test to make sure a fake device is used instead of a real | 64 // Used by unit test to make sure a fake device is used instead of a real |
| 60 // video capture device. Due to timing requirements, the function must be | 65 // video capture device. Due to timing requirements, the function must be |
| 61 // called before EnumerateDevices and Open. | 66 // called before EnumerateDevices and Open. |
| 62 void UseFakeDevice(); | 67 void UseFakeDevice(); |
| 63 MessageLoop* GetMessageLoop(); | 68 MessageLoop* GetMessageLoop(); |
| 64 | 69 |
| 65 private: | 70 private: |
| 66 friend struct base::DefaultLazyInstanceTraits<VideoCaptureManager>; | 71 friend struct base::DefaultLazyInstanceTraits<VideoCaptureManager>; |
| 67 | 72 |
| 68 VideoCaptureManager(); | 73 VideoCaptureManager(); |
| 69 | 74 |
| 70 // Called by the public functions, executed on vc_device_thread_. | 75 // Called by the public functions, executed on vc_device_thread_. |
| 71 void OnEnumerateDevices(); | 76 void OnEnumerateDevices(); |
| 72 void OnOpen(MediaCaptureSessionId capture_session_id, | 77 void OnOpen(int capture_session_id, const StreamDeviceInfo device); |
|
John Knottenbelt
2011/06/16 15:20:43
Is it possible to pass const references here for S
mflodman1
2011/06/20 19:48:03
Done.
| |
| 73 const MediaCaptureDeviceInfo device); | 78 void OnClose(int capture_session_id); |
| 74 void OnClose(MediaCaptureSessionId capture_session_id); | |
| 75 void OnStart(const media::VideoCaptureParams capture_params, | 79 void OnStart(const media::VideoCaptureParams capture_params, |
| 76 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 80 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| 77 void OnStop(const media::VideoCaptureSessionId capture_session_id, | 81 void OnStop(const media::VideoCaptureSessionId capture_session_id, |
| 78 Task* stopped_task); | 82 Task* stopped_task); |
| 79 | 83 |
| 80 | |
| 81 // Executed on Browser::IO thread to call Listener. | 84 // Executed on Browser::IO thread to call Listener. |
| 82 void OnOpened(MediaCaptureSessionId capture_session_id); | 85 void OnOpened(int capture_session_id); |
| 83 void OnClosed(MediaCaptureSessionId capture_session_id); | 86 void OnClosed(int capture_session_id); |
| 84 void OnDevicesEnumerated(const MediaCaptureDevices& devices); | 87 void OnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
| 85 void OnError(MediaCaptureSessionId capture_session_id, | 88 void OnError(int capture_session_id, MediaStreamProviderError error); |
| 86 MediaStreamProviderError error); | |
| 87 | 89 |
| 88 // Executed on vc_device_thread_ to make sure Listener is called from | 90 // Executed on vc_device_thread_ to make sure Listener is called from |
| 89 // Browser::IO thread. | 91 // Browser::IO thread. |
| 90 void PostOnOpened(MediaCaptureSessionId capture_session_id); | 92 void PostOnOpened(int capture_session_id); |
| 91 void PostOnClosed(MediaCaptureSessionId capture_session_id); | 93 void PostOnClosed(int capture_session_id); |
| 92 void PostOnDevicesEnumerated(MediaCaptureDevices devices); | 94 void PostOnDevicesEnumerated(StreamDeviceInfoArray devices); |
| 93 void PostOnError(MediaCaptureSessionId capture_session_id, | 95 void PostOnError(int capture_session_id, MediaStreamProviderError error); |
| 94 MediaStreamProviderError error); | |
| 95 | 96 |
| 96 // Helpers | 97 // Helpers |
| 97 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); | 98 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); |
| 98 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); | 99 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); |
| 99 bool DeviceOpened(const MediaCaptureDeviceInfo& device_info); | 100 bool DeviceOpened(const StreamDeviceInfo& device_info); |
| 100 bool IsOnCaptureDeviceThread() const; | 101 bool IsOnCaptureDeviceThread() const; |
| 101 | 102 |
| 102 // Thread for all calls to VideoCaptureDevice | 103 // Thread for all calls to VideoCaptureDevice |
| 103 base::Thread vc_device_thread_; | 104 base::Thread vc_device_thread_; |
| 104 | 105 |
| 105 // Only accessed on Browser::IO thread | 106 // Only accessed on Browser::IO thread |
| 106 MediaStreamProviderListener* listener_; | 107 MediaStreamProviderListener* listener_; |
| 107 MediaCaptureSessionId new_capture_session_id_; | 108 int new_capture_session_id_; |
| 108 | 109 |
| 109 // Only accessed from vc_device_thread_ | 110 // Only accessed from vc_device_thread_ |
| 110 // TODO(mflodman) Change map key type when changing typedef for | 111 // TODO(mflodman) Change map key type when changing typedef for |
| 111 // MediaCaptureSessionId. | 112 // MediaCaptureSessionId. |
| 112 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; | 113 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; |
| 113 VideoCaptureDevices devices_; | 114 VideoCaptureDevices devices_; |
|
Leandro Graciá Gil
2011/06/16 17:39:53
It's probably worth to make a comment saying that
mflodman1
2011/06/20 19:48:03
Done.
| |
| 114 | 115 |
| 115 // Set to true if using fake devices for testing, false by default. | 116 // Set to true if using fake devices for testing, false by default. |
| 116 bool use_fake_device_; | 117 bool use_fake_device_; |
| 117 | 118 |
| 118 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 119 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 } // namespace media_stream | 122 } // namespace media_stream |
| 122 | 123 |
| 123 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); | 124 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); |
| 124 | 125 |
| 125 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 126 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |