Coverage Report

Created: 2026-07-30 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/svt-av1/Source/Lib/Codec/reference_object.c
Line
Count
Source
1
/*
2
* Copyright(c) 2019 Intel Corporation
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 https://www.aomedia.org/license/software-license. 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 https://www.aomedia.org/license/patent-license.
10
*/
11
12
#include <stdlib.h>
13
#include <string.h>
14
15
#include "svt_threads.h"
16
#include "reference_object.h"
17
#include "pic_buffer_desc.h"
18
#include "utility.h"
19
#include "enc_mode_config.h"
20
21
static void initialize_samples_neighboring_reference_picture_8bit(EbByte recon_samples_buffer_ptr, uint16_t stride,
22
2.91k
                                                                  uint16_t recon_width, uint16_t recon_height) {
23
2.91k
    uint8_t* recon_samples_ptr;
24
2.91k
    uint16_t sample_count;
25
26
    // 1. zero out the top row
27
2.91k
    recon_samples_ptr = recon_samples_buffer_ptr - stride - 1;
28
2.91k
    svt_memset(recon_samples_ptr, 0, sizeof(uint8_t) * (1 + recon_width + 1));
29
30
    // 2. zero out the bottom row
31
2.91k
    recon_samples_ptr = recon_samples_buffer_ptr + (recon_height)*stride - 1;
32
2.91k
    svt_memset(recon_samples_ptr, 0, sizeof(uint8_t) * (1 + recon_width + 1));
33
34
    // 3. zero out the left column
35
2.91k
    recon_samples_ptr = recon_samples_buffer_ptr - 1;
36
383k
    for (sample_count = 0; sample_count < recon_height; sample_count++) {
37
380k
        recon_samples_ptr[sample_count * stride] = 0;
38
380k
    }
39
    // 4. zero out the right column
40
2.91k
    recon_samples_ptr = recon_samples_buffer_ptr + recon_width;
41
383k
    for (sample_count = 0; sample_count < recon_height; sample_count++) {
42
380k
        recon_samples_ptr[sample_count * stride] = 0;
43
380k
    }
44
2.91k
}
45
46
970
static void initialize_samples_neighboring_reference_picture(EbPictureBufferDesc* ref_pic) {
47
970
    initialize_samples_neighboring_reference_picture_8bit(
48
970
        ref_pic->y_buffer, ref_pic->y_stride, ref_pic->width, ref_pic->height);
49
50
970
    initialize_samples_neighboring_reference_picture_8bit(
51
970
        ref_pic->u_buffer, ref_pic->u_stride, ref_pic->width >> 1, ref_pic->height >> 1);
52
53
970
    initialize_samples_neighboring_reference_picture_8bit(
54
970
        ref_pic->v_buffer, ref_pic->v_stride, ref_pic->width >> 1, ref_pic->height >> 1);
55
970
}
56
57
970
static void svt_reference_object_dctor(EbPtr p) {
58
970
    EbReferenceObject* obj = (EbReferenceObject*)p;
59
60
970
    EB_DELETE(obj->reference_picture);
61
970
    EB_FREE_2D(obj->unit_info);
62
970
    EB_FREE_ALIGNED_ARRAY(obj->mvs);
63
970
    EB_FREE_ARRAY(obj->sb_intra);
64
970
    EB_FREE_ARRAY(obj->sb_skip);
65
970
    EB_FREE_ARRAY(obj->sb_64x64_mvp);
66
970
    EB_FREE_ARRAY(obj->sb_me_64x64_dist);
67
970
    EB_FREE_ARRAY(obj->sb_me_8x8_cost_var);
68
970
    EB_FREE_ARRAY(obj->sb_min_sq_size);
69
970
    EB_FREE_ARRAY(obj->sb_max_sq_size);
70
9.70k
    for (uint8_t sr_denom_idx = 0; sr_denom_idx < NUM_SR_SCALES + 1; sr_denom_idx++) {
71
96.0k
        for (uint8_t resize_denom_idx = 0; resize_denom_idx < NUM_RESIZE_SCALES + 1; resize_denom_idx++) {
72
87.3k
            if (obj->downscaled_reference_picture[sr_denom_idx][resize_denom_idx] != NULL) {
73
0
                EB_DELETE(obj->downscaled_reference_picture[sr_denom_idx][resize_denom_idx]);
74
0
            }
75
87.3k
            EB_DESTROY_MUTEX(obj->resize_mutex[sr_denom_idx][resize_denom_idx]);
76
87.3k
        }
77
8.73k
    }
78
970
}
79
80
/*
81
svt_reference_param_update: update the parameters in EbReferenceObject for changing the resolution on the fly
82
*/
83
0
EbErrorType svt_reference_param_update(EbReferenceObject* ref_object, SequenceControlSet* scs) {
84
0
    EbPictureBufferDescInitData picture_buffer_desc_init_data_ptr;
85
86
0
    bool is_16bit = SVT_EFFECTIVE_BIT_DEPTH(scs->static_config.encoder_bit_depth) > EB_EIGHT_BIT;
87
    // Initialize the various Picture types
88
0
    picture_buffer_desc_init_data_ptr.max_width           = scs->max_input_luma_width;
89
0
    picture_buffer_desc_init_data_ptr.max_height          = scs->max_input_luma_height;
90
0
    picture_buffer_desc_init_data_ptr.bit_depth           = scs->encoder_bit_depth;
91
0
    picture_buffer_desc_init_data_ptr.color_format        = scs->static_config.encoder_color_format;
92
0
    picture_buffer_desc_init_data_ptr.buffer_enable_mask  = PICTURE_BUFFER_DESC_FULL_MASK;
93
0
    picture_buffer_desc_init_data_ptr.rest_units_per_tile = scs->rest_units_per_tile;
94
0
    picture_buffer_desc_init_data_ptr.sb_total_count      = scs->b64_total_count;
95
0
    uint16_t padding                                      = scs->super_block_size + 32;
96
0
    if (scs->static_config.superres_mode > SUPERRES_NONE || scs->static_config.resize_mode > RESIZE_NONE) {
97
0
        padding += scs->super_block_size;
98
0
    }
99
100
0
    picture_buffer_desc_init_data_ptr.border            = padding;
101
0
    picture_buffer_desc_init_data_ptr.mfmv              = scs->mfmv_enabled;
102
0
    picture_buffer_desc_init_data_ptr.is_16bit_pipeline = SVT_EFFECTIVE_IS_16BIT_PIPELINE(scs->is_16bit_pipeline);
103
104
0
    picture_buffer_desc_init_data_ptr.split_mode = false;
105
0
    if (is_16bit) {
106
0
        picture_buffer_desc_init_data_ptr.bit_depth = EB_TEN_BIT;
107
0
    }
108
109
0
    EbPictureBufferDescInitData picture_buffer_desc_init_data_16bit_ptr = picture_buffer_desc_init_data_ptr;
110
    //TODO:12bit
111
0
    if (picture_buffer_desc_init_data_ptr.bit_depth == EB_TEN_BIT) {
112
0
        picture_buffer_desc_init_data_16bit_ptr.split_mode = true;
113
0
        svt_picture_buffer_desc_update(ref_object->reference_picture, (EbPtr)&picture_buffer_desc_init_data_16bit_ptr);
114
0
    } else {
115
        // Hsan: set split_mode to 0 to as 8BIT input
116
0
        picture_buffer_desc_init_data_ptr.split_mode = false;
117
0
        svt_picture_buffer_desc_update(ref_object->reference_picture, (EbPtr)&picture_buffer_desc_init_data_ptr);
118
119
0
        initialize_samples_neighboring_reference_picture(ref_object->reference_picture);
120
0
    }
121
122
0
    ref_object->mi_rows = ref_object->reference_picture->height >> MI_SIZE_LOG2;
123
0
    ref_object->mi_cols = ref_object->reference_picture->width >> MI_SIZE_LOG2;
124
0
    return EB_ErrorNone;
125
0
}
126
127
/*****************************************
128
 * svt_picture_buffer_desc_ctor
129
 *  Initializes the Buffer Descriptor's
130
 *  values that are fixed for the life of
131
 *  the descriptor.
132
 *****************************************/
