[pjsip] How to do a periodic check?

Benny Prijono bennylp at pjsip.org
Tue Apr 1 18:56:58 EDT 2008


On Tue, Apr 1, 2008 at 3:02 PM, Markus Vechiorno <finalpfc at hotmail.com> wrote:
>
>  Benny yesterday you told me:
>
>  > You can use pjsip_endpt_schedule_timer() to schedule a timer.
>
>  I has been trying to understand this function and how to use it bu I can´t
> make ir work fine. I use:
>
>  pjsip_endpt_schedule_timer (pjsua_get_pjsip_endpt(),
>          my_timer_entry,
>          my_timer);
>
>  - The first argument of this function is the pjsip endpoint. So, I think
> "pjsua_get_pjsip_endpt()" is right here. Isn't it?

Yes.

>  - The second argument must be a timer_entry pointer, so I define:
>                    struct pj_timer_entry* my_timer_entry;

I assume my_timer_entry will be alloc-ed first.

>                    my_timer_entry->id = 1;
>                   my_timer_entry->cb = &funcion_aux;
>                   my_timer_entry->_timer_value = my_timer_2; //I don't know
> the objective of this timer.

Use pj_timer_entry_init() to initialize your timer entry, it's much
cleaner and it'll be forward compatible with future PJSIP releases if
there is a change on this area. And your timer entry must be valid
throughout the duration of the timer.

>    Where :
>                    struct pj_time_val my_timer_2;
>                    my_timer_2.sec = 5; my_timer_2.msec=0;
>
>                    static void funcion_aux( pj_timer_heap_t *timer_heap,
>                          struct pj_timer_entry *entry)
>                        {
>                         PJ_UNUSED_ARG(timer_heap);
>                         PJ_UNUSED_ARG(entry);
>                         puts("MINE ----> Periodic call");
>                        }
>    Is this right for the second argument?

I think so. But PJLIB's timer is not periodic, so you'd have to
re-schedule the entry again in the callback if you want to make a
periodic timer.

>  - The third argument must be a time_val pointer, so I use:
>                    struct pj_time_val* my_timer;
>                   my_timer->sec=5; my_timer->msec=0;

Assuming my_timer is alloc-ed first, that's fine. But normally we can
just use a local variable for the pj_time_val.

>  I don't know why it doesn't work. I think this code should make my
> application to show the message "MINE---> Periodic call" every 5 seconds but
> it doesn't do it.
>
>  Where am I wrong?

If the snippets above are the whole code, it looks like few things are
missing (the alloc() stuff for the pointers).

Cheers
 Benny


>  Thanks a lot, and sorry for the large mail.
>
>
>
>
> > Date: Mon, 31 Mar 2008 10:27:18 +0100
> > From: bennylp at pjsip.org
> > To: pjsip at lists.pjsip.org
> > Subject: Re: [pjsip] How to do a periodic check?
> >
> > On Mon, Mar 31, 2008 at 10:01 AM, Markus Vechiorno <finalpfc at hotmail.com>
> wrote:
> > > Hi,
> > >
> > > I want to make a check of some parameters every x seconds
> (periodically).
> > > Is there a way to call to a function periodically?
> > > I can use the functions implemented in "dq" in pjsua because what I need
> is
> > > to check the packet loss rate.
> > >
> > > I saw smth about pjmedia clock, but I need to know how to control it.
> > >
> > > For example, if I want to call pjsua_call_dump ecery 2 seconds what
> could
> > > be the way?
> >
> > You can use pjsip_endpt_schedule_timer() to schedule a timer. The
> > pjmedia clock probably is too heavy for this since it creates a worker
> > thread with real-time priority to wait for the timer (although you can
> > disable the priority boost). But you can use that, just set
> > samples_per_frame to N*clock_rate if you want the callback to be
> > called once every N seconds.
> >
> > Cheers
> > Benny
> >
>
>
> ________________________________
> Sigue los principales acontecimientos deportivos en directo. MSN Motor
> _______________________________________________
>  Visit our blog: http://blog.pjsip.org
>
>  pjsip mailing list
>  pjsip at lists.pjsip.org
>  http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
>




More information about the pjsip mailing list