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