133
970
EbErrorType svt_reference_object_ctor(EbReferenceObject* ref_object, EbPtr object_init_data_ptr) {
134
970
    EbReferenceObjectDescInitData* ref_init_ptr = (EbReferenceObjectDescInitData*)object_init_data_ptr;
135
970
    EbPictureBufferDescInitData*   picture_buffer_desc_init_data_ptr = &ref_init_ptr->reference_picture_desc_init_data;
136
970
    EbPictureBufferDescInitData    picture_buffer_desc_init_data_16bit_ptr = *picture_buffer_desc_init_data_ptr;
137
138
970
    ref_object->dctor = svt_reference_object_dctor;
139
    //TODO:12bit
140
970
    if (picture_buffer_desc_init_data_16bit_ptr.bit_depth == EB_TEN_BIT) {
141
        // Hsan: set split_mode to 0 to construct the packed reference buffer (used @ EP)
142
        // Use 10bit here to use in MD
143
0
        picture_buffer_desc_init_data_16bit_ptr.split_mode = true;
144
0
        picture_buffer_desc_init_data_16bit_ptr.bit_depth  = EB_TEN_BIT;
145
0
        EB_NEW(ref_object->reference_picture,
146
0
               svt_picture_buffer_desc_ctor,
147
0
               (EbPtr)&picture_buffer_desc_init_data_16bit_ptr);
148
970
    } else {
149
        // Hsan: set split_mode to 0 to as 8BIT input
150
970
        picture_buffer_desc_init_data_ptr->split_mode = false;
151
970
        EB_NEW(ref_object->reference_picture, svt_picture_buffer_desc_ctor, (EbPtr)picture_buffer_desc_init_data_ptr);
152
153
970
        initialize_samples_neighboring_reference_picture(ref_object->reference_picture);
154
970
    }
155
970
    uint32_t mi_rows = ref_object->reference_picture->height >> MI_SIZE_LOG2;
156
970
    uint32_t mi_cols = ref_object->reference_picture->width >> MI_SIZE_LOG2;
157
    // there should be one unit info per plane and per rest unit
158
970
    EB_MALLOC_2D(ref_object->unit_info, MAX_PLANES, picture_buffer_desc_init_data_ptr->rest_units_per_tile);
159
160
970
    if (picture_buffer_desc_init_data_ptr->mfmv) {
161
        //MFMV map is 8x8 based.
162
970
        const int mem_size = ((mi_rows + 1) >> 1) * ((mi_cols + 1) >> 1);
163
970
        EB_CALLOC_ALIGNED_ARRAY(ref_object->mvs, mem_size);
164
970
    }
165
970
    svt_memset(&ref_object->film_grain_params, 0, sizeof(ref_object->film_grain_params));
166
    // set all supplemental downscaled reference picture pointers to NULL
167
    // resize_mutex[][] is only taken by the super-res / reference-rescaling paths (resize.c);
168
    // skip creating those mutexes when neither super-res nor resize is enabled.
169
970
    const bool scaling_enabled = ref_init_ptr->static_config->superres_mode > SUPERRES_NONE ||
170
970
        ref_init_ptr->static_config->resize_mode > RESIZE_NONE;
171
9.70k
    for (uint8_t sr_denom_idx = 0; sr_denom_idx < NUM_SR_SCALES + 1; sr_denom_idx++) {
172
96.0k
        for (uint8_t resize_denom_idx = 0; resize_denom_idx < NUM_RESIZE_SCALES + 1; resize_denom_idx++) {
173
87.3k
            ref_object->downscaled_reference_picture[sr_denom_idx][resize_denom_idx] = NULL;
174
87.3k
            ref_object->downscaled_picture_number[sr_denom_idx][resize_denom_idx]    = (uint64_t)~0;
175
87.3k
            if (scaling_enabled) {
176
0
                EB_CREATE_MUTEX(ref_object->resize_mutex[sr_denom_idx][resize_denom_idx]);
177
0
            }
178
87.3k
        }
179
8.73k
    }
180
181
970
    ref_object->mi_rows = mi_rows;
182
970
    ref_object->mi_cols = mi_cols;
183
970
    ref_object->r0      = 0.0;
184
970
    EB_MALLOC_ARRAY(ref_object->sb_intra, picture_buffer_desc_init_data_ptr->sb_total_count);
185
970
    EB_MALLOC_ARRAY(ref_object->sb_skip, picture_buffer_desc_init_data_ptr->sb_total_count);
186
970
    EB_MALLOC_ARRAY(ref_object->sb_64x64_mvp, picture_buffer_desc_init_data_ptr->sb_total_count);
187
970
    EB_CALLOC_ARRAY(ref_object->sb_me_64x64_dist, picture_buffer_desc_init_data_ptr->sb_total_count);
188
970
    EB_MALLOC_ARRAY(ref_object->sb_me_8x8_cost_var, picture_buffer_desc_init_data_ptr->sb_total_count);
189
970
    EB_MALLOC_ARRAY(ref_object->sb_min_sq_size, picture_buffer_desc_init_data_ptr->sb_total_count);
190
970
    EB_MALLOC_ARRAY(ref_object->sb_max_sq_size, picture_buffer_desc_init_data_ptr->sb_total_count);
191
970
    return EB_ErrorNone;
192
970
}
193
194
970
EbErrorType svt_reference_object_creator(EbPtr* object_dbl_ptr, EbPtr object_init_data_ptr) {
195
970
    EbReferenceObject* obj;
196
197
970
    *object_dbl_ptr = NULL;
198
970
    EB_NEW(obj, svt_reference_object_ctor, object_init_data_ptr);
199
970
    *object_dbl_ptr = obj;
200
201
970
    return EB_ErrorNone;
202
970
}
203
204
0
EbErrorType svt_reference_object_reset(EbReferenceObject* ref_object, SequenceControlSet* scs) {
205
0
    ref_object->mi_rows = scs->max_input_luma_height >> MI_SIZE_LOG2;
206
0
    ref_object->mi_cols = scs->max_input_luma_width >> MI_SIZE_LOG2;
207
208
0
    return EB_ErrorNone;
209
0
}
210
211
1.94k
static void svt_pa_reference_object_dctor(EbPtr p) {
212
1.94k
    EbPaReferenceObject* obj = (EbPaReferenceObject*)p;
213
1.94k
    if (obj->dummy_obj) {
214
0
        return;
215
0
    }
216
1.94k
    EB_DELETE(obj->input_padded_pic);
217
1.94k
    EB_DELETE(obj->quarter_downsampled_picture_ptr);
218
1.94k
    EB_DELETE(obj->sixteenth_downsampled_picture_ptr);
219
19.4k
    for (uint8_t sr_denom_idx = 0; sr_denom_idx < NUM_SR_SCALES + 1; sr_denom_idx++) {
220
192k
        for (uint8_t resize_denom_idx = 0; resize_denom_idx < NUM_RESIZE_SCALES + 1; resize_denom_idx++) {
221
174k
            if (obj->downscaled_input_padded_picture_ptr[sr_denom_idx][resize_denom_idx] != NULL) {
222
0
                EB_DELETE(obj->downscaled_input_padded_picture_ptr[sr_denom_idx][resize_denom_idx]);
223
0
                EB_DELETE(obj->downscaled_quarter_downsampled_picture_ptr[sr_denom_idx][resize_denom_idx]);
224
0
                EB_DELETE(obj->downscaled_sixteenth_downsampled_picture_ptr[sr_denom_idx][resize_denom_idx]);
225
0
            }
226
174k
            EB_DESTROY_MUTEX(obj->resize_mutex[sr_denom_idx][resize_denom_idx]);
227
174k
        }
228
17.4k
    }
229
1.94k
}
230
231
0
static void svt_tpl_reference_object_dctor(EbPtr p) {
232
0
    EbTplReferenceObject* obj = (EbTplReferenceObject*)p;
233
0
    EB_DELETE(obj->ref_picture_ptr);
234
0
}
235
236
/*
237
svt_pa_reference_param_update: update the parameters in EbPaReferenceObject for changing the resolution on the fly
238
*/
239
0
EbErrorType svt_pa_reference_param_update(EbPaReferenceObject* pa_ref_obj, SequenceControlSet* scs) {
240
0
    EbPictureBufferDescInitData ref_pic_buf_desc_init_data;
241
0
    EbPictureBufferDescInitData quart_pic_buf_desc_init_data;
242
0
    EbPictureBufferDescInitData sixteenth_pic_buf_desc_init_data;
243
    // PA Reference Picture Buffers
244
    // Currently, only Luma samples are needed in the PA
245
0
    ref_pic_buf_desc_init_data.max_width    = scs->max_input_luma_width;
246
0
    ref_pic_buf_desc_init_data.max_height   = scs->max_input_luma_height;
247
0
    ref_pic_buf_desc_init_data.bit_depth    = EB_EIGHT_BIT;
248
0
    ref_pic_buf_desc_init_data.color_format = EB_YUV420; //use 420 for picture analysis
249
    //No full-resolution pixel data is allocated for PA REF,
250
    // it points directly to the Luma input samples of the app data
251
0
    ref_pic_buf_desc_init_data.buffer_enable_mask = 0;
252
253
0
    ref_pic_buf_desc_init_data.border              = scs->border;
254
0
    ref_pic_buf_desc_init_data.split_mode          = false;
255
0
    ref_pic_buf_desc_init_data.rest_units_per_tile = scs->rest_units_per_tile;
256
0
    ref_pic_buf_desc_init_data.mfmv                = 0;
257
0
    ref_pic_buf_desc_init_data.is_16bit_pipeline   = false;
258
259
0
    quart_pic_buf_desc_init_data.max_width           = scs->max_input_luma_width >> 1;
260
0
    quart_pic_buf_desc_init_data.max_height          = scs->max_input_luma_height >> 1;
261
0
    quart_pic_buf_desc_init_data.bit_depth           = EB_EIGHT_BIT;
262
0
    quart_pic_buf_desc_init_data.color_format        = EB_YUV420;
263
0
    quart_pic_buf_desc_init_data.buffer_enable_mask  = PICTURE_BUFFER_DESC_LUMA_MASK;
264
0
    quart_pic_buf_desc_init_data.border              = scs->b64_size >> 1;
265
0
    quart_pic_buf_desc_init_data.split_mode          = false;
266
0
    quart_pic_buf_desc_init_data.rest_units_per_tile = scs->rest_units_per_tile;
267
0
    quart_pic_buf_desc_init_data.mfmv                = 0;
268
0
    quart_pic_buf_desc_init_data.is_16bit_pipeline   = false;
269
270
0
    sixteenth_pic_buf_desc_init_data.max_width           = scs->max_input_luma_width >> 2;
271
0
    sixteenth_pic_buf_desc_init_data.max_height          = scs->max_input_luma_height >> 2;
272
0
    sixteenth_pic_buf_desc_init_data.bit_depth           = EB_EIGHT_BIT;
273
0
    sixteenth_pic_buf_desc_init_data.color_format        = EB_YUV420;
274
0
    sixteenth_pic_buf_desc_init_data.buffer_enable_mask  = PICTURE_BUFFER_DESC_LUMA_MASK;
275
0
    sixteenth_pic_buf_desc_init_data.border              = scs->b64_size >> 2;
276
0
    sixteenth_pic_buf_desc_init_data.split_mode          = false;
277
0
    sixteenth_pic_buf_desc_init_data.rest_units_per_tile = scs->rest_units_per_tile;
278
0
    sixteenth_pic_buf_desc_init_data.mfmv                = 0;
279
0
    sixteenth_pic_buf_desc_init_data.is_16bit_pipeline   = false;
280
281
    // Reference picture constructor
282
0
    svt_picture_buffer_desc_update(pa_ref_obj->input_padded_pic, (EbPtr)&ref_pic_buf_desc_init_data);
283
    // Downsampled reference picture constructor
284
0
    svt_picture_buffer_desc_update(pa_ref_obj->quarter_downsampled_picture_ptr, (EbPtr)&quart_pic_buf_desc_init_data);
285
0
    svt_picture_buffer_desc_update(pa_ref_obj->sixteenth_downsampled_picture_ptr,
286
0
                                   (EbPtr)&sixteenth_pic_buf_desc_init_data);
287
0
    return EB_ErrorNone;
288
0
}
289
290
/*****************************************
291
 * svt_pa_reference_object_ctor
292
 *  Initializes the Buffer Descriptor's
293
 *  values that are fixed for the life of
294
 *  the descriptor.
295
 *****************************************/
