@@ -296,6 +296,56 @@ void av2_alloc_cdef_buffers(AV2_COMMON *const cm,
296296 cdef_info -> allocated_mi_rows );
297297}
298298
299+ void av2_alloc_restoration_line_buffers (AV2_COMMON * const cm ,
300+ RestorationLineBuffers * * rlbs_ptr ) {
301+ if (!* rlbs_ptr ) {
302+ CHECK_MEM_ERROR (cm , * rlbs_ptr , avm_calloc (1 , sizeof (* * rlbs_ptr )));
303+ }
304+
305+ RestorationLineBuffers * rlbs = * rlbs_ptr ;
306+ const int frame_w = cm -> mi_params .mi_cols << MI_SIZE_LOG2 ;
307+ for (PLANE_TYPE ptype = PLANE_TYPE_Y ;
308+ ptype <= (cm -> seq_params .monochrome ? PLANE_TYPE_Y : PLANE_TYPE_UV );
309+ ++ ptype ) {
310+ // allocate for line buffer width.
311+ const int ss_x = ptype && cm -> seq_params .subsampling_x ;
312+ const int plane_w =
313+ ((frame_w + ss_x ) >> ss_x ) + 2 * RESTORATION_BORDER_HORZ ;
314+ const int stride = ALIGN_POWER_OF_TWO (plane_w , 5 );
315+
316+ if (stride > rlbs -> line_stride [ptype ]) {
317+ for (int i = 0 ; i < RESTORATION_BORDER_VERT ; ++ i ) {
318+ avm_free (rlbs -> tmp_save_above [ptype ][i ]);
319+ rlbs -> tmp_save_above [ptype ][i ] = NULL ;
320+ CHECK_MEM_ERROR (
321+ cm , rlbs -> tmp_save_above [ptype ][i ],
322+ avm_memalign (32 , stride * sizeof (* rlbs -> tmp_save_above [ptype ][i ])));
323+
324+ avm_free (rlbs -> tmp_save_below [ptype ][i ]);
325+ rlbs -> tmp_save_below [ptype ][i ] = NULL ;
326+ CHECK_MEM_ERROR (
327+ cm , rlbs -> tmp_save_below [ptype ][i ],
328+ avm_memalign (32 , stride * sizeof (* rlbs -> tmp_save_below [ptype ][i ])));
329+ }
330+ rlbs -> line_stride [ptype ] = stride ;
331+ }
332+ }
333+ }
334+
335+ void av2_free_restoration_line_buffers (RestorationLineBuffers * rlbs ) {
336+ if (rlbs ) {
337+ for (PLANE_TYPE ptype = PLANE_TYPE_Y ; ptype < PLANE_TYPES ; ++ ptype ) {
338+ for (int i = 0 ; i < RESTORATION_BORDER_VERT ; ++ i ) {
339+ avm_free (rlbs -> tmp_save_above [ptype ][i ]);
340+ rlbs -> tmp_save_above [ptype ][i ] = NULL ;
341+ avm_free (rlbs -> tmp_save_below [ptype ][i ]);
342+ rlbs -> tmp_save_below [ptype ][i ] = NULL ;
343+ }
344+ }
345+ avm_free (rlbs );
346+ }
347+ }
348+
299349// Assumes cm->rst_info[p].restoration_unit_size is already initialized
300350void av2_alloc_restoration_buffers (AV2_COMMON * cm ) {
301351 const int num_planes = av2_num_planes (cm );
@@ -307,9 +357,8 @@ void av2_alloc_restoration_buffers(AV2_COMMON *cm) {
307357 translate_pcwiener_filters_to_wienerns (cm );
308358 }
309359
310- if (cm -> rlbs == NULL ) {
311- CHECK_MEM_ERROR (cm , cm -> rlbs , avm_malloc (sizeof (RestorationLineBuffers )));
312- }
360+ av2_alloc_restoration_line_buffers (cm , & cm -> rlbs );
361+
313362 if (cm -> lru_stripe_buf == NULL ) {
314363 CHECK_MEM_ERROR (
315364 cm , cm -> lru_stripe_buf ,
@@ -373,7 +422,7 @@ void av2_free_restoration_buffers(AV2_COMMON *cm) {
373422 int p ;
374423 for (p = 0 ; p < MAX_MB_PLANE ; ++ p )
375424 av2_free_restoration_struct (& cm -> rst_info [p ]);
376- avm_free (cm -> rlbs );
425+ av2_free_restoration_line_buffers (cm -> rlbs );
377426 cm -> rlbs = NULL ;
378427 avm_free (cm -> lru_stripe_buf );
379428 cm -> lru_stripe_buf = NULL ;
0 commit comments