• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device 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 
16 #ifndef HDF_AUDIO_SERVER_COMMON_H
17 #define HDF_AUDIO_SERVER_COMMON_H
18 
19 #include "hdf_device_desc.h"
20 #include "hdf_log.h"
21 #include "audio_events.h"
22 #include "audio_internal.h"
23 
24 #define MAX_AUDIO_ADAPTER_NUM_SERVER    8   // Limit the number of sound cards supported to a maximum of 8
25 #define STR_MAX 512
26 
27 enum AudioServerType {
28     AUDIO_SERVER_PRIMARY,
29     AUDIO_SERVER_USB,
30     AUDIO_SERVER_A2DP,
31     AUDIO_SERVER_BOTTOM
32 };
33 
34 /* RenderManage Info */
35 struct AudioInfoInAdapter {
36     const char *adapterName;
37     struct AudioAdapter *adapter;
38     int adapterUserNum;
39     int renderStatus;
40     int renderPriority;
41     struct AudioRender *render;
42     bool renderBusy;
43     bool renderDestory;
44     uint32_t renderPid;
45     int captureStatus;
46     int capturePriority;
47     struct AudioCapture *capture;
48     bool captureBusy;
49     bool captureDestory;
50     uint32_t capturePid;
51 };
52 
53 int32_t AudioAdapterListGetAdapterCapture(const char *adapterName,
54     struct AudioAdapter **adapter, struct AudioCapture **capture);
55 int32_t AudioDestroyCaptureInfoInAdapter(const char *adapterName);
56 int32_t AudioCreatCaptureCheck(const char *adapterName, const int32_t priority);
57 int32_t AudioAddCaptureInfoInAdapter(const char *adapterName,
58     struct AudioCapture *capture,
59     const struct AudioAdapter *adapter,
60     const int32_t priority,
61     uint32_t capturePid);
62 int32_t AudioAdapterListGetAdapter(const char *adapterName, struct AudioAdapter **adapter);
63 int32_t AudioCreatRenderCheck(const char *adapterName, const int32_t priority);
64 int32_t AudioAddRenderInfoInAdapter(const char *adapterName,
65     struct AudioRender *render,
66     const struct AudioAdapter *adapter,
67     const int32_t priority,
68     uint32_t renderPid);
69 int32_t AudioDestroyRenderInfoInAdapter(const char *adapterName);
70 int32_t AudioAdapterListGetAdapterRender(const char *adapterName,
71     struct AudioAdapter **adapter, struct AudioRender **render);
72 int32_t AudioAdapterCheckListExist(const char *adapterName);
73 int32_t AudioAdapterListDestory(const char *adapterName, struct AudioAdapter **adapter);
74 int32_t AudioAdapterListAdd(const char *adapterName, struct AudioAdapter *adapter);
75 int32_t HdiServiceRenderCaptureReadData(struct HdfSBuf *data,
76     const char **adapterName, uint32_t *pid);
77 int32_t AudioAdapterListGetRender(const char *adapterName,
78     struct AudioRender **render, uint32_t pid);
79 void AudioSetRenderStatus(const char *adapterName, bool renderStatus);
80 int32_t AudioGetRenderStatus(const char *adapterName);
81 int32_t AudioAdapterListCheckAndGetRender(struct AudioRender **render, struct HdfSBuf *data);
82 int32_t AudioAdapterListGetCapture(const char *adapterName,
83     struct AudioCapture **capture, uint32_t pid);
84 int32_t AudioAdapterFrameGetCapture(const char *adapterName,
85     struct AudioCapture **capture, uint32_t pid, uint32_t *index);
86 void AudioSetCaptureBusy(uint32_t index, bool captureStatus);
87 int32_t AudioAdapterListCheckAndGetCapture(struct AudioCapture **capture, struct HdfSBuf *data);
88 int32_t ReadAudioSapmleAttrbutes(struct HdfSBuf *data, struct AudioSampleAttributes *attrs);
89 int32_t WriteAudioSampleAttributes(struct HdfSBuf *reply, const struct AudioSampleAttributes *attrs);
90 void AudioSetCaptureStatus(const char *adapterName, bool captureStatus);
91 int32_t AudioGetCaptureStatus(const char *adapterName);
92 int32_t ServerManageGetAdapterNum(void);
93 struct AudioInfoInAdapter *ServerManageGetAdapters(void);
94 void AdaptersServerManageRelease(const struct AudioInfoInAdapter *adaptersManage, int32_t num);
95 void AdaptersServerManageInfomationRecycle(void);
96 int32_t AdaptersServerManageInit(const struct AudioAdapterDescriptor *descs, int32_t num);
97 int32_t HdiServicePositionWrite(struct HdfSBuf *reply,
98     uint64_t frames, struct AudioTimeStamp time);
99 int32_t HdiServiceReqMmapBuffer(struct AudioMmapBufferDescripter *desc, struct HdfSBuf *data);
100 
101 int32_t HdiServiceGetFuncs();
102 int32_t HdiServiceGetAllAdapter(const struct HdfDeviceIoClient *client,
103     struct HdfSBuf *data, struct HdfSBuf *reply);
104 int32_t HdiServiceLoadAdapter(const struct HdfDeviceIoClient *client,
105     struct HdfSBuf *data, struct HdfSBuf *reply);
106 int32_t HdiServiceInitAllPorts(const struct HdfDeviceIoClient *client,
107     struct HdfSBuf *data, struct HdfSBuf *reply);
108 int32_t HdiServiceUnloadAdapter(const struct HdfDeviceIoClient *client,
109     struct HdfSBuf *data, struct HdfSBuf *reply);
110 int32_t HdiServiceGetPortCapability(const struct HdfDeviceIoClient *client,
111     struct HdfSBuf *data, struct HdfSBuf *reply);
112 int32_t HdiServiceSetPassthroughMode(const struct HdfDeviceIoClient *client,
113     struct HdfSBuf *data, struct HdfSBuf *reply);
114 int32_t HdiServiceGetPassthroughMode(const struct HdfDeviceIoClient *client,
115     struct HdfSBuf *data, struct HdfSBuf *reply);
116 int32_t HdiServiceGetDevStatusByPNP(const struct HdfDeviceIoClient *client,
117     struct HdfSBuf *data, struct HdfSBuf *reply);
118 int32_t AudioServiceStateChange(struct HdfDeviceObject *device,
119     struct AudioEvent *audioSrvEvent);
120 
121 enum AudioServerType AudioHdiGetLoadServerFlag(void);
122 void AudioHdiSetLoadServerFlag(enum AudioServerType serverType);
123 void AudioHdiClearLoadServerFlag(void);
124 
125 int32_t HdiServiceDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data,
126     struct HdfSBuf *reply);
127 #endif
128 
129