| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <pjsua-lib/pjsua.h> |
| 20 |
#include <pjsua-lib/pjsua_internal.h> |
| 21 |
|
| 22 |
#if defined(PJSUA_MEDIA_HAS_PJMEDIA) && PJSUA_MEDIA_HAS_PJMEDIA != 0 |
| 23 |
|
| 24 |
#define THIS_FILE "pjsua_txt.c" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
PJ_DEF(pj_status_t) |
| 29 |
pjsua_call_send_text(pjsua_call_id call_id, |
| 30 |
const pjsua_call_send_text_param *param) |
| 31 |
{ |
| 32 |
pjsua_call *call; |
| 33 |
pjsua_call_media *call_med; |
| 34 |
pjsip_dialog *dlg = NULL; |
| 35 |
int med_idx; |
| 36 |
pj_status_t status; |
| 37 |
|
| 38 |
PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls && |
| 39 |
param, PJ_EINVAL); |
| 40 |
|
| 41 |
pj_log_push_indent(); |
| 42 |
|
| 43 |
status = acquire_call("pjsua_call_send_text()", call_id, &call, &dlg); |
| 44 |
if (status != PJ_SUCCESS) |
| 45 |
goto on_return; |
| 46 |
|
| 47 |
|
| 48 |
if ((med_idx = param->med_idx) == -1) { |
| 49 |
unsigned i; |
| 50 |
|
| 51 |
for (i = 0; i < call->med_cnt; ++i) { |
| 52 |
if (call->media[i].type == PJMEDIA_TYPE_TEXT && |
| 53 |
(call->media[i].dir & PJMEDIA_DIR_ENCODING)) |
| 54 |
{ |
| 55 |
med_idx = i; |
| 56 |
break; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
if (med_idx == -1) { |
| 61 |
status = PJ_ENOTFOUND; |
| 62 |
goto on_return; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
PJ_ASSERT_ON_FAIL(med_idx >= 0 && med_idx < (int)call->med_cnt, |
| 67 |
{status = PJ_EINVAL; goto on_return;}); |
| 68 |
|
| 69 |
|
| 70 |
call_med = &call->media[med_idx]; |
| 71 |
if (call_med->type != PJMEDIA_TYPE_TEXT || |
| 72 |
(call_med->dir & PJMEDIA_DIR_ENCODING) == 0 || |
| 73 |
!call_med->strm.t.stream) |
| 74 |
{ |
| 75 |
status = PJ_EINVALIDOP; |
| 76 |
goto on_return; |
| 77 |
} |
| 78 |
|
| 79 |
status = pjmedia_txt_stream_send_text(call_med->strm.t.stream, |
| 80 |
¶m->text); |
| 81 |
|
| 82 |
on_return: |
| 83 |
if (dlg) pjsip_dlg_dec_lock(dlg); |
| 84 |
pj_log_pop_indent(); |
| 85 |
return status; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
static void rx_text_cb(pjmedia_txt_stream *strm, void *user_data, |
| 92 |
const pjmedia_txt_stream_data *data) |
| 93 |
{ |
| 94 |
pjsua_call_id call_id; |
| 95 |
pjsua_txt_stream_data txt; |
| 96 |
|
| 97 |
PJ_UNUSED_ARG(strm); |
| 98 |
|
| 99 |
call_id = (pjsua_call_id)(pj_ssize_t)user_data; |
| 100 |
if (pjsua_var.calls[call_id].hanging_up) |
| 101 |
return; |
| 102 |
|
| 103 |
pj_log_push_indent(); |
| 104 |
|
| 105 |
if (pjsua_var.ua_cfg.cb.on_call_rx_text) { |
| 106 |
txt.seq = data->seq; |
| 107 |
txt.ts = data->ts; |
| 108 |
txt.text = data->text; |
| 109 |
(*pjsua_var.ua_cfg.cb.on_call_rx_text)(call_id, &txt); |
| 110 |
} |
| 111 |
|
| 112 |
pj_log_pop_indent(); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
void pjsua_txt_stop_stream(pjsua_call_media *call_med) |
| 117 |
{ |
| 118 |
pjmedia_txt_stream *strm = call_med->strm.t.stream; |
| 119 |
pjmedia_stream_common *c_strm = (pjmedia_stream_common *)strm; |
| 120 |
pjmedia_rtcp_stat stat; |
| 121 |
pjmedia_txt_stream_info prev_txt_si; |
| 122 |
|
| 123 |
pj_assert(call_med->type == PJMEDIA_TYPE_TEXT); |
| 124 |
|
| 125 |
if (!strm) |
| 126 |
return; |
| 127 |
|
| 128 |
PJ_LOG(4,(THIS_FILE, "Stopping text stream..")); |
| 129 |
pj_log_push_indent(); |
| 130 |
|
| 131 |
pjmedia_txt_stream_get_info(strm, &prev_txt_si); |
| 132 |
call_med->prev_local_addr = prev_txt_si.local_addr; |
| 133 |
call_med->prev_rem_addr = prev_txt_si.rem_addr; |
| 134 |
|
| 135 |
pjmedia_stream_common_send_rtcp_bye(c_strm); |
| 136 |
|
| 137 |
if (pjmedia_stream_common_get_stat(c_strm, &stat) == PJ_SUCCESS) |
| 138 |
{ |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
call_med->rtp_tx_seq_ts_set = 1 | (1 << 1); |
| 146 |
call_med->rtp_tx_seq = stat.rtp_tx_last_seq; |
| 147 |
call_med->rtp_tx_ts = stat.rtp_tx_last_ts; |
| 148 |
} |
| 149 |
|
| 150 |
pjmedia_txt_stream_destroy(strm); |
| 151 |
call_med->strm.t.stream = NULL; |
| 152 |
|
| 153 |
pj_log_pop_indent(); |
| 154 |
} |
| 155 |
|
| 156 |
pj_status_t pjsua_txt_channel_update(pjsua_call_media *call_med, |
| 157 |
pj_pool_t *tmp_pool, |
| 158 |
pjmedia_txt_stream_info *si, |
| 159 |
const pjmedia_sdp_session *local_sdp, |
| 160 |
const pjmedia_sdp_session *remote_sdp) |
| 161 |
{ |
| 162 |
pjsua_call *call = call_med->call; |
| 163 |
unsigned strm_idx = call_med->idx; |
| 164 |
pj_status_t status = PJ_SUCCESS; |
| 165 |
|
| 166 |
PJ_UNUSED_ARG(tmp_pool); |
| 167 |
PJ_UNUSED_ARG(local_sdp); |
| 168 |
PJ_UNUSED_ARG(remote_sdp); |
| 169 |
|
| 170 |
PJ_LOG(4,(THIS_FILE,"Text channel update for index %d for call %d...", |
| 171 |
call_med->idx, call_med->call->index)); |
| 172 |
pj_log_push_indent(); |
| 173 |
|
| 174 |
si->rtcp_sdes_bye_disabled = pjsua_var.media_cfg.no_rtcp_sdes_bye; |
| 175 |
|
| 176 |
|
| 177 |
if (local_sdp->media[strm_idx]->desc.port != 0) { |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
si->jb_init = pjsua_var.media_cfg.jb_init; |
| 183 |
si->jb_min_pre = pjsua_var.media_cfg.jb_min_pre; |
| 184 |
si->jb_max_pre = pjsua_var.media_cfg.jb_max_pre; |
| 185 |
si->jb_max = pjsua_var.media_cfg.jb_max; |
| 186 |
si->jb_discard_algo = pjsua_var.media_cfg.jb_discard_algo; |
| 187 |
|
| 188 |
|
| 189 |
si->ssrc = call_med->ssrc; |
| 190 |
si->cname = call->cname; |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
si->rtp_ts = call_med->rtp_tx_ts; |
| 198 |
si->rtp_seq = call_med->rtp_tx_seq; |
| 199 |
si->rtp_seq_ts_set = call_med->rtp_tx_seq_ts_set; |
| 200 |
|
| 201 |
#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0 |
| 202 |
|
| 203 |
si->use_ka = pjsua_var.acc[call->acc_id].cfg.use_stream_ka; |
| 204 |
|
| 205 |
si->ka_cfg = pjsua_var.acc[call->acc_id].cfg.stream_ka_cfg; |
| 206 |
#endif |
| 207 |
|
| 208 |
if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_stream_precreate) { |
| 209 |
pjsua_on_stream_precreate_param prm; |
| 210 |
prm.stream_idx = strm_idx; |
| 211 |
prm.stream_info.type = PJMEDIA_TYPE_TEXT; |
| 212 |
prm.stream_info.info.txt = *si; |
| 213 |
(*pjsua_var.ua_cfg.cb.on_stream_precreate)(call->index, &prm); |
| 214 |
|
| 215 |
|
| 216 |
si->jb_init = prm.stream_info.info.aud.jb_init; |
| 217 |
si->jb_min_pre = prm.stream_info.info.aud.jb_min_pre; |
| 218 |
si->jb_max_pre = prm.stream_info.info.aud.jb_max_pre; |
| 219 |
si->jb_max = prm.stream_info.info.aud.jb_max; |
| 220 |
si->jb_discard_algo = prm.stream_info.info.aud.jb_discard_algo; |
| 221 |
#if defined(PJMEDIA_STREAM_ENABLE_KA) && (PJMEDIA_STREAM_ENABLE_KA != 0) |
| 222 |
si->use_ka = prm.stream_info.info.aud.use_ka; |
| 223 |
|
| 224 |
si->ka_cfg = prm.stream_info.info.aud.ka_cfg; |
| 225 |
#endif |
| 226 |
si->rtcp_sdes_bye_disabled = |
| 227 |
prm.stream_info.info.aud.rtcp_sdes_bye_disabled; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
status = pjmedia_txt_stream_create(pjsua_var.med_endpt, NULL, si, |
| 232 |
call_med->tp, NULL, |
| 233 |
&call_med->strm.t.stream); |
| 234 |
if (status != PJ_SUCCESS) { |
| 235 |
goto on_return; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
status = pjmedia_txt_stream_start(call_med->strm.t.stream); |
| 240 |
if (status != PJ_SUCCESS) { |
| 241 |
goto on_return; |
| 242 |
} |
| 243 |
|
| 244 |
if (call_med->prev_state == PJSUA_CALL_MEDIA_NONE) { |
| 245 |
pjmedia_stream_common_send_rtcp_sdes( |
| 246 |
(pjmedia_stream_common *)call_med->strm.t.stream); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_call_rx_text) { |
| 251 |
pjmedia_txt_stream_set_rx_callback( |
| 252 |
call_med->strm.t.stream, &rx_text_cb, |
| 253 |
(void *)(pj_ssize_t)(call->index), 0); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
on_return: |
| 258 |
pj_log_pop_indent(); |
| 259 |
if (status != PJ_SUCCESS) |
| 260 |
pjsua_perror(THIS_FILE, "pjsua_txt_channel_update failed", status); |
| 261 |
return status; |
| 262 |
} |
| 263 |
|
| 264 |
#endif |