Debian Codegraph @

Xpjproject/pjsip-apps/src/3rdparty_media_sample/alt_pjsua_txt.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2024-2025 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <pjsua-lib/pjsua.h>
19 #include <pjsua-lib/pjsua_internal.h>
20
21 #if defined(PJSUA_MEDIA_HAS_PJMEDIA) && PJSUA_MEDIA_HAS_PJMEDIA != 0
22 # error The PJSUA_MEDIA_HAS_PJMEDIA should be declared as zero
23 #endif
24
25
26 #define THIS_FILE "alt_pjsua_txt.c"
27 #define UNIMPLEMENTED(func) PJ_LOG(2,(THIS_FILE, "*** Call to unimplemented function %s ***", #func));
28
29 /*****************************************************************************
30 * API
31 */
32
33 /* Our callback to receive incoming RTP packets */
34 static void txt_rtp_cb(void *user_data, void *pkt, pj_ssize_t size)
35 {
36 pjsua_call_media *call_med = (pjsua_call_media*) user_data;
37
38 /* TODO: Do something with the packet */
39 PJ_LOG(4,(THIS_FILE, "RX %d bytes text RTP packet", (int)size));
40 }
41
42 /* Our callback to receive RTCP packets */
43 static void txt_rtcp_cb(void *user_data, void *pkt, pj_ssize_t size)
44 {
45 pjsua_call_media *call_med = (pjsua_call_media*) user_data;
46
47 /* TODO: Do something with the packet here */
48 PJ_LOG(4,(THIS_FILE, "RX %d bytes text RTCP packet", (int)size));
49 }
50
51 /* A demo function to send dummy "RTP" packets periodically. You would not
52 * need to have this function in the real app!
53 */
54 static void timer_to_send_txt_rtp(void *user_data)
55 {
56 pjsua_call_media *call_med = (pjsua_call_media*) user_data;
57 const char *pkt = "Not RTP packet";
58
59 if (!call_med->call || !call_med->call->inv || !call_med->tp) {
60 /* Call has been disconnected. There is race condition here as
61 * this cb may be called sometime after call has been disconnected */
62 return;
63 }
64
65 pjmedia_transport_send_rtp(call_med->tp, pkt, strlen(pkt));
66
67 pjsua_schedule_timer2(&timer_to_send_txt_rtp, call_med, 2000);
68 }
69
70 static void timer_to_send_txt_rtcp(void *user_data)
71 {
72 pjsua_call_media *call_med = (pjsua_call_media*) user_data;
73 const char *pkt = "Not RTCP packet";
74
75 if (!call_med->call || !call_med->call->inv || !call_med->tp) {
76 /* Call has been disconnected. There is race condition here as
77 * this cb may be called sometime after call has been disconnected */
78 return;
79 }
80
81 pjmedia_transport_send_rtcp(call_med->tp, pkt, strlen(pkt));
82
83 pjsua_schedule_timer2(&timer_to_send_txt_rtcp, call_med, 5000);
84 }
85
86 /* Stop the text stream of a call. */
87 void pjsua_txt_stop_stream(pjsua_call_media *call_med)
88 {
89 /* Detach our RTP/RTCP callbacks from transport */
90 if (call_med->tp) {
91 pjmedia_transport_detach(call_med->tp, call_med);
92 }
93
94 /* TODO: destroy your text stream here */
95 }
96
97 /*
98 * This function is called whenever SDP negotiation has completed
99 * successfully. Here you'd want to start your text stream
100 * based on the info in the SDPs.
101 */
102 pj_status_t pjsua_txt_channel_update(pjsua_call_media *call_med,
103 pj_pool_t *tmp_pool,
104 pjmedia_txt_stream_info *si,
105 const pjmedia_sdp_session *local_sdp,
106 const pjmedia_sdp_session *remote_sdp)
107 {
108 pj_status_t status = PJ_SUCCESS;
109
110 PJ_LOG(4,(THIS_FILE,"Alt text channel update.."));
111 pj_log_push_indent();
112
113 /* Check if no media is active */
114 if (si->dir != PJMEDIA_DIR_NONE) {
115 /* Attach our RTP and RTCP callbacks to the media transport */
116 status = pjmedia_transport_attach(call_med->tp, call_med,
117 &si->rem_addr, &si->rem_rtcp,
118 pj_sockaddr_get_len(&si->rem_addr),
119 &txt_rtp_cb, &txt_rtcp_cb);
120
121 /* For a demonstration, let's use a timer to send "RTP" packet
122 * periodically.
123 */
124 pjsua_schedule_timer2(&timer_to_send_txt_rtp, call_med, 0);
125 pjsua_schedule_timer2(&timer_to_send_txt_rtcp, call_med, 2500);
126
127 /* TODO:
128 * - Create and start your media stream based on the parameters
129 * in si
130 */
131 }
132
133 on_return:
134 pj_log_pop_indent();
135 return status;
136 }
137
138 /*****************************************************************************
139 *
140 * Call API which MAY need to be re-implemented if different backend is used.
141 */
142
143 /* Send text to remote. */
144 PJ_DEF(pj_status_t)
145 pjsua_call_send_text(pjsua_call_id call_id,
146 const pjsua_call_send_text_param *param)
147 {
148 UNIMPLEMENTED(pjsua_call_send_text)
149 return PJ_ENOTSUP;
150 }