296
1.94k
EbErrorType svt_pa_reference_object_ctor(EbPaReferenceObject* pa_ref_obj_, EbPtr object_init_data_ptr) {
297
1.94k
    EbPictureBufferDescInitData* picture_buffer_desc_init_data_ptr = (EbPictureBufferDescInitData*)object_init_data_ptr;
298
1.94k
    const EbPaReferenceObjectDescInitData* pa_init = (EbPaReferenceObjectDescInitData*)object_init_data_ptr;
299
300
1.94k
    pa_ref_obj_->dctor = svt_pa_reference_object_dctor;
301
302
    // Reference picture constructor
303
1.94k
    EB_NEW(pa_ref_obj_->input_padded_pic, svt_picture_buffer_desc_ctor, (EbPtr)picture_buffer_desc_init_data_ptr);
304
    // Downsampled reference picture constructor
305
1.94k
    if (picture_buffer_desc_init_data_ptr[1].buffer_enable_mask) {
306
0
        EB_NEW(pa_ref_obj_->quarter_downsampled_picture_ptr,
307
0
               svt_picture_buffer_desc_ctor,
308
0
               (EbPtr)(picture_buffer_desc_init_data_ptr + 1));
309
0
    }
310
1.94k
    if (picture_buffer_desc_init_data_ptr[2].buffer_enable_mask) {
311
0
        EB_NEW(pa_ref_obj_->sixteenth_downsampled_picture_ptr,
312
0
               svt_picture_buffer_desc_ctor,
313
0
               (EbPtr)(picture_buffer_desc_init_data_ptr + 2));
314
0
    }
315
    // set all supplemental downscaled reference picture pointers to NULL
316
    // resize_mutex[][] is only taken by the super-res / reference-rescaling paths (resize.c);
317
    // skip creating those mutexes when neither super-res nor resize is enabled.
318
1.94k
    const bool scaling_enabled = pa_init->static_config->superres_mode > SUPERRES_NONE ||
319
1.94k
        pa_init->static_config->resize_mode > RESIZE_NONE;
320
19.4k
    for (uint8_t sr_down_idx = 0; sr_down_idx < NUM_SR_SCALES + 1; sr_down_idx++) {
321
192k
        for (uint8_t resize_down_idx = 0; resize_down_idx < NUM_RESIZE_SCALES + 1; resize_down_idx++) {
322
174k
            pa_ref_obj_->downscaled_input_padded_picture_ptr[sr_down_idx][resize_down_idx]          = NULL;
323
174k
            pa_ref_obj_->downscaled_quarter_downsampled_picture_ptr[sr_down_idx][resize_down_idx]   = NULL;
324
174k
            pa_ref_obj_->downscaled_sixteenth_downsampled_picture_ptr[sr_down_idx][resize_down_idx] = NULL;
325
174k
            pa_ref_obj_->downscaled_picture_number[sr_down_idx][resize_down_idx]                    = (uint64_t)~0;
326
174k
            if (scaling_enabled) {
327
0
                EB_CREATE_MUTEX(pa_ref_obj_->resize_mutex[sr_down_idx][resize_down_idx]);
328
0
            }
329
174k
        }
330
17.4k
    }
331
332
1.94k
    return EB_ErrorNone;
333
1.94k
}
334
335
1.94k
EbErrorType svt_pa_reference_object_creator(EbPtr* object_dbl_ptr, EbPtr object_init_data_ptr) {
336
1.94k
    EbPaReferenceObject* obj;
337
338
1.94k
    *object_dbl_ptr = NULL;
339
1.94k
    EB_NEW(obj, svt_pa_reference_object_ctor, object_init_data_ptr);
340
1.94k
    *object_dbl_ptr = obj;
341
342
1.94k
    return EB_ErrorNone;
343
1.94k
}
344
345
/*
346
svt_tpl_reference_param_update: update the parameters in tpl_ref_obj for changing the resolution on the fly
347
*/
348
0
EbErrorType svt_tpl_reference_param_update(EbTplReferenceObject* tpl_ref_obj, SequenceControlSet* scs) {
349
0
    EbPictureBufferDescInitData ref_pic_buf_desc_init_data;
350
    // PA Reference Picture Buffers
351
    // Currently, only Luma samples are needed in the PA
352
0
    ref_pic_buf_desc_init_data.max_width    = scs->max_input_luma_width;
353
0
    ref_pic_buf_desc_init_data.max_height   = scs->max_input_luma_height;
354
0
    ref_pic_buf_desc_init_data.bit_depth    = EB_EIGHT_BIT;
355
0
    ref_pic_buf_desc_init_data.color_format = EB_YUV420; //use 420 for picture analysis
356
357
    // Allocate one ref pic to be used in TPL
358
0
    ref_pic_buf_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_Y_FLAG;
359
360
0
    ref_pic_buf_desc_init_data.border            = TPL_PAD;
361
0
    ref_pic_buf_desc_init_data.split_mode        = false;
362
0
    ref_pic_buf_desc_init_data.mfmv              = 0;
363
0
    ref_pic_buf_desc_init_data.is_16bit_pipeline = false;
364
365
0
    ref_pic_buf_desc_init_data.rest_units_per_tile = 0;
366
0
    ref_pic_buf_desc_init_data.sb_total_count      = scs->sb_total_count;
367
368
    // Reference picture constructor
369
0
    svt_picture_buffer_desc_update(tpl_ref_obj->ref_picture_ptr, (EbPtr)&ref_pic_buf_desc_init_data);
370
371
0
    return EB_ErrorNone;
372
0
}
373
374
0
EbErrorType svt_tpl_reference_object_ctor(EbTplReferenceObject* tpl_ref_obj_, EbPtr object_init_data_ptr) {
375
0
    EbPictureBufferDescInitData* picture_buffer_desc_init_data_ptr = (EbPictureBufferDescInitData*)object_init_data_ptr;
376
377
0
    tpl_ref_obj_->dctor = svt_tpl_reference_object_dctor;
378
379
    // Reference picture constructor
380
0
    EB_NEW(tpl_ref_obj_->ref_picture_ptr, svt_picture_buffer_desc_ctor, (EbPtr)picture_buffer_desc_init_data_ptr);
381
382
0
    return EB_ErrorNone;
383
0
}
384
385
0
EbErrorType svt_tpl_reference_object_creator(EbPtr* object_dbl_ptr, EbPtr object_init_data_ptr) {
386
0
    EbTplReferenceObject* obj;
387
388
0
    *object_dbl_ptr = NULL;
389
0
    EB_NEW(obj, svt_tpl_reference_object_ctor, object_init_data_ptr);
390
0
    *object_dbl_ptr = obj;
391
392
0
    return EB_ErrorNone;
393
0
}
394
395
/************************************************
396
* Release Pa Reference Objects
397
** Check if reference pictures are needed
398
** release them when appropriate
399
************************************************/
400
485
void svt_aom_release_pa_reference_objects(SequenceControlSet* scs, PictureParentControlSet* pcs) {
401
485
    (void)scs;
402
    // PA Reference Pictures
403
485
    if (pcs->slice_type != I_SLICE) {
404
        // Release the PA reference Pictures from both lists
405
0
        for (REF_FRAME_MINUS1 ref = LAST; ref < ALT + 1; ref++) {
406
0
            const uint8_t list_idx = get_list_idx(ref + 1);
407
0
            const uint8_t ref_idx  = get_ref_frame_idx(ref + 1);
408
0
            if (pcs->ref_pa_pic_ptr_array[list_idx][ref_idx] != NULL) {
409
0
                svt_release_object(pcs->ref_pa_pic_ptr_array[list_idx][ref_idx]);
410
0
                if (pcs->ref_y8b_array[list_idx][ref_idx]) {
411
                    //y8b  needs to get decremented at the same time of pa ref
412
0
                    svt_release_object(pcs->ref_y8b_array[list_idx][ref_idx]);
413
0
                }
414
0
            }
415
0
        }
416
0
    }
417
418
485
    if (pcs->pa_ref_pic_wrapper != NULL) {
419
        //assert((int32_t)pcs->pa_ref_pic_wrapper->live_count > 0);
420
485
        svt_release_object(pcs->pa_ref_pic_wrapper);
421
422
485
        if (pcs->y8b_wrapper) {
423
            //y8b needs to get decremented at the same time of pa ref
424
485
            svt_release_object(pcs->y8b_wrapper);
425
485
        }
426
485
    }
427
    // Mark that the PCS released PA references
428
485
    pcs->reference_released = 1;
429
485
    return;
430
485
}