1 /*
2 * Copyright 2016 Rockchip Electronics Co. LTD
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define MODULE_TAG "rc_data"
18
19 #include "mpp_env.h"
20 #include "mpp_mem.h"
21 #include "mpp_list.h"
22 #include "mpp_debug.h"
23 #include "mpp_common.h"
24
25 #include "rc_data.h"
26 #include "rc_data_impl.h"
27
28 #define RC_FRM_STATUS_VALID (0x00000001)
29 #define RC_HAL_SET_VALID (0x00000002)
30 #define RC_HAL_RET_VALID (0x00000004)
31
rc_data_init(DataGroup * grp,DataGroupCfg * cfg)32 MPP_RET rc_data_init(DataGroup *grp, DataGroupCfg *cfg)
33 {
34 if (NULL == grp || NULL == cfg ||
35 cfg->base_cnt < 0 || cfg->extra_cnt < 0) {
36 mpp_err_f("invalid data group %p cfg %p\n", grp, cfg);
37 return MPP_ERR_NULL_PTR;
38 }
39
40 DataGroupImpl *p = mpp_malloc(DataGroupImpl, 1);
41
42 mpp_assert(p);
43 MPP_RET ret = rc_data_group_init(p, cfg->base_cnt, cfg->extra_cnt);
44
45 return ret;
46 }
47
rc_data_deinit(DataGroup grp)48 MPP_RET rc_data_deinit(DataGroup grp)
49 {
50 if (NULL == grp) {
51 mpp_err_f("invalid data group %p \n", grp);
52 return MPP_ERR_NULL_PTR;
53 }
54
55 DataGroupImpl *p = (DataGroupImpl *)grp;
56 rc_data_group_deinit(p);
57 MPP_FREE(grp);
58
59 return MPP_OK;
60 }
61
rc_data_reset(DataGroup grp)62 MPP_RET rc_data_reset(DataGroup grp)
63 {
64 if (NULL == grp) {
65 mpp_err_f("invalid data group %p \n", grp);
66 return MPP_ERR_NULL_PTR;
67 }
68
69 DataGroupImpl *p = (DataGroupImpl *)grp;
70
71 return rc_data_group_reset(p);
72 }
73
rc_data_get(DataGroup grp,RK_S32 seq_id)74 RcData rc_data_get(DataGroup grp, RK_S32 seq_id)
75 {
76 if (NULL == grp) {
77 mpp_err_f("invalid data group %p\n", grp);
78 return NULL;
79 }
80
81 DataGroupImpl *p = (DataGroupImpl *)grp;
82 RcData data = (RcData)rc_data_group_get_node_by_seq_id(p, seq_id);
83
84 return data;
85 }
86
87 #define check_is_rc_data(data) _check_is_rc_data(data, __FUNCTION__)
88
_check_is_rc_data(void * data,const char * caller)89 MPP_RET _check_is_rc_data(void *data, const char *caller)
90 {
91 if (data && ((RcDataNode *)data)->head.node == data)
92 return MPP_OK;
93
94 mpp_err("%s node %p failed on check\n", caller, data);
95 mpp_abort();
96 return MPP_NOK;
97 }
98
rc_data_get_seq_id(RcData data)99 const RK_S32 *rc_data_get_seq_id(RcData data)
100 {
101 if (!check_is_rc_data(data))
102 return NULL;
103
104 RcDataNode *node = (RcDataNode *)data;
105
106 return (const RK_S32 *)&node->head.seq_id;
107 }
108
rc_data_get_qp_sum(RcData data)109 const RK_S32 *rc_data_get_qp_sum(RcData data)
110 {
111 if (!check_is_rc_data(data))
112 return NULL;
113
114 RcDataNode *node = (RcDataNode *)data;
115
116 return (const RK_S32 *)&node->base.qp_sum;
117 }
118
rc_data_get_strm_size(RcData data)119 const RK_S32 *rc_data_get_strm_size(RcData data)
120 {
121 if (!check_is_rc_data(data))
122 return NULL;
123
124 RcDataNode *node = (RcDataNode *)data;
125
126 return (const RK_S32 *)&node->base.stream_size;
127 }
128
rc_data_get_frm_status(RcData data)129 const EncFrmStatus *rc_data_get_frm_status(RcData data)
130 {
131 if (!check_is_rc_data(data))
132 return NULL;
133
134 RcDataNode *node = (RcDataNode *)data;
135
136 return (const EncFrmStatus *)&node->head.frm_status;
137 }
138
rc_data_get_hal_set(RcData data)139 const RcHalSet *rc_data_get_hal_set(RcData data)
140 {
141 if (!check_is_rc_data(data))
142 return NULL;
143
144 RcDataNode *node = (RcDataNode *)data;
145 if (NULL == node->extra)
146 return NULL;
147
148 return (const RcHalSet *)&node->extra->set;
149 }
150
rc_data_get_hal_ret(RcData data)151 const RcHalRet *rc_data_get_hal_ret(RcData data)
152 {
153 if (!check_is_rc_data(data))
154 return NULL;
155
156 RcDataNode *node = (RcDataNode *)data;
157 if (NULL == node->extra)
158 return NULL;
159
160 return (const RcHalRet *)&node->extra->ret;
161 }
162