/* mediastreamer2 library - modular sound and video processing and streaming Copyright (C) 2006 Simon MORLAT (address@hidden) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mediastreamer2/blankplayer.h" #include "mediastreamer2/msticker.h" //#define FDEBUG //#define SILENT_WARN //#define SILENT_ERROR //#define SILENT_INFO #include "dbg_macro.h" #ifdef DMALLOC #include "dmalloc.h" #endif typedef enum { INIT, STARTED, PAUSE } PlayerState; struct _PlayerData{ PlayerState state; int rate; int nchannels; }; typedef struct _PlayerData PlayerData; static void player_init(MSFilter *f){ PlayerData *d=ms_new(PlayerData,1); d->state=INIT; d->rate=8000; d->nchannels=1; f->data=d; } static int player_start(MSFilter *f, void *arg){ PlayerData *d=(PlayerData*)f->data; ms_filter_lock(f); d->state=STARTED; ms_filter_unlock(f); return 0; } static int player_pause(MSFilter *f, void *arg){ PlayerData *d=(PlayerData*)f->data; ms_filter_lock(f); d->state=PAUSE; ms_filter_unlock(f); return 0; } static void player_uninit(MSFilter *f){ PlayerData *d=(PlayerData*)f->data; ms_free(d); } #undef _RAMP__ //#define _RAMP__ 20 #ifdef _RAMP__ static short ramp = 0x0; #endif static void player_process(MSFilter *f){ PlayerData *d=(PlayerData*)f->data; int bytes=2*(f->ticker->interval*d->rate*d->nchannels)/1000; ms_filter_lock(f); if (d->state==STARTED){ mblk_t *om=allocb(bytes,0); if (om){ #ifdef _RAMP__ int i; for (i=0;ib_wptr)[i] = ramp; ramp += _RAMP__; } #else memset(om->b_wptr,0,bytes); #endif om->b_wptr+=bytes; ms_queue_put(f->outputs[0],om); }else{ ERROR("NOMEM"); ms_warning("Fail to allocate %i bytes",bytes); } } ms_filter_unlock(f); } static int player_get_sr(MSFilter *f, void*arg){ PlayerData *d=(PlayerData*)f->data; *((int*)arg)=d->rate; return 0; } static int player_get_nch(MSFilter *f, void *arg){ PlayerData *d=(PlayerData*)f->data; *((int*)arg)=d->nchannels; return 0; } static MSFilterMethod player_methods[]={ { MS_BLANK_PLAYER_START, player_start }, { MS_BLANK_PLAYER_PAUSE, player_pause }, { MS_FILTER_GET_SAMPLE_RATE, player_get_sr}, { MS_FILTER_GET_NCHANNELS, player_get_nch }, { 0, NULL } }; #ifdef WIN32 MSFilterDesc ms_file_player_desc={ MS_BLANK_PLAYER_ID, "MSBlankPlayer", "Blank stream producer", MS_FILTER_OTHER, NULL, 0, 1, player_init, NULL, player_process, NULL, player_uninit, player_methods }; #else MSFilterDesc ms_blank_player_desc={ .id=MS_BLANK_PLAYER_ID, .name="MSBlankPlayer", .text="Blank stream producer", .category=MS_FILTER_OTHER, .ninputs=0, .noutputs=1, .init=player_init, .process=player_process, .uninit=player_uninit, .methods=player_methods }; #endif MS_FILTER_DESC_EXPORT(ms_blank_player_desc)