Coverage Report

Created: 2024-06-24 06:30

/src/libmpeg2/decoder/impeg2d_deinterlace.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <stdio.h>
21
#include "iv_datatypedef.h"
22
#include "iv.h"
23
24
#include "icv.h"
25
#include "ideint.h"
26
27
#include "impeg2_buf_mgr.h"
28
#include "impeg2_disp_mgr.h"
29
#include "impeg2_defs.h"
30
#include "impeg2_platform_macros.h"
31
#include "impeg2_inter_pred.h"
32
#include "impeg2_idct.h"
33
#include "impeg2_globals.h"
34
#include "impeg2_mem_func.h"
35
#include "impeg2_format_conv.h"
36
#include "impeg2_macros.h"
37
38
#include "impeg2d.h"
39
#include "impeg2d_bitstream.h"
40
#include "impeg2d_structs.h"
41
#include "impeg2d_globals.h"
42
#include "impeg2d_mc.h"
43
#include "impeg2d_pic_proc.h"
44
#include "impeg2d_deinterlace.h"
45
46
typedef struct
47
{
48
    IVD_ARCH_T ivd_arch;
49
    ICV_ARCH_T icv_arch;
50
}arch_map_t;
51
52
static const arch_map_t gas_impeg2d_arch_mapping[] =
53
{
54
    {ARCH_ARM_NONEON,       ICV_ARM_NONEON},
55
    {ARCH_ARM_A9Q,          ICV_ARM_A9Q},
56
    {ARCH_ARM_A9A,          ICV_ARM_A9A},
57
    {ARCH_ARM_A9,           ICV_ARM_A9},
58
    {ARCH_ARM_A7,           ICV_ARM_A7},
59
    {ARCH_ARM_A5,           ICV_ARM_A5},
60
    {ARCH_ARM_A15,          ICV_ARM_A15},
61
    {ARCH_ARM_NEONINTR,     ICV_ARM_NEONINTR},
62
    {ARCH_ARMV8_GENERIC,    ICV_ARMV8_GENERIC},
63
    {ARCH_X86_GENERIC,      ICV_X86_GENERIC},
64
    {ARCH_X86_SSSE3,        ICV_X86_SSSE3},
65
    {ARCH_X86_SSE42,        ICV_X86_SSE42},
66
    {ARCH_X86_AVX2,         ICV_X86_AVX2},
67
    {ARCH_MIPS_GENERIC,     ICV_MIPS_GENERIC},
68
    {ARCH_MIPS_32,          ICV_MIPS_32},
69
    {ARCH_RISCV_GENERIC,    ICV_RISCV_GENERIC},
70
};
71
72
73
static void impeg2d_get_pic(icv_pic_t *ps_dst,
74
                            UWORD8 *pu1_buf_y,
75
                            UWORD8 *pu1_buf_u,
76
                            UWORD8 *pu1_buf_v,
77
                            WORD32 wd,
78
                            WORD32 ht,
79
                            WORD32 strd)
80
166k
{
81
166k
    ps_dst->ai4_wd[0] = wd;
82
166k
    ps_dst->ai4_wd[1] = wd / 2;
83
166k
    ps_dst->ai4_wd[2] = wd / 2;
84
85
166k
    ps_dst->ai4_ht[0] = ht;
86
166k
    ps_dst->ai4_ht[1] = ht / 2;
87
166k
    ps_dst->ai4_ht[2] = ht / 2;
88
89
166k
    ps_dst->ai4_strd[0] = strd;
90
166k
    ps_dst->ai4_strd[1] = strd / 2;
91
166k
    ps_dst->ai4_strd[2] = strd / 2;
92
93
166k
    ps_dst->apu1_buf[0] = pu1_buf_y;
94
166k
    ps_dst->apu1_buf[1] = pu1_buf_u;
95
166k
    ps_dst->apu1_buf[2] = pu1_buf_v;
96
97
166k
    ps_dst->e_color_fmt = ICV_YUV420P;
98
166k
}
99
static void impeg2d_get_flds(icv_pic_t *ps_frm,
100
                             icv_pic_t *ps_top_fld,
101
                             icv_pic_t *ps_bot_fld)
