blob: 5521ad8a587441223743c2f9a8c91d43590050d9 [file] [log] [blame]
nisseaf916892017-01-10 07:44:26 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "api/video/video_frame.h"
nisseaf916892017-01-10 07:44:26 -080012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/checks.h"
14#include "rtc_base/timeutils.h"
nisseaf916892017-01-10 07:44:26 -080015
16namespace webrtc {
17
Emircan Uysaler800787f2018-07-16 10:01:49 -070018VideoFrame::Builder::Builder() = default;
19
20VideoFrame::Builder::~Builder() = default;
21
22VideoFrame VideoFrame::Builder::build() {
23 return VideoFrame(video_frame_buffer_, timestamp_us_, timestamp_rtp_,
24 ntp_time_ms_, rotation_, color_space_);
25}
26
27VideoFrame::Builder& VideoFrame::Builder::set_video_frame_buffer(
28 const rtc::scoped_refptr<VideoFrameBuffer>& buffer) {
29 video_frame_buffer_ = buffer;
30 return *this;
31}
32
33VideoFrame::Builder& VideoFrame::Builder::set_timestamp_ms(
34 int64_t timestamp_ms) {
35 timestamp_us_ = timestamp_ms * rtc::kNumMicrosecsPerMillisec;
36 return *this;
37}
38
39VideoFrame::Builder& VideoFrame::Builder::set_timestamp_us(
40 int64_t timestamp_us) {
41 timestamp_us_ = timestamp_us;
42 return *this;
43}
44
45VideoFrame::Builder& VideoFrame::Builder::set_timestamp_rtp(
46 uint32_t timestamp_rtp) {
47 timestamp_rtp_ = timestamp_rtp;
48 return *this;
49}
50
51VideoFrame::Builder& VideoFrame::Builder::set_ntp_time_ms(int64_t ntp_time_ms) {
52 ntp_time_ms_ = ntp_time_ms;
53 return *this;
54}
55
56VideoFrame::Builder& VideoFrame::Builder::set_rotation(VideoRotation rotation) {
57 rotation_ = rotation;
58 return *this;
59}
60
61VideoFrame::Builder& VideoFrame::Builder::set_color_space(
62 const ColorSpace& color_space) {
63 color_space_ = color_space;
64 return *this;
65}
66
nisseaf916892017-01-10 07:44:26 -080067VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
68 webrtc::VideoRotation rotation,
69 int64_t timestamp_us)
70 : video_frame_buffer_(buffer),
71 timestamp_rtp_(0),
72 ntp_time_ms_(0),
73 timestamp_us_(timestamp_us),
74 rotation_(rotation) {}
75
76VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
Niels Möller2ac64462018-06-11 11:14:32 +020077 uint32_t timestamp_rtp,
nisseaf916892017-01-10 07:44:26 -080078 int64_t render_time_ms,
79 VideoRotation rotation)
80 : video_frame_buffer_(buffer),
Niels Möller2ac64462018-06-11 11:14:32 +020081 timestamp_rtp_(timestamp_rtp),
nisseaf916892017-01-10 07:44:26 -080082 ntp_time_ms_(0),
83 timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec),
84 rotation_(rotation) {
85 RTC_DCHECK(buffer);
86}
87
Emircan Uysaler800787f2018-07-16 10:01:49 -070088VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
89 int64_t timestamp_us,
90 uint32_t timestamp_rtp,
91 int64_t ntp_time_ms,
92 VideoRotation rotation,
93 const absl::optional<ColorSpace>& color_space)
94 : video_frame_buffer_(buffer),
95 timestamp_rtp_(timestamp_rtp),
96 ntp_time_ms_(ntp_time_ms),
97 timestamp_us_(timestamp_us),
98 rotation_(rotation),
99 color_space_(color_space) {}
100
nisseaf916892017-01-10 07:44:26 -0800101VideoFrame::~VideoFrame() = default;
102
103VideoFrame::VideoFrame(const VideoFrame&) = default;
104VideoFrame::VideoFrame(VideoFrame&&) = default;
105VideoFrame& VideoFrame::operator=(const VideoFrame&) = default;
106VideoFrame& VideoFrame::operator=(VideoFrame&&) = default;
107
108int VideoFrame::width() const {
109 return video_frame_buffer_ ? video_frame_buffer_->width() : 0;
110}
111
112int VideoFrame::height() const {
113 return video_frame_buffer_ ? video_frame_buffer_->height() : 0;
114}
115
kthelgason2bc68642017-02-07 07:02:22 -0800116uint32_t VideoFrame::size() const {
117 return width() * height();
118}
119
nisseaf916892017-01-10 07:44:26 -0800120rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const {
121 return video_frame_buffer_;
122}
123
nisseaf916892017-01-10 07:44:26 -0800124int64_t VideoFrame::render_time_ms() const {
125 return timestamp_us() / rtc::kNumMicrosecsPerMillisec;
126}
127
128} // namespace webrtc