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 | 11dfff0 | 2019-06-10 19:10:29 +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 | 11dfff0 | 2019-06-10 19:10:29 +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 | |
| 34 | int EncoderSimulcastProxy::InitEncode(const VideoCodec* inst, |
| 35 | int number_of_cores, |
| 36 | size_t max_payload_size) { |
Elad Alon | 11dfff0 | 2019-06-10 19:10:29 +0200 | [diff] [blame^] | 37 | RTC_NOTREACHED(); |
| 38 | return WEBRTC_VIDEO_CODEC_ERROR; |
| 39 | } |
| 40 | |
| 41 | // TODO(eladalon): s/inst/codec_settings/g. |
| 42 | int EncoderSimulcastProxy::InitEncode(const VideoCodec* inst, |
| 43 | const VideoEncoder::Settings& settings) { |
| 44 | int ret = encoder_->InitEncode(inst, settings); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 45 | 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 Alon | 11dfff0 | 2019-06-10 19:10:29 +0200 | [diff] [blame^] | 50 | ret = encoder_->InitEncode(inst, settings); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 51 | } |
| 52 | return ret; |
| 53 | } |
| 54 | |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 55 | int EncoderSimulcastProxy::Encode( |
| 56 | const VideoFrame& input_image, |
| 57 | const std::vector<VideoFrameType>* frame_types) { |
Niels Möller | c8d2e73 | 2019-03-06 12:00:33 +0100 | [diff] [blame] | 58 | return encoder_->Encode(input_image, frame_types); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | int EncoderSimulcastProxy::RegisterEncodeCompleteCallback( |
| 62 | EncodedImageCallback* callback) { |
| 63 | callback_ = callback; |
| 64 | return encoder_->RegisterEncodeCompleteCallback(callback); |
| 65 | } |
| 66 | |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 67 | void EncoderSimulcastProxy::SetRates(const RateControlParameters& parameters) { |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 68 | encoder_->SetRates(parameters); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Elad Alon | fb20afd | 2019-04-10 16:38:16 +0200 | [diff] [blame] | 71 | void EncoderSimulcastProxy::OnPacketLossRateUpdate(float packet_loss_rate) { |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 72 | encoder_->OnPacketLossRateUpdate(packet_loss_rate); |
Elad Alon | fb20afd | 2019-04-10 16:38:16 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void EncoderSimulcastProxy::OnRttUpdate(int64_t rtt_ms) { |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 76 | encoder_->OnRttUpdate(rtt_ms); |
Elad Alon | fb20afd | 2019-04-10 16:38:16 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void EncoderSimulcastProxy::OnLossNotification( |
| 80 | const LossNotification& loss_notification) { |
| 81 | encoder_->OnLossNotification(loss_notification); |
| 82 | } |
| 83 | |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 84 | VideoEncoder::EncoderInfo EncoderSimulcastProxy::GetEncoderInfo() const { |
| 85 | return encoder_->GetEncoderInfo(); |
| 86 | } |
| 87 | |
| 88 | } // namespace webrtc |