AOMedia AV1 Codec
yv12config.h
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AOM_SCALE_YV12CONFIG_H_
13 #define AOM_AOM_SCALE_YV12CONFIG_H_
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #include "config/aom_config.h"
20 
21 #include "aom/aom_codec.h"
22 #include "aom/aom_frame_buffer.h"
23 #include "aom/aom_integer.h"
24 #include "aom/internal/aom_image_internal.h"
25 
28 #define AOMINNERBORDERINPIXELS 160
29 #define AOM_INTERP_EXTEND 4
30 #define AOM_BORDER_IN_PIXELS 288
31 #define AOM_ENC_NO_SCALE_BORDER 160
32 #define AOM_ENC_ALLINTRA_BORDER 64
33 #define AOM_DEC_BORDER_IN_PIXELS 64
34 
35 #if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
36 struct image_pyramid;
37 struct corner_list;
38 #endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
39 
44 typedef struct yv12_buffer_config {
46  union {
47  struct {
48  int y_width;
49  int uv_width;
50  };
51  int widths[2];
52  };
53  union {
54  struct {
55  int y_height;
56  int uv_height;
57  };
58  int heights[2];
59  };
60  union {
61  struct {
62  int y_crop_width;
63  int uv_crop_width;
64  };
65  int crop_widths[2];
66  };
67  union {
68  struct {
69  int y_crop_height;
70  int uv_crop_height;
71  };
72  int crop_heights[2];
73  };
74  union {
75  struct {
76  int y_stride;
77  int uv_stride;
78  };
79  int strides[2];
80  };
81  union {
82  struct {
83  uint8_t *y_buffer;
84  uint8_t *u_buffer;
85  uint8_t *v_buffer;
86  };
87  uint8_t *buffers[3];
88  };
89 
90  // Indicate whether y_buffer, u_buffer, and v_buffer points to the internally
91  // allocated memory or external buffers.
92  int use_external_reference_buffers;
93  // This is needed to store y_buffer, u_buffer, and v_buffer when set reference
94  // uses an external refernece, and restore those buffer pointers after the
95  // external reference frame is no longer used.
96  uint8_t *store_buf_adr[3];
97 
98  // Global motion search data
99 #if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
100  // 8-bit downsampling pyramid for the Y plane
101  struct image_pyramid *y_pyramid;
102  struct corner_list *corners;
103 #endif // CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
104 
105  uint8_t *buffer_alloc;
106  size_t buffer_alloc_sz;
107  int border;
108  size_t frame_size;
109  int subsampling_x;
110  int subsampling_y;
111  unsigned int bit_depth;
112  aom_color_primaries_t color_primaries;
113  aom_transfer_characteristics_t transfer_characteristics;
114  aom_matrix_coefficients_t matrix_coefficients;
115  uint8_t monochrome;
116  aom_chroma_sample_position_t chroma_sample_position;
117  aom_color_range_t color_range;
118  int render_width;
119  int render_height;
120 
121  int corrupted;
122  int flags;
123  aom_metadata_array_t *metadata;
126 
129 #define YV12_FLAG_HIGHBITDEPTH 8
130 
131 // Allocate a frame buffer
132 //
133 // If ybf currently contains an image, all associated memory will be freed and
134 // then reallocated. In contrast, aom_realloc_frame_buffer() will reuse any
135 // existing allocations where possible. So, if ybf is likely to already be
136 // set up, please consider aom_realloc_frame_buffer() instead.
137 //
138 // See aom_realloc_frame_buffer() for the meanings of the arguments, and
139 // available return values.
140 int aom_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
141  int ss_x, int ss_y, int use_highbitdepth, int border,
142  int byte_alignment, int num_pyramid_levels,
143  int alloc_y_plane_only);
144 
145 // Updates the yv12 buffer config with the frame buffer. |byte_alignment| must
146 // be a power of 2, from 32 to 1024. 0 sets legacy alignment. If cb is not
147 // NULL, then libaom is using the frame buffer callbacks to handle memory.
148 // If cb is not NULL, libaom will call cb with minimum size in bytes needed
149 // to decode the current frame. If cb is NULL, libaom will allocate memory
150 // internally to decode the current frame.
151 //
152 // If num_pyramid_levels > 0, then an image pyramid will be allocated with
153 // the specified number of levels.
154 //
155 // Any buffer which may become a source or ref frame buffer in the encoder
156 // must have num_pyramid_levels = cpi->image_pyramid_levels. This will cause
157 // an image pyramid to be allocated if one is needed.
158 //
159 // Any other buffers (in particular, any buffers inside the decoder)
160 // must have cpi->image_pyramid_levels = 0, as a pyramid is unneeded there.
161 //
162 // Returns 0 on success. Returns < 0 on failure.
163 int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
164  int ss_x, int ss_y, int use_highbitdepth,
165  int border, int byte_alignment,
167  aom_get_frame_buffer_cb_fn_t cb, void *cb_priv,
168  int num_pyramid_levels, int alloc_y_plane_only);
169 
170 int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf);
171 
180 void aom_remove_metadata_from_frame_buffer(YV12_BUFFER_CONFIG *ybf);
181 
195 int aom_copy_metadata_to_frame_buffer(YV12_BUFFER_CONFIG *ybf,
196  const aom_metadata_array_t *arr);
197 
206 static AOM_INLINE int aom_calc_y_stride(int aligned_width, int border) {
207  return ((aligned_width + 2 * border) + 31) & ~31;
208 }
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif // AOM_AOM_SCALE_YV12CONFIG_H_
Describes the codec algorithm interface to applications.
Describes the decoder external frame buffer interface.
int(* aom_get_frame_buffer_cb_fn_t)(void *priv, size_t min_size, aom_codec_frame_buffer_t *fb)
get frame buffer callback prototype
Definition: aom_frame_buffer.h:64
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
struct aom_metadata_array aom_metadata_array_t
Array of aom_metadata structs for an image.
Definition: aom_image.h:169
enum aom_transfer_characteristics aom_transfer_characteristics_t
List of supported transfer functions.
enum aom_color_range aom_color_range_t
List of supported color range.
enum aom_color_primaries aom_color_primaries_t
List of supported color primaries.
enum aom_matrix_coefficients aom_matrix_coefficients_t
List of supported matrix coefficients.
External frame buffer.
Definition: aom_frame_buffer.h:40
YV12 frame buffer data structure.
Definition: yv12config.h:44