Upstream version 9.38.198.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   TWO_PASS twopass;
28   struct vpx_fixed_buf rc_twopass_stats_in;
29   unsigned int current_video_frame_in_layer;
30   int is_key_frame;
31   vpx_svc_parameters_t svc_params_received;
32   struct lookahead_entry  *alt_ref_source;
33   int alt_ref_idx;
34   int has_alt_frame;
35   size_t layer_size;
36 } LAYER_CONTEXT;
37
38 typedef struct {
39   int spatial_layer_id;
40   int temporal_layer_id;
41   int number_spatial_layers;
42   int number_temporal_layers;
43
44   // Store scaled source frames to be used for temporal filter to generate
45   // a alt ref frame.
46   YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];
47
48   // Layer context used for rate control in one pass temporal CBR mode or
49   // two pass spatial mode. Defined for temporal or spatial layers for now.
50   // Does not support temporal combined with spatial RC.
51   LAYER_CONTEXT layer_context[MAX(VPX_TS_MAX_LAYERS, VPX_SS_MAX_LAYERS)];
52 } SVC;
53
54 struct VP9_COMP;
55
56 // Initialize layer context data from init_config().
57 void vp9_init_layer_context(struct VP9_COMP *const cpi);
58
59 // Update the layer context from a change_config() call.
60 void vp9_update_layer_context_change_config(struct VP9_COMP *const cpi,
61                                             const int target_bandwidth);
62
63 // Prior to encoding the frame, update framerate-related quantities
64 // for the current temporal layer.
65 void vp9_update_temporal_layer_framerate(struct VP9_COMP *const cpi);
66
67 // Update framerate-related quantities for the current spatial layer.
68 void vp9_update_spatial_layer_framerate(struct VP9_COMP *const cpi,
69                                         double framerate);
70
71 // Prior to encoding the frame, set the layer context, for the current layer
72 // to be encoded, to the cpi struct.
73 void vp9_restore_layer_context(struct VP9_COMP *const cpi);
74
75 // Save the layer context after encoding the frame.
76 void vp9_save_layer_context(struct VP9_COMP *const cpi);
77
78 // Initialize second pass rc for spatial svc.
79 void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi);
80
81 // Increment number of video frames in layer
82 void vp9_inc_frame_in_layer(SVC *svc);
83
84 // Check if current layer is key frame in spatial upper layer
85 int vp9_is_upper_layer_key_frame(const struct VP9_COMP *const cpi);
86
87 // Copy the source image, flags and svc parameters into a new framebuffer
88 // with the expected stride/border
89 int vp9_svc_lookahead_push(const struct VP9_COMP *const cpi,
90                            struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
91                            int64_t ts_start, int64_t ts_end,
92                            unsigned int flags);
93
94 // Get the next source buffer to encode
95 struct lookahead_entry *vp9_svc_lookahead_pop(struct VP9_COMP *const cpi,
96                                               struct lookahead_ctx *ctx,
97                                               int drain);
98
99 // Get a future source buffer to encode
100 struct lookahead_entry *vp9_svc_lookahead_peek(struct VP9_COMP *const cpi,
101                                                struct lookahead_ctx *ctx,
102                                                int index, int copy_params);
103
104 #ifdef __cplusplus
105 }  // extern "C"
106 #endif
107
108 #endif  // VP9_ENCODER_VP9_SVC_LAYERCONTEXT_