Home | History | Annotate | Download | only in encoder
      1 /*
      2  * Copyright (c) 2018, 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 #include <assert.h>
     13 
     14 #include "av1/encoder/encoder.h"
     15 #include "av1/encoder/ethread.h"
     16 #include "av1/encoder/av1_multi_thread.h"
     17 
     18 void av1_row_mt_mem_alloc(AV1_COMP *cpi, int max_sb_rows) {
     19   struct AV1Common *cm = &cpi->common;
     20   MultiThreadHandle *multi_thread_ctxt = &cpi->multi_thread_ctxt;
     21   int tile_row, tile_col;
     22   const int tile_cols = cm->tile_cols;
     23   const int tile_rows = cm->tile_rows;
     24 
     25   multi_thread_ctxt->allocated_tile_cols = tile_cols;
     26   multi_thread_ctxt->allocated_tile_rows = tile_rows;
     27   multi_thread_ctxt->allocated_sb_rows = max_sb_rows;
     28 
     29   // Allocate memory for row based multi-threading
     30   for (tile_row = 0; tile_row < multi_thread_ctxt->allocated_tile_rows;
     31        tile_row++) {
     32     for (tile_col = 0; tile_col < multi_thread_ctxt->allocated_tile_cols;
     33          tile_col++) {
     34       TileDataEnc *this_tile =
     35           &cpi->tile_data[tile_row * multi_thread_ctxt->allocated_tile_cols +
     36                           tile_col];
     37       av1_row_mt_sync_mem_alloc(&this_tile->row_mt_sync, cm, max_sb_rows);
     38       if (cpi->oxcf.cdf_update_mode)
     39         CHECK_MEM_ERROR(
     40             cm, this_tile->row_ctx,
     41             (FRAME_CONTEXT *)aom_memalign(
     42                 16,
     43                 AOMMAX(1, (av1_get_sb_cols_in_tile(cm, this_tile->tile_info) -
     44                            1)) *
     45                     sizeof(*this_tile->row_ctx)));
     46     }
     47   }
     48 }
     49 
     50 void av1_row_mt_mem_dealloc(AV1_COMP *cpi) {
     51   MultiThreadHandle *multi_thread_ctxt = &cpi->multi_thread_ctxt;
     52   int tile_col;
     53   int tile_row;
     54 
     55   // Free row based multi-threading sync memory
     56   for (tile_row = 0; tile_row < multi_thread_ctxt->allocated_tile_rows;
     57        tile_row++) {
     58     for (tile_col = 0; tile_col < multi_thread_ctxt->allocated_tile_cols;
     59          tile_col++) {
     60       TileDataEnc *this_tile =
     61           &cpi->tile_data[tile_row * multi_thread_ctxt->allocated_tile_cols +
     62                           tile_col];
     63       av1_row_mt_sync_mem_dealloc(&this_tile->row_mt_sync);
     64       if (cpi->oxcf.cdf_update_mode) aom_free(this_tile->row_ctx);
     65     }
     66   }
     67   multi_thread_ctxt->allocated_sb_rows = 0;
     68   multi_thread_ctxt->allocated_tile_cols = 0;
     69   multi_thread_ctxt->allocated_tile_rows = 0;
     70 }
     71