tee.c 2.42 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)

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.
*/

Simon Morlat's avatar
Simon Morlat committed
20

aymeric's avatar
aymeric committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#include "mediastreamer2/mstee.h"

#define MS_TEE_NOUTPUTS 10

typedef struct _TeeData{
	bool_t muted[MS_TEE_NOUTPUTS];
}TeeData;

static void tee_init(MSFilter *f){
	f->data=ms_new0(TeeData,1);
}

static void tee_uninit(MSFilter *f){
	ms_free(f->data);
}

static void tee_process(MSFilter *f){
	TeeData *d=(TeeData*)f->data;
	mblk_t *im;
	int i;
	while((im=ms_queue_get(f->inputs[0]))!=NULL){
		for(i=0;i<f->desc->noutputs;i++){
			if (f->outputs[i]!=NULL && !d->muted[i])
				ms_queue_put(f->outputs[i],dupmsg(im));
		}
		freemsg(im);
	}
}

static int tee_mute(MSFilter *f, void *arg){
	TeeData *d=(TeeData*)f->data;
	int pin=((int*)arg)[0];
	if (pin>=0 && pin<MS_TEE_NOUTPUTS){
		d->muted[pin]=TRUE;
		return 0;
	}
	return -1;
}

static int tee_unmute(MSFilter *f, void *arg){
	TeeData *d=(TeeData*)f->data;
	int pin=((int*)arg)[0];
	if (pin>=0 && pin<MS_TEE_NOUTPUTS){
		d->muted[pin]=FALSE;
		return 0;
	}
	return -1;
}

static MSFilterMethod tee_methods[]={
	{	MS_TEE_MUTE	,	tee_mute	},
	{	MS_TEE_UNMUTE	,	tee_unmute	},
	{	0		,	NULL		}
};

#ifdef _MSC_VER

MSFilterDesc ms_tee_desc={
	MS_TEE_ID,
	"MSTee",
81
	N_("A filter that reads from input and copy to its multiple outputs."),
aymeric's avatar
aymeric committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
	MS_FILTER_OTHER,
	NULL,
	1,
	MS_TEE_NOUTPUTS,
    	tee_init,
	NULL,
	tee_process,
	NULL,
	tee_uninit,
    	tee_methods
};

#else

MSFilterDesc ms_tee_desc={
	.id=MS_TEE_ID,
	.name="MSTee",
99
	.text=N_("A filter that reads from input and copy to its multiple outputs."),
aymeric's avatar
aymeric committed
100 101 102 103 104 105 106 107 108 109 110 111
	.category=MS_FILTER_OTHER,
	.ninputs=1,
	.noutputs=MS_TEE_NOUTPUTS,
	.init=tee_init,
	.process=tee_process,
	.uninit=tee_uninit,
	.methods=tee_methods
};

#endif

MS_FILTER_DESC_EXPORT(ms_tee_desc)