OLD | NEW |
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_API_VIDEO_VIDEO_FRAME_H_ |
12 #define WEBRTC_VIDEO_FRAME_H_ | 12 #define WEBRTC_API_VIDEO_VIDEO_FRAME_H_ |
13 | 13 |
14 #include "webrtc/base/scoped_ref_ptr.h" | 14 #include <stdint.h> |
15 #include "webrtc/base/timeutils.h" | 15 |
16 #include "webrtc/common_types.h" | 16 #include "webrtc/api/video/video_rotation.h" |
17 #include "webrtc/common_video/include/video_frame_buffer.h" | 17 #include "webrtc/api/video/video_frame_buffer.h" |
18 #include "webrtc/common_video/rotation.h" | |
19 #include "webrtc/typedefs.h" | |
20 | 18 |
21 namespace webrtc { | 19 namespace webrtc { |
22 | 20 |
23 class VideoFrame { | 21 class VideoFrame { |
24 public: | 22 public: |
25 // TODO(nisse): This constructor is consistent with | 23 // TODO(nisse): This constructor is consistent with |
26 // cricket::WebRtcVideoFrame. After the class | 24 // cricket::WebRtcVideoFrame. After the class |
27 // cricket::WebRtcVideoFrame and its baseclass cricket::VideoFrame | 25 // cricket::WebRtcVideoFrame and its baseclass cricket::VideoFrame |
28 // are deleted, we should consider whether or not we want to stick | 26 // are deleted, we should consider whether or not we want to stick |
29 // to this style and deprecate the other constructors. | 27 // to this style and deprecate the other constructors. |
30 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 28 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
31 webrtc::VideoRotation rotation, | 29 webrtc::VideoRotation rotation, |
32 int64_t timestamp_us); | 30 int64_t timestamp_us); |
33 | 31 |
34 // Preferred constructor. | 32 // Preferred constructor. |
35 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 33 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
36 uint32_t timestamp, | 34 uint32_t timestamp, |
37 int64_t render_time_ms, | 35 int64_t render_time_ms, |
38 VideoRotation rotation); | 36 VideoRotation rotation); |
39 | 37 |
| 38 ~VideoFrame(); |
| 39 |
40 // Support move and copy. | 40 // Support move and copy. |
41 VideoFrame(const VideoFrame&) = default; | 41 VideoFrame(const VideoFrame&); |
42 VideoFrame(VideoFrame&&) = default; | 42 VideoFrame(VideoFrame&&); |
43 VideoFrame& operator=(const VideoFrame&) = default; | 43 VideoFrame& operator=(const VideoFrame&); |
44 VideoFrame& operator=(VideoFrame&&) = default; | 44 VideoFrame& operator=(VideoFrame&&); |
45 | 45 |
46 // Get frame width. | 46 // Get frame width. |
47 int width() const; | 47 int width() const; |
48 | 48 |
49 // Get frame height. | 49 // Get frame height. |
50 int height() const; | 50 int height() const; |
51 | 51 |
52 // System monotonic clock, same timebase as rtc::TimeMicros(). | 52 // System monotonic clock, same timebase as rtc::TimeMicros(). |
53 int64_t timestamp_us() const { return timestamp_us_; } | 53 int64_t timestamp_us() const { return timestamp_us_; } |
54 void set_timestamp_us(int64_t timestamp_us) { | 54 void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; } |
55 timestamp_us_ = timestamp_us; | |
56 } | |
57 | 55 |
58 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame | 56 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame |
59 // merge, timestamps other than timestamp_us will likely be | 57 // merge, timestamps other than timestamp_us will likely be |
60 // deprecated. | 58 // deprecated. |
61 | 59 |
62 // Set frame timestamp (90kHz). | 60 // Set frame timestamp (90kHz). |
63 void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } | 61 void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } |
64 | 62 |
65 // Get frame timestamp (90kHz). | 63 // Get frame timestamp (90kHz). |
66 uint32_t timestamp() const { return timestamp_rtp_; } | 64 uint32_t timestamp() const { return timestamp_rtp_; } |
67 | 65 |
68 // For now, transport_frame_id and rtp timestamp are the same. | 66 // For now, transport_frame_id and rtp timestamp are the same. |
69 // TODO(nisse): Must be handled differently for QUIC. | 67 // TODO(nisse): Must be handled differently for QUIC. |
70 uint32_t transport_frame_id() const { return timestamp(); } | 68 uint32_t transport_frame_id() const { return timestamp(); } |
71 | 69 |
72 // Set capture ntp time in milliseconds. | 70 // Set capture ntp time in milliseconds. |
73 void set_ntp_time_ms(int64_t ntp_time_ms) { | 71 void set_ntp_time_ms(int64_t ntp_time_ms) { ntp_time_ms_ = ntp_time_ms; } |
74 ntp_time_ms_ = ntp_time_ms; | |
75 } | |
76 | 72 |
77 // Get capture ntp time in milliseconds. | 73 // Get capture ntp time in milliseconds. |
78 int64_t ntp_time_ms() const { return ntp_time_ms_; } | 74 int64_t ntp_time_ms() const { return ntp_time_ms_; } |
79 | 75 |
80 // Naming convention for Coordination of Video Orientation. Please see | 76 // Naming convention for Coordination of Video Orientation. Please see |
81 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126
114v120700p.pdf | 77 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126
114v120700p.pdf |
82 // | 78 // |
83 // "pending rotation" or "pending" = a frame that has a VideoRotation > 0. | 79 // "pending rotation" or "pending" = a frame that has a VideoRotation > 0. |
84 // | 80 // |
85 // "not pending" = a frame that has a VideoRotation == 0. | 81 // "not pending" = a frame that has a VideoRotation == 0. |
86 // | 82 // |
87 // "apply rotation" = modify a frame from being "pending" to being "not | 83 // "apply rotation" = modify a frame from being "pending" to being "not |
88 // pending" rotation (a no-op for "unrotated"). | 84 // pending" rotation (a no-op for "unrotated"). |
89 // | 85 // |
90 VideoRotation rotation() const { return rotation_; } | 86 VideoRotation rotation() const { return rotation_; } |
91 void set_rotation(VideoRotation rotation) { | 87 void set_rotation(VideoRotation rotation) { rotation_ = rotation; } |
92 rotation_ = rotation; | |
93 } | |
94 | 88 |
95 // Set render time in milliseconds. | 89 // Set render time in milliseconds. |
96 void set_render_time_ms(int64_t render_time_ms) { | 90 void set_render_time_ms(int64_t render_time_ms); |
97 set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec);; | |
98 } | |
99 | 91 |
100 // Get render time in milliseconds. | 92 // Get render time in milliseconds. |
101 int64_t render_time_ms() const { | 93 int64_t render_time_ms() const; |
102 return timestamp_us() / rtc::kNumMicrosecsPerMillisec; | |
103 } | |
104 | 94 |
105 // Return the underlying buffer. Never nullptr for a properly | 95 // Return the underlying buffer. Never nullptr for a properly |
106 // initialized VideoFrame. | 96 // initialized VideoFrame. |
107 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; | 97 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; |
108 | 98 |
| 99 // TODO(nisse): Deprecated. |
109 // Return true if the frame is stored in a texture. | 100 // Return true if the frame is stored in a texture. |
110 bool is_texture() const { | 101 bool is_texture() const { |
111 return video_frame_buffer() && | 102 return video_frame_buffer()->native_handle() != nullptr; |
112 video_frame_buffer()->native_handle() != nullptr; | |
113 } | 103 } |
114 | 104 |
115 private: | 105 private: |
116 // An opaque reference counted handle that stores the pixel data. | 106 // An opaque reference counted handle that stores the pixel data. |
117 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | 107 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; |
118 uint32_t timestamp_rtp_; | 108 uint32_t timestamp_rtp_; |
119 int64_t ntp_time_ms_; | 109 int64_t ntp_time_ms_; |
120 int64_t timestamp_us_; | 110 int64_t timestamp_us_; |
121 VideoRotation rotation_; | 111 VideoRotation rotation_; |
122 }; | 112 }; |
123 | 113 |
| 114 } // namespace webrtc |
124 | 115 |
125 // TODO(pbos): Rename EncodedFrame and reformat this class' members. | 116 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_H_ |
126 class EncodedImage { | |
127 public: | |
128 static const size_t kBufferPaddingBytesH264; | |
129 | |
130 // Some decoders require encoded image buffers to be padded with a small | |
131 // number of additional bytes (due to over-reading byte readers). | |
132 static size_t GetBufferPaddingBytes(VideoCodecType codec_type); | |
133 | |
134 EncodedImage() : EncodedImage(nullptr, 0, 0) {} | |
135 | |
136 EncodedImage(uint8_t* buffer, size_t length, size_t size) | |
137 : _buffer(buffer), _length(length), _size(size) {} | |
138 | |
139 struct AdaptReason { | |
140 AdaptReason() | |
141 : quality_resolution_downscales(-1), | |
142 bw_resolutions_disabled(-1) {} | |
143 | |
144 int quality_resolution_downscales; // Number of times this frame is down | |
145 // scaled in resolution due to quality. | |
146 // Or -1 if information is not provided. | |
147 int bw_resolutions_disabled; // Number of resolutions that are not sent | |
148 // due to bandwidth for this frame. | |
149 // Or -1 if information is not provided. | |
150 }; | |
151 uint32_t _encodedWidth = 0; | |
152 uint32_t _encodedHeight = 0; | |
153 uint32_t _timeStamp = 0; | |
154 // NTP time of the capture time in local timebase in milliseconds. | |
155 int64_t ntp_time_ms_ = 0; | |
156 int64_t capture_time_ms_ = 0; | |
157 FrameType _frameType = kVideoFrameDelta; | |
158 uint8_t* _buffer; | |
159 size_t _length; | |
160 size_t _size; | |
161 VideoRotation rotation_ = kVideoRotation_0; | |
162 bool _completeFrame = false; | |
163 AdaptReason adapt_reason_; | |
164 int qp_ = -1; // Quantizer value. | |
165 | |
166 // When an application indicates non-zero values here, it is taken as an | |
167 // indication that all future frames will be constrained with those limits | |
168 // until the application indicates a change again. | |
169 PlayoutDelay playout_delay_ = {-1, -1}; | |
170 }; | |
171 | |
172 } // namespace webrtc | |
173 #endif // WEBRTC_VIDEO_FRAME_H_ | |
OLD | NEW |