pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | * WEBRTC VP8 wrapper interface |
| 11 | */ |
| 12 | |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 13 | #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_IMPL_H_ |
| 14 | #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_IMPL_H_ |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 15 | |
Erik Språng | 78ce619 | 2016-09-12 16:04:43 +0200 | [diff] [blame] | 16 | #include <memory> |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
| 19 | // NOTE: This include order must remain to avoid compile errors, even though |
| 20 | // it breaks the style guide. |
| 21 | #include "vpx/vpx_encoder.h" |
| 22 | #include "vpx/vpx_decoder.h" |
| 23 | #include "vpx/vp8cx.h" |
| 24 | #include "vpx/vp8dx.h" |
| 25 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 26 | #include "webrtc/api/video/video_frame.h" |
kjellander | 6f8ce06 | 2015-11-16 13:52:24 -0800 | [diff] [blame] | 27 | #include "webrtc/common_video/include/i420_buffer_pool.h" |
nisse | ea3a798 | 2017-05-15 02:42:11 -0700 | [diff] [blame] | 28 | #include "webrtc/common_video/include/video_frame.h" |
pbos@webrtc.org | a440732 | 2013-07-16 12:32:05 +0000 | [diff] [blame] | 29 | #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
pbos | fa18e25 | 2017-05-02 02:51:12 -0700 | [diff] [blame] | 30 | #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
| 31 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
kjellander@webrtc.org | b7ce964 | 2015-11-18 23:04:10 +0100 | [diff] [blame] | 32 | #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 33 | |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 34 | namespace webrtc { |
| 35 | |
| 36 | class TemporalLayers; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 37 | |
| 38 | class VP8EncoderImpl : public VP8Encoder { |
| 39 | public: |
| 40 | VP8EncoderImpl(); |
| 41 | |
| 42 | virtual ~VP8EncoderImpl(); |
| 43 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 44 | int Release() override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 45 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 46 | int InitEncode(const VideoCodec* codec_settings, |
| 47 | int number_of_cores, |
| 48 | size_t max_payload_size) override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 49 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 50 | int Encode(const VideoFrame& input_image, |
| 51 | const CodecSpecificInfo* codec_specific_info, |
| 52 | const std::vector<FrameType>* frame_types) override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 53 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 54 | int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 55 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 56 | int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 57 | |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 58 | int SetRateAllocation(const BitrateAllocation& bitrate, |
| 59 | uint32_t new_framerate) override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 60 | |
kthelgason | 876222f | 2016-11-29 01:44:11 -0800 | [diff] [blame] | 61 | ScalingSettings GetScalingSettings() const override; |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 62 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 63 | const char* ImplementationName() const override; |
| 64 | |
pbos | 18ad1d4 | 2017-05-04 05:04:46 -0700 | [diff] [blame] | 65 | static vpx_enc_frame_flags_t EncodeFlags( |
| 66 | const TemporalLayers::FrameConfig& references); |
pbos | fa18e25 | 2017-05-02 02:51:12 -0700 | [diff] [blame] | 67 | |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 68 | private: |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 69 | void SetupTemporalLayers(int num_streams, |
| 70 | int num_temporal_layers, |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 71 | const VideoCodec& codec); |
| 72 | |
marpan@webrtc.org | 6daacbc | 2015-03-04 21:47:06 +0000 | [diff] [blame] | 73 | // Set the cpu_speed setting for encoder based on resolution and/or platform. |
| 74 | int SetCpuSpeed(int width, int height); |
| 75 | |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 76 | // Determine number of encoder threads to use. |
| 77 | int NumberOfThreads(int width, int height, int number_of_cores); |
| 78 | |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 79 | // Call encoder initialize function and set control settings. |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 80 | int InitAndSetControlSettings(); |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 81 | |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 82 | void PopulateCodecSpecific(CodecSpecificInfo* codec_specific, |
pbos | 18ad1d4 | 2017-05-04 05:04:46 -0700 | [diff] [blame] | 83 | const TemporalLayers::FrameConfig& tl_config, |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 84 | const vpx_codec_cx_pkt& pkt, |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 85 | int stream_idx, |
nisse | 25d0bdc | 2017-03-22 07:15:09 -0700 | [diff] [blame] | 86 | uint32_t timestamp); |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 87 | |
pbos | 18ad1d4 | 2017-05-04 05:04:46 -0700 | [diff] [blame] | 88 | int GetEncodedPartitions(const TemporalLayers::FrameConfig tl_configs[], |
| 89 | const VideoFrame& input_image); |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 90 | |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 91 | // Set the stream state for stream |stream_idx|. |
| 92 | void SetStreamState(bool send_stream, int stream_idx); |
| 93 | |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 94 | uint32_t MaxIntraTarget(uint32_t optimal_buffer_size); |
| 95 | |
Peter Boström | 1182afe | 2017-03-21 12:35:51 -0400 | [diff] [blame] | 96 | const bool use_gf_boost_; |
asapersson | 142fcc9 | 2017-08-17 08:58:54 -0700 | [diff] [blame] | 97 | const rtc::Optional<int> min_pixels_per_frame_; |
Peter Boström | 1182afe | 2017-03-21 12:35:51 -0400 | [diff] [blame] | 98 | |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 99 | EncodedImageCallback* encoded_complete_callback_; |
| 100 | VideoCodec codec_; |
| 101 | bool inited_; |
| 102 | int64_t timestamp_; |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 103 | int qp_max_; |
marpan@webrtc.org | 6daacbc | 2015-03-04 21:47:06 +0000 | [diff] [blame] | 104 | int cpu_speed_default_; |
asapersson | 384e731 | 2016-11-01 04:08:22 -0700 | [diff] [blame] | 105 | int number_of_cores_; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 106 | uint32_t rc_max_intra_target_; |
brandtr | 080830c | 2017-05-03 03:25:53 -0700 | [diff] [blame] | 107 | std::vector<std::unique_ptr<TemporalLayers>> temporal_layers_; |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 108 | std::vector<uint16_t> picture_id_; |
brandtr | 080830c | 2017-05-03 03:25:53 -0700 | [diff] [blame] | 109 | std::vector<uint8_t> tl0_pic_idx_; |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 110 | std::vector<bool> key_frame_request_; |
| 111 | std::vector<bool> send_stream_; |
| 112 | std::vector<int> cpu_speed_; |
| 113 | std::vector<vpx_image_t> raw_images_; |
| 114 | std::vector<EncodedImage> encoded_images_; |
| 115 | std::vector<vpx_codec_ctx_t> encoders_; |
| 116 | std::vector<vpx_codec_enc_cfg_t> configurations_; |
| 117 | std::vector<vpx_rational_t> downsampling_factors_; |
Peter Boström | 1182afe | 2017-03-21 12:35:51 -0400 | [diff] [blame] | 118 | }; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 119 | |
| 120 | class VP8DecoderImpl : public VP8Decoder { |
| 121 | public: |
| 122 | VP8DecoderImpl(); |
| 123 | |
| 124 | virtual ~VP8DecoderImpl(); |
| 125 | |
Peter Boström | b302ad4 | 2015-05-21 09:42:33 +0200 | [diff] [blame] | 126 | int InitDecode(const VideoCodec* inst, int number_of_cores) override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 127 | |
Peter Boström | b302ad4 | 2015-05-21 09:42:33 +0200 | [diff] [blame] | 128 | int Decode(const EncodedImage& input_image, |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 129 | bool missing_frames, |
| 130 | const RTPFragmentationHeader* fragmentation, |
| 131 | const CodecSpecificInfo* codec_specific_info, |
| 132 | int64_t /*render_time_ms*/) override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 133 | |
Peter Boström | b302ad4 | 2015-05-21 09:42:33 +0200 | [diff] [blame] | 134 | int RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override; |
| 135 | int Release() override; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 136 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 137 | const char* ImplementationName() const override; |
| 138 | |
asapersson | e5d02f9 | 2017-08-09 23:37:05 -0700 | [diff] [blame] | 139 | struct DeblockParams { |
| 140 | int max_level = 6; // Deblocking strength: [0, 16]. |
| 141 | int degrade_qp = 1; // If QP value is below, start lowering |max_level|. |
| 142 | int min_qp = 0; // If QP value is below, turn off deblocking. |
| 143 | }; |
| 144 | |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 145 | private: |
asapersson | e5d02f9 | 2017-08-09 23:37:05 -0700 | [diff] [blame] | 146 | class QpSmoother; |
wu@webrtc.org | 6c75c98 | 2014-04-15 17:46:33 +0000 | [diff] [blame] | 147 | int ReturnFrame(const vpx_image_t* img, |
| 148 | uint32_t timeStamp, |
sakal | 5fec128 | 2017-02-20 06:43:58 -0800 | [diff] [blame] | 149 | int64_t ntp_time_ms, |
| 150 | int qp); |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 151 | |
Peter Boström | 1182afe | 2017-03-21 12:35:51 -0400 | [diff] [blame] | 152 | const bool use_postproc_arm_; |
| 153 | |
magjed@webrtc.org | 73d763e | 2015-03-17 11:40:45 +0000 | [diff] [blame] | 154 | I420BufferPool buffer_pool_; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 155 | DecodedImageCallback* decode_complete_callback_; |
| 156 | bool inited_; |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 157 | vpx_codec_ctx_t* decoder_; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 158 | int propagation_cnt_; |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 159 | int last_frame_width_; |
| 160 | int last_frame_height_; |
mikhal@webrtc.org | b2c28c3 | 2013-08-23 21:54:50 +0000 | [diff] [blame] | 161 | bool key_frame_required_; |
asapersson | e5d02f9 | 2017-08-09 23:37:05 -0700 | [diff] [blame] | 162 | DeblockParams deblock_; |
| 163 | const std::unique_ptr<QpSmoother> qp_smoother_; |
Peter Boström | 1182afe | 2017-03-21 12:35:51 -0400 | [diff] [blame] | 164 | }; |
pwestin@webrtc.org | 8d89b58 | 2012-09-20 20:49:12 +0000 | [diff] [blame] | 165 | } // namespace webrtc |
| 166 | |
pbos@webrtc.org | 9115cde | 2014-12-09 10:36:40 +0000 | [diff] [blame] | 167 | #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_IMPL_H_ |