Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / source / libvpx / vp9 / encoder / vp9_svc_layercontext.h
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
11 #ifndef VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
12 #define VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
13
14 #include "vpx/vpx_encoder.h"
15
16 #include "vp9/encoder/vp9_ratectrl.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 typedef struct {
23   RATE_CONTROL rc;
24   int target_bandwidth;
25   double framerate;
26   int avg_frame_size;
27   int max_q;
28   int min_q;
29   int scaling_factor_num;
30   int scaling_factor_den;
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   struct lookahead_entry  *alt_ref_source;
38   int alt_ref_idx;
39   int gold_ref_idx;
40   int has_alt_frame;
41   size_t layer_size;
42   struct vpx_psnr_pkt psnr_pkt;
43 } LAYER_CONTEXT;
44
45 typedef struct {
46   int spatial_layer_id;
47   int temporal_layer_id;
48   int number_spatial_layers;
49   int number_temporal_layers;
50
51   int spatial_layer_to_encode;
52
53   // Workaround for multiple frame contexts
54   enum {
55     ENCODED = 0,
56     ENCODING,
57     NEED_TO_ENCODE
58   }encode_empty_frame_state;
59   struct lookahead_entry empty_frame;
60   int empty_frame_width;
61   int empty_frame_height;
62
63   // Store scaled source frames to be used for temporal filter to generate
64   // a alt ref frame.
65   YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];
66
67   // Layer context used for rate control in one pass temporal CBR mode or
68   // two pass spatial mode. Defined for temporal or spatial layers for now.
69   // Does not support temporal combined with spatial RC.
70   LAYER_CONTEXT layer_context[MAX(VPX_TS_MAX_LAYERS, VPX_SS_MAX_LAYERS)];
71 } SVC;
72
73 struct VP9_COMP;
74
75 // Initialize layer context data from init_config().
76 void vp9_init_layer_context(struct VP9_COMP *const cpi);
77
78 // Update the layer context from a change_config() call.
79 void vp9_update_layer_context_change_config(struct VP9_COMP *const cpi,
80                                             const int target_bandwidth);
81
82 // Prior to encoding the frame, update framerate-related quantities
83 // for the current temporal layer.
84 void vp9_update_temporal_layer_framerate(struct VP9_COMP *const cpi);
85
86 // Update framerate-related quantities for the current spatial layer.
87 void vp9_update_spatial_layer_framerate(struct VP9_COMP *const cpi,
88                                         double framerate);
89
90 // Prior to encoding the frame, set the layer context, for the current layer
91 // to be encoded, to the cpi struct.
92 void vp9_restore_layer_context(struct VP9_COMP *const cpi);
93
94 // Save the layer context after encoding the frame.
95 void vp9_save_layer_context(struct VP9_COMP *const cpi);
96
97 // Initialize second pass rc for spatial svc.
98 void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi);
99
100 // Increment number of video frames in layer
101 void vp9_inc_frame_in_layer(struct VP9_COMP *const cpi);
102
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
106 // Get the next source buffer to encode
107 struct lookahead_entry *vp9_svc_lookahead_pop(struct VP9_COMP *const cpi,
108                                               struct lookahead_ctx *ctx,
109                                               int drain);
110
111 // Start a frame and initialize svc parameters
112 int vp9_svc_start_frame(struct VP9_COMP *const cpi);
113
114 #ifdef __cplusplus
115 }  // extern "C"
116 #endif
117
118 #endif  // VP9_ENCODER_VP9_SVC_LAYERCONTEXT_