blob: 13f84f0377eab67a9fbc282938e36210bcbc50fd [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AOM_SCALE_YV12CONFIG_H_
13#define AOM_SCALE_YV12CONFIG_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#ifdef __cplusplus
16extern "C" {
17#endif
18
Yaowu Xuf883b422016-08-30 14:01:10 -070019#include "./aom_config.h"
20#include "aom/aom_codec.h"
21#include "aom/aom_frame_buffer.h"
22#include "aom/aom_integer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070023
Yaowu Xuf883b422016-08-30 14:01:10 -070024#define AOMINNERBORDERINPIXELS 160
Yaowu Xuf883b422016-08-30 14:01:10 -070025#define AOM_INTERP_EXTEND 4
Yaowu Xu671f2bd2016-09-30 15:07:57 -070026
27// TODO(jingning): Use unified inter predictor for encoder and
28// decoder during the development process. Revisit the frame border
29// to improve the decoder performance.
Debargha Mukherjee5433fa42017-10-10 09:55:51 -070030#define AOM_BORDER_IN_PIXELS 288
Yaowu Xuc27fc142016-08-22 16:08:15 -070031
32typedef struct yv12_buffer_config {
Rupert Swarbrick82529d22017-09-20 13:36:39 +010033 union {
34 struct {
35 int y_width;
36 int uv_width;
37 int alpha_width;
38 };
39 int widths[3];
40 };
41 union {
42 struct {
43 int y_height;
44 int uv_height;
45 int alpha_height;
46 };
47 int heights[3];
48 };
49 union {
50 struct {
51 int y_crop_width;
52 int uv_crop_width;
53 };
54 int crop_widths[2];
55 };
56 union {
57 struct {
58 int y_crop_height;
59 int uv_crop_height;
60 };
61 int crop_heights[2];
62 };
63 union {
64 struct {
65 int y_stride;
66 int uv_stride;
67 int alpha_stride;
68 };
69 int strides[3];
70 };
71 union {
72 struct {
73 uint8_t *y_buffer;
74 uint8_t *u_buffer;
75 uint8_t *v_buffer;
76 uint8_t *alpha_buffer;
77 };
78 uint8_t *buffers[4];
79 };
Yaowu Xuc27fc142016-08-22 16:08:15 -070080
David Barker557ce7b2016-11-16 10:22:24 +000081 // If the frame is stored in a 16-bit buffer, this stores an 8-bit version
82 // for use in global motion detection. It is allocated on-demand.
83 uint8_t *y_buffer_8bit;
Yaowu Xu9b0f7032017-07-31 11:01:19 -070084 int buf_8bit_valid;
David Barker557ce7b2016-11-16 10:22:24 +000085
Yaowu Xuc27fc142016-08-22 16:08:15 -070086 uint8_t *buffer_alloc;
87 size_t buffer_alloc_sz;
88 int border;
89 size_t frame_size;
90 int subsampling_x;
91 int subsampling_y;
92 unsigned int bit_depth;
Andrey Norkin9e694632017-12-21 18:50:57 -080093 aom_color_primaries_t color_primaries;
94 aom_transfer_characteristics_t transfer_characteristics;
95 aom_matrix_coefficients_t matrix_coefficients;
Debargha Mukherjeef340fec2018-01-10 18:12:22 -080096 int monochrome;
anorkin76fb1262017-03-22 15:12:12 -070097 aom_chroma_sample_position_t chroma_sample_position;
Yaowu Xuf883b422016-08-30 14:01:10 -070098 aom_color_range_t color_range;
Yaowu Xuc27fc142016-08-22 16:08:15 -070099 int render_width;
100 int render_height;
101
102 int corrupted;
103 int flags;
104} YV12_BUFFER_CONFIG;
105
106#define YV12_FLAG_HIGHBITDEPTH 8
107
Yaowu Xuf883b422016-08-30 14:01:10 -0700108int aom_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800109 int ss_x, int ss_y, int use_highbitdepth, int border,
110 int byte_alignment);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700111
112// Updates the yv12 buffer config with the frame buffer. |byte_alignment| must
113// be a power of 2, from 32 to 1024. 0 sets legacy alignment. If cb is not
114// NULL, then libaom is using the frame buffer callbacks to handle memory.
115// If cb is not NULL, libaom will call cb with minimum size in bytes needed
116// to decode the current frame. If cb is NULL, libaom will allocate memory
117// internally to decode the current frame. Returns 0 on success. Returns < 0
118// on failure.
Yaowu Xuf883b422016-08-30 14:01:10 -0700119int aom_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800120 int ss_x, int ss_y, int use_highbitdepth,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700121 int border, int byte_alignment,
Yaowu Xuf883b422016-08-30 14:01:10 -0700122 aom_codec_frame_buffer_t *fb,
123 aom_get_frame_buffer_cb_fn_t cb, void *cb_priv);
124int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700125
126#ifdef __cplusplus
127}
128#endif
129
Yaowu Xuf883b422016-08-30 14:01:10 -0700130#endif // AOM_SCALE_YV12CONFIG_H_