2014-03-13 18:26:52 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebM 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
|
|
|
|
#define VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
|
|
|
|
|
|
|
|
#include "vpx/vpx_encoder.h"
|
|
|
|
|
|
|
|
#include "vp9/encoder/vp9_ratectrl.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
RATE_CONTROL rc;
|
|
|
|
int target_bandwidth;
|
2015-05-22 01:15:37 +02:00
|
|
|
int spatial_layer_target_bandwidth; // Target for the spatial layer.
|
2014-03-13 18:26:52 +01:00
|
|
|
double framerate;
|
|
|
|
int avg_frame_size;
|
2014-09-19 03:05:07 +02:00
|
|
|
int max_q;
|
|
|
|
int min_q;
|
|
|
|
int scaling_factor_num;
|
|
|
|
int scaling_factor_den;
|
2014-05-16 12:31:30 +02:00
|
|
|
TWO_PASS twopass;
|
2014-08-22 03:06:04 +02:00
|
|
|
vpx_fixed_buf_t rc_twopass_stats_in;
|
2014-03-28 00:59:44 +01:00
|
|
|
unsigned int current_video_frame_in_layer;
|
2014-04-24 22:31:46 +02:00
|
|
|
int is_key_frame;
|
2014-09-02 21:05:14 +02:00
|
|
|
int frames_from_key_frame;
|
2014-08-18 23:51:04 +02:00
|
|
|
FRAME_TYPE last_frame_type;
|
2016-07-27 05:43:23 +02:00
|
|
|
struct lookahead_entry *alt_ref_source;
|
2014-07-14 20:24:17 +02:00
|
|
|
int alt_ref_idx;
|
2014-08-01 19:26:51 +02:00
|
|
|
int gold_ref_idx;
|
2014-07-14 20:24:17 +02:00
|
|
|
int has_alt_frame;
|
|
|
|
size_t layer_size;
|
2014-09-11 20:28:03 +02:00
|
|
|
struct vpx_psnr_pkt psnr_pkt;
|
2015-09-08 17:47:42 +02:00
|
|
|
// Cyclic refresh parameters (aq-mode=3), that need to be updated per-frame.
|
|
|
|
int sb_index;
|
|
|
|
signed char *map;
|
|
|
|
uint8_t *last_coded_q_map;
|
2015-09-29 19:00:16 +02:00
|
|
|
uint8_t *consec_zero_mv;
|
2016-07-14 00:58:11 +02:00
|
|
|
uint8_t speed;
|
2014-03-13 18:26:52 +01:00
|
|
|
} LAYER_CONTEXT;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int spatial_layer_id;
|
|
|
|
int temporal_layer_id;
|
|
|
|
int number_spatial_layers;
|
|
|
|
int number_temporal_layers;
|
2014-07-14 20:24:17 +02:00
|
|
|
|
2014-09-19 03:05:07 +02:00
|
|
|
int spatial_layer_to_encode;
|
2015-10-02 00:46:06 +02:00
|
|
|
int first_spatial_layer_to_encode;
|
2015-10-27 21:02:02 +01:00
|
|
|
int rc_drop_superframe;
|
2014-09-19 03:05:07 +02:00
|
|
|
|
2014-10-15 01:25:03 +02:00
|
|
|
// Workaround for multiple frame contexts
|
2016-07-27 05:43:23 +02:00
|
|
|
enum { ENCODED = 0, ENCODING, NEED_TO_ENCODE } encode_empty_frame_state;
|
2014-10-15 01:25:03 +02:00
|
|
|
struct lookahead_entry empty_frame;
|
2015-05-21 01:43:27 +02:00
|
|
|
int encode_intra_empty_frame;
|
2014-10-15 01:25:03 +02:00
|
|
|
|
2014-07-14 20:24:17 +02:00
|
|
|
// Store scaled source frames to be used for temporal filter to generate
|
|
|
|
// a alt ref frame.
|
|
|
|
YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];
|
2016-02-25 17:38:08 +01:00
|
|
|
// Temp buffer used for 2-stage down-sampling, for real-time mode.
|
|
|
|
YV12_BUFFER_CONFIG scaled_temp;
|
2016-07-12 02:06:10 +02:00
|
|
|
int scaled_one_half;
|
|
|
|
int scaled_temp_is_alloc;
|
2014-07-14 20:24:17 +02:00
|
|
|
|
2014-03-28 00:59:44 +01:00
|
|
|
// Layer context used for rate control in one pass temporal CBR mode or
|
2015-05-22 01:15:37 +02:00
|
|
|
// two pass spatial mode.
|
|
|
|
LAYER_CONTEXT layer_context[VPX_MAX_LAYERS];
|
|
|
|
// Indicates what sort of temporal layering is used.
|
|
|
|
// Currently, this only works for CBR mode.
|
|
|
|
VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
|
2015-09-02 20:34:00 +02:00
|
|
|
// Frame flags and buffer indexes for each spatial layer, set by the
|
|
|
|
// application (external settings).
|
|
|
|
int ext_frame_flags[VPX_MAX_LAYERS];
|
|
|
|
int ext_lst_fb_idx[VPX_MAX_LAYERS];
|
|
|
|
int ext_gld_fb_idx[VPX_MAX_LAYERS];
|
|
|
|
int ext_alt_fb_idx[VPX_MAX_LAYERS];
|
2015-12-07 21:23:56 +01:00
|
|
|
int ref_frame_index[REF_FRAMES];
|
|
|
|
int force_zero_mode_spatial_ref;
|
|
|
|
int current_superframe;
|
2016-01-15 18:35:41 +01:00
|
|
|
int use_base_mv;
|
2017-04-14 02:19:06 +02:00
|
|
|
// phase_scaler used to control the downscaling filter for source scaling.
|
|
|
|
// phase_scaler = 0 will do sub-sampling (no weighted average),
|
|
|
|
// phase_scaler = 8 will center the target pixel and use the averaging filter,
|
|
|
|
// for eightap regular: {-1, 6, -19, 78, 78, -19, 6, -1 }.
|
|
|
|
int phase_scaler;
|
2014-03-13 18:26:52 +01:00
|
|
|
} SVC;
|
|
|
|
|
|
|
|
struct VP9_COMP;
|
|
|
|
|
|
|
|
// Initialize layer context data from init_config().
|
|
|
|
void vp9_init_layer_context(struct VP9_COMP *const cpi);
|
|
|
|
|
|
|
|
// Update the layer context from a change_config() call.
|
|
|
|
void vp9_update_layer_context_change_config(struct VP9_COMP *const cpi,
|
|
|
|
const int target_bandwidth);
|
|
|
|
|
|
|
|
// Prior to encoding the frame, update framerate-related quantities
|
2014-03-27 23:46:32 +01:00
|
|
|
// for the current temporal layer.
|
|
|
|
void vp9_update_temporal_layer_framerate(struct VP9_COMP *const cpi);
|
|
|
|
|
|
|
|
// Update framerate-related quantities for the current spatial layer.
|
|
|
|
void vp9_update_spatial_layer_framerate(struct VP9_COMP *const cpi,
|
|
|
|
double framerate);
|
2014-03-13 18:26:52 +01:00
|
|
|
|
|
|
|
// Prior to encoding the frame, set the layer context, for the current layer
|
|
|
|
// to be encoded, to the cpi struct.
|
|
|
|
void vp9_restore_layer_context(struct VP9_COMP *const cpi);
|
|
|
|
|
|
|
|
// Save the layer context after encoding the frame.
|
|
|
|
void vp9_save_layer_context(struct VP9_COMP *const cpi);
|
|
|
|
|
2014-03-28 00:59:44 +01:00
|
|
|
// Initialize second pass rc for spatial svc.
|
|
|
|
void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi);
|
|
|
|
|
2014-04-09 03:59:09 +02:00
|
|
|
// Increment number of video frames in layer
|
2014-09-02 21:05:14 +02:00
|
|
|
void vp9_inc_frame_in_layer(struct VP9_COMP *const cpi);
|
2014-04-09 03:59:09 +02:00
|
|
|
|
2014-04-24 22:31:46 +02:00
|
|
|
// Check if current layer is key frame in spatial upper layer
|
|
|
|
int vp9_is_upper_layer_key_frame(const struct VP9_COMP *const cpi);
|
|
|
|
|
2014-06-24 23:01:17 +02:00
|
|
|
// Get the next source buffer to encode
|
|
|
|
struct lookahead_entry *vp9_svc_lookahead_pop(struct VP9_COMP *const cpi,
|
|
|
|
struct lookahead_ctx *ctx,
|
|
|
|
int drain);
|
|
|
|
|
2014-09-19 03:05:07 +02:00
|
|
|
// Start a frame and initialize svc parameters
|
|
|
|
int vp9_svc_start_frame(struct VP9_COMP *const cpi);
|
2014-06-24 23:01:17 +02:00
|
|
|
|
2015-05-22 01:15:37 +02:00
|
|
|
int vp9_one_pass_cbr_svc_start_layer(struct VP9_COMP *const cpi);
|
|
|
|
|
2015-09-08 17:47:42 +02:00
|
|
|
void vp9_free_svc_cyclic_refresh(struct VP9_COMP *const cpi);
|
|
|
|
|
2016-03-07 22:43:11 +01:00
|
|
|
void vp9_svc_reset_key_frame(struct VP9_COMP *const cpi);
|
|
|
|
|
2014-03-13 18:26:52 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // VP9_ENCODER_VP9_SVC_LAYERCONTEXT_
|