mediastreamer2_framework_tester.c 6.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006-2013 Belledonne Communications, Grenoble

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/mediastream.h"
#include "mediastreamer2/dtmfgen.h"
#include "mediastreamer2/msfileplayer.h"
#include "mediastreamer2/msfilerec.h"
#include "mediastreamer2/msrtp.h"
#include "mediastreamer2/mstonedetector.h"
#include "mediastreamer2_tester.h"
#include "mediastreamer2_tester_private.h"

30
static int tester_before_all(void) {
31 32 33 34 35 36
/*	ms_init();
	ms_filter_enable_statistics(TRUE);
	ortp_init();*/
	return 0;
}

37
static int tester_after_all(void) {
38 39 40 41 42
/*	ms_exit();*/
	return 0;
}

static void filter_register_tester(void) {
43
	MSFilter* filter;
44
	MSFactory* factory = NULL;
45
	
46
	factory = ms_factory_new_with_voip();
47 48 49 50 51

	BC_ASSERT_PTR_NOT_NULL(ms_factory_lookup_filter_by_name(factory, "MSVoidSource"));

	BC_ASSERT_PTR_NOT_NULL(ms_factory_lookup_filter_by_name(factory, "MSVoidSource"));
	filter= ms_factory_create_decoder(factory, "pcma");
52
	BC_ASSERT_PTR_NOT_NULL(filter);
53
	ms_filter_destroy(filter);
54

55 56
	BC_ASSERT_PTR_NOT_NULL(ms_factory_lookup_filter_by_name(factory,"MSVoidSource"));
	filter= ms_factory_create_decoder(factory, "pcma");
57
	BC_ASSERT_PTR_NOT_NULL(filter);
58
	ms_filter_destroy(filter);
59

60 61
	ms_factory_destroy(factory);
	
62
}
63 64
#ifdef VIDEO_ENABLED
static void test_video_processing (void) {
65 66
	MSVideoSize src_size = { MS_VIDEO_SIZE_VGA_W, MS_VIDEO_SIZE_VGA_H };
	MSVideoSize src_dest = { MS_VIDEO_SIZE_VGA_W, MS_VIDEO_SIZE_VGA_H };
67 68 69 70 71 72 73
	mblk_t * yuv_block2;
	YuvBuf yuv;
	int y_bytes_per_row = src_size.width + src_size.width%32 ;
	uint8_t* y = (uint8_t*)ms_malloc(y_bytes_per_row*src_size.height); /*to allow bloc to work with multiple of 32*/
	int crcb_bytes_per_row = src_size.width/2 + (src_size.width/2)%32 ;
	uint8_t* cbcr = (uint8_t*)ms_malloc(crcb_bytes_per_row*src_size.height);
	int i,j;
74
	MSYuvBufAllocator *yba = ms_yuv_buf_allocator_new();
75 76 77 78 79 80 81 82

	for (i=0;i<src_size.height*src_size.width;i++) {
		y[i]=i%256;
	}
	for (i=0;i<src_size.height*src_size.width/2;i++) {
		cbcr[i]=i%256;
	}

83
	yuv_block2 = copy_ycbcrbiplanar_to_true_yuv_with_rotation_and_down_scale_by_2(yba,	y
84 85 86 87 88 89 90 91 92
																					,cbcr
																					,0
																					, src_size.width
																					, src_size.height
																					, y_bytes_per_row
																					, crcb_bytes_per_row
																					, 1
																					, 0);

93
	BC_ASSERT_FALSE(ms_yuv_buf_init_from_mblk(&yuv, yuv_block2));
94

95 96
	BC_ASSERT_EQUAL(src_dest.width,yuv.w, int, "%d");
	BC_ASSERT_EQUAL(src_dest.height,yuv.h, int, "%d");
97 98 99 100 101 102

	/*check y*/
	for (i=0;i<yuv.h;i++) {
		for (j=0;j<yuv.w;j++)
		if (yuv.planes[0][i*yuv.strides[0]+j] != y[i*y_bytes_per_row+j]) {
			ms_error("Wrong value  [%i] at ofset [%i], should be [%i]",yuv.planes[0][i*yuv.strides[0]+j],i*yuv.strides[0]+j,y[i*y_bytes_per_row+j]);
103
			BC_FAIL("bad y value");
104 105 106 107 108 109 110 111 112
			break;
		}
	}

	/*check cb*/
	for (i=0;i<yuv.h/2;i++) {
		for (j=0;j<yuv.w/2;j++)
		if (yuv.planes[1][i*yuv.strides[1]+j] != cbcr[i*crcb_bytes_per_row+2*j]) {
			ms_error("Wrong value  [%i] at ofset [%i], should be [%i]",yuv.planes[1][i*yuv.strides[1]+j],i*yuv.strides[1]+j,y[i*crcb_bytes_per_row+2*j]);
113
			BC_FAIL("bad cb value");
114 115 116 117 118 119 120 121 122
			break;
		}
	}

	/*check cr*/
	for (i=0;i<yuv.h/2;i++) {
		for (j=0;j<yuv.w/2;j++)
		if (yuv.planes[2][i*yuv.strides[2]+j] != cbcr[i*crcb_bytes_per_row+2*j+1]) {
			ms_error("Wrong value  [%i] at ofset [%i], should be [%i]",yuv.planes[2][i*yuv.strides[2]+j],i*yuv.strides[2]+j,y[i*crcb_bytes_per_row+2*j+1]);
123
			BC_FAIL("bad cr value");
124 125 126
			break;
		}
	}
127
	freemsg(yuv_block2);
128 129
	ms_free(y);
	ms_free(cbcr);
130
	ms_yuv_buf_allocator_free(yba);
131 132 133

}
#endif
134

