| 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); |
| 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 // Holds bookkeeping info for each VideoCaptureImpl shared by clients. |
| 111 struct DeviceEntry; |
| 112 |
| 104 void StopCapture(int client_id, media::VideoCaptureSessionId id); | 113 void StopCapture(int client_id, media::VideoCaptureSessionId id); |
| 105 void UnrefDevice(media::VideoCaptureSessionId id); | 114 void UnrefDevice(media::VideoCaptureSessionId id); |
| 106 | 115 |
| 107 // The int is used to count clients of the corresponding VideoCaptureImpl. | 116 // Devices currently in use. |
| 108 // VideoCaptureImpl objects are owned by this object. But they are | 117 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 | 118 |
| 115 // This is an internal ID for identifying clients of VideoCaptureImpl. | 119 // This is an internal ID for identifying clients of VideoCaptureImpl. |
| 116 // The ID is global for the render process. | 120 // The ID is global for the render process. |
| 117 int next_client_id_; | 121 int next_client_id_; |
| 118 | 122 |
| 119 const scoped_refptr<VideoCaptureMessageFilter> filter_; | 123 const scoped_refptr<VideoCaptureMessageFilter> filter_; |
| 120 | 124 |
| 121 // Hold a pointer to the Render Main message loop to check we operate on the | 125 // Hold a pointer to the Render Main message loop to check we operate on the |
| 122 // right thread. | 126 // right thread. |
| 123 const scoped_refptr<base::SingleThreadTaskRunner> render_main_task_runner_; | 127 const scoped_refptr<base::SingleThreadTaskRunner> render_main_task_runner_; |
| 124 | 128 |
| 129 // Set to true if SuspendDevices(true) was called. This, along with |
| 130 // DeviceEntry::is_individually_suspended, is used to determine whether to |
| 131 // take action when suspending/resuming each device. |
| 132 bool is_suspending_all_; |
| 133 |
| 125 // Bound to the render thread. | 134 // Bound to the render thread. |
| 126 // NOTE: Weak pointers must be invalidated before all other member variables. | 135 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 127 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_; | 136 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_; |
| 128 | 137 |
| 129 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); | 138 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); |
| 130 }; | 139 }; |
| 131 | 140 |
| 132 } // namespace content | 141 } // namespace content |
| 133 | 142 |
| 134 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 143 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
| OLD | NEW |