1 /******************************************************************************
2 *
3 * Copyright (C) 2022 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
21 /**
22 *******************************************************************************
23 * @file
24 * isvce_fmt_conv.c
25 *
26 * @brief
27 * Contains functions for format conversion or frame copy of output buffer
28 *
29 * @author
30 * ittiam
31 *
32 * @par List of Functions:
33 * - isvce_fmt_conv()
34 *
35 * @remarks
36 * None
37 *
38 *******************************************************************************
39 */
40 #include "ih264_typedefs.h"
41 #include "ih264_macros.h"
42 /* Dependencies of ih264_buf_mgr.h */
43 /* Dependencies of ih264_list.h */
44 #include "ih264_error.h"
45 /* Dependencies of ih264_common_tables.h */
46 #include "ih264_defs.h"
47 #include "ih264_structs.h"
48 #include "ih264_buf_mgr.h"
49 #include "ih264_common_tables.h"
50 #include "ih264_list.h"
51 #include "ih264_platform_macros.h"
52 #include "ih264_trans_data.h"
53 #include "ih264_size_defs.h"
54 /* Dependencies of ih264e_cabac_structs.h */
55 #include "ih264_cabac_tables.h"
56 /* Dependencies of ime_structs.h */
57 #include "ime_defs.h"
58 #include "ime_distortion_metrics.h"
59 /* Dependencies of ih264e_structs.h */
60 #include "iv2.h"
61 #include "ive2.h"
62 #include "ih264_defs.h"
63 #include "ih264_deblk_edge_filters.h"
64 #include "ih264_inter_pred_filters.h"
65 #include "ih264_structs.h"
66 #include "ih264_trans_quant_itrans_iquant.h"
67 /* Dependencies of ih264e_bitstream.h */
68 #include "ih264e_error.h"
69 #include "ih264e_bitstream.h"
70 #include "ih264e_cabac_structs.h"
71 #include "irc_cntrl_param.h"
72 #include "irc_frame_info_collector.h"
73 #include "ime_statistics.h"
74 #include "ime_structs.h"
75 /* Dependencies of 'ih264e_utils.h' */
76 #include "ih264e_defs.h"
77 #include "ih264e_structs.h"
78 #include "ih264e_fmt_conv.h"
79 #include "isvce_structs.h"
80
isvce_fmt_conv(isvce_codec_t * ps_codec,svc_au_buf_t * ps_pic,UWORD8 * pu1_y_dst,UWORD8 * pu1_u_dst,UWORD8 * pu1_v_dst,UWORD32 u4_dst_y_strd,UWORD32 u4_dst_uv_strd,WORD32 cur_row,WORD32 num_rows)81 IH264E_ERROR_T isvce_fmt_conv(isvce_codec_t *ps_codec, svc_au_buf_t *ps_pic, UWORD8 *pu1_y_dst,
82 UWORD8 *pu1_u_dst, UWORD8 *pu1_v_dst, UWORD32 u4_dst_y_strd,
83 UWORD32 u4_dst_uv_strd, WORD32 cur_row, WORD32 num_rows)
84 {
85 IH264E_ERROR_T ret = IH264E_SUCCESS;
86 UWORD8 *pu1_y_src, *pu1_uv_src;
87 UWORD8 *pu1_y_dst_tmp, *pu1_uv_dst_tmp;
88 UWORD8 *pu1_u_dst_tmp, *pu1_v_dst_tmp;
89 WORD32 is_u_first;
90 UWORD8 *pu1_luma;
91 UWORD8 *pu1_chroma;
92 WORD32 wd;
93
94 WORD32 src_y_strd;
95 WORD32 src_uv_strd;
96
97 WORD32 layer_id = ps_pic->u1_num_spatial_layers - 1;
98
99 if(0 == num_rows)
100 {
101 return ret;
102 }
103
104 pu1_luma = ps_pic->ps_layer_yuv_buf_props[layer_id].as_component_bufs[0].pv_data;
105 pu1_chroma = ps_pic->ps_layer_yuv_buf_props[layer_id].as_component_bufs[1].pv_data;
106
107 src_y_strd = ps_pic->ps_layer_yuv_buf_props[layer_id].as_component_bufs[0].i4_data_stride;
108 src_uv_strd = ps_pic->ps_layer_yuv_buf_props[layer_id].as_component_bufs[1].i4_data_stride;
109
110 wd = ps_codec->s_cfg.u4_disp_wd;
111 is_u_first = (IV_YUV_420SP_UV == ps_codec->e_codec_color_format) ? 1 : 0;
112
113 /* In case of 420P output luma copy is disabled for shared mode */
114 {
115 pu1_y_src = pu1_luma + cur_row * src_y_strd;
116 pu1_uv_src = pu1_chroma + (cur_row / 2) * src_uv_strd;
117
118 pu1_y_dst_tmp = pu1_y_dst + cur_row * u4_dst_y_strd;
119 pu1_uv_dst_tmp = pu1_u_dst + (cur_row / 2) * u4_dst_uv_strd;
120 pu1_u_dst_tmp = pu1_u_dst + (cur_row / 2) * u4_dst_uv_strd;
121 pu1_v_dst_tmp = pu1_v_dst + (cur_row / 2) * u4_dst_uv_strd;
122
123 /* If the call is non-blocking and there are no rows to be copied then
124 * return */
125 /* In non-shared mode, reference buffers are in 420SP UV format,
126 * if output also is in 420SP_UV, then just copy
127 * if output is in 420SP_VU then swap UV values
128 */
129 if((IV_YUV_420SP_UV == ps_codec->s_cfg.e_recon_color_fmt) ||
130 (IV_YUV_420SP_VU == ps_codec->s_cfg.e_recon_color_fmt))
131 {
132 ih264e_fmt_conv_420sp_to_420sp(pu1_y_src, pu1_uv_src, pu1_y_dst_tmp, pu1_uv_dst_tmp, wd,
133 num_rows, ps_codec->i4_rec_strd, ps_codec->i4_rec_strd,
134 u4_dst_y_strd, u4_dst_uv_strd);
135 }
136 else if(IV_YUV_420P == ps_codec->s_cfg.e_recon_color_fmt)
137 {
138 ih264e_fmt_conv_420sp_to_420p(pu1_y_src, pu1_uv_src, pu1_y_dst_tmp, pu1_u_dst_tmp,
139 pu1_v_dst_tmp, wd, num_rows, ps_codec->i4_rec_strd,
140 ps_codec->i4_rec_strd, u4_dst_y_strd, u4_dst_uv_strd,
141 is_u_first, 0);
142 }
143 }
144 return (ret);
145 }
146