Example #1
0
static void _sender_process(MSFilter * f)
{
	SenderData *d = (SenderData *) f->data;
	RtpSession *s = d->session;

	mblk_t *im;
	uint32_t timestamp;

	
	if (d->relay_session_id_size>0 && 
		( (f->ticker->time-d->last_rsi_time)>5000 || d->last_rsi_time==0) ) {
		ms_message("relay session id sent in RTCP APP");
		rtp_session_send_rtcp_APP(s,0,"RSID",(const uint8_t *)d->relay_session_id,d->relay_session_id_size);
		d->last_rsi_time=f->ticker->time;
	}

	ms_filter_lock(f);
	im = ms_queue_get(f->inputs[0]);
	do {
		mblk_t *header;

		timestamp = get_cur_timestamp(f, im);
		
		if (d->dtmf != 0 && !d->skip) {
			ms_debug("prepare to send RFC2833 dtmf.");
			d->skip_until = timestamp + d->dtmf_duration;
			d->dtmf_ts_cur=timestamp;
			d->skip = TRUE;
		}
		if (d->skip) {
			uint32_t origin_ts=d->skip_until-d->dtmf_duration;
			if (RTP_TIMESTAMP_IS_NEWER_THAN(timestamp,d->dtmf_ts_cur)){
				ms_debug("Sending RFC2833 packet, start_timestamp=%u, dtmf_ts_cur=%u",origin_ts,d->dtmf_ts_cur);
				send_dtmf(f, origin_ts);
			}
		}
		if (im){
			if (d->skip == FALSE && d->mute_mic==FALSE){
				header = rtp_session_create_packet(s, 12, NULL, 0);
				rtp_set_markbit(header, mblk_get_marker_info(im));
				header->b_cont = im;
				rtp_session_sendm_with_ts(s, header, timestamp);
			}else{
				freemsg(im);
			}
		}
	}while ((im = ms_queue_get(f->inputs[0])) != NULL);

	if (d->last_sent_time == -1) {
		if ((d->last_stun_sent_time == -1) || ((f->ticker->time - d->last_stun_sent_time) >= 500)) {
			d->last_stun_sent_time = f->ticker->time;
		}
		if (d->last_stun_sent_time == f->ticker->time) {
			send_stun_packet(s);
		}
	}

	ms_filter_unlock(f);
}
Example #2
0
static void resample_process_ms2(MSFilter *obj) {
    ResampleData *dt=(ResampleData*)obj->data;
    mblk_t *m;

    if (dt->output_rate==dt->input_rate) {
        while((m=ms_queue_get(obj->inputs[0]))!=NULL) {
            ms_queue_put(obj->outputs[0],m);
        }
        return;
    }
    ms_filter_lock(obj);
    if (dt->handle!=NULL) {
        unsigned int inrate=0, outrate=0;
        speex_resampler_get_rate(dt->handle,&inrate,&outrate);
        if (inrate!=dt->input_rate || outrate!=dt->output_rate) {
            speex_resampler_destroy(dt->handle);
            dt->handle=0;
        }
    }
    if (dt->handle==NULL) {
        int err=0;
        dt->handle=speex_resampler_init(dt->nchannels, dt->input_rate, dt->output_rate, SPEEX_RESAMPLER_QUALITY_VOIP, &err);
    }


    while((m=ms_queue_get(obj->inputs[0]))!=NULL) {
        unsigned int inlen=(m->b_wptr-m->b_rptr)/(2*dt->nchannels);
        unsigned int outlen=((inlen*dt->output_rate)/dt->input_rate)+1;
        unsigned int inlen_orig=inlen;
        mblk_t *om=allocb(outlen*2*dt->nchannels,0);
        if (dt->nchannels==1) {
            speex_resampler_process_int(dt->handle,
                                        0,
                                        (int16_t*)m->b_rptr,
                                        &inlen,
                                        (int16_t*)om->b_wptr,
                                        &outlen);
        } else {
            speex_resampler_process_interleaved_int(dt->handle,
                                                    (int16_t*)m->b_rptr,
                                                    &inlen,
                                                    (int16_t*)om->b_wptr,
                                                    &outlen);
        }
        if (inlen_orig!=inlen) {
            ms_error("Bug in resampler ! only %u samples consumed instead of %u, out=%u",
                     inlen,inlen_orig,outlen);
        }
        om->b_wptr+=outlen*2*dt->nchannels;
        mblk_set_timestamp_info(om,dt->ts);
        dt->ts+=outlen;
        ms_queue_put(obj->outputs[0],om);
        freemsg(m);
    }
    ms_filter_unlock(obj);
}
static void detector_process(MSFilter *f) {
    DetectorState *s=(DetectorState *)f->data;
    mblk_t *m;

    while ((m=ms_queue_get(f->inputs[0]))!=NULL) {
        ms_queue_put(f->outputs[0],m);
        if (s->tone_def->frequency!=0) {
            ms_bufferizer_put(s->buf,dupmsg(m));
        }
    }
    if (s->tone_def->frequency!=0) {
        uint8_t *buf=_alloca(s->framesize);

        while(ms_bufferizer_read(s->buf,buf,s->framesize)!=0) {
            float en=compute_energy((int16_t*)buf,s->framesize/2);
            if (en>energy_min) {
                float freq_en=goertzel_state_run(&s->tone_gs,(int16_t*)buf,s->framesize/2,en);
                if (freq_en>=s->tone_def->min_amplitude) {
                    if (s->dur==0) s->starttime=f->ticker->time;
                    s->dur+=s->frame_ms;
                    if (s->dur>s->tone_def->min_duration && !s->event_sent) {
                        MSToneDetectorEvent event;

                        strncpy(event.tone_name,s->tone_def->tone_name,sizeof(event.tone_name));
                        event.tone_start_time=s->starttime;
                        ms_filter_notify(f,MS_TONE_DETECTOR_EVENT,&event);
                        s->event_sent=TRUE;
                    }
                } else end_tone(s);
            } else end_tone(s);
        }
    }
}
Example #4
0
static void rec_process(MSFilter *f){
	RecState *s=(RecState*)f->data;
	mblk_t *m;
	int err;
	while((m=ms_queue_get(f->inputs[0]))!=NULL){
		mblk_t *it=m;
		ms_mutex_lock(&f->lock);
		if (s->state==Started){
			while(it!=NULL){
				int len=it->b_wptr-it->b_rptr;
			    DWORD byte_written=0;
				if ((err=WriteFile(s->fd,it->b_rptr,len, &byte_written, NULL))!=len){
					if (err<0)
					{
#if !defined(_WIN32_WCE)
						ms_warning("MSFileRec: fail to write %i bytes: %s",len,strerror(errno));
#else
						ms_warning("MSFileRec: fail to write %i bytes: %i",len,WSAGetLastError());
#endif
					}
				}
				it=it->b_cont;
				s->size+=len;
			}
		}
		ms_mutex_unlock(&f->lock);
		freemsg(m);
	}
}
Example #5
0
static void oss_write_process(MSFilter *f){
	MSSndCard *card=(MSSndCard*)f->data;
	mblk_t *m;
	while((m=ms_queue_get(f->inputs[0]))!=NULL){
		oss_put(card,m);
	}
}
Example #6
0
void alsa_write_process(MSFilter *obj){
	AlsaWriteData *ad=(AlsaWriteData*)obj->data;
	mblk_t *im=NULL;
	int size;
	int samples;
	int err;
	if (ad->handle==NULL && ad->pcmdev!=NULL){
		ad->handle=alsa_open_w(ad->pcmdev,16,ad->nchannels==2,ad->rate);
#ifdef EPIPE_BUGFIX
		alsa_fill_w (ad->pcmdev);
#endif
	}
	if (ad->handle==NULL) {
		ms_queue_flush(obj->inputs[0]);
		return;
	}
	while ((im=ms_queue_get(obj->inputs[0]))!=NULL){
		while((size=im->b_wptr-im->b_rptr)>0){
			samples=size/(2*ad->nchannels);
			err=alsa_write(ad->handle,im->b_rptr,samples);
			if (err>0) {
				im->b_rptr+=err*(2*ad->nchannels);
			}
			else break;
		}
		freemsg(im);
	}
}
Example #7
0
static void pixconv_process(MSFilter *f){
	mblk_t *im,*om=NULL;
	PixConvState *s=(PixConvState*)f->data;

	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		if (s->in_fmt==s->out_fmt){
			om=im;
		}else{
			MSPicture inbuf;
			if (ms_picture_init_from_mblk_with_size(&inbuf,im,s->in_fmt,s->size.width,s->size.height)==0){
				om=pixconv_alloc_mblk(s);
				if (s->scaler==NULL){
					s->scaler=ms_scaler_create_context(inbuf.w, inbuf.h,
						s->in_fmt,inbuf.w,inbuf.h,
						s->out_fmt,MS_SCALER_METHOD_BILINEAR);
				}
				if (s->in_fmt==MS_RGB24_REV){
					inbuf.planes[0]+=inbuf.strides[0]*(inbuf.h-1);
					inbuf.strides[0]=-inbuf.strides[0];
				}
				if (ms_scaler_process (s->scaler,inbuf.planes,inbuf.strides, s->outbuf.planes, s->outbuf.strides)<0){
					ms_error("MSPixConv: Error in ms_sws_scale().");
				}
			}
			freemsg(im);
		}
		if (om!=NULL) ms_queue_put(f->outputs[0],om);
	}
}
static void adapter_process(MSFilter *f){
	AdapterState *s=(AdapterState*)f->data;
	mblk_t *im,*om;
	size_t msgsize;
	
	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		if (s->inputchans==s->outputchans){
			ms_queue_put(f->outputs[0],im);
		}else if (s->inputchans==2){
			msgsize=msgdsize(im)/2;
			om=allocb(msgsize,0);
			for (;im->b_rptr<im->b_wptr;im->b_rptr+=4,om->b_wptr+=2){
				*(int16_t*)om->b_wptr=*(int16_t*)im->b_rptr;
			}
			ms_queue_put(f->outputs[0],om);
			freemsg(im);
		}else if (s->outputchans==2){
			msgsize=msgdsize(im)*2;
			om=allocb(msgsize,0);
			for (;im->b_rptr<im->b_wptr;im->b_rptr+=2,om->b_wptr+=4){
				((int16_t*)om->b_wptr)[0]=*(int16_t*)im->b_rptr;
				((int16_t*)om->b_wptr)[1]=*(int16_t*)im->b_rptr;
			}
			ms_queue_put(f->outputs[0],om);
			freemsg(im);
		}
	}
}
Example #9
0
static void ca_write_process(MSFilter *f){
	CAData *d = (CAData *) f->data;
	mblk_t *m;
	while((m=ms_queue_get(f->inputs[0]))!=NULL){
		ca_put(d,m);
	}
}
Example #10
0
static void dec_process(MSFilter *f){
	DecState *s=(DecState*)f->data;
	mblk_t *inputMessage, *outputMessage;
	struct	BV16_Bit_Stream bs;

	while((inputMessage=ms_queue_get(f->inputs[0]))!=NULL){

		while(inputMessage->b_rptr<inputMessage->b_wptr) {
			outputMessage = allocb(SIGNAL_FRAME_SIZE,0);
			mblk_meta_copy(inputMessage, outputMessage);
			BV16_BitUnPack((UWord8*)inputMessage->b_rptr, &bs);
			BV16_Decode(&bs, &s->state, (short*)(outputMessage->b_wptr));
			outputMessage->b_wptr+=SIGNAL_FRAME_SIZE;
			inputMessage->b_rptr+=BITSTREAM_FRAME_SIZE;
			ms_queue_put(f->outputs[0],outputMessage);
			if (s->plc) ms_concealer_inc_sample_time(s->concealer,f->ticker->time, 5, 1);

		}
		freemsg(inputMessage);

	}
	// called every 10 ms
	if (s->plc && ms_concealer_context_is_concealement_required(s->concealer, f->ticker->time)) {
		int ms_concealed;
		// need to conceal 10 ms
		for (ms_concealed=0; ms_concealed<s->packet_ms_size; ms_concealed+=5){
			outputMessage = allocb(SIGNAL_FRAME_SIZE,0);
			BV16_PLC(&s->state,(short*)outputMessage->b_wptr);
			outputMessage->b_wptr+=SIGNAL_FRAME_SIZE;
			mblk_set_plc_flag(outputMessage, 1);
			ms_queue_put(f->outputs[0],outputMessage);
		}
		ms_concealer_inc_sample_time(s->concealer,f->ticker->time,10, 0);
	}
}
Example #11
0
	/***
	Encodes 8 kHz-sampled narrowband speech at a bit rate of or 16 kbit/s,
	uses 5 ms frames.
	The encoder receives 10 ms speech => 160 bytes.
	***/
