| 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 <memory> | 8 #include <memory> |
| 9 #include <vector> | 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" |
| 20 #include "content/public/renderer/media_stream_video_sink.h" | 20 #include "content/public/renderer/media_stream_video_sink.h" |
| 21 #include "media/base/video_capture_types.h" | 21 #include "media/base/video_capture_types.h" |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 class VideoCaptureImpl; | 25 class VideoCaptureImpl; |
| 26 class VideoCaptureMessageFilter; | |
| 27 | 26 |
| 28 // TODO(hclam): This class should be renamed to VideoCaptureService. | 27 // TODO(hclam): This class should be renamed to VideoCaptureService. |
| 29 | 28 |
| 30 // This class provides access to a video capture device in the browser | 29 // This class provides access to a video capture device in the browser |
| 31 // process through IPC. The main function is to deliver video frames | 30 // process through IPC. The main function is to deliver video frames |
| 32 // to a client. | 31 // to a client. |
| 33 // | 32 // |
| 34 // THREADING | 33 // THREADING |
| 35 // | 34 // |
| 36 // VideoCaptureImplManager lives only on the Render Main thread. All methods | 35 // VideoCaptureImplManager lives only on the Render Main thread. All methods |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // |callback| will be called on the IO thread. | 89 // |callback| will be called on the IO thread. |
| 91 void GetDeviceFormatsInUse(media::VideoCaptureSessionId id, | 90 void GetDeviceFormatsInUse(media::VideoCaptureSessionId id, |
| 92 const VideoCaptureDeviceFormatsCB& callback); | 91 const VideoCaptureDeviceFormatsCB& callback); |
| 93 | 92 |
| 94 // Make all existing VideoCaptureImpl instances stop/resume delivering | 93 // Make all existing VideoCaptureImpl instances stop/resume delivering |
| 95 // video frames to their clients, depends on flag |suspend|. This is called in | 94 // 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 | 95 // response to a RenderView-wide PageHidden/Shown() event. To suspend/resume |
| 97 // an individual session, please call Suspend(id) or Resume(id). | 96 // an individual session, please call Suspend(id) or Resume(id). |
| 98 void SuspendDevices(bool suspend); | 97 void SuspendDevices(bool suspend); |
| 99 | 98 |
| 100 VideoCaptureMessageFilter* video_capture_message_filter() const { | |
| 101 return filter_.get(); | |
| 102 } | |
| 103 | |
| 104 protected: | |
| 105 virtual std::unique_ptr<VideoCaptureImpl> CreateVideoCaptureImplForTesting( | 99 virtual std::unique_ptr<VideoCaptureImpl> CreateVideoCaptureImplForTesting( |
| 106 media::VideoCaptureSessionId id, | 100 media::VideoCaptureSessionId session_id) const; |
| 107 VideoCaptureMessageFilter* filter) const; | |
| 108 | 101 |
| 109 private: | 102 private: |
| 110 // Holds bookkeeping info for each VideoCaptureImpl shared by clients. | 103 // Holds bookkeeping info for each VideoCaptureImpl shared by clients. |
| 111 struct DeviceEntry; | 104 struct DeviceEntry; |
| 112 | 105 |
| 113 void StopCapture(int client_id, media::VideoCaptureSessionId id); | 106 void StopCapture(int client_id, media::VideoCaptureSessionId id); |
| 114 void UnrefDevice(media::VideoCaptureSessionId id); | 107 void UnrefDevice(media::VideoCaptureSessionId id); |
| 115 | 108 |
| 116 // Devices currently in use. | 109 // Devices currently in use. |
| 117 std::vector<DeviceEntry> devices_; | 110 std::vector<DeviceEntry> devices_; |
| 118 | 111 |
| 119 // This is an internal ID for identifying clients of VideoCaptureImpl. | 112 // This is an internal ID for identifying clients of VideoCaptureImpl. |
| 120 // The ID is global for the render process. | 113 // The ID is global for the render process. |
| 121 int next_client_id_; | 114 int next_client_id_; |
| 122 | 115 |
| 123 const scoped_refptr<VideoCaptureMessageFilter> filter_; | |
| 124 | |
| 125 // Hold a pointer to the Render Main message loop to check we operate on the | 116 // Hold a pointer to the Render Main message loop to check we operate on the |
| 126 // right thread. | 117 // right thread. |
| 127 const scoped_refptr<base::SingleThreadTaskRunner> render_main_task_runner_; | 118 const scoped_refptr<base::SingleThreadTaskRunner> render_main_task_runner_; |
| 128 | 119 |
| 129 // Set to true if SuspendDevices(true) was called. This, along with | 120 // Set to true if SuspendDevices(true) was called. This, along with |
| 130 // DeviceEntry::is_individually_suspended, is used to determine whether to | 121 // DeviceEntry::is_individually_suspended, is used to determine whether to |
| 131 // take action when suspending/resuming each device. | 122 // take action when suspending/resuming each device. |
| 132 bool is_suspending_all_; | 123 bool is_suspending_all_; |
| 133 | 124 |
| 134 // Bound to the render thread. | 125 // Bound to the render thread. |
| 135 // NOTE: Weak pointers must be invalidated before all other member variables. | 126 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 136 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_; | 127 base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_; |
| 137 | 128 |
| 138 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); | 129 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); |
| 139 }; | 130 }; |
| 140 | 131 |
| 141 } // namespace content | 132 } // namespace content |
| 142 | 133 |
| 143 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ | 134 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
| OLD | NEW |