Подготовка к обновлению РБС (рефак radiusip)
This commit is contained in:
parent
724bf83bd9
commit
9e7efb8b04
@ -1,6 +1,6 @@
|
||||
from django.shortcuts import redirect
|
||||
|
||||
from apps.workerslocation.models.model_voice_call import VoiceCall
|
||||
from apps.pla.models.model_voice_call import VoiceCall
|
||||
|
||||
|
||||
def start_call(request, alarm):
|
||||
|
||||
@ -52,7 +52,7 @@ def save_pla(request):
|
||||
|
||||
client.save()
|
||||
else:
|
||||
point = AlarmForm.objects.get(id=param['id'])
|
||||
point = Alarm.objects.get(id=param['id'])
|
||||
form = AlarmForm(request.POST,instance=point)
|
||||
if form.is_valid():
|
||||
point = form.save(commit=False)
|
||||
|
||||
@ -81,34 +81,45 @@ async def receive_messages(websocket, auth_dict):
|
||||
identifier = message_item.get('identifier')
|
||||
|
||||
if identifier == 'core/connection_response':
|
||||
logging.log(f"Соединение установлено. Инициализация модулей...")
|
||||
logging.log(
|
||||
f"Соединение установлено. Инициализация модулей...")
|
||||
await send_messages(websocket, get_call_initialize_command())
|
||||
await send_messages(websocket, get_location_initialize_command())
|
||||
await send_messages(websocket,
|
||||
get_location_initialize_command())
|
||||
|
||||
if identifier == 'call:1/initialization_response':
|
||||
call_mapi_initialized = True
|
||||
ssrc = message_item['payload'].get('voip_ssrc', SSRC)
|
||||
voip_port = message_item['payload'].get('voip_port', API_PORT)
|
||||
|
||||
elif identifier == 'location:0/position_broadcast' and auth_dict['wlocationsystem']:
|
||||
elif identifier == 'location:0/position_broadcast' and auth_dict[
|
||||
'wlocationsystem']:
|
||||
logging.log(message_item['payload'])
|
||||
await save_location(message_item['payload'])
|
||||
|
||||
elif call_mapi_initialized and voice_call and auth_dict['plasystem']:
|
||||
logging.log("Запрос на отправку аудио. Инициализация трансляции трансляцию...")
|
||||
elif call_mapi_initialized and voice_call and auth_dict[
|
||||
'plasystem']:
|
||||
logging.log(
|
||||
"Запрос на отправку аудио. Инициализация трансляции трансляцию...")
|
||||
await set_voice_call_sent(voice_call)
|
||||
await send_messages(websocket, get_transmit_command(promise_id, ssrc, auth_dict['raduisip_group']))
|
||||
await send_messages(websocket,
|
||||
get_transmit_command(promise_id, ssrc,
|
||||
auth_dict[
|
||||
'raduisip_group']))
|
||||
logging.log("Начало трансляции файла.")
|
||||
await start_audio_stream(voice_call.alarm_file.audio_file.path, auth_dict['radiusip_host_ws'],
|
||||
await start_audio_stream(voice_call.alarm_file.audio_file.path,
|
||||
auth_dict['radiusip_host_ws'],
|
||||
voip_port, ssrc)
|
||||
await send_messages(websocket, get_promise_cancel_command(promise_id))
|
||||
await send_messages(websocket,
|
||||
get_promise_cancel_command(promise_id))
|
||||
promise_id += 1
|
||||
logging.log("Трансляция завершена и вызов остановлен.")
|
||||
|
||||
|
||||
@sync_to_async
|
||||
def get_voice_calls():
|
||||
return VoiceCall.objects.filter(sent=False).prefetch_related('alarm_file').first()
|
||||
return VoiceCall.objects.filter(sent=False).prefetch_related(
|
||||
'alarm_file').first()
|
||||
|
||||
|
||||
@sync_to_async()
|
||||
@ -139,8 +150,10 @@ def convert_audio_to_g711a(input_file):
|
||||
"""Конвертирует аудиофайл в формат G.711A (PCMA) с частотой 8000 Гц, используя ffmpeg."""
|
||||
output_file = "converted_audio.g711a"
|
||||
command = [
|
||||
"C:\\ffmpeg\\bin\\ffmpeg.exe", "-y", "-i", input_file,
|
||||
"-ar", "8000", "-ac", "1", "-f", "alaw", output_file # G.711A — это a-law
|
||||
# Путь до ffmpeg если windows
|
||||
"ffmpeg", "-y", "-i", input_file,
|
||||
"-ar", "8000", "-ac", "1", "-f", "alaw", output_file
|
||||
# G.711A — это a-law
|
||||
]
|
||||
|
||||
# Выполнение команды ffmpeg для конвертации
|
||||
@ -178,7 +191,8 @@ async def start_audio_stream(audio_path, dest_ip, dest_port, ssrc):
|
||||
break
|
||||
|
||||
# Создаем RTP пакет с заголовком
|
||||
rtp_packet = struct.pack("!BBHII", 0x80, RTP_PAYLOAD_TYPE, sequence_number,
|
||||
rtp_packet = struct.pack("!BBHII", 0x80, RTP_PAYLOAD_TYPE,
|
||||
sequence_number,
|
||||
timestamp, ssrc) + frame_data
|
||||
sock.sendto(rtp_packet, (dest_ip, dest_port))
|
||||
|
||||
@ -187,7 +201,8 @@ async def start_audio_stream(audio_path, dest_ip, dest_port, ssrc):
|
||||
# Обновляем таймстамп на количество байт (160 байт для 20 мс при G.711A)
|
||||
|
||||
# Расчет времени для отправки следующего пакета
|
||||
next_packet_time = start_time + (sequence_number * PACKET_DURATION_MS / 1000)
|
||||
next_packet_time = start_time + (
|
||||
sequence_number * PACKET_DURATION_MS / 1000)
|
||||
delay = max(0, next_packet_time - time.time())
|
||||
time.sleep(delay)
|
||||
|
||||
@ -210,7 +225,8 @@ def get_settings_from_db():
|
||||
'radiusip_api_key': get_settings(prefix + 'token', ''),
|
||||
'radiusip_login': get_settings(prefix + 'login', ''),
|
||||
'radiusip_password': get_settings(prefix + 'pass', ''),
|
||||
'raduisip_group': get_settings(prefix + 'group', 'dmr:1@groups.17826016.global'),
|
||||
'raduisip_group': get_settings(prefix + 'group',
|
||||
'dmr:1@groups.17826016.global'),
|
||||
'wlocationsystem': True if wlocationsystem == 'Radiusip' else False,
|
||||
'plasystem': True if plasystem == 'Radiusip' else False,
|
||||
}
|
||||
@ -239,7 +255,7 @@ if __name__ == '__main__':
|
||||
|
||||
django.setup()
|
||||
from apps.general.views.settingsmodule import get_settings
|
||||
from apps.workerslocation.models.model_voice_call import VoiceCall
|
||||
from apps.pla.models.model_voice_call import VoiceCall
|
||||
from apps.workerslocation.models.workers_locations import WorkersLocation
|
||||
from sabron.util import logging
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user