[asterisk-dev] How to create a slinear silent frame?

Holger Wirtz wirtz at dfn.de
Mon May 18 04:36:18 CDT 2009


Hi,

I tried to create an empty frame (with data set to 0000000...) but I get
 crashes when I try to send this frames with ast_write() to a channel.

I created the frame like this:

--- cut here ---
struct ast_frame* frame_create_silent_voice(int offset,int samples)
{
        struct ast_frame* f=NULL;
        short *data=NULL;
        int i=0;

        if((f=calloc(1,sizeof(struct ast_frame)))==NULL)
        {
                ast_log(LOG_ERROR,"Unable to allocate memory for slinear
frame\n");
                return(NULL);
        }

        f->frametype=AST_FRAME_VOICE;
        f->subclass=AST_FORMAT_SLINEAR;
        f->mallocd=AST_MALLOCD_HDR|AST_MALLOCD_DATA;
        f->samples=samples;
        f->datalen=samples*sizeof(short);
        f->offset=offset;
        f->src=NULL;
        f->data=NULL;

        if((data=(short *)calloc(1,sizeof(short)*samples)+offset)==NULL)
        {
                ast_log(LOG_ERROR,"Unable to create array for frame
data\n");
                if(f!=NULL)
                {
                        free(f);
                        f=NULL;
                }
        }
        else
        {
                f->data=data;
        }

        return(f);
}
--- cut here ---

What am I doing wrong, can anyone help?

Thanks, Holger
-- 
#####  #### ##  ##   Holger Wirtz         Phone : (+49 30) 884299-40
##  ## ##   ### ##   DFN-Verein           Fax   : (+49 30) 884299-70
##  ## #### ######   Alexanderplatz 1     E-Mail: wirtz at dfn.de
##  ## ##   ## ###   10178 Berlin
#####  ##   ##  ##   GERMANY              WWW   : http://www.dfn.de
GPG-Fingerprint: ABFA 1F51 DD8D 503C 85DC  0C51 E961 79E2 6685 9BCF



More information about the asterisk-dev mailing list