| 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 // VideoCaptureDevice is the abstract base class for realizing video capture | 5 // VideoCaptureDevice is the abstract base class for realizing video capture |
| 6 // device support in Chromium. It provides the interface for OS dependent | 6 // device support in Chromium. It provides the interface for OS dependent |
| 7 // implementations. | 7 // implementations. |
| 8 // The class is created and functions are invoked on a thread owned by | 8 // The class is created and functions are invoked on a thread owned by |
| 9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS | 9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS |
| 10 // specific implementation. | 10 // specific implementation. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "base/files/file.h" | 23 #include "base/files/file.h" |
| 24 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "base/memory/ref_counted.h" | 25 #include "base/memory/ref_counted.h" |
| 26 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 29 #include "media/base/video_frame.h" | 29 #include "media/base/video_frame.h" |
| 30 #include "media/capture/capture_export.h" | 30 #include "media/capture/capture_export.h" |
| 31 #include "media/capture/mojo/image_capture.mojom.h" | 31 #include "media/capture/mojo/image_capture.mojom.h" |
| 32 #include "media/capture/video/scoped_result_callback.h" | 32 #include "media/capture/video/scoped_result_callback.h" |
| 33 #include "media/capture/video/video_capture_buffer_handle.h" |
| 33 #include "media/capture/video/video_capture_device_descriptor.h" | 34 #include "media/capture/video/video_capture_device_descriptor.h" |
| 34 #include "media/capture/video_capture_types.h" | 35 #include "media/capture/video_capture_types.h" |
| 35 #include "ui/gfx/gpu_memory_buffer.h" | 36 #include "ui/gfx/gpu_memory_buffer.h" |
| 36 | 37 |
| 37 namespace tracked_objects { | 38 namespace tracked_objects { |
| 38 class Location; | 39 class Location; |
| 39 } // namespace tracked_objects | 40 } // namespace tracked_objects |
| 40 | 41 |
| 41 namespace media { | 42 namespace media { |
| 42 | 43 |
| 43 class CAPTURE_EXPORT FrameBufferPool { | 44 class CAPTURE_EXPORT FrameBufferPool { |
| 44 public: | 45 public: |
| 45 virtual ~FrameBufferPool() {} | 46 virtual ~FrameBufferPool() {} |
| 46 | 47 |
| 47 virtual void SetBufferHold(int buffer_id) = 0; | 48 virtual void SetBufferHold(int buffer_id) = 0; |
| 48 virtual void ReleaseBufferHold(int buffer_id) = 0; | 49 virtual void ReleaseBufferHold(int buffer_id) = 0; |
| 49 virtual mojo::ScopedSharedBufferHandle GetHandleForTransit(int buffer_id) = 0; | |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class CAPTURE_EXPORT VideoFrameConsumerFeedbackObserver { | 52 class CAPTURE_EXPORT VideoFrameConsumerFeedbackObserver { |
| 53 public: | 53 public: |
| 54 virtual ~VideoFrameConsumerFeedbackObserver() {} | 54 virtual ~VideoFrameConsumerFeedbackObserver() {} |
| 55 | 55 |
| 56 // During processing of a video frame, consumers may report back their | 56 // During processing of a video frame, consumers may report back their |
| 57 // utilization level to the source device. The device may use this information | 57 // utilization level to the source device. The device may use this information |
| 58 // to adjust the rate of data it pushes out. Values are interpreted as | 58 // to adjust the rate of data it pushes out. Values are interpreted as |
| 59 // follows: | 59 // follows: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 79 class CAPTURE_EXPORT VideoCaptureDevice | 79 class CAPTURE_EXPORT VideoCaptureDevice |
| 80 : public VideoFrameConsumerFeedbackObserver { | 80 : public VideoFrameConsumerFeedbackObserver { |
| 81 public: | 81 public: |
| 82 | 82 |
| 83 // Interface defining the methods that clients of VideoCapture must have. It | 83 // Interface defining the methods that clients of VideoCapture must have. It |
| 84 // is actually two-in-one: clients may implement OnIncomingCapturedData() or | 84 // is actually two-in-one: clients may implement OnIncomingCapturedData() or |
| 85 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. | 85 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. |
| 86 // All clients must implement OnError(). | 86 // All clients must implement OnError(). |
| 87 class CAPTURE_EXPORT Client { | 87 class CAPTURE_EXPORT Client { |
| 88 public: | 88 public: |
| 89 // Memory buffer returned by Client::ReserveOutputBuffer(). | 89 // Move-only type representing access to a buffer handle as well as |
| 90 // read-write permission to its contents. |
| 90 class CAPTURE_EXPORT Buffer { | 91 class CAPTURE_EXPORT Buffer { |
| 91 public: | 92 public: |
| 92 virtual ~Buffer() = 0; | 93 // Destructor-only interface for encapsulating scoped access permission to |
| 93 virtual int id() const = 0; | 94 // a Buffer. |
| 94 virtual int frame_feedback_id() const = 0; | 95 class CAPTURE_EXPORT ScopedAccessPermission { |
| 95 virtual gfx::Size dimensions() const = 0; | 96 public: |
| 96 virtual size_t mapped_size() const = 0; | 97 virtual ~ScopedAccessPermission() {} |
| 97 virtual void* data(int plane) = 0; | 98 }; |
| 98 void* data() { return data(0); } | 99 |
| 99 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) | 100 class CAPTURE_EXPORT HandleProvider { |
| 100 virtual base::FileDescriptor AsPlatformFile() = 0; | 101 public: |
| 101 #endif | 102 virtual ~HandleProvider() {} |
| 102 virtual bool IsBackedByVideoFrame() const = 0; | 103 virtual mojo::ScopedSharedBufferHandle |
| 103 virtual scoped_refptr<VideoFrame> GetVideoFrame() = 0; | 104 GetHandleForInterProcessTransit() = 0; |
| 105 virtual base::SharedMemoryHandle |
| 106 GetNonOwnedSharedMemoryHandleForLegacyIPC() = 0; |
| 107 virtual std::unique_ptr<VideoCaptureBufferHandle> |
| 108 GetHandleForInProcessAccess() = 0; |
| 109 }; |
| 110 |
| 111 Buffer(); |
| 112 Buffer(int buffer_id, |
| 113 int frame_feedback_id, |
| 114 std::unique_ptr<HandleProvider> handle_provider, |
| 115 std::unique_ptr<ScopedAccessPermission> access_permission); |
| 116 ~Buffer(); |
| 117 Buffer(Buffer&& other); |
| 118 Buffer& operator=(Buffer&& other); |
| 119 |
| 120 bool is_valid() const { return handle_provider_ != nullptr; } |
| 121 int id() const { return id_; } |
| 122 int frame_feedback_id() const { return frame_feedback_id_; } |
| 123 HandleProvider* handle_provider() const { return handle_provider_.get(); } |
| 124 |
| 125 private: |
| 126 std::unique_ptr<HandleProvider> handle_provider_; |
| 127 std::unique_ptr<ScopedAccessPermission> access_permission_; |
| 128 int id_; |
| 129 int frame_feedback_id_; |
| 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(Buffer); |
| 104 }; | 132 }; |
| 105 | 133 |
| 106 virtual ~Client() {} | 134 virtual ~Client() {} |
| 107 | 135 |
| 108 // Captured a new video frame, data for which is pointed to by |data|. | 136 // Captured a new video frame, data for which is pointed to by |data|. |
| 109 // | 137 // |
| 110 // The format of the frame is described by |frame_format|, and is assumed to | 138 // The format of the frame is described by |frame_format|, and is assumed to |
| 111 // be tightly packed. This method will try to reserve an output buffer and | 139 // be tightly packed. This method will try to reserve an output buffer and |
| 112 // copy from |data| into the output buffer. If no output buffer is | 140 // copy from |data| into the output buffer. If no output buffer is |
| 113 // available, the frame will be silently dropped. |reference_time| is | 141 // available, the frame will be silently dropped. |reference_time| is |
| (...skipping 17 matching lines...) Expand all Loading... |
| 131 int frame_feedback_id = 0) = 0; | 159 int frame_feedback_id = 0) = 0; |
| 132 | 160 |
| 133 // Reserve an output buffer into which contents can be captured directly. | 161 // Reserve an output buffer into which contents can be captured directly. |
| 134 // The returned Buffer will always be allocated with a memory size suitable | 162 // The returned Buffer will always be allocated with a memory size suitable |
| 135 // for holding a packed video frame with pixels of |format| format, of | 163 // for holding a packed video frame with pixels of |format| format, of |
| 136 // |dimensions| frame dimensions. It is permissible for |dimensions| to be | 164 // |dimensions| frame dimensions. It is permissible for |dimensions| to be |
| 137 // zero; in which case the returned Buffer does not guarantee memory | 165 // zero; in which case the returned Buffer does not guarantee memory |
| 138 // backing, but functions as a reservation for external input for the | 166 // backing, but functions as a reservation for external input for the |
| 139 // purposes of buffer throttling. | 167 // purposes of buffer throttling. |
| 140 // | 168 // |
| 141 // The output buffer stays reserved and mapped for use until the Buffer | 169 // The buffer stays reserved for use by the caller as long as it |
| 142 // object is destroyed or returned. | 170 // holds on to the contained |buffer_read_write_permission|. |
| 143 virtual std::unique_ptr<Buffer> ReserveOutputBuffer( | 171 virtual Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
| 144 const gfx::Size& dimensions, | 172 VideoPixelFormat format, |
| 145 VideoPixelFormat format, | 173 VideoPixelStorage storage, |
| 146 VideoPixelStorage storage, | 174 int frame_feedback_id) = 0; |
| 147 int frame_feedback_id) = 0; | |
| 148 | 175 |
| 149 // Provides VCD::Client with a populated Buffer containing the content of | 176 // Provides VCD::Client with a populated Buffer containing the content of |
| 150 // the next video frame. The |buffer| must originate from an earlier call to | 177 // the next video frame. The |buffer| must originate from an earlier call to |
| 151 // ReserveOutputBuffer(). | 178 // ReserveOutputBuffer(). |
| 152 // See OnIncomingCapturedData for details of |reference_time| and | 179 // See OnIncomingCapturedData for details of |reference_time| and |
| 153 // |timestamp|. | 180 // |timestamp|. |
| 154 virtual void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 181 virtual void OnIncomingCapturedBuffer(Buffer buffer, |
| 155 const VideoCaptureFormat& format, | 182 const VideoCaptureFormat& format, |
| 156 base::TimeTicks reference_time, | 183 base::TimeTicks reference_time, |
| 157 base::TimeDelta timestamp) = 0; | 184 base::TimeDelta timestamp) = 0; |
| 158 | 185 |
| 159 // Extended version of OnIncomingCapturedBuffer() allowing clients to | 186 // Extended version of OnIncomingCapturedBuffer() allowing clients to |
| 160 // pass a custom |visible_rect| and |additional_metadata|. | 187 // pass a custom |visible_rect| and |additional_metadata|. |
| 161 virtual void OnIncomingCapturedBufferExt( | 188 virtual void OnIncomingCapturedBufferExt( |
| 162 std::unique_ptr<Buffer> buffer, | 189 Buffer buffer, |
| 163 const VideoCaptureFormat& format, | 190 const VideoCaptureFormat& format, |
| 164 base::TimeTicks reference_time, | 191 base::TimeTicks reference_time, |
| 165 base::TimeDelta timestamp, | 192 base::TimeDelta timestamp, |
| 166 gfx::Rect visible_rect, | 193 gfx::Rect visible_rect, |
| 167 const VideoFrameMetadata& additional_metadata) = 0; | 194 const VideoFrameMetadata& additional_metadata) = 0; |
| 168 | 195 |
| 169 // Attempts to reserve the same Buffer provided in the last call to one of | 196 // Attempts to reserve the same Buffer provided in the last call to one of |
| 170 // the OnIncomingCapturedBufferXXX() methods. This will fail if the content | 197 // the OnIncomingCapturedBufferXXX() methods. This will fail if the content |
| 171 // of the Buffer has not been preserved, or if the |dimensions|, |format|, | 198 // of the Buffer has not been preserved, or if the |dimensions|, |format|, |
| 172 // or |storage| disagree with how it was reserved via ReserveOutputBuffer(). | 199 // or |storage| disagree with how it was reserved via ReserveOutputBuffer(). |
| 173 // When this operation fails, nullptr will be returned. | 200 // When this operation fails, nullptr will be returned. |
| 174 virtual std::unique_ptr<Buffer> ResurrectLastOutputBuffer( | 201 virtual Buffer ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
| 175 const gfx::Size& dimensions, | 202 VideoPixelFormat format, |
| 176 VideoPixelFormat format, | 203 VideoPixelStorage storage, |
| 177 VideoPixelStorage storage, | 204 int new_frame_feedback_id) = 0; |
| 178 int new_frame_feedback_id) = 0; | |
| 179 | 205 |
| 180 // An error has occurred that cannot be handled and VideoCaptureDevice must | 206 // An error has occurred that cannot be handled and VideoCaptureDevice must |
| 181 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. | 207 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. |
| 182 virtual void OnError(const tracked_objects::Location& from_here, | 208 virtual void OnError(const tracked_objects::Location& from_here, |
| 183 const std::string& reason) = 0; | 209 const std::string& reason) = 0; |
| 184 | 210 |
| 185 // VideoCaptureDevice requests the |message| to be logged. | 211 // VideoCaptureDevice requests the |message| to be logged. |
| 186 virtual void OnLog(const std::string& message) {} | 212 virtual void OnLog(const std::string& message) {} |
| 187 | 213 |
| 188 // Returns the current buffer pool utilization, in the range 0.0 (no buffers | 214 // Returns the current buffer pool utilization, in the range 0.0 (no buffers |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 302 |
| 277 private: | 303 private: |
| 278 // Gets the power line frequency from the current system time zone if this is | 304 // Gets the power line frequency from the current system time zone if this is |
| 279 // defined, otherwise returns 0. | 305 // defined, otherwise returns 0. |
| 280 PowerLineFrequency GetPowerLineFrequencyForLocation() const; | 306 PowerLineFrequency GetPowerLineFrequencyForLocation() const; |
| 281 }; | 307 }; |
| 282 | 308 |
| 283 } // namespace media | 309 } // namespace media |
| 284 | 310 |
| 285 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ | 311 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ |
| OLD | NEW |