[asterisk-dev] How to create a slinear silent frame? SOLVED
Holger Wirtz
wirtz at dfn.de
Tue May 19 00:39:52 CDT 2009
Dmitry, Russell,
thanks for your help! I fixed the problem with not using "offset" but
can anyone tell me when offset is beeing used?
Another question: Is there a documentation outside the sources where I
can get some more information about channels and frames?
Regards, Holger
Dmitry Andrianov wrote:
> 2 Holger Wirtz:
>
> I believe you should not use calloc/free to manipulate frames.
> Also, I have no idea why you are trying to manipulate "offset" frame field. This is probably the thing which makes your code crash.
>
> create buffer and zero it once.
> ..
>
>
> struct ast_frame frame = {
> .frametype = AST_FRAME_VOICE,
> .subclass = AST_FORMAT_SLINEAR,
> .data = buffer,
> .datalen = sizeof(buffer),
> .samples = samples,
> .src = __FUNCTION__,
> };
>
> return ast_frdup(&frame);
>
> should work.
>
>
> 2 Atis Lezdins:
> one frame (20ms) is not enough to produce any beep. You will need many frames for the beep to be heard.
> In any case, apps/app_morsecode.c should be good start.
>
> Regards,
> Dmitry Andrianov
>
> -----Original Message-----
> From: asterisk-dev-bounces at lists.digium.com [mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Atis Lezdins
> Sent: Monday, May 18, 2009 3:17 PM
> To: Asterisk Developers Mailing List
> Subject: Re: [asterisk-dev] How to create a slinear silent frame?
>
> 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
>
--
##### #### ## ## 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