nisse | af91689 | 2017-01-10 15:44:26 | [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 04:47:31 | [diff] [blame] | 11 | #include "api/video/video_frame.h" |
nisse | af91689 | 2017-01-10 15:44:26 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 13 | #include "rtc_base/checks.h" |
| 14 | #include "rtc_base/timeutils.h" |
nisse | af91689 | 2017-01-10 15:44:26 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 19 | webrtc::VideoRotation rotation, |
| 20 | int64_t timestamp_us) |
| 21 | : video_frame_buffer_(buffer), |
| 22 | timestamp_rtp_(0), |
| 23 | ntp_time_ms_(0), |
| 24 | timestamp_us_(timestamp_us), |
| 25 | rotation_(rotation) {} |
| 26 | |
| 27 | VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
Niels Möller | 2ac6446 | 2018-06-11 09:14:32 | [diff] [blame] | 28 | uint32_t timestamp_rtp, |
nisse | af91689 | 2017-01-10 15:44:26 | [diff] [blame] | 29 | int64_t render_time_ms, |
| 30 | VideoRotation rotation) |
| 31 | : video_frame_buffer_(buffer), |
Niels Möller | 2ac6446 | 2018-06-11 09:14:32 | [diff] [blame] | 32 | timestamp_rtp_(timestamp_rtp), |
nisse | af91689 | 2017-01-10 15:44:26 | [diff] [blame] | 33 | ntp_time_ms_(0), |
| 34 | timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), |
| 35 | rotation_(rotation) { |
| 36 | RTC_DCHECK(buffer); |
| 37 | } |
| 38 | |
| 39 | VideoFrame::~VideoFrame() = default; |
| 40 | |
| 41 | VideoFrame::VideoFrame(const VideoFrame&) = default; |
| 42 | VideoFrame::VideoFrame(VideoFrame&&) = default; |
| 43 | VideoFrame& VideoFrame::operator=(const VideoFrame&) = default; |
| 44 | VideoFrame& VideoFrame::operator=(VideoFrame&&) = default; |
| 45 | |
| 46 | int VideoFrame::width() const { |
| 47 | return video_frame_buffer_ ? video_frame_buffer_->width() : 0; |
| 48 | } |
| 49 | |
| 50 | int VideoFrame::height() const { |
| 51 | return video_frame_buffer_ ? video_frame_buffer_->height() : 0; |
| 52 | } |
| 53 | |
kthelgason | 2bc6864 | 2017-02-07 15:02:22 | [diff] [blame] | 54 | uint32_t VideoFrame::size() const { |
| 55 | return width() * height(); |
| 56 | } |
| 57 | |
nisse | af91689 | 2017-01-10 15:44:26 | [diff] [blame] | 58 | rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const { |
| 59 | return video_frame_buffer_; |
| 60 | } |
| 61 | |
nisse | af91689 | 2017-01-10 15:44:26 | [diff] [blame] | 62 | int64_t VideoFrame::render_time_ms() const { |
| 63 | return timestamp_us() / rtc::kNumMicrosecsPerMillisec; |
| 64 | } |
| 65 | |
| 66 | } // namespace webrtc |