You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
4.0 KiB
89 lines
4.0 KiB
// radio.h — рация (PTT walkie-talkie): мультикаст голоса по CHAT-группе. |
|
// |
|
// Флудит Opus-кадры всем подписчикам канала (узлы с TOPO_FLAG_RADIO в NODEINFO). |
|
// Передача полудуплексная: радио включается на прослушивание, PTT — на передачу. |
|
// Все функции — в uasync-потоке, кроме регистрации frame/mute callbacks |
|
// аудио-потребителем при init/destroy. |
|
#ifndef RADIO_H |
|
#define RADIO_H |
|
|
|
#include <stdint.h> |
|
|
|
#include "radio_proto.h" |
|
|
|
struct TOPO_GROUP; |
|
struct UTUN_INSTANCE; |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
/* ── жизненный цикл ── */ |
|
|
|
int radio_init(struct TOPO_GROUP* group); /* из topo_group_create */ |
|
void radio_destroy(struct TOPO_GROUP* group); /* из topo_group_destroy */ |
|
|
|
int radio_init_instance(struct UTUN_INSTANCE* inst); /* etcp_bind(ETCP_ID_RADIO) */ |
|
void radio_destroy_instance(struct UTUN_INSTANCE* inst); /* etcp_unbind */ |
|
|
|
/* ── приём Opus-кадра пира (для аудио-движка radio_audio) ── */ |
|
|
|
typedef void (*radio_frame_fn)(struct UTUN_INSTANCE* inst, uint64_t group_id, |
|
uint64_t src_node_id, uint16_t stream_id, uint16_t seq, |
|
uint8_t fin, const uint8_t* opus, int len, void* arg); |
|
void radio_set_frame_cb(struct UTUN_INSTANCE* inst, radio_frame_fn fn, void* arg); |
|
|
|
/* Локальные настройки участников: только uasync, без изменения подписки и пересылки. */ |
|
int radio_member_muted(struct UTUN_INSTANCE* inst, uint64_t group_id, uint64_t node_id); |
|
int radio_set_member_muted(struct UTUN_INSTANCE* inst, uint64_t group_id, uint64_t node_id, int muted); |
|
/* После удаления записи участника из БД удалить её из локального кэша. */ |
|
void radio_forget_member_mute(struct UTUN_INSTANCE* inst, uint64_t group_id, uint64_t node_id); |
|
/* Аудио-потребитель очищает накопленный звук источника при изменении настройки. */ |
|
typedef void (*radio_mute_fn)(struct UTUN_INSTANCE* inst, uint64_t group_id, uint64_t node_id, int muted, void* arg); |
|
void radio_set_mute_cb(struct UTUN_INSTANCE* inst, radio_mute_fn fn, void* arg); |
|
|
|
/* ── передача (PTT), uasync-поток ── */ |
|
|
|
int radio_talk_begin(struct UTUN_INSTANCE* inst, uint64_t group_id); /* новая передача, seq=0 */ |
|
int radio_talk_send(struct UTUN_INSTANCE* inst, uint64_t group_id, const uint8_t* opus, int len); |
|
int radio_talk_end(struct UTUN_INSTANCE* inst, uint64_t group_id); /* FIN-кадр */ |
|
|
|
/* Включить/выключить прослушивание рации канала (флаг + BGP-рассылка). */ |
|
void radio_set_active(struct UTUN_INSTANCE* inst, uint64_t group_id, int on); |
|
int radio_is_active(struct UTUN_INSTANCE* inst, uint64_t group_id); |
|
|
|
/* Число подписчиков рации канала (без себя) — для индикатора в GUI. */ |
|
int radio_subscribers(struct UTUN_INSTANCE* inst, uint64_t group_id); |
|
|
|
/* Число дропнутых дублей (src,stream,seq) — для диагностики/тестов. */ |
|
uint32_t radio_dup_dropped(struct UTUN_INSTANCE* inst, uint64_t group_id); |
|
|
|
/* ── trampoline-структуры (GUI/аудио-поток → uasync) ── */ |
|
|
|
struct radio_talk_arg { |
|
struct UTUN_INSTANCE* inst; |
|
uint64_t group_id; |
|
}; |
|
|
|
struct radio_media_arg { |
|
struct UTUN_INSTANCE* inst; |
|
uint64_t group_id; |
|
uint16_t len; |
|
uint8_t opus[RADIO_MAX_OPUS]; |
|
}; |
|
|
|
struct radio_set_active_arg { |
|
struct UTUN_INSTANCE* inst; |
|
uint64_t group_id; |
|
int on; |
|
}; |
|
|
|
void radio_talk_begin_trampoline(void* arg); |
|
void radio_talk_end_trampoline(void* arg); |
|
void radio_talk_send_trampoline(void* arg); |
|
void radio_set_active_trampoline(void* arg); |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif /* RADIO_H */
|
|
|