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_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/api/video/video_frame.h" |
| 15 #include "webrtc/base/timeutils.h" | 15 |
| 16 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" |
| 17 #include "webrtc/common_video/include/video_frame_buffer.h" | |
| 18 #include "webrtc/common_video/rotation.h" | |
| 19 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
| 20 | 18 |
| 21 namespace webrtc { | 19 namespace webrtc { |
| 22 | 20 |
| 23 class VideoFrame { | |
| 24 public: | |
| 25 // TODO(nisse): Deprecated. Using the default constructor violates the | |
| 26 // reasonable assumption that video_frame_buffer() returns a valid buffer. | |
| 27 VideoFrame(); | |
| 28 | |
| 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 | |
| 38 // Preferred constructor. | |
| 39 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | |
| 40 uint32_t timestamp, | |
| 41 int64_t render_time_ms, | |
| 42 VideoRotation rotation); | |
| 43 | |
| 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; | |
| 49 | |
| 50 // Get frame width. | |
| 51 int width() const; | |
| 52 | |
| 53 // Get frame height. | |
| 54 int height() const; | |
| 55 | |
| 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 | |
| 62 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame | |
| 63 // merge, timestamps other than timestamp_us will likely be | |
| 64 // deprecated. | |
| 65 | |
| 66 // Set frame timestamp (90kHz). | |
| 67 void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } | |
| 68 | |
| 69 // Get frame timestamp (90kHz). | |
| 70 uint32_t timestamp() const { return timestamp_rtp_; } | |
| 71 | |
| 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 | |
| 76 // Set capture ntp time in milliseconds. | |
| 77 void set_ntp_time_ms(int64_t ntp_time_ms) { | |
| 78 ntp_time_ms_ = ntp_time_ms; | |
| 79 } | |
| 80 | |
| 81 // Get capture ntp time in milliseconds. | |
| 82 int64_t ntp_time_ms() const { return ntp_time_ms_; } | |
| 83 | |
| 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_126 114v120700p.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 // | |
| 94 VideoRotation rotation() const { return rotation_; } | |
| 95 void set_rotation(VideoRotation rotation) { | |
| 96 rotation_ = rotation; | |
| 97 } | |
| 98 | |
| 99 // Set render time in milliseconds. | |
| 100 void set_render_time_ms(int64_t render_time_ms) { | |
| 101 set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec);; | |
| 102 } | |
| 103 | |
| 104 // Get render time in milliseconds. | |
| 105 int64_t render_time_ms() const { | |
| 106 return timestamp_us() / rtc::kNumMicrosecsPerMillisec; | |
| 107 } | |
| 108 | |
| 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. | |
| 116 bool IsZeroSize() const; | |
| 117 | |
| 118 // Return the underlying buffer. Never nullptr for a properly | |
| 119 // initialized VideoFrame. | |
| 120 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; | |
| 121 | |
| 122 // Return true if the frame is stored in a texture. | |
| 123 bool is_texture() const { | |
| 124 return video_frame_buffer() && | |
| 125 video_frame_buffer()->native_handle() != nullptr; | |
| 126 } | |
| 127 | |
| 128 private: | |
| 129 // An opaque reference counted handle that stores the pixel data. | |
| 130 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | |
| 131 uint32_t timestamp_rtp_; | |
| 132 int64_t ntp_time_ms_; | |
| 133 int64_t timestamp_us_; | |
| 134 VideoRotation rotation_; | |
| 135 }; | |
| 136 | |
| 137 | |
| 138 // TODO(pbos): Rename EncodedFrame and reformat this class' members. | 21 // TODO(pbos): Rename EncodedFrame and reformat this class' members. |
| 139 class EncodedImage { | 22 class EncodedImage { |
|
the sun
2016/11/24 10:36:59
This also need to be in api/? Did you intend to mo
nisse-webrtc
2016/11/25 08:58:03
For now, I intend to move only interfaces related
| |
| 140 public: | 23 public: |
| 141 static const size_t kBufferPaddingBytesH264; | 24 static const size_t kBufferPaddingBytesH264; |
| 142 | 25 |
| 143 // Some decoders require encoded image buffers to be padded with a small | 26 // Some decoders require encoded image buffers to be padded with a small |
| 144 // number of additional bytes (due to over-reading byte readers). | 27 // number of additional bytes (due to over-reading byte readers). |
| 145 static size_t GetBufferPaddingBytes(VideoCodecType codec_type); | 28 static size_t GetBufferPaddingBytes(VideoCodecType codec_type); |
| 146 | 29 |
| 147 EncodedImage() : EncodedImage(nullptr, 0, 0) {} | 30 EncodedImage() : EncodedImage(nullptr, 0, 0) {} |
| 148 | 31 |
| 149 EncodedImage(uint8_t* buffer, size_t length, size_t size) | 32 EncodedImage(uint8_t* buffer, size_t length, size_t size) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 177 int qp_ = -1; // Quantizer value. | 60 int qp_ = -1; // Quantizer value. |
| 178 | 61 |
| 179 // When an application indicates non-zero values here, it is taken as an | 62 // 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 | 63 // indication that all future frames will be constrained with those limits |
| 181 // until the application indicates a change again. | 64 // until the application indicates a change again. |
| 182 PlayoutDelay playout_delay_ = {-1, -1}; | 65 PlayoutDelay playout_delay_ = {-1, -1}; |
| 183 }; | 66 }; |
| 184 | 67 |
| 185 } // namespace webrtc | 68 } // namespace webrtc |
| 186 #endif // WEBRTC_VIDEO_FRAME_H_ | 69 #endif // WEBRTC_VIDEO_FRAME_H_ |
| OLD | NEW |