pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_VIDEO_FRAME_H_ |
| 12 | #define WEBRTC_VIDEO_FRAME_H_ |
| 13 | |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 14 | #include "webrtc/base/scoped_ref_ptr.h" |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 15 | #include "webrtc/base/timeutils.h" |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 16 | #include "webrtc/common_types.h" |
kjellander | 6f8ce06 | 2015-11-16 13:52:24 -0800 | [diff] [blame] | 17 | #include "webrtc/common_video/include/video_frame_buffer.h" |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 18 | #include "webrtc/common_video/rotation.h" |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 19 | #include "webrtc/typedefs.h" |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 23 | class VideoFrame { |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 24 | public: |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 25 | // TODO(nisse): Deprecated. Using the default constructor violates the |
| 26 | // reasonable assumption that video_frame_buffer() returns a valid buffer. |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 27 | VideoFrame(); |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 28 | |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 29 | // TODO(nisse): This constructor is consistent with |
| 30 | // cricket::WebRtcVideoFrame. After the class |
| 31 | // cricket::WebRtcVideoFrame and its baseclass cricket::VideoFrame |
| 32 | // are deleted, we should consider whether or not we want to stick |
| 33 | // to this style and deprecate the other constructors. |
| 34 | VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 35 | webrtc::VideoRotation rotation, |
| 36 | int64_t timestamp_us); |
| 37 | |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 38 | // Preferred constructor. |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 39 | VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 40 | uint32_t timestamp, |
| 41 | int64_t render_time_ms, |
| 42 | VideoRotation rotation); |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 43 | |
nisse | 67dca9f | 2016-10-31 08:05:50 -0700 | [diff] [blame] | 44 | // Support move and copy. |
| 45 | VideoFrame(const VideoFrame&) = default; |
| 46 | VideoFrame(VideoFrame&&) = default; |
| 47 | VideoFrame& operator=(const VideoFrame&) = default; |
| 48 | VideoFrame& operator=(VideoFrame&&) = default; |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 49 | |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 50 | // Get frame width. |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 51 | int width() const; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 52 | |
| 53 | // Get frame height. |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 54 | int height() const; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 55 | |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 56 | // System monotonic clock, same timebase as rtc::TimeMicros(). |
| 57 | int64_t timestamp_us() const { return timestamp_us_; } |
| 58 | void set_timestamp_us(int64_t timestamp_us) { |
| 59 | timestamp_us_ = timestamp_us; |
| 60 | } |
| 61 | |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 62 | // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 63 | // merge, timestamps other than timestamp_us will likely be |
| 64 | // deprecated. |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 65 | |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 66 | // Set frame timestamp (90kHz). |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 67 | void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 68 | |
| 69 | // Get frame timestamp (90kHz). |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 70 | uint32_t timestamp() const { return timestamp_rtp_; } |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 71 | |
nisse | 0934785 | 2016-10-19 00:30:30 -0700 | [diff] [blame] | 72 | // For now, transport_frame_id and rtp timestamp are the same. |
| 73 | // TODO(nisse): Must be handled differently for QUIC. |
| 74 | uint32_t transport_frame_id() const { return timestamp(); } |
| 75 | |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 76 | // Set capture ntp time in milliseconds. |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 77 | void set_ntp_time_ms(int64_t ntp_time_ms) { |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 78 | ntp_time_ms_ = ntp_time_ms; |
| 79 | } |
| 80 | |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 81 | // Get capture ntp time in milliseconds. |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 82 | int64_t ntp_time_ms() const { return ntp_time_ms_; } |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 83 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 84 | // Naming convention for Coordination of Video Orientation. Please see |
| 85 | // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf |
| 86 | // |
| 87 | // "pending rotation" or "pending" = a frame that has a VideoRotation > 0. |
| 88 | // |
| 89 | // "not pending" = a frame that has a VideoRotation == 0. |
| 90 | // |
| 91 | // "apply rotation" = modify a frame from being "pending" to being "not |
| 92 | // pending" rotation (a no-op for "unrotated"). |
| 93 | // |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 94 | VideoRotation rotation() const { return rotation_; } |
| 95 | void set_rotation(VideoRotation rotation) { |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 96 | rotation_ = rotation; |
| 97 | } |
| 98 | |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 99 | // Set render time in milliseconds. |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 100 | void set_render_time_ms(int64_t render_time_ms) { |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 101 | set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec);; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 102 | } |
| 103 | |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 104 | // Get render time in milliseconds. |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 105 | int64_t render_time_ms() const { |
| 106 | return timestamp_us() / rtc::kNumMicrosecsPerMillisec; |
| 107 | } |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 108 | |
nisse | 6691070 | 2016-06-22 08:47:49 -0700 | [diff] [blame] | 109 | // Return true if and only if video_frame_buffer() is null. Which is possible |
| 110 | // only if the object was default-constructed. |
| 111 | // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and |
| 112 | // webrtc::VideoFrame merge. The intention is that video_frame_buffer() never |
| 113 | // should return nullptr. To handle potentially uninitialized or non-existent |
| 114 | // frames, consider using rtc::Optional. Otherwise, IsZeroSize() can be |
| 115 | // replaced by video_frame_buffer() == nullptr. |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 116 | bool IsZeroSize() const; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 117 | |
nisse | 26acec4 | 2016-04-15 03:43:39 -0700 | [diff] [blame] | 118 | // Return the underlying buffer. Never nullptr for a properly |
| 119 | // initialized VideoFrame. |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 120 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 121 | |
skvlad | 3abb764 | 2016-06-16 12:08:03 -0700 | [diff] [blame] | 122 | // Return true if the frame is stored in a texture. |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 123 | bool is_texture() const { |
skvlad | 3abb764 | 2016-06-16 12:08:03 -0700 | [diff] [blame] | 124 | return video_frame_buffer() && |
| 125 | video_frame_buffer()->native_handle() != nullptr; |
| 126 | } |
| 127 | |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 128 | private: |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 129 | // An opaque reference counted handle that stores the pixel data. |
| 130 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 131 | uint32_t timestamp_rtp_; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 132 | int64_t ntp_time_ms_; |
nisse | 74c10b5 | 2016-09-05 00:51:16 -0700 | [diff] [blame] | 133 | int64_t timestamp_us_; |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 134 | VideoRotation rotation_; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 137 | |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 138 | // TODO(pbos): Rename EncodedFrame and reformat this class' members. |
| 139 | class EncodedImage { |
| 140 | public: |
hbos | d664836 | 2016-01-21 05:43:11 -0800 | [diff] [blame] | 141 | static const size_t kBufferPaddingBytesH264; |
| 142 | |
| 143 | // Some decoders require encoded image buffers to be padded with a small |
| 144 | // number of additional bytes (due to over-reading byte readers). |
| 145 | static size_t GetBufferPaddingBytes(VideoCodecType codec_type); |
| 146 | |
pbos@webrtc.org | 4c8b930 | 2015-03-10 12:55:17 +0000 | [diff] [blame] | 147 | EncodedImage() : EncodedImage(nullptr, 0, 0) {} |
Per | ba7dc72 | 2016-04-19 15:01:23 +0200 | [diff] [blame] | 148 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 149 | EncodedImage(uint8_t* buffer, size_t length, size_t size) |
pbos@webrtc.org | 4c8b930 | 2015-03-10 12:55:17 +0000 | [diff] [blame] | 150 | : _buffer(buffer), _length(length), _size(size) {} |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 151 | |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 152 | struct AdaptReason { |
| 153 | AdaptReason() |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 154 | : quality_resolution_downscales(-1), |
| 155 | bw_resolutions_disabled(-1) {} |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 156 | |
| 157 | int quality_resolution_downscales; // Number of times this frame is down |
| 158 | // scaled in resolution due to quality. |
| 159 | // Or -1 if information is not provided. |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 160 | int bw_resolutions_disabled; // Number of resolutions that are not sent |
| 161 | // due to bandwidth for this frame. |
| 162 | // Or -1 if information is not provided. |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 163 | }; |
pbos@webrtc.org | 4c8b930 | 2015-03-10 12:55:17 +0000 | [diff] [blame] | 164 | uint32_t _encodedWidth = 0; |
| 165 | uint32_t _encodedHeight = 0; |
| 166 | uint32_t _timeStamp = 0; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 167 | // NTP time of the capture time in local timebase in milliseconds. |
pbos@webrtc.org | 4c8b930 | 2015-03-10 12:55:17 +0000 | [diff] [blame] | 168 | int64_t ntp_time_ms_ = 0; |
| 169 | int64_t capture_time_ms_ = 0; |
Peter Boström | 49e196a | 2015-10-23 15:58:18 +0200 | [diff] [blame] | 170 | FrameType _frameType = kVideoFrameDelta; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 171 | uint8_t* _buffer; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 172 | size_t _length; |
| 173 | size_t _size; |
Per | ba7dc72 | 2016-04-19 15:01:23 +0200 | [diff] [blame] | 174 | VideoRotation rotation_ = kVideoRotation_0; |
pbos@webrtc.org | 4c8b930 | 2015-03-10 12:55:17 +0000 | [diff] [blame] | 175 | bool _completeFrame = false; |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 176 | AdaptReason adapt_reason_; |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 177 | int qp_ = -1; // Quantizer value. |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 178 | |
| 179 | // When an application indicates non-zero values here, it is taken as an |
| 180 | // indication that all future frames will be constrained with those limits |
| 181 | // until the application indicates a change again. |
| 182 | PlayoutDelay playout_delay_ = {-1, -1}; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | } // namespace webrtc |
| 186 | #endif // WEBRTC_VIDEO_FRAME_H_ |