LCOV - code coverage report
Current view: top level - Codec - EbPictureBufferDesc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 173 209 82.8 %
Date: 2019-11-25 17:38:06 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /*
       2             : * Copyright(c) 2019 Intel Corporation
       3             : * SPDX - License - Identifier: BSD - 2 - Clause - Patent
       4             : */
       5             : 
       6             : /*
       7             : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
       8             : *
       9             : * This source code is subject to the terms of the BSD 2 Clause License and
      10             : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
      11             : * was not distributed with this source code in the LICENSE file, you can
      12             : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
      13             : * Media Patent License 1.0 was not distributed with this source code in the
      14             : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
      15             : */
      16             : 
      17             : #include <stdlib.h>
      18             : 
      19             : #include "EbPictureBufferDesc.h"
      20             : 
      21       16442 : static void eb_picture_buffer_desc_dctor(EbPtr p)
      22             : {
      23       16442 :     EbPictureBufferDesc *obj = (EbPictureBufferDesc*)p;
      24       16442 :     if (obj->buffer_enable_mask & PICTURE_BUFFER_DESC_Y_FLAG) {
      25       16328 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_y);
      26       16328 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_bit_inc_y);
      27             :     }
      28       16442 :     if (obj->buffer_enable_mask & PICTURE_BUFFER_DESC_Cb_FLAG) {
      29       15970 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_cb);
      30       15970 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_bit_inc_cb);
      31             :     }
      32       16442 :     if (obj->buffer_enable_mask & PICTURE_BUFFER_DESC_Cb_FLAG) {
      33       15970 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_cr);
      34       15970 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_bit_inc_cr);
      35             :     }
      36       16442 : }
      37             : 
      38             : /*****************************************
      39             :  * eb_picture_buffer_desc_ctor
      40             :  *  Initializes the Buffer Descriptor's
      41             :  *  values that are fixed for the life of
      42             :  *  the descriptor.
      43             :  *****************************************/
      44       16442 : EbErrorType eb_picture_buffer_desc_ctor(
      45             :     EbPictureBufferDesc* pictureBufferDescPtr,
      46             :     EbPtr   object_init_data_ptr)
      47             : {
      48       16442 :     EbPictureBufferDescInitData  *pictureBufferDescInitDataPtr = (EbPictureBufferDescInitData*)object_init_data_ptr;
      49             : 
      50       16442 :     uint32_t bytesPerPixel = (pictureBufferDescInitDataPtr->bit_depth == EB_8BIT) ? 1 : (pictureBufferDescInitDataPtr->bit_depth <= EB_16BIT) ? 2 : 4;
      51       16442 :     const uint16_t subsampling_x = (pictureBufferDescInitDataPtr->color_format == EB_YUV444 ? 1 : 2) - 1;
      52             : 
      53       16442 :     pictureBufferDescPtr->dctor = eb_picture_buffer_desc_dctor;
      54             : 
      55       16442 :     if (pictureBufferDescInitDataPtr->bit_depth > EB_8BIT && pictureBufferDescInitDataPtr->bit_depth <= EB_16BIT && pictureBufferDescInitDataPtr->split_mode == EB_TRUE)
      56           0 :         bytesPerPixel = 1;
      57             : 
      58             :     // Set the Picture Buffer Static variables
      59       16442 :     pictureBufferDescPtr->max_width = pictureBufferDescInitDataPtr->max_width;
      60       16442 :     pictureBufferDescPtr->max_height = pictureBufferDescInitDataPtr->max_height;
      61       16442 :     pictureBufferDescPtr->width = pictureBufferDescInitDataPtr->max_width;
      62       16442 :     pictureBufferDescPtr->height = pictureBufferDescInitDataPtr->max_height;
      63       16442 :     pictureBufferDescPtr->bit_depth = pictureBufferDescInitDataPtr->bit_depth;
      64       16442 :     pictureBufferDescPtr->color_format = pictureBufferDescInitDataPtr->color_format;
      65       16442 :     pictureBufferDescPtr->stride_y = pictureBufferDescInitDataPtr->max_width + pictureBufferDescInitDataPtr->left_padding + pictureBufferDescInitDataPtr->right_padding;
      66       16442 :     pictureBufferDescPtr->stride_cb = pictureBufferDescPtr->stride_cr = pictureBufferDescPtr->stride_y >> subsampling_x;
      67       16442 :     pictureBufferDescPtr->origin_x = pictureBufferDescInitDataPtr->left_padding;
      68       16442 :     pictureBufferDescPtr->origin_y = pictureBufferDescInitDataPtr->top_padding;
      69       16442 :     pictureBufferDescPtr->origin_bot_y = pictureBufferDescInitDataPtr->bot_padding;
      70             : 
      71       16442 :     pictureBufferDescPtr->luma_size = (pictureBufferDescInitDataPtr->max_width + pictureBufferDescInitDataPtr->left_padding + pictureBufferDescInitDataPtr->right_padding) *
      72       16442 :         (pictureBufferDescInitDataPtr->max_height + pictureBufferDescInitDataPtr->top_padding + pictureBufferDescInitDataPtr->bot_padding);
      73       16442 :     pictureBufferDescPtr->chroma_size = pictureBufferDescPtr->luma_size >> (3 - pictureBufferDescInitDataPtr->color_format);
      74       16442 :     pictureBufferDescPtr->packedFlag = EB_FALSE;
      75             : 
      76       16442 :     if (pictureBufferDescInitDataPtr->split_mode == EB_TRUE) {
      77           0 :         pictureBufferDescPtr->stride_bit_inc_y = pictureBufferDescPtr->stride_y;
      78           0 :         pictureBufferDescPtr->stride_bit_inc_cb = pictureBufferDescPtr->stride_cb;
      79           0 :         pictureBufferDescPtr->stride_bit_inc_cr = pictureBufferDescPtr->stride_cr;
      80             :     }
      81       16442 :     pictureBufferDescPtr->buffer_enable_mask = pictureBufferDescInitDataPtr->buffer_enable_mask;
      82             : 
      83             :     // Allocate the Picture Buffers (luma & chroma)
      84       16442 :     if (pictureBufferDescInitDataPtr->buffer_enable_mask & PICTURE_BUFFER_DESC_Y_FLAG) {
      85       16328 :         EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_y, pictureBufferDescPtr->luma_size * bytesPerPixel);
      86       16328 :         pictureBufferDescPtr->buffer_bit_inc_y = 0;
      87       16328 :         if (pictureBufferDescInitDataPtr->split_mode == EB_TRUE) {
      88           0 :             EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_bit_inc_y, pictureBufferDescPtr->luma_size * bytesPerPixel);
      89             :         }
      90             :     }
      91             : 
      92       16442 :     if (pictureBufferDescInitDataPtr->buffer_enable_mask & PICTURE_BUFFER_DESC_Cb_FLAG) {
      93       15970 :         EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_cb, pictureBufferDescPtr->chroma_size * bytesPerPixel);
      94       15970 :         pictureBufferDescPtr->buffer_bit_inc_cb = 0;
      95       15970 :         if (pictureBufferDescInitDataPtr->split_mode == EB_TRUE) {
      96           0 :             EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_bit_inc_cb, pictureBufferDescPtr->chroma_size * bytesPerPixel);
      97             :         }
      98             :     }
      99             : 
     100       16442 :     if (pictureBufferDescInitDataPtr->buffer_enable_mask & PICTURE_BUFFER_DESC_Cr_FLAG) {
     101       15970 :         EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_cr, pictureBufferDescPtr->chroma_size * bytesPerPixel);
     102       15970 :         pictureBufferDescPtr->buffer_bit_inc_cr = 0;
     103       15970 :         if (pictureBufferDescInitDataPtr->split_mode == EB_TRUE) {
     104           0 :             EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_bit_inc_cr, pictureBufferDescPtr->chroma_size * bytesPerPixel);
     105             :         }
     106             :     }
     107             : 
     108       16442 :     return EB_ErrorNone;
     109             : }
     110             : 
     111          44 : void eb_recon_picture_buffer_desc_dctor(EbPtr p)
     112             : {
     113          44 :     EbPictureBufferDesc *obj = (EbPictureBufferDesc*)p;
     114          44 :     if (obj->buffer_enable_mask & PICTURE_BUFFER_DESC_Y_FLAG)
     115          44 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_y);
     116          44 :     if (obj->buffer_enable_mask & PICTURE_BUFFER_DESC_Cb_FLAG)
     117          44 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_cb);
     118          44 :     if (obj->buffer_enable_mask & PICTURE_BUFFER_DESC_Cb_FLAG)
     119          44 :         EB_FREE_ALIGNED_ARRAY(obj->buffer_cr);
     120          44 : }
     121             : /*****************************************
     122             :  * eb_recon_picture_buffer_desc_ctor
     123             :  *  Initializes the Buffer Descriptor's
     124             :  *  values that are fixed for the life of
     125             :  *  the descriptor.
     126             :  *****************************************/
     127          44 : EbErrorType eb_recon_picture_buffer_desc_ctor(
     128             :     EbPictureBufferDesc  *pictureBufferDescPtr,
     129             :     EbPtr   object_init_data_ptr)
     130             : {
     131          44 :     EbPictureBufferDescInitData  *pictureBufferDescInitDataPtr = (EbPictureBufferDescInitData*)object_init_data_ptr;
     132          44 :     const uint16_t subsampling_x = (pictureBufferDescInitDataPtr->color_format == EB_YUV444 ? 1 : 2) - 1;
     133             : 
     134          44 :     uint32_t bytesPerPixel = (pictureBufferDescInitDataPtr->bit_depth == EB_8BIT) ? 1 : 2;
     135             : 
     136          44 :     pictureBufferDescPtr->dctor = eb_recon_picture_buffer_desc_dctor;
     137             :     // Set the Picture Buffer Static variables
     138          44 :     pictureBufferDescPtr->max_width = pictureBufferDescInitDataPtr->max_width;
     139          44 :     pictureBufferDescPtr->max_height = pictureBufferDescInitDataPtr->max_height;
     140          44 :     pictureBufferDescPtr->width = pictureBufferDescInitDataPtr->max_width;
     141          44 :     pictureBufferDescPtr->height = pictureBufferDescInitDataPtr->max_height;
     142          44 :     pictureBufferDescPtr->bit_depth = pictureBufferDescInitDataPtr->bit_depth;
     143          44 :     pictureBufferDescPtr->color_format = pictureBufferDescInitDataPtr->color_format;
     144          44 :     pictureBufferDescPtr->stride_y = pictureBufferDescInitDataPtr->max_width + pictureBufferDescInitDataPtr->left_padding + pictureBufferDescInitDataPtr->right_padding;
     145          44 :     pictureBufferDescPtr->stride_cb = pictureBufferDescPtr->stride_cr = pictureBufferDescPtr->stride_y >> subsampling_x;
     146          44 :     pictureBufferDescPtr->origin_x = pictureBufferDescInitDataPtr->left_padding;
     147          44 :     pictureBufferDescPtr->origin_y = pictureBufferDescInitDataPtr->top_padding;
     148          44 :     pictureBufferDescPtr->origin_bot_y = pictureBufferDescInitDataPtr->bot_padding;
     149             : 
     150          44 :     pictureBufferDescPtr->luma_size = (pictureBufferDescInitDataPtr->max_width + pictureBufferDescInitDataPtr->left_padding + pictureBufferDescInitDataPtr->right_padding) *
     151          44 :         (pictureBufferDescInitDataPtr->max_height + pictureBufferDescInitDataPtr->top_padding + pictureBufferDescInitDataPtr->bot_padding);
     152          44 :     pictureBufferDescPtr->chroma_size = pictureBufferDescPtr->luma_size >> (3 - pictureBufferDescInitDataPtr->color_format);
     153             : 
     154          44 :     pictureBufferDescPtr->buffer_enable_mask = pictureBufferDescInitDataPtr->buffer_enable_mask;
     155             : 
     156             :     // Allocate the Picture Buffers (luma & chroma)
     157          44 :     if (pictureBufferDescInitDataPtr->buffer_enable_mask & PICTURE_BUFFER_DESC_Y_FLAG) {
     158          44 :         EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_y, pictureBufferDescPtr->luma_size * bytesPerPixel);
     159             :     }
     160          44 :     if (pictureBufferDescInitDataPtr->buffer_enable_mask & PICTURE_BUFFER_DESC_Cb_FLAG) {
     161          44 :         EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_cb, pictureBufferDescPtr->chroma_size * bytesPerPixel);
     162             :    }
     163          44 :     if (pictureBufferDescInitDataPtr->buffer_enable_mask & PICTURE_BUFFER_DESC_Cr_FLAG) {
     164          44 :         EB_CALLOC_ALIGNED_ARRAY(pictureBufferDescPtr->buffer_cr, pictureBufferDescPtr->chroma_size * bytesPerPixel);
     165             :     }
     166          44 :     return EB_ErrorNone;
     167             : }
     168     1781120 : void link_Eb_to_aom_buffer_desc_8bit(
     169             :     EbPictureBufferDesc          *picBuffDsc,
     170             :     Yv12BufferConfig             *aomBuffDsc
     171             : )
     172             : {
     173             :     //forces an 8 bit version
     174             :     //NOTe:  Not all fileds are connected. add more connections as needed.
     175             :     {
     176     1781120 :         aomBuffDsc->y_buffer = picBuffDsc->buffer_y + picBuffDsc->origin_x + (picBuffDsc->origin_y     * picBuffDsc->stride_y);
     177     1781120 :         aomBuffDsc->u_buffer = picBuffDsc->buffer_cb + picBuffDsc->origin_x / 2 + (picBuffDsc->origin_y / 2 * picBuffDsc->stride_cb);
     178     1781120 :         aomBuffDsc->v_buffer = picBuffDsc->buffer_cr + picBuffDsc->origin_x / 2 + (picBuffDsc->origin_y / 2 * picBuffDsc->stride_cb);
     179             : 
     180     1781120 :         aomBuffDsc->y_width = picBuffDsc->width;
     181     1781120 :         aomBuffDsc->uv_width = picBuffDsc->width / 2;
     182             : 
     183     1781120 :         aomBuffDsc->y_height = picBuffDsc->height;
     184     1781120 :         aomBuffDsc->uv_height = picBuffDsc->height / 2;
     185             : 
     186     1781120 :         aomBuffDsc->y_stride = picBuffDsc->stride_y;
     187     1781120 :         aomBuffDsc->uv_stride = picBuffDsc->stride_cb;
     188             : 
     189     1781120 :         aomBuffDsc->border = picBuffDsc->origin_x;
     190             : 
     191     1781120 :         aomBuffDsc->subsampling_x = 1;
     192     1781120 :         aomBuffDsc->subsampling_y = 1;
     193             : 
     194     1781120 :         aomBuffDsc->y_crop_width = aomBuffDsc->y_width;
     195     1781120 :         aomBuffDsc->uv_crop_width = aomBuffDsc->uv_width;
     196     1781120 :         aomBuffDsc->y_crop_height = aomBuffDsc->y_height;
     197     1781120 :         aomBuffDsc->uv_crop_height = aomBuffDsc->uv_height;
     198             : 
     199     1781120 :         aomBuffDsc->flags = 0;
     200             :     }
     201     1781120 : }
     202             : 
     203             : //Jing: TODO
     204             : //Change here later
     205         300 : void link_eb_to_aom_buffer_desc(
     206             :     EbPictureBufferDesc          *picBuffDsc,
     207             :     Yv12BufferConfig             *aomBuffDsc
     208             : )
     209             : {
     210             :     //NOTe:  Not all fileds are connected. add more connections as needed.
     211         300 :     if (picBuffDsc->bit_depth == EB_8BIT) {
     212         300 :         aomBuffDsc->y_buffer = picBuffDsc->buffer_y + picBuffDsc->origin_x + (picBuffDsc->origin_y     * picBuffDsc->stride_y);
     213         300 :         aomBuffDsc->u_buffer = picBuffDsc->buffer_cb + picBuffDsc->origin_x / 2 + (picBuffDsc->origin_y / 2 * picBuffDsc->stride_cb);
     214         300 :         aomBuffDsc->v_buffer = picBuffDsc->buffer_cr + picBuffDsc->origin_x / 2 + (picBuffDsc->origin_y / 2 * picBuffDsc->stride_cb);
     215             : 
     216         300 :         aomBuffDsc->y_width = picBuffDsc->width;
     217         300 :         aomBuffDsc->uv_width = picBuffDsc->width / 2;
     218             : 
     219         300 :         aomBuffDsc->y_height = picBuffDsc->height;
     220         300 :         aomBuffDsc->uv_height = picBuffDsc->height / 2;
     221             : 
     222         300 :         aomBuffDsc->y_stride = picBuffDsc->stride_y;
     223         300 :         aomBuffDsc->uv_stride = picBuffDsc->stride_cb;
     224             : 
     225         300 :         aomBuffDsc->border = picBuffDsc->origin_x;
     226             : 
     227         300 :         aomBuffDsc->subsampling_x = 1;
     228         300 :         aomBuffDsc->subsampling_y = 1;
     229             : 
     230         300 :         aomBuffDsc->y_crop_width = aomBuffDsc->y_width;
     231         300 :         aomBuffDsc->uv_crop_width = aomBuffDsc->uv_width;
     232         300 :         aomBuffDsc->y_crop_height = aomBuffDsc->y_height;
     233         300 :         aomBuffDsc->uv_crop_height = aomBuffDsc->uv_height;
     234             : 
     235         300 :         aomBuffDsc->flags = 0;
     236             :     }
     237             :     else {
     238             :         /*
     239             :         Moving within a 16bit memory area: 2 possible mecanisms:
     240             : 
     241             :         1. to move from one location to another by an offset x, using 16bit pointers
     242             :            int32_t x;
     243             :            U16* Base16b;
     244             :            U16* NewAdd16b = Base16b + x
     245             :            int32_t data = NewAdd16b[0];
     246             : 
     247             :          2. to move from one location to another by an offset x, using 8bit pointers
     248             : 
     249             :             int32_t x;
     250             :             U16* Base16b;
     251             : 
     252             :             U16* baseAd8b = Base16b/2; //convert the base address into 8bit
     253             :             U16* newAd8b  = baseAd8b + x;
     254             : 
     255             :             then before reading the data, we need to convert the pointer back to 16b
     256             :             U16* NewAdd16b = newAd8b*2 ;
     257             :             int32_t data = NewAdd16b[0];
     258             : 
     259             :             NewAdd16b = Base16b + off
     260             :                       = Base16b_asInt + 2*off
     261             :                       =(Base16b_asInt/2 +off)*2
     262             :         */
     263             : 
     264           0 :         aomBuffDsc->y_buffer = CONVERT_TO_BYTEPTR(picBuffDsc->buffer_y);
     265           0 :         aomBuffDsc->u_buffer = CONVERT_TO_BYTEPTR(picBuffDsc->buffer_cb);
     266           0 :         aomBuffDsc->v_buffer = CONVERT_TO_BYTEPTR(picBuffDsc->buffer_cr);
     267             : 
     268           0 :         aomBuffDsc->y_buffer += picBuffDsc->origin_x + (picBuffDsc->origin_y     * picBuffDsc->stride_y);
     269           0 :         aomBuffDsc->u_buffer += picBuffDsc->origin_x / 2 + (picBuffDsc->origin_y / 2 * picBuffDsc->stride_cb);
     270           0 :         aomBuffDsc->v_buffer += picBuffDsc->origin_x / 2 + (picBuffDsc->origin_y / 2 * picBuffDsc->stride_cb);
     271             : 
     272           0 :         aomBuffDsc->y_width = picBuffDsc->width;
     273           0 :         aomBuffDsc->uv_width = picBuffDsc->width / 2;
     274             : 
     275           0 :         aomBuffDsc->y_height = picBuffDsc->height;
     276           0 :         aomBuffDsc->uv_height = picBuffDsc->height / 2;
     277             : 
     278           0 :         aomBuffDsc->y_stride = picBuffDsc->stride_y;
     279           0 :         aomBuffDsc->uv_stride = picBuffDsc->stride_cb;
     280             : 
     281           0 :         aomBuffDsc->border = picBuffDsc->origin_x;
     282             : 
     283           0 :         aomBuffDsc->subsampling_x = 1;
     284           0 :         aomBuffDsc->subsampling_y = 1;
     285             : 
     286           0 :         aomBuffDsc->y_crop_width = aomBuffDsc->y_width;
     287           0 :         aomBuffDsc->uv_crop_width = aomBuffDsc->uv_width;
     288           0 :         aomBuffDsc->y_crop_height = aomBuffDsc->y_height;
     289           0 :         aomBuffDsc->uv_crop_height = aomBuffDsc->uv_height;
     290           0 :         aomBuffDsc->flags = YV12_FLAG_HIGHBITDEPTH;
     291             :     }
     292         300 : }
     293             : 
     294             : void *eb_aom_memalign(size_t align, size_t size);
     295             : void eb_aom_free(void *memblk);
     296             : 
     297             : #define yv12_align_addr(addr, align) \
     298             :   (void *)(((size_t)(addr) + ((align)-1)) & (size_t) - (align))
     299             : 
     300          60 : int32_t eb_aom_realloc_frame_buffer(Yv12BufferConfig *ybf, int32_t width, int32_t height,
     301             :     int32_t ss_x, int32_t ss_y, int32_t use_highbitdepth,
     302             :     int32_t border, int32_t byte_alignment,
     303             :     AomCodecFrameBuffer *fb,
     304             :     aom_get_frame_buffer_cb_fn_t cb, void *cb_priv) {
     305          60 :     if (ybf) {
     306          60 :         const int32_t aom_byte_align = (byte_alignment == 0) ? 1 : byte_alignment;
     307          60 :         const int32_t aligned_width = (width + 7) & ~7;
     308          60 :         const int32_t aligned_height = (height + 7) & ~7;
     309          60 :         const int32_t y_stride = ((aligned_width + 2 * border) + 31) & ~31;
     310          60 :         const uint64_t yplane_size =
     311          60 :             (aligned_height + 2 * border) * (uint64_t)y_stride + byte_alignment;
     312          60 :         const int32_t uv_width = aligned_width >> ss_x;
     313          60 :         const int32_t uv_height = aligned_height >> ss_y;
     314          60 :         const int32_t uv_stride = y_stride >> ss_x;
     315          60 :         const int32_t uv_border_w = border >> ss_x;
     316          60 :         const int32_t uv_border_h = border >> ss_y;
     317          60 :         const uint64_t uvplane_size =
     318          60 :             (uv_height + 2 * uv_border_h) * (uint64_t)uv_stride + byte_alignment;
     319             : 
     320          60 :         const uint64_t frame_size =
     321          60 :             (1 + use_highbitdepth) * (yplane_size + 2 * uvplane_size);
     322             : 
     323          60 :         uint8_t *buf = NULL;
     324             : 
     325          60 :         if (cb != NULL) {
     326           0 :             const int32_t align_addr_extra_size = 31;
     327           0 :             const uint64_t external_frame_size = frame_size + align_addr_extra_size;
     328             : 
     329             :             assert(fb != NULL);
     330             : 
     331             :             if (external_frame_size != (size_t)external_frame_size) return -1;
     332             : 
     333             :             // Allocation to hold larger frame, or first allocation.
     334           0 :             if (cb(cb_priv, (size_t)external_frame_size, fb) < 0) return -1;
     335             : 
     336           0 :             if (fb->data == NULL || fb->size < external_frame_size) return -1;
     337             : 
     338           0 :             ybf->buffer_alloc = (uint8_t *)yv12_align_addr(fb->data, 32);
     339             : 
     340             : #if defined(__has_feature)
     341             : #if __has_feature(memory_sanitizer)
     342             :             // This memset is needed for fixing the issue of using uninitialized
     343             :             // value in msan test. It will cause a perf loss, so only do this for
     344             :             // msan test.
     345             :             memset(ybf->buffer_alloc, 0, (int32_t)frame_size);
     346             : #endif
     347             : #endif
     348             :         }
     349          60 :         else if (frame_size > (size_t)ybf->buffer_alloc_sz) {
     350             :             // Allocation to hold larger frame, or first allocation.
     351          60 :             if (ybf->buffer_alloc_sz > 0)
     352           0 :                 EB_FREE_ARRAY(ybf->buffer_alloc);
     353             :             if (frame_size != (size_t)frame_size) return -1;
     354          60 :             EB_MALLOC_ARRAY(ybf->buffer_alloc, frame_size);
     355             : 
     356          60 :             if (!ybf->buffer_alloc) return -1;
     357             : 
     358          60 :             ybf->buffer_alloc_sz = (size_t)frame_size;
     359             : 
     360             :             // This memset is needed for fixing valgrind error from C loop filter
     361             :             // due to access uninitialized memory in frame border. It could be
     362             :             // removed if border is totally removed.
     363          60 :             memset(ybf->buffer_alloc, 0, ybf->buffer_alloc_sz);
     364             :         }
     365             : 
     366             :         /* Only support allocating buffers that have a border that's a multiple
     367             :         * of 32. The border restriction is required to get 16-byte alignment of
     368             :         * the start of the chroma rows without introducing an arbitrary gap
     369             :         * between planes, which would break the semantics of things like
     370             :         * aom_img_set_rect(). */
     371          60 :         if (border & 0x1f) return -3;
     372             : 
     373          60 :         ybf->y_crop_width = width;
     374          60 :         ybf->y_crop_height = height;
     375          60 :         ybf->y_width = aligned_width;
     376          60 :         ybf->y_height = aligned_height;
     377          60 :         ybf->y_stride = y_stride;
     378             : 
     379          60 :         ybf->uv_crop_width = (width + ss_x) >> ss_x;
     380          60 :         ybf->uv_crop_height = (height + ss_y) >> ss_y;
     381          60 :         ybf->uv_width = uv_width;
     382          60 :         ybf->uv_height = uv_height;
     383          60 :         ybf->uv_stride = uv_stride;
     384             : 
     385          60 :         ybf->border = border;
     386          60 :         ybf->frame_size = (size_t)frame_size;
     387          60 :         ybf->subsampling_x = ss_x;
     388          60 :         ybf->subsampling_y = ss_y;
     389             : 
     390          60 :         buf = ybf->buffer_alloc;
     391          60 :         if (use_highbitdepth) {
     392             :             // Store uint16 addresses when using 16bit framebuffers
     393           0 :             buf = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
     394           0 :             ybf->flags = YV12_FLAG_HIGHBITDEPTH;
     395             :         }
     396             :         else
     397          60 :             ybf->flags = 0;
     398          60 :         ybf->y_buffer = (uint8_t *)yv12_align_addr(
     399             :             buf + (border * y_stride) + border, aom_byte_align);
     400          60 :         ybf->u_buffer = (uint8_t *)yv12_align_addr(
     401             :             buf + yplane_size + (uv_border_h * uv_stride) + uv_border_w,
     402             :             aom_byte_align);
     403          60 :         ybf->v_buffer =
     404          60 :             (uint8_t *)yv12_align_addr(buf + yplane_size + uvplane_size +
     405             :             (uv_border_h * uv_stride) + uv_border_w,
     406             :                 aom_byte_align);
     407             : 
     408          60 :         ybf->use_external_refernce_buffers = 0;
     409             : 
     410             :         //if (use_highbitdepth) {
     411             :         //    if (ybf->y_buffer_8bit) eb_aom_free(ybf->y_buffer_8bit);
     412             :         //    ybf->y_buffer_8bit = (uint8_t *)eb_aom_memalign(32, (size_t)yplane_size);
     413             :         //    if (!ybf->y_buffer_8bit) return -1;
     414             :         //}
     415             :         //else {
     416             :         //    assert(!ybf->y_buffer_8bit);
     417             :         //}
     418             : 
     419          60 :         ybf->corrupted = 0; /* assume not corrupted by errors */
     420          60 :         return 0;
     421             :     }
     422           0 :     return -2;
     423             : }

Generated by: LCOV version 1.14