102
103k
{
103
103k
    ps_top_fld->ai4_wd[0] = ps_frm->ai4_wd[0];
104
103k
    ps_top_fld->ai4_wd[1] = ps_frm->ai4_wd[1];
105
103k
    ps_top_fld->ai4_wd[2] = ps_frm->ai4_wd[2];
106
107
103k
    ps_top_fld->ai4_ht[0] = ps_frm->ai4_ht[0] / 2;
108
103k
    ps_top_fld->ai4_ht[1] = ps_frm->ai4_ht[1] / 2;
109
103k
    ps_top_fld->ai4_ht[2] = ps_frm->ai4_ht[2] / 2;
110
111
103k
    ps_top_fld->ai4_strd[0] = ps_frm->ai4_strd[0] * 2;
112
103k
    ps_top_fld->ai4_strd[1] = ps_frm->ai4_strd[1] * 2;
113
103k
    ps_top_fld->ai4_strd[2] = ps_frm->ai4_strd[2] * 2;
114
115
103k
    ps_top_fld->e_color_fmt = ps_frm->e_color_fmt;
116
117
    /* Copy top field structure to bottom field, since properties of both fields are same */
118
103k
    *ps_bot_fld = *ps_top_fld;
119
120
    /* Initialize the addresses for top field */
121
103k
    ps_top_fld->apu1_buf[0] = ps_frm->apu1_buf[0];
122
103k
    ps_top_fld->apu1_buf[1] = ps_frm->apu1_buf[1];
123
103k
    ps_top_fld->apu1_buf[2] = ps_frm->apu1_buf[2];
124
125
    /* Initialize the addresses for bottom field */
126
103k
    ps_bot_fld->apu1_buf[0] = ps_frm->apu1_buf[0] + ps_frm->ai4_strd[0];
127
103k
    ps_bot_fld->apu1_buf[1] = ps_frm->apu1_buf[1] + ps_frm->ai4_strd[1];
128
103k
    ps_bot_fld->apu1_buf[2] = ps_frm->apu1_buf[2] + ps_frm->ai4_strd[2];
129
130
103k
    return;
131
103k
}
132
133
134
static ICV_ARCH_T impeg2d_get_arch(IVD_ARCH_T e_arch)
135
63.1k
{
136
63.1k
    ICV_ARCH_T ret_arch;
137
63.1k
    WORD32 num_entries, i;
138
139
63.1k
    ret_arch = ICV_ARM_A9;
140
63.1k
    num_entries = sizeof(gas_impeg2d_arch_mapping) / sizeof(gas_impeg2d_arch_mapping[0]);
141
173k
    for(i = 0; i < num_entries; i++)
142
173k
    {
143
173k
        if(e_arch == gas_impeg2d_arch_mapping[i].ivd_arch)
144
63.0k
        {
145
63.0k
            ret_arch = gas_impeg2d_arch_mapping[i].icv_arch;
146
63.0k
            break;
147
63.0k
        }
148
173k
    }
149
63.1k
    return ret_arch;
150
63.1k
}
151
152
/******************************************************************************
153
*  Function Name   : impeg2d_deinterlace
154
*
155
*  Description     : Deinterlace current picture
156
*
157
*  Arguments       :
158
*  dec             : Decoder Context
159
*
160
*  Values Returned : 0 on success, -1 on error
161
******************************************************************************/
162
WORD32 impeg2d_deint_ctxt_size(void)
163
12.4k
{
164
12.4k
    return ideint_ctxt_size();
165
12.4k
}
166
167
/******************************************************************************
168
*  Function Name   : impeg2d_deinterlace
169
*
170
*  Description     : Deinterlace current picture
171
*
172
*  Arguments       :
173
*  dec             : Decoder Context
174
*
175
*  Values Returned : 0 on success, -1 on error
176
******************************************************************************/
177
WORD32 impeg2d_deinterlace(dec_state_t *ps_dec,
178
                           pic_buf_t *ps_src_pic,
179
                           iv_yuv_buf_t *ps_disp_frm_buf,
180
                           WORD32 start_row,
181
                           WORD32 num_rows)
