FreeCalypso > hg > sipout-test-utils
view test-fsk/rtp_tx.c @ 14:f96153d15889
sipout-test-voice: implement play from file
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 May 2024 22:10:38 -0800 |
parents | 030d52b96a23 |
children |
line wrap: on
line source
/* * In this module we implement outgoing RTP stream generation. */ #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> #include <spandsp.h> #include "../include/tmgw_const.h" #include "../include/rtp_defs.h" #include "../include/pstn_defs.h" #include "../libutil/osmo_bits.h" extern struct sockaddr_in rtp_local_addr, rtp_remote_addr; extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected; extern struct timeval cur_event_time; extern int fsk_mode_tx; static uint32_t rtp_ssrc; static uint32_t rtp_out_ts; static uint16_t rtp_out_seq; static fsk_tx_state_t *fsk_tx_state; static g711_state_t *g711_enc_state; void assign_rtpout_ssrc() { rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid(); } static int supply_bit() { return 1; } void init_pcm_tx() { fsk_tx_state = fsk_tx_init(NULL, &preset_fsk_specs[fsk_mode_tx], supply_bit, NULL); if (!fsk_tx_state) { fprintf(stderr, "error: fsk_tx_init() failed!\n"); exit(1); } g711_enc_state = g711_init(NULL, pcma_selected ? G711_ALAW : G711_ULAW); if (!g711_enc_state) { fprintf(stderr, "error: g711_init() failed!\n"); exit(1); } } void generate_rtp_packet() { struct rtp_packet pkt; socklen_t addrlen; int16_t linear[FRAME_20MS]; pkt.v_p_x_cc = 0x80; pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU; pkt.seq = htons(rtp_out_seq++); pkt.tstamp = htonl(rtp_out_ts); rtp_out_ts += FRAME_20MS; pkt.ssrc = rtp_ssrc; fsk_tx(fsk_tx_state, linear, FRAME_20MS); g711_encode(g711_enc_state, pkt.payload, linear, FRAME_20MS); addrlen = sizeof(struct sockaddr_in); sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, (struct sockaddr *) &rtp_remote_addr, addrlen); }