vp9_svc_layercontext.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2014 The WebM 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. #ifndef VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
  11. #define VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
  12. #include "vpx/vpx_encoder.h"
  13. #include "vp9/encoder/vp9_ratectrl.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef struct {
  18. RATE_CONTROL rc;
  19. int target_bandwidth;
  20. int spatial_layer_target_bandwidth; // Target for the spatial layer.
  21. double framerate;
  22. int avg_frame_size;
  23. int max_q;
  24. int min_q;
  25. int scaling_factor_num;
  26. int scaling_factor_den;
  27. TWO_PASS twopass;
  28. vpx_fixed_buf_t rc_twopass_stats_in;
  29. unsigned int current_video_frame_in_layer;
  30. int is_key_frame;
  31. int frames_from_key_frame;
  32. FRAME_TYPE last_frame_type;
  33. struct lookahead_entry *alt_ref_source;
  34. int alt_ref_idx;
  35. int gold_ref_idx;
  36. int has_alt_frame;
  37. size_t layer_size;
  38. struct vpx_psnr_pkt psnr_pkt;
  39. // Cyclic refresh parameters (aq-mode=3), that need to be updated per-frame.
  40. int sb_index;
  41. signed char *map;
  42. uint8_t *last_coded_q_map;
  43. uint8_t *consec_zero_mv;
  44. uint8_t speed;
  45. } LAYER_CONTEXT;
  46. typedef struct {
  47. int spatial_layer_id;
  48. int temporal_layer_id;
  49. int number_spatial_layers;
  50. int number_temporal_layers;
  51. int spatial_layer_to_encode;
  52. int first_spatial_layer_to_encode;
  53. int rc_drop_superframe;
  54. // Workaround for multiple frame contexts
  55. enum { ENCODED = 0, ENCODING, NEED_TO_ENCODE } encode_empty_frame_state;
  56. struct lookahead_entry empty_frame;
  57. int encode_intra_empty_frame;
  58. // Store scaled source frames to be used for temporal filter to generate
  59. // a alt ref frame.
  60. YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];
  61. // Temp buffer used for 2-stage down-sampling, for real-time mode.
  62. YV12_BUFFER_CONFIG scaled_temp;
  63. int scaled_one_half;
  64. int scaled_temp_is_alloc;
  65. // Layer context used for rate control in one pass temporal CBR mode or
  66. // two pass spatial mode.
  67. LAYER_CONTEXT layer_context[VPX_MAX_LAYERS];
  68. // Indicates what sort of temporal layering is used.
  69. // Currently, this only works for CBR mode.
  70. VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
  71. // Frame flags and buffer indexes for each spatial layer, set by the
  72. // application (external settings).
  73. int ext_frame_flags[VPX_MAX_LAYERS];
  74. int ext_lst_fb_idx[VPX_MAX_LAYERS];
  75. int ext_gld_fb_idx[VPX_MAX_LAYERS];
  76. int ext_alt_fb_idx[VPX_MAX_LAYERS];
  77. int ref_frame_index[REF_FRAMES];
  78. int force_zero_mode_spatial_ref;
  79. int current_superframe;
  80. int use_base_mv;
  81. } SVC;
  82. struct VP9_COMP;
  83. // Initialize layer context data from init_config().
  84. void vp9_init_layer_context(struct VP9_COMP *const cpi);
  85. // Update the layer context from a change_config() call.
  86. void vp9_update_layer_context_change_config(struct VP9_COMP *const cpi,
  87. const int target_bandwidth);
  88. // Prior to encoding the frame, update framerate-related quantities
  89. // for the current temporal layer.
  90. void vp9_update_temporal_layer_framerate(struct VP9_COMP *const cpi);
  91. // Update framerate-related quantities for the current spatial layer.
  92. void vp9_update_spatial_layer_framerate(struct VP9_COMP *const cpi,
  93. double framerate);
  94. // Prior to encoding the frame, set the layer context, for the current layer
  95. // to be encoded, to the cpi struct.
  96. void vp9_restore_layer_context(struct VP9_COMP *const cpi);
  97. // Save the layer context after encoding the frame.
  98. void vp9_save_layer_context(struct VP9_COMP *const cpi);
  99. // Initialize second pass rc for spatial svc.
  100. void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi);
  101. // Increment number of video frames in layer
  102. void vp9_inc_frame_in_layer(struct VP9_COMP *const cpi);
  103. // Check if current layer is key frame in spatial upper layer
  104. int vp9_is_upper_layer_key_frame(const struct VP9_COMP *const cpi);
  105. // Get the next source buffer to encode
  106. struct lookahead_entry *vp9_svc_lookahead_pop(struct VP9_COMP *const cpi,
  107. struct lookahead_ctx *ctx,
  108. int drain);
  109. // Start a frame and initialize svc parameters
  110. int vp9_svc_start_frame(struct VP9_COMP *const cpi);
  111. int vp9_one_pass_cbr_svc_start_layer(struct VP9_COMP *const cpi);
  112. void vp9_free_svc_cyclic_refresh(struct VP9_COMP *const cpi);
  113. void vp9_svc_reset_key_frame(struct VP9_COMP *const cpi);
  114. #ifdef __cplusplus
  115. } // extern "C"
  116. #endif
  117. #endif // VP9_ENCODER_VP9_SVC_LAYERCONTEXT_