182
63.1k
{
183
63.1k
    icv_pic_t as_inp_flds[3];
184
63.1k
    IDEINT_ERROR_T ret;
185
63.1k
    icv_pic_t s_src_frm;
186
63.1k
    icv_pic_t s_dst_frm;
187
63.1k
    UWORD8 *pu1_dst_y, *pu1_dst_u, *pu1_dst_v;
188
63.1k
    ideint_params_t s_params;
189
190
63.1k
    if((NULL == ps_src_pic) || (NULL == ps_src_pic->pu1_y) || (0 == num_rows))
191
0
        return -1;
192
193
63.1k
    s_params.e_arch = impeg2d_get_arch(ps_dec->e_processor_arch);
194
63.1k
    s_params.e_soc = ICV_SOC_GENERIC;
195
63.1k
    s_params.e_mode = IDEINT_MODE_SPATIAL;
196
63.1k
    s_params.i4_cur_fld_top = ps_dec->u2_top_field_first;
197
63.1k
    s_params.i4_disable_weave = 0;
198
63.1k
    s_params.pf_aligned_alloc = NULL;
199
63.1k
    s_params.pf_aligned_free = NULL;
200
201
63.1k
    impeg2d_get_pic(&s_src_frm, ps_src_pic->pu1_y, ps_src_pic->pu1_u,
202
63.1k
                    ps_src_pic->pu1_v, ps_dec->u2_horizontal_size,
203
63.1k
                    ps_dec->u2_vertical_size, ps_dec->u2_frame_width);
204
63.1k
    impeg2d_get_flds(&s_src_frm, &as_inp_flds[1], &as_inp_flds[2]);
205
206
63.1k
    if(ps_dec->ps_deint_pic)
207
40.2k
    {
208
40.2k
        icv_pic_t s_prv_frm;
209
40.2k
        icv_pic_t s_fld;
210
40.2k
        impeg2d_get_pic(&s_prv_frm, ps_dec->ps_deint_pic->pu1_y,
211
40.2k
                        ps_dec->ps_deint_pic->pu1_u,
212
40.2k
                        ps_dec->ps_deint_pic->pu1_v, ps_dec->u2_horizontal_size,
213
40.2k
                        ps_dec->u2_vertical_size, ps_dec->u2_frame_width);
214
40.2k
        impeg2d_get_flds(&s_prv_frm, &s_fld, &as_inp_flds[0]);
215
40.2k
    }
216
22.8k
    else
217
22.8k
    {
218
22.8k
        as_inp_flds[0].apu1_buf[0] = NULL;
219
22.8k
        as_inp_flds[0].apu1_buf[1] = NULL;
220
22.8k
        as_inp_flds[0].apu1_buf[2] = NULL;
221
22.8k
    }
222
223
63.1k
    pu1_dst_y = ps_disp_frm_buf->pv_y_buf;
224
63.1k
    pu1_dst_u = ps_disp_frm_buf->pv_u_buf;
225
63.1k
    pu1_dst_v = ps_disp_frm_buf->pv_v_buf;
226
227
    /* Use intermediate buffer as output to deinterlacer,
228
     * if color format is not 420P
229
     */
230
63.1k
    if(IV_YUV_420P != ps_dec->i4_chromaFormat)
231
23.9k
    {
232
23.9k
        UWORD8 *pu1_buf_y;
233
23.9k
        UWORD8 *pu1_buf_u;
234
23.9k
        UWORD8 *pu1_buf_v;
235
23.9k
        WORD32 wd = ALIGN16(ps_dec->u2_horizontal_size);
236
23.9k
        WORD32 ht = ALIGN16(ps_dec->u2_vertical_size);
237
238
23.9k
        pu1_buf_y = ps_dec->pu1_deint_fmt_buf;
239
23.9k
        pu1_buf_u = pu1_buf_y + wd * ht;
240
23.9k
        pu1_buf_v = pu1_buf_u + wd * ht / 4;
241
242
23.9k
        pu1_dst_u = pu1_buf_u;
243
23.9k
        pu1_dst_v = pu1_buf_v;
244
245
23.9k
        if((ps_dec->i4_chromaFormat != IV_YUV_420SP_UV) &&
246
23.9k
           (ps_dec->i4_chromaFormat != IV_YUV_420SP_VU))
247
0
        {
248
0
            pu1_dst_y = pu1_buf_y;
249
0
        }
250
251
23.9k
    }
252
63.1k
    impeg2d_get_pic(&s_dst_frm, pu1_dst_y, pu1_dst_u, pu1_dst_v,
253
63.1k
                    ps_dec->u2_horizontal_size, ps_dec->u2_vertical_size,
254
63.1k
                    ps_dec->u4_frm_buf_stride);
255
256
257
63.1k
    ret = ideint_process(ps_dec->pv_deinterlacer_ctxt, &as_inp_flds[0],
258
63.1k
                         &as_inp_flds[1], &as_inp_flds[2], &s_dst_frm,
259
63.1k
                         &s_params, start_row, num_rows);
260
261
63.1k
    if(IDEINT_ERROR_NONE != ret)
262
0
    {
263
0
        return -1;
264
0
    }
265
266
    /* Format convert deinterlacer output if required*/
267
63.1k
    if(IV_YUV_420P != ps_dec->i4_chromaFormat)
268
23.8k
    {
269
23.8k
        pic_buf_t s_src_pic;
270
271
23.8k
        s_src_pic = *ps_src_pic;
272
23.8k
        s_src_pic.pu1_y = pu1_dst_y;
273
23.8k
        s_src_pic.pu1_u = pu1_dst_u;
274
23.8k
        s_src_pic.pu1_v = pu1_dst_v;
275
276
23.8k
        impeg2d_format_convert(ps_dec,
277
23.8k
                               &s_src_pic,
278
23.8k
                               ps_disp_frm_buf,
279
23.8k
                               start_row,
280
23.8k
                               num_rows);
281
282
23.8k
    }
283
63.1k
    return 0;
284
285
63.1k
}