2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-02 08:37:48 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef VIDEO_VIDEO_STREAM_ENCODER_H_
|
|
|
|
|
#define VIDEO_VIDEO_STREAM_ENCODER_H_
|
2012-04-27 05:25:53 +00:00
|
|
|
|
2017-10-24 15:40:52 -07:00
|
|
|
#include <atomic>
|
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
|
|
|
#include <map>
|
2016-03-01 11:52:33 -08:00
|
|
|
#include <memory>
|
2016-05-02 11:35:24 -07:00
|
|
|
#include <string>
|
2015-02-06 13:10:19 +00:00
|
|
|
#include <vector>
|
2012-10-25 11:30:29 +00:00
|
|
|
|
2020-06-03 09:24:06 +02:00
|
|
|
#include "api/adaptation/resource.h"
|
2022-03-29 11:04:48 +02:00
|
|
|
#include "api/field_trials_view.h"
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2019-09-16 14:53:40 +02:00
|
|
|
#include "api/units/data_rate.h"
|
2018-07-20 15:49:43 -07:00
|
|
|
#include "api/video/video_bitrate_allocator.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_rotation.h"
|
2018-05-11 11:15:30 +02:00
|
|
|
#include "api/video/video_sink_interface.h"
|
2018-05-21 14:09:31 +02:00
|
|
|
#include "api/video/video_stream_encoder_interface.h"
|
2018-07-24 09:29:58 +02:00
|
|
|
#include "api/video/video_stream_encoder_observer.h"
|
|
|
|
|
#include "api/video/video_stream_encoder_settings.h"
|
2019-02-26 18:31:00 +01:00
|
|
|
#include "api/video_codecs/video_codec.h"
|
2018-05-21 14:09:31 +02:00
|
|
|
#include "api/video_codecs/video_encoder.h"
|
2020-06-02 13:02:36 +02:00
|
|
|
#include "call/adaptation/adaptation_constraint.h"
|
2020-07-03 13:51:48 +02:00
|
|
|
#include "call/adaptation/resource_adaptation_processor.h"
|
2020-03-10 19:08:05 +01:00
|
|
|
#include "call/adaptation/resource_adaptation_processor_interface.h"
|
2020-01-13 11:27:18 +01:00
|
|
|
#include "call/adaptation/video_source_restrictions.h"
|
2020-04-17 12:10:59 +02:00
|
|
|
#include "call/adaptation/video_stream_input_state_provider.h"
|
2019-01-11 11:11:10 +01:00
|
|
|
#include "modules/video_coding/utility/frame_dropper.h"
|
2021-03-15 10:12:57 +01:00
|
|
|
#include "modules/video_coding/utility/qp_parser.h"
|
2019-02-06 16:20:17 +01:00
|
|
|
#include "rtc_base/experiments/rate_control_settings.h"
|
2019-09-16 14:53:40 +02:00
|
|
|
#include "rtc_base/numerics/exp_filter.h"
|
2019-02-26 18:31:00 +01:00
|
|
|
#include "rtc_base/race_checker.h"
|
2019-01-11 11:11:10 +01:00
|
|
|
#include "rtc_base/rate_statistics.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/task_queue.h"
|
2020-09-21 14:31:23 +02:00
|
|
|
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
2020-08-25 13:12:12 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2019-09-10 10:48:48 +02:00
|
|
|
#include "system_wrappers/include/clock.h"
|
2020-04-17 17:15:26 +02:00
|
|
|
#include "video/adaptation/video_stream_encoder_resource_manager.h"
|
2019-02-06 16:20:17 +01:00
|
|
|
#include "video/encoder_bitrate_adjuster.h"
|
2021-11-05 12:00:55 +01:00
|
|
|
#include "video/frame_cadence_adapter.h"
|
2019-05-13 16:13:36 +02:00
|
|
|
#include "video/frame_encode_metadata_writer.h"
|
2020-01-13 11:27:18 +01:00
|
|
|
#include "video/video_source_sink_controller.h"
|
2020-06-02 13:02:36 +02:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
2011-12-01 17:02:23 +00:00
|
|
|
|
2017-08-03 08:27:51 -07:00
|
|
|
// VideoStreamEncoder represent a video encoder that accepts raw video frames as
|
|
|
|
|
// input and produces an encoded bit stream.
|
2016-05-02 06:31:25 -07:00
|
|
|
// Usage:
|
2016-09-01 01:17:40 -07:00
|
|
|
// Instantiate.
|
2016-09-16 07:53:41 -07:00
|
|
|
// Call SetSink.
|
|
|
|
|
// Call SetSource.
|
2016-09-01 01:17:40 -07:00
|
|
|
// Call ConfigureEncoder with the codec settings.
|
|
|
|
|
// Call Stop() when done.
|
2018-04-19 17:09:15 +02:00
|
|
|
class VideoStreamEncoder : public VideoStreamEncoderInterface,
|
2020-01-10 15:44:01 +01:00
|
|
|
private EncodedImageCallback,
|
2020-06-02 13:02:36 +02:00
|
|
|
public VideoSourceRestrictionsListener {
|
2011-12-01 17:02:23 +00:00
|
|
|
public:
|
2021-01-03 10:26:03 +01:00
|
|
|
// TODO(bugs.webrtc.org/12000): Reporting of VideoBitrateAllocation is being
|
|
|
|
|
// deprecated. Instead VideoLayersAllocation should be reported.
|
|
|
|
|
enum class BitrateAllocationCallbackType {
|
|
|
|
|
kVideoBitrateAllocation,
|
|
|
|
|
kVideoBitrateAllocationWhenScreenSharing,
|
|
|
|
|
kVideoLayersAllocation
|
|
|
|
|
};
|
2021-11-05 12:00:55 +01:00
|
|
|
VideoStreamEncoder(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
uint32_t number_of_cores,
|
|
|
|
|
VideoStreamEncoderObserver* encoder_stats_observer,
|
|
|
|
|
const VideoStreamEncoderSettings& settings,
|
|
|
|
|
std::unique_ptr<OveruseFrameDetector> overuse_detector,
|
|
|
|
|
std::unique_ptr<FrameCadenceAdapterInterface> frame_cadence_adapter,
|
2021-11-18 16:07:01 +01:00
|
|
|
std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>
|
|
|
|
|
encoder_queue,
|
2022-03-09 15:12:07 +01:00
|
|
|
BitrateAllocationCallbackType allocation_cb_type,
|
2022-03-29 11:04:48 +02:00
|
|
|
const FieldTrialsView& field_trials);
|
2018-07-17 16:03:46 +02:00
|
|
|
~VideoStreamEncoder() override;
|
2011-12-01 17:02:23 +00:00
|
|
|
|
2022-01-26 15:01:10 +00:00
|
|
|
VideoStreamEncoder(const VideoStreamEncoder&) = delete;
|
|
|
|
|
VideoStreamEncoder& operator=(const VideoStreamEncoder&) = delete;
|
|
|
|
|
|
2020-06-11 12:07:14 +02:00
|
|
|
void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) override;
|
|
|
|
|
std::vector<rtc::scoped_refptr<Resource>> GetAdaptationResources() override;
|
|
|
|
|
|
2018-04-19 17:09:15 +02:00
|
|
|
void SetSource(rtc::VideoSourceInterface<VideoFrame>* source,
|
2018-05-16 14:20:41 -07:00
|
|
|
const DegradationPreference& degradation_preference) override;
|
2016-11-01 11:45:46 -07:00
|
|
|
|
2018-04-19 17:09:15 +02:00
|
|
|
void SetSink(EncoderSink* sink, bool rotation_applied) override;
|
2012-03-05 17:12:41 +00:00
|
|
|
|
2016-09-01 01:17:40 -07:00
|
|
|
// TODO(perkj): Can we remove VideoCodec.startBitrate ?
|
2018-04-19 17:09:15 +02:00
|
|
|
void SetStartBitrate(int start_bitrate_bps) override;
|
2012-04-27 05:25:53 +00:00
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
void SetFecControllerOverride(
|
|
|
|
|
FecControllerOverride* fec_controller_override) override;
|
|
|
|
|
|
2016-09-23 15:52:06 +02:00
|
|
|
void ConfigureEncoder(VideoEncoderConfig config,
|
2018-04-26 09:51:47 +02:00
|
|
|
size_t max_data_payload_length) override;
|
2016-06-15 00:47:53 -07:00
|
|
|
|
2016-09-01 01:17:40 -07:00
|
|
|
// Permanently stop encoding. After this method has returned, it is
|
|
|
|
|
// guaranteed that no encoded frames will be delivered to the sink.
|
2018-04-19 17:09:15 +02:00
|
|
|
void Stop() override;
|
2015-02-26 13:15:22 +00:00
|
|
|
|
2018-04-19 17:09:15 +02:00
|
|
|
void SendKeyFrame() override;
|
2012-10-25 11:30:29 +00:00
|
|
|
|
2019-04-10 16:37:07 +02:00
|
|
|
void OnLossNotification(
|
|
|
|
|
const VideoEncoder::LossNotification& loss_notification) override;
|
|
|
|
|
|
2019-03-06 15:37:33 +01:00
|
|
|
void OnBitrateUpdated(DataRate target_bitrate,
|
2019-09-09 13:36:55 +02:00
|
|
|
DataRate stable_target_bitrate,
|
2019-03-06 15:37:33 +01:00
|
|
|
DataRate target_headroom,
|
2014-12-08 19:46:23 +00:00
|
|
|
uint8_t fraction_lost,
|
2020-02-07 14:29:32 +01:00
|
|
|
int64_t round_trip_time_ms,
|
|
|
|
|
double cwnd_reduce_ratio) override;
|
|
|
|
|
|
|
|
|
|
DataRate UpdateTargetBitrate(DataRate target_bitrate,
|
|
|
|
|
double cwnd_reduce_ratio);
|
2012-04-27 05:25:53 +00:00
|
|
|
|
2016-11-01 11:45:46 -07:00
|
|
|
protected:
|
2021-07-27 16:22:11 +02:00
|
|
|
// Used for testing. For example the `ScalingObserverInterface` methods must
|
|
|
|
|
// be called on `encoder_queue_`.
|
2016-11-01 11:45:46 -07:00
|
|
|
rtc::TaskQueue* encoder_queue() { return &encoder_queue_; }
|
|
|
|
|
|
2020-01-10 15:44:01 +01:00
|
|
|
void OnVideoSourceRestrictionsUpdated(
|
2020-04-17 15:31:48 +02:00
|
|
|
VideoSourceRestrictions restrictions,
|
|
|
|
|
const VideoAdaptationCounters& adaptation_counters,
|
2020-07-01 11:47:46 +02:00
|
|
|
rtc::scoped_refptr<Resource> reason,
|
|
|
|
|
const VideoSourceRestrictions& unfiltered_restrictions) override;
|
2020-01-10 15:44:01 +01:00
|
|
|
|
2020-02-25 16:26:01 +01:00
|
|
|
// Used for injected test resources.
|
|
|
|
|
// TODO(eshr): Move all adaptation tests out of VideoStreamEncoder tests.
|
2020-05-11 16:29:22 +02:00
|
|
|
void InjectAdaptationResource(rtc::scoped_refptr<Resource> resource,
|
2020-06-02 13:02:36 +02:00
|
|
|
VideoAdaptationReason reason);
|
|
|
|
|
void InjectAdaptationConstraint(AdaptationConstraint* adaptation_constraint);
|
2020-02-25 16:26:01 +01:00
|
|
|
|
2020-06-02 13:02:36 +02:00
|
|
|
void AddRestrictionsListenerForTesting(
|
|
|
|
|
VideoSourceRestrictionsListener* restrictions_listener);
|
|
|
|
|
void RemoveRestrictionsListenerForTesting(
|
|
|
|
|
VideoSourceRestrictionsListener* restrictions_listener);
|
2020-05-12 18:49:07 +02:00
|
|
|
|
2011-12-01 17:02:23 +00:00
|
|
|
private:
|
2021-11-05 12:00:55 +01:00
|
|
|
class CadenceCallback : public FrameCadenceAdapterInterface::Callback {
|
|
|
|
|
public:
|
|
|
|
|
explicit CadenceCallback(VideoStreamEncoder& video_stream_encoder)
|
|
|
|
|
: video_stream_encoder_(video_stream_encoder) {}
|
|
|
|
|
// FrameCadenceAdapterInterface::Callback overrides.
|
2021-11-18 16:07:01 +01:00
|
|
|
void OnFrame(Timestamp post_time,
|
|
|
|
|
int frames_scheduled_for_processing,
|
|
|
|
|
const VideoFrame& frame) override {
|
|
|
|
|
video_stream_encoder_.OnFrame(post_time, frames_scheduled_for_processing,
|
|
|
|
|
frame);
|
2021-11-05 12:00:55 +01:00
|
|
|
}
|
|
|
|
|
void OnDiscardedFrame() override {
|
|
|
|
|
video_stream_encoder_.OnDiscardedFrame();
|
|
|
|
|
}
|
2021-12-30 13:01:33 +01:00
|
|
|
void RequestRefreshFrame() override {
|
|
|
|
|
video_stream_encoder_.RequestRefreshFrame();
|
|
|
|
|
}
|
2021-11-05 12:00:55 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
VideoStreamEncoder& video_stream_encoder_;
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-16 06:15:23 -08:00
|
|
|
class VideoFrameInfo {
|
|
|
|
|
public:
|
2016-10-02 23:45:26 -07:00
|
|
|
VideoFrameInfo(int width, int height, bool is_texture)
|
|
|
|
|
: width(width), height(height), is_texture(is_texture) {}
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
bool is_texture;
|
2017-01-16 06:15:23 -08:00
|
|
|
int pixel_count() const { return width * height; }
|
2016-10-02 23:45:26 -07:00
|
|
|
};
|
|
|
|
|
|
2019-09-26 09:55:03 +02:00
|
|
|
struct EncoderRateSettings {
|
2019-04-08 15:14:01 +02:00
|
|
|
EncoderRateSettings();
|
|
|
|
|
EncoderRateSettings(const VideoBitrateAllocation& bitrate,
|
|
|
|
|
double framerate_fps,
|
|
|
|
|
DataRate bandwidth_allocation,
|
2019-09-09 13:36:55 +02:00
|
|
|
DataRate encoder_target,
|
|
|
|
|
DataRate stable_encoder_target);
|
2019-04-08 15:14:01 +02:00
|
|
|
bool operator==(const EncoderRateSettings& rhs) const;
|
|
|
|
|
bool operator!=(const EncoderRateSettings& rhs) const;
|
|
|
|
|
|
2019-09-26 09:55:03 +02:00
|
|
|
VideoEncoder::RateControlParameters rate_control;
|
2019-04-08 15:14:01 +02:00
|
|
|
// This is the scalar target bitrate before the VideoBitrateAllocator, i.e.
|
2021-07-27 16:22:11 +02:00
|
|
|
// the `target_bitrate` argument of the OnBitrateUpdated() method. This is
|
2019-04-08 15:14:01 +02:00
|
|
|
// needed because the bitrate allocator may truncate the total bitrate and a
|
|
|
|
|
// later call to the same allocator instance, e.g.
|
|
|
|
|
// |using last_encoder_rate_setings_->bitrate.get_sum_bps()|, may trick it
|
|
|
|
|
// into thinking the available bitrate has decreased since the last call.
|
|
|
|
|
DataRate encoder_target;
|
2019-09-09 13:36:55 +02:00
|
|
|
DataRate stable_encoder_target;
|
2019-04-08 15:14:01 +02:00
|
|
|
};
|
|
|
|
|
|
2020-07-03 13:51:48 +02:00
|
|
|
class DegradationPreferenceManager;
|
|
|
|
|
|
2018-02-07 13:42:09 +01:00
|
|
|
void ReconfigureEncoder() RTC_RUN_ON(&encoder_queue_);
|
2020-04-17 12:10:59 +02:00
|
|
|
void OnEncoderSettingsChanged() RTC_RUN_ON(&encoder_queue_);
|
2021-11-18 16:07:01 +01:00
|
|
|
void OnFrame(Timestamp post_time,
|
|
|
|
|
int frames_scheduled_for_processing,
|
|
|
|
|
const VideoFrame& video_frame);
|
2021-11-05 12:00:55 +01:00
|
|
|
void OnDiscardedFrame();
|
2021-12-30 13:01:33 +01:00
|
|
|
void RequestRefreshFrame();
|
2016-09-16 07:53:41 -07:00
|
|
|
|
2018-04-10 13:05:49 +02:00
|
|
|
void MaybeEncodeVideoFrame(const VideoFrame& frame,
|
|
|
|
|
int64_t time_when_posted_in_ms);
|
|
|
|
|
|
2016-09-07 06:32:18 -07:00
|
|
|
void EncodeVideoFrame(const VideoFrame& frame,
|
|
|
|
|
int64_t time_when_posted_in_ms);
|
2021-03-29 14:09:04 +02:00
|
|
|
// Indicates whether frame should be dropped because the pixel count is too
|
2018-04-10 13:05:49 +02:00
|
|
|
// large for the current bitrate configuration.
|
|
|
|
|
bool DropDueToSize(uint32_t pixel_count) const RTC_RUN_ON(&encoder_queue_);
|
2011-12-01 17:02:23 +00:00
|
|
|
|
2016-09-01 01:17:40 -07:00
|
|
|
// Implements EncodedImageCallback.
|
|
|
|
|
EncodedImageCallback::Result OnEncodedImage(
|
|
|
|
|
const EncodedImage& encoded_image,
|
2020-08-12 17:30:36 +02:00
|
|
|
const CodecSpecificInfo* codec_specific_info) override;
|
2016-08-16 00:38:44 -07:00
|
|
|
|
2017-10-23 10:45:37 +02:00
|
|
|
void OnDroppedFrame(EncodedImageCallback::DropReason reason) override;
|
2016-11-29 01:44:11 -08:00
|
|
|
|
2016-09-01 01:17:40 -07:00
|
|
|
bool EncoderPaused() const;
|
|
|
|
|
void TraceFrameDropStart();
|
|
|
|
|
void TraceFrameDropEnd();
|
|
|
|
|
|
2021-07-27 16:22:11 +02:00
|
|
|
// Returns a copy of `rate_settings` with the `bitrate` field updated using
|
2020-10-07 11:28:41 +02:00
|
|
|
// the current VideoBitrateAllocator.
|
|
|
|
|
EncoderRateSettings UpdateBitrateAllocation(
|
2019-04-08 15:14:01 +02:00
|
|
|
const EncoderRateSettings& rate_settings) RTC_RUN_ON(&encoder_queue_);
|
|
|
|
|
|
2019-01-11 11:11:10 +01:00
|
|
|
uint32_t GetInputFramerateFps() RTC_RUN_ON(&encoder_queue_);
|
2019-04-08 15:14:01 +02:00
|
|
|
void SetEncoderRates(const EncoderRateSettings& rate_settings)
|
|
|
|
|
RTC_RUN_ON(&encoder_queue_);
|
2019-01-11 11:11:10 +01:00
|
|
|
|
2020-01-17 11:44:24 +01:00
|
|
|
void RunPostEncode(const EncodedImage& encoded_image,
|
2019-01-11 11:11:10 +01:00
|
|
|
int64_t time_sent_us,
|
2019-11-25 15:01:09 +01:00
|
|
|
int temporal_index,
|
|
|
|
|
DataSize frame_size);
|
2019-02-26 18:31:00 +01:00
|
|
|
void ReleaseEncoder() RTC_RUN_ON(&encoder_queue_);
|
2021-07-27 16:22:11 +02:00
|
|
|
// After calling this function `resource_adaptation_processor_` will be null.
|
2020-08-25 13:12:28 +02:00
|
|
|
void ShutdownResourceAdaptationQueue();
|
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
|
|
|
|
2019-12-03 16:54:17 +01:00
|
|
|
void CheckForAnimatedContent(const VideoFrame& frame,
|
|
|
|
|
int64_t time_when_posted_in_ms)
|
|
|
|
|
RTC_RUN_ON(&encoder_queue_);
|
|
|
|
|
|
2022-01-21 11:35:04 +01:00
|
|
|
void RequestEncoderSwitch() RTC_RUN_ON(&encoder_queue_);
|
|
|
|
|
|
2022-03-29 11:04:48 +02:00
|
|
|
const FieldTrialsView& field_trials_;
|
2021-10-28 15:29:42 +02:00
|
|
|
TaskQueueBase* const worker_queue_;
|
2011-12-01 17:02:23 +00:00
|
|
|
|
2022-04-06 16:44:30 +02:00
|
|
|
const int number_of_cores_;
|
2016-09-16 07:53:41 -07:00
|
|
|
|
2016-09-23 15:52:06 +02:00
|
|
|
EncoderSink* sink_;
|
2018-07-24 09:29:58 +02:00
|
|
|
const VideoStreamEncoderSettings settings_;
|
2021-01-03 10:26:03 +01:00
|
|
|
const BitrateAllocationCallbackType allocation_cb_type_;
|
2019-02-06 16:20:17 +01:00
|
|
|
const RateControlSettings rate_control_settings_;
|
2011-12-01 17:02:23 +00:00
|
|
|
|
2020-02-10 11:30:00 +01:00
|
|
|
std::unique_ptr<VideoEncoderFactory::EncoderSelectorInterface> const
|
|
|
|
|
encoder_selector_;
|
2018-07-24 09:29:58 +02:00
|
|
|
VideoStreamEncoderObserver* const encoder_stats_observer_;
|
2021-11-05 12:00:55 +01:00
|
|
|
// Adapter that avoids public inheritance of the cadence adapter's callback
|
|
|
|
|
// interface.
|
|
|
|
|
CadenceCallback cadence_callback_;
|
|
|
|
|
// Frame cadence encoder adapter. Frames enter this adapter first, and it then
|
|
|
|
|
// forwards them to our OnFrame method.
|
2021-11-18 16:07:01 +01:00
|
|
|
std::unique_ptr<FrameCadenceAdapterInterface> frame_cadence_adapter_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_) RTC_PT_GUARDED_BY(&encoder_queue_);
|
2021-10-13 22:50:53 +02:00
|
|
|
|
2018-02-07 10:18:32 +01:00
|
|
|
VideoEncoderConfig encoder_config_ RTC_GUARDED_BY(&encoder_queue_);
|
2018-04-19 09:04:13 +02:00
|
|
|
std::unique_ptr<VideoEncoder> encoder_ RTC_GUARDED_BY(&encoder_queue_)
|
|
|
|
|
RTC_PT_GUARDED_BY(&encoder_queue_);
|
2019-02-26 18:31:00 +01:00
|
|
|
bool encoder_initialized_;
|
2016-11-16 16:41:30 +01:00
|
|
|
std::unique_ptr<VideoBitrateAllocator> rate_allocator_
|
2018-02-07 13:42:09 +01:00
|
|
|
RTC_GUARDED_BY(&encoder_queue_) RTC_PT_GUARDED_BY(&encoder_queue_);
|
2018-02-07 10:18:32 +01:00
|
|
|
int max_framerate_ RTC_GUARDED_BY(&encoder_queue_);
|
2016-09-01 01:17:40 -07:00
|
|
|
|
2016-10-02 23:45:26 -07:00
|
|
|
// Set when ConfigureEncoder has been called in order to lazy reconfigure the
|
|
|
|
|
// encoder on the next frame.
|
2018-02-07 10:18:32 +01:00
|
|
|
bool pending_encoder_reconfiguration_ RTC_GUARDED_BY(&encoder_queue_);
|
2018-12-10 09:47:34 +00:00
|
|
|
// Set when configuration must create a new encoder object, e.g.,
|
|
|
|
|
// because of a codec change.
|
|
|
|
|
bool pending_encoder_creation_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-07-02 14:18:34 +02:00
|
|
|
|
2018-06-15 12:28:07 +02:00
|
|
|
absl::optional<VideoFrameInfo> last_frame_info_
|
2018-02-07 10:18:32 +01:00
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
int crop_width_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
int crop_height_ RTC_GUARDED_BY(&encoder_queue_);
|
2020-01-21 17:45:35 +01:00
|
|
|
absl::optional<uint32_t> encoder_target_bitrate_bps_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2018-02-07 10:18:32 +01:00
|
|
|
size_t max_data_payload_length_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-04-08 15:14:01 +02:00
|
|
|
absl::optional<EncoderRateSettings> last_encoder_rate_settings_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2018-02-07 10:18:32 +01:00
|
|
|
bool encoder_paused_and_dropped_frame_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-07-02 14:18:34 +02:00
|
|
|
|
|
|
|
|
// Set to true if at least one frame was sent to encoder since last encoder
|
|
|
|
|
// initialization.
|
|
|
|
|
bool was_encode_called_since_last_initialization_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
|
2019-07-03 11:53:48 +02:00
|
|
|
bool encoder_failed_ RTC_GUARDED_BY(&encoder_queue_);
|
2016-09-01 01:17:40 -07:00
|
|
|
Clock* const clock_;
|
2016-11-01 11:45:46 -07:00
|
|
|
|
2016-09-01 01:17:40 -07:00
|
|
|
// Used to make sure incoming time stamp is increasing for every frame.
|
2021-11-18 16:07:01 +01:00
|
|
|
int64_t last_captured_timestamp_ RTC_GUARDED_BY(&encoder_queue_);
|
2016-09-01 01:17:40 -07:00
|
|
|
// Delta used for translating between NTP and internal timestamps.
|
2021-11-18 16:07:01 +01:00
|
|
|
const int64_t delta_ntp_internal_ms_ RTC_GUARDED_BY(&encoder_queue_);
|
2016-09-01 01:17:40 -07:00
|
|
|
|
2021-11-18 16:07:01 +01:00
|
|
|
int64_t last_frame_log_ms_ RTC_GUARDED_BY(&encoder_queue_);
|
2018-02-07 10:18:32 +01:00
|
|
|
int captured_frame_count_ RTC_GUARDED_BY(&encoder_queue_);
|
2020-02-07 14:29:32 +01:00
|
|
|
int dropped_frame_cwnd_pushback_count_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
int dropped_frame_encoder_block_count_ RTC_GUARDED_BY(&encoder_queue_);
|
2018-06-15 12:28:07 +02:00
|
|
|
absl::optional<VideoFrame> pending_frame_ RTC_GUARDED_BY(&encoder_queue_);
|
2018-04-10 13:05:49 +02:00
|
|
|
int64_t pending_frame_post_time_us_ RTC_GUARDED_BY(&encoder_queue_);
|
2016-09-12 00:10:45 -07:00
|
|
|
|
2019-02-18 13:01:26 +01:00
|
|
|
VideoFrame::UpdateRect accumulated_update_rect_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2019-10-30 11:19:47 +01:00
|
|
|
bool accumulated_update_rect_is_valid_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-02-18 13:01:26 +01:00
|
|
|
|
2019-12-03 16:54:17 +01:00
|
|
|
// Used for automatic content type detection.
|
|
|
|
|
absl::optional<VideoFrame::UpdateRect> last_update_rect_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
Timestamp animation_start_time_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
bool cap_resolution_due_to_video_content_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
// Used to correctly ignore changes in update_rect introduced by
|
|
|
|
|
// resize triggered by animation detection.
|
|
|
|
|
enum class ExpectResizeState {
|
|
|
|
|
kNoResize, // Normal operation.
|
|
|
|
|
kResize, // Resize was triggered by the animation detection.
|
|
|
|
|
kFirstFrameAfterResize // Resize observed.
|
|
|
|
|
} expect_resize_state_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
FecControllerOverride* fec_controller_override_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2018-06-15 12:28:07 +02:00
|
|
|
absl::optional<int64_t> last_parameters_update_ms_
|
2018-02-07 10:18:32 +01:00
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2019-03-25 12:06:59 +01:00
|
|
|
absl::optional<int64_t> last_encode_info_ms_ RTC_GUARDED_BY(&encoder_queue_);
|
2016-12-01 06:34:11 -08:00
|
|
|
|
2018-10-24 11:32:39 +02:00
|
|
|
VideoEncoder::EncoderInfo encoder_info_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-02-26 18:31:00 +01:00
|
|
|
VideoCodec send_codec_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-01-11 11:11:10 +01:00
|
|
|
|
2019-02-26 18:31:00 +01:00
|
|
|
FrameDropper frame_dropper_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-01-11 11:11:10 +01:00
|
|
|
// If frame dropper is not force disabled, frame dropping might still be
|
|
|
|
|
// disabled if VideoEncoder::GetEncoderInfo() indicates that the encoder has a
|
|
|
|
|
// trusted rate controller. This is determined on a per-frame basis, as the
|
|
|
|
|
// encoder behavior might dynamically change.
|
|
|
|
|
bool force_disable_frame_dropper_ RTC_GUARDED_BY(&encoder_queue_);
|
2021-07-27 16:22:11 +02:00
|
|
|
// Incremented on worker thread whenever `frame_dropper_` determines that a
|
2019-01-11 11:11:10 +01:00
|
|
|
// frame should be dropped. Decremented on whichever thread runs
|
|
|
|
|
// OnEncodedImage(), which is only called by one thread but not necessarily
|
|
|
|
|
// the worker thread.
|
|
|
|
|
std::atomic<int> pending_frame_drops_;
|
2018-10-24 11:32:39 +02:00
|
|
|
|
2020-02-07 14:29:32 +01:00
|
|
|
// Congestion window frame drop ratio (drop 1 in every
|
|
|
|
|
// cwnd_frame_drop_interval_ frames).
|
|
|
|
|
absl::optional<int> cwnd_frame_drop_interval_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
// Frame counter for congestion window frame drop.
|
|
|
|
|
int cwnd_frame_counter_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
|
2019-02-06 16:20:17 +01:00
|
|
|
std::unique_ptr<EncoderBitrateAdjuster> bitrate_adjuster_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
|
2019-02-21 21:19:53 +01:00
|
|
|
// TODO(sprang): Change actually support keyframe per simulcast stream, or
|
2021-07-27 16:22:11 +02:00
|
|
|
// turn this into a simple bool `pending_keyframe_request_`.
|
2019-03-07 10:18:23 +01:00
|
|
|
std::vector<VideoFrameType> next_frame_types_ RTC_GUARDED_BY(&encoder_queue_);
|
2019-02-21 21:19:53 +01:00
|
|
|
|
2019-05-13 16:13:36 +02:00
|
|
|
FrameEncodeMetadataWriter frame_encode_metadata_writer_;
|
2019-02-26 18:31:00 +01:00
|
|
|
|
|
|
|
|
// Experiment groups parsed from field trials for realtime video ([0]) and
|
|
|
|
|
// screenshare ([1]). 0 means no group specified. Positive values are
|
|
|
|
|
// experiment group numbers incremented by 1.
|
|
|
|
|
const std::array<uint8_t, 2> experiment_groups_;
|
|
|
|
|
|
2019-12-03 16:54:17 +01:00
|
|
|
struct AutomaticAnimationDetectionExperiment {
|
|
|
|
|
bool enabled = false;
|
|
|
|
|
int min_duration_ms = 2000;
|
|
|
|
|
double min_area_ratio = 0.8;
|
|
|
|
|
int min_fps = 10;
|
|
|
|
|
std::unique_ptr<StructParametersParser> Parser() {
|
|
|
|
|
return StructParametersParser::Create(
|
|
|
|
|
"enabled", &enabled, //
|
|
|
|
|
"min_duration_ms", &min_duration_ms, //
|
|
|
|
|
"min_area_ratio", &min_area_ratio, //
|
|
|
|
|
"min_fps", &min_fps);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AutomaticAnimationDetectionExperiment
|
|
|
|
|
ParseAutomatincAnimationDetectionFieldTrial() const;
|
|
|
|
|
|
|
|
|
|
AutomaticAnimationDetectionExperiment
|
|
|
|
|
automatic_animation_detection_experiment_ RTC_GUARDED_BY(&encoder_queue_);
|
|
|
|
|
|
2021-03-29 14:09:04 +02:00
|
|
|
// Provides video stream input states: current resolution and frame rate.
|
2020-05-11 16:29:22 +02:00
|
|
|
VideoStreamInputStateProvider input_state_provider_;
|
2020-07-01 11:47:46 +02:00
|
|
|
|
2022-01-25 23:41:22 +01:00
|
|
|
const std::unique_ptr<VideoStreamAdapter> video_stream_adapter_
|
2020-08-25 13:12:12 +02:00
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2020-04-17 18:36:19 +02:00
|
|
|
// Responsible for adapting input resolution or frame rate to ensure resources
|
2020-08-25 13:12:12 +02:00
|
|
|
// (e.g. CPU or bandwidth) are not overused. Adding resources can occur on any
|
|
|
|
|
// thread.
|
2020-07-09 13:35:33 +02:00
|
|
|
std::unique_ptr<ResourceAdaptationProcessorInterface>
|
2022-01-25 23:41:22 +01:00
|
|
|
resource_adaptation_processor_ RTC_GUARDED_BY(&encoder_queue_);
|
2020-08-25 13:12:12 +02:00
|
|
|
std::unique_ptr<DegradationPreferenceManager> degradation_preference_manager_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2020-06-02 13:02:36 +02:00
|
|
|
std::vector<AdaptationConstraint*> adaptation_constraints_
|
2020-08-25 13:12:12 +02:00
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2020-04-17 18:36:19 +02:00
|
|
|
// Handles input, output and stats reporting related to VideoStreamEncoder
|
|
|
|
|
// specific resources, such as "encode usage percent" measurements and "QP
|
2021-03-29 14:09:04 +02:00
|
|
|
// scaling". Also involved with various mitigations such as initial frame
|
2020-04-17 18:36:19 +02:00
|
|
|
// dropping.
|
2021-07-27 16:22:11 +02:00
|
|
|
// The manager primarily operates on the `encoder_queue_` but its lifetime is
|
2020-08-25 13:12:28 +02:00
|
|
|
// tied to the VideoStreamEncoder (which is destroyed off the encoder queue)
|
|
|
|
|
// and its resource list is accessible from any thread.
|
2020-08-25 13:12:12 +02:00
|
|
|
VideoStreamEncoderResourceManager stream_resource_manager_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2020-08-25 13:12:28 +02:00
|
|
|
std::vector<rtc::scoped_refptr<Resource>> additional_resources_
|
|
|
|
|
RTC_GUARDED_BY(&encoder_queue_);
|
2020-04-17 18:36:19 +02:00
|
|
|
// Carries out the VideoSourceRestrictions provided by the
|
|
|
|
|
// ResourceAdaptationProcessor, i.e. reconfigures the source of video frames
|
|
|
|
|
// to provide us with different resolution or frame rate.
|
2020-05-11 16:29:22 +02:00
|
|
|
// This class is thread-safe.
|
2020-09-21 14:31:23 +02:00
|
|
|
VideoSourceSinkController video_source_sink_controller_
|
2021-10-28 15:29:42 +02:00
|
|
|
RTC_GUARDED_BY(worker_queue_);
|
2020-01-07 10:11:17 +01:00
|
|
|
|
2021-02-25 10:39:51 +01:00
|
|
|
// Default bitrate limits in EncoderInfoSettings allowed.
|
|
|
|
|
const bool default_limits_allowed_;
|
|
|
|
|
|
2021-03-15 10:12:57 +01:00
|
|
|
// QP parser is used to extract QP value from encoded frame when that is not
|
|
|
|
|
// provided by encoder.
|
|
|
|
|
QpParser qp_parser_;
|
|
|
|
|
const bool qp_parsing_allowed_;
|
|
|
|
|
|
2022-01-21 11:35:04 +01:00
|
|
|
// Enables encoder switching on initialization failures.
|
|
|
|
|
bool switch_encoder_on_init_failures_;
|
|
|
|
|
|
2022-04-06 16:44:30 +02:00
|
|
|
const absl::optional<int> vp9_low_tier_core_threshold_;
|
|
|
|
|
|
2020-05-12 18:49:07 +02:00
|
|
|
// Public methods are proxied to the task queues. The queues must be destroyed
|
|
|
|
|
// first to make sure no tasks run that use other members.
|
2019-10-15 11:02:53 +02:00
|
|
|
rtc::TaskQueue encoder_queue_;
|
|
|
|
|
|
2021-10-28 15:29:42 +02:00
|
|
|
// Used to cancel any potentially pending tasks to the worker thread.
|
2020-09-21 14:31:23 +02:00
|
|
|
ScopedTaskSafety task_safety_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2011-12-01 17:02:23 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // VIDEO_VIDEO_STREAM_ENCODER_H_
|