jehan's avatar
jehan committed
135 136
static void test_is_multicast(void) {

137 138 139 140 141
	BC_ASSERT_TRUE(ms_is_multicast("224.1.2.3"));
	BC_ASSERT_TRUE(ms_is_multicast("239.0.0.0"));
	BC_ASSERT_TRUE(ms_is_multicast("ff02::3:2"));
	BC_ASSERT_FALSE(ms_is_multicast("192.68.0.1"));
	BC_ASSERT_FALSE(ms_is_multicast("::1"));
jehan's avatar
jehan committed
142 143

}
144 145 146 147

static void test_filterdesc_enable_disable_base(const char* mime, const char* filtername,bool_t is_enc) {
	MSFilter *filter;

148
	MSFactory *factory = NULL;
149
	factory = ms_factory_new_with_voip();
François Grisez's avatar
François Grisez committed
150

151
	if (is_enc)
152
			filter = ms_factory_create_encoder(factory,mime);
153
		else
154
			filter = ms_factory_create_decoder(factory,mime);
155 156 157 158

	BC_ASSERT_PTR_NOT_NULL(filter);
	ms_filter_destroy(filter);

159 160
	BC_ASSERT_FALSE(ms_factory_enable_filter_from_name(factory,filtername,FALSE));
	BC_ASSERT_FALSE(ms_factory_filter_from_name_enabled(factory,filtername));
161
	if (is_enc)
162
			filter = ms_factory_create_encoder(factory,mime);
163
		else
164
			filter = ms_factory_create_decoder(factory,mime);
165 166
	BC_ASSERT_PTR_NULL(filter);

167 168
	BC_ASSERT_FALSE(ms_factory_enable_filter_from_name(factory,filtername,TRUE));
	BC_ASSERT_TRUE(ms_factory_filter_from_name_enabled(factory,filtername));
169
	if (is_enc)
170
		filter = ms_factory_create_encoder(factory,mime);
171
	else
172
		filter = ms_factory_create_decoder(factory,mime);
173 174 175
	BC_ASSERT_PTR_NOT_NULL(filter);

	ms_filter_destroy(filter);
176
	
177
	ms_factory_destroy(factory);
178
}
179
static void test_filterdesc_enable_disable(void) {
180 181 182
	test_filterdesc_enable_disable_base("pcmu", "MSUlawDec", FALSE);
	test_filterdesc_enable_disable_base("pcma", "MSAlawEnc", TRUE);
}
183
static test_t tests[] = {
184 185 186
	 { "Multiple ms_voip_init", filter_register_tester },
	 { "Is multicast", test_is_multicast},
	 { "FilterDesc enabling/disabling", test_filterdesc_enable_disable},
187
#ifdef VIDEO_ENABLED
188
	 { "Video processing function", test_video_processing}
189
#endif
190 191 192 193
};

test_suite_t framework_test_suite = {
	"Framework",
194 195 196 197
	tester_before_all,
	tester_after_all,
	NULL,
	NULL,
198 199 200
	sizeof(tests) / sizeof(tests[0]),
	tests
};