1 /* Copyright 2020 Rockchip Electronics Co. LTD
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 * author: rimon.xu@rock-chips.com
16 * date: 2020-11-06
17 */
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <string.h>
21 #include <stdlib.h>
22
23 #include "rk_debug.h"
24 #include "rk_comm_mb.h"
25 #include "rk_comm_aio.h"
26 #include "rk_comm_vdec.h"
27 #include "rk_mpi_sys.h"
28 #include "rk_mpi_mb.h"
29
30 #include "test_comm_argparse.h"
31
32 enum _testAllocType {
33 TEST_ALLOC_TYPE_INTERNAL = 0,
34 TEST_ALLOC_TYPE_EXTERNAL_HAS_FREE,
35 TEST_ALLOC_TYPE_EXTERNAL
36 };
37
test_dump_vstream_info(VDEC_STREAM_S * vstream)38 RK_S32 test_dump_vstream_info(VDEC_STREAM_S *vstream) {
39 MB_BLK mb = vstream->pMbBlk;
40 RK_LOGI("test dump vtsream info:");
41 RK_LOGI("mb (%p), data(%p), fd(%d), len(%d), pts(%lld), eos(%d)",
42 mb, RK_MPI_MB_Handle2VirAddr(mb), RK_MPI_MB_Handle2Fd(mb),
43 vstream->u32Len, vstream->u64PTS, vstream->bEndOfStream);
44 return RK_SUCCESS;
45 }
46
test_video_stream_buffer_free(void * ctx)47 RK_S32 test_video_stream_buffer_free(void *ctx) {
48 if (ctx) {
49 free(ctx);
50 ctx = RK_NULL;
51 }
52 return RK_SUCCESS;
53 }
54
test_video_stream(RK_S32 type)55 RK_S32 test_video_stream(RK_S32 type) {
56 VDEC_STREAM_S vstream;
57 switch (type) {
58 case TEST_ALLOC_TYPE_INTERNAL: {
59 vstream.bEndOfStream = RK_FALSE;
60 vstream.u32Len = 0;
61 vstream.u64PTS = 50;
62 RK_MPI_SYS_MmzAlloc(&(vstream.pMbBlk), RK_NULL, RK_NULL, 250);
63
64 // do something.....
65 test_dump_vstream_info(&vstream);
66
67 RK_MPI_MB_ReleaseMB(vstream.pMbBlk);
68 } break;
69 case TEST_ALLOC_TYPE_EXTERNAL: {
70 RK_U8 *data = reinterpret_cast<RK_U8 *>(malloc(250));
71 vstream.bEndOfStream = RK_FALSE;
72 vstream.u32Len = 100;
73 vstream.u64PTS = 50;
74 MB_EXT_CONFIG_S extConfig = {0};
75 extConfig.pu8VirAddr = data;
76 extConfig.u64Size = 250;
77 RK_MPI_SYS_CreateMB(&(vstream.pMbBlk), &extConfig);
78
79 // do something.....
80 test_dump_vstream_info(&vstream);
81
82 RK_MPI_SYS_Free(vstream.pMbBlk);
83 if (data) {
84 free(data);
85 data = RK_NULL;
86 }
87 } break;
88 case TEST_ALLOC_TYPE_EXTERNAL_HAS_FREE: {
89 vstream.bEndOfStream = RK_FALSE;
90 vstream.u32Len = 100;
91 vstream.u64PTS = 50;
92 MB_EXT_CONFIG_S extConfig = {0};
93 extConfig.pu8VirAddr = reinterpret_cast<RK_U8 *>(malloc(250));
94 extConfig.u64Size = 250;
95 extConfig.pFreeCB = test_video_stream_buffer_free;
96 extConfig.pOpaque = extConfig.pu8VirAddr;
97 RK_MPI_SYS_CreateMB(&(vstream.pMbBlk), &extConfig);
98 // do something.....
99 test_dump_vstream_info(&vstream);
100 RK_MPI_SYS_Free(vstream.pMbBlk);
101 } break;
102 default:
103 break;
104 }
105
106 return RK_SUCCESS;
107 }
108
unit_test_mpi_vaio_struct()109 RK_S32 unit_test_mpi_vaio_struct() {
110 for (RK_S32 i = 0; i < 3; i++) {
111 test_video_stream(i);
112 }
113 return RK_SUCCESS;
114 }
115
116
117 static const char *const usages[] = {
118 "[options]: ",
119 NULL,
120 };
121
main(int argc,const char ** argv)122 RK_S32 main(int argc, const char **argv) {
123 struct argparse_option options[] = {
124 OPT_HELP(),
125 OPT_GROUP("basic options:"),
126 OPT_END(),
127 };
128
129 struct argparse argparse;
130 argparse_init(&argparse, options, usages, 0);
131 argparse_describe(&argparse, "\nselect a test case to run.",
132 "\nuse --help for details.");
133
134 argc = argparse_parse(&argparse, argc, argv);
135 argparse_usage(&argparse);
136
137 unit_test_mpi_vaio_struct();
138
139 return 0;
140 }
141
142