Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Side by Side Diff: media/capture/video/video_capture_device.h

Issue 2518143004: [Mojo Video Capture] Replace RESOURCE_UTILIZATION with interface ReceiverLoadObserver (Closed)
Patch Set: Fixes for failing bots Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 #include "media/mojo/interfaces/image_capture.mojom.h" 34 #include "media/mojo/interfaces/image_capture.mojom.h"
35 #include "mojo/public/cpp/bindings/array.h" 35 #include "mojo/public/cpp/bindings/array.h"
36 #include "ui/gfx/gpu_memory_buffer.h" 36 #include "ui/gfx/gpu_memory_buffer.h"
37 37
38 namespace tracked_objects { 38 namespace tracked_objects {
39 class Location; 39 class Location;
40 } // namespace tracked_objects 40 } // namespace tracked_objects
41 41
42 namespace media { 42 namespace media {
43 43
44 class CAPTURE_EXPORT VideoCaptureDevice { 44 class CAPTURE_EXPORT FrameReceiverObserver {
miu 2016/12/01 05:25:18 Should this interface be in vcd_client.h instead?
chfremer 2016/12/02 01:28:29 With the simplification, this interface is no long
45 public:
46 virtual ~FrameReceiverObserver() {}
47
48 virtual void OnReceiverReportingUtilization(int buffer_id,
49 double utilization) = 0;
50
51 static double no_utilization_recorded() { return -1.0; }
miu 2016/12/01 05:25:18 nit: static constexpr double kNoUtilizationRecorde
chfremer 2016/12/02 01:28:28 Done.
52 };
53
54 // During processing of a video frame delivered to |receiver|, we may report
miu 2016/12/01 05:25:18 1. Please fix: The code comment refers to "|receiv
chfremer 2016/12/02 01:28:28 Done.
55 // back to the device under how much load the |receiver| is. The Device may
56 // use this information to adjust the rate of data it pushes out to the
57 // receiver to avoid overloading it.
58 // Values are interpreted as follows:
59 // Less than 0.0 is meaningless and should be ignored. 1.0 indicates a
60 // maximum sustainable utilization. Greater than 1.0 indicates the consumer
61 // is likely to stall or drop frames if the data volume is not reduced.
62 //
63 // Example: In a system that encodes and transmits video frames over the
64 // network, this value can be used to indicate whether sufficient CPU
65 // is available for encoding and/or sufficient bandwidth is available for
66 // transmission over the network. The maximum of the two utilization
67 // measurements would be used as feedback.
68 class CAPTURE_EXPORT ConsumerLoadObserver {
miu 2016/12/01 05:25:18 History: At one point, we were wondering whether w
chfremer 2016/12/02 01:28:28 Done.
69 public:
70 virtual ~ConsumerLoadObserver() {}
71 virtual void OnConsumerReportingUtilization(int frame_id,
miu 2016/12/01 05:25:18 naming nit: s/frame_id/frame_feedback_id/ everywhe
chfremer 2016/12/02 01:28:28 Done.
72 double utilization){};
miu 2016/12/01 05:25:18 style nit: add space before open brace
chfremer 2016/12/02 01:28:29 Oops. Seems there was an extra ";" which caused th
73 };
74
75 class CAPTURE_EXPORT VideoCaptureDevice : public ConsumerLoadObserver {
45 public: 76 public:
46 77
47 // Interface defining the methods that clients of VideoCapture must have. It 78 // Interface defining the methods that clients of VideoCapture must have. It
48 // is actually two-in-one: clients may implement OnIncomingCapturedData() or 79 // is actually two-in-one: clients may implement OnIncomingCapturedData() or
49 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. 80 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them.
50 // All clients must implement OnError(). 81 // All clients must implement OnError().
51 class CAPTURE_EXPORT Client { 82 class CAPTURE_EXPORT Client {
52 public: 83 public:
53 // Memory buffer returned by Client::ReserveOutputBuffer(). 84 // Memory buffer returned by Client::ReserveOutputBuffer().
54 class CAPTURE_EXPORT Buffer { 85 class CAPTURE_EXPORT Buffer {
(...skipping 23 matching lines...) Expand all
78 // Audio/Video sync, not an exact presentation time for playout, because it 109 // Audio/Video sync, not an exact presentation time for playout, because it
79 // could contain noise. |timestamp| measures the ideal time span between the 110 // could contain noise. |timestamp| measures the ideal time span between the
80 // first frame in the stream and the current frame; however, the time source 111 // first frame in the stream and the current frame; however, the time source
81 // is determined by the platform's device driver and is often not the system 112 // is determined by the platform's device driver and is often not the system
82 // clock, or even has a drift with respect to system clock. 113 // clock, or even has a drift with respect to system clock.
83 virtual void OnIncomingCapturedData(const uint8_t* data, 114 virtual void OnIncomingCapturedData(const uint8_t* data,
84 int length, 115 int length,
85 const VideoCaptureFormat& frame_format, 116 const VideoCaptureFormat& frame_format,
86 int clockwise_rotation, 117 int clockwise_rotation,
87 base::TimeTicks reference_time, 118 base::TimeTicks reference_time,
88 base::TimeDelta timestamp) = 0; 119 base::TimeDelta timestamp,
120 int frame_id = 0) = 0;
miu 2016/12/01 05:25:18 Please document the new argument.
chfremer 2016/12/02 01:28:28 Done.
89 121
90 // Reserve an output buffer into which contents can be captured directly. 122 // Reserve an output buffer into which contents can be captured directly.
91 // The returned Buffer will always be allocated with a memory size suitable 123 // The returned Buffer will always be allocated with a memory size suitable
92 // for holding a packed video frame with pixels of |format| format, of 124 // for holding a packed video frame with pixels of |format| format, of
93 // |dimensions| frame dimensions. It is permissible for |dimensions| to be 125 // |dimensions| frame dimensions. It is permissible for |dimensions| to be
94 // zero; in which case the returned Buffer does not guarantee memory 126 // zero; in which case the returned Buffer does not guarantee memory
95 // backing, but functions as a reservation for external input for the 127 // backing, but functions as a reservation for external input for the
96 // purposes of buffer throttling. 128 // purposes of buffer throttling.
97 // 129 //
98 // The output buffer stays reserved and mapped for use until the Buffer 130 // The output buffer stays reserved and mapped for use until the Buffer
99 // object is destroyed or returned. 131 // object is destroyed or returned.
100 virtual std::unique_ptr<Buffer> ReserveOutputBuffer( 132 virtual std::unique_ptr<Buffer> ReserveOutputBuffer(
101 const gfx::Size& dimensions, 133 const gfx::Size& dimensions,
102 VideoPixelFormat format, 134 VideoPixelFormat format,
103 VideoPixelStorage storage) = 0; 135 VideoPixelStorage storage) = 0;
104 136
105 // Captured new video data, held in |frame| or |buffer|, respectively for 137 // Captured new video data, held in |frame| or |buffer|, respectively for
106 // OnIncomingCapturedVideoFrame() and OnIncomingCapturedBuffer(). 138 // OnIncomingCapturedVideoFrame() and OnIncomingCapturedBuffer().
107 // 139 //
108 // In both cases, as the frame is backed by a reservation returned by 140 // In both cases, as the frame is backed by a reservation returned by
109 // ReserveOutputBuffer(), delivery is guaranteed and will require no 141 // ReserveOutputBuffer(), delivery is guaranteed and will require no
110 // additional copies in the browser process. 142 // additional copies in the browser process.
111 // See OnIncomingCapturedData for details of |reference_time| and 143 // See OnIncomingCapturedData for details of |reference_time| and
112 // |timestamp|. 144 // |timestamp|.
113 // TODO(chfremer): Consider removing one of the two in order to simplify the 145 // TODO(chfremer): Consider removing one of the two in order to simplify the
114 // interface. 146 // interface.
115 virtual void OnIncomingCapturedBuffer( 147 virtual void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer,
116 std::unique_ptr<Buffer> buffer, 148 const VideoCaptureFormat& format,
117 const VideoCaptureFormat& frame_format, 149 base::TimeTicks reference_time,
118 base::TimeTicks reference_time, 150 base::TimeDelta timestamp,
119 base::TimeDelta timestamp) = 0; 151 int frame_id) = 0;
120 virtual void OnIncomingCapturedVideoFrame( 152 virtual void OnIncomingCapturedVideoFrame(std::unique_ptr<Buffer> buffer,
121 std::unique_ptr<Buffer> buffer, 153 scoped_refptr<VideoFrame> frame,
122 scoped_refptr<VideoFrame> frame) = 0; 154 int frame_id) = 0;
123 155
124 // Attempts to reserve the same Buffer provided in the last call to one of 156 // Attempts to reserve the same Buffer provided in the last call to one of
125 // the OnIncomingCapturedXXX() methods. This will fail if the content of the 157 // the OnIncomingCapturedXXX() methods. This will fail if the content of the
126 // Buffer has not been preserved, or if the |dimensions|, |format|, or 158 // Buffer has not been preserved, or if the |dimensions|, |format|, or
127 // |storage| disagree with how it was reserved via ReserveOutputBuffer(). 159 // |storage| disagree with how it was reserved via ReserveOutputBuffer().
128 // When this operation fails, nullptr will be returned. 160 // When this operation fails, nullptr will be returned.
129 virtual std::unique_ptr<Buffer> ResurrectLastOutputBuffer( 161 virtual std::unique_ptr<Buffer> ResurrectLastOutputBuffer(
130 const gfx::Size& dimensions, 162 const gfx::Size& dimensions,
131 VideoPixelFormat format, 163 VideoPixelFormat format,
132 VideoPixelStorage storage) = 0; 164 VideoPixelStorage storage) = 0;
133 165
134 // An error has occurred that cannot be handled and VideoCaptureDevice must 166 // An error has occurred that cannot be handled and VideoCaptureDevice must
135 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. 167 // be StopAndDeAllocate()-ed. |reason| is a text description of the error.
136 virtual void OnError(const tracked_objects::Location& from_here, 168 virtual void OnError(const tracked_objects::Location& from_here,
137 const std::string& reason) = 0; 169 const std::string& reason) = 0;
138 170
139 // VideoCaptureDevice requests the |message| to be logged. 171 // VideoCaptureDevice requests the |message| to be logged.
140 virtual void OnLog(const std::string& message) {} 172 virtual void OnLog(const std::string& message) {}
141 173
142 // Returns the current buffer pool utilization, in the range 0.0 (no buffers 174 // Returns the current buffer pool utilization, in the range 0.0 (no buffers
143 // are in use by producers or consumers) to 1.0 (all buffers are in use). 175 // are in use by producers or consumers) to 1.0 (all buffers are in use).
144 virtual double GetBufferPoolUtilization() const = 0; 176 virtual double GetBufferPoolUtilization() const = 0;
145 }; 177 };
146 178
147 virtual ~VideoCaptureDevice(); 179 ~VideoCaptureDevice() override;
148 180
149 // Prepares the video capturer for use. StopAndDeAllocate() must be called 181 // Prepares the video capturer for use. StopAndDeAllocate() must be called
150 // before the object is deleted. 182 // before the object is deleted.
151 virtual void AllocateAndStart(const VideoCaptureParams& params, 183 virtual void AllocateAndStart(const VideoCaptureParams& params,
152 std::unique_ptr<Client> client) = 0; 184 std::unique_ptr<Client> client) = 0;
153 185
154 // In cases where the video capturer self-pauses (e.g., a screen capturer 186 // In cases where the video capturer self-pauses (e.g., a screen capturer
155 // where the screen's content has not changed in a while), consumers may call 187 // where the screen's content has not changed in a while), consumers may call
156 // this to request a "refresh frame" be delivered to the Client. This is used 188 // this to request a "refresh frame" be delivered to the Client. This is used
157 // in a number of circumstances, such as: 189 // in a number of circumstances, such as:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 262
231 private: 263 private:
232 // Gets the power line frequency from the current system time zone if this is 264 // Gets the power line frequency from the current system time zone if this is
233 // defined, otherwise returns 0. 265 // defined, otherwise returns 0.
234 PowerLineFrequency GetPowerLineFrequencyForLocation() const; 266 PowerLineFrequency GetPowerLineFrequencyForLocation() const;
235 }; 267 };
236 268
237 } // namespace media 269 } // namespace media
238 270
239 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ 271 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698