nisse | af91689 | 2017-01-10 07:44:26 -0800 | [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_API_VIDEO_VIDEO_FRAME_H_ |
| 12 | #define WEBRTC_API_VIDEO_VIDEO_FRAME_H_ |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | |
| 16 | #include "webrtc/api/video/video_rotation.h" |
| 17 | #include "webrtc/api/video/video_frame_buffer.h" |
| 18 | |
| 19 | // TODO(nisse): Transition hack, some downstream applications expect |
| 20 | // that including this file also defines base/timeutils.h constants. |
| 21 | // Delete after applications are fixed to include the right headers. |
| 22 | #include "webrtc/base/timeutils.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class VideoFrame { |
| 27 | public: |
| 28 | // TODO(nisse): This constructor is consistent with the now deleted |
| 29 | // cricket::WebRtcVideoFrame. We should consider whether or not we |
| 30 | // want to stick to this style and deprecate the other constructor. |
| 31 | VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 32 | webrtc::VideoRotation rotation, |
| 33 | int64_t timestamp_us); |
| 34 | |
| 35 | // Preferred constructor. |
| 36 | VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 37 | uint32_t timestamp, |
| 38 | int64_t render_time_ms, |
| 39 | VideoRotation rotation); |
| 40 | |
| 41 | ~VideoFrame(); |
| 42 | |
| 43 | // Support move and copy. |
| 44 | VideoFrame(const VideoFrame&); |
| 45 | VideoFrame(VideoFrame&&); |
| 46 | VideoFrame& operator=(const VideoFrame&); |
| 47 | VideoFrame& operator=(VideoFrame&&); |
| 48 | |
| 49 | // Get frame width. |
| 50 | int width() const; |
minyue | 35fc2aa | 2017-02-01 03:14:00 -0800 | [diff] [blame] | 51 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 52 | // Get frame height. |
| 53 | int height() const; |
| 54 | |
| 55 | // System monotonic clock, same timebase as rtc::TimeMicros(). |
| 56 | int64_t timestamp_us() const { return timestamp_us_; } |
| 57 | void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; } |
| 58 | |
| 59 | // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame |
| 60 | // merge, timestamps other than timestamp_us will likely be |
| 61 | // deprecated. |
| 62 | |
| 63 | // Set frame timestamp (90kHz). |
| 64 | void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } |
| 65 | |
| 66 | // Get frame timestamp (90kHz). |
| 67 | uint32_t timestamp() const { return timestamp_rtp_; } |
| 68 | |
| 69 | // For now, transport_frame_id and rtp timestamp are the same. |
| 70 | // TODO(nisse): Must be handled differently for QUIC. |
| 71 | uint32_t transport_frame_id() const { return timestamp(); } |
| 72 | |
| 73 | // Set capture ntp time in milliseconds. |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 74 | // TODO(nisse): Deprecated. Migrate all users to timestamp_us(). |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 75 | void set_ntp_time_ms(int64_t ntp_time_ms) { ntp_time_ms_ = ntp_time_ms; } |
| 76 | |
| 77 | // Get capture ntp time in milliseconds. |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 78 | // TODO(nisse): Deprecated. Migrate all users to timestamp_us(). |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 79 | int64_t ntp_time_ms() const { return ntp_time_ms_; } |
| 80 | |
| 81 | // Naming convention for Coordination of Video Orientation. Please see |
| 82 | // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf |
| 83 | // |
| 84 | // "pending rotation" or "pending" = a frame that has a VideoRotation > 0. |
| 85 | // |
| 86 | // "not pending" = a frame that has a VideoRotation == 0. |
| 87 | // |
| 88 | // "apply rotation" = modify a frame from being "pending" to being "not |
| 89 | // pending" rotation (a no-op for "unrotated"). |
| 90 | // |
| 91 | VideoRotation rotation() const { return rotation_; } |
| 92 | void set_rotation(VideoRotation rotation) { rotation_ = rotation; } |
| 93 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 94 | // Get render time in milliseconds. |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 95 | // TODO(nisse): Deprecated. Migrate all users to timestamp_us(). |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 96 | int64_t render_time_ms() const; |
| 97 | |
| 98 | // Return the underlying buffer. Never nullptr for a properly |
| 99 | // initialized VideoFrame. |
| 100 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; |
| 101 | |
| 102 | // TODO(nisse): Deprecated. |
| 103 | // Return true if the frame is stored in a texture. |
| 104 | bool is_texture() const { |
| 105 | return video_frame_buffer()->native_handle() != nullptr; |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | // An opaque reference counted handle that stores the pixel data. |
| 110 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; |
| 111 | uint32_t timestamp_rtp_; |
| 112 | int64_t ntp_time_ms_; |
| 113 | int64_t timestamp_us_; |
| 114 | VideoRotation rotation_; |
| 115 | }; |
| 116 | |
| 117 | } // namespace webrtc |
| 118 | |
| 119 | #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_H_ |