2012-09-20 20:49:12 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* WEBRTC VP8 wrapper interface
|
|
|
|
|
*/
|
|
|
|
|
|
2014-12-09 10:36:40 +00:00
|
|
|
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_IMPL_H_
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-09-12 16:04:43 +02:00
|
|
|
#include <memory>
|
2014-12-09 10:36:40 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
// NOTE: This include order must remain to avoid compile errors, even though
|
|
|
|
|
// it breaks the style guide.
|
|
|
|
|
#include "vpx/vpx_encoder.h"
|
|
|
|
|
#include "vpx/vpx_decoder.h"
|
|
|
|
|
#include "vpx/vp8cx.h"
|
|
|
|
|
#include "vpx/vp8dx.h"
|
|
|
|
|
|
2017-01-10 07:44:26 -08:00
|
|
|
#include "webrtc/api/video/video_frame.h"
|
2015-11-16 13:52:24 -08:00
|
|
|
#include "webrtc/common_video/include/i420_buffer_pool.h"
|
2015-11-18 22:00:21 +01:00
|
|
|
#include "webrtc/modules/video_coding/include/video_codec_interface.h"
|
2013-07-16 12:32:05 +00:00
|
|
|
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
|
2015-11-18 23:04:10 +01:00
|
|
|
#include "webrtc/modules/video_coding/utility/quality_scaler.h"
|
2015-04-10 12:52:13 +02:00
|
|
|
#include "webrtc/video_frame.h"
|
2012-09-20 20:49:12 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class TemporalLayers;
|
|
|
|
|
|
|
|
|
|
class VP8EncoderImpl : public VP8Encoder {
|
|
|
|
|
public:
|
|
|
|
|
VP8EncoderImpl();
|
|
|
|
|
|
|
|
|
|
virtual ~VP8EncoderImpl();
|
|
|
|
|
|
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
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-11-16 16:41:30 +01:00
|
|
|
int SetRateAllocation(const BitrateAllocation& bitrate,
|
|
|
|
|
uint32_t new_framerate) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2016-11-29 01:44:11 -08:00
|
|
|
ScalingSettings GetScalingSettings() const override;
|
2015-04-21 15:30:11 -07:00
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* ImplementationName() const override;
|
|
|
|
|
|
2012-09-20 20:49:12 +00:00
|
|
|
private:
|
2015-12-21 03:04:49 -08:00
|
|
|
void SetupTemporalLayers(int num_streams,
|
|
|
|
|
int num_temporal_layers,
|
2014-12-09 10:36:40 +00:00
|
|
|
const VideoCodec& codec);
|
|
|
|
|
|
2015-03-04 21:47:06 +00:00
|
|
|
// Set the cpu_speed setting for encoder based on resolution and/or platform.
|
|
|
|
|
int SetCpuSpeed(int width, int height);
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// Update frame size for codec.
|
2016-06-13 13:06:01 +02:00
|
|
|
int UpdateCodecFrameSize(int width, int height);
|
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,
|
2017-03-22 07:15:09 -07:00
|
|
|
uint32_t timestamp);
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2017-03-22 07:15:09 -07: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);
|
|
|
|
|
|
2017-03-21 12:35:51 -04:00
|
|
|
const bool use_gf_boost_;
|
|
|
|
|
|
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_;
|
2014-12-09 10:36:40 +00:00
|
|
|
std::vector<TemporalLayers*> temporal_layers_;
|
|
|
|
|
std::vector<uint16_t> picture_id_;
|
|
|
|
|
std::vector<int> last_key_frame_picture_id_;
|
|
|
|
|
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_;
|
2017-03-21 12:35:51 -04:00
|
|
|
};
|
2012-09-20 20:49:12 +00:00
|
|
|
|
|
|
|
|
class VP8DecoderImpl : public VP8Decoder {
|
|
|
|
|
public:
|
|
|
|
|
VP8DecoderImpl();
|
|
|
|
|
|
|
|
|
|
virtual ~VP8DecoderImpl();
|
|
|
|
|
|
2015-05-21 09:42:33 +02:00
|
|
|
int InitDecode(const VideoCodec* inst, int number_of_cores) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2015-05-21 09:42:33 +02:00
|
|
|
int Decode(const EncodedImage& input_image,
|
2015-12-21 03:04:49 -08:00
|
|
|
bool missing_frames,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation,
|
|
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
|
|
|
int64_t /*render_time_ms*/) override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2015-05-21 09:42:33 +02:00
|
|
|
int RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override;
|
|
|
|
|
int Release() override;
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* ImplementationName() const override;
|
|
|
|
|
|
2012-09-20 20:49:12 +00:00
|
|
|
private:
|
2014-04-15 17:46:33 +00:00
|
|
|
int ReturnFrame(const vpx_image_t* img,
|
|
|
|
|
uint32_t timeStamp,
|
2017-02-20 06:43:58 -08:00
|
|
|
int64_t ntp_time_ms,
|
|
|
|
|
int qp);
|
2012-09-20 20:49:12 +00:00
|
|
|
|
2017-03-21 12:35:51 -04:00
|
|
|
const bool use_postproc_arm_;
|
|
|
|
|
|
2015-03-17 11:40:45 +00:00
|
|
|
I420BufferPool buffer_pool_;
|
2012-09-20 20:49:12 +00:00
|
|
|
DecodedImageCallback* decode_complete_callback_;
|
|
|
|
|
bool inited_;
|
2014-12-09 10:36:40 +00:00
|
|
|
vpx_codec_ctx_t* decoder_;
|
2012-09-20 20:49:12 +00:00
|
|
|
int propagation_cnt_;
|
2014-12-09 10:36:40 +00:00
|
|
|
int last_frame_width_;
|
|
|
|
|
int last_frame_height_;
|
2013-08-23 21:54:50 +00:00
|
|
|
bool key_frame_required_;
|
2017-03-21 12:35:51 -04:00
|
|
|
};
|
2012-09-20 20:49:12 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2014-12-09 10:36:40 +00:00
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_IMPL_H_
|