1 /*
2 *
3 * Copyright 2015 Rockchip Electronics Co. LTD
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 #define MODULE_TAG "hal_vp8d_api"
18
19 #include <string.h>
20
21 #include "rk_type.h"
22 #include "mpp_hal.h"
23 #include "mpp_platform.h"
24 #include "mpp_env.h"
25 #include "hal_vp8d_vdpu1.h"
26 #include "hal_vp8d_vdpu2.h"
27
28 RK_U32 hal_vp8d_debug = 0;
29
hal_vp8d_reg_gen(void * hal,HalTaskInfo * task)30 static MPP_RET hal_vp8d_reg_gen (void *hal, HalTaskInfo *task)
31 {
32 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
33
34 if (!self->hal_api.reg_gen)
35 return MPP_OK;
36
37 return self->hal_api.reg_gen(hal, task);
38 }
39
hal_vp8d_start(void * hal,HalTaskInfo * task)40 static MPP_RET hal_vp8d_start (void *hal, HalTaskInfo *task)
41 {
42 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
43
44 if (!self->hal_api.start)
45 return MPP_OK;
46
47 return self->hal_api.start(hal, task);
48 }
49
hal_vp8d_wait(void * hal,HalTaskInfo * task)50 static MPP_RET hal_vp8d_wait (void *hal, HalTaskInfo *task)
51 {
52 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
53
54 if (!self->hal_api.wait)
55 return MPP_OK;
56
57 return self->hal_api.wait(hal, task);
58 }
59
hal_vp8d_reset(void * hal)60 static MPP_RET hal_vp8d_reset (void *hal)
61 {
62 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
63
64 if (!self->hal_api.reset)
65 return MPP_OK;
66
67 return self->hal_api.reset(hal);;
68 }
69
hal_vp8d_flush(void * hal)70 static MPP_RET hal_vp8d_flush (void *hal)
71 {
72 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
73
74 if (!self->hal_api.flush)
75 return MPP_OK;
76
77 return self->hal_api.flush(hal);
78 }
79
hal_vp8d_control(void * hal,MpiCmd cmd_type,void * param)80 static MPP_RET hal_vp8d_control (void *hal, MpiCmd cmd_type, void *param)
81 {
82 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
83
84 if (!self->hal_api.control)
85 return MPP_OK;
86
87 return self->hal_api.control(hal, cmd_type, param);
88 }
89
hal_vp8d_deinit(void * hal)90 static MPP_RET hal_vp8d_deinit (void *hal)
91 {
92 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
93
94 if (!self->hal_api.deinit)
95 return MPP_OK;
96
97 return self->hal_api.deinit(hal);
98 }
99
hal_vp8d_init(void * hal,MppHalCfg * cfg)100 static MPP_RET hal_vp8d_init(void *hal, MppHalCfg *cfg)
101 {
102 VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
103 MppHalApi *p_api = NULL;
104 VpuHwMode hw_mode = MODE_NULL;
105 RK_U32 hw_flag = 0;
106
107 if (NULL == self)
108 return MPP_ERR_VALUE;
109
110 mpp_env_get_u32("hal_vp8d_debug", &hal_vp8d_debug, 0);
111
112 memset(self, 0, sizeof(VP8DHalContext_t));
113 p_api = &self->hal_api;
114
115 hw_flag = mpp_get_vcodec_type();
116 if (hw_flag & HAVE_VDPU1)
117 hw_mode = VDPU1_MODE;
118 if (hw_flag & HAVE_VDPU2)
119 hw_mode = VDPU2_MODE;
120
121 switch (hw_mode) {
122 case VDPU2_MODE:
123 p_api->init = hal_vp8d_vdpu2_init;
124 p_api->deinit = hal_vp8d_vdpu2_deinit;
125 p_api->reg_gen = hal_vp8d_vdpu2_gen_regs;
126 p_api->start = hal_vp8d_vdpu2_start;
127 p_api->wait = hal_vp8d_vdpu2_wait;
128 p_api->reset = NULL;
129 p_api->flush = NULL;
130 p_api->control = NULL;
131 break;
132 case VDPU1_MODE:
133 p_api->init = hal_vp8d_vdpu1_init;
134 p_api->deinit = hal_vp8d_vdpu1_deinit;
135 p_api->reg_gen = hal_vp8d_vdpu1_gen_regs;
136 p_api->start = hal_vp8d_vdpu1_start;
137 p_api->wait = hal_vp8d_vdpu1_wait;
138 p_api->reset = NULL;
139 p_api->flush = NULL;
140 p_api->control = NULL;
141 break;
142 default:
143 return MPP_ERR_INIT;
144 break;
145 }
146
147 return p_api->init (hal, cfg);
148 }
149
150
151 const MppHalApi hal_api_vp8d = {
152 .name = "vp8d_rkdec",
153 .type = MPP_CTX_DEC,
154 .coding = MPP_VIDEO_CodingVP8,
155 .ctx_size = sizeof(VP8DHalContext_t),
156 .flag = 0,
157 .init = hal_vp8d_init,
158 .deinit = hal_vp8d_deinit,
159 .reg_gen = hal_vp8d_reg_gen,
160 .start = hal_vp8d_start,
161 .wait = hal_vp8d_wait,
162 .reset = hal_vp8d_reset,
163 .flush = hal_vp8d_flush,
164 .control = hal_vp8d_control,
165 };
166