• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 #define AOMINNERBORDERINPIXELS 160
26 #define AOM_INTERP_EXTEND 4
27 #define AOM_BORDER_IN_PIXELS 288
28 #define AOM_ENC_NO_SCALE_BORDER 160
29 #define AOM_ENC_LOOKAHEAD_BORDER 64
30 #define AOM_DEC_BORDER_IN_PIXELS 64
31 
32 typedef struct yv12_buffer_config {
33   union {
34     struct {
35       int y_width;
36       int uv_width;
37     };
38     int widths[2];
39   };
40   union {
41     struct {
42       int y_height;
43       int uv_height;
44     };
45     int heights[2];
46   };
47   union {
48     struct {
49       int y_crop_width;
50       int uv_crop_width;
51     };
52     int crop_widths[2];
53   };
54   union {
55     struct {
56       int y_crop_height;
57       int uv_crop_height;
58     };
59     int crop_heights[2];
60   };
61   union {
62     struct {
63       int y_stride;
64       int uv_stride;
65     };
66     int strides[2];
67   };
68   union {
69     struct {
70       uint8_t *y_buffer;
71       uint8_t *u_buffer;
72       uint8_t *v_buffer;
73     };
74     uint8_t *buffers[3];
75   };
76 
77   // Indicate whether y_buffer, u_buffer, and v_buffer points to the internally
78   // allocated memory or external buffers.
79   int use_external_reference_buffers;
80   // This is needed to store y_buffer, u_buffer, and v_buffer when set reference
81   // uses an external refernece, and restore those buffer pointers after the
82   // external reference frame is no longer used.
83   uint8_t *store_buf_adr[3];
84 
85   // If the frame is stored in a 16-bit buffer, this stores an 8-bit version
86   // for use in global motion detection. It is allocated on-demand.
87   uint8_t *y_buffer_8bit;
88   int buf_8bit_valid;
89 
90   uint8_t *buffer_alloc;
91   size_t buffer_alloc_sz;
92   int border;
93   size_t frame_size;
94   int subsampling_x;
95   int subsampling_y;
96   unsigned int bit_depth;
97   aom_color_primaries_t color_primaries;
98   aom_transfer_characteristics_t transfer_characteristics;
99   aom_matrix_coefficients_t matrix_coefficients;
100   uint8_t monochrome;
101   aom_chroma_sample_position_t chroma_sample_position;
102   aom_color_range_t color_range;
103   int render_width;
104   int render_height;
105 
106   int corrupted;
107   int flags;
108 } YV12_BUFFER_CONFIG;
109 
110 #define YV12_FLAG_HIGHBITDEPTH 8
111 
112 int aom_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
113                            int ss_x, int ss_y, int use_highbitdepth, int border,
114                            int byte_alignment);
115 
116 // Updates the yv12 buffer config with the frame buffer. |byte_alignment| must
117 // be a power of 2, from 32 to 1024. 0 sets legacy alignment. If cb is not
118 // NULL, then libaom is using the frame buffer callbacks to handle memory.
119 // If cb is not NULL, libaom will call cb with minimum size in bytes needed
120 // to decode the current frame. If cb is NULL, libaom will allocate memory
121 // internally to decode the current frame. Returns 0 on success. Returns < 0
122 // on failure.
123 int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
124                              int ss_x, int ss_y, int use_highbitdepth,
125                              int border, int byte_alignment,
126                              aom_codec_frame_buffer_t *fb,
127                              aom_get_frame_buffer_cb_fn_t cb, void *cb_priv);
128 
129 int aom_realloc_lookahead_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
130                                  int ss_x, int ss_y, int use_highbitdepth,
131                                  int border, int byte_alignment,
132                                  aom_codec_frame_buffer_t *fb,
133                                  aom_get_frame_buffer_cb_fn_t cb,
134                                  void *cb_priv);
135 
136 int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf);
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif  // AOM_AOM_SCALE_YV12CONFIG_H_
143