Chromium Code Reviews| 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 |
|
the sun
2016/11/24 10:36:59
nit: add stdint.h
nisse-webrtc
2016/11/25 08:58:02
Done. (It was indirectly included, via video_frame
| |
| 14 #include "webrtc/base/scoped_ref_ptr.h" | 14 #include "webrtc/api/video/rotation.h" |
| 15 #include "webrtc/base/timeutils.h" | 15 |
| 16 #include "webrtc/common_types.h" | 16 // TODO(nisse): Including the abstract interface here makes more sense |
| 17 #include "webrtc/common_video/include/video_frame_buffer.h" | 17 // than forward declaring it. Right? |
|
the sun
2016/11/24 10:36:59
Agree.
nisse-webrtc
2016/11/25 08:58:02
Good. TODO comment deleted.
| |
| 18 #include "webrtc/common_video/rotation.h" | 18 #include "webrtc/api/video/video_frame_buffer.h" |
| 19 #include "webrtc/typedefs.h" | |
| 20 | 19 |
| 21 namespace webrtc { | 20 namespace webrtc { |
| 22 | 21 |
| 23 class VideoFrame { | 22 class VideoFrame { |
| 24 public: | 23 public: |
| 25 // TODO(nisse): Deprecated. Using the default constructor violates the | 24 // TODO(nisse): Deprecated. Using the default constructor violates the |
| 26 // reasonable assumption that video_frame_buffer() returns a valid buffer. | 25 // reasonable assumption that video_frame_buffer() returns a valid buffer. |
| 27 VideoFrame(); | 26 VideoFrame(); |
| 28 | 27 |
| 29 // TODO(nisse): This constructor is consistent with | 28 // TODO(nisse): This constructor is consistent with |
| 30 // cricket::WebRtcVideoFrame. After the class | 29 // cricket::WebRtcVideoFrame. After the class |
| 31 // cricket::WebRtcVideoFrame and its baseclass cricket::VideoFrame | 30 // cricket::WebRtcVideoFrame and its baseclass cricket::VideoFrame |
| 32 // are deleted, we should consider whether or not we want to stick | 31 // are deleted, we should consider whether or not we want to stick |
| 33 // to this style and deprecate the other constructors. | 32 // to this style and deprecate the other constructors. |
| 34 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 33 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 35 webrtc::VideoRotation rotation, | 34 webrtc::VideoRotation rotation, |
| 36 int64_t timestamp_us); | 35 int64_t timestamp_us); |
| 37 | 36 |
| 38 // Preferred constructor. | 37 // Preferred constructor. |
| 39 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 38 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 40 uint32_t timestamp, | 39 uint32_t timestamp, |
| 41 int64_t render_time_ms, | 40 int64_t render_time_ms, |
| 42 VideoRotation rotation); | 41 VideoRotation rotation); |
| 43 | 42 |
| 43 ~VideoFrame(); | |
| 44 | |
| 44 // Support move and copy. | 45 // Support move and copy. |
| 45 VideoFrame(const VideoFrame&) = default; | 46 VideoFrame(const VideoFrame&); |
| 46 VideoFrame(VideoFrame&&) = default; | 47 VideoFrame(VideoFrame&&); |
| 47 VideoFrame& operator=(const VideoFrame&) = default; | 48 VideoFrame& operator=(const VideoFrame&); |
| 48 VideoFrame& operator=(VideoFrame&&) = default; | 49 VideoFrame& operator=(VideoFrame&&); |
| 49 | 50 |
| 50 // Get frame width. | 51 // Get frame width. |
| 51 int width() const; | 52 int width() const; |
| 52 | 53 |
| 53 // Get frame height. | 54 // Get frame height. |
| 54 int height() const; | 55 int height() const; |
| 55 | 56 |
| 56 // System monotonic clock, same timebase as rtc::TimeMicros(). | 57 // System monotonic clock, same timebase as rtc::TimeMicros(). |
| 57 int64_t timestamp_us() const { return timestamp_us_; } | 58 int64_t timestamp_us() const { return timestamp_us_; } |
| 58 void set_timestamp_us(int64_t timestamp_us) { | 59 void set_timestamp_us(int64_t timestamp_us) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 // | 91 // |
| 91 // "apply rotation" = modify a frame from being "pending" to being "not | 92 // "apply rotation" = modify a frame from being "pending" to being "not |
| 92 // pending" rotation (a no-op for "unrotated"). | 93 // pending" rotation (a no-op for "unrotated"). |
| 93 // | 94 // |
| 94 VideoRotation rotation() const { return rotation_; } | 95 VideoRotation rotation() const { return rotation_; } |
| 95 void set_rotation(VideoRotation rotation) { | 96 void set_rotation(VideoRotation rotation) { |
| 96 rotation_ = rotation; | 97 rotation_ = rotation; |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Set render time in milliseconds. | 100 // Set render time in milliseconds. |
| 100 void set_render_time_ms(int64_t render_time_ms) { | 101 void set_render_time_ms(int64_t render_time_ms); |
| 101 set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec);; | |
| 102 } | |
| 103 | 102 |
| 104 // Get render time in milliseconds. | 103 // Get render time in milliseconds. |
| 105 int64_t render_time_ms() const { | 104 int64_t render_time_ms() const; |
| 106 return timestamp_us() / rtc::kNumMicrosecsPerMillisec; | |
| 107 } | |
| 108 | 105 |
| 109 // Return true if and only if video_frame_buffer() is null. Which is possible | 106 // Return true if and only if video_frame_buffer() is null. Which is possible |
| 110 // only if the object was default-constructed. | 107 // only if the object was default-constructed. |
| 111 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and | 108 // TODO(nisse): Deprecated. Should be deleted in the cricket::VideoFrame and |
| 112 // webrtc::VideoFrame merge. The intention is that video_frame_buffer() never | 109 // webrtc::VideoFrame merge. The intention is that video_frame_buffer() never |
| 113 // should return nullptr. To handle potentially uninitialized or non-existent | 110 // should return nullptr. To handle potentially uninitialized or non-existent |
| 114 // frames, consider using rtc::Optional. Otherwise, IsZeroSize() can be | 111 // frames, consider using rtc::Optional. Otherwise, IsZeroSize() can be |
| 115 // replaced by video_frame_buffer() == nullptr. | 112 // replaced by video_frame_buffer() == nullptr. |
| 116 bool IsZeroSize() const; | 113 bool IsZeroSize() const; |
| 117 | 114 |
| 118 // Return the underlying buffer. Never nullptr for a properly | 115 // Return the underlying buffer. Never nullptr for a properly |
| 119 // initialized VideoFrame. | 116 // initialized VideoFrame. |
| 120 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; | 117 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; |
| 121 | 118 |
| 122 // Return true if the frame is stored in a texture. | 119 // Return true if the frame is stored in a texture. |
| 123 bool is_texture() const { | 120 bool is_texture() const { |
| 124 return video_frame_buffer() && | 121 return video_frame_buffer() && |
| 125 video_frame_buffer()->native_handle() != nullptr; | 122 video_frame_buffer()->native_handle() != nullptr; |
| 126 } | 123 } |
| 127 | 124 |
| 128 private: | 125 private: |
| 129 // An opaque reference counted handle that stores the pixel data. | 126 // An opaque reference counted handle that stores the pixel data. |
| 130 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | 127 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; |
| 131 uint32_t timestamp_rtp_; | 128 uint32_t timestamp_rtp_; |
| 132 int64_t ntp_time_ms_; | 129 int64_t ntp_time_ms_; |
| 133 int64_t timestamp_us_; | 130 int64_t timestamp_us_; |
| 134 VideoRotation rotation_; | 131 VideoRotation rotation_; |
| 135 }; | 132 }; |
| 136 | 133 |
| 134 } // namespace webrtc | |
| 137 | 135 |
| 138 // TODO(pbos): Rename EncodedFrame and reformat this class' members. | 136 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_H_ |
| 139 class EncodedImage { | |
| 140 public: | |
| 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 | |
| 147 EncodedImage() : EncodedImage(nullptr, 0, 0) {} | |
| 148 | |
| 149 EncodedImage(uint8_t* buffer, size_t length, size_t size) | |
| 150 : _buffer(buffer), _length(length), _size(size) {} | |
| 151 | |
| 152 struct AdaptReason { | |
| 153 AdaptReason() | |
| 154 : quality_resolution_downscales(-1), | |
| 155 bw_resolutions_disabled(-1) {} | |
| 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. | |
| 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. | |
| 163 }; | |
| 164 uint32_t _encodedWidth = 0; | |
| 165 uint32_t _encodedHeight = 0; | |
| 166 uint32_t _timeStamp = 0; | |
| 167 // NTP time of the capture time in local timebase in milliseconds. | |
| 168 int64_t ntp_time_ms_ = 0; | |
| 169 int64_t capture_time_ms_ = 0; | |
| 170 FrameType _frameType = kVideoFrameDelta; | |
| 171 uint8_t* _buffer; | |
| 172 size_t _length; | |
| 173 size_t _size; | |
| 174 VideoRotation rotation_ = kVideoRotation_0; | |
| 175 bool _completeFrame = false; | |
| 176 AdaptReason adapt_reason_; | |
| 177 int qp_ = -1; // Quantizer value. | |
| 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}; | |
| 183 }; | |
| 184 | |
| 185 } // namespace webrtc | |
| 186 #endif // WEBRTC_VIDEO_FRAME_H_ | |
| OLD | NEW |