blob: 70995dce2283e6408172e15e7d06015e322dc554 [file] [log] [blame]
b.liuf191eb72024-12-12 10:45:23 +08001/*
2* mbtk_rtp.h
3*
4* MBTK RTP(VOIP) internal header file.
5*
6* Author : lb
7* Date : 2024/12/2 14:14:06
8*/
9#ifndef _MBTK_RTP_INTERNAL_H
10#define _MBTK_RTP_INTERNAL_H
11#include "mbtk_type.h"
12#include "mbtk_audio2.h"
13#include "mbtk_ril_api.h"
14#include "mbtk_loop_buffer.h"
15
16#define MBTK_IND_START_FLAG 0xFF
17#define MBTK_IND_END_FLAG 0xEE
18
19#define RTP_UDP_SER_PORT_DEFAULT 53248
20#define RTP_UDP_CLI_PORT_DEFAULT 55555
21#define RTP_IPC_SOCK_PATH "/tmp/mbtk_rtp_sock"
22
23#define RTP_SAMPLE_NUMBER 2 // 2 Byte for every sample.
24#define RTP_DEFAULT_MTU 1280
25#define MAX_IOVECS 16
26
27typedef void (*rtp_socket_read_cb_func)(int fd);
28
29typedef enum {
30 RTP_STATE_DISABLE = 0, // RTP disable,do nothing. Only wait audio mode change.
31 RTP_STATE_ENABLE, // RTP enable,but not on call.
32 RTP_STATE_VOIP_PROCESS // RTP enable and on call.
33} rtp_state_enum;
34
35typedef enum {
36 RTP_UDP_SER_STATE_IDEL,
37 RTP_UDP_SER_STATE_STARTING,
38 RTP_UDP_SER_STATE_RUNNING,
39 RTP_UDP_SER_STATE_STOPING
40} rtp_udp_ser_state_enum;
41
42typedef enum {
43 RTP_VOIP_SER_STATE_IDEL,
44 RTP_VOIP_SER_STATE_STARTING,
45 RTP_VOIP_SER_STATE_RUNNING,
46 RTP_VOIP_SER_STATE_STOPING
47} rtp_voip_ser_state_enum;
48
49typedef struct {
50 rtp_state_enum rtp_state_pre;
51 rtp_state_enum rtp_state_cur;
52 int volume;
53 char remote_ip[20];
54 int server_port; // Must be 53248 (remote port)
55 int client_port; // local port
56
57 char vlan[32];
58 mbtk_audio_sample_rate_enum sample_rate;
59 int channel; // Only support : 1
60} rtp_config_t;
61
62typedef struct {
63 uint32 version; // 2 (2 bit)
64 uint32 padding; // 0 (1 bit)
65 uint32 extension; // 0 (1 bit)
66 uint32 csrc_count; // 1 (4 bit)
67
68 uint32 marker; // 0 (1 bit)
69 uint32 payload_type; // 0x60 (7 bit)
70
71 uint32 sequence; // (16 bit)
72
73 uint32 timestamp; // (32 bit)
74
75 uint32 ssrc; // 0xFFFF0000 (32 bit)
76
77 uint32 csrc; // 0xFFFF0000 (32 bit)
78} rtp_header_info_t;
79
80typedef struct {
81 int fd;
82 rtp_socket_read_cb_func read_cb;
83} rtp_socket_info_t;
84
85typedef struct {
86 uint32 mtu;
87
88 uint32 pack_size;
89 struct iovec iov[MAX_IOVECS];
90 int iov_idx;
91
92 uint8 remain_buff[RTP_DEFAULT_MTU];
93 uint32 remain_buff_len;
94} rtp_udp_send_info_t;
95
96typedef struct {
97 bool first_packet;
98 uint32_t offset;
99
100 mbtk_loop_buff_handle *recv_buff;
101} rtp_udp_recv_info_t;
102
103typedef struct {
104 mbtk_ril_handle* ril_handle;
105 int epoll_fd;
106
107 rtp_socket_info_t unix_sock_cli;
108
109 rtp_socket_info_t udp_recv_sock; // Server
110 rtp_socket_info_t udp_send_sock; // Client
111
112 uint32 frame_size;
113 uint32 playback_size;
114 uint32 sample_for_ms;
115
116 rtp_udp_send_info_t send;
117 rtp_udp_recv_info_t recv;
118
119 pthread_cond_t cond;
120 pthread_mutex_t mutex;
121} rtp_info_t;
122
123#endif /* _MBTK_RTP_INTERNAL_H */