#include "remoting/protocol/webrtc_video_encoder_wrapper.h"
#include <stdint.h>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "remoting/base/constants.h"
#include "remoting/base/session_options.h"
#include "remoting/codec/webrtc_video_encoder_av1.h"
#include "remoting/codec/webrtc_video_encoder_vpx.h"
#include "remoting/protocol/video_stream_event_router.h"
#include "remoting/protocol/webrtc_video_frame_adapter.h"
#include "third_party/webrtc/api/video_codecs/av1_profile.h"
#include "third_party/webrtc/api/video_codecs/sdp_video_format.h"
#include "third_party/webrtc/api/video_codecs/vp9_profile.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
#include "third_party/webrtc/modules/video_coding/include/video_codec_interface.h"
#include "third_party/webrtc/modules/video_coding/include/video_error_codes.h"
#if defined(USE_H264_ENCODER)
#include "remoting/codec/webrtc_video_encoder_gpu.h"
#endif
namespace remoting::protocol {
namespace {
const int kMaxQuantizer = …;
const int kMinQuantizer = …;
const int64_t kPixelsPerMegapixel = …;
const int kBigFrameThresholdPixels = …;
const int kEstimatedBytesPerMegapixel = …;
constexpr base::TimeDelta kKeepAliveInterval = …;
constexpr auto kMinFrameDuration = …;
constexpr auto kMaxFrameDuration = …;
std::string EncodeResultToString(WebrtcVideoEncoder::EncodeResult result) { … }
}
WebrtcVideoEncoderWrapper::WebrtcVideoEncoderWrapper(
const webrtc::SdpVideoFormat& format,
const SessionOptions& session_options,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
base::WeakPtr<VideoStreamEventRouter> video_stream_event_router)
: … { … }
WebrtcVideoEncoderWrapper::~WebrtcVideoEncoderWrapper() { … }
void WebrtcVideoEncoderWrapper::SetEncoderForTest(
std::unique_ptr<WebrtcVideoEncoder> encoder) { … }
int32_t WebrtcVideoEncoderWrapper::InitEncode(
const webrtc::VideoCodec* codec_settings,
const webrtc::VideoEncoder::Settings& settings) { … }
int32_t WebrtcVideoEncoderWrapper::RegisterEncodeCompleteCallback(
webrtc::EncodedImageCallback* callback) { … }
int32_t WebrtcVideoEncoderWrapper::Release() { … }
int32_t WebrtcVideoEncoderWrapper::Encode(
const webrtc::VideoFrame& frame,
const std::vector<webrtc::VideoFrameType>* frame_types) { … }
void WebrtcVideoEncoderWrapper::SetRates(
const RateControlParameters& parameters) { … }
void WebrtcVideoEncoderWrapper::OnRttUpdate(int64_t rtt_ms) { … }
webrtc::VideoEncoder::EncoderInfo WebrtcVideoEncoderWrapper::GetEncoderInfo()
const { … }
webrtc::EncodedImageCallback::Result
WebrtcVideoEncoderWrapper::ReturnEncodedFrame(
const WebrtcVideoEncoder::EncodedFrame& frame) { … }
void WebrtcVideoEncoderWrapper::OnFrameEncoded(
WebrtcVideoEncoder::EncodeResult encode_result,
std::unique_ptr<WebrtcVideoEncoder::EncodedFrame> encoded_frame) { … }
void WebrtcVideoEncoderWrapper::NotifyFrameDropped() { … }
bool WebrtcVideoEncoderWrapper::ShouldDropQualityForLargeFrame(
const webrtc::DesktopFrame& frame) { … }
void WebrtcVideoEncoderWrapper::SchedulePendingFrame() { … }
void WebrtcVideoEncoderWrapper::DropPendingFrame() { … }
}