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 | |
| 58 | int EncoderSimulcastProxy::SetRateAllocation( |
| 59 | const VideoBitrateAllocation& bitrate, |
| 60 | uint32_t new_framerate) { |
| 61 | return encoder_->SetRateAllocation(bitrate, new_framerate); |
| 62 | } |
| 63 | |
| 64 | VideoEncoder::EncoderInfo EncoderSimulcastProxy::GetEncoderInfo() const { |
| 65 | return encoder_->GetEncoderInfo(); |
| 66 | } |
| 67 | |
| 68 | } // namespace webrtc |