| 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 // VideoCaptureManager is used to open/close, start/stop, enumerate available | 5 // VideoCaptureManager is used to open/close, start/stop, enumerate available |
| 6 // video capture devices, and manage VideoCaptureController's. | 6 // video capture devices, and manage VideoCaptureController's. |
| 7 // All functions are expected to be called from Browser::IO thread. | 7 // All functions are expected to be called from Browser::IO thread. |
| 8 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. | 8 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. |
| 9 // A device can only be opened once. | 9 // A device can only be opened once. |
| 10 | 10 |
| 11 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 11 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| 12 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 12 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| 13 | 13 |
| 14 #include <list> | 14 #include <list> |
| 15 #include <map> | 15 #include <map> |
| 16 | 16 |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "content/browser/renderer_host/media/media_stream_provider.h" | 18 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "content/common/media/media_stream_options.h" | 20 #include "content/common/media/media_stream_options.h" |
| 21 #include "media/video/capture/video_capture_device.h" | 21 #include "media/video/capture/video_capture_device.h" |
| 22 #include "media/video/capture/video_capture_types.h" | 22 #include "media/video/capture/video_capture_types.h" |
| 23 | 23 |
| 24 namespace media { |
| 25 struct RuntimeVideoEncodingParameters; |
| 26 struct VideoEncodingParameters; |
| 27 } // namespace media |
| 28 |
| 24 namespace content { | 29 namespace content { |
| 25 class MockVideoCaptureManager; | 30 class MockVideoCaptureManager; |
| 26 class VideoCaptureController; | 31 class VideoCaptureController; |
| 27 class VideoCaptureControllerEventHandler; | 32 class VideoCaptureControllerEventHandler; |
| 28 | 33 |
| 29 // VideoCaptureManager opens/closes and start/stops video capture devices. | 34 // VideoCaptureManager opens/closes and start/stops video capture devices. |
| 30 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { | 35 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { |
| 31 public: | 36 public: |
| 32 // Calling |Start| of this id will open the first device, even though open has | 37 // Calling |Start| of this id will open the first device, even though open has |
| 33 // not been called. This is used to be able to use video capture devices | 38 // not been called. This is used to be able to use video capture devices |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 // Start allocates the device and no other application can use the device | 57 // Start allocates the device and no other application can use the device |
| 53 // before Stop is called. Captured video frames will be delivered to | 58 // before Stop is called. Captured video frames will be delivered to |
| 54 // video_capture_receiver. | 59 // video_capture_receiver. |
| 55 virtual void Start(const media::VideoCaptureParams& capture_params, | 60 virtual void Start(const media::VideoCaptureParams& capture_params, |
| 56 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 61 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| 57 | 62 |
| 58 // Stops capture device referenced by |capture_session_id|. No more frames | 63 // Stops capture device referenced by |capture_session_id|. No more frames |
| 59 // will be delivered to the frame receiver, and |stopped_cb| will be called. | 64 // will be delivered to the frame receiver, and |stopped_cb| will be called. |
| 60 // |stopped_cb| can be NULL. | 65 // |stopped_cb| can be NULL. |
| 61 virtual void Stop(const media::VideoCaptureSessionId& capture_session_id, | 66 virtual void Stop(const media::VideoCaptureSessionId& capture_session_id, |
| 62 base::Closure stopped_cb); | 67 const base::Closure& stopped_cb); |
| 68 |
| 69 // Called by VideoCaptureHost to request a parameter change in the encoded |
| 70 // output bitstream of a capture device, if supported. |
| 71 virtual void TryConfigureEncodedBitstream( |
| 72 const media::VideoCaptureSessionId& session_id, |
| 73 const media::RuntimeVideoEncodingParameters& params); |
| 63 | 74 |
| 64 // Used by unit test to make sure a fake device is used instead of a real | 75 // 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 | 76 // video capture device. Due to timing requirements, the function must be |
| 66 // called before EnumerateDevices and Open. | 77 // called before EnumerateDevices and Open. |
| 67 void UseFakeDevice(); | 78 void UseFakeDevice(); |
| 68 | 79 |
| 69 // Called by VideoCaptureHost to get a controller for |capture_params|. | 80 // Called by VideoCaptureHost to get a controller for |capture_params|. |
| 70 // The controller is returned via calling |added_cb|. | 81 // The controller is returned via calling |added_cb|. |
| 71 void AddController( | 82 void AddController( |
| 72 const media::VideoCaptureParams& capture_params, | 83 const media::VideoCaptureParams& capture_params, |
| 73 VideoCaptureControllerEventHandler* handler, | 84 VideoCaptureControllerEventHandler* handler, |
| 74 base::Callback<void(VideoCaptureController*)> added_cb); | 85 const base::Callback<void(VideoCaptureController*)>& added_cb); |
| 75 // Called by VideoCaptureHost to remove the |controller|. | 86 // Called by VideoCaptureHost to remove the |controller|. |
| 76 void RemoveController( | 87 void RemoveController( |
| 77 VideoCaptureController* controller, | 88 VideoCaptureController* controller, |
| 78 VideoCaptureControllerEventHandler* handler); | 89 VideoCaptureControllerEventHandler* handler); |
| 79 | 90 |
| 91 // Called by VideoCaptureHost to request the encoding capabilities of a |
| 92 // capture device. |
| 93 void RequestEncodingCapability( |
| 94 const media::VideoCaptureSessionId& session_id, |
| 95 const base::Callback<void( |
| 96 const media::VideoEncodingCapability&)>& caps_cb); |
| 97 |
| 80 private: | 98 private: |
| 81 friend class MockVideoCaptureManager; | 99 friend class MockVideoCaptureManager; |
| 82 | 100 |
| 83 virtual ~VideoCaptureManager(); | 101 virtual ~VideoCaptureManager(); |
| 84 | 102 |
| 85 typedef std::list<VideoCaptureControllerEventHandler*> Handlers; | 103 typedef std::list<VideoCaptureControllerEventHandler*> Handlers; |
| 86 struct Controller; | 104 struct Controller; |
| 87 | 105 |
| 88 // Called by the public functions, executed on device thread. | 106 // Called by the public functions, executed on device thread. |
| 89 void OnEnumerateDevices(MediaStreamType stream_type); | 107 void OnEnumerateDevices(MediaStreamType stream_type); |
| 90 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); | 108 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); |
| 91 void OnClose(int capture_session_id); | 109 void OnClose(int capture_session_id); |
| 92 void OnStart(const media::VideoCaptureParams capture_params, | 110 void OnStart(const media::VideoCaptureParams capture_params, |
| 93 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 111 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| 94 void OnStop(const media::VideoCaptureSessionId capture_session_id, | 112 void OnStop(const media::VideoCaptureSessionId capture_session_id, |
| 95 base::Closure stopped_cb); | 113 const base::Closure& stopped_cb); |
| 114 void OnTryConfigureEncodedBitstream( |
| 115 const media::VideoCaptureSessionId& session_id, |
| 116 const media::RuntimeVideoEncodingParameters& params); |
| 96 void DoAddControllerOnDeviceThread( | 117 void DoAddControllerOnDeviceThread( |
| 97 const media::VideoCaptureParams capture_params, | 118 const media::VideoCaptureParams capture_params, |
| 98 VideoCaptureControllerEventHandler* handler, | 119 VideoCaptureControllerEventHandler* handler, |
| 99 base::Callback<void(VideoCaptureController*)> added_cb); | 120 const base::Callback<void(VideoCaptureController*)>& added_cb); |
| 100 void DoRemoveControllerOnDeviceThread( | 121 void DoRemoveControllerOnDeviceThread( |
| 101 VideoCaptureController* controller, | 122 VideoCaptureController* controller, |
| 102 VideoCaptureControllerEventHandler* handler); | 123 VideoCaptureControllerEventHandler* handler); |
| 124 void DoRequestEncodingCapabilityOnDeviceThread( |
| 125 const media::VideoCaptureSessionId& session_id, |
| 126 const base::Callback<void( |
| 127 const media::VideoEncodingCapability&)>& caps_cb); |
| 103 | 128 |
| 104 // Executed on Browser::IO thread to call Listener. | 129 // Executed on Browser::IO thread to call Listener. |
| 105 void OnOpened(MediaStreamType type, int capture_session_id); | 130 void OnOpened(MediaStreamType type, int capture_session_id); |
| 106 void OnClosed(MediaStreamType type, int capture_session_id); | 131 void OnClosed(MediaStreamType type, int capture_session_id); |
| 107 void OnDevicesEnumerated(MediaStreamType stream_type, | 132 void OnDevicesEnumerated(MediaStreamType stream_type, |
| 108 scoped_ptr<StreamDeviceInfoArray> devices); | 133 scoped_ptr<StreamDeviceInfoArray> devices); |
| 109 void OnError(MediaStreamType type, int capture_session_id, | 134 void OnError(MediaStreamType type, int capture_session_id, |
| 110 MediaStreamProviderError error); | 135 MediaStreamProviderError error); |
| 111 | 136 |
| 112 // Executed on device thread to make sure Listener is called from | 137 // Executed on device thread to make sure Listener is called from |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. | 178 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. |
| 154 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; | 179 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; |
| 155 Controllers controllers_; | 180 Controllers controllers_; |
| 156 | 181 |
| 157 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 182 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 158 }; | 183 }; |
| 159 | 184 |
| 160 } // namespace content | 185 } // namespace content |
| 161 | 186 |
| 162 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 187 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |