blob: 88cff1b5679a1b6fdd0d4de20999f7170ada64d1 [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
13#include "media/engine/simulcast_encoder_adapter.h"
14#include "modules/video_coding/include/video_error_codes.h"
15
16namespace webrtc {
17EncoderSimulcastProxy::EncoderSimulcastProxy(VideoEncoderFactory* factory,
18 const SdpVideoFormat& format)
19 : factory_(factory), video_format_(format), callback_(nullptr) {
20 encoder_ = factory_->CreateVideoEncoder(format);
21}
22
23EncoderSimulcastProxy::EncoderSimulcastProxy(VideoEncoderFactory* factory)
24 : EncoderSimulcastProxy(factory, SdpVideoFormat("VP8")) {}
25
26EncoderSimulcastProxy::~EncoderSimulcastProxy() {}
27
28int EncoderSimulcastProxy::Release() {
29 return encoder_->Release();
30}
31
32int 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öller87e2d782019-03-07 10:18:23 +010046int EncoderSimulcastProxy::Encode(
47 const VideoFrame& input_image,
48 const std::vector<VideoFrameType>* frame_types) {
Niels Möllerc8d2e732019-03-06 12:00:33 +010049 return encoder_->Encode(input_image, frame_types);
Florent Castellie7862cc2018-12-06 13:38:24 +010050}
51
52int EncoderSimulcastProxy::RegisterEncodeCompleteCallback(
53 EncodedImageCallback* callback) {
54 callback_ = callback;
55 return encoder_->RegisterEncodeCompleteCallback(callback);
56}
57
Erik Språng16cb8f52019-04-12 13:59:09 +020058void EncoderSimulcastProxy::SetRates(const RateControlParameters& parameters) {
Elad Alonfe4f6942019-05-07 23:13:42 +020059 encoder_->SetRates(parameters);
Florent Castellie7862cc2018-12-06 13:38:24 +010060}
61
Elad Alonfb20afd2019-04-10 16:38:16 +020062void EncoderSimulcastProxy::OnPacketLossRateUpdate(float packet_loss_rate) {
Elad Alonfe4f6942019-05-07 23:13:42 +020063 encoder_->OnPacketLossRateUpdate(packet_loss_rate);
Elad Alonfb20afd2019-04-10 16:38:16 +020064}
65
66void EncoderSimulcastProxy::OnRttUpdate(int64_t rtt_ms) {
Elad Alonfe4f6942019-05-07 23:13:42 +020067 encoder_->OnRttUpdate(rtt_ms);
Elad Alonfb20afd2019-04-10 16:38:16 +020068}
69
70void EncoderSimulcastProxy::OnLossNotification(
71 const LossNotification& loss_notification) {
72 encoder_->OnLossNotification(loss_notification);
73}
74
Florent Castellie7862cc2018-12-06 13:38:24 +010075VideoEncoder::EncoderInfo EncoderSimulcastProxy::GetEncoderInfo() const {
76 return encoder_->GetEncoderInfo();
77}
78
79} // namespace webrtc