2018-05-21 14:09:31 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_
|
|
|
|
|
#define API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-06-11 12:07:14 +02:00
|
|
|
#include "api/adaptation/resource.h"
|
2019-06-28 15:19:43 +02:00
|
|
|
#include "api/fec_controller_override.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/rtp_parameters.h" // For DegradationPreference.
|
2020-06-11 12:07:14 +02:00
|
|
|
#include "api/scoped_refptr.h"
|
2019-03-06 15:37:33 +01:00
|
|
|
#include "api/units/data_rate.h"
|
2019-01-22 10:35:42 +01:00
|
|
|
#include "api/video/video_bitrate_allocator.h"
|
2020-10-15 17:53:22 +02:00
|
|
|
#include "api/video/video_layers_allocation.h"
|
2018-05-21 14:09:31 +02:00
|
|
|
#include "api/video/video_sink_interface.h"
|
|
|
|
|
#include "api/video/video_source_interface.h"
|
|
|
|
|
#include "api/video_codecs/video_encoder.h"
|
|
|
|
|
#include "api/video_codecs/video_encoder_config.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// This interface represents a class responsible for creating and driving the
|
|
|
|
|
// encoder(s) for a single video stream. It is also responsible for adaptation
|
|
|
|
|
// decisions related to video quality, requesting reduced frame rate or
|
|
|
|
|
// resolution from the VideoSource when needed.
|
|
|
|
|
// TODO(bugs.webrtc.org/8830): This interface is under development. Changes
|
|
|
|
|
// under consideration include:
|
|
|
|
|
//
|
|
|
|
|
// 1. Taking out responsibility for adaptation decisions, instead only reporting
|
|
|
|
|
// per-frame measurements to the decision maker.
|
|
|
|
|
//
|
|
|
|
|
// 2. Moving responsibility for simulcast and for software fallback into this
|
|
|
|
|
// class.
|
2021-11-05 12:00:55 +01:00
|
|
|
class VideoStreamEncoderInterface {
|
2018-05-21 14:09:31 +02:00
|
|
|
public:
|
|
|
|
|
// Interface for receiving encoded video frames and notifications about
|
|
|
|
|
// configuration changes.
|
|
|
|
|
class EncoderSink : public EncodedImageCallback {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnEncoderConfigurationChanged(
|
|
|
|
|
std::vector<VideoStream> streams,
|
2020-04-02 14:10:27 +02:00
|
|
|
bool is_svc,
|
2019-02-04 11:09:46 +01:00
|
|
|
VideoEncoderConfig::ContentType content_type,
|
2018-05-21 14:09:31 +02:00
|
|
|
int min_transmit_bitrate_bps) = 0;
|
2020-10-07 15:09:05 +02:00
|
|
|
|
|
|
|
|
virtual void OnBitrateAllocationUpdated(
|
|
|
|
|
const VideoBitrateAllocation& allocation) = 0;
|
2020-10-15 17:53:22 +02:00
|
|
|
|
|
|
|
|
virtual void OnVideoLayersAllocationUpdated(
|
|
|
|
|
VideoLayersAllocation allocation) = 0;
|
2018-05-21 14:09:31 +02:00
|
|
|
};
|
|
|
|
|
|
2021-11-05 12:00:55 +01:00
|
|
|
virtual ~VideoStreamEncoderInterface() = default;
|
|
|
|
|
|
2020-06-11 12:07:14 +02:00
|
|
|
// If the resource is overusing, the VideoStreamEncoder will try to reduce
|
|
|
|
|
// resolution or frame rate until no resource is overusing.
|
|
|
|
|
// TODO(https://crbug.com/webrtc/11565): When the ResourceAdaptationProcessor
|
|
|
|
|
// is moved to Call this method could be deleted altogether in favor of
|
|
|
|
|
// Call-level APIs only.
|
|
|
|
|
virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
|
|
|
|
|
virtual std::vector<rtc::scoped_refptr<Resource>>
|
|
|
|
|
GetAdaptationResources() = 0;
|
|
|
|
|
|
2018-05-21 14:09:31 +02:00
|
|
|
// Sets the source that will provide video frames to the VideoStreamEncoder's
|
2021-07-25 21:50:14 +02:00
|
|
|
// OnFrame method. `degradation_preference` control whether or not resolution
|
2018-05-21 14:09:31 +02:00
|
|
|
// or frame rate may be reduced. The VideoStreamEncoder registers itself with
|
2021-07-25 21:50:14 +02:00
|
|
|
// `source`, and signals adaptation decisions to the source in the form of
|
2018-05-21 14:09:31 +02:00
|
|
|
// VideoSinkWants.
|
2022-07-05 08:55:19 +02:00
|
|
|
// TODO(bugs.webrtc.org/14246): When adaptation logic is extracted from this
|
|
|
|
|
// class, it no longer needs to know the source.
|
2018-05-21 14:09:31 +02:00
|
|
|
virtual void SetSource(
|
|
|
|
|
rtc::VideoSourceInterface<VideoFrame>* source,
|
|
|
|
|
const DegradationPreference& degradation_preference) = 0;
|
|
|
|
|
|
2021-07-25 21:50:14 +02:00
|
|
|
// Sets the `sink` that gets the encoded frames. `rotation_applied` means
|
|
|
|
|
// that the source must support rotation. Only set `rotation_applied` if the
|
2018-05-21 14:09:31 +02:00
|
|
|
// remote side does not support the rotation extension.
|
|
|
|
|
virtual void SetSink(EncoderSink* sink, bool rotation_applied) = 0;
|
|
|
|
|
|
|
|
|
|
// Sets an initial bitrate, later overriden by OnBitrateUpdated. Mainly
|
|
|
|
|
// affects the resolution of the initial key frame: If incoming frames are
|
|
|
|
|
// larger than reasonable for the start bitrate, and scaling is enabled,
|
|
|
|
|
// VideoStreamEncoder asks the source to scale down and drops a few initial
|
|
|
|
|
// frames.
|
|
|
|
|
// TODO(nisse): This is a poor interface, and mixes bandwidth estimation and
|
|
|
|
|
// codec configuration in an undesired way. For the actual send bandwidth, we
|
|
|
|
|
// should always be somewhat conservative, but we may nevertheless want to let
|
|
|
|
|
// the application configure a more optimistic quality for the initial
|
|
|
|
|
// resolution. Should be replaced by a construction time setting.
|
|
|
|
|
virtual void SetStartBitrate(int start_bitrate_bps) = 0;
|
|
|
|
|
|
|
|
|
|
// Request a key frame. Used for signalling from the remote receiver.
|
|
|
|
|
virtual void SendKeyFrame() = 0;
|
|
|
|
|
|
2019-04-10 16:37:07 +02:00
|
|
|
// Inform the encoder that a loss has occurred.
|
|
|
|
|
virtual void OnLossNotification(
|
|
|
|
|
const VideoEncoder::LossNotification& loss_notification) = 0;
|
|
|
|
|
|
2021-07-25 21:50:14 +02:00
|
|
|
// Set the currently estimated network properties. A `target_bitrate`
|
2018-05-21 14:09:31 +02:00
|
|
|
// of zero pauses the encoder.
|
2021-07-25 21:50:14 +02:00
|
|
|
// `stable_target_bitrate` is a filtered version of `target_bitrate`. It is
|
2019-09-09 13:36:55 +02:00
|
|
|
// always less or equal to it. It can be used to avoid rapid changes of
|
|
|
|
|
// expensive encoding settings, such as resolution.
|
2021-07-25 21:50:14 +02:00
|
|
|
// `link_allocation` is the bandwidth available for this video stream on the
|
|
|
|
|
// network link. It is always at least `target_bitrate` but may be higher
|
2019-04-08 15:14:01 +02:00
|
|
|
// if we are not network constrained.
|
2019-03-06 15:37:33 +01:00
|
|
|
virtual void OnBitrateUpdated(DataRate target_bitrate,
|
2019-09-09 13:36:55 +02:00
|
|
|
DataRate stable_target_bitrate,
|
2019-04-08 15:14:01 +02:00
|
|
|
DataRate link_allocation,
|
2018-05-21 14:09:31 +02:00
|
|
|
uint8_t fraction_lost,
|
2020-02-07 14:29:32 +01:00
|
|
|
int64_t round_trip_time_ms,
|
|
|
|
|
double cwnd_reduce_ratio) = 0;
|
2018-05-21 14:09:31 +02:00
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
// Set a FecControllerOverride, through which the encoder may override
|
|
|
|
|
// decisions made by FecController.
|
|
|
|
|
virtual void SetFecControllerOverride(
|
2019-06-28 18:20:58 +02:00
|
|
|
FecControllerOverride* fec_controller_override) = 0;
|
2019-06-28 15:19:43 +02:00
|
|
|
|
2021-07-25 21:50:14 +02:00
|
|
|
// Creates and configures an encoder with the given `config`. The
|
|
|
|
|
// `max_data_payload_length` is used to support single NAL unit
|
2018-05-21 14:09:31 +02:00
|
|
|
// packetization for H.264.
|
|
|
|
|
virtual void ConfigureEncoder(VideoEncoderConfig config,
|
|
|
|
|
size_t max_data_payload_length) = 0;
|
|
|
|
|
|
|
|
|
|
// Permanently stop encoding. After this method has returned, it is
|
|
|
|
|
// guaranteed that no encoded frames will be delivered to the sink.
|
|
|
|
|
virtual void Stop() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_
|