Skip to content

Commit

Permalink
ifs log enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
krishanifs committed Sep 23, 2024
1 parent 43c7457 commit 9b528d0
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
33 changes: 33 additions & 0 deletions pjlib/include/pj/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,44 @@
*
* @param expr The expression to be evaluated.
*/
#ifndef _DEBUG
#ifndef pj_assert
#include "pj/log.h"
#include <string.h>
#ifdef _WIN32
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#else
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
#define pj_assert(expr) \
do { \
if (!(expr)) { PJ_LOG(1,(__FILENAME__, "Assert failed: " #expr)); } \
} while (0)
#endif
#else
#ifndef pj_assert
# define pj_assert(expr) assert(expr)
#endif
#endif

/**
* @hideinitializer
* for all buils log the message
* Check during debug build that an expression is true. If the expression
* computes to false during run-time, then the program will stop at the
* offending statements.
* For release build, this macro only print message on the log.
* @param expr The expression to be evaluated.
* @param ... file name,The format string for the log message ("config.c", " PJ_VERSION: %s", PJ_VERSION)
*/
#ifndef PJ_ASSERT_LOG
#include "pj/log.h"
#define PJ_ASSERT_LOG(expr,...) \
do { \
if (!(expr)) { PJ_LOG(1,(__VA_ARGS__)); assert(expr); } \
} while (0)

#endif
/**
* @hideinitializer
* If the expression yields false, assertion will be triggered
Expand Down
16 changes: 12 additions & 4 deletions pjlib/src/pj/os_core_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#else
# define LOG_MUTEX(expr) PJ_LOG(6,expr)
#endif

# define LOG_MUTEX_WARN(expr) PJ_LOG(1,expr)
#define THIS_FILE "os_core_win32.c"

/*
Expand Down Expand Up @@ -1093,10 +1093,18 @@ PJ_DEF(pj_status_t) pj_mutex_lock(pj_mutex_t *mutex)
status = PJ_STATUS_FROM_OS(GetLastError());

#endif
if (status == PJ_SUCCESS)
{
LOG_MUTEX((mutex->obj_name,
(status==PJ_SUCCESS ? "Mutex acquired by thread %s" : "FAILED by %s"),
"Mutex acquired by thread %s",
pj_thread_this()->obj_name));

}
else
{
LOG_MUTEX_WARN((mutex->obj_name,
"FAILED by %s",
pj_thread_this()->obj_name));
}
#if PJ_DEBUG
if (status == PJ_SUCCESS) {
mutex->owner = pj_thread_this();
Expand Down Expand Up @@ -1296,7 +1304,7 @@ static pj_status_t pj_sem_wait_for(pj_sem_t *sem, unsigned timeout)
LOG_MUTEX((sem->obj_name, "Semaphore acquired by thread %s",
pj_thread_this()->obj_name));
} else {
LOG_MUTEX((sem->obj_name, "Semaphore: thread %s FAILED to acquire",
LOG_MUTEX_WARN((sem->obj_name, "Semaphore: thread %s FAILED to acquire",
pj_thread_this()->obj_name));
}

Expand Down
20 changes: 12 additions & 8 deletions pjmedia/src/pjmedia/silencedet.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ PJ_DEF(pj_bool_t) pjmedia_silence_det_apply( pjmedia_silence_det *sd,
/* Voiced for long time (>recalc_on_voiced), current
* threshold seems to be too low.
*/
unsigned old = sd->threshold;
sd->threshold = (avg_recent_level + sd->threshold) >> 1;
TRACE_((THIS_FILE,"Re-adjust threshold (in talk burst)"
"to %d", sd->threshold));
if (sd->threshold != old)
TRACE_((THIS_FILE,"%s re-adjust threshold (in talk burst) to %d (was %d)",
sd->objname, sd->threshold, old));

sd->voiced_timer = 0;

Expand All @@ -248,8 +250,8 @@ PJ_DEF(pj_bool_t) pjmedia_silence_det_apply( pjmedia_silence_det *sd,
break;

case STATE_SILENCE:
TRACE_((THIS_FILE,"Starting talk burst (level=%d threshold=%d)",
level, sd->threshold));
TRACE_((THIS_FILE,"%s starting talk burst (level=%d threshold=%d)",
sd->objname, level, sd->threshold));

case STATE_START_SILENCE:
sd->state = STATE_VOICED;
Expand All @@ -271,9 +273,11 @@ PJ_DEF(pj_bool_t) pjmedia_silence_det_apply( pjmedia_silence_det *sd,
switch(sd->state) {
case STATE_SILENCE:
if (sd->silence_timer >= sd->recalc_on_silence) {
unsigned old = sd->threshold;
sd->threshold = avg_recent_level << 1;
TRACE_((THIS_FILE,"Re-adjust threshold (in silence)"
"to %d", sd->threshold));
if (sd->threshold != old)
TRACE_((THIS_FILE,"%s re-adjust threshold (in silence) to %d (was %d)",
sd->objname, sd->threshold, old));

sd->silence_timer = 0;

Expand All @@ -294,8 +298,8 @@ PJ_DEF(pj_bool_t) pjmedia_silence_det_apply( pjmedia_silence_det *sd,
if (sd->silence_timer >= sd->before_silence) {
sd->state = STATE_SILENCE;
sd->threshold = avg_recent_level << 1;
TRACE_((THIS_FILE,"Starting silence (level=%d "
"threshold=%d)", level, sd->threshold));
TRACE_((THIS_FILE,"%s starting silence (level=%d threshold=%d)",
sd->objname, level, sd->threshold));

/* Reset sig_level */
sd->sum_level = avg_recent_level;
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port,
pjmedia_rtp_hdr *rtp = (pjmedia_rtp_hdr*) channel->out_pkt;

rtp->m = 1;
PJ_LOG(5,(stream->port.info.name.ptr,"Start talksprut.."));
PJ_LOG(5,(stream->port.info.name.ptr,"Starting talksprut.."));
}

stream->is_streaming = PJ_TRUE;
Expand Down
4 changes: 2 additions & 2 deletions pjsip/src/pjsip/sip_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,8 @@ PJ_DEF(void) pjsip_dlg_dec_lock(pjsip_dialog *dlg)
{
PJ_ASSERT_ON_FAIL(dlg!=NULL, return);

PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_dec_lock(), sess_count=%d",
dlg->sess_count));
PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_dec_lock(), sess_count=%d, tsx_count=%d",
dlg->sess_count, dlg->tsx_count));

pj_assert(dlg->sess_count > 0);
--dlg->sess_count;
Expand Down
1 change: 1 addition & 0 deletions pjsip/src/pjsip/sip_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,7 @@ static void send_msg_callback( pjsip_send_state *send_state,
tsx_update_transport(tsx, send_state->cur_transport);

/* Update remote address. */
pj_assert(tdata->dest_info.cur_addr < _countof(tdata->dest_info.addr.entry));
tsx->addr_len = tdata->dest_info.addr.entry[tdata->dest_info.cur_addr].addr_len;
pj_memcpy(&tsx->addr,
&tdata->dest_info.addr.entry[tdata->dest_info.cur_addr].addr,
Expand Down
5 changes: 4 additions & 1 deletion pjsip/src/pjsua-lib/pjsua_aud.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ pj_status_t pjsua_aud_channel_update(pjsua_call_media *call_med,
PJ_UNUSED_ARG(local_sdp);
PJ_UNUSED_ARG(remote_sdp);

PJ_LOG(4,(THIS_FILE,"Audio channel update.."));
PJ_LOG(4,(THIS_FILE,"Audio channel update for index %d for call %d...",
call_med->idx, call_med->call->index));
pj_log_push_indent();

si->rtcp_sdes_bye_disabled = pjsua_var.media_cfg.no_rtcp_sdes_bye;
Expand Down Expand Up @@ -834,6 +835,8 @@ pj_status_t pjsua_aud_channel_update(pjsua_call_media *call_med,

on_return:
pj_log_pop_indent();
if (status != PJ_SUCCESS)
PJ_LOG(2, (THIS_FILE, "pjsua_aud_channel_update failed"));
return status;
}

Expand Down
2 changes: 1 addition & 1 deletion pjsip/src/pjsua-lib/pjsua_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ PJ_DEF(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *cfg)
pjsua_logging_config_dup(pjsua_var.pool, &pjsua_var.log_cfg, cfg);

/* Redirect log function to ours */
pj_log_set_log_func( &log_writer );
pj_log_set_log_func( (cfg && cfg->cb && !cfg->log_filename.slen) ? cfg->cb : &log_writer );

/* Set decor */
pj_log_set_decor(pjsua_var.log_cfg.decor);
Expand Down

0 comments on commit 9b528d0

Please sign in to comment.