hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Copyright 2021 Rockchip Electronics Co. LTD
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#define MODULE_TAG "hal_av1d_api"
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <unistd.h>
 
#include "mpp_mem.h"
#include "mpp_env.h"
#include "mpp_platform.h"
#include "mpp_common.h"
 
#include "dxva_syntax.h"
 
#include "hal_av1d_vdpu_reg.h"
#include "hal_av1d_vdpu.h"
#include "hal_av1d_common.h"
 
RK_U32 hal_av1d_debug = 0;
 
MPP_RET hal_av1d_init(void *hal, MppHalCfg *cfg)
{
    MPP_RET ret         = MPP_OK;
    Av1dHalCtx *p_hal   = (Av1dHalCtx *)hal;
    RK_U32 vcodec_type  = mpp_get_vcodec_type();
    MppClientType type  = VPU_CLIENT_AV1DEC;
 
    INP_CHECK(ret, NULL == p_hal);
    memset(p_hal, 0, sizeof(Av1dHalCtx));
    mpp_env_get_u32("hal_av1d_debug", &hal_av1d_debug, 0);
 
    // check codec_type first
    if (!(vcodec_type & (HAVE_RKVDEC | HAVE_VDPU1 | HAVE_VDPU2))) {
        mpp_err_f("can not found av1 decoder hardware on platform %x\n", vcodec_type);
        return ret;
    }
 
    p_hal->api = &hal_av1d_vdpu;
 
    //!< callback function to parser module
    p_hal->dec_cb = cfg->dec_cb;
 
    ret = mpp_dev_init(&cfg->dev, type);
    if (ret) {
        mpp_err("mpp_dev_init failed ret: %d\n", ret);
        goto __FAILED;
    }
 
    //< get buffer group
    if (p_hal->buf_group == NULL) {
        FUN_CHECK(ret = mpp_buffer_group_get_internal
                        (&p_hal->buf_group, MPP_BUFFER_TYPE_ION));
    }
 
    p_hal->dev          = cfg->dev;
    p_hal->cfg          = cfg->cfg;
    p_hal->slots        = cfg->frame_slots;
    p_hal->packet_slots = cfg->packet_slots;
    p_hal->fast_mode    = cfg->cfg->base.fast_parse;
 
    if (p_hal->buf_group == NULL) {
        FUN_CHECK(ret = mpp_buffer_group_get_internal
                        (&p_hal->buf_group, MPP_BUFFER_TYPE_ION));
    }
    //!< run init funtion
    FUN_CHECK(ret = p_hal->api->init(hal, cfg));
 
__RETURN:
    return MPP_OK;
__FAILED:
    return ret;
}
 
MPP_RET hal_av1d_deinit(void *hal)
{
    MPP_RET ret         = MPP_ERR_UNKNOW;
    Av1dHalCtx *p_hal   = (Av1dHalCtx *)hal;
 
    FUN_CHECK(ret = p_hal->api->deinit(hal));
 
    if (p_hal->dev) {
        mpp_dev_deinit(p_hal->dev);
        p_hal->dev = NULL;
    }
 
    if (p_hal->buf_group) {
        FUN_CHECK(ret = mpp_buffer_group_put(p_hal->buf_group));
    }
 
    return MPP_OK;
__FAILED:
    return ret;
}
 
MPP_RET hal_av1d_gen_regs(void *hal, HalTaskInfo *task)
{
    Av1dHalCtx *p_hal = (Av1dHalCtx *)hal;
    MPP_RET ret = MPP_NOK;
 
    if (p_hal && p_hal->api && p_hal->api->reg_gen)
        ret = p_hal->api->reg_gen(hal, task);
    return ret;
}
 
MPP_RET hal_av1d_start(void *hal, HalTaskInfo *task)
{
    Av1dHalCtx *p_hal = (Av1dHalCtx *)hal;
    MPP_RET ret = MPP_NOK;
 
    if (p_hal && p_hal->api && p_hal->api->start)
        ret = p_hal->api->start(hal, task);
    return ret;
}
 
MPP_RET hal_av1d_wait(void *hal, HalTaskInfo *task)
{
    Av1dHalCtx *p_hal = (Av1dHalCtx *)hal;
    MPP_RET ret = MPP_NOK;
 
    if (p_hal && p_hal->api && p_hal->api->wait)
        ret = p_hal->api->wait(hal, task);
    return ret;
}
 
MPP_RET hal_av1d_reset(void *hal)
{
    Av1dHalCtx *p_hal = (Av1dHalCtx *)hal;
    MPP_RET ret = MPP_NOK;
 
    if (p_hal && p_hal->api && p_hal->api->reset)
        ret = p_hal->api->reset(hal);
    return ret;
}
 
MPP_RET hal_av1d_flush(void *hal)
{
    Av1dHalCtx *p_hal = (Av1dHalCtx *)hal;
    MPP_RET ret = MPP_NOK;
 
    if (p_hal && p_hal->api && p_hal->api->flush)
        ret = p_hal->api->flush(hal);
    return ret;
}
 
MPP_RET hal_av1d_control(void *hal, MpiCmd cmd_type, void *param)
{
    Av1dHalCtx *p_hal = (Av1dHalCtx *)hal;
    MPP_RET ret = MPP_NOK;
 
    if (p_hal && p_hal->api && p_hal->api->control)
        ret = p_hal->api->control(hal, cmd_type, param);
    return ret;
}
 
const MppHalApi hal_api_av1d = {
    .name       = "av1d_vdpu",
    .type       = MPP_CTX_DEC,
    .coding     = MPP_VIDEO_CodingAV1,
    .ctx_size   = sizeof(Av1dHalCtx),
    .flag       = 0,
    .init       = hal_av1d_init,
    .deinit     = hal_av1d_deinit,
    .reg_gen    = hal_av1d_gen_regs,
    .start      = hal_av1d_start,
    .wait       = hal_av1d_wait,
    .reset      = hal_av1d_reset,
    .flush      = hal_av1d_flush,
    .control    = hal_av1d_control,
};