2012-09-20 20:49:12 +00:00
|
|
|
/*
|
2018-03-14 17:52:55 +01:00
|
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
2012-09-20 20:49:12 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-03-14 17:52:55 +01:00
|
|
|
#ifndef MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_VP8_ENCODER_H_
|
|
|
|
|
#define MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_VP8_ENCODER_H_
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-09-12 16:04:43 +02:00
|
|
|
#include <memory>
|
2019-03-06 16:40:42 +01:00
|
|
|
#include <string>
|
2014-12-09 10:36:40 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-10-05 14:17:58 +02:00
|
|
|
#include "api/video/encoded_image.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_frame.h"
|
2018-03-14 17:52:55 +01:00
|
|
|
#include "api/video_codecs/video_encoder.h"
|
2019-03-06 21:14:54 +01:00
|
|
|
#include "api/video_codecs/vp8_frame_buffer_controller.h"
|
2019-01-29 14:05:55 +01:00
|
|
|
#include "api/video_codecs/vp8_frame_config.h"
|
2018-03-14 17:52:55 +01:00
|
|
|
#include "common_types.h" // NOLINT(build/include)
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/codecs/vp8/include/vp8.h"
|
2018-10-04 17:52:36 +02:00
|
|
|
#include "modules/video_coding/codecs/vp8/libvpx_interface.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/include/video_codec_interface.h"
|
2019-03-06 16:40:42 +01:00
|
|
|
#include "modules/video_coding/utility/framerate_controller.h"
|
2018-11-02 11:38:46 +01:00
|
|
|
#include "rtc_base/experiments/cpu_speed_experiment.h"
|
2019-02-13 10:49:37 +01:00
|
|
|
#include "rtc_base/experiments/rate_control_settings.h"
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2018-03-14 17:52:55 +01:00
|
|
|
#include "vpx/vp8cx.h"
|
|
|
|
|
#include "vpx/vpx_encoder.h"
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2018-03-14 17:52:55 +01:00
|
|
|
namespace webrtc {
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2018-10-04 17:52:36 +02:00
|
|
|
class LibvpxVp8Encoder : public VideoEncoder {
|
2012-09-20 20:49:12 +00:00
|
|
|
public:
|
2018-03-14 17:52:55 +01:00
|
|
|
LibvpxVp8Encoder();
|
2018-10-04 17:52:36 +02:00
|
|
|
explicit LibvpxVp8Encoder(std::unique_ptr<LibvpxInterface> interface);
|
2018-03-14 17:52:55 +01:00
|
|
|
~LibvpxVp8Encoder() override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
int Release() override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
int InitEncode(const VideoCodec* codec_settings,
|
|
|
|
|
int number_of_cores,
|
|
|
|
|
size_t max_payload_size) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
int Encode(const VideoFrame& input_image,
|
|
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
|
|
|
const std::vector<FrameType>* frame_types) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2018-04-23 12:32:22 +02:00
|
|
|
int SetRateAllocation(const VideoBitrateAllocation& bitrate,
|
2016-11-16 16:41:30 +01:00
|
|
|
uint32_t new_framerate) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2018-11-07 16:47:06 +01:00
|
|
|
EncoderInfo GetEncoderInfo() const override;
|
2015-12-18 16:01:11 +01:00
|
|
|
|
2019-01-29 14:05:55 +01:00
|
|
|
static vpx_enc_frame_flags_t EncodeFlags(const Vp8FrameConfig& references);
|
2017-05-02 02:51:12 -07:00
|
|
|
|
2012-09-20 20:49:12 +00:00
|
|
|
private:
|
2018-10-01 18:47:03 +02:00
|
|
|
void SetupTemporalLayers(const VideoCodec& codec);
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2018-11-02 11:38:46 +01:00
|
|
|
// Get the cpu_speed setting for encoder based on resolution and/or platform.
|
|
|
|
|
int GetCpuSpeed(int width, int height);
|
2015-03-04 21:47:06 +00:00
|
|
|
|
2014-12-09 10:36:40 +00:00
|
|
|
// Determine number of encoder threads to use.
|
|
|
|
|
int NumberOfThreads(int width, int height, int number_of_cores);
|
|
|
|
|
|
2012-09-20 20:49:12 +00:00
|
|
|
// Call encoder initialize function and set control settings.
|
2014-12-09 10:36:40 +00:00
|
|
|
int InitAndSetControlSettings();
|
2012-09-20 20:49:12 +00:00
|
|
|
|
|
|
|
|
void PopulateCodecSpecific(CodecSpecificInfo* codec_specific,
|
|
|
|
|
const vpx_codec_cx_pkt& pkt,
|
2014-12-09 10:36:40 +00:00
|
|
|
int stream_idx,
|
2018-10-03 11:05:16 +02:00
|
|
|
int encoder_idx,
|
2017-03-22 07:15:09 -07:00
|
|
|
uint32_t timestamp);
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2018-10-03 11:05:16 +02:00
|
|
|
int GetEncodedPartitions(const VideoFrame& input_image);
|
2014-12-09 10:36:40 +00:00
|
|
|
|
|
|
|
|
// Set the stream state for stream |stream_idx|.
|
|
|
|
|
void SetStreamState(bool send_stream, int stream_idx);
|
2012-09-20 20:49:12 +00:00
|
|
|
|
|
|
|
|
uint32_t MaxIntraTarget(uint32_t optimal_buffer_size);
|
|
|
|
|
|
2018-09-10 10:48:01 +02:00
|
|
|
uint32_t FrameDropThreshold(size_t spatial_idx) const;
|
|
|
|
|
|
2019-03-06 16:40:42 +01:00
|
|
|
size_t SteadyStateSize(int sid, int tid);
|
|
|
|
|
|
2018-10-04 17:52:36 +02:00
|
|
|
const std::unique_ptr<LibvpxInterface> libvpx_;
|
2017-03-21 12:35:51 -04:00
|
|
|
|
2018-11-02 11:38:46 +01:00
|
|
|
const absl::optional<std::vector<CpuSpeedExperiment::Config>>
|
|
|
|
|
experimental_cpu_speed_config_arm_;
|
2019-02-13 10:49:37 +01:00
|
|
|
const RateControlSettings rate_control_settings_;
|
2018-11-02 11:38:46 +01:00
|
|
|
|
2012-09-20 20:49:12 +00:00
|
|
|
EncodedImageCallback* encoded_complete_callback_;
|
|
|
|
|
VideoCodec codec_;
|
|
|
|
|
bool inited_;
|
|
|
|
|
int64_t timestamp_;
|
2014-12-09 10:36:40 +00:00
|
|
|
int qp_max_;
|
2015-03-04 21:47:06 +00:00
|
|
|
int cpu_speed_default_;
|
2016-11-01 04:08:22 -07:00
|
|
|
int number_of_cores_;
|
2012-09-20 20:49:12 +00:00
|
|
|
uint32_t rc_max_intra_target_;
|
2019-03-06 21:14:54 +01:00
|
|
|
std::vector<std::unique_ptr<Vp8FrameBufferController>>
|
|
|
|
|
frame_buffer_controllers_;
|
2014-12-09 10:36:40 +00:00
|
|
|
std::vector<bool> key_frame_request_;
|
|
|
|
|
std::vector<bool> send_stream_;
|
|
|
|
|
std::vector<int> cpu_speed_;
|
|
|
|
|
std::vector<vpx_image_t> raw_images_;
|
|
|
|
|
std::vector<EncodedImage> encoded_images_;
|
|
|
|
|
std::vector<vpx_codec_ctx_t> encoders_;
|
|
|
|
|
std::vector<vpx_codec_enc_cfg_t> configurations_;
|
|
|
|
|
std::vector<vpx_rational_t> downsampling_factors_;
|
2019-03-06 16:40:42 +01:00
|
|
|
|
|
|
|
|
// Variable frame-rate screencast related fields and methods.
|
|
|
|
|
const struct VariableFramerateExperiment {
|
|
|
|
|
bool enabled = false;
|
|
|
|
|
// Framerate is limited to this value in steady state.
|
|
|
|
|
float framerate_limit = 5.0;
|
|
|
|
|
// This qp or below is considered a steady state.
|
|
|
|
|
int steady_state_qp = 15;
|
|
|
|
|
// Frames of at least this percentage below ideal for configured bitrate are
|
|
|
|
|
// considered in a steady state.
|
|
|
|
|
int steady_state_undershoot_percentage = 30;
|
|
|
|
|
} variable_framerate_experiment_;
|
|
|
|
|
static VariableFramerateExperiment ParseVariableFramerateConfig(
|
|
|
|
|
std::string group_name);
|
|
|
|
|
FramerateController framerate_controller_;
|
|
|
|
|
int num_steady_state_frames_;
|
2017-03-21 12:35:51 -04:00
|
|
|
};
|
2012-09-20 20:49:12 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2018-03-14 17:52:55 +01:00
|
|
|
#endif // MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_VP8_ENCODER_H_
|