Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pjsip-apps/src/pjsua/pjsua_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ static void on_call_state(pjsua_call_id call_id, pjsip_event *e)
find_next_call();
}

/* Dump media state upon disconnected */
if (1) {
/* Dump media state upon disconnected.
* Moved to on_stream_destroyed() since media has been deactivated
* upon disconnection.
*/
if (0) {
PJ_LOG(5,(THIS_FILE,
"Call %d disconnected, dumping media stats..",
call_id));
Expand Down Expand Up @@ -271,6 +274,21 @@ static void on_call_state(pjsua_call_id call_id, pjsip_event *e)
}
}

/*
* Handler when audio stream is destroyed.
*/
static void on_stream_destroyed(pjsua_call_id call_id,
pjmedia_stream *strm,
unsigned stream_idx)
{
if (1) {
PJ_LOG(5,(THIS_FILE,
"Call %d stream %d destroyed, dumping media stats..",
call_id, stream_idx));
log_call_dump(call_id);
}
}

/**
* Handler when there is incoming call.
*/
Expand Down Expand Up @@ -1317,6 +1335,7 @@ int stdout_refresh_proc(void *arg)
return 0;
}


static pj_status_t app_init(void)
{
pjsua_transport_id transport_id = -1;
Expand Down Expand Up @@ -1351,6 +1370,7 @@ static pj_status_t app_init(void)

/* Initialize application callbacks */
app_config.cfg.cb.on_call_state = &on_call_state;
app_config.cfg.cb.on_stream_destroyed = &on_stream_destroyed;
app_config.cfg.cb.on_call_media_state = &on_call_media_state;
app_config.cfg.cb.on_incoming_call = &on_incoming_call;
app_config.cfg.cb.on_dtmf_digit2 = &call_on_dtmf_callback2;
Expand Down
19 changes: 17 additions & 2 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -5277,9 +5277,11 @@ pjsua_call_send_dtmf_param_default(pjsua_call_send_dtmf_param *param);
PJ_DECL(unsigned) pjsua_call_get_max_count(void);

/**
* Get number of currently active calls.
* Get the number of current calls. The number includes active calls
* (pjsua_call_is_active(call_id) == PJ_TRUE), as well as calls that
* are no longer active but still in the process of hanging up.
*
* @return Number of currently active calls.
* @return Number of current calls.
*/
PJ_DECL(unsigned) pjsua_call_get_count(void);

Expand Down Expand Up @@ -5557,6 +5559,19 @@ pjsua_call_answer_with_sdp(pjsua_call_id call_id,
* while #pjsua_call_answer() only works with incoming calls on EARLY
* state.
*
* After calling this function, media will be deinitialized (call media
* callbacks, if any, will still be received) and then, on_call_state()
* will be immediately called with state DISCONNECTED. No further
* call callbacks will be received after this. The call hangup process
* itself (sending BYE, waiting for the response, and resource cleanup)
* will continue in the background and the call slot can be reused only
* after this process is completed. If application has limited call slots
* and would like to check if there are any free slots remaining, it can
* query the number of free slots using the APIs:
* pjsua_call_get_max_count()-pjsua_call_get_count()
*
* Note that on_call_tsx_state() will not be called when using this API.
*
* @param call_id Call identification.
* @param code Optional status code to be sent when we're rejecting
* incoming call. If the value is zero, "603/Decline"
Expand Down
6 changes: 6 additions & 0 deletions pjsip/include/pjsua-lib/pjsua_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ struct pjsua_call
created yet. This temporary
variable is used to handle such
case, see ticket #1916. */

pj_timer_entry hangup_timer; /**< Hangup retry timer. */
unsigned hangup_retry; /**< Number of hangup retries. */
unsigned hangup_code; /**< Hangup code. */
pj_str_t hangup_reason; /**< Hangup reason. */
pjsua_msg_data *hangup_msg_data;/**< Hangup message data. */
};


Expand Down
34 changes: 21 additions & 13 deletions pjsip/src/pjsua-lib/pjsua_aud.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,9 @@ void pjsua_aud_stop_stream(pjsua_call_media *call_med)
call_med->rtp_tx_ts = stat.rtp_tx_last_ts;
}

