jesse.huang | 3af2c4f | 2023-06-15 16:34:14 -0700 | [diff] [blame] | 1 | // Copyright 2023 Amlogic, Inc. |
| 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 | #ifndef COMMON_H |
| 16 | #define COMMON_H |
| 17 | |
| 18 | #include <iostream> |
| 19 | #include <cstring> |
| 20 | #include <cstdlib> |
| 21 | #include <string.h> |
| 22 | #include <thread> |
| 23 | #include <chrono> |
| 24 | #include <mutex> |
| 25 | #include <condition_variable> |
jesse.huang | a2e057f | 2023-08-14 10:00:22 -0700 | [diff] [blame] | 26 | #include <unordered_set> |
| 27 | #include <unordered_map> |
jesse.huang | 3af2c4f | 2023-06-15 16:34:14 -0700 | [diff] [blame] | 28 | |
| 29 | #include <sys/mman.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <unistd.h> |
| 33 | #include <dirent.h> |
| 34 | |
| 35 | #include <binder/Binder.h> |
| 36 | |
| 37 | #include "audio_if.h" |
| 38 | |
| 39 | #define NAME_OF_SERVICE "audio_service_binder" |
| 40 | #define MAX_NUM_TRIES_TO_GET_SERVICE 3 |
| 41 | #define NUM_AUDIO_PORT_CONFIG_TYPES 3 |
| 42 | |
| 43 | struct { |
| 44 | const int AUDIO_PORT_TYPE_DEVICE_COUNT_ID = 0, |
| 45 | AUDIO_PORT_TYPE_MIX_COUNT_ID = 1, |
| 46 | AUDIO_PORT_TYPE_SESSION_COUNT_ID = 2; |
| 47 | } audioPortTypeIds; |
| 48 | |
| 49 | #define NUM_AUDIO_GAIN_VALUES 8 |
| 50 | |
| 51 | #define AUDIO_PORT_TYPE_DEVICE_ADDRESS "null" |
| 52 | // #define AUDIO_PORT_TYPE_DEVICE_ADDRESS_LENGTH std::min((int) strlen(AUDIO_PORT_TYPE_DEVICE_ADDRESS), AUDIO_DEVICE_MAX_ADDRESS_LEN - 1) |
| 53 | |
| 54 | #define KSHAREDBUFFERSIZE 262144 |
| 55 | |
| 56 | #define INPUT_STREAM_LABEL "input stream pid-seq" |
| 57 | #define OUTPUT_STREAM_LABEL "output stream pid-seq" |
xingri.gao | 826841b | 2024-07-03 19:17:40 +0800 | [diff] [blame^] | 58 | #define PATCH_LABEL "patch pid-seq" |
| 59 | |
jesse.huang | 3af2c4f | 2023-06-15 16:34:14 -0700 | [diff] [blame] | 60 | #define DEBUG_INFO std::string(__func__) + " " + std::to_string(__LINE__) |
| 61 | |
| 62 | #define BINDERFSPATH "/dev/binderfs" |
| 63 | #define POSIXSHMPATH "/dev/shm/uenvShm" |
| 64 | #define AUDIO_PERMISSION_STR "777" |
| 65 | #define STREAM_OBJECT_UMASK S_IWGRP // write access for other not removed |
| 66 | #define CURRENT_DIRECTORY "." |
| 67 | #define PARENT_DIRECTORY ".." |
| 68 | |
| 69 | typedef enum { |
jesse.huang | a2e057f | 2023-08-14 10:00:22 -0700 | [diff] [blame] | 70 | AUDIO_STREAM_OUT, |
| 71 | AUDIO_STREAM_IN, |
| 72 | } audio_stream_direction; |
jesse.huang | 3af2c4f | 2023-06-15 16:34:14 -0700 | [diff] [blame] | 73 | |
| 74 | struct { |
| 75 | const std::string AUDIO_CLIENT_BINDER_TEST = "[AudioClientBinderTest]", |
| 76 | AUDIO_CLIENT_BINDER = "[AudioClient]", |
| 77 | AUDIO_SERVICE_BINDER = "[AudioServer]"; |
| 78 | } processNameLogs; |
| 79 | |
| 80 | #define BINDER_EXCEPTION -32 |
| 81 | #define FIRST_CALL_TRANSACTION_VAL ::android::IBinder::FIRST_CALL_TRANSACTION |
| 82 | |
| 83 | typedef enum { |
| 84 | CMD_AS_GC = FIRST_CALL_TRANSACTION_VAL, |
| 85 | CMD_AS_DCC = CMD_AS_GC + 1, |
| 86 | CMD_AS_DIC = CMD_AS_DCC + 1, |
| 87 | CMD_AS_DSVV = CMD_AS_DIC + 1, |
| 88 | CMD_AS_DSMV = CMD_AS_DSVV + 1, |
| 89 | CMD_AS_DGMV = CMD_AS_DSMV + 1, |
| 90 | CMD_AS_DSM = CMD_AS_DGMV + 1, |
| 91 | CMD_AS_DSMicM = CMD_AS_DSM + 1, |
| 92 | CMD_AS_DGMicM = CMD_AS_DSMicM + 1, |
| 93 | CMD_AS_DSP = CMD_AS_DGMicM + 1, |
| 94 | CMD_AS_DGP = CMD_AS_DSP + 1, |
| 95 | CMD_AS_DGIBS = CMD_AS_DGP + 1, |
| 96 | CMD_AS_DOOS = CMD_AS_DGIBS + 1, |
| 97 | CMD_AS_DCOS = CMD_AS_DOOS + 1, |
| 98 | CMD_AS_DOIS = CMD_AS_DCOS + 1, |
| 99 | CMD_AS_DCIS = CMD_AS_DOIS + 1, |
| 100 | CMD_AS_DD = CMD_AS_DCIS + 1, |
| 101 | CMD_AS_DSMasterM = CMD_AS_DD + 1, |
| 102 | CMD_AS_DGMasterM = CMD_AS_DSMasterM + 1, |
| 103 | CMD_AS_DCAP = CMD_AS_DGMasterM + 1, |
| 104 | CMD_AS_DRAP = CMD_AS_DCAP + 1, |
| 105 | CMD_AS_DSAPC = CMD_AS_DRAP + 1, |
| 106 | CMD_AS_SGSR = CMD_AS_DSAPC + 1, |
| 107 | CMD_AS_SGBS = CMD_AS_SGSR + 1, |
| 108 | CMD_AS_SGC = CMD_AS_SGBS + 1, |
| 109 | CMD_AS_SGF = CMD_AS_SGC + 1, |
| 110 | CMD_AS_SS = CMD_AS_SGF + 1, |
| 111 | CMD_AS_SGD = CMD_AS_SS + 1, |
| 112 | CMD_AS_SSP = CMD_AS_SGD + 1, |
| 113 | CMD_AS_SGP = CMD_AS_SSP + 1, |
| 114 | CMD_AS_SO_GL = CMD_AS_SGP + 1, |
| 115 | CMD_AS_SO_SV = CMD_AS_SO_GL + 1, |
| 116 | CMD_AS_SO_W = CMD_AS_SO_SV + 1, |
| 117 | CMD_AS_SO_GRP = CMD_AS_SO_W + 1, |
| 118 | CMD_AS_SO_GNWT = CMD_AS_SO_GRP + 1, |
| 119 | CMD_AS_SO_P = CMD_AS_SO_GNWT + 1, |
| 120 | CMD_AS_SO_R = CMD_AS_SO_P + 1, |
| 121 | CMD_AS_SO_F = CMD_AS_SO_R + 1, |
| 122 | CMD_AS_SO_GPP = CMD_AS_SO_F + 1, |
| 123 | CMD_AS_SI_SG = CMD_AS_SO_GPP + 1, |
| 124 | CMD_AS_SI_R = CMD_AS_SI_SG + 1, |
| 125 | CMD_AS_SI_GIFL = CMD_AS_SI_R + 1, |
| 126 | CMD_AS_SI_GCP = CMD_AS_SI_GIFL + 1, |
| 127 | CMD_AS_SP = CMD_AS_SI_GCP + 1, |
| 128 | CMD_AS_ESP = CMD_AS_SP + 1, |
| 129 | CMD_AS_EGP = CMD_AS_ESP + 1, |
| 130 | } transact_code; |
| 131 | |
| 132 | // mode_t = unsigned int |
| 133 | |
| 134 | extern int posixOpenFile(const std::string& processNameLog, const char* identifierLabel, const char* identifier, int oflag, unsigned int mode); |
| 135 | |
| 136 | extern int posixMapData(const std::string& processNameLog, const char* identifierLabel, const char* identifier, void*& data, size_t length, int prot, int flags, int fd); |
| 137 | |
| 138 | extern int posixOpenFileAndSetDataSize(const std::string& processNameLog, const char* identifierLabel, const char* identifier, int oflag, unsigned int mode, off_t length); |
| 139 | |
| 140 | extern int posixOpenFileSetDataSizeAndMapData(const std::string& processNameLog, const char* identifierLabel, const char* identifier, int oflag, unsigned int mode, off_t length, |
| 141 | void*& data, int prot, int flags); |
| 142 | |
| 143 | extern int posixOpenFileAndMapData(const std::string& processNameLog, const char* identifierLabel, const char* identifier, int oflag, unsigned int mode, void*& data, size_t length, int prot, int flags); |
| 144 | |
| 145 | extern int posixCloseFile(const std::string& processNameLog, const char* identifierLabel, const char* identifier, int fd); |
| 146 | |
jesse.huang | ca30b0b | 2023-08-15 15:03:55 -0700 | [diff] [blame] | 147 | extern int posixUnmapDataCloseFileAndUnlinkName(const std::string& processNameLog, const char* identifierLabel, const char* identifier, void*& data, size_t length, int fd); |
jesse.huang | 3af2c4f | 2023-06-15 16:34:14 -0700 | [diff] [blame] | 148 | |
| 149 | extern void SetAudioPermissions(const std::string& processNameLog, const char* file_path); |
| 150 | |
| 151 | #endif // COMMON_H |