#include "media/engine/simulcast_encoder_adapter.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "absl/algorithm/container.h"
#include "absl/base/nullability.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/environment/environment.h"
#include "api/fec_controller_override.h"
#include "api/field_trials_view.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/units/data_rate.h"
#include "api/units/timestamp.h"
#include "api/video/encoded_image.h"
#include "api/video/video_bitrate_allocation.h"
#include "api/video/video_bitrate_allocator.h"
#include "api/video/video_codec_constants.h"
#include "api/video/video_codec_type.h"
#include "api/video/video_frame.h"
#include "api/video/video_frame_buffer.h"
#include "api/video/video_frame_type.h"
#include "api/video/video_rotation.h"
#include "api/video_codecs/scalability_mode.h"
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/simulcast_stream.h"
#include "api/video_codecs/video_codec.h"
#include "api/video_codecs/video_encoder.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "api/video_codecs/video_encoder_software_fallback_wrapper.h"
#include "common_video/framerate_controller.h"
#include "media/base/sdp_video_format_utils.h"
#include "media/base/video_common.h"
#include "modules/video_coding/include/video_error_codes.h"
#include "modules/video_coding/include/video_error_codes_utils.h"
#include "modules/video_coding/utility/simulcast_rate_allocator.h"
#include "rtc_base/checks.h"
#include "rtc_base/experiments/rate_control_settings.h"
#include "rtc_base/logging.h"
namespace webrtc {
namespace {
const unsigned int kLowestResMaxQp = …;
uint32_t SumStreamMaxBitrate(int streams, const VideoCodec& codec) { … }
int CountAllStreams(const VideoCodec& codec) { … }
int CountActiveStreams(const VideoCodec& codec) { … }
int VerifyCodec(const VideoCodec* codec_settings) { … }
bool StreamQualityCompare(const SimulcastStream& a, const SimulcastStream& b) { … }
void GetLowestAndHighestQualityStreamIndixes(
rtc::ArrayView<const SimulcastStream> streams,
int* lowest_quality_stream_idx,
int* highest_quality_stream_idx) { … }
std::vector<uint32_t> GetStreamStartBitratesKbps(const Environment& env,
const VideoCodec& codec) { … }
}
SimulcastEncoderAdapter::EncoderContext::EncoderContext(
std::unique_ptr<VideoEncoder> encoder,
bool prefer_temporal_support,
VideoEncoder::EncoderInfo primary_info,
VideoEncoder::EncoderInfo fallback_info)
: … { … }
void SimulcastEncoderAdapter::EncoderContext::Release() { … }
SimulcastEncoderAdapter::StreamContext::StreamContext(
SimulcastEncoderAdapter* parent,
std::unique_ptr<EncoderContext> encoder_context,
std::unique_ptr<FramerateController> framerate_controller,
int stream_idx,
uint16_t width,
uint16_t height,
bool is_paused)
: … { … }
SimulcastEncoderAdapter::StreamContext::StreamContext(StreamContext&& rhs)
: … { … }
SimulcastEncoderAdapter::StreamContext::~StreamContext() { … }
std::unique_ptr<SimulcastEncoderAdapter::EncoderContext>
SimulcastEncoderAdapter::StreamContext::ReleaseEncoderContext() && { … }
void SimulcastEncoderAdapter::StreamContext::OnKeyframe(Timestamp timestamp) { … }
bool SimulcastEncoderAdapter::StreamContext::ShouldDropFrame(
Timestamp timestamp) { … }
EncodedImageCallback::Result
SimulcastEncoderAdapter::StreamContext::OnEncodedImage(
const EncodedImage& encoded_image,
const CodecSpecificInfo* codec_specific_info) { … }
void SimulcastEncoderAdapter::StreamContext::OnDroppedFrame(
DropReason ) { … }
SimulcastEncoderAdapter::SimulcastEncoderAdapter(
const Environment& env,
absl::Nonnull<VideoEncoderFactory*> primary_factory,
absl::Nullable<VideoEncoderFactory*> fallback_factory,
const SdpVideoFormat& format)
: … { … }
SimulcastEncoderAdapter::~SimulcastEncoderAdapter() { … }
void SimulcastEncoderAdapter::SetFecControllerOverride(
FecControllerOverride* ) { … }
int SimulcastEncoderAdapter::Release() { … }
int SimulcastEncoderAdapter::InitEncode(
const VideoCodec* codec_settings,
const VideoEncoder::Settings& settings) { … }
int SimulcastEncoderAdapter::Encode(
const VideoFrame& input_image,
const std::vector<VideoFrameType>* frame_types) { … }
int SimulcastEncoderAdapter::RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) { … }
void SimulcastEncoderAdapter::SetRates(
const RateControlParameters& parameters) { … }
void SimulcastEncoderAdapter::OnPacketLossRateUpdate(float packet_loss_rate) { … }
void SimulcastEncoderAdapter::OnRttUpdate(int64_t rtt_ms) { … }
void SimulcastEncoderAdapter::OnLossNotification(
const LossNotification& loss_notification) { … }
EncodedImageCallback::Result SimulcastEncoderAdapter::OnEncodedImage(
size_t stream_idx,
const EncodedImage& encodedImage,
const CodecSpecificInfo* codecSpecificInfo) { … }
void SimulcastEncoderAdapter::OnDroppedFrame(size_t stream_idx) { … }
bool SimulcastEncoderAdapter::Initialized() const { … }
void SimulcastEncoderAdapter::DestroyStoredEncoders() { … }
std::unique_ptr<SimulcastEncoderAdapter::EncoderContext>
SimulcastEncoderAdapter::FetchOrCreateEncoderContext(
bool is_lowest_quality_stream) const { … }
webrtc::VideoCodec SimulcastEncoderAdapter::MakeStreamCodec(
const webrtc::VideoCodec& codec,
int stream_idx,
uint32_t start_bitrate_kbps,
bool is_lowest_quality_stream,
bool is_highest_quality_stream) { … }
void SimulcastEncoderAdapter::OverrideFromFieldTrial(
VideoEncoder::EncoderInfo* info) const { … }
VideoEncoder::EncoderInfo SimulcastEncoderAdapter::GetEncoderInfo() const { … }
}