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 // 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 "mojo/public/cpp/bindings/array.h" | 36 #include "mojo/public/cpp/bindings/array.h" |
| 36 #include "ui/gfx/gpu_memory_buffer.h" | 37 #include "ui/gfx/gpu_memory_buffer.h" |
| 37 | 38 |
| 38 namespace tracked_objects { | 39 namespace tracked_objects { |
| 39 class Location; | 40 class Location; |
| 40 } // namespace tracked_objects | 41 } // namespace tracked_objects |
| 41 | 42 |
| 42 namespace media { | 43 namespace media { |
| 43 | 44 |
| 44 class CAPTURE_EXPORT FrameBufferPool { | 45 class CAPTURE_EXPORT FrameBufferPool { |
| 45 public: | 46 public: |
| 46 virtual ~FrameBufferPool() {} | 47 virtual ~FrameBufferPool() {} |
| 47 | 48 |
| 48 virtual void SetBufferHold(int buffer_id) = 0; | 49 virtual void SetBufferHold(int buffer_id) = 0; |
| 49 virtual void ReleaseBufferHold(int buffer_id) = 0; | 50 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: |
| 61 // Less than 0.0 is meaningless and should be ignored. 1.0 indicates a | 61 // Less than 0.0 is meaningless and should be ignored. 1.0 indicates a |
| 62 // maximum sustainable utilization. Greater than 1.0 indicates the consumer | 62 // maximum sustainable utilization. Greater than 1.0 indicates the consumer |
| 63 // is likely to stall or drop frames if the data volume is not reduced. | 63 // is likely to stall or drop frames if the data volume is not reduced. |
| 64 // | 64 // |
| 65 // Example: In a system that encodes and transmits video frames over the | 65 // Example: In a system that encodes and transmits video frames over the |
| 66 // network, this value can be used to indicate whether sufficient CPU | 66 // network, this value can be used to indicate whether sufficient CPU |
| 67 // is available for encoding and/or sufficient bandwidth is available for | 67 // is available for encoding and/or sufficient bandwidth is available for |
| 68 // transmission over the network. The maximum of the two utilization | 68 // transmission over the network. The maximum of the two utilization |
| 69 // measurements would be used as feedback. | 69 // measurements would be used as feedback. |
| 70 // | 70 // |
| 71 // The parameter |frame_feedback_id| must match a |frame_feedback_id| | 71 // The parameter |frame_feedback_id| must match a |frame_feedback_id| |
| 72 // previously sent out by the VideoCaptureDevice we are giving feedback about. | 72 // previously sent out by the VideoCaptureDevice we are giving feedback about. |
| 73 // It is used to indicate which particular frame the reported utilization | 73 // It is used to indicate which particular frame the reported utilization |
| 74 // corresponds to. | 74 // corresponds to. |
| 75 virtual void OnUtilizationReport(int frame_feedback_id, double utilization) {} | 75 virtual void OnUtilizationReport(int frame_feedback_id, double utilization) {} |
| 76 | 76 |
| 77 static constexpr double kNoUtilizationRecorded = -1.0; | 77 static constexpr double kNoUtilizationRecorded = -1.0; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class CAPTURE_EXPORT BufferAccessProvider { | |
| 81 public: | |
| 82 virtual ~BufferAccessProvider() {} | |
| 83 virtual mojo::ScopedSharedBufferHandle GetHandleForTransit() = 0; | |
| 84 virtual std::unique_ptr<VideoCaptureBufferHandle> GetReadWriteAccess() = 0; | |
| 85 }; | |
| 86 | |
| 80 class CAPTURE_EXPORT VideoCaptureDevice | 87 class CAPTURE_EXPORT VideoCaptureDevice |
| 81 : public VideoFrameConsumerFeedbackObserver { | 88 : public VideoFrameConsumerFeedbackObserver { |
| 82 public: | 89 public: |
| 83 | 90 |
| 84 // Interface defining the methods that clients of VideoCapture must have. It | 91 // Interface defining the methods that clients of VideoCapture must have. It |
| 85 // is actually two-in-one: clients may implement OnIncomingCapturedData() or | 92 // is actually two-in-one: clients may implement OnIncomingCapturedData() or |
| 86 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. | 93 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. |
| 87 // All clients must implement OnError(). | 94 // All clients must implement OnError(). |
| 88 class CAPTURE_EXPORT Client { | 95 class CAPTURE_EXPORT Client { |
| 89 public: | 96 public: |
| 90 // Memory buffer returned by Client::ReserveOutputBuffer(). | 97 // Move-only struct representing access to and reservation of a buffer. |
| 91 class CAPTURE_EXPORT Buffer { | 98 struct CAPTURE_EXPORT Buffer { |
|
miu
2016/12/20 22:25:37
Putting the prior two comments together, it then s
miu
2016/12/20 22:25:37
naming: I'd suggest renaming this to BufferPtr bec
miu
2016/12/20 22:25:37
Random thinking out-loud: IIUC the usage cases cor
chfremer
2016/12/22 19:01:20
I like this idea, and I would go with it if I didn
chfremer
2016/12/22 19:01:20
Hmm, the way I see it, VideoCaptureBufferHandle is
chfremer
2016/12/22 19:01:20
I agree this would make sense if we were to follow
miu
2016/12/27 23:38:48
You have a better grasp on the big picture than I
chfremer
2016/12/28 01:06:44
You are making a good point, which makes me realiz
| |
| 92 public: | 99 public: |
| 93 virtual ~Buffer() = 0; | 100 Buffer(); |
| 94 virtual int id() const = 0; | 101 Buffer(int buffer_id, |
| 95 virtual int frame_feedback_id() const = 0; | 102 int frame_feedback_id, |
| 96 virtual gfx::Size dimensions() const = 0; | 103 std::unique_ptr<BufferAccessProvider> access_provider); |
| 97 virtual size_t mapped_size() const = 0; | 104 ~Buffer(); |
| 98 virtual void* data(int plane) = 0; | 105 Buffer(Buffer&& other); |
| 99 void* data() { return data(0); } | 106 Buffer& operator=(Buffer&& other); |
| 100 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) | 107 |
| 101 virtual base::FileDescriptor AsPlatformFile() = 0; | 108 int id; |
|
miu
2016/12/20 22:25:37
It seems weird to expose these data members public
chfremer
2016/12/22 19:01:20
Done. Maybe my idea of "plain old set of members"
miu
2016/12/27 23:38:48
Seems fine, since the intent is to allow public mo
| |
| 102 #endif | 109 int frame_feedback_id; |
| 103 virtual bool IsBackedByVideoFrame() const = 0; | 110 std::unique_ptr<BufferAccessProvider> access_provider; |
| 104 virtual scoped_refptr<VideoFrame> GetVideoFrame() = 0; | 111 bool is_valid() { return access_provider != nullptr; } |
| 105 }; | 112 }; |
| 106 | 113 |
| 107 virtual ~Client() {} | 114 virtual ~Client() {} |
| 108 | 115 |
| 109 // Captured a new video frame, data for which is pointed to by |data|. | 116 // Captured a new video frame, data for which is pointed to by |data|. |
| 110 // | 117 // |
| 111 // The format of the frame is described by |frame_format|, and is assumed to | 118 // The format of the frame is described by |frame_format|, and is assumed to |
| 112 // be tightly packed. This method will try to reserve an output buffer and | 119 // be tightly packed. This method will try to reserve an output buffer and |
| 113 // copy from |data| into the output buffer. If no output buffer is | 120 // copy from |data| into the output buffer. If no output buffer is |
| 114 // available, the frame will be silently dropped. |reference_time| is | 121 // available, the frame will be silently dropped. |reference_time| is |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 132 int frame_feedback_id = 0) = 0; | 139 int frame_feedback_id = 0) = 0; |
| 133 | 140 |
| 134 // Reserve an output buffer into which contents can be captured directly. | 141 // Reserve an output buffer into which contents can be captured directly. |
| 135 // The returned Buffer will always be allocated with a memory size suitable | 142 // The returned Buffer will always be allocated with a memory size suitable |
| 136 // for holding a packed video frame with pixels of |format| format, of | 143 // for holding a packed video frame with pixels of |format| format, of |
| 137 // |dimensions| frame dimensions. It is permissible for |dimensions| to be | 144 // |dimensions| frame dimensions. It is permissible for |dimensions| to be |
| 138 // zero; in which case the returned Buffer does not guarantee memory | 145 // zero; in which case the returned Buffer does not guarantee memory |
| 139 // backing, but functions as a reservation for external input for the | 146 // backing, but functions as a reservation for external input for the |
| 140 // purposes of buffer throttling. | 147 // purposes of buffer throttling. |
| 141 // | 148 // |
| 142 // The output buffer stays reserved and mapped for use until the Buffer | 149 // The buffer stays reserved for use by the caller as long as it |
| 143 // object is destroyed or returned. | 150 // holds on to the contained |access_provider|. |
| 144 virtual std::unique_ptr<Buffer> ReserveOutputBuffer( | 151 virtual Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
| 145 const gfx::Size& dimensions, | 152 VideoPixelFormat format, |
| 146 VideoPixelFormat format, | 153 VideoPixelStorage storage, |
| 147 VideoPixelStorage storage, | 154 int frame_feedback_id) = 0; |
| 148 int frame_feedback_id) = 0; | |
| 149 | 155 |
| 150 // Provides VCD::Client with a populated Buffer containing the content of | 156 // Provides VCD::Client with a populated Buffer containing the content of |
| 151 // the next video frame. The |buffer| must originate from an earlier call to | 157 // the next video frame. The |buffer| must originate from an earlier call to |
| 152 // ReserveOutputBuffer(). | 158 // ReserveOutputBuffer(). |
| 153 // See OnIncomingCapturedData for details of |reference_time| and | 159 // See OnIncomingCapturedData for details of |reference_time| and |
| 154 // |timestamp|. | 160 // |timestamp|. |
| 155 virtual void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 161 virtual void OnIncomingCapturedBuffer(Buffer buffer, |
| 156 const VideoCaptureFormat& format, | 162 const VideoCaptureFormat& format, |
| 157 base::TimeTicks reference_time, | 163 base::TimeTicks reference_time, |
| 158 base::TimeDelta timestamp) = 0; | 164 base::TimeDelta timestamp) = 0; |
| 159 | 165 |
| 160 // Extended version of OnIncomingCapturedBuffer() allowing clients to | 166 // Extended version of OnIncomingCapturedBuffer() allowing clients to |
| 161 // pass a custom |visible_rect| and |additional_metadata|. | 167 // pass a custom |visible_rect| and |additional_metadata|. |
| 162 virtual void OnIncomingCapturedBufferExt( | 168 virtual void OnIncomingCapturedBufferExt( |
| 163 std::unique_ptr<Buffer> buffer, | 169 Buffer buffer, |
| 164 const VideoCaptureFormat& format, | 170 const VideoCaptureFormat& format, |
| 165 base::TimeTicks reference_time, | 171 base::TimeTicks reference_time, |
| 166 base::TimeDelta timestamp, | 172 base::TimeDelta timestamp, |
| 167 gfx::Rect visible_rect, | 173 gfx::Rect visible_rect, |
| 168 const VideoFrameMetadata& additional_metadata) = 0; | 174 const VideoFrameMetadata& additional_metadata) = 0; |
| 169 | 175 |
| 170 // Attempts to reserve the same Buffer provided in the last call to one of | 176 // Attempts to reserve the same Buffer provided in the last call to one of |
| 171 // the OnIncomingCapturedBufferXXX() methods. This will fail if the content | 177 // the OnIncomingCapturedBufferXXX() methods. This will fail if the content |
| 172 // of the Buffer has not been preserved, or if the |dimensions|, |format|, | 178 // of the Buffer has not been preserved, or if the |dimensions|, |format|, |
| 173 // or |storage| disagree with how it was reserved via ReserveOutputBuffer(). | 179 // or |storage| disagree with how it was reserved via ReserveOutputBuffer(). |
| 174 // When this operation fails, nullptr will be returned. | 180 // When this operation fails, nullptr will be returned. |
| 175 virtual std::unique_ptr<Buffer> ResurrectLastOutputBuffer( | 181 virtual Buffer ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
| 176 const gfx::Size& dimensions, | 182 VideoPixelFormat format, |
| 177 VideoPixelFormat format, | 183 VideoPixelStorage storage, |
| 178 VideoPixelStorage storage, | 184 int new_frame_feedback_id) = 0; |
| 179 int new_frame_feedback_id) = 0; | |
| 180 | 185 |
| 181 // An error has occurred that cannot be handled and VideoCaptureDevice must | 186 // An error has occurred that cannot be handled and VideoCaptureDevice must |
| 182 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. | 187 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. |
| 183 virtual void OnError(const tracked_objects::Location& from_here, | 188 virtual void OnError(const tracked_objects::Location& from_here, |
| 184 const std::string& reason) = 0; | 189 const std::string& reason) = 0; |
| 185 | 190 |
| 186 // VideoCaptureDevice requests the |message| to be logged. | 191 // VideoCaptureDevice requests the |message| to be logged. |
| 187 virtual void OnLog(const std::string& message) {} | 192 virtual void OnLog(const std::string& message) {} |
| 188 | 193 |
| 189 // Returns the current buffer pool utilization, in the range 0.0 (no buffers | 194 // 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... | |
| 277 | 282 |
| 278 private: | 283 private: |
| 279 // Gets the power line frequency from the current system time zone if this is | 284 // Gets the power line frequency from the current system time zone if this is |
| 280 // defined, otherwise returns 0. | 285 // defined, otherwise returns 0. |
| 281 PowerLineFrequency GetPowerLineFrequencyForLocation() const; | 286 PowerLineFrequency GetPowerLineFrequencyForLocation() const; |
| 282 }; | 287 }; |
| 283 | 288 |
| 284 } // namespace media | 289 } // namespace media |
| 285 | 290 |
| 286 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ | 291 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ |
| OLD | NEW |