blob: 7a6638f56f639118bebe0cae7248dbec85bc483f [file] [log] [blame]
Florent Castellie7862cc2018-12-06 13:38:24 +01001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "media/engine/encoder_simulcast_proxy.h"
12
Elad Alon370f93a2019-06-11 14:57:57 +020013#include "api/video_codecs/video_encoder.h"
Florent Castellie7862cc2018-12-06 13:38:24 +010014#include "media/engine/simulcast_encoder_adapter.h"
15#include "modules/video_coding/include/video_error_codes.h"
16
17namespace webrtc {
Elad Alon370f93a2019-06-11 14:57:57 +020018
Florent Castellie7862cc2018-12-06 13:38:24 +010019EncoderSimulcastProxy::EncoderSimulcastProxy(VideoEncoderFactory* factory,
20 const SdpVideoFormat& format)
21 : factory_(factory), video_format_(format), callback_(nullptr) {
22 encoder_ = factory_->CreateVideoEncoder(format);
23}
24
25EncoderSimulcastProxy::EncoderSimulcastProxy(VideoEncoderFactory* factory)
26 : EncoderSimulcastProxy(factory, SdpVideoFormat("VP8")) {}
27
28EncoderSimulcastProxy::~EncoderSimulcastProxy() {}
29
30int EncoderSimulcastProxy::Release() {
31 return encoder_->Release();
32}
33
Elad Alon8f01c4e2019-06-28 15:19:43 +020034void EncoderSimulcastProxy::SetFecControllerOverride(
35 FecControllerOverride* fec_controller_override) {
36 encoder_->SetFecControllerOverride(fec_controller_override);
37}
38
Elad Alon370f93a2019-06-11 14:57:57 +020039// TODO(eladalon): s/inst/codec_settings/g.
Florent Castellie7862cc2018-12-06 13:38:24 +010040int EncoderSimulcastProxy::InitEncode(const VideoCodec* inst,
Elad Alon370f93a2019-06-11 14:57:57 +020041 const VideoEncoder::Settings& settings) {
42 int ret = encoder_->InitEncode(inst, settings);
Florent Castellie7862cc2018-12-06 13:38:24 +010043 if (ret == WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED) {
44 encoder_.reset(new SimulcastEncoderAdapter(factory_, video_format_));
45 if (callback_) {
46 encoder_->RegisterEncodeCompleteCallback(callback_);
47 }
Elad Alon370f93a2019-06-11 14:57:57 +020048 ret = encoder_->InitEncode(inst, settings);
Florent Castellie7862cc2018-12-06 13:38:24 +010049 }
50 return ret;
51}
52
Niels Möller87e2d782019-03-07 10:18:23 +010053int EncoderSimulcastProxy::Encode(
54 const VideoFrame& input_image,
55 const std::vector<VideoFrameType>* frame_types) {
Niels Möllerc8d2e732019-03-06 12:00:33 +010056 return encoder_->Encode(input_image, frame_types);
Florent Castellie7862cc2018-12-06 13:38:24 +010057}
58
59int EncoderSimulcastProxy::RegisterEncodeCompleteCallback(
60 EncodedImageCallback* callback) {
61 callback_ = callback;
62 return encoder_->RegisterEncodeCompleteCallback(callback);
63}
64
Erik Språng16cb8f52019-04-12 13:59:09 +020065void EncoderSimulcastProxy::SetRates(const RateControlParameters& parameters) {
Elad Alonfe4f6942019-05-07 23:13:42 +020066 encoder_->SetRates(parameters);
Florent Castellie7862cc2018-12-06 13:38:24 +010067}
68
Elad Alonfb20afd2019-04-10 16:38:16 +020069void EncoderSimulcastProxy::OnPacketLossRateUpdate(float packet_loss_rate) {
Elad Alonfe4f6942019-05-07 23:13:42 +020070 encoder_->OnPacketLossRateUpdate(packet_loss_rate);
Elad Alonfb20afd2019-04-10 16:38:16 +020071}
72
73void EncoderSimulcastProxy::OnRttUpdate(int64_t rtt_ms) {
Elad Alonfe4f6942019-05-07 23:13:42 +020074 encoder_->OnRttUpdate(rtt_ms);
Elad Alonfb20afd2019-04-10 16:38:16 +020075}
76
77void EncoderSimulcastProxy::OnLossNotification(
78 const LossNotification& loss_notification) {
79 encoder_->OnLossNotification(loss_notification);
80}
81
Florent Castellie7862cc2018-12-06 13:38:24 +010082VideoEncoder::EncoderInfo EncoderSimulcastProxy::GetEncoderInfo() const {
83 return encoder_->GetEncoderInfo();
84}
85
86} // namespace webrtc