Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 1 | /* |
| 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 Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 13 | #include "api/video_codecs/video_encoder.h" |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 14 | #include "media/engine/simulcast_encoder_adapter.h" |
| 15 | #include "modules/video_coding/include/video_error_codes.h" |
| 16 | |
| 17 | namespace webrtc { |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 18 | |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 19 | EncoderSimulcastProxy::EncoderSimulcastProxy(VideoEncoderFactory* factory, |
| 20 | const SdpVideoFormat& format) |
| 21 | : factory_(factory), video_format_(format), callback_(nullptr) { |
| 22 | encoder_ = factory_->CreateVideoEncoder(format); |
| 23 | } |
| 24 | |
| 25 | EncoderSimulcastProxy::EncoderSimulcastProxy(VideoEncoderFactory* factory) |
| 26 | : EncoderSimulcastProxy(factory, SdpVideoFormat("VP8")) {} |
| 27 | |
| 28 | EncoderSimulcastProxy::~EncoderSimulcastProxy() {} |
| 29 | |
| 30 | int EncoderSimulcastProxy::Release() { |
| 31 | return encoder_->Release(); |
| 32 | } |
| 33 | |
Elad Alon | 8f01c4e | 2019-06-28 15:19:43 +0200 | [diff] [blame] | 34 | void EncoderSimulcastProxy::SetFecControllerOverride( |
| 35 | FecControllerOverride* fec_controller_override) { |
| 36 | encoder_->SetFecControllerOverride(fec_controller_override); |
| 37 | } |
| 38 | |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 39 | // TODO(eladalon): s/inst/codec_settings/g. |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 40 | int EncoderSimulcastProxy::InitEncode(const VideoCodec* inst, |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 41 | const VideoEncoder::Settings& settings) { |
| 42 | int ret = encoder_->InitEncode(inst, settings); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 43 | 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 Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 48 | ret = encoder_->InitEncode(inst, settings); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 49 | } |
| 50 | return ret; |
| 51 | } |
| 52 | |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 53 | int EncoderSimulcastProxy::Encode( |
| 54 | const VideoFrame& input_image, |
| 55 | const std::vector<VideoFrameType>* frame_types) { |
Niels Möller | c8d2e73 | 2019-03-06 12:00:33 +0100 | [diff] [blame] | 56 | return encoder_->Encode(input_image, frame_types); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | int EncoderSimulcastProxy::RegisterEncodeCompleteCallback( |
| 60 | EncodedImageCallback* callback) { |
| 61 | callback_ = callback; |
| 62 | return encoder_->RegisterEncodeCompleteCallback(callback); |
| 63 | } |
| 64 | |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 65 | void EncoderSimulcastProxy::SetRates(const RateControlParameters& parameters) { |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 66 | encoder_->SetRates(parameters); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Elad Alon | fb20afd | 2019-04-10 16:38:16 +0200 | [diff] [blame] | 69 | void EncoderSimulcastProxy::OnPacketLossRateUpdate(float packet_loss_rate) { |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 70 | encoder_->OnPacketLossRateUpdate(packet_loss_rate); |
Elad Alon | fb20afd | 2019-04-10 16:38:16 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void EncoderSimulcastProxy::OnRttUpdate(int64_t rtt_ms) { |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 74 | encoder_->OnRttUpdate(rtt_ms); |
Elad Alon | fb20afd | 2019-04-10 16:38:16 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void EncoderSimulcastProxy::OnLossNotification( |
| 78 | const LossNotification& loss_notification) { |
| 79 | encoder_->OnLossNotification(loss_notification); |
| 80 | } |
| 81 | |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 82 | VideoEncoder::EncoderInfo EncoderSimulcastProxy::GetEncoderInfo() const { |
| 83 | return encoder_->GetEncoderInfo(); |
| 84 | } |
| 85 | |
| 86 | } // namespace webrtc |