xref: /OK3568_Linux_fs/external/mpp/mpp/codec/rc/rc_data_base.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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_base"
18 
19 #include "mpp_mem.h"
20 
21 #include "rc_data_base.h"
22 
node_group_init(NodeGroup ** grp,RK_S32 node_size,RK_S32 node_count)23 MPP_RET node_group_init(NodeGroup **grp, RK_S32 node_size, RK_S32 node_count)
24 {
25     NodeGroup *p = mpp_malloc_size(NodeGroup, sizeof(NodeGroup) +
26                                    node_size * node_count);
27 
28     if (p) {
29         p->node_size = node_size;
30         p->node_count = node_count;
31         p->first = (void *)(p + 1);
32         p->last = (RK_U8 *)p->first + node_size * (node_count - 1);
33     }
34 
35     *grp = p;
36     return MPP_OK;
37 }
38 
node_group_deinit(NodeGroup * p)39 MPP_RET node_group_deinit(NodeGroup *p)
40 {
41     MPP_FREE(p);
42     return MPP_OK;
43 }
44 
node_group_get(NodeGroup * p,RK_S32 idx)45 void *node_group_get(NodeGroup *p, RK_S32 idx)
46 {
47     RK_U8 *node = (RK_U8 *)p->first;
48 
49     return (void *)(node + idx * p->node_size);
50 }
51 
node_group_check(NodeGroup * p,void * node)52 MPP_RET node_group_check(NodeGroup *p, void *node)
53 {
54     void *first = p->first;
55     void *last = p->last;
56 
57     return (node >= first && node <= last) ? (MPP_OK) : (MPP_NOK);
58 }
59