webrtc_m130/api/video/video_frame.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

220 lines
6.6 KiB
C++
Raw Normal View History

/*
* 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 <algorithm>
#include <utility>
#include "rtc_base/checks.h"
#include "rtc_base/time_utils.h"
namespace webrtc {
void VideoFrame::UpdateRect::Union(const UpdateRect& other) {
if (other.IsEmpty())
return;
if (IsEmpty()) {
*this = other;
return;
}
int right = std::max(offset_x + width, other.offset_x + other.width);
int bottom = std::max(offset_y + height, other.offset_y + other.height);
offset_x = std::min(offset_x, other.offset_x);
offset_y = std::min(offset_y, other.offset_y);
width = right - offset_x;
height = bottom - offset_y;
RTC_DCHECK_GT(width, 0);
RTC_DCHECK_GT(height, 0);
}
void VideoFrame::UpdateRect::Intersect(const UpdateRect& other) {
if (other.IsEmpty() || IsEmpty()) {
MakeEmptyUpdate();
return;
}
int right = std::min(offset_x + width, other.offset_x + other.width);
int bottom = std::min(offset_y + height, other.offset_y + other.height);
offset_x = std::max(offset_x, other.offset_x);
offset_y = std::max(offset_y, other.offset_y);
width = right - offset_x;
height = bottom - offset_y;
if (width <= 0 || height <= 0) {
MakeEmptyUpdate();
}
}
void VideoFrame::UpdateRect::MakeEmptyUpdate() {
width = height = offset_x = offset_y = 0;
}
bool VideoFrame::UpdateRect::IsEmpty() const {
return width == 0 && height == 0;
}
VideoFrame::Builder::Builder() = default;
VideoFrame::Builder::~Builder() = default;
VideoFrame VideoFrame::Builder::build() {
RTC_CHECK(video_frame_buffer_ != nullptr);
return VideoFrame(id_, video_frame_buffer_, timestamp_us_, timestamp_rtp_,
ntp_time_ms_, rotation_, color_space_, update_rect_,
packet_infos_);
}
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 absl::optional<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_update_rect(
const VideoFrame::UpdateRect& update_rect) {
update_rect_ = update_rect;
return *this;
}
VideoFrame::Builder& VideoFrame::Builder::set_packet_infos(
RtpPacketInfos packet_infos) {
packet_infos_ = std::move(packet_infos);
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),
update_rect_{0, 0, buffer->width(), buffer->height()} {}
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),
update_rect_{0, 0, buffer->width(), buffer->height()} {
RTC_DCHECK(buffer);
}
Revert "Reland "Partial frame capture API part 1"" This reverts commit 12e5d392cc8fc0ba7a04587c190daa4232e412bb. Reason for revert: Partial Capture API is not needed, according to new info from the Chrome team. Original change's description: > Reland "Partial frame capture API part 1" > > 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} TBR=ilnik@webrtc.org,nisse@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10152 Change-Id: I1c1dd51a8b5a09f743f212336beb01447f60f26e Reviewed-on: https://webrtc-review.googlesource.com/c/122092 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26638}
2019-02-11 13:35:03 +01:00
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<UpdateRect>& update_rect,
RtpPacketInfos packet_infos)
: 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),
update_rect_(update_rect.value_or(UpdateRect{
0, 0, video_frame_buffer_->width(), video_frame_buffer_->height()})),
packet_infos_(std::move(packet_infos)) {
RTC_DCHECK_GE(update_rect_.offset_x, 0);
RTC_DCHECK_GE(update_rect_.offset_y, 0);
RTC_DCHECK_LE(update_rect_.offset_x + update_rect_.width, width());
RTC_DCHECK_LE(update_rect_.offset_y + update_rect_.height, height());
}
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;
}
Reland of Drop frames until specified bitrate is achieved. (patchset #1 id:1 of https://codereview.webrtc.org/2666303002/ ) Reason for revert: Perf test broke as it made assumptions that quality scaling was turned off. This turns out not to be the case. Fixed by turning quality scaling off for the tests. Original issue's description: > Revert of Drop frames until specified bitrate is achieved. (patchset #12 id:240001 of https://codereview.webrtc.org/2630333002/ ) > > Reason for revert: > due to failures on perf tests (not on perf stats, but fails running due to dcheck failures), see e.g., https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20(K%20Nexus5) > > Original issue's description: > > Drop frames until specified bitrate is achieved. > > > > This CL fixes a regression introduced with the new quality scaler > > where the video would no longer start in a scaled mode. This CL adds > > code that compares incoming captured frames to the target bitrate, > > and if they are found to be too large, they are dropped and sinkWants > > set to a lower resolution. The number of dropped frames should be low > > (0-4 in most cases) and should not introduce a noticeable delay, or > > at least should be preferrable to having the first 2-4 seconds of video > > have very low quality. > > > > BUG=webrtc:6953 > > > > Review-Url: https://codereview.webrtc.org/2630333002 > > Cr-Commit-Position: refs/heads/master@{#16391} > > Committed: https://chromium.googlesource.com/external/webrtc/+/83399caec5762d2dad038b8e9d86163e92c18c9f > > TBR=perkj@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,kthelgason@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:6953 > > Review-Url: https://codereview.webrtc.org/2666303002 > Cr-Commit-Position: refs/heads/master@{#16395} > Committed: https://chromium.googlesource.com/external/webrtc/+/35fc2aa82fb5a562f3f76f2b91a55f05ebfd4874 TBR=perkj@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,minyue@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:6953 Review-Url: https://codereview.webrtc.org/2675223002 Cr-Commit-Position: refs/heads/master@{#16473}
2017-02-07 07:02:22 -08:00
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(
const rtc::scoped_refptr<VideoFrameBuffer>& buffer) {
RTC_CHECK(buffer);
video_frame_buffer_ = buffer;
}
int64_t VideoFrame::render_time_ms() const {
return timestamp_us() / rtc::kNumMicrosecsPerMillisec;
}
} // namespace webrtc