blob: ebb25010262ae4d254e67b678c1a0f7799ea21e8 [file] [log] [blame]
Yaowu Xuf883b422016-08-30 14:01:10 -07001/*
Krishna Rapaka7319db52021-09-28 20:35:29 -07002 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
Yaowu Xuf883b422016-08-30 14:01:10 -07003 *
Vibhoothi41c6dd72021-10-12 18:48:26 +00004 * This source code is subject to the terms of the BSD 3-Clause Clear License
5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6 * License was not distributed with this source code in the LICENSE file, you
7 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the
8 * Alliance for Open Media Patent License 1.0 was not distributed with this
9 * source code in the PATENTS file, you can obtain it at
10 * aomedia.org/license/patent-license/.
Yaowu Xuf883b422016-08-30 14:01:10 -070011 */
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_AV1_AV1_IFACE_COMMON_H_
13#define AOM_AV1_AV1_IFACE_COMMON_H_
Yaowu Xuf883b422016-08-30 14:01:10 -070014
Daniel Max Valenzuelacc6cf052019-12-17 11:13:15 -080015#include <assert.h>
16
Yaowu Xuf883b422016-08-30 14:01:10 -070017#include "aom_ports/mem.h"
Yaowu Xu3f003232018-07-30 09:10:11 -070018#include "aom_scale/yv12config.h"
Vishnu Teja Manyamd42d5622020-12-02 10:17:29 +053019#include "av1/common/enums.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070020
Vishnu Teja Manyamdd4574d2020-11-11 17:06:21 +053021/* Constant value specifying size of subgop*/
22#define MAX_SUBGOP_SIZE 32
23typedef struct {
24 int disp_frame_idx;
25 int is_filtered;
26 int show_frame;
27 int show_existing_frame;
28 int pyramid_level;
Vishnu Teja Manyam4d1db462020-12-02 09:07:12 +053029 int qindex;
Vishnu Teja Manyamd42d5622020-12-02 10:17:29 +053030 int refresh_frame_flags;
Vishnu Teja Manyamf4109c62020-12-02 20:05:54 +053031 int num_references;
32 int ref_frame_pyr_level[INTER_REFS_PER_FRAME];
33 int ref_frame_disp_order[INTER_REFS_PER_FRAME];
34 int is_valid_ref_frame[INTER_REFS_PER_FRAME];
Vishnu Teja Manyamd42d5622020-12-02 10:17:29 +053035 unsigned int ref_frame_map[REF_FRAMES];
Vishnu Teja Manyamdd4574d2020-11-11 17:06:21 +053036} SubGOPStepData;
37
38typedef struct {
39 int num_steps;
40 int step_idx_enc;
41 int step_idx_dec;
42 SubGOPStepData step[MAX_SUBGOP_SIZE];
43} SubGOPData;
44
Yaowu Xuf883b422016-08-30 14:01:10 -070045static void yuvconfig2image(aom_image_t *img, const YV12_BUFFER_CONFIG *yv12,
46 void *user_priv) {
Johann123e8a62017-12-28 14:40:49 -080047 /* aom_img_wrap() doesn't allow specifying independent strides for
48 * the Y, U, and V planes, nor other alignment adjustments that
49 * might be representable by a YV12_BUFFER_CONFIG, so we just
50 * initialize all the fields.
51 */
Yaowu Xuf883b422016-08-30 14:01:10 -070052 int bps;
53 if (!yv12->subsampling_y) {
54 if (!yv12->subsampling_x) {
55 img->fmt = AOM_IMG_FMT_I444;
56 bps = 24;
57 } else {
58 img->fmt = AOM_IMG_FMT_I422;
59 bps = 16;
60 }
61 } else {
Thomas Daede2e3cd5c2018-03-30 14:22:15 -070062 img->fmt = AOM_IMG_FMT_I420;
63 bps = 12;
Yaowu Xuf883b422016-08-30 14:01:10 -070064 }
Andrey Norkin9e694632017-12-21 18:50:57 -080065 img->cp = yv12->color_primaries;
66 img->tc = yv12->transfer_characteristics;
67 img->mc = yv12->matrix_coefficients;
Debargha Mukherjeef340fec2018-01-10 18:12:22 -080068 img->monochrome = yv12->monochrome;
anorkin76fb1262017-03-22 15:12:12 -070069 img->csp = yv12->chroma_sample_position;
Yaowu Xuf883b422016-08-30 14:01:10 -070070 img->range = yv12->color_range;
71 img->bit_depth = 8;
Yunqing Wangb21dac92018-04-17 15:45:15 -070072 img->w = yv12->y_width;
73 img->h = yv12->y_height;
Yaowu Xuf883b422016-08-30 14:01:10 -070074 img->d_w = yv12->y_crop_width;
75 img->d_h = yv12->y_crop_height;
76 img->r_w = yv12->render_width;
77 img->r_h = yv12->render_height;
78 img->x_chroma_shift = yv12->subsampling_x;
79 img->y_chroma_shift = yv12->subsampling_y;
James Almer857e93f2022-05-25 16:44:43 +000080 bps *= 2;
81 // aom_image_t uses byte strides and a pointer to the first byte
82 // of the image.
83 img->fmt = (aom_img_fmt_t)(img->fmt | AOM_IMG_FMT_HIGHBITDEPTH);
84 img->bit_depth = yv12->bit_depth;
James Almer756717c2022-10-19 17:32:48 +000085 img->planes[AOM_PLANE_Y] = (uint8_t *)yv12->y_buffer;
86 img->planes[AOM_PLANE_U] = (uint8_t *)yv12->u_buffer;
87 img->planes[AOM_PLANE_V] = (uint8_t *)yv12->v_buffer;
James Almer857e93f2022-05-25 16:44:43 +000088 img->stride[AOM_PLANE_Y] = 2 * yv12->y_stride;
89 img->stride[AOM_PLANE_U] = 2 * yv12->uv_stride;
90 img->stride[AOM_PLANE_V] = 2 * yv12->uv_stride;
Yaowu Xuf883b422016-08-30 14:01:10 -070091 img->bps = bps;
92 img->user_priv = user_priv;
93 img->img_data = yv12->buffer_alloc;
94 img->img_data_owner = 0;
95 img->self_allocd = 0;
Yunqing Wang6ff48092018-11-13 14:10:48 -080096 img->sz = yv12->frame_size;
Daniel Max Valenzuelacc6cf052019-12-17 11:13:15 -080097 assert(!yv12->metadata);
98 img->metadata = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -070099}
100
101static aom_codec_err_t image2yuvconfig(const aom_image_t *img,
102 YV12_BUFFER_CONFIG *yv12) {
James Almer756717c2022-10-19 17:32:48 +0000103 yv12->y_buffer = (uint16_t *)img->planes[AOM_PLANE_Y];
104 yv12->u_buffer = (uint16_t *)img->planes[AOM_PLANE_U];
105 yv12->v_buffer = (uint16_t *)img->planes[AOM_PLANE_V];
Yaowu Xuf883b422016-08-30 14:01:10 -0700106
107 yv12->y_crop_width = img->d_w;
108 yv12->y_crop_height = img->d_h;
109 yv12->render_width = img->r_w;
110 yv12->render_height = img->r_h;
Yunqing Wangb21dac92018-04-17 15:45:15 -0700111 yv12->y_width = img->w;
112 yv12->y_height = img->h;
Yaowu Xuf883b422016-08-30 14:01:10 -0700113
114 yv12->uv_width =
115 img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2 : yv12->y_width;
116 yv12->uv_height =
117 img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 : yv12->y_height;
118 yv12->uv_crop_width = yv12->uv_width;
119 yv12->uv_crop_height = yv12->uv_height;
120
121 yv12->y_stride = img->stride[AOM_PLANE_Y];
122 yv12->uv_stride = img->stride[AOM_PLANE_U];
Andrey Norkin9e694632017-12-21 18:50:57 -0800123 yv12->color_primaries = img->cp;
124 yv12->transfer_characteristics = img->tc;
125 yv12->matrix_coefficients = img->mc;
Debargha Mukherjeef340fec2018-01-10 18:12:22 -0800126 yv12->monochrome = img->monochrome;
anorkin76fb1262017-03-22 15:12:12 -0700127 yv12->chroma_sample_position = img->csp;
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 yv12->color_range = img->range;
129
James Almer857e93f2022-05-25 16:44:43 +0000130 // In aom_image_t
131 // planes point to uint8 address of start of data
132 // stride counts uint8s to reach next row
133 // In YV12_BUFFER_CONFIG
134 // y_buffer, u_buffer, v_buffer point to uint16 address of data
135 // stride and border counts in uint16s
136 // This means that all the address calculations in the main body of code
137 // should work correctly.
138 // However, before we do any pixel operations we need to cast the address
139 // to a uint16 ponter and double its value.
James Almer857e93f2022-05-25 16:44:43 +0000140 yv12->y_stride >>= 1;
141 yv12->uv_stride >>= 1;
Yunqing Wang42b4be02018-12-17 13:34:08 -0800142
143 // Note(yunqing): if img is allocated the same as the frame buffer, y_stride
144 // is 32-byte aligned. Also, handle the cases while allocating img without a
145 // border or stride_align is less than 32.
146 int border = (yv12->y_stride - (int)((img->w + 31) & ~31)) / 2;
147 yv12->border = (border < 0) ? 0 : border;
Yaowu Xuf883b422016-08-30 14:01:10 -0700148 yv12->subsampling_x = img->x_chroma_shift;
149 yv12->subsampling_y = img->y_chroma_shift;
Daniel Max Valenzuela6b855be2019-09-11 16:48:45 -0700150 yv12->metadata = img->metadata;
Yaowu Xuf883b422016-08-30 14:01:10 -0700151 return AOM_CODEC_OK;
152}
153
James Almer857e93f2022-05-25 16:44:43 +0000154static void image2yuvconfig_upshift(aom_image_t *hbd_img,
155 const aom_image_t *img,
156 YV12_BUFFER_CONFIG *yv12) {
157 aom_img_upshift(hbd_img, img, 0);
158 // Copy some properties aom_img_upshift() ignores
159 hbd_img->cp = img->cp;
160 hbd_img->tc = img->tc;
161 hbd_img->mc = img->mc;
162 hbd_img->monochrome = img->monochrome;
163 hbd_img->csp = img->csp;
164 hbd_img->range = img->range;
165 image2yuvconfig(hbd_img, yv12);
166 yv12->metadata = img->metadata;
167}
James Zerne1cbb132018-08-22 14:10:36 -0700168#endif // AOM_AV1_AV1_IFACE_COMMON_H_