filter-template.c 6.25 KB
Newer Older
jehan's avatar
jehan committed
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
filter-template.c

mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2011-2012 Belledonne Communications, Grenoble, France

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
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
*/


#include "mediastreamer2/msfilter.h"


/******************************************************************************
 * This file is mediastreamer2 filter template to be used to create new       *
 * filters.                                                                   *
 * The procedure to follow to create a new filter is to:                      *
 *  1. Copy this file to the file that will be your new filter                *
 *  2. Replace any "MyFilter" and "my_filter" occurences to the name that     *
 *     suits your new filter                                                  *
 *  3. Fill in the blanks where are located comments beginning with           *
 *     FILTER_TODO                                                            *
 *****************************************************************************/


/**
 * Definition of the private data structure of the filter.
jehan's avatar
jehan committed
40
 */
41 42 43 44 45
typedef struct _MyFilterData {
	char some_value;
	/* FILTER_TODO: Fill the private data structure with the data fields
	   that are required to run your filter. */
} MyFilterData;
jehan's avatar
jehan committed
46 47


48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/******************************************************************************
 * Methods to (de)initialize and run the filter                               *
 *****************************************************************************/

/**
 * Initialization of the filter.
 *
 * This function is called once when the filter is created by calling
 * ms_filter_new(), ms_filter_new_from_desc(), ms_filter_new_from_name(),
 * ms_filter_create_encoder() or ms_filter_create_decoder().
 */
static void my_filter_init(MSFilter *f) {
	MyFilterData *d = (MyFilterData *)ms_new(MyFilterData, 1);
	d->some_value = 42;
	/* FILTER_TODO: Initialize the filter private data and eventually
	   call initialization functions of the libraries on which the filter
	   depends. */
	f->data = d;
jehan's avatar
jehan committed
66 67
}

68 69 70 71 72 73 74
/**
 * Preprocessing performed when the filter is attached to a ticker.
 *
 * This function is called only once.
 */
static void my_filter_preprocess(MSFilter *f) {
	/* FILTER_TODO: Fill with the implementation specific to the filter. */
jehan's avatar
jehan committed
75 76
}

77 78 79 80 81 82 83 84 85 86 87
/**
 * Core of the filter: this is where the processing is done.
 *
 * The principle is to read data from the input(s), perform some processing on
 * it, and then write it to the output(s).
 *
 * This function is called at each tick of the ticker to which the filter has
 * been attached to.
 */
static void my_filter_process(MSFilter *f) {
	/* FILTER_TODO: Fill with the implementation specific to the filter. */
jehan's avatar
jehan committed
88 89
}

90 91 92 93 94 95 96 97
/**
 * Postprocessing performed when the filter is detached from the ticker it was
 * attached to.
 *
 * This function is called only once.
 */
static void my_filter_postprocess(MSFilter *f) {
	/* FILTER_TODO: Fill with the implementation specific to the filter. */
jehan's avatar
jehan committed
98 99
}

100 101 102 103 104 105 106 107 108 109 110 111
/**
 * Uninitialization of the filter.
 *
 * This function is called once when the filter is destroyed by calling
 * ms_filter_destroy().
 */
static void my_filter_uninit(MSFilter *f) {
	MyFilterData *d = (MyFilterData *)f->data;
	/* FILTER_TODO: Uninitialize the filter private data and eventually
	   call the uninitialization functions of the libraries on which the
	   filter depends. */
	ms_free(d);
jehan's avatar
jehan committed
112 113 114
}


115 116 117
/******************************************************************************
 * Methods to configure the filter                                            *
 *****************************************************************************/
jehan's avatar
jehan committed
118

119 120 121
static int my_filter_set_sample_rate(MSFilter *f, void *arg) {
	/* FILTER_TODO: Fill with real implementation. */
	return 0;
jehan's avatar
jehan committed
122 123
}

124 125 126
static int my_filter_get_sample_rate(MSFilter *f, void *arg) {
	/* FILTER_TODO: Fill with real implementation. */
	return 0;
jehan's avatar
jehan committed
127 128
}

129 130 131 132 133 134 135 136 137 138 139 140 141
/**
 * This array defines the list of functions that can be called to configure
 * the filter.
 *
 * The mean to call these functions is to call the ms_filter_call_method() or
 * ms_filter_call_method_noarg() functions.
 *
 * The array must be NULL terminated.
 */
static MSFilterMethod my_filter_methods[] = {
	{	MS_FILTER_SET_SAMPLE_RATE,	my_filter_set_sample_rate	},
	{	MS_FILTER_GET_SAMPLE_RATE,	my_filter_get_sample_rate	},
	{	0,				NULL				}
jehan's avatar
jehan committed
142 143 144
};


145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
/******************************************************************************
 * Definition of the filter                                                   *
 *****************************************************************************/

/* MY_FILTER_ID is to be added in from allfilters.h */
#define MY_FILTER_NAME		"MyFilter"
#define MY_FILTER_DESCRIPTION	"An empty filter."
#define MY_FILTER_CATEGORY	MS_FILTER_OTHER
#define MY_FILTER_ENC_FMT	NULL
#define MY_FILTER_NINPUTS	1
#define MY_FILTER_NOUTPUTS	0
#define MY_FILTER_FLAGS		0

#ifndef _MSC_VER

MSFilterDesc my_filter_desc = {
	.id = MY_FILTER_ID,
	.name = MY_FILTER_NAME,
	.text = MY_FILTER_DESCRIPTION,
	.category = MY_FILTER_CATEGORY,
	.enc_fmt = MY_FILTER_ENC_FMT,
	.ninputs = MY_FILTER_NINPUTS,
	.noutputs = MY_FILTER_NOUTPUTS,
	.init = my_filter_init,
	.preprocess = my_filter_preprocess,
	.process = my_filter_process,
	.postprocess = my_filter_postprocess,
	.uninit = my_filter_uninit,
	.methods = my_filter_methods,
	.flags = MY_FILTER_FLAGS
};

#else

MSFilterDesc my_filter_desc = {
	MY_FILTER_ID,
	MY_FILTER_NAME,
	MY_FILTER_DESCRIPTION,
	MY_FILTER_CATEGORY,
	MY_FILTER_ENC_FMT,
	MY_FILTER_NINPUTS,
	MY_FILTER_NOUTPUTS,
	my_filter_init,
	my_filter_preprocess,
	my_filter_process,
	my_filter_postprocess,
	my_filter_uninit,
	my_filter_methods,
	MY_FILTER_FLAGS
};

#endif
jehan's avatar
jehan committed
197

198
MS_FILTER_DESC_EXPORT(my_filter_desc)