[asterisk-dev] [Code Review] Pinequeue: Play queue prompts in the background - making call available to agent faster

Mark Michelson reviewboard at asterisk.org
Thu Apr 26 17:48:43 CDT 2012


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1887/#review6077
-----------------------------------------------------------


Unfortunately I've run out of time to be able to look at this today. I'll look at it more tomorrow. Here are some thoughts:

In app_queue.c, how does the channel get serviced once the generator is created? In the previous incarnation of play_file(), there was a call to ast_waitstream() that would service the channel (and thus play the file) to the channel. When you put a generator on the channel, something needs to call ast_waitfor() and ast_read() in order to have the generator generate data for it. In say.c, it looks like you call ast_autoservice_start() at one point in order to have the autoservice thread do this for you, but in app_queue, this does not happen.

The code is a bit disorganized. play_file() in app_queue should be broken up into at least two functions (one to play the file in the background and one to play and wait until the file completes plus more for other logical operations). In addition, the code be organized a bit better, so that, for instance, all operations that get done when now_playing == 0 are done in one block instead of having it done in disparate blocks. This will improve readability and make it a bit easier to review.

Some of the locations of data seems odd to me. For instance, the generator that has been added to app_queue.c seems like it should go into file.c instead, since it is potentially useful for other applications to use. This way you could add some sort of ast_streamfile_background() call that would allow you to play files in the background from any application. I already mention down below that the datastore information and callbacks can be moved into the global_datastores.h and global_datastores.c files.

This seems like a very nice addition since this is how most queuing systems work. The implementation details are a bit off though. I will look at this more tomorrow.


/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11124>

    I dont' understand this comment, and I don't understand why you would allow the memberdelay to occur without checking if autoservice succeeded in starting.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11123>

    This change seems unnecessary since res3 is not referenced anywhere else.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11146>

    Use PATH_MAX for file name sizes.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11145>

    Use PATH_MAX for the size of file names.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11121>

    Always have the channel locked when you call ast_channel_datastore_find()



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11142>

    Use ast_copy_string instead of strcpy.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11144>

    What is the point of these two lines?



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11143>

    Use ast_free()



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11147>

    Check the return of both functions to make sure that data was successfully allocated.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11151>

    When was autoservice started?



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11153>

    You don't need to output an error for a failed allocation since ast_calloc will do that for you.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11154>

    I don't understand why you save chan into the generator. The generator callbacks all take the channel as a parameter.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11127>

    Use ast_calloc and put a space after the comma. Check the result of ast_calloc to be sure that aqsi was properly allocated.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11128>

    Instead of doing this, just initialize datastore to NULL when it is declared.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11136>

    Check to be sure that ast_datastore_alloc() succeeds. Also, remove the parentheses after ast_prompt_list



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11129>

    Use ast_copy_string since strcpy is prone to buffer overflows. It may be that qe.moh and aqsi.moh are currently sized the same, but that guarantee may not always last.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11132>

    Always lock the channel when adding a datastore.



/trunk/apps/app_queue.c
<https://reviewboard.asterisk.org/r/1887/#comment11134>

    Please don't add initials to code comments. See the third bullet point here: https://wiki.asterisk.org/wiki/display/AST/Coding+Guidelines#CodingGuidelines-GeneralRules



/trunk/include/asterisk/channel.h
<https://reviewboard.asterisk.org/r/1887/#comment11139>

    One thing that may simplify your life here is to check out global_datastores.h and global_datastores.c. We store datastore information in those files if the datastore may be accessed by multiple source files. An example of one is the datastore that keeps track of all the interfaces that have been dialed by a channel to ensure that the channel does not get caught in a forwarding loop.
    
    Using those files, you would not have to spread out the datastore information between channel.h, file.h, and file.c



/trunk/include/asterisk/channel.h
<https://reviewboard.asterisk.org/r/1887/#comment11140>

    Use doxygen-style comments here.



/trunk/main/say.c
<https://reviewboard.asterisk.org/r/1887/#comment11156>

    Invert this logic so that you can return early if !aqsi and then you can reduce the indentation of the majority of this function. You can actually give the same treatment to the if block above where you call ast_channel_datastore_find()


- Mark


On April 26, 2012, 9:42 a.m., Olle E Johansson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1887/
> -----------------------------------------------------------
> 
> (Updated April 26, 2012, 9:42 a.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> Today, when a prompt is being played to a call waiting in the queue and an agent becomes available, the agent will not get the call until the prompt is finished. Both customer and agent is kept waiting.
> 
> With this rather big piece of code, we attach a generator to play prompts. The generator can, like all generators, be stopped at any time so that the agent (queue member) can get the call immediately.
> 
> The generator is now placed in app_queue, but could propably be moved somewhere else. It also changes functionality in main/say.c in order to be able to place those prompts in the same prompt queue for background processing. The same generator could be used to sevice conference bridges and maybe be added as a dialplan function at some point for background playlists.
> 
> 
> This addresses bug 19795.
>     https://issues.asterisk.org/jira/browse/19795
> 
> 
> Diffs
> -----
> 
>   /trunk/apps/app_queue.c 364000 
>   /trunk/configs/queues.conf.sample 364000 
>   /trunk/include/asterisk/channel.h 364000 
>   /trunk/include/asterisk/file.h 364000 
>   /trunk/main/asterisk.dynamics 364000 
>   /trunk/main/file.c 364000 
>   /trunk/main/say.c 364000 
> 
> Diff: https://reviewboard.asterisk.org/r/1887/diff
> 
> 
> Testing
> -------
> 
> Quite a lot of testing in our environment during the rather long time we've been testing this. Customer is happy.
> 
> 
> There was some complaints from a bowl of petunias, which made me a bit surprised.
> 
> 
> Thanks,
> 
> Olle E
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120426/28b8cd45/attachment-0001.htm>


More information about the asterisk-dev mailing list