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