Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve callgen speed #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions yate/callgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import signal
import logging
from pathlib import Path

from aiohttp import web

Expand All @@ -11,7 +12,6 @@

soundfile_extensions = [".slin", ".gsm"]

logging.basicConfig(level=logging.INFO)


class SoundCallInfo:
Expand All @@ -29,7 +29,7 @@ def __init__(self, port, sounds_directory, bind_global=False):

self.active_calls = {}
self.yate = YateAsync("127.0.0.1", port)
self.sounds_directory = sounds_directory
self.sounds_directories = sounds_directory

self.web_app = web.Application()
self.web_app.add_routes([web.post("/call", self.web_call_handler)])
Expand Down Expand Up @@ -72,6 +72,7 @@ def shutdown(self):
self.shutdown_future.set_result(True)

async def web_call_handler(self, request):
logging.debug("TRACE: Request handler begin")
params = await request.post()

soundfile = params.get("soundfile")
Expand Down Expand Up @@ -160,20 +161,26 @@ def drop_call_if_not_answered(self, id):
self._drop_call(id)

def find_soundfile(self, name):
for root, _, files in os.walk(self.sounds_directory):
for f in files:
fname, fext = os.path.splitext(f)
if fname == name and fext in soundfile_extensions:
return os.path.join(root, f)

for directory in self.sounds_directories:
for ext in soundfile_extensions:
test_path = Path(directory) / (name + ext)
logging.debug("Testing %s for existence", test_path)
if test_path.exists():
return str(test_path)

def main():
parser = argparse.ArgumentParser(description='Yate CLI to generate automated calls.')
parser.add_argument("port", type=int, help="The port at which yate is listening")
parser.add_argument("sounds_directory", type=str, help="The directory at which we find the sounds")
parser.add_argument("sounds_directory", type=str, nargs="+", help="Directories at which we find the sounds")
parser.add_argument("--bind_global", action="store_true")
parser.add_argument("--trace", action="store_true", help="Enable debug tracing")


args = parser.parse_args()
if args.trace:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
app = YateCallGenerator(args.port, args.sounds_directory, args.bind_global)
app.run()

Expand Down
Loading