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

Side by Side Diff: webrtc/video_frame.h

Issue 2282713002: Introduce webrtc::VideoFrame::timestamp_us, and corresponding constructor. (Closed)
Patch Set: Improve comments and constructor order. 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
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
32 // TODO(nisse): This constructor is consistent with
33 // cricket::WebRtcVideoFrame. After the class
34 // cricket::WebRtcVideoFrame and its baseclass cricket::VideoFrame
35 // are deleted, we should consider whether or not we want to stick
36 // to this style and deprecate the other constructors.
37 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
38 webrtc::VideoRotation rotation,
39 int64_t timestamp_us);
40
31 // Preferred constructor. 41 // Preferred constructor.
32 VideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, 42 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
33 uint32_t timestamp, 43 uint32_t timestamp,
34 int64_t render_time_ms, 44 int64_t render_time_ms,
35 VideoRotation rotation); 45 VideoRotation rotation);
36 46
37 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based 47 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
38 // on set dimensions - height and plane stride. 48 // on set dimensions - height and plane stride.
39 // If required size is bigger than the allocated one, new buffers of adequate 49 // If required size is bigger than the allocated one, new buffers of adequate
40 // size will be allocated. 50 // size will be allocated.
41 51
42 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and 52 // 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 106 // webrtc::VideoFrame merge. When used with memset, consider using
97 // libyuv::I420Rect instead. 107 // libyuv::I420Rect instead.
98 int allocated_size(PlaneType type) const; 108 int allocated_size(PlaneType type) const;
99 109
100 // Get frame width. 110 // Get frame width.
101 int width() const; 111 int width() const;
102 112
103 // Get frame height. 113 // Get frame height.
104 int height() const; 114 int height() const;
105 115
116 // System monotonic clock, same timebase as rtc::TimeMicros().
117 int64_t timestamp_us() const { return timestamp_us_; }
118 void set_timestamp_us(int64_t timestamp_us) {
119 timestamp_us_ = timestamp_us;
120 }
121
106 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame 122 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame
107 // merge, we'll have methods timestamp_us and set_timestamp_us, all 123 // merge, timestamps other than timestamp_us will likely be
108 // other frame timestamps will likely be deprecated. 124 // deprecated.
109 125
110 // Set frame timestamp (90kHz). 126 // Set frame timestamp (90kHz).
111 void set_timestamp(uint32_t timestamp) { timestamp_ = timestamp; } 127 void set_timestamp(uint32_t timestamp) { timestamp_ = timestamp; }
112 128
113 // Get frame timestamp (90kHz). 129 // Get frame timestamp (90kHz).
114 uint32_t timestamp() const { return timestamp_; } 130 uint32_t timestamp() const { return timestamp_; }
115 131
116 // Set capture ntp time in milliseconds. 132 // Set capture ntp time in milliseconds.
117 void set_ntp_time_ms(int64_t ntp_time_ms) { 133 void set_ntp_time_ms(int64_t ntp_time_ms) {
118 ntp_time_ms_ = ntp_time_ms; 134 ntp_time_ms_ = ntp_time_ms;
(...skipping 12 matching lines...) Expand all
131 // "apply rotation" = modify a frame from being "pending" to being "not 147 // "apply rotation" = modify a frame from being "pending" to being "not
132 // pending" rotation (a no-op for "unrotated"). 148 // pending" rotation (a no-op for "unrotated").
133 // 149 //
134 VideoRotation rotation() const { return rotation_; } 150 VideoRotation rotation() const { return rotation_; }
135 void set_rotation(VideoRotation rotation) { 151 void set_rotation(VideoRotation rotation) {
136 rotation_ = rotation; 152 rotation_ = rotation;
137 } 153 }
138 154
139 // Set render time in milliseconds. 155 // Set render time in milliseconds.
140 void set_render_time_ms(int64_t render_time_ms) { 156 void set_render_time_ms(int64_t render_time_ms) {
141 render_time_ms_ = render_time_ms; 157 set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec);;
142 } 158 }
143 159
144 // Get render time in milliseconds. 160 // Get render time in milliseconds.
145 int64_t render_time_ms() const { return render_time_ms_; } 161 int64_t render_time_ms() const {
162 return timestamp_us() / rtc::kNumMicrosecsPerMillisec;
163 }
146 164
147 // Return true if and only if video_frame_buffer() is null. Which is possible 165 // Return true if and only if video_frame_buffer() is null. Which is possible
148 // only if the object was default-constructed. 166 // only if the object was default-constructed.
149 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and 167 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and
150 // webrtc::VideoFrame merge. The intention is that video_frame_buffer() never 168 // webrtc::VideoFrame merge. The intention is that video_frame_buffer() never
151 // should return nullptr. To handle potentially uninitialized or non-existent 169 // should return nullptr. To handle potentially uninitialized or non-existent
152 // frames, consider using rtc::Optional. Otherwise, IsZeroSize() can be 170 // frames, consider using rtc::Optional. Otherwise, IsZeroSize() can be
153 // replaced by video_frame_buffer() == nullptr. 171 // replaced by video_frame_buffer() == nullptr.
154 bool IsZeroSize() const; 172 bool IsZeroSize() const;
155 173
156 // Return the underlying buffer. Never nullptr for a properly 174 // Return the underlying buffer. Never nullptr for a properly
157 // initialized VideoFrame. 175 // initialized VideoFrame.
158 // Creating a new reference breaks the HasOneRef and IsMutable 176 // Creating a new reference breaks the HasOneRef and IsMutable
159 // logic. So return a const ref to our reference. 177 // logic. So return a const ref to our reference.
160 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& video_frame_buffer() 178 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& video_frame_buffer()
161 const; 179 const;
162 180
163 // Return true if the frame is stored in a texture. 181 // Return true if the frame is stored in a texture.
164 bool is_texture() { 182 bool is_texture() {
165 return video_frame_buffer() && 183 return video_frame_buffer() &&
166 video_frame_buffer()->native_handle() != nullptr; 184 video_frame_buffer()->native_handle() != nullptr;
167 } 185 }
168 186
169 private: 187 private:
170 // An opaque reference counted handle that stores the pixel data. 188 // An opaque reference counted handle that stores the pixel data.
171 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; 189 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
172 uint32_t timestamp_; 190 uint32_t timestamp_;
mflodman 2016/09/02 12:29:59 Can we rename this one for now, since this is used
nisse-webrtc 2016/09/02 12:46:24 Renaming the member variable is easy. Renaming set
173 int64_t ntp_time_ms_; 191 int64_t ntp_time_ms_;
174 int64_t render_time_ms_; 192 int64_t timestamp_us_;
175 VideoRotation rotation_; 193 VideoRotation rotation_;
176 }; 194 };
177 195
178 196
179 // TODO(pbos): Rename EncodedFrame and reformat this class' members. 197 // TODO(pbos): Rename EncodedFrame and reformat this class' members.
180 class EncodedImage { 198 class EncodedImage {
181 public: 199 public:
182 static const size_t kBufferPaddingBytesH264; 200 static const size_t kBufferPaddingBytesH264;
183 201
184 // Some decoders require encoded image buffers to be padded with a small 202 // 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. 236 int qp_ = -1; // Quantizer value.
219 237
220 // When an application indicates non-zero values here, it is taken as an 238 // 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 239 // indication that all future frames will be constrained with those limits
222 // until the application indicates a change again. 240 // until the application indicates a change again.
223 PlayoutDelay playout_delay_ = {-1, -1}; 241 PlayoutDelay playout_delay_ = {-1, -1};
224 }; 242 };
225 243
226 } // namespace webrtc 244 } // namespace webrtc
227 #endif // WEBRTC_VIDEO_FRAME_H_ 245 #endif // WEBRTC_VIDEO_FRAME_H_
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698