2016-09-22 01:25:59 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/adapted_video_track_source.h"
|
2016-09-22 01:25:59 -07:00
|
|
|
|
2019-01-25 20:26:48 +01:00
|
|
|
#include "api/scoped_refptr.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/i420_buffer.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/video/video_frame_buffer.h"
|
|
|
|
|
#include "api/video/video_rotation.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2017-01-10 07:44:26 -08:00
|
|
|
|
2016-09-22 01:25:59 -07:00
|
|
|
namespace rtc {
|
|
|
|
|
|
2019-01-31 13:23:46 +01:00
|
|
|
AdaptedVideoTrackSource::AdaptedVideoTrackSource() = default;
|
2016-09-22 01:25:59 -07:00
|
|
|
|
2016-12-08 08:04:51 -08:00
|
|
|
AdaptedVideoTrackSource::AdaptedVideoTrackSource(int required_alignment)
|
2019-01-31 13:23:46 +01:00
|
|
|
: video_adapter_(required_alignment) {}
|
|
|
|
|
|
2018-04-05 11:42:24 +02:00
|
|
|
AdaptedVideoTrackSource::~AdaptedVideoTrackSource() = default;
|
2016-12-08 08:04:51 -08:00
|
|
|
|
2016-09-22 01:25:59 -07:00
|
|
|
bool AdaptedVideoTrackSource::GetStats(Stats* stats) {
|
2020-07-07 15:43:11 +02:00
|
|
|
webrtc::MutexLock lock(&stats_mutex_);
|
2016-09-22 01:25:59 -07:00
|
|
|
|
|
|
|
|
if (!stats_) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*stats = *stats_;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
void AdaptedVideoTrackSource::OnFrame(const webrtc::VideoFrame& frame) {
|
2016-09-22 01:25:59 -07:00
|
|
|
rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer(
|
|
|
|
|
frame.video_frame_buffer());
|
|
|
|
|
/* Note that this is a "best effort" approach to
|
|
|
|
|
wants.rotation_applied; apply_rotation_ can change from false to
|
|
|
|
|
true between the check of apply_rotation() and the call to
|
|
|
|
|
broadcaster_.OnFrame(), in which case we generate a frame with
|
|
|
|
|
pending rotation despite some sink with wants.rotation_applied ==
|
|
|
|
|
true was just added. The VideoBroadcaster enforces
|
|
|
|
|
synchronization for us in this case, by not passing the frame on
|
|
|
|
|
to sinks which don't want it. */
|
2017-06-01 10:02:26 -07:00
|
|
|
if (apply_rotation() && frame.rotation() != webrtc::kVideoRotation_0 &&
|
|
|
|
|
buffer->type() == webrtc::VideoFrameBuffer::Type::kI420) {
|
2016-09-22 01:25:59 -07:00
|
|
|
/* Apply pending rotation. */
|
2019-06-05 15:59:12 +02:00
|
|
|
webrtc::VideoFrame rotated_frame(frame);
|
|
|
|
|
rotated_frame.set_video_frame_buffer(
|
|
|
|
|
webrtc::I420Buffer::Rotate(*buffer->GetI420(), frame.rotation()));
|
|
|
|
|
rotated_frame.set_rotation(webrtc::kVideoRotation_0);
|
2019-01-03 23:49:37 +01:00
|
|
|
broadcaster_.OnFrame(rotated_frame);
|
2016-09-22 01:25:59 -07:00
|
|
|
} else {
|
|
|
|
|
broadcaster_.OnFrame(frame);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AdaptedVideoTrackSource::AddOrUpdateSink(
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
|
2016-09-22 01:25:59 -07:00
|
|
|
const rtc::VideoSinkWants& wants) {
|
|
|
|
|
broadcaster_.AddOrUpdateSink(sink, wants);
|
|
|
|
|
OnSinkWantsChanged(broadcaster_.wants());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AdaptedVideoTrackSource::RemoveSink(
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) {
|
2016-09-22 01:25:59 -07:00
|
|
|
broadcaster_.RemoveSink(sink);
|
|
|
|
|
OnSinkWantsChanged(broadcaster_.wants());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AdaptedVideoTrackSource::apply_rotation() {
|
|
|
|
|
return broadcaster_.wants().rotation_applied;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AdaptedVideoTrackSource::OnSinkWantsChanged(
|
|
|
|
|
const rtc::VideoSinkWants& wants) {
|
2019-11-15 16:56:01 +01:00
|
|
|
video_adapter_.OnSinkWants(wants);
|
2016-09-22 01:25:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AdaptedVideoTrackSource::AdaptFrame(int width,
|
|
|
|
|
int height,
|
|
|
|
|
int64_t time_us,
|
|
|
|
|
int* out_width,
|
|
|
|
|
int* out_height,
|
|
|
|
|
int* crop_width,
|
|
|
|
|
int* crop_height,
|
|
|
|
|
int* crop_x,
|
|
|
|
|
int* crop_y) {
|
|
|
|
|
{
|
2020-07-07 15:43:11 +02:00
|
|
|
webrtc::MutexLock lock(&stats_mutex_);
|
2017-11-16 11:09:55 +01:00
|
|
|
stats_ = Stats{width, height};
|
2016-09-22 01:25:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!broadcaster_.frame_wanted()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!video_adapter_.AdaptFrameResolution(
|
|
|
|
|
width, height, time_us * rtc::kNumNanosecsPerMicrosec, crop_width,
|
|
|
|
|
crop_height, out_width, out_height)) {
|
2017-10-23 10:45:37 +02:00
|
|
|
broadcaster_.OnDiscardedFrame();
|
2016-09-22 01:25:59 -07:00
|
|
|
// VideoAdapter dropped the frame.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*crop_x = (width - *crop_width) / 2;
|
|
|
|
|
*crop_y = (height - *crop_height) / 2;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|