Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1 | /* |
Krishna Rapaka | 7319db5 | 2021-09-28 20:35:29 -0700 | [diff] [blame] | 2 | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3 | * |
Vibhoothi | 41c6dd7 | 2021-10-12 18:48:26 +0000 | [diff] [blame] | 4 | * 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 11 | */ |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_AV1_IFACE_COMMON_H_ |
| 13 | #define AOM_AV1_AV1_IFACE_COMMON_H_ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | |
Daniel Max Valenzuela | cc6cf05 | 2019-12-17 11:13:15 -0800 | [diff] [blame] | 15 | #include <assert.h> |
| 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "aom_ports/mem.h" |
Yaowu Xu | 3f00323 | 2018-07-30 09:10:11 -0700 | [diff] [blame] | 18 | #include "aom_scale/yv12config.h" |
Vishnu Teja Manyam | d42d562 | 2020-12-02 10:17:29 +0530 | [diff] [blame] | 19 | #include "av1/common/enums.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | |
Vishnu Teja Manyam | dd4574d | 2020-11-11 17:06:21 +0530 | [diff] [blame] | 21 | /* Constant value specifying size of subgop*/ |
| 22 | #define MAX_SUBGOP_SIZE 32 |
| 23 | typedef 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 Manyam | 4d1db46 | 2020-12-02 09:07:12 +0530 | [diff] [blame] | 29 | int qindex; |
Vishnu Teja Manyam | d42d562 | 2020-12-02 10:17:29 +0530 | [diff] [blame] | 30 | int refresh_frame_flags; |
Vishnu Teja Manyam | f4109c6 | 2020-12-02 20:05:54 +0530 | [diff] [blame] | 31 | 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 Manyam | d42d562 | 2020-12-02 10:17:29 +0530 | [diff] [blame] | 35 | unsigned int ref_frame_map[REF_FRAMES]; |
Vishnu Teja Manyam | dd4574d | 2020-11-11 17:06:21 +0530 | [diff] [blame] | 36 | } SubGOPStepData; |
| 37 | |
| 38 | typedef 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | static void yuvconfig2image(aom_image_t *img, const YV12_BUFFER_CONFIG *yv12, |
| 46 | void *user_priv) { |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 47 | /* 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 52 | 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 Daede | 2e3cd5c | 2018-03-30 14:22:15 -0700 | [diff] [blame] | 62 | img->fmt = AOM_IMG_FMT_I420; |
| 63 | bps = 12; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 64 | } |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 65 | img->cp = yv12->color_primaries; |
| 66 | img->tc = yv12->transfer_characteristics; |
| 67 | img->mc = yv12->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 68 | img->monochrome = yv12->monochrome; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 69 | img->csp = yv12->chroma_sample_position; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | img->range = yv12->color_range; |
| 71 | img->bit_depth = 8; |
Yunqing Wang | b21dac9 | 2018-04-17 15:45:15 -0700 | [diff] [blame] | 72 | img->w = yv12->y_width; |
| 73 | img->h = yv12->y_height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 74 | 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 Almer | 857e93f | 2022-05-25 16:44:43 +0000 | [diff] [blame] | 80 | 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 Almer | 756717c | 2022-10-19 17:32:48 +0000 | [diff] [blame] | 85 | 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 Almer | 857e93f | 2022-05-25 16:44:43 +0000 | [diff] [blame] | 88 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | 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 Wang | 6ff4809 | 2018-11-13 14:10:48 -0800 | [diff] [blame] | 96 | img->sz = yv12->frame_size; |
Daniel Max Valenzuela | cc6cf05 | 2019-12-17 11:13:15 -0800 | [diff] [blame] | 97 | assert(!yv12->metadata); |
| 98 | img->metadata = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static aom_codec_err_t image2yuvconfig(const aom_image_t *img, |
| 102 | YV12_BUFFER_CONFIG *yv12) { |
James Almer | 756717c | 2022-10-19 17:32:48 +0000 | [diff] [blame] | 103 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 106 | |
| 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 Wang | b21dac9 | 2018-04-17 15:45:15 -0700 | [diff] [blame] | 111 | yv12->y_width = img->w; |
| 112 | yv12->y_height = img->h; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | |
| 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 Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 123 | yv12->color_primaries = img->cp; |
| 124 | yv12->transfer_characteristics = img->tc; |
| 125 | yv12->matrix_coefficients = img->mc; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 126 | yv12->monochrome = img->monochrome; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 127 | yv12->chroma_sample_position = img->csp; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 128 | yv12->color_range = img->range; |
| 129 | |
James Almer | 857e93f | 2022-05-25 16:44:43 +0000 | [diff] [blame] | 130 | // 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 Almer | 857e93f | 2022-05-25 16:44:43 +0000 | [diff] [blame] | 140 | yv12->y_stride >>= 1; |
| 141 | yv12->uv_stride >>= 1; |
Yunqing Wang | 42b4be0 | 2018-12-17 13:34:08 -0800 | [diff] [blame] | 142 | |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 148 | yv12->subsampling_x = img->x_chroma_shift; |
| 149 | yv12->subsampling_y = img->y_chroma_shift; |
Daniel Max Valenzuela | 6b855be | 2019-09-11 16:48:45 -0700 | [diff] [blame] | 150 | yv12->metadata = img->metadata; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 151 | return AOM_CODEC_OK; |
| 152 | } |
| 153 | |
James Almer | 857e93f | 2022-05-25 16:44:43 +0000 | [diff] [blame] | 154 | static 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 Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 168 | #endif // AOM_AV1_AV1_IFACE_COMMON_H_ |