vp9_svc_layercontext.h 3.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 *  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;
  double framerate;
  int avg_frame_size;
27 28 29 30
  int max_q;
  int min_q;
  int scaling_factor_num;
  int scaling_factor_den;
Paul Wilkins's avatar
Paul Wilkins committed
31
  TWO_PASS twopass;
32
  vpx_fixed_buf_t rc_twopass_stats_in;
33
  unsigned int current_video_frame_in_layer;
34
  int is_key_frame;
35
  int frames_from_key_frame;
36
  FRAME_TYPE last_frame_type;
37 38
  struct lookahead_entry  *alt_ref_source;
  int alt_ref_idx;
39
  int gold_ref_idx;
40 41
  int has_alt_frame;
  size_t layer_size;
42
  struct vpx_psnr_pkt psnr_pkt;
43 44 45 46 47 48 49
} LAYER_CONTEXT;

typedef struct {
  int spatial_layer_id;
  int temporal_layer_id;
  int number_spatial_layers;
  int number_temporal_layers;
50

51 52
  int spatial_layer_to_encode;

53 54 55 56
  // Store scaled source frames to be used for temporal filter to generate
  // a alt ref frame.
  YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];

57 58
  // Layer context used for rate control in one pass temporal CBR mode or
  // two pass spatial mode. Defined for temporal or spatial layers for now.
59 60
  // Does not support temporal combined with spatial RC.
  LAYER_CONTEXT layer_context[MAX(VPX_TS_MAX_LAYERS, VPX_SS_MAX_LAYERS)];
61 62 63 64 65 66 67 68 69 70 71 72
} 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
73 74 75 76 77 78
// 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);
79 80 81 82 83 84 85 86

// 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);

87 88 89
// Initialize second pass rc for spatial svc.
void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi);

90
// Increment number of video frames in layer
91
void vp9_inc_frame_in_layer(struct VP9_COMP *const cpi);
92

93 94 95
// Check if current layer is key frame in spatial upper layer
int vp9_is_upper_layer_key_frame(const struct VP9_COMP *const cpi);

96 97 98 99 100
// 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);

101 102
// Start a frame and initialize svc parameters
int vp9_svc_start_frame(struct VP9_COMP *const cpi);
103

104 105 106 107 108
#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // VP9_ENCODER_VP9_SVC_LAYERCONTEXT_