| 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_ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace media_stream { | 22 namespace media_stream { |
| 23 | 23 |
| 24 // VideoCaptureManager opens/closes and start/stops video capture devices. | 24 // VideoCaptureManager opens/closes and start/stops video capture devices. |
| 25 class VideoCaptureManager : public MediaStreamProvider { | 25 class VideoCaptureManager : public MediaStreamProvider { |
| 26 public: | 26 public: |
| 27 // 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 |
| 28 // 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 |
| 29 // before MediaStream is implemented in Chrome and WebKit. | 29 // before MediaStream is implemented in Chrome and WebKit. |
| 30 enum { kStartOpenSessionId = 1 }; | 30 enum { kStartOpenSessionId = 1 }; |
| 31 | 31 |
| 32 // Called to get a pointer to the singleton | 32 // Called to get a pointer to the singleton. |
| 33 static VideoCaptureManager* Get(); | 33 static VideoCaptureManager* Get(); |
| 34 | 34 |
| 35 // Implements MediaStreamProvider. | 35 // Implements MediaStreamProvider. |
| 36 virtual void Register(MediaStreamProviderListener* listener); | 36 virtual void Register(MediaStreamProviderListener* listener); |
| 37 | 37 |
| 38 virtual void Unregister(); | 38 virtual void Unregister(); |
| 39 | 39 |
| 40 virtual void EnumerateDevices(); | 40 virtual void EnumerateDevices(); |
| 41 | 41 |
| 42 virtual int Open(const StreamDeviceInfo& device); | 42 virtual int Open(const StreamDeviceInfo& device); |
| 43 | 43 |
| 44 virtual void Close(int capture_session_id); | 44 virtual void Close(int capture_session_id); |
| 45 | 45 |
| 46 // Functions used to start and stop media flow. | 46 // Functions used to start and stop media flow. |
| 47 // 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 |
| 48 // before Stop is called. Captured video frames will be delivered to | 48 // before Stop is called. Captured video frames will be delivered to |
| 49 // video_capture_receiver. | 49 // video_capture_receiver. |
| 50 void Start(const media::VideoCaptureParams& capture_params, | 50 void Start(const media::VideoCaptureParams& capture_params, |
| 51 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 51 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| 52 | 52 |
| 53 // Stops capture device referenced by |capture_session_id|. No more frames | 53 // 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. | 54 // will be delivered to the frame receiver, and |stopped_task| will be called. |
| 55 void Stop(const media::VideoCaptureSessionId capture_session_id, | 55 void Stop(const media::VideoCaptureSessionId& capture_session_id, |
| 56 Task* stopped_task); | 56 Task* stopped_task); |
| 57 | 57 |
| 58 // A capture device error has occurred for |capture_session_id|. The device | 58 // A capture device error has occurred for |capture_session_id|. The device |
| 59 // won't stream any more captured frames. | 59 // won't stream any more captured frames. |
| 60 void Error(const media::VideoCaptureSessionId& capture_session_id); | 60 void Error(const media::VideoCaptureSessionId& capture_session_id); |
| 61 | 61 |
| 62 virtual ~VideoCaptureManager(); | 62 virtual ~VideoCaptureManager(); |
| 63 | 63 |
| 64 // 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 |
| 65 // video capture device. Due to timing requirements, the function must be | 65 // video capture device. Due to timing requirements, the function must be |
| (...skipping 27 matching lines...) Expand all Loading... |
| 93 void PostOnClosed(int capture_session_id); | 93 void PostOnClosed(int capture_session_id); |
| 94 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); | 94 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
| 95 void PostOnError(int capture_session_id, MediaStreamProviderError error); | 95 void PostOnError(int capture_session_id, MediaStreamProviderError error); |
| 96 | 96 |
| 97 // Helpers | 97 // Helpers |
| 98 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); | 98 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); |
| 99 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); | 99 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); |
| 100 bool DeviceOpened(const StreamDeviceInfo& device_info); | 100 bool DeviceOpened(const StreamDeviceInfo& device_info); |
| 101 bool IsOnCaptureDeviceThread() const; | 101 bool IsOnCaptureDeviceThread() const; |
| 102 | 102 |
| 103 // Thread for all calls to VideoCaptureDevice | 103 // Thread for all calls to VideoCaptureDevice. |
| 104 base::Thread vc_device_thread_; | 104 base::Thread vc_device_thread_; |
| 105 | 105 |
| 106 // Only accessed on Browser::IO thread | 106 // Only accessed on Browser::IO thread. |
| 107 MediaStreamProviderListener* listener_; | 107 MediaStreamProviderListener* listener_; |
| 108 int new_capture_session_id_; | 108 int new_capture_session_id_; |
| 109 | 109 |
| 110 // Only accessed from vc_device_thread_ | 110 // Only accessed from vc_device_thread_. |
| 111 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for | 111 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for |
| 112 // deleting the instances when they are not used any longer. | 112 // deleting the instances when they are not used any longer. |
| 113 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; | 113 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; |
| 114 VideoCaptureDevices devices_; | 114 VideoCaptureDevices devices_; |
| 115 | 115 |
| 116 // 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. |
| 117 bool use_fake_device_; | 117 bool use_fake_device_; |
| 118 | 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 119 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 } // namespace media_stream | 122 } // namespace media_stream |
| 123 | 123 |
| 124 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); | 124 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); |
| 125 | 125 |
| 126 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 126 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |