blob: fa800a3dec4e12b0f9646a8177634aae5259ed16 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**
2* @File: codec_res_request_api.c
3* @Brief: Implementation of Device Manager in Sanechips
4*
5* Copyright (C) 2017 Sanechips Technology Co., Ltd.
6* @Author: chen.tianming@zte.com.cn
7*
8* This program is free software; you can redistribute it and/or modify
9* it under the terms of the GNU General Public License version 2 as
10* published by the Free Software Foundation.
11* */
12
13/*******************************************************************************
14 * Í·Îļþ *
15******************************************************************************/
16#include<stdio.h>
17#include<stdlib.h>
18#include<sys/msg.h>
19#include<errno.h>
20#include<pthread.h>
21#include<string.h>
22#include"softap_api.h"
23
24/*******************************************************************************
25 * ºê¶¨Òå *
26 ******************************************************************************/
27
28/*******************************************************************************
29 * Êý¾ÝÀàÐͶ¨Òå *
30 ******************************************************************************/
31
32/*******************************************************************************
33 * ½Ó¿Ú¶¨Òå *
34 ******************************************************************************/
35
36/**
37 *º¯Êý˵Ã÷£ºÇëÇóʹÓÃaudio×ÊÔ´½Ó¿Ú
38 *²ÎÊý˵Ã÷: @ reqParam Èë²ÎÊý£¬°üÀ¨ÇëÇóµÄÒµÎñ£¬Ä£¿éºÅ£»
39 @spData ³ö²Î,·´Ó³µ±Ç°µÄÖ÷¿ØµÄ״̬¡£
40 *·µ»ØÖµ£º true ÉêÇë³É¹¦£»
41 false ÉêÇëʧ°Ü(¶ÔÓÚ»ìÒôµÈÏà¹Ø²Ù×÷£¬ÅäºÏ³ö²Î)
42 *±¸×¢£º
43 */
44BOOL audio_resource_request(T_audio_Res_Request *reqParam, T_audio_UseRsp *RspData)
45{
46 int tempQueueId = -1;
47 MSG_BUF msg = {0};
48 long msgSize = 0;
49 T_audio_UseReq useReqData = {0};
50 int moduleIdTmp = MODULE_ID_AP_AUDIODYNAMIC_BASE;//ÄÚ²¿¶¯Ì¬»ñȡԴģ¿éID£¬³õʼֵΪMODULE_ID_AP_AUDIODYNAMIC_BASE
51
52 if(!reqParam || !RspData) {
53 softap_assert("audio_resource_request function: input param is null \n");
54 return FALSE;
55 }
56 /* ´´½¨ÏûÏ¢¶ÓÁУ¬´ËÏûÏ¢¶ÓÁÐÁÙʱÐÔ£¬Ê¹ÓÃÍêºóɾ³ý */
57// if(-1 == (tempQueueId = msgget(reqParam->tempMouduleId, IPC_CREAT | IPC_EXCL)))
58// softap_assert("audio_resource_request function: create Message queue Error£º%s", strerror(errno));
59
60 /* ´´½¨ÏûÏ¢¶ÓÁУ¬´ËÏûÏ¢¶ÓÁÐÁÙʱÐÔ£¬Ê¹ÓÃÍêºóɾ³ý */
61 while((tempQueueId = msgget(moduleIdTmp,IPC_CREAT | IPC_EXCL| 0600)) < 0)
62 {
63 moduleIdTmp++;
64 if (moduleIdTmp > MODULE_ID_AP_AUDIODYNAMIC_END) {
65 //µ±module_id´óÓÚMODULE_ID_AP_AUDIODYNAMIC_ENDֵʱ£¬Ö÷¶¯¶ÏÑÔ
66 softap_assert("audio dynamatic msg queue too many now !!!!!!!!");
67 }
68 }
69
70 /* ×é×°ÏûÏ¢·¢Ë͸øaudio Ö÷¿Ø, ²¢µÈ´ýÖ÷¿Ø¸ø³öÃ÷È·´ð¸´ */
71 useReqData.type = reqParam->audioType;
72 useReqData.moduleId = reqParam->moduleId;
73 useReqData.tempModuleId = moduleIdTmp;
74 if(0 > platform_send_msg(moduleIdTmp, MODULE_ID_CODEC, USE_AUDIO_REQ, sizeof(T_audio_UseReq), (unsigned char *)&useReqData))
75 softap_assert("audio_resource_request function: Send USE_AUDIO_REQ msg Error: %s", strerror(errno));
76
77 /*µÈ´ýaudioÖ÷¿Ø»Ø¸´ */
78 while(1)
79 {
80 /*»ñÈ¡ÏûÏ¢½øÐд¦Àí*/
81 memset(&msg,0, sizeof(MSG_BUF));
82 msgSize = sizeof(MSG_BUF) - sizeof(long);
83 if(0 > msgrcv(tempQueueId, &msg, msgSize, 0, 0))
84 softap_assert("audio_resource_request function: Rec msg Error %s\n", strerror(errno));
85
86 slog(RTC_PRINT, SLOG_NORMAL, "audio_resource_request function: Rec msg now:tempModuleId(%x), srcId(%x), dstId(%x), msgCmd(%d)\n", moduleIdTmp,msg.src_id, msg.dst_id, msg.usMsgCmd);
87 /*ÏûÏ¢´¦Àí */
88 if(USE_AUDIO_RSP == msg.usMsgCmd)
89 {
90 T_audio_UseRsp *serverResData =(T_audio_UseRsp *) msg.aucDataBuf;
91 RspData->result = serverResData->result;
92 RspData->type = serverResData->type;
93 RspData->using_type = serverResData->using_type;
94 slog(RTC_PRINT, SLOG_NORMAL, "audio_resource_request function: get debug info: RspData->resul(%d), using_type(%d)\n ", RspData->result, serverResData->using_type);
95
96 /* ɾ³ýÏûÏ¢¶ÓÁÐ */
97 if(0 > msgctl(tempQueueId, IPC_RMID, 0))
98 {
99 slog(RTC_PRINT, SLOG_NORMAL,"error num(%d): error case:%s",errno,strerror(errno));
100 }
101 if(0 == serverResData->result) // success
102 {
103 return TRUE;
104 }
105 else
106 {
107 slog(RTC_PRINT, SLOG_NORMAL, "audio res request fail now: using_type(%d)\n",serverResData->using_type);
108 return FALSE;
109 }
110
111 }
112
113 }
114
115}