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