Commit 51feb8dc authored by Ghislain MARY's avatar Ghislain MARY

Add the void_source filter that generates silence.

parent e5f7137b
......@@ -2,12 +2,14 @@
extern MSFilterDesc ms_tee_desc;
extern MSFilterDesc ms_join_desc;
extern MSFilterDesc ms_void_source_desc;
extern MSFilterDesc ms_void_sink_desc;
MSFilterDesc * ms_base_filter_descs[]={
&ms_tee_desc,
&ms_join_desc,
&ms_void_source_desc,
&ms_void_sink_desc,
NULL
};
......
......@@ -2,6 +2,7 @@
extern MSFilterDesc ms_tee_desc;
extern MSFilterDesc ms_join_desc;
extern MSFilterDesc ms_void_source_desc;
extern MSFilterDesc ms_void_sink_desc;
extern MSFilterDesc ms_itc_source_desc;
extern MSFilterDesc ms_itc_sink_desc;
......@@ -9,6 +10,7 @@ extern MSFilterDesc ms_itc_sink_desc;
MSFilterDesc * ms_base_filter_descs[]={
&ms_tee_desc,
&ms_join_desc,
&ms_void_source_desc,
&ms_void_sink_desc,
&ms_itc_source_desc,
&ms_itc_sink_desc,
......
......@@ -81,6 +81,7 @@ typedef enum MSFilterId{
MS_H263_OLD_ENC_ID,
MS_MIRE_ID,
MS_VFW_ID,
MS_VOID_SOURCE_ID,
MS_VOID_SINK_ID,
MS_DSCAP_ID,
MS_AQ_READ_ID,
......
......@@ -18,8 +18,58 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msticker.h"
struct VoidSourceState {
int rate;
int nchannels;
};
typedef struct VoidSourceState VoidSourceState;
static void void_source_init(MSFilter *f) {
VoidSourceState *s = (VoidSourceState *)ms_new(VoidSourceState, 1);
s->rate = 8000;
s->nchannels = 1;
f->data = s;
}
static void void_source_uninit(MSFilter *f) {
ms_free(f->data);
}
static void void_source_process(MSFilter *f) {
mblk_t *m;
VoidSourceState *s = (VoidSourceState *)f->data;
int nsamples;
nsamples = (f->ticker->interval * s->rate) / 1000;
m = allocb(nsamples * s->nchannels * 2, 0);
memset(m->b_wptr, 0, nsamples * s->nchannels * 2);
m->b_wptr += nsamples * s->nchannels * 2;
ms_queue_put(f->outputs[0], m);
}
static int void_source_set_rate(MSFilter *f, void *arg) {
VoidSourceState *s = (VoidSourceState *)f->data;
s->rate = *((int*)arg);
return 0;
}
static int void_source_set_nchannels(MSFilter *f, void *arg) {
VoidSourceState *s = (VoidSourceState *)f->data;
s->nchannels = *(int *)arg;
return 0;
}
MSFilterMethod void_source_methods[] = {
{ MS_FILTER_SET_SAMPLE_RATE, void_source_set_rate },
{ MS_FILTER_SET_NCHANNELS, void_source_set_nchannels },
{ 0, NULL }
};
static void void_sink_process(MSFilter *f){
mblk_t *im;
while((im=ms_queue_get(f->inputs[0]))!=NULL){
......@@ -29,6 +79,23 @@ static void void_sink_process(MSFilter *f){
#ifdef _MSC_VER
MSFilterDesc ms_void_source_desc={
MS_VOID_SOURCE_ID,
"MSVoidSource",
N_("A filter that generates silence on its output (useful for beginning some graphs)."),
MS_FILTER_OTHER,
NULL,
0,
1,
void_source_init,
NULL,
void_source_process,
NULL,
void_source_uninit,
void_source_methods,
MS_FILTER_IS_PUMP
};
MSFilterDesc ms_void_sink_desc={
MS_VOID_SINK_ID,
"MSVoidSink",
......@@ -46,6 +113,20 @@ MSFilterDesc ms_void_sink_desc={
#else
MSFilterDesc ms_void_source_desc={
.id=MS_VOID_SOURCE_ID,
.name="MSVoidSource",
.text=N_("A filter that generates silence on its output (useful for beginning some graphs)."),
.category=MS_FILTER_OTHER,
.ninputs=0,
.noutputs=1,
.init=void_source_init,
.process=void_source_process,
.uninit=void_source_uninit,
.methods=void_source_methods,
.flags=MS_FILTER_IS_PUMP
};
MSFilterDesc ms_void_sink_desc={
.id=MS_VOID_SINK_ID,
.name="MSVoidSink",
......@@ -58,4 +139,5 @@ MSFilterDesc ms_void_sink_desc={
#endif
MS_FILTER_DESC_EXPORT(ms_void_source_desc)
MS_FILTER_DESC_EXPORT(ms_void_sink_desc)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment