[asterisk-dev] How to create a slinear silent frame?
Atis Lezdins
atis at iq-labs.net
Mon May 18 06:16:36 CDT 2009
On Mon, May 18, 2009 at 12:36 PM, Holger Wirtz <wirtz at dfn.de> wrote:
> 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?
>
While on topic, i'm also interested how to create a beep frame. There
are some frequency generations in indications.c, but i guess i'll need
just a frame :)
Regards,
Atis
--
Atis Lezdins,
VoIP Project Manager / Developer,
IQ Labs Inc,
atis at iq-labs.net
Skype: atis.lezdins
Cell Phone: +371 28806004
Cell Phone: +1 800 7300689
Work phone: +1 800 7502835
More information about the asterisk-dev
mailing list