nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | #include "api/video/video_frame.h" |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "rtc_base/checks.h" |
| 14 | #include "rtc_base/timeutils.h" |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
Emircan Uysaler | 800787f | 2018-07-16 10:01:49 -0700 | [diff] [blame] | 18 | VideoFrame::Builder::Builder() = default; |
| 19 | |
| 20 | VideoFrame::Builder::~Builder() = default; |
| 21 | |
| 22 | VideoFrame VideoFrame::Builder::build() { |
| 23 | return VideoFrame(video_frame_buffer_, timestamp_us_, timestamp_rtp_, |
Johannes Kron | 4749e4e | 2018-11-21 10:18:18 +0100 | [diff] [blame^] | 24 | ntp_time_ms_, rotation_, color_space_); |
Emircan Uysaler | 800787f | 2018-07-16 10:01:49 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | VideoFrame::Builder& VideoFrame::Builder::set_video_frame_buffer( |
| 28 | const rtc::scoped_refptr<VideoFrameBuffer>& buffer) { |
| 29 | video_frame_buffer_ = buffer; |
| 30 | return *this; |
| 31 | } |
| 32 | |
| 33 | VideoFrame::Builder& VideoFrame::Builder::set_timestamp_ms( |
| 34 | int64_t timestamp_ms) { |
| 35 | timestamp_us_ = timestamp_ms * rtc::kNumMicrosecsPerMillisec; |
| 36 | return *this; |
| 37 | } |
| 38 | |
| 39 | VideoFrame::Builder& VideoFrame::Builder::set_timestamp_us( |
| 40 | int64_t timestamp_us) { |
| 41 | timestamp_us_ = timestamp_us; |
| 42 | return *this; |
| 43 | } |
| 44 | |
| 45 | VideoFrame::Builder& VideoFrame::Builder::set_timestamp_rtp( |
| 46 | uint32_t timestamp_rtp) { |
| 47 | timestamp_rtp_ = timestamp_rtp; |
| 48 | return *this; |
| 49 | } |
| 50 | |
| 51 | VideoFrame::Builder& VideoFrame::Builder::set_ntp_time_ms(int64_t ntp_time_ms) { |
| 52 | ntp_time_ms_ = ntp_time_ms; |
| 53 | return *this; |
| 54 | } |
| 55 | |
| 56 | VideoFrame::Builder& VideoFrame::Builder::set_rotation(VideoRotation rotation) { |
| 57 | rotation_ = rotation; |
| 58 | return *this; |
| 59 | } |
| 60 | |
| 61 | VideoFrame::Builder& VideoFrame::Builder::set_color_space( |
| 62 | const ColorSpace& color_space) { |
| 63 | color_space_ = color_space; |
| 64 | return *this; |
| 65 | } |
| 66 | |
Johannes Kron | 4749e4e | 2018-11-21 10:18:18 +0100 | [diff] [blame^] | 67 | VideoFrame::Builder& VideoFrame::Builder::set_color_space( |
| 68 | const ColorSpace* color_space) { |
| 69 | color_space_ = |
| 70 | color_space ? absl::make_optional(*color_space) : absl::nullopt; |
Johannes Kron | fbf1683 | 2018-11-05 16:13:02 +0100 | [diff] [blame] | 71 | return *this; |
| 72 | } |
| 73 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 74 | VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 75 | webrtc::VideoRotation rotation, |
| 76 | int64_t timestamp_us) |
| 77 | : video_frame_buffer_(buffer), |
| 78 | timestamp_rtp_(0), |
| 79 | ntp_time_ms_(0), |
| 80 | timestamp_us_(timestamp_us), |
| 81 | rotation_(rotation) {} |
| 82 | |
| 83 | VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
Niels Möller | 2ac6446 | 2018-06-11 11:14:32 +0200 | [diff] [blame] | 84 | uint32_t timestamp_rtp, |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 85 | int64_t render_time_ms, |
| 86 | VideoRotation rotation) |
| 87 | : video_frame_buffer_(buffer), |
Niels Möller | 2ac6446 | 2018-06-11 11:14:32 +0200 | [diff] [blame] | 88 | timestamp_rtp_(timestamp_rtp), |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 89 | ntp_time_ms_(0), |
| 90 | timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), |
| 91 | rotation_(rotation) { |
| 92 | RTC_DCHECK(buffer); |
| 93 | } |
| 94 | |
Emircan Uysaler | 800787f | 2018-07-16 10:01:49 -0700 | [diff] [blame] | 95 | VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 96 | int64_t timestamp_us, |
| 97 | uint32_t timestamp_rtp, |
| 98 | int64_t ntp_time_ms, |
| 99 | VideoRotation rotation, |
Johannes Kron | 4749e4e | 2018-11-21 10:18:18 +0100 | [diff] [blame^] | 100 | const absl::optional<ColorSpace>& color_space) |
Emircan Uysaler | 800787f | 2018-07-16 10:01:49 -0700 | [diff] [blame] | 101 | : video_frame_buffer_(buffer), |
| 102 | timestamp_rtp_(timestamp_rtp), |
| 103 | ntp_time_ms_(ntp_time_ms), |
| 104 | timestamp_us_(timestamp_us), |
| 105 | rotation_(rotation), |
Johannes Kron | 4749e4e | 2018-11-21 10:18:18 +0100 | [diff] [blame^] | 106 | color_space_(color_space) {} |
Emircan Uysaler | 800787f | 2018-07-16 10:01:49 -0700 | [diff] [blame] | 107 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 108 | VideoFrame::~VideoFrame() = default; |
| 109 | |
| 110 | VideoFrame::VideoFrame(const VideoFrame&) = default; |
| 111 | VideoFrame::VideoFrame(VideoFrame&&) = default; |
| 112 | VideoFrame& VideoFrame::operator=(const VideoFrame&) = default; |
| 113 | VideoFrame& VideoFrame::operator=(VideoFrame&&) = default; |
| 114 | |
| 115 | int VideoFrame::width() const { |
| 116 | return video_frame_buffer_ ? video_frame_buffer_->width() : 0; |
| 117 | } |
| 118 | |
| 119 | int VideoFrame::height() const { |
| 120 | return video_frame_buffer_ ? video_frame_buffer_->height() : 0; |
| 121 | } |
| 122 | |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 123 | uint32_t VideoFrame::size() const { |
| 124 | return width() * height(); |
| 125 | } |
| 126 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 127 | rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const { |
| 128 | return video_frame_buffer_; |
| 129 | } |
| 130 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 131 | int64_t VideoFrame::render_time_ms() const { |
| 132 | return timestamp_us() / rtc::kNumMicrosecsPerMillisec; |
| 133 | } |
| 134 | |
| 135 | } // namespace webrtc |