1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong DID Co., Ltd.
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 #include "codec_dfx_service.h"
16 #include <hdf_base.h>
17 #include "codec_adapter_interface.h"
18 #include "codec_component_manager_service.h"
19 #include "codec_log_wrapper.h"
20 
21 #define CODEC_MAX_DFX_DUMP_LEN  256
22 
DevCodecHostDump(struct HdfSBuf * data,struct HdfSBuf * reply)23 int32_t DevCodecHostDump(struct HdfSBuf *data, struct HdfSBuf *reply)
24 {
25     uint32_t argv = 0;
26     (void)HdfSbufReadUint32(data, &argv);
27     if (argv != 1) {
28         HdfSbufWriteString(reply, "please enter -h for help!! \n");
29         return HDF_SUCCESS;
30     }
31     const char *para = HdfSbufReadString(data);
32     if (para == NULL) {
33         CODEC_LOGE("para is NULL");
34         return HDF_FAILURE;
35     }
36     if (strcmp(para, "-h") == 0) {
37         HdfSbufWriteString(reply, "-h: codec dump help ! \n");
38         HdfSbufWriteString(reply, "-l: dump codec components info list ! \n");
39         return HDF_SUCCESS;
40     }
41 
42     if (strcmp(para, "-l") == 0) {
43         struct CodecComponentManagerSerivce *managerService = CodecComponentManagerSerivceGet();
44         if (managerService == NULL) {
45             CODEC_LOGE("managerService is NULL");
46             return HDF_FAILURE;
47         }
48         struct ComponentTypeNode *pos = NULL;
49         struct ComponentTypeNode *next = NULL;
50         DLIST_FOR_EACH_ENTRY_SAFE(pos, next, &managerService->head, struct ComponentTypeNode, node)
51         {
52             if (pos == NULL) {
53                 CODEC_LOGE("pos is NULL");
54                 return HDF_FAILURE;
55             }
56             struct CodecComponentNode *codecNode = CodecComponentTypeServiceGetCodecNode(pos->service);
57             if (codecNode != NULL) {
58                 char dump[CODEC_MAX_DFX_DUMP_LEN + 1] = { 0 };
59                 int32_t ret = OmxAdapterWriteDumperData(dump, CODEC_MAX_DFX_DUMP_LEN, pos->componentId, codecNode);
60                 if (ret != HDF_SUCCESS) {
61                     CODEC_LOGE("OmxAdapterWriteDumperData err");
62                     return HDF_FAILURE;
63                 }
64                 HdfSbufWriteString(reply, dump);
65                 HdfSbufWriteString(reply, "--------------------------------------------------------------------- \n");
66             }
67         }
68         CODEC_LOGI("codec hidumper success!");
69         return HDF_SUCCESS;
70     }
71     HdfSbufWriteString(reply, "unknow param, please enter -h for help! \n");
72     return HDF_SUCCESS;
73 }
74