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