blob: da769a9c8556fca433c01459d4864962d78daed4 [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 Alon370f93a2019-06-11 14:57:57 +020034// TODO(eladalon): s/inst/codec_settings/g.
Florent Castellie7862cc2018-12-06 13:38:24 +010035int EncoderSimulcastProxy::InitEncode(const VideoCodec* inst,
Elad Alon370f93a2019-06-11 14:57:57 +020036 const VideoEncoder::Settings& settings) {
37 int ret = encoder_->InitEncode(inst, settings);
Florent Castellie7862cc2018-12-06 13:38:24 +010038 if (ret == WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED) {
39 encoder_.reset(new SimulcastEncoderAdapter(factory_, video_format_));
40 if (callback_) {
41 encoder_->RegisterEncodeCompleteCallback(callback_);
42 }
Elad Alon370f93a2019-06-11 14:57:57 +020043 ret = encoder_->InitEncode(inst, settings);
Florent Castellie7862cc2018-12-06 13:38:24 +010044 }
45 return ret;
46}
47
Niels Möller87e2d782019-03-07 10:18:23 +010048int EncoderSimulcastProxy::Encode(
49 const VideoFrame& input_image,
50 const std::vector<VideoFrameType>* frame_types) {
Niels Möllerc8d2e732019-03-06 12:00:33 +010051 return encoder_->Encode(input_image, frame_types);
Florent Castellie7862cc2018-12-06 13:38:24 +010052}
53
54int EncoderSimulcastProxy::RegisterEncodeCompleteCallback(
55 EncodedImageCallback* callback) {
56 callback_ = callback;
57 return encoder_->RegisterEncodeCompleteCallback(callback);
58}
59
Erik Språng16cb8f52019-04-12 13:59:09 +020060void EncoderSimulcastProxy::SetRates(const RateControlParameters& parameters) {
Elad Alonfe4f6942019-05-07 23:13:42 +020061 encoder_->SetRates(parameters);
Florent Castellie7862cc2018-12-06 13:38:24 +010062}
63
Elad Alonfb20afd2019-04-10 16:38:16 +020064void EncoderSimulcastProxy::OnPacketLossRateUpdate(float packet_loss_rate) {
Elad Alonfe4f6942019-05-07 23:13:42 +020065 encoder_->OnPacketLossRateUpdate(packet_loss_rate);
Elad Alonfb20afd2019-04-10 16:38:16 +020066}
67
68void EncoderSimulcastProxy::OnRttUpdate(int64_t rtt_ms) {
Elad Alonfe4f6942019-05-07 23:13:42 +020069 encoder_->OnRttUpdate(rtt_ms);
Elad Alonfb20afd2019-04-10 16:38:16 +020070}
71
72void EncoderSimulcastProxy::OnLossNotification(
73 const LossNotification& loss_notification) {
74 encoder_->OnLossNotification(loss_notification);
75}
76
Florent Castellie7862cc2018-12-06 13:38:24 +010077VideoEncoder::EncoderInfo EncoderSimulcastProxy::GetEncoderInfo() const {
78 return encoder_->GetEncoderInfo();
79}
80
81} // namespace webrtc