static void enc_process (MSFilter *f){
	EncState *s=(EncState*)f->data;
	struct	BV16_Bit_Stream bs;
	short *buf= NULL;
	mblk_t *inputMessage = NULL, *outputMessage = NULL;
	int frame_per_packet=s->ptime/5;
	int in_rcvd_bytes = 0;

	in_rcvd_bytes = SIGNAL_FRAME_SIZE * frame_per_packet;
	buf=(short*)alloca(in_rcvd_bytes);
	memset((void*)buf,0, in_rcvd_bytes );

	while((inputMessage=ms_queue_get(f->inputs[0]))!=NULL){
		ms_bufferizer_put(s->bufferizer,inputMessage);

	}

	/* process ptimes ms of data : (ptime in ms)/1000->ptime is seconds * 8000(sample rate) * 2(byte per sample) */
	while(ms_bufferizer_get_avail(s->bufferizer)>= in_rcvd_bytes){
		int bufferIndex;
		outputMessage = allocb(BITSTREAM_FRAME_SIZE*frame_per_packet,0); /* output bitStream is 80 bits long * number of samples */
		/* process buffer in 5 ms frames but read everything first*/
		ms_bufferizer_read(s->bufferizer,(uint8_t*)buf,in_rcvd_bytes);
		for (bufferIndex=0; bufferIndex<frame_per_packet; bufferIndex++) {
			BV16_Encode(&bs, &s->state, (short*)&buf[bufferIndex*FRSZ]);
			BV16_BitPack( (UWord8*)outputMessage->b_wptr, &bs );
			outputMessage->b_wptr+=BITSTREAM_FRAME_SIZE;
		}
		mblk_set_timestamp_info(outputMessage,s->ts);
		ms_bufferizer_fill_current_metas(s->bufferizer, outputMessage);
		ms_queue_put(f->outputs[0],outputMessage);
		s->ts +=  FRSZ * frame_per_packet;
	}

}
Example #12
0
static void enc_process(MSFilter *f){
	EncState *s=(EncState*)f->data;
	mblk_t *im;
	unsigned int unitary_buff_size = sizeof(int16_t)*160;
	unsigned int buff_size = unitary_buff_size*s->ptime/20;
	int16_t* buff;
	int offset;

	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		ms_bufferizer_put(s->bufferizer,im);
	}
	while(ms_bufferizer_get_avail(s->bufferizer) >= buff_size) {
		mblk_t *om=allocb(33*s->ptime/20,0);
		buff = (int16_t *)alloca(buff_size);
		ms_bufferizer_read(s->bufferizer,(uint8_t*)buff,buff_size);

		for (offset=0;offset<buff_size;offset+=unitary_buff_size) {
			gsm_encode(s->state,(gsm_signal*)&buff[offset/sizeof(int16_t)],(gsm_byte*)om->b_wptr);
			om->b_wptr+=33;
		}
		mblk_set_timestamp_info(om,s->ts);
		ms_queue_put(f->outputs[0],om);
		s->ts+=buff_size/sizeof(int16_t)/*sizeof(buf)/2*/;
	}
}
Example #13
0
static void enc_process(MSFilter *f){
	EncData *d=(EncData*)f->data;
	uint32_t ts=f->ticker->time*90LL;
    int sizeAll=0,key=0;
    SPSInfo sps={0};
    PPSInfo pps={0};
    mblk_t *im;
    MSPicture pic;
    MSQueue nalus;
    ms_queue_init(&nalus);
    ms_mutex_lock(&f->lock);
    while((im=ms_queue_get(f->inputs[0]))!=NULL){
        if (ms_yuv_buf_init_from_mblk(&pic,im)==0){
            if (x264_encoder_start(d,&pic,&nalus,&sizeAll,&sps,&pps,&key)==0){
                if (d->flv->state==Started){
                    MSQueue nalus_t;
                    ms_queue_init(&nalus_t);
                    x264_flv_to_file(f,&nalus,&nalus_t,sizeAll,&sps,&pps,key);
                    //x264_nals_to_file(d->flv,&nalus,&nalus_t);
                    rfc3984_pack(d->packer,&nalus_t,f->outputs[0],ts);
                }
                else{
                    rfc3984_pack(d->packer,&nalus,f->outputs[0],ts);
                }

                d->framenum++;
            }else{
                ms_error("MSH264Enc: x264_encoder_start error");
            }
        }
        freemsg(im);
    }
    ms_mutex_unlock(&f->lock);
}
Example #14
0
static void write264FlvTag(FLVStream *flv,FLVTag *tag,MSQueue *naluq, MSQueue *naluq_t)
{
    mblk_t *tm;
    int len;
    if(flvFull(flv,tag->dataSize + 15)) {
       // struct timeval tv1,tv2;
       // gettimeofday(&tv2,NULL);
        flvFlush(flv);
       // gettimeofday(&tv1,NULL);
       // ms_message("[INFO] TIME=%d ", tv1.tv_sec*1000 + tv1.tv_usec/1000 - tv2.tv_sec*1000 - tv2.tv_usec/1000);
    }

	FLVVideoTag *dataTag=&(tag->tagData);

	putChar(flv, tag->tagType);
	putUI24(flv, tag->dataSize);
	putUI24(flv, tag->timeStamp);
	putChar(flv, tag->timestampExtended);
	putUI24(flv, tag->streamID);

	putChar(flv, (dataTag->frameType<<4)|dataTag->codecId);
	putChar(flv, dataTag->pktType);
	putUI24(flv, dataTag->compositionTime);
     while((tm=ms_queue_get(naluq))!=NULL){
        len=tm->b_wptr-tm->b_rptr;
	    putUI32(flv, len);
        writeData(flv,tm->b_rptr,len);

        ms_queue_put(naluq_t,dupmsg(tm));
        freemsg(tm);
     }
	putUI32(flv, tag->dataSize + 11);
}
Example #15
0
static void vad_dtx_process(MSFilter *f){
	VadDtxContext *ctx=(VadDtxContext*)f->data;
	mblk_t *m;

	while((m=ms_queue_get(f->inputs[0]))!=NULL){
		update_energy(ctx,(int16_t*)m->b_rptr, (m->b_wptr - m->b_rptr) / 2, f->ticker->time);

		if (ortp_extremum_get_current(&ctx->max)<silence_threshold){
			if (!ctx->silence_mode){
				MSCngData cngdata={0};
				cngdata.datasize=1; /*only noise level*/
				cngdata.data[0]=0; /*noise level set to zero for the moment*/
				ms_message("vad_dtx_process(): silence period detected.");
				ctx->silence_mode=1;
				ms_filter_notify(f, MS_VAD_DTX_NO_VOICE, &cngdata);
			}
		}else{
			if (ctx->silence_mode){
				ms_message("vad_dtx_process(): silence period finished.");
				ctx->silence_mode=0;
				ms_filter_notify(f, MS_VAD_DTX_VOICE, NULL);
			}
		}
		ms_queue_put(f->outputs[0],m);
	}

}
Example #16
0
static void itc_sink_process(MSFilter *f) {
    MSFilter *other=(MSFilter *)f->data;
    mblk_t *im;
    while((im=ms_queue_get(f->inputs[0]))!=NULL) {
        itc_source_queue_packet(other,im);
    }
}
Example #17
0
static void sender_process(MSFilter * f)
{
	SenderData *d = (SenderData *) f->data;
	RtpSession *s = d->session;

	mblk_t *im;
	uint32_t timestamp;

	if (s == NULL){
		ms_queue_flush(f->inputs[0]);
		return;
	}

	if (d->relay_session_id_size>0 && 
		( (f->ticker->time-d->last_rsi_time)>5000 || d->last_rsi_time==0) ) {
		ms_message("relay session id sent in RTCP APP");
		rtp_session_send_rtcp_APP(s,0,"RSID",(const uint8_t *)d->relay_session_id,d->relay_session_id_size);
		d->last_rsi_time=f->ticker->time;
	}

	while ((im = ms_queue_get(f->inputs[0])) != NULL) {
		mblk_t *header;

		timestamp = get_cur_timestamp(f, mblk_get_timestamp_info(im));
		ms_filter_lock(f);
		if (d->skip) {
			ms_debug("skipping..");
			send_dtmf(f, d->skip_until-d->dtmf_duration, timestamp);
			d->dtmf_start = FALSE;
			if (!RTP_TIMESTAMP_IS_NEWER_THAN(timestamp, d->skip_until)) {
				freemsg(im);
				ms_filter_unlock(f);
				continue;
			}
			d->skip = FALSE;
			d->dtmf = 0;
		}

		if (d->skip == FALSE && d->mute_mic==FALSE){
			int pt = mblk_get_payload_type(im);
			header = rtp_session_create_packet(s, 12, NULL, 0);
			if (pt>0)
				rtp_set_payload_type(header, pt);
			rtp_set_markbit(header, mblk_get_marker_info(im));
			header->b_cont = im;
			rtp_session_sendm_with_ts(s, header, timestamp);
		}
		else{
			freemsg(im);
		}

		if (d->dtmf != 0) {
			ms_debug("prepare to send RFC2833 dtmf.");
			d->skip_until = timestamp + d->dtmf_duration;
			d->skip = TRUE;
			d->dtmf_start = TRUE;
		}
		ms_filter_unlock(f);
	}
}
Example #18
0
static void aq_write_process(MSFilter * f)
{
	mblk_t *m;
	while ((m = ms_queue_get(f->inputs[0])) != NULL) {
		aq_put(f, m);
	}
}
Example #19
0
void ms_speex_dec_process(MSSpeexDec *obj)
{
	MSFifo *outf=obj->outf[0];
	MSQueue *inq=obj->inq[0];
	gint16 *output;
	gint gran=obj->frame_size*2;
	gint i;
	MSMessage *m;
	
	g_return_if_fail(inq!=NULL);
	g_return_if_fail(outf!=NULL);
	
	m=ms_queue_get(inq);
	g_return_if_fail(m!=NULL);
	speex_bits_reset(&obj->bits);
	ms_fifo_get_write_ptr(outf,gran,(void**)&output);
	g_return_if_fail(output!=NULL);
	if (m->data!=NULL){
		
		speex_bits_read_from(&obj->bits,m->data,m->size);
		/* decode */
		speex_decode_int(obj->speex_state,&obj->bits,(short*)output);
	}else{
		/* we have a missing packet */
		speex_decode_int(obj->speex_state,NULL,(short*)output);
	}
	ms_message_destroy(m);
	
}
Example #20
0
static void dec_process(MSFilter *f){
	DecState *s=(DecState*)f->data;
	int nbytes = 0;
	mblk_t *im;
	mblk_t *om;
	const int frsz= BV16_FRAME_SIZE * 2 * 4;
	int i,frames;

	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		om=allocb(frsz,0);

		nbytes=msgdsize(im);
		frames = nbytes/(BV16_CODE_SIZE * 2);
		
		//ms_error("read bv16 data, size %d, frame %d",msgdsize(im),frames);

		for(i=0;i<frames;i++){

			if (mblk_get_precious_flag(im)) { //¶ª°üÒþ±Î
				bv16_fillin(s->dec, (int16_t *) om->b_wptr, BV16_CODE_SIZE);
			} else {
				bv16_decode(s->dec, (int16_t *) om->b_wptr, (uint8_t *) im->b_rptr, BV16_CODE_SIZE);
			}
			im->b_rptr += 10;
			om->b_wptr += 80;
		}
	
		ms_queue_put(f->outputs[0],om);
		freemsg(im);
	}
		
}
static void enc_process(MSFilter *f){
	static const int nsamples=160;
	EncState *s=(EncState*)f->data;
	mblk_t *im,*om;
	int16_t samples[nsamples];
	
	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		ms_bufferizer_put (s->mb,im);
	}
	while((ms_bufferizer_read(s->mb,(uint8_t*)samples,nsamples*2))>=nsamples*2){
		int ret;
		om=allocb(33,0);
		*om->b_wptr=0xf0;
		om->b_wptr++;
		ret=Encoder_Interface_Encode(s->enc,MR122,samples,om->b_wptr,0);
		if (ret<=0){
			ms_warning("Encoder returned %i",ret);
			freemsg(om);
			continue;
		}
		om->b_wptr+=ret;
		mblk_set_timestamp_info(om,s->ts);
		s->ts+=nsamples;
		ms_queue_put(f->outputs[0],om);
	}
}
Example #22
0
static void video_player_process(MSFilter *f){
	StreamData *d=(StreamData*)f->data;
	VideoState *is = d->is;
	mblk_t *om=NULL;
	ConfSlotQueue *confq= video_player_get_video_outq(d->is);

	ms_filter_lock(f);
	float elapsed=(float)(f->ticker->time-d->starttime);

	
	if ((elapsed*d->fps/1000.0)>d->index){

		ms_mutex_lock(&confq->lock);
		om = ms_queue_get(&confq->q);
		ms_mutex_unlock(&confq->lock);

		if(om!=NULL) ms_queue_put(f->outputs[0],om);

		d->index++;
	}
	ms_filter_unlock(f);

	
	
}
Example #23
0
static void dec_process(MSFilter *f){
	mblk_t *im;
	mblk_t *m;
	ogg_packet op;
	int tdt;
	DecState *s=(DecState*)f->data;
	while( (im=ms_queue_get(f->inputs[0]))!=0) {
		m=dec_unpacketize(f,s,im,&tdt);
		if (m!=NULL){
			/* now in im we have only the theora data*/
			op.packet=(uint8_t*)m->b_rptr;
			op.bytes=m->b_wptr-m->b_rptr;
			op.b_o_s=0;
			op.e_o_s=0;
			op.granulepos=0;
			op.packetno=0;
			if (tdt!=THEORA_RAW_DATA) /*packed conf*/ {
				if (!s->ready){
					if (dec_init_theora(s,&op))
						s->ready=TRUE;
				}
			}else{
				if (s->ready){
					dec_process_frame(f,s,&op);
				}else{
					ms_warning("skipping theora packet because decoder was not initialized yet with theora header and tables");
				}
			}
			freemsg(m);
		}
	}
}
Example #24
0
static void enc_process(MSFilter *f) {
	mblk_t *im,*om;
	uint64_t timems=f->ticker->time;
	uint32_t timestamp=timems*90;
	EncState *s=(EncState*)f->data;
	unsigned int flags = 0;
	vpx_codec_err_t err;
	YuvBuf yuv;

	ms_filter_lock(f);
	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		vpx_image_t img;

		om = NULL;
		flags = 0;

		ms_yuv_buf_init_from_mblk(&yuv, im);
		vpx_img_wrap(&img, VPX_IMG_FMT_I420, s->vconf.vsize.width, s->vconf.vsize.height, 1, yuv.planes[0]);
		
		if (video_starter_need_i_frame (&s->starter,f->ticker->time)){
			/*sends an I frame at 2 seconds and 4 seconds after the beginning of the call*/
			s->req_vfu=TRUE;
		}
		if (s->req_vfu){
			flags = VPX_EFLAG_FORCE_KF;
			s->req_vfu=FALSE;
		}

		err = vpx_codec_encode(&s->codec, &img, s->frame_count, 1, flags, VPX_DL_REALTIME);

		if (err) {
			ms_error("vpx_codec_encode failed : %d %s (%s)\n", err, vpx_codec_err_to_string(err), vpx_codec_error_detail(&s->codec));
		} else {
			vpx_codec_iter_t iter = NULL;
			const vpx_codec_cx_pkt_t *pkt;

			s->frame_count++;
			if (s->frame_count==1){
				video_starter_first_frame (&s->starter,f->ticker->time);
			}

			while( (pkt = vpx_codec_get_cx_data(&s->codec, &iter)) ) {
				if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
					if (pkt->data.frame.sz > 0) {
						om = allocb(pkt->data.frame.sz,0);
						memcpy(om->b_wptr, pkt->data.frame.buf, pkt->data.frame.sz);
						om->b_wptr += pkt->data.frame.sz;
						#ifdef FRAGMENT_ON_PARTITIONS
						vp8_fragment_and_send(f, s, om, timestamp, pkt, (pkt->data.frame.partition_id == s->token_partition_count));
						#else
						vp8_fragment_and_send(f, s, om, timestamp, pkt, 1);
						#endif
					}
				}
			}
		}
		freemsg(im);
	}
	ms_filter_unlock(f);
}
Example #25
0
static void au_write_process(MSFilter *f) {
    AUWrite *d = (AUWrite *) f->data;
    mblk_t *m;
    while((m=ms_queue_get(f->inputs[0]))!=NULL) {
        au_write_put(d,m);
    }
}
Example #26
0
static void pixconv_process(MSFilter *f){
	mblk_t *im,*om;
	PixConvState *s=(PixConvState*)f->data;

	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		if (s->in_fmt==s->out_fmt){
			om=im;
		}else{
			AVPicture inbuf;
			avpicture_fill(&inbuf,im->b_rptr,s->in_fmt,s->size.width,s->size.height);
			om=pixconv_alloc_mblk(s);
			if (s->sws_ctx==NULL){
				s->sws_ctx=sws_getContext(s->size.width,s->size.height,
				s->in_fmt,s->size.width,s->size.height,
				s->out_fmt,SWS_FAST_BILINEAR,
                		NULL, NULL, NULL);
			}
			if (sws_scale(s->sws_ctx,inbuf.data,inbuf.linesize, 0,
				0, s->outbuf.planes, s->outbuf.strides)!=0){
				ms_error("MSPixConv: Error in sws_scale().");
			}
			freemsg(im);
		}
		if (om!=NULL) ms_queue_put(f->outputs[0],om);
	}
}
Example #27
0
static void void_sink_process(MSFilter *f){
	mblk_t *im;
	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		dump2file(im);
		freemsg(im);
	}
}
Example #28
0
static void winsnd_write_process(MSFilter *f){
	WinSnd *d=(WinSnd*)f->data;
	mblk_t *m;
	MMRESULT mr;
	mblk_t *old;
	if (d->outdev==NULL) {
		ms_queue_flush(f->inputs[0]);
		return;
	}
	if (d->overrun){
		ms_warning("nbufs_playing=%i",d->nbufs_playing);
		if (d->nbufs_playing>0){
			ms_queue_flush(f->inputs[0]);
			return;
		}
		else d->overrun=FALSE;
	}
	while(1){
		int outcurbuf=d->outcurbuf % WINSND_OUT_NBUFS;
		WAVEHDR *hdr=&d->hdrs_write[outcurbuf];
		old=(mblk_t*)hdr->dwUser;
		if (d->nsamples==0){
			int tmpsize=(int)(WINSND_OUT_DELAY*d->wfx.nAvgBytesPerSec);
			mblk_t *tmp=allocb(tmpsize,0);
			memset(tmp->b_wptr,0,tmpsize);
			tmp->b_wptr+=tmpsize;
			playout_buf(d,hdr,tmp);
			d->outcurbuf++;
			d->nsamples+=(int)(WINSND_OUT_DELAY*d->wfx.nSamplesPerSec);
			continue;
		}
		m=ms_queue_get(f->inputs[0]);
		if (!m) break;
		d->nsamples+=msgdsize(m)/d->wfx.nBlockAlign;
		/*if the output buffer has finished to play, unprepare it*/
		if (hdr->dwFlags & WHDR_DONE){
			mr=waveOutUnprepareHeader(d->outdev,hdr,sizeof(*hdr));
			if (mr != MMSYSERR_NOERROR){
				ms_error("waveOutUnprepareHeader error");
			}
			freemsg(old);
			old=NULL;
			hdr->dwFlags=0;
			hdr->dwUser=0;
		}
		if (old==NULL){
			/* a free wavheader */
			playout_buf(d,hdr,m);
		}else{
			/* no more free wavheader, overrun !*/
			ms_warning("WINSND overrun, restarting");
			d->overrun=TRUE;
			d->nsamples=0;
			waveOutReset(d->outdev);
			break;
		}
		d->outcurbuf++;
	}
}
Example #29
0
static void filter_process(MSFilter *f){
	isac_decoder_t* obj = (isac_decoder_t*)f->data;
	mblk_t* im;
	int count = 0;

	im = ms_queue_get( f->inputs[0] );
	while( im != NULL ){
		decode(f, im);
		freemsg(im);
		count++;
		im = ms_queue_get( f->inputs[0] );
	}

	if( ms_concealer_context_is_concealement_required(obj->plc_ctx, f->ticker->time) ) {

		WebRtc_Word16 flen =  (obj->ptime == 30) ? ISAC_30MS_SAMPLE_COUNT
												 : ISAC_60MS_SAMPLE_COUNT;
		mblk_t* plc_blk = allocb(flen*2, 0 );
		//        ms_message("PLC for %d ms", obj->ptime);

		// interpolate 1 frame for 30ms ptime, 2 frames for 60ms
		WebRtc_Word16 ret = WebRtcIsacfix_DecodePlc(obj->isac,
													(WebRtc_Word16*)plc_blk->b_wptr,
													(obj->ptime == 30) ? 1 : 2);

		if( ret < 0 ) {

			ms_error("WebRtcIsacfix_DecodePlc error: %d", WebRtcIsacfix_GetErrorCode(obj->isac) );
			freeb(plc_blk);

		} else {

			plc_blk->b_wptr += ret*2;
			obj->seq_nb++;

			// insert this interpolated block into the output, with correct args:
			mblk_set_cseq(plc_blk, obj->seq_nb );
			mblk_set_plc_flag(plc_blk, 1); // this one's a PLC packet

			ms_queue_put(f->outputs[0], plc_blk);

			ms_concealer_inc_sample_time(obj->plc_ctx, f->ticker->time, obj->ptime, FALSE);

		}
	}
}
Example #30
0
static void size_conv_process(MSFilter *f){
	SizeConvState *s=(SizeConvState*)f->data;
	YuvBuf inbuf;
	mblk_t *im;
	int cur_frame;

	ms_filter_lock(f);

	if (s->frame_count==-1){
		s->start_time=(float)f->ticker->time;
		s->frame_count=0;
	}
	while((im=ms_queue_get(f->inputs[0]))!=NULL ){
		putq(&s->rq, im);
	}

	cur_frame=(int)((f->ticker->time-s->start_time)*s->fps/1000.0);
	if (cur_frame<=s->frame_count && s->fps>=0) {
		/* too much frame */
		while(s->rq.q_mcount>1){
			ms_message("MSSizeConv: extra frame removed.");
			im=getq(&s->rq);
			freemsg(im);
		}
		ms_filter_unlock(f);
		return;
	}

	if (cur_frame>s->frame_count && s->fps>=0) {
		/*keep the most recent frame if several frames have been captured */
		while(s->rq.q_mcount>1){
			ms_message("MSSizeConv: extra frame removed.");
			im=getq(&s->rq);
			freemsg(im);
		}
	}
	while((im=getq(&s->rq))!=NULL ){
		if (ms_yuv_buf_init_from_mblk(&inbuf,im)==0){
			if (inbuf.w==s->target_vsize.width &&
				inbuf.h==s->target_vsize.height){
				ms_queue_put(f->outputs[0],im);
			}else{
				struct ms_SwsContext *sws_ctx=get_resampler(s,inbuf.w,inbuf.h);
				mblk_t *om=size_conv_alloc_mblk(s);
				if (ms_sws_scale(sws_ctx,inbuf.planes,inbuf.strides, 0,
					inbuf.h, s->outbuf.planes, s->outbuf.strides)<0){
					ms_error("MSSizeConv: error in ms_sws_scale().");
				}
				ms_queue_put(f->outputs[0],om);
				freemsg(im);
			}
			s->frame_count++;
		}else freemsg(im);
	}

	ms_filter_unlock(f);
}