wav file end does not stop playback from port (w/ patch)

JJ
Jens Jorgensen
Thu, Sep 17, 2009 4:20 AM

Hello,

I've been working on a little script. I'm trying to get pjsip to make a
call to a VOIP system (Cisco UC500) and play a short wav file (an
announcement). Since I'm a big python fan I'm trying to get this work
using the python pjsua.py module. I've run across a couple of problems.
Ultimately, I want to get a callback when the wav finishes playing so I
can end the call. In order to do this, I need to know when the wav file
playback is done. I could of course hack this by figuring out how many
seconds it is in advance, and then just ending the call based on a
timer. But since pjlib already has a hook to get a callback, why not use
it! Of course the first hurdle is that pjsua doesn't directly export
this functionality. I've got a small hack working that let's me stash a
void* associated with the playback id to help me do this (I need this
not for the C-level code, but for the python callback object). However,
things are still not quite right. I get the callback, but then I keep
getting the callback repeatedly! The documentation says that if the
callback returns something other than PJ_SUCCESS or if
PJMEDIA_FILE_NO_LOOP is not set then playback will finish. Well, I've
been doing both of those things and what I see happening is I keep
getting the callback and on the handset where I'm receiving the call I
here weird noises (probably just a repeating clip from the last chunk of
audio data read?). I've arranged for the build to include debug symbols
an run it in the debugger. And what do I find:

    if (status != PJ_SUCCESS) {
    /* bennylp: why do we need this????
     * Also see comments on similar issue with write_port().
    PJ_LOG(4,(THIS_FILE, "Port %.*s get_frame() returned %d. "
                 "Port is now disabled",
                 (int)conf_port->name.slen,
                 conf_port->name.ptr,
                 status));
    conf_port->rx_setting = PJMEDIA_PORT_DISABLE;
     */
    continue;
    }

Well, whoever commented this code out, I think you have your answer. :-)

I still get some funny sound at the end, but at least my callback when
the file end is reached is called once and only once. I work on
debugging that problem next.

May I propose the attached change?

--
Jens B. Jorgensen
jbj1@ultraemail.net

Hello, I've been working on a little script. I'm trying to get pjsip to make a call to a VOIP system (Cisco UC500) and play a short wav file (an announcement). Since I'm a big python fan I'm trying to get this work using the python pjsua.py module. I've run across a couple of problems. Ultimately, I want to get a callback when the wav finishes playing so I can end the call. In order to do this, I need to know when the wav file playback is done. I could of course hack this by figuring out how many seconds it is in advance, and then just ending the call based on a timer. But since pjlib already has a hook to get a callback, why not use it! Of course the first hurdle is that pjsua doesn't directly export this functionality. I've got a small hack working that let's me stash a void* associated with the playback id to help me do this (I need this not for the C-level code, but for the python callback object). However, things are still not quite right. I get the callback, but then I keep getting the callback repeatedly! The documentation says that if the callback returns something other than PJ_SUCCESS or if PJMEDIA_FILE_NO_LOOP is not set then playback will finish. Well, I've been doing both of those things and what I see happening is I keep getting the callback and on the handset where I'm receiving the call I here weird noises (probably just a repeating clip from the last chunk of audio data read?). I've arranged for the build to include debug symbols an run it in the debugger. And what do I find: if (status != PJ_SUCCESS) { /* bennylp: why do we need this???? * Also see comments on similar issue with write_port(). PJ_LOG(4,(THIS_FILE, "Port %.*s get_frame() returned %d. " "Port is now disabled", (int)conf_port->name.slen, conf_port->name.ptr, status)); conf_port->rx_setting = PJMEDIA_PORT_DISABLE; */ continue; } Well, whoever commented this code out, I think you have your answer. :-) I still get some funny sound at the end, but at least my callback when the file end is reached is called once and only once. I work on debugging that problem next. May I propose the attached change? -- Jens B. Jorgensen jbj1@ultraemail.net