SDK: add audio option for MediaHandler API
- modify AudioFilter for Windows build
Change-Id: Icddd014b0d42cd3848000c7b8b97baa7cab709aa
GitLab: #3
diff --git a/SDK/skeletonSrcProfile.py b/SDK/skeletonSrcProfile.py
index 6e8e7d2..1e3e110 100644
--- a/SDK/skeletonSrcProfile.py
+++ b/SDK/skeletonSrcProfile.py
@@ -36,10 +36,14 @@
Preferences.__init__(self, action)
self.names = []
self.apis = []
+ self.dataTypes = []
self.mainFile = self.pluginDirectory + "/main.cpp"
self.newNames = []
self.globNames()
self.initPackage()
+ with open('./Templates/defaultStrings.json') as f:
+ self.defaultStrings = json.load(f)
+ f.close()
def initPackage(self):
if os.path.exists(self.packageFile):
@@ -155,8 +159,15 @@
self.names.append(name)
if ("MediaHandler" in file):
self.apis.append(PLUGINS_APIS["MEDIA_HANDLER"])
- if ("ConversationHandler" in file):
+ elif ("ConversationHandler" in file):
self.apis.append(PLUGINS_APIS["CONVERSATION_HANDLER"])
+ if ("Subscriber" in file):
+ if ("Video" in file):
+ self.dataTypes.append(DATA_TYPES["VIDEO"])
+ elif ("Audio" in file):
+ self.dataTypes.append(DATA_TYPES["AUDIO"])
+ elif ("Conversation" in file):
+ self.dataTypes.append(DATA_TYPES["TEXT"])
def createHandlers(self, split):
if (len(self.names) == 0):
@@ -186,6 +197,7 @@
print(f"\nChoose a API for functionality \"{functionName}\".")
print("\nAvailable APIs: ")
print("(1) video during a call (Media Handler API)")
+ print("(2) audio during a call (Media Handler API)")
print(
colored(
"For more information about the API, call help preferences.",
@@ -194,6 +206,10 @@
apiType = input("\nEnter a data type number: ")
if (apiType not in PLUGINS_APIS.values()):
print(colored(f"Data type '{apiType}' not valid!", "red"))
+ else:
+ self.dataTypes.append(list(DATA_TYPES.values())[int(apiType)-1])
+ if (apiType == PLUGINS_APIS["MEDIA_HANDLER_AUDIO"]):
+ apiType = PLUGINS_APIS["MEDIA_HANDLER"]
self.names.append(functionName)
self.newNames.append(functionName)
self.apis.append(apiType)
@@ -205,7 +221,6 @@
for j, item in enumerate(self.apis):
temp = ''
localNames = self.names.copy()
- localApis = self.apis.copy()
if (item == PLUGINS_APIS["MEDIA_HANDLER"]):
localNames[j] = self.names[j] + "MediaHandler"
if (split):
@@ -228,16 +243,33 @@
data = f.read()
data = data.replace("HEADER", self.header)
data = data.replace("GENERIC", self.names[j])
+ data = data.replace("DATATYPE", self.dataTypes[j])
f.close()
with open(f"{self.pluginDirectory}/{self.names[j]}MediaHandler.h", 'w') as f:
f.write(data)
f.close()
- with open('./Templates/genericVideoSubscriber.h', 'r') as f:
+ with open('./Templates/genericMediaSubscriber.h', 'r') as f:
data = f.read()
data = data.replace("HEADER", self.header)
data = data.replace("GENERIC", self.names[j])
+ data = data.replace("DATATYPE", self.dataTypes[j])
f.close()
- with open(f"{self.pluginDirectory}/{self.names[j]}VideoSubscriber.h", 'w') as f:
+ data = data.split("---")
+ for k, dataItem in enumerate(data):
+ if (f"{self.dataTypes[j]}INCLUDES" in dataItem):
+ tempString = data[k]
+ data[k] = ""
+ if (self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}INCLUDES"]):
+ for string in self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}INCLUDES"]:
+ data[k] += tempString.replace(f"{self.dataTypes[j]}INCLUDES", string)
+ elif (f"{self.dataTypes[j]}PRIVATE" in dataItem):
+ tempString = data[k]
+ data[k] = ""
+ if (self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}PRIVATE"]):
+ for string in self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}PRIVATE"]:
+ data[k] += tempString.replace(f"{self.dataTypes[j]}PRIVATE", string)
+ data = "".join(data)
+ with open(f"{self.pluginDirectory}/{self.names[j]}{self.dataTypes[j]}Subscriber.h", 'w') as f:
f.write(data)
f.close()
elif (item == PLUGINS_APIS["CONVERSATION_HANDLER"]):
@@ -259,16 +291,44 @@
data = data.replace("HEADER", self.header)
data = data.replace("PLUGINNAME", self.pluginName)
data = data.replace("GENERIC", self.names[j])
+ data = data.replace("DATATYPE", self.dataTypes[j])
+ data = data.replace("DataType", self.dataTypes[j].lower())
f.close()
with open(f"{self.pluginDirectory}/{self.names[j]}MediaHandler.cpp", 'w') as f:
f.write(data)
f.close()
- with open('./Templates/genericVideoSubscriber.cpp', 'r') as f:
+ with open('./Templates/genericMediaSubscriber.cpp', 'r') as f:
data = f.read()
data = data.replace("HEADER", self.header)
data = data.replace("GENERIC", self.names[j])
+ data = data.replace("DATATYPE", self.dataTypes[j])
f.close()
- with open(f"{self.pluginDirectory}/{self.names[j]}VideoSubscriber.cpp", 'w') as f:
+ data = data.split("---")
+ for k, dataItem in enumerate(data):
+ if (f"FFMPEG{self.dataTypes[j]}INCLUDES" in dataItem):
+ tempString = data[k]
+ tempStringSplits = tempString.split("\n")[1:]
+ data[k] = ""
+ if (self.defaultStrings["genericmediasubscriber"]["impl"][f"FFMPEG{self.dataTypes[j]}INCLUDES"]):
+ for string in self.defaultStrings["genericmediasubscriber"]["impl"][f"FFMPEG{self.dataTypes[j]}INCLUDES"]:
+ data[k] += tempStringSplits[1].replace(f"FFMPEG{self.dataTypes[j]}INCLUDES", string) + "\n"
+ tempStringSplits[1] = data[k]
+ data[k] = tempStringSplits[0] + "\n" + tempStringSplits[1] + tempStringSplits[2]
+ elif (f"{self.dataTypes[j]}INCLUDES" in dataItem):
+ tempString = data[k]
+ data[k] = ""
+ if (self.defaultStrings["genericmediasubscriber"]["impl"][f"{self.dataTypes[j]}INCLUDES"]):
+ for string in self.defaultStrings["genericmediasubscriber"]["impl"][f"{self.dataTypes[j]}INCLUDES"]:
+ data[k] += tempString.replace(f"{self.dataTypes[j]}INCLUDES", string)
+ elif (f"{self.dataTypes[j]}UPDATE" in dataItem):
+ fileName = self.defaultStrings["genericmediasubscriber"]["impl"][f"{self.dataTypes[j]}UPDATE"]
+ with open(f"./Templates/{fileName}") as updateFile:
+ updateTxt = updateFile.read()
+ updateFile.close()
+ data[k] = data[k].replace(f"{self.dataTypes[j]}UPDATE", updateTxt)
+
+ data = "".join(data)
+ with open(f"{self.pluginDirectory}/{self.names[j]}{self.dataTypes[j]}Subscriber.cpp", 'w') as f:
f.write(data)
f.close()
elif (item == PLUGINS_APIS["CONVERSATION_HANDLER"]):
@@ -373,13 +433,9 @@
self.package["version"] = '0.0.0'
f.close()
- with open('./Templates/defaultDependenciesStrings.json') as f:
- defaultStrings = json.load(f)
- f.close()
-
for api in self.apis:
if api == PLUGINS_APIS["MEDIA_HANDLER"]:
- for dep in defaultStrings["package.json"]["MediaHandler"]["deps"]:
+ for dep in self.defaultStrings["package.json"]["MediaHandler"]["deps"]:
if dep not in self.package["deps"]:
self.package["deps"].append(dep)
with open(f"{self.pluginDirectory}/package.json", 'w') as f:
@@ -397,31 +453,54 @@
outputStr += baseStr.replace(key, name)
return outputStr
- def fillBuildFile(self, inputStr):
+ def fillBuildFile(self, inputStr, fileType): #fileType = 0 -> build.sh; fileType = 1 -> CMakeLists.txt
inputStr = inputStr.replace('PLUGINNAME', self.pluginName)
inputStr = inputStr.replace('MANIFESTVERSION', self.version)
splits = inputStr.split('---')
tempPart = []
for i, split in enumerate(splits):
- if (("FFMPEG" in split or "avutil" in split)
+ if ("FFMPEG" in split
and PLUGINS_APIS['MEDIA_HANDLER'] not in self.apis):
splits[i] = ''
elif ("CPPFILENAME" in split):
splits[i] = self.globFiles(split, "CPPFILENAME", "cpp")
elif ("HFILENAME" in split):
splits[i] = self.globFiles(split, "HFILENAME", "h")
+ elif ("FFMPEGEXTRA" in split):
+ splits[i] = splits[i].replace("FFMPEGEXTRA", "")
elif ("FFMPEGCPP" in split):
- splits[i] = split.replace("FFMPEGCPP", '')
+ tempString = splits[i]
+ splits[i] = ""
+ for item in self.defaultStrings["buildFiles"]["MediaHandler"][f"{self.ffmpegBuildOption}FFMPEGCPP"]:
+ splits[i] += tempString.replace("FFMPEGCPP", item)
elif ("FFMPEGH" in split):
- splits[i] = split.replace("FFMPEGH", '')
+ tempString = splits[i]
+ splits[i] = ""
+ for item in self.defaultStrings["buildFiles"]["MediaHandler"][f"{self.ffmpegBuildOption}FFMPEGH"]:
+ splits[i] += tempString.replace("FFMPEGH", item)
+ elif ("FFMPEGLIBS" in split):
+ tempString = splits[i]
+ splits[i] = ""
+ for item in self.defaultStrings["buildFiles"]["MediaHandler"][f"{self.ffmpegBuildOption}FFMPEGLIBS"]:
+ if (fileType):
+ splits[i] += tempString.replace("FFMPEGLIBS", f"{item} ")
+ else:
+ splits[i] += tempString.replace("FFMPEGLIBS", f"-l:lib{item}.a")
inputStr = ''.join(splits)
return inputStr
def createBuildFiles(self):
+ self.ffmpegBuildOption = None
+ for typeItem in self.dataTypes:
+ if (typeItem == DATA_TYPES["VIDEO"]):
+ self.ffmpegBuildOption = 'Video'
+ break
+ elif (typeItem == DATA_TYPES["AUDIO"]):
+ self.ffmpegBuildOption = 'Audio'
with open("./Templates/CMakeLists.txt", 'r') as f:
cmakelists = f.read()
f.close()
- cmakelists = self.fillBuildFile(cmakelists)
+ cmakelists = self.fillBuildFile(cmakelists, 1)
with open(self.cmakelistsFile, 'w') as f:
f.write(cmakelists)
f.close()
@@ -429,7 +508,7 @@
with open("./Templates/build.sh", 'r') as f:
build = f.read()
f.close()
- build = self.fillBuildFile(build)
+ build = self.fillBuildFile(build, 0)
with open(self.buildFile, 'w') as f:
f.write(build)
f.close()