void ms_qdispatcher_init(MSQdispatcher *obj) { ms_filter_init(MS_FILTER(obj)); MS_FILTER(obj)->inqueues=obj->q_inputs; MS_FILTER(obj)->outqueues=obj->q_outputs; memset(obj->q_inputs,0,sizeof(MSQueue*)*MS_QDISPATCHER_MAX_INPUTS); memset(obj->q_outputs,0,sizeof(MSQueue*)*MS_QDISPATCHER_MAX_OUTPUTS); }
/* FOR INTERNAL USE*/ void ms_MULAWdecoder_init(MSMULAWDecoder *r) { ms_filter_init(MS_FILTER(r)); MS_FILTER(r)->infifos=r->f_inputs; MS_FILTER(r)->outfifos=r->f_outputs; MS_FILTER(r)->r_mingran=MULAW_DECODER_RMAXGRAN; memset(r->f_inputs,0,sizeof(MSFifo*)*MSMULAWDECODER_MAX_INPUTS); memset(r->f_outputs,0,sizeof(MSFifo*)*MSMULAWDECODER_MAX_INPUTS); }
/** * ms_ring_player_new: * @name: The path to the 16-bit 8khz raw file to be played as a ring. * @seconds: The number of seconds that separates two rings. * * Allocates a new MSRingPlayer object. * * * Returns: a pointer the the object, NULL if name could not be open. */ MSFilter * ms_ring_player_new(char *name, gint seconds) { MSRingPlayer *r; int fd=-1; if ((name!=NULL) && (strlen(name)!=0)) { fd=open(name,O_RDONLY); if (fd<0) { g_warning("ms_ring_player_new: failed to open %s.\n",name); return NULL; } }else { g_warning("ms_ring_player_new: Bad file name"); return NULL; } r=g_new(MSRingPlayer,1); ms_ring_player_init(r); if (ms_ring_player_class==NULL) { ms_ring_player_class=g_new(MSRingPlayerClass,1); ms_ring_player_class_init(ms_ring_player_class); } MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_ring_player_class); r->fd=fd; r->silence=seconds; r->freq=8000; if (strstr(name,".wav")!=NULL){ wave_header_t header; int freq,freq2; /* read the header */ read(fd,&header,sizeof(wave_header_t)); freq=wave_header_get_rate(&header); if ((freq2=freq_is_supported(freq))>0){ r->freq=freq2; }else { g_warning("Unsupported sampling rate %i",freq); r->freq=8000; } r->channel=wave_header_get_channel(&header); lseek(fd,WAVE_HEADER_OFFSET,SEEK_SET); #ifdef WORDS_BIGENDIAN r->need_swap=1; #else r->need_swap=0; #endif } ms_ring_player_set_property(r, MS_FILTER_PROPERTY_FREQ,&r->freq); r->state=PLAY_RING; return(MS_FILTER(r)); }
void ms_speex_dec_init(MSSpeexDec *obj) { ms_filter_init(MS_FILTER(obj)); obj->initialized=0; MS_FILTER(obj)->outfifos=obj->outf; MS_FILTER(obj)->inqueues=obj->inq; obj->outf[0]=NULL; obj->inq[0]=NULL; obj->frequency=8000; /*default value */ }
/* FOR INTERNAL USE*/ void ms_ring_player_init(MSRingPlayer *r) { ms_filter_init(MS_FILTER(r)); MS_FILTER(r)->outfifos=r->foutputs; MS_FILTER(r)->outqueues=r->qoutputs; memset(r->foutputs,0,sizeof(MSFifo*)*MS_RING_PLAYER_MAX_OUTPUTS); memset(r->qoutputs,0,sizeof(MSQueue*)*MS_RING_PLAYER_MAX_OUTPUTS); r->fd=-1; r->current_pos=0; r->need_swap=0; r->sync=NULL; }
MSFilter * ms_qdispatcher_new(void) { MSQdispatcher *obj; obj=g_malloc(sizeof(MSQdispatcher)); if (ms_qdispatcher_class==NULL){ ms_qdispatcher_class=g_malloc0(sizeof(MSQdispatcherClass)); ms_qdispatcher_class_init(ms_qdispatcher_class); } MS_FILTER(obj)->klass=MS_FILTER_CLASS(ms_qdispatcher_class); ms_qdispatcher_init(obj); return MS_FILTER(obj); }
/* FOR INTERNAL USE*/ void ms_read_init(MSRead *r) { ms_filter_init(MS_FILTER(r)); MS_FILTER(r)->outfifos=r->foutputs; MS_FILTER(r)->outqueues=r->qoutputs; memset(r->foutputs,0,sizeof(MSFifo*)*MSREAD_MAX_OUTPUTS); memset(r->qoutputs,0,sizeof(MSQueue*)*MSREAD_MAX_OUTPUTS); r->fd=-1; r->gran=320; r->state=MS_READ_STATE_STOPPED; r->need_swap=0; r->rate=8000; }
MSFilter * ms_speex_dec_new() { MSSpeexDec *obj=g_new(MSSpeexDec,1); if (ms_speex_dec_class==NULL){ ms_speex_dec_class=g_new(MSSpeexDecClass,1); ms_speex_dec_class_init(ms_speex_dec_class); } MS_FILTER(obj)->klass=MS_FILTER_CLASS(ms_speex_dec_class); ms_speex_dec_init(obj); return MS_FILTER(obj); }
MSFilter * ms_ilbc_encoder_new(void) { MSILBCEncoder *r; r=g_new(MSILBCEncoder,1); ms_ilbc_encoder_init(r); if (ms_ilbc_encoder_class==NULL) { ms_ilbc_encoder_class=g_new(MSILBCEncoderClass,1); ms_ilbc_encoder_class_init(ms_ilbc_encoder_class); } MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_ilbc_encoder_class); return(MS_FILTER(r)); }
void ms_rtp_send_init(MSRtpSend *r) { ms_filter_init(MS_FILTER(r)); MS_FILTER(r)->infifos=r->f_inputs; MS_FILTER(r)->inqueues=r->q_inputs; MS_FILTER(r)->r_mingran=MSRTPSEND_DEF_GRAN; memset(r->f_inputs,0,sizeof(MSFifo*)*MSRTPSEND_MAX_INPUTS); memset(r->q_inputs,0,sizeof(MSFifo*)*MSRTPSEND_MAX_INPUTS); r->rtpsession=NULL; r->ts=0; r->ts_inc=0; r->flags=0; r->delay=0; }
/* FOR INTERNAL USE*/ void ms_ilbc_encoder_init(MSILBCEncoder *r) { /* default bitrate */ r->bitrate = 15200; r->ms_per_frame = 20; r->samples_per_frame = BLOCKL_20MS; r->bytes_per_compressed_frame = NO_OF_BYTES_20MS; ms_filter_init(MS_FILTER(r)); MS_FILTER(r)->infifos=r->f_inputs; MS_FILTER(r)->outqueues=r->q_outputs; MS_FILTER(r)->r_mingran= (r->samples_per_frame * 2); memset(r->f_inputs,0,sizeof(MSFifo*)*MSILBCENCODER_MAX_INPUTS); memset(r->q_outputs,0,sizeof(MSFifo*)*MSILBCENCODER_MAX_INPUTS); }
MSFilter * ms_rtp_send_new(void) { MSRtpSend *r; r=g_new(MSRtpSend,1); if (ms_rtp_send_class==NULL) { ms_rtp_send_class=g_new(MSRtpSendClass,1); ms_rtp_send_class_init(ms_rtp_send_class); } MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_rtp_send_class); ms_rtp_send_init(r); return(MS_FILTER(r)); }
void ms_read_process(MSRead *r) { MSFifo *f; MSQueue *q; MSMessage *msg=NULL; int err; gint gran=r->gran; void *p; f=r->foutputs[0]; if ((f!=NULL) && (r->state==MS_READ_STATE_STARTED)) { ms_fifo_get_write_ptr(f,gran,&p); if (p!=NULL) { err=read(r->fd,p,gran); if (err<0) { /* temp: */ g_warning("ms_read_process: failed to read: %s.\n",strerror(errno)); } else if (err<gran){ ms_trace("ms_read_process: end of file."); ms_filter_notify_event(MS_FILTER(r),MS_READ_EVENT_EOF,NULL); r->state=MS_READ_STATE_STOPPED; close(r->fd); r->fd=-1; } if (r->need_swap) swap_buffer(p,gran); } } /* process output queues*/ q=r->qoutputs[0]; if ((q!=NULL) && (r->fd>0)) { msg=ms_message_new(r->gran); err=read(r->fd,msg->data,r->gran); if (err>0){ msg->size=err; ms_queue_put(q,msg); if (r->need_swap) swap_buffer(msg->data,r->gran); }else{ ms_filter_notify_event(MS_FILTER(r),MS_READ_EVENT_EOF,NULL); ms_trace("End of file reached."); r->state=MS_READ_STATE_STOPPED; } } }
MSFilter * ms_read_new(char *name) { MSRead *r; int fd=-1; r=g_new(MSRead,1); ms_read_init(r); if (ms_read_class==NULL) { ms_read_class=g_new(MSReadClass,1); ms_read_class_init(ms_read_class); } MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_read_class); r->fd=-1; if (name!=NULL) ms_read_open(r,name); return(MS_FILTER(r)); }
void ms_rtp_send_process(MSRtpSend *r) { MSFifo *fi; MSQueue *qi; MSSync *sync= r->sync; int gran=ms_sync_get_samples_per_tick(sync); guint32 ts; void *s; guint skip; guint32 synctime=sync->time; g_return_if_fail(gran>0); if (r->rtpsession==NULL) return; ms_filter_lock(MS_FILTER(r)); skip=r->delay!=0; if (skip) r->delay--; /* process output fifo and output queue*/ fi=r->f_inputs[0]; if (fi!=NULL) { ts=get_new_timestamp(r,synctime); /* try to read r->packet_size bytes and send them in a rtp packet*/ ms_fifo_get_read_ptr(fi,r->packet_size,&s); if (!skip){ rtp_session_send_with_ts(r->rtpsession,s,r->packet_size,ts); ms_trace("len=%i, ts=%i ",r->packet_size,ts); } } qi=r->q_inputs[0]; if (qi!=NULL) { MSMessage *msg; /* read a MSMessage and send it through the network*/ while ( (msg=ms_queue_get(qi))!=NULL){ ts=get_new_timestamp(r,synctime); if (!skip) { /*g_message("Sending packet with ts=%u",ts);*/ rtp_session_send_with_ts(r->rtpsession,msg->data,msg->size,ts); } ms_message_destroy(msg); } } ms_filter_unlock(MS_FILTER(r)); }
void ms_rtp_send_set_timing(MSRtpSend *r, guint32 ts_inc, gint payload_size) { r->ts_inc=ts_inc; r->packet_size=payload_size; if (r->ts_inc!=0) r->flags|=RTPSEND_CONFIGURED; else r->flags&=~RTPSEND_CONFIGURED; MS_FILTER(r)->r_mingran=payload_size; /*g_message("ms_rtp_send_set_timing: ts_inc=%i",ts_inc);*/ }
gint ms_rtp_send_dtmf(MSRtpSend *r, gchar dtmf) { gint res; if (r->rtpsession==NULL) return -1; if (rtp_session_telephone_events_supported(r->rtpsession)==-1){ g_warning("ERROR : telephone events not supported.\n"); return -1; } ms_filter_lock(MS_FILTER(r)); g_message("Sending DTMF."); res=rtp_session_send_dtmf(r->rtpsession, dtmf, r->ts); if (res==0){ /* //r->ts+=r->ts_inc; */ r->delay+=2; }else g_warning("Could not send dtmf."); ms_filter_unlock(MS_FILTER(r)); return res; }
void ms_ring_player_process(MSRingPlayer *r) { MSFifo *f; gint err; gint processed=0; gint gran=r->gran; char *p; g_return_if_fail(gran>0); /* process output fifos*/ f=r->foutputs[0]; ms_fifo_get_write_ptr(f,gran,(void**)&p); g_return_if_fail(p!=NULL); for (processed=0;processed<gran;){ switch(r->state){ case PLAY_RING: err=read(r->fd,&p[processed],gran-processed); if (err<0) { memset(&p[processed],0,gran-processed); processed=gran; g_warning("ms_ring_player_process: failed to read: %s.\n",strerror(errno)); return; } else if (err<gran) {/* end of file */ r->current_pos=r->silence_bytes; lseek(r->fd,WAVE_HEADER_OFFSET,SEEK_SET); r->state=PLAY_SILENCE; ms_filter_notify_event(MS_FILTER(r),MS_RING_PLAYER_END_OF_RING_EVENT,NULL); } if (r->need_swap) swap_buffer(&p[processed],err); processed+=err; break; case PLAY_SILENCE: err=gran-processed; if (r->current_pos>err){ memset(&p[processed],0,err); r->current_pos-=gran; processed=gran; }else{ memset(&p[processed],0,r->current_pos); processed+=r->current_pos; r->state=PLAY_RING; } break; } } }
void ms_rtp_send_setup(MSRtpSend *r, MSSync *sync) { MSFilter *codec; MSCodecInfo *info; r->sync=sync; codec=ms_filter_search_upstream_by_type(MS_FILTER(r),MS_FILTER_AUDIO_CODEC); if (codec==NULL) codec=ms_filter_search_upstream_by_type(MS_FILTER(r),MS_FILTER_VIDEO_CODEC); if (codec==NULL){ g_warning("ms_rtp_send_setup: could not find upstream codec."); return; } info=MS_CODEC_INFO(codec->klass->info); if (info->info.type==MS_FILTER_AUDIO_CODEC){ int ts_inc=info->fr_size/2; int psize=info->dt_size; if (ts_inc==0){ /* dont'use the normal frame size: this is a variable frame size codec */ /* use the MS_FILTER(codec)->r_mingran */ ts_inc=MS_FILTER(codec)->r_mingran/2; psize=0; } ms_rtp_send_set_timing(r,ts_inc,psize); } }
void ms_ilbc_encoder_setup(MSILBCEncoder *r) { MSFilterClass *klass = NULL; switch (r->ms_per_frame) { case 20: r->samples_per_frame = BLOCKL_20MS; r->bytes_per_compressed_frame = NO_OF_BYTES_20MS; break; case 30: r->samples_per_frame = BLOCKL_30MS; r->bytes_per_compressed_frame = NO_OF_BYTES_30MS; break; default: g_error("Bad bitrate value (%i) for ilbc encoder!", r->ms_per_frame); break; } MS_FILTER(r)->r_mingran= (r->samples_per_frame * 2); g_message("Using ilbc encoder with %i ms frames mode.",r->ms_per_frame); initEncode(&r->ilbc_enc, r->ms_per_frame /* ms frames */); }