summaryrefslogtreecommitdiffstats
path: root/media/libvpx/libvpx/vp9/encoder/vp9_alt_ref_aq.h
blob: 22a657e035c9567cab36ed46a1d22fa714aa176e (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 *  Copyright (c) 2016 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.
 */

/*
 *  \file vp9_alt_ref_aq.h
 *
 *  This file  contains public interface  for setting up  adaptive segmentation
 *  for altref frames.  Go to alt_ref_aq_private.h for implmentation details.
 */

#ifndef VPX_VP9_ENCODER_VP9_ALT_REF_AQ_H_
#define VPX_VP9_ENCODER_VP9_ALT_REF_AQ_H_

#include "vpx/vpx_integer.h"

// Where to disable segmentation
#define ALT_REF_AQ_LOW_BITRATE_BOUNDARY 150

// Last frame always has overall quality = 0,
// so it is questionable if I can process it
#define ALT_REF_AQ_APPLY_TO_LAST_FRAME 1

// If I should try to compare gain
// against segmentation overhead
#define ALT_REF_AQ_PROTECT_GAIN 0

// Threshold to disable segmentation
#define ALT_REF_AQ_PROTECT_GAIN_THRESH 0.5

#ifdef __cplusplus
extern "C" {
#endif

// Simple structure for storing images
struct MATX_8U {
  int rows;
  int cols;
  int stride;

  uint8_t *data;
};

struct VP9_COMP;
struct ALT_REF_AQ;

/*!\brief Constructor
 *
 * \return Instance of the class
 */
struct ALT_REF_AQ *vp9_alt_ref_aq_create(void);

/*!\brief Upload segmentation_map to self object
 *
 * \param    self             Instance of the class
 * \param    segmentation_map Segmentation map to upload
 */
void vp9_alt_ref_aq_upload_map(struct ALT_REF_AQ *const self,
                               const struct MATX_8U *segmentation_map);

/*!\brief Return pointer to the altref segmentation map
 *
 * \param    self                    Instance of the class
 * \param    segmentation_overhead   Segmentation overhead in bytes
 * \param    bandwidth               Current frame bandwidth in bytes
 *
 * \return  Boolean value to disable segmentation
 */
int vp9_alt_ref_aq_disable_if(const struct ALT_REF_AQ *self,
                              int segmentation_overhead, int bandwidth);

/*!\brief Set number of segments
 *
 * It is used for delta quantizer computations
 * and thus it can be larger than
 * maximum value of the segmentation map
 *
 * \param    self        Instance of the class
 * \param    nsegments   Maximum number of segments
 */
void vp9_alt_ref_aq_set_nsegments(struct ALT_REF_AQ *const self, int nsegments);

/*!\brief Set up LOOKAHEAD_AQ segmentation mode
 *
 * Set up segmentation mode to LOOKAHEAD_AQ
 * (expected future frames prediction
 *  quality refering to the current frame).
 *
 * \param    self    Instance of the class
 * \param    cpi     Encoder context
 */
void vp9_alt_ref_aq_setup_mode(struct ALT_REF_AQ *const self,
                               struct VP9_COMP *const cpi);

/*!\brief Set up LOOKAHEAD_AQ segmentation map and delta quantizers
 *
 * \param    self    Instance of the class
 * \param    cpi     Encoder context
 */
void vp9_alt_ref_aq_setup_map(struct ALT_REF_AQ *const self,
                              struct VP9_COMP *const cpi);

/*!\brief Restore main segmentation map mode and reset the class variables
 *
 * \param    self    Instance of the class
 * \param    cpi     Encoder context
 */
void vp9_alt_ref_aq_unset_all(struct ALT_REF_AQ *const self,
                              struct VP9_COMP *const cpi);

/*!\brief Destructor
 *
 * \param    self    Instance of the class
 */
void vp9_alt_ref_aq_destroy(struct ALT_REF_AQ *const self);

#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // VPX_VP9_ENCODER_VP9_ALT_REF_AQ_H_