if (pjsua_var.ua_cfg.cb.on_stream_destroyed) {
if (!call_med->call->hanging_up &&
pjsua_var.ua_cfg.cb.on_stream_destroyed)
{
pjsua_var.ua_cfg.cb.on_stream_destroyed(call_med->call->index,
strm, call_med->idx);
}
Expand All @@ -558,15 +560,19 @@ void pjsua_aud_stop_stream(pjsua_call_media *call_med)
static void dtmf_callback(pjmedia_stream *strm, void *user_data,
int digit)
{
pjsua_call_id call_id;

PJ_UNUSED_ARG(strm);

call_id = (pjsua_call_id)(pj_ssize_t)user_data;
if (pjsua_var.calls[call_id].hanging_up)
return;

pj_log_push_indent();

if (pjsua_var.ua_cfg.cb.on_dtmf_digit2) {
pjsua_call_id call_id;
pjsua_dtmf_info info;

call_id = (pjsua_call_id)(pj_ssize_t)user_data;
info.method = PJSUA_DTMF_METHOD_RFC2833;
info.digit = digit;
info.duration = PJSUA_UNKNOWN_DTMF_DURATION;
Expand All @@ -576,9 +582,6 @@ static void dtmf_callback(pjmedia_stream *strm, void *user_data,
* callback, please see ticket #460:
* http://trac.pjsip.org/repos/ticket/460#comment:4
*/
pjsua_call_id call_id;

call_id = (pjsua_call_id)(pj_ssize_t)user_data;
(*pjsua_var.ua_cfg.cb.on_dtmf_digit)(call_id, digit);
}

Expand All @@ -596,10 +599,13 @@ static void dtmf_event_callback(pjmedia_stream *strm, void *user_data,

PJ_UNUSED_ARG(strm);

call_id = (pjsua_call_id)(pj_ssize_t)user_data;
if (pjsua_var.calls[call_id].hanging_up)
return;

pj_log_push_indent();

if (pjsua_var.ua_cfg.cb.on_dtmf_event) {
call_id = (pjsua_call_id)(pj_ssize_t)user_data;
evt.method = PJSUA_DTMF_METHOD_RFC2833;
evt.timestamp = event->timestamp;
evt.digit = event->digit;
Expand Down Expand Up @@ -668,7 +674,7 @@ pj_status_t pjsua_aud_channel_update(pjsua_call_media *call_med,
si->ka_cfg = pjsua_var.acc[call->acc_id].cfg.stream_ka_cfg;
#endif

if (pjsua_var.ua_cfg.cb.on_stream_precreate) {
if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_stream_precreate) {
pjsua_on_stream_precreate_param prm;
prm.stream_idx = strm_idx;
prm.stream_info.type = PJMEDIA_TYPE_AUDIO;
Expand Down Expand Up @@ -707,12 +713,13 @@ pj_status_t pjsua_aud_channel_update(pjsua_call_media *call_med,
/* If DTMF callback is installed by application, install our
* callback to the session.
*/
if (pjsua_var.ua_cfg.cb.on_dtmf_event) {
if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_dtmf_event) {
pjmedia_stream_set_dtmf_event_callback(call_med->strm.a.stream,
&dtmf_event_callback,
(void*)(pj_ssize_t)(call->index));
} else if (pjsua_var.ua_cfg.cb.on_dtmf_digit ||
pjsua_var.ua_cfg.cb.on_dtmf_digit2)
} else if (!call->hanging_up &&
(pjsua_var.ua_cfg.cb.on_dtmf_digit ||
pjsua_var.ua_cfg.cb.on_dtmf_digit2))
{
pjmedia_stream_set_dtmf_callback(call_med->strm.a.stream,
&dtmf_callback,
Expand All @@ -729,7 +736,7 @@ pj_status_t pjsua_aud_channel_update(pjsua_call_media *call_med,
* Note: application may modify media_port to point to different
* media port
*/
if (pjsua_var.ua_cfg.cb.on_stream_created2) {
if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_stream_created2) {
pjsua_on_stream_created_param prm;

prm.stream = call_med->strm.a.stream;
Expand All @@ -741,7 +748,8 @@ pj_status_t pjsua_aud_channel_update(pjsua_call_media *call_med,
call_med->strm.a.destroy_port = prm.destroy_port;
call_med->strm.a.media_port = prm.port;

} else if (pjsua_var.ua_cfg.cb.on_stream_created) {
} else if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_stream_created)
{
(*pjsua_var.ua_cfg.cb.on_stream_created)(call->index,
call_med->strm.a.stream,
strm_idx,
Expand Down
Loading