2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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.
11 #ifndef VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
12 #define VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
14 #include "vpx/vpx_encoder.h"
16 #include "vp9/encoder/vp9_ratectrl.h"
25 int spatial_layer_target_bandwidth; // Target for the spatial layer.
30 int scaling_factor_num;
31 int scaling_factor_den;
33 vpx_fixed_buf_t rc_twopass_stats_in;
34 unsigned int current_video_frame_in_layer;
36 int frames_from_key_frame;
37 FRAME_TYPE last_frame_type;
38 struct lookahead_entry *alt_ref_source;
43 struct vpx_psnr_pkt psnr_pkt;
44 // Cyclic refresh parameters (aq-mode=3), that need to be updated per-frame.
47 uint8_t *last_coded_q_map;
48 uint8_t *consec_zero_mv;
53 int temporal_layer_id;
54 int number_spatial_layers;
55 int number_temporal_layers;
57 int spatial_layer_to_encode;
58 int first_spatial_layer_to_encode;
59 int rc_drop_superframe;
61 // Workaround for multiple frame contexts
66 }encode_empty_frame_state;
67 struct lookahead_entry empty_frame;
68 int encode_intra_empty_frame;
70 // Store scaled source frames to be used for temporal filter to generate
72 YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];
74 // Layer context used for rate control in one pass temporal CBR mode or
75 // two pass spatial mode.
76 LAYER_CONTEXT layer_context[VPX_MAX_LAYERS];
77 // Indicates what sort of temporal layering is used.
78 // Currently, this only works for CBR mode.
79 VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
80 // Frame flags and buffer indexes for each spatial layer, set by the
81 // application (external settings).
82 int ext_frame_flags[VPX_MAX_LAYERS];
83 int ext_lst_fb_idx[VPX_MAX_LAYERS];
84 int ext_gld_fb_idx[VPX_MAX_LAYERS];
85 int ext_alt_fb_idx[VPX_MAX_LAYERS];
86 int ref_frame_index[REF_FRAMES];
87 int force_zero_mode_spatial_ref;
88 int current_superframe;
94 // Initialize layer context data from init_config().
95 void vp9_init_layer_context(struct VP9_COMP *const cpi);
97 // Update the layer context from a change_config() call.
98 void vp9_update_layer_context_change_config(struct VP9_COMP *const cpi,
99 const int target_bandwidth);
101 // Prior to encoding the frame, update framerate-related quantities
102 // for the current temporal layer.
103 void vp9_update_temporal_layer_framerate(struct VP9_COMP *const cpi);
105 // Update framerate-related quantities for the current spatial layer.
106 void vp9_update_spatial_layer_framerate(struct VP9_COMP *const cpi,
109 // Prior to encoding the frame, set the layer context, for the current layer
110 // to be encoded, to the cpi struct.
111 void vp9_restore_layer_context(struct VP9_COMP *const cpi);
113 // Save the layer context after encoding the frame.
114 void vp9_save_layer_context(struct VP9_COMP *const cpi);
116 // Initialize second pass rc for spatial svc.
117 void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi);
119 // Increment number of video frames in layer
120 void vp9_inc_frame_in_layer(struct VP9_COMP *const cpi);
122 // Check if current layer is key frame in spatial upper layer
123 int vp9_is_upper_layer_key_frame(const struct VP9_COMP *const cpi);
125 // Get the next source buffer to encode
126 struct lookahead_entry *vp9_svc_lookahead_pop(struct VP9_COMP *const cpi,
127 struct lookahead_ctx *ctx,
130 // Start a frame and initialize svc parameters
131 int vp9_svc_start_frame(struct VP9_COMP *const cpi);
133 int vp9_one_pass_cbr_svc_start_layer(struct VP9_COMP *const cpi);
135 void vp9_free_svc_cyclic_refresh(struct VP9_COMP *const cpi);
141 #endif // VP9_ENCODER_VP9_SVC_LAYERCONTEXT_