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

Side by Side Diff: webrtc/video_frame.h

Issue 2282713002: Introduce webrtc::VideoFrame::timestamp_us, and corresponding constructor. (Closed)
Patch Set: Delete testcase WebRtcVideoEngine2Test.ProducesIncreasingTimestampsWithResetInputSources Created 4 years, 3 months 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 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_VIDEO_FRAME_H_ 11 #ifndef WEBRTC_VIDEO_FRAME_H_
12 #define WEBRTC_VIDEO_FRAME_H_ 12 #define WEBRTC_VIDEO_FRAME_H_
13 13
14 #include "webrtc/base/scoped_ref_ptr.h" 14 #include "webrtc/base/scoped_ref_ptr.h"
15 #include "webrtc/base/timeutils.h"
15 #include "webrtc/common_types.h" 16 #include "webrtc/common_types.h"
16 #include "webrtc/common_video/include/video_frame_buffer.h" 17 #include "webrtc/common_video/include/video_frame_buffer.h"
17 #include "webrtc/common_video/rotation.h" 18 #include "webrtc/common_video/rotation.h"
18 #include "webrtc/typedefs.h" 19 #include "webrtc/typedefs.h"
19 20
20 namespace webrtc { 21 namespace webrtc {
21 22
22 // TODO(nisse): This class duplicates cricket::VideoFrame. There's 23 // TODO(nisse): This class duplicates cricket::VideoFrame. There's
23 // ongoing work to merge the classes. See 24 // ongoing work to merge the classes. See
24 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5682. 25 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5682.
25 class VideoFrame { 26 class VideoFrame {
26 public: 27 public:
27 // TODO(nisse): Deprecated. Using the default constructor violates the 28 // TODO(nisse): Deprecated. Using the default constructor violates the
28 // reasonable assumption that video_frame_buffer() returns a valid buffer. 29 // reasonable assumption that video_frame_buffer() returns a valid buffer.
29 VideoFrame(); 30 VideoFrame();
30 31
31 // Preferred constructor. 32 // New style constructor, consistent with cricket::WebRtcVideoFrame.
danilchap 2016/08/26 13:19:30 do not use word 'new' it will be old quickly. "Con
nisse-webrtc 2016/08/29 07:49:58 I rephrased as a TODO comment pointing out the dir
32 VideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, 33 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
danilchap 2016/08/26 13:19:30 might be cleaner to pass this refptr by value inst
nisse-webrtc 2016/08/29 07:49:58 Makes sense. But I think it's for a different cl,
34 webrtc::VideoRotation rotation,
danilchap 2016/08/26 13:19:30 for consistency might be better to order parameter
nisse-webrtc 2016/08/29 07:49:58 Sorry about that. But this argument ordering is a
danilchap 2016/08/29 08:28:16 Acknowledged. Not sure why consistency with WebRtc
35 int64_t timestamp_us);
36
37 // Preferred old style constructor.
danilchap 2016/08/26 13:19:30 avoice using word 'old' too for same reason as wor
nisse-webrtc 2016/08/29 07:49:58 Done.
38 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
33 uint32_t timestamp, 39 uint32_t timestamp,
34 int64_t render_time_ms, 40 int64_t render_time_ms,
35 VideoRotation rotation); 41 VideoRotation rotation);
36 42
37 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based 43 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
38 // on set dimensions - height and plane stride. 44 // on set dimensions - height and plane stride.
39 // If required size is bigger than the allocated one, new buffers of adequate 45 // If required size is bigger than the allocated one, new buffers of adequate
40 // size will be allocated. 46 // size will be allocated.
41 47
42 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and 48 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // webrtc::VideoFrame merge. When used with memset, consider using 102 // webrtc::VideoFrame merge. When used with memset, consider using
97 // libyuv::I420Rect instead. 103 // libyuv::I420Rect instead.
98 int allocated_size(PlaneType type) const; 104 int allocated_size(PlaneType type) const;
99 105
100 // Get frame width. 106 // Get frame width.
101 int width() const; 107 int width() const;
102 108
103 // Get frame height. 109 // Get frame height.
104 int height() const; 110 int height() const;
105 111
112 // System monotonic clock, same timebase as rtc::TimeMicros().
113 int64_t timestamp_us() const { return timestamp_us_; }
114 void set_timestamp_us(int64_t timestamp_us) {
115 timestamp_us_ = timestamp_us;
116 }
117
106 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame 118 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame
107 // merge, we'll have methods timestamp_us and set_timestamp_us, all 119 // merge, timestamps other than timestamp_us will likely be
108 // other frame timestamps will likely be deprecated. 120 // deprecated.
109 121
110 // Set frame timestamp (90kHz). 122 // Set frame timestamp (90kHz).
111 void set_timestamp(uint32_t timestamp) { timestamp_ = timestamp; } 123 void set_timestamp(uint32_t timestamp) { timestamp_ = timestamp; }
112 124
113 // Get frame timestamp (90kHz). 125 // Get frame timestamp (90kHz).
114 uint32_t timestamp() const { return timestamp_; } 126 uint32_t timestamp() const { return timestamp_; }
115 127
116 // Set capture ntp time in milliseconds. 128 // Set capture ntp time in milliseconds.
117 void set_ntp_time_ms(int64_t ntp_time_ms) { 129 void set_ntp_time_ms(int64_t ntp_time_ms) {
118 ntp_time_ms_ = ntp_time_ms; 130 ntp_time_ms_ = ntp_time_ms;
(...skipping 12 matching lines...) Expand all
131 // "apply rotation" = modify a frame from being "pending" to being "not 143 // "apply rotation" = modify a frame from being "pending" to being "not
132 // pending" rotation (a no-op for "unrotated"). 144 // pending" rotation (a no-op for "unrotated").
133 // 145 //
134 VideoRotation rotation() const { return rotation_; } 146 VideoRotation rotation() const { return rotation_; }
135 void set_rotation(VideoRotation rotation) { 147 void set_rotation(VideoRotation rotation) {
136 rotation_ = rotation; 148 rotation_ = rotation;
137 } 149 }
138 150
139 // Set render time in milliseconds. 151 // Set render time in milliseconds.
140 void set_render_time_ms(int64_t render_time_ms) { 152 void set_render_time_ms(int64_t render_time_ms) {
141 render_time_ms_ = render_time_ms; 153 set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec);;
142 } 154 }
143 155
144 // Get render time in milliseconds. 156 // Get render time in milliseconds.
145 int64_t render_time_ms() const { return render_time_ms_; } 157 int64_t render_time_ms() const {
158 return timestamp_us() / rtc::kNumMicrosecsPerMillisec;
159 }
146 160
147 // Return true if and only if video_frame_buffer() is null. Which is possible 161 // Return true if and only if video_frame_buffer() is null. Which is possible
148 // only if the object was default-constructed. 162 // only if the object was default-constructed.
149 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and 163 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and
150 // webrtc::VideoFrame merge. The intention is that video_frame_buffer() never 164 // webrtc::VideoFrame merge. The intention is that video_frame_buffer() never
151 // should return nullptr. To handle potentially uninitialized or non-existent 165 // should return nullptr. To handle potentially uninitialized or non-existent
152 // frames, consider using rtc::Optional. Otherwise, IsZeroSize() can be 166 // frames, consider using rtc::Optional. Otherwise, IsZeroSize() can be
153 // replaced by video_frame_buffer() == nullptr. 167 // replaced by video_frame_buffer() == nullptr.
154 bool IsZeroSize() const; 168 bool IsZeroSize() const;
155 169
156 // Return the underlying buffer. Never nullptr for a properly 170 // Return the underlying buffer. Never nullptr for a properly
157 // initialized VideoFrame. 171 // initialized VideoFrame.
158 // Creating a new reference breaks the HasOneRef and IsMutable 172 // Creating a new reference breaks the HasOneRef and IsMutable
159 // logic. So return a const ref to our reference. 173 // logic. So return a const ref to our reference.
160 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& video_frame_buffer() 174 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& video_frame_buffer()
161 const; 175 const;
162 176
163 // Return true if the frame is stored in a texture. 177 // Return true if the frame is stored in a texture.
164 bool is_texture() { 178 bool is_texture() {
165 return video_frame_buffer() && 179 return video_frame_buffer() &&
166 video_frame_buffer()->native_handle() != nullptr; 180 video_frame_buffer()->native_handle() != nullptr;
167 } 181 }
168 182
169 private: 183 private:
170 // An opaque reference counted handle that stores the pixel data. 184 // An opaque reference counted handle that stores the pixel data.
171 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; 185 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
172 uint32_t timestamp_; 186 uint32_t timestamp_;
173 int64_t ntp_time_ms_; 187 int64_t ntp_time_ms_;
174 int64_t render_time_ms_; 188 int64_t timestamp_us_;
175 VideoRotation rotation_; 189 VideoRotation rotation_;
176 }; 190 };
177 191
178 192
179 // TODO(pbos): Rename EncodedFrame and reformat this class' members. 193 // TODO(pbos): Rename EncodedFrame and reformat this class' members.
180 class EncodedImage { 194 class EncodedImage {
181 public: 195 public:
182 static const size_t kBufferPaddingBytesH264; 196 static const size_t kBufferPaddingBytesH264;
183 197
184 // Some decoders require encoded image buffers to be padded with a small 198 // Some decoders require encoded image buffers to be padded with a small
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 int qp_ = -1; // Quantizer value. 232 int qp_ = -1; // Quantizer value.
219 233
220 // When an application indicates non-zero values here, it is taken as an 234 // When an application indicates non-zero values here, it is taken as an
221 // indication that all future frames will be constrained with those limits 235 // indication that all future frames will be constrained with those limits
222 // until the application indicates a change again. 236 // until the application indicates a change again.
223 PlayoutDelay playout_delay_ = {-1, -1}; 237 PlayoutDelay playout_delay_ = {-1, -1};
224 }; 238 };
225 239
226 } // namespace webrtc 240 } // namespace webrtc
227 #endif // WEBRTC_VIDEO_FRAME_H_ 241 #endif // WEBRTC_VIDEO_FRAME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698