Reland with fixes to undefined behavior. Define new optional struct in VideoFrame to signal that the frame is a changed part of a whole picture and add a flag to signal that partial update may be issued by the VideoFrame source. Also, fix too strict assumptions in FrameBuffers PasteFrom methods. Also, add ability to set a new buffer in video frame. Original Reviewed-on: https://webrtc-review.googlesource.com/c/120405 Bug: webrtc:10152 Change-Id: I85790dfc7cec2f23abfe9d6cd18dc76a0c343bc0 Reviewed-on: https://webrtc-review.googlesource.com/c/120780 Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26493}
168 lines
4.9 KiB
C++
168 lines
4.9 KiB
C++
/*
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "api/video/video_frame.h"
|
|
|
|
#include "rtc_base/checks.h"
|
|
#include "rtc_base/time_utils.h"
|
|
|
|
namespace webrtc {
|
|
|
|
VideoFrame::Builder::Builder() = default;
|
|
|
|
VideoFrame::Builder::~Builder() = default;
|
|
|
|
VideoFrame VideoFrame::Builder::build() {
|
|
return VideoFrame(id_, video_frame_buffer_, timestamp_us_, timestamp_rtp_,
|
|
ntp_time_ms_, rotation_, color_space_,
|
|
partial_frame_description_,
|
|
cache_buffer_for_partial_updates_);
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_video_frame_buffer(
|
|
const rtc::scoped_refptr<VideoFrameBuffer>& buffer) {
|
|
video_frame_buffer_ = buffer;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_timestamp_ms(
|
|
int64_t timestamp_ms) {
|
|
timestamp_us_ = timestamp_ms * rtc::kNumMicrosecsPerMillisec;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_timestamp_us(
|
|
int64_t timestamp_us) {
|
|
timestamp_us_ = timestamp_us;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_timestamp_rtp(
|
|
uint32_t timestamp_rtp) {
|
|
timestamp_rtp_ = timestamp_rtp;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_ntp_time_ms(int64_t ntp_time_ms) {
|
|
ntp_time_ms_ = ntp_time_ms;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_rotation(VideoRotation rotation) {
|
|
rotation_ = rotation;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_color_space(
|
|
const ColorSpace& color_space) {
|
|
color_space_ = color_space;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_color_space(
|
|
const ColorSpace* color_space) {
|
|
color_space_ =
|
|
color_space ? absl::make_optional(*color_space) : absl::nullopt;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_id(uint16_t id) {
|
|
id_ = id;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_partial_frame_description(
|
|
const absl::optional<PartialFrameDescription>& description) {
|
|
partial_frame_description_ = description;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::Builder& VideoFrame::Builder::set_cache_buffer_for_partial_updates(
|
|
bool cache_buffer_for_partial_updates) {
|
|
cache_buffer_for_partial_updates_ = cache_buffer_for_partial_updates;
|
|
return *this;
|
|
}
|
|
|
|
VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
|
|
webrtc::VideoRotation rotation,
|
|
int64_t timestamp_us)
|
|
: video_frame_buffer_(buffer),
|
|
timestamp_rtp_(0),
|
|
ntp_time_ms_(0),
|
|
timestamp_us_(timestamp_us),
|
|
rotation_(rotation) {}
|
|
|
|
VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
|
|
uint32_t timestamp_rtp,
|
|
int64_t render_time_ms,
|
|
VideoRotation rotation)
|
|
: video_frame_buffer_(buffer),
|
|
timestamp_rtp_(timestamp_rtp),
|
|
ntp_time_ms_(0),
|
|
timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec),
|
|
rotation_(rotation) {
|
|
RTC_DCHECK(buffer);
|
|
}
|
|
|
|
VideoFrame::VideoFrame(
|
|
uint16_t id,
|
|
const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
|
|
int64_t timestamp_us,
|
|
uint32_t timestamp_rtp,
|
|
int64_t ntp_time_ms,
|
|
VideoRotation rotation,
|
|
const absl::optional<ColorSpace>& color_space,
|
|
const absl::optional<PartialFrameDescription> partial_frame_description,
|
|
bool cache_buffer_for_partial_updates)
|
|
: id_(id),
|
|
video_frame_buffer_(buffer),
|
|
timestamp_rtp_(timestamp_rtp),
|
|
ntp_time_ms_(ntp_time_ms),
|
|
timestamp_us_(timestamp_us),
|
|
rotation_(rotation),
|
|
color_space_(color_space),
|
|
partial_frame_description_(partial_frame_description),
|
|
cache_buffer_for_partial_updates_(cache_buffer_for_partial_updates) {}
|
|
|
|
VideoFrame::~VideoFrame() = default;
|
|
|
|
VideoFrame::VideoFrame(const VideoFrame&) = default;
|
|
VideoFrame::VideoFrame(VideoFrame&&) = default;
|
|
VideoFrame& VideoFrame::operator=(const VideoFrame&) = default;
|
|
VideoFrame& VideoFrame::operator=(VideoFrame&&) = default;
|
|
|
|
int VideoFrame::width() const {
|
|
return video_frame_buffer_ ? video_frame_buffer_->width() : 0;
|
|
}
|
|
|
|
int VideoFrame::height() const {
|
|
return video_frame_buffer_ ? video_frame_buffer_->height() : 0;
|
|
}
|
|
|
|
uint32_t VideoFrame::size() const {
|
|
return width() * height();
|
|
}
|
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const {
|
|
return video_frame_buffer_;
|
|
}
|
|
|
|
void VideoFrame::set_video_frame_buffer(
|
|
rtc::scoped_refptr<VideoFrameBuffer> buffer) {
|
|
RTC_CHECK(buffer.get());
|
|
video_frame_buffer_ = buffer;
|
|
}
|
|
|
|
int64_t VideoFrame::render_time_ms() const {
|
|
return timestamp_us() / rtc::kNumMicrosecsPerMillisec;
|
|
}
|
|
|
|
} // namespace webrtc
|