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