• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019, Alliance for Open Media. 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 
11 #ifndef AOM_AV1_ENCODER_SVC_LAYERCONTEXT_H_
12 #define AOM_AV1_ENCODER_SVC_LAYERCONTEXT_H_
13 
14 #include "av1/encoder/aq_cyclicrefresh.h"
15 #include "av1/encoder/encoder.h"
16 #include "av1/encoder/ratectrl.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 typedef struct {
23   RATE_CONTROL rc;
24   int framerate_factor;
25   int64_t layer_target_bitrate;
26   int scaling_factor_num;
27   int scaling_factor_den;
28   int64_t target_bandwidth;
29   int64_t spatial_layer_target_bandwidth;
30   double framerate;
31   int avg_frame_size;
32   int max_q;
33   int min_q;
34   int frames_from_key_frame;
35   // Cyclic refresh parameters (aq-mode=3), that need to be updated per-frame.
36   int sb_index;
37   int8_t *map;
38   uint8_t *last_coded_q_map;
39   int actual_num_seg1_blocks;
40   int actual_num_seg2_blocks;
41   int counter_encode_maxq_scene_change;
42   uint8_t speed;
43   unsigned char group_index;
44 } LAYER_CONTEXT;
45 
46 typedef struct SVC {
47   int spatial_layer_id;
48   int temporal_layer_id;
49   int number_spatial_layers;
50   int number_temporal_layers;
51   int external_ref_frame_config;
52   int non_reference_frame;
53   // LAST_FRAME (0), LAST2_FRAME(1), LAST3_FRAME(2), GOLDEN_FRAME(3),
54   // BWDREF_FRAME(4), ALTREF2_FRAME(5), ALTREF_FRAME(6).
55   int reference[INTER_REFS_PER_FRAME];
56   int ref_idx[INTER_REFS_PER_FRAME];
57   int refresh[REF_FRAMES];
58   double base_framerate;
59   unsigned int current_superframe;
60   unsigned int buffer_time_index[REF_FRAMES];
61   unsigned char buffer_spatial_layer[REF_FRAMES];
62   int skip_nonzeromv_last;
63   int skip_nonzeromv_gf;
64   // Layer context used for rate control in one pass temporal CBR mode or
65   // two pass spatial mode.
66   LAYER_CONTEXT layer_context[AOM_MAX_LAYERS];
67 } SVC;
68 
69 struct AV1_COMP;
70 
71 // Initialize layer context data from init_config().
72 void av1_init_layer_context(struct AV1_COMP *const cpi);
73 
74 // Update the layer context from a change_config() call.
75 void av1_update_layer_context_change_config(struct AV1_COMP *const cpi,
76                                             const int64_t target_bandwidth);
77 
78 // Prior to encoding the frame, update framerate-related quantities
79 // for the current temporal layer.
80 void av1_update_temporal_layer_framerate(struct AV1_COMP *const cpi);
81 
82 // Prior to encoding the frame, set the layer context, for the current layer
83 // to be encoded, to the cpi struct.
84 void av1_restore_layer_context(struct AV1_COMP *const cpi);
85 
86 // Save the layer context after encoding the frame.
87 void av1_save_layer_context(struct AV1_COMP *const cpi);
88 
89 void av1_free_svc_cyclic_refresh(struct AV1_COMP *const cpi);
90 
91 void av1_svc_reset_temporal_layers(struct AV1_COMP *const cpi, int is_key);
92 
93 void av1_one_pass_cbr_svc_start_layer(struct AV1_COMP *const cpi);
94 
95 #ifdef __cplusplus
96 }  // extern "C"
97 #endif
98 
99 #endif  // AOM_AV1_ENCODER_SVC_LAYERCONTEXT_H_
100