Chromium Code Reviews| 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 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 6 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/common/media/video_capture.h" | 19 #include "content/common/media/video_capture.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 base::Closure StartCapture( | 70 base::Closure StartCapture( |
| 71 media::VideoCaptureSessionId id, | 71 media::VideoCaptureSessionId id, |
| 72 const media::VideoCaptureParams& params, | 72 const media::VideoCaptureParams& params, |
| 73 const VideoCaptureStateUpdateCB& state_update_cb, | 73 const VideoCaptureStateUpdateCB& state_update_cb, |
| 74 const VideoCaptureDeliverFrameCB& deliver_frame_cb); | 74 const VideoCaptureDeliverFrameCB& deliver_frame_cb); |
| 75 | 75 |
| 76 // Requests that the video capturer send a frame "soon" (e.g., to resolve | 76 // Requests that the video capturer send a frame "soon" (e.g., to resolve |
| 77 // picture loss or quality issues). | 77 // picture loss or quality issues). |
| 78 void RequestRefreshFrame(media::VideoCaptureSessionId id); | 78 void RequestRefreshFrame(media::VideoCaptureSessionId id); |
| 79 | 79 |
| 80 // Requests frame delivery be suspended/resumed for a given capture session. | |
| 81 void Suspend(media::VideoCaptureSessionId id); | |
| 82 void Resume(media::VideoCaptureSessionId id); | |
| 83 | |
| 80 // Get supported formats supported by the device for the given session | 84 // Get supported formats supported by the device for the given session |
| 81 // ID. |callback| will be called on the IO thread. | 85 // ID. |callback| will be called on the IO thread. |
| 82 void GetDeviceSupportedFormats(media::VideoCaptureSessionId id, | 86 void GetDeviceSupportedFormats(media::VideoCaptureSessionId id, |
| 83 const VideoCaptureDeviceFormatsCB& callback); | 87 const VideoCaptureDeviceFormatsCB& callback); |
| 84 | 88 |
| 85 // Get supported formats currently in use for the given session ID. | 89 // Get supported formats currently in use for the given session ID. |
| 86 // |callback| will be called on the IO thread. | 90 // |callback| will be called on the IO thread. |
| 87 void GetDeviceFormatsInUse(media::VideoCaptureSessionId id, | 91 void GetDeviceFormatsInUse(media::VideoCaptureSessionId id, |
| 88 const VideoCaptureDeviceFormatsCB& callback); | 92 const VideoCaptureDeviceFormatsCB& callback); |
| 89 | 93 |
| 90 // Make all existing VideoCaptureImpl instances stop/resume delivering | 94 // Make all existing VideoCaptureImpl instances stop/resume delivering |
| 91 // video frames to their clients, depends on flag |suspend|. | 95 // video frames to their clients, depends on flag |suspend|. This is called in |
| 96 // response to a RenderView-wide PageHidden/Shown() event. To suspend/resume | |
| 97 // an individual session, please call Suspend(id) or Resume(id). | |
| 92 void SuspendDevices(bool suspend); | 98 void SuspendDevices(bool suspend); |
|
chfremer
2016/09/27 00:54:59
Deciding which devices need to be suspended/resume
miu
2016/09/27 23:42:23
No, that's not the scoping/responsibility of this
chfremer
2016/09/28 00:27:36
Oops, I have misunderstood the responsibilities of
| |
| 93 | 99 |
| 94 VideoCaptureMessageFilter* video_capture_message_filter() const { | 100 VideoCaptureMessageFilter* video_capture_message_filter() const { |
| 95 return filter_.get(); | 101 return filter_.get(); |
| 96 } | 102 } |
| 97 | 103 |
| 98 protected: | 104 protected: |
| 99 virtual VideoCaptureImpl* CreateVideoCaptureImplForTesting( | 105 virtual std::unique_ptr<VideoCaptureImpl> CreateVideoCaptureImplForTesting( |
| 100 media::VideoCaptureSessionId id, | 106 media::VideoCaptureSessionId id, |
| 101 VideoCaptureMessageFilter* filter) const; | 107 VideoCaptureMessageFilter* filter) const; |
| 102 | 108 |
| 103 private: | 109 private: |
| 110 struct DeviceEntry { | |
| 111 media::VideoCaptureSessionId session_id; | |
| 112 | |
| 113 // To be used and destroyed only on the IO thread. | |
| 114 std::unique_ptr<VideoCaptureImpl> impl; | |
| 115 | |
| 116 // Number of clients using |impl|. | |
| 117 int client_count; | |
| 118 | |
| 119 // This is set to true if this device is being suspended, via | |
| 120 // VideoCaptureImplManager::Suspend(). | |
| 121 // See also: VideoCaptureImplManager::is_suspending_all_. | |
| 122 bool is_individually_suspended; | |
| 123 | |
| 124 DeviceEntry(); | |
| 125 DeviceEntry(DeviceEntry&& other); | |
| 126 DeviceEntry& operator=(DeviceEntry&& other); | |
| 127 ~DeviceEntry(); | |
| 128 }; | |
| 129 | |
| 104 void StopCapture(int client_id, media::VideoCaptureSessionId id); | 130 void StopCapture(int client_id, media::VideoCaptureSessionId id); |
| 105 void UnrefDevice(media::VideoCaptureSessionId id); | 131 void UnrefDevice(media::VideoCaptureSessionId id); |
| 106 | 132 |
| 107 // The int is used to count clients of the corresponding VideoCaptureImpl. | 133 // Devices currently in use. |
| 108 // VideoCaptureImpl objects are owned by this object. But they are | 134 std::vector<DeviceEntry> devices_; |
| 109 // destroyed on the IO thread. These are raw pointers because we destroy | |
| 110 // them manually. | |
| 111 typedef std::map<media::VideoCaptureSessionId, | |
| 112 std::pair<int, VideoCaptureImpl*>> VideoCaptureDeviceMap; | |
| 113 VideoCaptureDeviceMap devices_; | |
| 114 | 135 |
| 115 // This is an internal ID for identifying clients of VideoCaptureImpl. | 136 // This is an internal ID for identifying clients of VideoCaptureImpl. |
| 116 // The ID is global for the render process. | 137 // The ID is global for the render process. |
| 117 int next_client_id_; | 138 int next_client_id_; |
| 118 | 139 |
| 119 const scoped_refptr<VideoCaptureMessageFilter> filter_; | 140 const scoped_refptr<VideoCaptureMessageFilter> filter_; |
| 120 | 141 |
| 121 // Hold a pointer to the Render Main message loop to check we operate on the | 142 // Hold a pointer to the Render Main message loop to check we operate on the |
| 122 // right thread. | 143 // right thread. |
| 123 const scoped_refptr<base::SingleThreadTaskRunner> render_main_task_runner_; | 144 const scoped_refptr<base::SingleThreadTaskRunner> render_main_task_runner_; |
| 124 | 145 |
| 146 // Set to true if SuspendDevices(true) was called. This, along with | |
| 147 // DeviceEntry::is_individually_suspended, is used to determine whether to | |
| 148 // take action when suspending/resuming each device. | |
| 149 bool is_suspending_all_; | |
| 150 | |
| 125 // Bound to the render thread. | 151 // Bound to the render thread. |
| 126 // NOTE: Weak pointers must be invalidated before all other member variables. | 152 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 127 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_; | 153 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_; |
| 128 | 154 |
| 129 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); | 155 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); |
| 130 }; | 156 }; |
| 131 | 157 |
| 132 } // namespace content | 158 } // namespace content |
| 133 | 159 |
| 134 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 160 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
| OLD | NEW |