2015-01-20 21:36:13 +00:00
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
|
2015-01-20 21:36:13 +00:00
|
|
|
*
|
2016-02-07 20:46:45 -08:00
|
|
|
* 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.
|
2015-01-20 21:36:13 +00:00
|
|
|
*/
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/video_adapter.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-02-12 11:54:26 +00:00
|
|
|
#include <algorithm>
|
2016-12-08 08:04:51 -08:00
|
|
|
#include <cmath>
|
2016-05-19 06:05:40 -07:00
|
|
|
#include <cstdlib>
|
2016-04-05 15:23:49 +02:00
|
|
|
#include <limits>
|
2017-10-31 09:53:08 -07:00
|
|
|
#include <utility>
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2018-06-15 15:58:38 +02:00
|
|
|
#include "absl/types/optional.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/video_common.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2019-10-18 15:03:13 +02:00
|
|
|
#include "system_wrappers/include/field_trial.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
namespace {
|
2019-10-18 15:03:13 +02:00
|
|
|
|
2016-05-13 10:26:00 -07:00
|
|
|
struct Fraction {
|
|
|
|
|
int numerator;
|
|
|
|
|
int denominator;
|
2017-02-10 07:04:27 -08:00
|
|
|
|
2019-10-18 15:03:13 +02:00
|
|
|
void DivideByGcd() {
|
2019-12-19 09:47:11 +01:00
|
|
|
int g = cricket::GreatestCommonDivisor(numerator, denominator);
|
2019-10-18 15:03:13 +02:00
|
|
|
numerator /= g;
|
|
|
|
|
denominator /= g;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 07:04:27 -08:00
|
|
|
// Determines number of output pixels if both width and height of an input of
|
2021-07-26 13:24:57 +02:00
|
|
|
// `input_pixels` pixels is scaled with the fraction numerator / denominator.
|
2017-02-10 07:04:27 -08:00
|
|
|
int scale_pixel_count(int input_pixels) {
|
|
|
|
|
return (numerator * numerator * input_pixels) / (denominator * denominator);
|
|
|
|
|
}
|
2016-05-13 10:26:00 -07:00
|
|
|
};
|
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
// Round `value_to_round` to a multiple of `multiple`. Prefer rounding upwards,
|
|
|
|
|
// but never more than `max_value`.
|
2016-12-08 08:04:51 -08:00
|
|
|
int roundUp(int value_to_round, int multiple, int max_value) {
|
|
|
|
|
const int rounded_value =
|
|
|
|
|
(value_to_round + multiple - 1) / multiple * multiple;
|
|
|
|
|
return rounded_value <= max_value ? rounded_value
|
|
|
|
|
: (max_value / multiple * multiple);
|
2013-08-30 21:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
// Generates a scale factor that makes `input_pixels` close to `target_pixels`,
|
|
|
|
|
// but no higher than `max_pixels`.
|
2019-10-18 15:03:13 +02:00
|
|
|
Fraction FindScale(int input_width,
|
|
|
|
|
int input_height,
|
|
|
|
|
int target_pixels,
|
|
|
|
|
int max_pixels,
|
|
|
|
|
bool variable_start_scale_factor) {
|
2016-12-08 08:04:51 -08:00
|
|
|
// This function only makes sense for a positive target.
|
2017-02-10 07:04:27 -08:00
|
|
|
RTC_DCHECK_GT(target_pixels, 0);
|
|
|
|
|
RTC_DCHECK_GT(max_pixels, 0);
|
|
|
|
|
RTC_DCHECK_GE(max_pixels, target_pixels);
|
|
|
|
|
|
2019-10-18 15:03:13 +02:00
|
|
|
const int input_pixels = input_width * input_height;
|
|
|
|
|
|
2017-02-10 07:04:27 -08:00
|
|
|
// Don't scale up original.
|
|
|
|
|
if (target_pixels >= input_pixels)
|
|
|
|
|
return Fraction{1, 1};
|
|
|
|
|
|
|
|
|
|
Fraction current_scale = Fraction{1, 1};
|
2016-12-08 08:04:51 -08:00
|
|
|
Fraction best_scale = Fraction{1, 1};
|
2019-10-18 15:03:13 +02:00
|
|
|
|
|
|
|
|
if (variable_start_scale_factor) {
|
2021-07-26 13:24:57 +02:00
|
|
|
// Start scaling down by 2/3 depending on `input_width` and `input_height`.
|
2019-10-18 15:03:13 +02:00
|
|
|
if (input_width % 3 == 0 && input_height % 3 == 0) {
|
|
|
|
|
// 2/3 (then alternates 3/4, 2/3, 3/4,...).
|
|
|
|
|
current_scale = Fraction{6, 6};
|
|
|
|
|
}
|
|
|
|
|
if (input_width % 9 == 0 && input_height % 9 == 0) {
|
|
|
|
|
// 2/3, 2/3 (then alternates 3/4, 2/3, 3/4,...).
|
|
|
|
|
current_scale = Fraction{36, 36};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 07:04:27 -08:00
|
|
|
// The minimum (absolute) difference between the number of output pixels and
|
|
|
|
|
// the target pixel count.
|
|
|
|
|
int min_pixel_diff = std::numeric_limits<int>::max();
|
2017-02-22 18:30:27 +01:00
|
|
|
if (input_pixels <= max_pixels) {
|
2017-02-10 07:04:27 -08:00
|
|
|
// Start condition for 1/1 case, if it is less than max.
|
|
|
|
|
min_pixel_diff = std::abs(input_pixels - target_pixels);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 15:03:13 +02:00
|
|
|
// Alternately scale down by 3/4 and 2/3. This results in fractions which are
|
2017-02-10 07:04:27 -08:00
|
|
|
// effectively scalable. For instance, starting at 1280x720 will result in
|
|
|
|
|
// the series (3/4) => 960x540, (1/2) => 640x360, (3/8) => 480x270,
|
|
|
|
|
// (1/4) => 320x180, (3/16) => 240x125, (1/8) => 160x90.
|
|
|
|
|
while (current_scale.scale_pixel_count(input_pixels) > target_pixels) {
|
|
|
|
|
if (current_scale.numerator % 3 == 0 &&
|
|
|
|
|
current_scale.denominator % 2 == 0) {
|
|
|
|
|
// Multiply by 2/3.
|
|
|
|
|
current_scale.numerator /= 3;
|
|
|
|
|
current_scale.denominator /= 2;
|
2016-12-08 08:04:51 -08:00
|
|
|
} else {
|
2017-02-10 07:04:27 -08:00
|
|
|
// Multiply by 3/4.
|
|
|
|
|
current_scale.numerator *= 3;
|
|
|
|
|
current_scale.denominator *= 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int output_pixels = current_scale.scale_pixel_count(input_pixels);
|
|
|
|
|
if (output_pixels <= max_pixels) {
|
|
|
|
|
int diff = std::abs(target_pixels - output_pixels);
|
|
|
|
|
if (diff < min_pixel_diff) {
|
|
|
|
|
min_pixel_diff = diff;
|
|
|
|
|
best_scale = current_scale;
|
|
|
|
|
}
|
2016-04-05 15:23:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-18 15:03:13 +02:00
|
|
|
best_scale.DivideByGcd();
|
2017-02-10 07:04:27 -08:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
return best_scale;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2016-04-05 15:23:49 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace cricket {
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2019-12-19 09:47:11 +01:00
|
|
|
VideoAdapter::VideoAdapter(int source_resolution_alignment)
|
2016-05-13 10:26:00 -07:00
|
|
|
: frames_in_(0),
|
2014-02-07 19:03:26 +00:00
|
|
|
frames_out_(0),
|
|
|
|
|
frames_scaled_(0),
|
2013-08-30 21:24:16 +00:00
|
|
|
adaption_changes_(0),
|
2014-11-14 13:25:25 +00:00
|
|
|
previous_width_(0),
|
|
|
|
|
previous_height_(0),
|
2019-10-18 15:03:13 +02:00
|
|
|
variable_start_scale_factor_(webrtc::field_trial::IsEnabled(
|
|
|
|
|
"WebRTC-Video-VariableStartScaleFactor")),
|
2019-12-19 09:47:11 +01:00
|
|
|
source_resolution_alignment_(source_resolution_alignment),
|
|
|
|
|
resolution_alignment_(source_resolution_alignment),
|
2017-02-10 07:04:27 -08:00
|
|
|
resolution_request_target_pixel_count_(std::numeric_limits<int>::max()),
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
resolution_request_max_pixel_count_(std::numeric_limits<int>::max()),
|
|
|
|
|
max_framerate_request_(std::numeric_limits<int>::max()) {}
|
2016-12-08 08:04:51 -08:00
|
|
|
|
|
|
|
|
VideoAdapter::VideoAdapter() : VideoAdapter(1) {}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-04-05 15:23:49 +02:00
|
|
|
VideoAdapter::~VideoAdapter() {}
|
|
|
|
|
|
2016-05-19 06:05:40 -07:00
|
|
|
bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) {
|
2018-09-06 15:02:55 +02:00
|
|
|
int max_fps = max_framerate_request_;
|
|
|
|
|
if (max_fps_)
|
|
|
|
|
max_fps = std::min(max_fps, *max_fps_);
|
|
|
|
|
|
|
|
|
|
if (max_fps <= 0)
|
|
|
|
|
return false;
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
// If `max_framerate_request_` is not set, it will default to maxint, which
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
// will lead to a frame_interval_ns rounded to 0.
|
2018-09-06 15:02:55 +02:00
|
|
|
int64_t frame_interval_ns = rtc::kNumNanosecsPerSec / max_fps;
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
if (frame_interval_ns <= 0) {
|
|
|
|
|
// Frame rate throttling not enabled.
|
2016-05-19 06:05:40 -07:00
|
|
|
return true;
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
}
|
2016-05-19 06:05:40 -07:00
|
|
|
|
|
|
|
|
if (next_frame_timestamp_ns_) {
|
|
|
|
|
// Time until next frame should be outputted.
|
|
|
|
|
const int64_t time_until_next_frame_ns =
|
|
|
|
|
(*next_frame_timestamp_ns_ - in_timestamp_ns);
|
|
|
|
|
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
// Continue if timestamp is within expected range.
|
|
|
|
|
if (std::abs(time_until_next_frame_ns) < 2 * frame_interval_ns) {
|
2016-05-19 06:05:40 -07:00
|
|
|
// Drop if a frame shouldn't be outputted yet.
|
|
|
|
|
if (time_until_next_frame_ns > 0)
|
|
|
|
|
return false;
|
|
|
|
|
// Time to output new frame.
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
*next_frame_timestamp_ns_ += frame_interval_ns;
|
2016-05-19 06:05:40 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// First timestamp received or timestamp is way outside expected range, so
|
|
|
|
|
// reset. Set first timestamp target to just half the interval to prefer
|
|
|
|
|
// keeping frames in case of jitter.
|
2017-11-16 11:09:55 +01:00
|
|
|
next_frame_timestamp_ns_ = in_timestamp_ns + frame_interval_ns / 2;
|
2016-05-19 06:05:40 -07:00
|
|
|
return true;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-25 08:47:01 -07:00
|
|
|
bool VideoAdapter::AdaptFrameResolution(int in_width,
|
2016-05-13 10:26:00 -07:00
|
|
|
int in_height,
|
2016-05-19 06:05:40 -07:00
|
|
|
int64_t in_timestamp_ns,
|
2016-05-13 10:26:00 -07:00
|
|
|
int* cropped_width,
|
|
|
|
|
int* cropped_height,
|
|
|
|
|
int* out_width,
|
|
|
|
|
int* out_height) {
|
2020-07-09 01:34:42 +02:00
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2014-02-07 19:03:26 +00:00
|
|
|
++frames_in_;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-05-13 10:26:00 -07:00
|
|
|
// The max output pixel count is the minimum of the requests from
|
2018-09-06 15:02:55 +02:00
|
|
|
// OnOutputFormatRequest and OnResolutionFramerateRequest.
|
2016-05-13 10:26:00 -07:00
|
|
|
int max_pixel_count = resolution_request_max_pixel_count_;
|
2018-09-06 15:02:55 +02:00
|
|
|
|
2018-10-26 14:00:18 +02:00
|
|
|
// Select target aspect ratio and max pixel count depending on input frame
|
|
|
|
|
// orientation.
|
|
|
|
|
absl::optional<std::pair<int, int>> target_aspect_ratio;
|
|
|
|
|
if (in_width > in_height) {
|
|
|
|
|
target_aspect_ratio = target_landscape_aspect_ratio_;
|
|
|
|
|
if (max_landscape_pixel_count_)
|
|
|
|
|
max_pixel_count = std::min(max_pixel_count, *max_landscape_pixel_count_);
|
|
|
|
|
} else {
|
|
|
|
|
target_aspect_ratio = target_portrait_aspect_ratio_;
|
|
|
|
|
if (max_portrait_pixel_count_)
|
|
|
|
|
max_pixel_count = std::min(max_pixel_count, *max_portrait_pixel_count_);
|
|
|
|
|
}
|
2018-09-06 15:02:55 +02:00
|
|
|
|
2017-02-10 07:04:27 -08:00
|
|
|
int target_pixel_count =
|
|
|
|
|
std::min(resolution_request_target_pixel_count_, max_pixel_count);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Drop the input frame if necessary.
|
2016-12-08 08:04:51 -08:00
|
|
|
if (max_pixel_count <= 0 || !KeepFrame(in_timestamp_ns)) {
|
2014-02-07 19:03:26 +00:00
|
|
|
// Show VAdapt log every 90 frames dropped. (3 seconds)
|
2014-02-13 23:18:49 +00:00
|
|
|
if ((frames_in_ - frames_out_) % 90 == 0) {
|
2014-02-07 19:03:26 +00:00
|
|
|
// TODO(fbarchard): Reduce to LS_VERBOSE when adapter info is not needed
|
|
|
|
|
// in default calls.
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "VAdapt Drop Frame: scaled " << frames_scaled_
|
|
|
|
|
<< " / out " << frames_out_ << " / in " << frames_in_
|
|
|
|
|
<< " Changes: " << adaption_changes_
|
|
|
|
|
<< " Input: " << in_width << "x" << in_height
|
2018-09-06 15:02:55 +02:00
|
|
|
<< " timestamp: " << in_timestamp_ns
|
|
|
|
|
<< " Output fps: " << max_framerate_request_ << "/"
|
2019-12-19 09:47:11 +01:00
|
|
|
<< max_fps_.value_or(-1)
|
|
|
|
|
<< " alignment: " << resolution_alignment_;
|
2014-02-07 19:03:26 +00:00
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-05-13 10:26:00 -07:00
|
|
|
// Drop frame.
|
2016-05-25 08:47:01 -07:00
|
|
|
return false;
|
2016-05-13 10:26:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate how the input should be cropped.
|
2018-10-26 14:00:18 +02:00
|
|
|
if (!target_aspect_ratio || target_aspect_ratio->first <= 0 ||
|
|
|
|
|
target_aspect_ratio->second <= 0) {
|
2016-05-13 10:26:00 -07:00
|
|
|
*cropped_width = in_width;
|
|
|
|
|
*cropped_height = in_height;
|
|
|
|
|
} else {
|
|
|
|
|
const float requested_aspect =
|
2018-10-26 14:00:18 +02:00
|
|
|
target_aspect_ratio->first /
|
|
|
|
|
static_cast<float>(target_aspect_ratio->second);
|
2016-05-13 10:26:00 -07:00
|
|
|
*cropped_width =
|
|
|
|
|
std::min(in_width, static_cast<int>(in_height * requested_aspect));
|
|
|
|
|
*cropped_height =
|
|
|
|
|
std::min(in_height, static_cast<int>(in_width / requested_aspect));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2019-10-18 15:03:13 +02:00
|
|
|
const Fraction scale =
|
|
|
|
|
FindScale(*cropped_width, *cropped_height, target_pixel_count,
|
|
|
|
|
max_pixel_count, variable_start_scale_factor_);
|
2019-12-19 09:47:11 +01:00
|
|
|
// Adjust cropping slightly to get correctly aligned output size and a perfect
|
|
|
|
|
// scale factor.
|
|
|
|
|
*cropped_width = roundUp(*cropped_width,
|
|
|
|
|
scale.denominator * resolution_alignment_, in_width);
|
|
|
|
|
*cropped_height = roundUp(
|
|
|
|
|
*cropped_height, scale.denominator * resolution_alignment_, in_height);
|
2016-05-13 10:26:00 -07:00
|
|
|
RTC_DCHECK_EQ(0, *cropped_width % scale.denominator);
|
|
|
|
|
RTC_DCHECK_EQ(0, *cropped_height % scale.denominator);
|
|
|
|
|
|
|
|
|
|
// Calculate final output size.
|
|
|
|
|
*out_width = *cropped_width / scale.denominator * scale.numerator;
|
|
|
|
|
*out_height = *cropped_height / scale.denominator * scale.numerator;
|
2019-12-19 09:47:11 +01:00
|
|
|
RTC_DCHECK_EQ(0, *out_width % resolution_alignment_);
|
|
|
|
|
RTC_DCHECK_EQ(0, *out_height % resolution_alignment_);
|
2013-08-30 21:24:16 +00:00
|
|
|
|
2014-02-07 19:03:26 +00:00
|
|
|
++frames_out_;
|
2016-05-13 10:26:00 -07:00
|
|
|
if (scale.numerator != scale.denominator)
|
2014-02-07 19:03:26 +00:00
|
|
|
++frames_scaled_;
|
2016-04-05 15:23:49 +02:00
|
|
|
|
2016-05-13 10:26:00 -07:00
|
|
|
if (previous_width_ &&
|
|
|
|
|
(previous_width_ != *out_width || previous_height_ != *out_height)) {
|
2013-08-30 21:24:16 +00:00
|
|
|
++adaption_changes_;
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Frame size changed: scaled " << frames_scaled_
|
|
|
|
|
<< " / out " << frames_out_ << " / in " << frames_in_
|
|
|
|
|
<< " Changes: " << adaption_changes_
|
|
|
|
|
<< " Input: " << in_width << "x" << in_height
|
|
|
|
|
<< " Scale: " << scale.numerator << "/"
|
|
|
|
|
<< scale.denominator << " Output: " << *out_width << "x"
|
2018-09-06 15:02:55 +02:00
|
|
|
<< *out_height << " fps: " << max_framerate_request_ << "/"
|
2019-12-19 09:47:11 +01:00
|
|
|
<< max_fps_.value_or(-1)
|
|
|
|
|
<< " alignment: " << resolution_alignment_;
|
2013-08-30 21:24:16 +00:00
|
|
|
}
|
2014-11-19 18:09:14 +00:00
|
|
|
|
2016-05-13 10:26:00 -07:00
|
|
|
previous_width_ = *out_width;
|
|
|
|
|
previous_height_ = *out_height;
|
2016-05-25 08:47:01 -07:00
|
|
|
|
|
|
|
|
return true;
|
2014-11-19 18:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 17:55:53 -08:00
|
|
|
void VideoAdapter::OnOutputFormatRequest(
|
2018-06-15 15:58:38 +02:00
|
|
|
const absl::optional<VideoFormat>& format) {
|
2018-09-06 15:02:55 +02:00
|
|
|
absl::optional<std::pair<int, int>> target_aspect_ratio;
|
|
|
|
|
absl::optional<int> max_pixel_count;
|
|
|
|
|
absl::optional<int> max_fps;
|
|
|
|
|
if (format) {
|
|
|
|
|
target_aspect_ratio = std::make_pair(format->width, format->height);
|
|
|
|
|
max_pixel_count = format->width * format->height;
|
|
|
|
|
if (format->interval > 0)
|
|
|
|
|
max_fps = rtc::kNumNanosecsPerSec / format->interval;
|
|
|
|
|
}
|
|
|
|
|
OnOutputFormatRequest(target_aspect_ratio, max_pixel_count, max_fps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoAdapter::OnOutputFormatRequest(
|
|
|
|
|
const absl::optional<std::pair<int, int>>& target_aspect_ratio,
|
|
|
|
|
const absl::optional<int>& max_pixel_count,
|
|
|
|
|
const absl::optional<int>& max_fps) {
|
2018-10-26 14:00:18 +02:00
|
|
|
absl::optional<std::pair<int, int>> target_landscape_aspect_ratio;
|
|
|
|
|
absl::optional<std::pair<int, int>> target_portrait_aspect_ratio;
|
|
|
|
|
if (target_aspect_ratio && target_aspect_ratio->first > 0 &&
|
|
|
|
|
target_aspect_ratio->second > 0) {
|
|
|
|
|
// Maintain input orientation.
|
|
|
|
|
const int max_side =
|
|
|
|
|
std::max(target_aspect_ratio->first, target_aspect_ratio->second);
|
|
|
|
|
const int min_side =
|
|
|
|
|
std::min(target_aspect_ratio->first, target_aspect_ratio->second);
|
|
|
|
|
target_landscape_aspect_ratio = std::make_pair(max_side, min_side);
|
|
|
|
|
target_portrait_aspect_ratio = std::make_pair(min_side, max_side);
|
|
|
|
|
}
|
|
|
|
|
OnOutputFormatRequest(target_landscape_aspect_ratio, max_pixel_count,
|
|
|
|
|
target_portrait_aspect_ratio, max_pixel_count, max_fps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoAdapter::OnOutputFormatRequest(
|
|
|
|
|
const absl::optional<std::pair<int, int>>& target_landscape_aspect_ratio,
|
|
|
|
|
const absl::optional<int>& max_landscape_pixel_count,
|
|
|
|
|
const absl::optional<std::pair<int, int>>& target_portrait_aspect_ratio,
|
|
|
|
|
const absl::optional<int>& max_portrait_pixel_count,
|
|
|
|
|
const absl::optional<int>& max_fps) {
|
2020-07-09 01:34:42 +02:00
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2018-10-26 14:00:18 +02:00
|
|
|
target_landscape_aspect_ratio_ = target_landscape_aspect_ratio;
|
|
|
|
|
max_landscape_pixel_count_ = max_landscape_pixel_count;
|
|
|
|
|
target_portrait_aspect_ratio_ = target_portrait_aspect_ratio;
|
|
|
|
|
max_portrait_pixel_count_ = max_portrait_pixel_count;
|
2018-09-06 15:02:55 +02:00
|
|
|
max_fps_ = max_fps;
|
2018-06-15 15:58:38 +02:00
|
|
|
next_frame_timestamp_ns_ = absl::nullopt;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 16:56:01 +01:00
|
|
|
void VideoAdapter::OnSinkWants(const rtc::VideoSinkWants& sink_wants) {
|
2020-07-09 01:34:42 +02:00
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2019-11-15 16:56:01 +01:00
|
|
|
resolution_request_max_pixel_count_ = sink_wants.max_pixel_count;
|
2017-02-10 07:04:27 -08:00
|
|
|
resolution_request_target_pixel_count_ =
|
2019-11-15 16:56:01 +01:00
|
|
|
sink_wants.target_pixel_count.value_or(
|
|
|
|
|
resolution_request_max_pixel_count_);
|
|
|
|
|
max_framerate_request_ = sink_wants.max_framerate_fps;
|
2019-12-19 09:47:11 +01:00
|
|
|
resolution_alignment_ = cricket::LeastCommonMultiple(
|
|
|
|
|
source_resolution_alignment_, sink_wants.resolution_alignment);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 16:50:44 +02:00
|
|
|
int VideoAdapter::GetTargetPixels() const {
|
|
|
|
|
webrtc::MutexLock lock(&mutex_);
|
|
|
|
|
return resolution_request_target_pixel_count_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float VideoAdapter::GetMaxFramerate() const {
|
|
|
|
|
webrtc::MutexLock lock(&mutex_);
|
2021-07-26 13:24:57 +02:00
|
|
|
// Minimum of `max_fps_` and `max_framerate_request_` is used to throttle
|
2020-08-26 16:50:44 +02:00
|
|
|
// frame-rate.
|
|
|
|
|
int framerate = std::min(max_framerate_request_,
|
|
|
|
|
max_fps_.value_or(max_framerate_request_));
|
|
|
|
|
if (framerate == std::numeric_limits<int>::max()) {
|
|
|
|
|
return std::numeric_limits<float>::infinity();
|
|
|
|
|
} else {
|
|
|
|
|
return max_framerate_request_;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
} // namespace cricket
|