blob: 3650e739bd03ce90599ca795e8025bae9601dce2 [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 Alon11dfff02019-06-10 19:10:29 +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 Alon11dfff02019-06-10 19:10:29 +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
34int EncoderSimulcastProxy::InitEncode(const VideoCodec* inst,
35 int number_of_cores,
36 size_t max_payload_size) {
Elad Alon11dfff02019-06-10 19:10:29 +020037 RTC_NOTREACHED();
38 return WEBRTC_VIDEO_CODEC_ERROR;
39}
40
41// TODO(eladalon): s/inst/codec_settings/g.
42int EncoderSimulcastProxy::InitEncode(const VideoCodec* inst,
43 const VideoEncoder::Settings& settings) {
44 int ret = encoder_->InitEncode(inst, settings);
Florent Castellie7862cc2018-12-06 13:38:24 +010045 if (ret == WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED) {
46 encoder_.reset(new SimulcastEncoderAdapter(factory_, video_format_));
47 if (callback_) {
48 encoder_->RegisterEncodeCompleteCallback(callback_);
49 }
Elad Alon11dfff02019-06-10 19:10:29 +020050 ret = encoder_->InitEncode(inst, settings);
Florent Castellie7862cc2018-12-06 13:38:24 +010051 }
52 return ret;
53}
54
Niels Möller87e2d782019-03-07 10:18:23 +010055int EncoderSimulcastProxy::Encode(
56 const VideoFrame& input_image,
57 const std::vector<VideoFrameType>* frame_types) {
Niels Möllerc8d2e732019-03-06 12:00:33 +010058 return encoder_->Encode(input_image, frame_types);
Florent Castellie7862cc2018-12-06 13:38:24 +010059}
60
61int EncoderSimulcastProxy::RegisterEncodeCompleteCallback(
62 EncodedImageCallback* callback) {
63 callback_ = callback;
64 return encoder_->RegisterEncodeCompleteCallback(callback);
65}
66
Erik Språng16cb8f52019-04-12 13:59:09 +020067void EncoderSimulcastProxy::SetRates(const RateControlParameters& parameters) {
Elad Alonfe4f6942019-05-07 23:13:42 +020068 encoder_->SetRates(parameters);
Florent Castellie7862cc2018-12-06 13:38:24 +010069}
70
Elad Alonfb20afd2019-04-10 16:38:16 +020071void EncoderSimulcastProxy::OnPacketLossRateUpdate(float packet_loss_rate) {
Elad Alonfe4f6942019-05-07 23:13:42 +020072 encoder_->OnPacketLossRateUpdate(packet_loss_rate);
Elad Alonfb20afd2019-04-10 16:38:16 +020073}
74
75void EncoderSimulcastProxy::OnRttUpdate(int64_t rtt_ms) {
Elad Alonfe4f6942019-05-07 23:13:42 +020076 encoder_->OnRttUpdate(rtt_ms);
Elad Alonfb20afd2019-04-10 16:38:16 +020077}
78
79void EncoderSimulcastProxy::OnLossNotification(
80 const LossNotification& loss_notification) {
81 encoder_->OnLossNotification(loss_notification);
82}
83
Florent Castellie7862cc2018-12-06 13:38:24 +010084VideoEncoder::EncoderInfo EncoderSimulcastProxy::GetEncoderInfo() const {
85 return encoder_->GetEncoderInfo();
86}
87
88} // namespace webrtc