1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2022 Rockchip Electronics Co. LTD
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Licensed under the Apache License, Version 2.0 (the "License");
5*4882a593Smuzhiyun * you may not use this file except in compliance with the License.
6*4882a593Smuzhiyun * You may obtain a copy of the License at
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * http://www.apache.org/licenses/LICENSE-2.0
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Unless required by applicable law or agreed to in writing, software
11*4882a593Smuzhiyun * distributed under the License is distributed on an "AS IS" BASIS,
12*4882a593Smuzhiyun * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4882a593Smuzhiyun * See the License for the specific language governing permissions and
14*4882a593Smuzhiyun * limitations under the License.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun */
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <stdio.h>
19*4882a593Smuzhiyun #include <cstring>
20*4882a593Smuzhiyun #include <cstdlib>
21*4882a593Smuzhiyun #include "rk_debug.h"
22*4882a593Smuzhiyun #include "rk_mpi_amix.h"
23*4882a593Smuzhiyun #include "test_comm_argparse.h"
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun typedef struct _rkTEST_AMIX_CTX_S {
26*4882a593Smuzhiyun RK_S32 s32DevId;
27*4882a593Smuzhiyun const char *psControlName;
28*4882a593Smuzhiyun char *psControlValue;
29*4882a593Smuzhiyun RK_BOOL bListControls;
30*4882a593Smuzhiyun RK_BOOL bListContents;
31*4882a593Smuzhiyun } TEST_AMIX_CTX_S;
32*4882a593Smuzhiyun
unit_test_mpi_amix(TEST_AMIX_CTX_S * ctx)33*4882a593Smuzhiyun static RK_S32 unit_test_mpi_amix(TEST_AMIX_CTX_S *ctx) {
34*4882a593Smuzhiyun RK_S32 i = 0, ret = 0;
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun if (ctx == RK_NULL)
37*4882a593Smuzhiyun return RK_FAILURE;
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun if (ctx->psControlName && ctx->psControlValue) {
40*4882a593Smuzhiyun ret = RK_MPI_AMIX_SetControl(ctx->s32DevId, ctx->psControlName, ctx->psControlValue);
41*4882a593Smuzhiyun if (ret) {
42*4882a593Smuzhiyun RK_LOGE("RK_MPI_AMIX_SetControl failed, ret = %X", ret);
43*4882a593Smuzhiyun return RK_FAILURE;
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun } else if (ctx->psControlName && !ctx->psControlValue) {
46*4882a593Smuzhiyun char value[64] = {0};
47*4882a593Smuzhiyun // Usage 1: Print the current selected value of control
48*4882a593Smuzhiyun ret = RK_MPI_AMIX_GetControl(ctx->s32DevId, ctx->psControlName, value);
49*4882a593Smuzhiyun if (ret) {
50*4882a593Smuzhiyun RK_LOGE("RK_MPI_AMIX_GetControl failed, ret = %X", ret);
51*4882a593Smuzhiyun return RK_FAILURE;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun RK_PRINT("Get current control value: %s\n", value);
55*4882a593Smuzhiyun // Usage 2: List the values of control directly with the NULL value param
56*4882a593Smuzhiyun RK_PRINT("List the control values:\n");
57*4882a593Smuzhiyun ret = RK_MPI_AMIX_GetControl(ctx->s32DevId, ctx->psControlName, NULL);
58*4882a593Smuzhiyun if (ret) {
59*4882a593Smuzhiyun RK_LOGE("RK_MPI_AMIX_GetControl failed, ret = %X", ret);
60*4882a593Smuzhiyun return RK_FAILURE;
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun if (ctx->bListControls)
65*4882a593Smuzhiyun RK_MPI_AMIX_ListControls(ctx->s32DevId);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun if (ctx->bListContents)
68*4882a593Smuzhiyun RK_MPI_AMIX_ListContents(ctx->s32DevId);
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun return RK_SUCCESS;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun static const char *const usages[] = {
74*4882a593Smuzhiyun "./rk_mpi_amix_test [-C card] [--control ctl_name] [--value ctl_val] [--list_controls] [--list_contents]...",
75*4882a593Smuzhiyun NULL,
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun
mpi_amix_test_show_options(const TEST_AMIX_CTX_S * ctx)78*4882a593Smuzhiyun static void mpi_amix_test_show_options(const TEST_AMIX_CTX_S *ctx) {
79*4882a593Smuzhiyun RK_PRINT("cmd parse result:\n");
80*4882a593Smuzhiyun RK_PRINT("sound control id : %d\n", ctx->s32DevId);
81*4882a593Smuzhiyun RK_PRINT("control name : %s\n", ctx->psControlName);
82*4882a593Smuzhiyun RK_PRINT("control value : %s\n", ctx->psControlValue);
83*4882a593Smuzhiyun RK_PRINT("list controls : %d\n", ctx->bListControls);
84*4882a593Smuzhiyun RK_PRINT("list contents : %d\n", ctx->bListContents);
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
main(int argc,const char ** argv)87*4882a593Smuzhiyun int main(int argc, const char **argv) {
88*4882a593Smuzhiyun TEST_AMIX_CTX_S *ctx = reinterpret_cast<TEST_AMIX_CTX_S *>(malloc(sizeof(TEST_AMIX_CTX_S)));
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun memset(ctx, 0, sizeof(TEST_AMIX_CTX_S));
91*4882a593Smuzhiyun ctx->s32DevId = 0;
92*4882a593Smuzhiyun ctx->psControlName = RK_NULL;
93*4882a593Smuzhiyun ctx->psControlValue = RK_NULL;
94*4882a593Smuzhiyun ctx->bListControls = RK_FALSE;
95*4882a593Smuzhiyun ctx->bListContents = RK_FALSE;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun struct argparse_option options[] = {
98*4882a593Smuzhiyun OPT_HELP(),
99*4882a593Smuzhiyun OPT_GROUP("basic options:"),
100*4882a593Smuzhiyun OPT_INTEGER('C', "card", &(ctx->s32DevId),
101*4882a593Smuzhiyun "specifies the card number of the mixer. default(0)", NULL, 0, 0),
102*4882a593Smuzhiyun OPT_STRING('\0', "control", &(ctx->psControlName),
103*4882a593Smuzhiyun "sets (or gets without control value) the name of a control. default(required)", NULL, 0, 0),
104*4882a593Smuzhiyun OPT_STRING('\0', "value", &(ctx->psControlValue),
105*4882a593Smuzhiyun "sets the value of a control. default(required)", NULL, 0, 0),
106*4882a593Smuzhiyun OPT_BOOLEAN('\0', "list_controls", &(ctx->bListControls),
107*4882a593Smuzhiyun "lists controls of the mixer. default(false).", NULL, 0, 0),
108*4882a593Smuzhiyun OPT_BOOLEAN('\0', "list_contents", &(ctx->bListContents),
109*4882a593Smuzhiyun "lists controls of the mixer and their contents. default(false).", NULL, 0, 0),
110*4882a593Smuzhiyun OPT_END(),
111*4882a593Smuzhiyun };
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun struct argparse argparse;
114*4882a593Smuzhiyun argparse_init(&argparse, options, usages, 0);
115*4882a593Smuzhiyun argparse_describe(&argparse, "\nselect a test case to run.",
116*4882a593Smuzhiyun "\nuse --help for details.");
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun argc = argparse_parse(&argparse, argc, argv);
119*4882a593Smuzhiyun mpi_amix_test_show_options(ctx);
120*4882a593Smuzhiyun if (ctx->psControlName == RK_NULL
121*4882a593Smuzhiyun && ctx->psControlValue == RK_NULL
122*4882a593Smuzhiyun && ctx->bListControls == RK_FALSE
123*4882a593Smuzhiyun && ctx->bListContents == RK_FALSE) {
124*4882a593Smuzhiyun argparse_usage(&argparse);
125*4882a593Smuzhiyun return RK_FAILURE;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun unit_test_mpi_amix(ctx);
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun if (ctx) {
131*4882a593Smuzhiyun free(ctx);
132*4882a593Smuzhiyun ctx = RK_NULL;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun return RK_SUCCESS;
135*4882a593Smuzhiyun }
136