Commit 1048b434 authored by Ghislain MARY's avatar Ghislain MARY

Add soundread-speexenc-speexdec-soundwrite unit test.

parent 4daf3be2
......@@ -88,6 +88,7 @@ static void dtmfgen_enc_dec_tonedet(void) {
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_codec_mime = "pcmu";
ms_tester_create_filters(filter_mask);
ms_filter_set_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL);
ms_connection_helper_start(&h);
......@@ -122,6 +123,7 @@ static void dtmfgen_enc_rtp_dec_tonedet(void) {
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_codec_mime = "pcmu";
ms_tester_create_filters(filter_mask);
ms_filter_set_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL);
rtps = create_duplex_rtpsession(50060, 0, FALSE);
......
......@@ -51,6 +51,8 @@ static void configure_resampler(MSFilter *resampler, MSFilter *from, MSFilter *t
ms_filter_call_method(resampler, MS_FILTER_SET_OUTPUT_SAMPLE_RATE, &to_rate);
ms_filter_call_method(from, MS_FILTER_GET_NCHANNELS, &from_channels);
ms_filter_call_method(to, MS_FILTER_GET_NCHANNELS, &to_channels);
if (from_channels == 0) from_channels = 1;
if (to_channels == 0) to_channels = 1;
ms_filter_call_method(resampler, MS_FILTER_SET_NCHANNELS, &from_channels);
ms_filter_call_method(resampler, MS_FILTER_SET_OUTPUT_NCHANNELS, &to_channels);
}
......@@ -265,6 +267,86 @@ static void soundread_soundwrite(void) {
ms_tester_destroy_ticker();
}
static void soundread_speexenc_speexdec_soundwrite(void) {
MSConnectionHelper h;
MSFilter *read_resampler = NULL, *write_resampler = NULL;
bool_t need_read_resampler = FALSE, need_write_resampler = FALSE;
unsigned int filter_mask = FILTER_MASK_SOUNDREAD | FILTER_MASK_ENCODER | FILTER_MASK_DECODER | FILTER_MASK_SOUNDWRITE;
int sample_rate = 8000;
int nchannels = 1;
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_codec_mime = "speex";
ms_tester_create_filters(filter_mask);
ms_filter_call_method(ms_tester_encoder, MS_FILTER_GET_BITRATE, &sample_rate);
ms_filter_call_method(ms_tester_decoder, MS_FILTER_SET_BITRATE, &sample_rate);
if (ms_filter_call_method(ms_tester_soundread, MS_FILTER_SET_BITRATE, &sample_rate) != 0) {
int soundread_sample_rate = 48000;
ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_BITRATE, &soundread_sample_rate);
if (sample_rate != soundread_sample_rate) need_read_resampler = TRUE;
}
if (ms_filter_call_method(ms_tester_soundread, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) {
int soundread_nchannels = 1;
ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_NCHANNELS, &soundread_nchannels);
if (nchannels != soundread_nchannels) need_read_resampler = TRUE;
}
if (need_read_resampler == TRUE) {
ms_tester_create_filter(&read_resampler, MS_RESAMPLE_ID);
configure_resampler(read_resampler, ms_tester_soundread, ms_tester_encoder);
}
if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_BITRATE, &sample_rate) != 0) {
int soundwrite_sample_rate = 48000;
ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_BITRATE, &soundwrite_sample_rate);
if (sample_rate != soundwrite_sample_rate) need_write_resampler = TRUE;
}
if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) {
int soundwrite_nchannels = 1;
ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_NCHANNELS, &soundwrite_nchannels);
if (nchannels != soundwrite_nchannels) need_write_resampler = TRUE;
}
if (need_write_resampler == TRUE) {
ms_tester_create_filter(&write_resampler, MS_RESAMPLE_ID);
configure_resampler(write_resampler, ms_tester_decoder, ms_tester_soundwrite);
}
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_soundread, -1, 0);
if (need_read_resampler == TRUE) {
ms_connection_helper_link(&h, read_resampler, 0, 0);
}
ms_connection_helper_link(&h, ms_tester_encoder, 0, 0);
ms_connection_helper_link(&h, ms_tester_decoder, 0, 0);
if (need_write_resampler == TRUE) {
ms_connection_helper_link(&h, write_resampler, 0, 0);
}
ms_connection_helper_link(&h, ms_tester_soundwrite, 0, -1);
ms_ticker_attach(ms_tester_ticker, ms_tester_soundread);
ms_sleep(5);
ms_ticker_detach(ms_tester_ticker, ms_tester_soundread);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, ms_tester_soundread, -1, 0);
if (need_read_resampler == TRUE) {
ms_connection_helper_unlink(&h, read_resampler, 0, 0);
}
ms_connection_helper_unlink(&h, ms_tester_encoder, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_decoder, 0, 0);
if (need_write_resampler == TRUE) {
ms_connection_helper_unlink(&h, write_resampler, 0, 0);
}
ms_connection_helper_unlink(&h, ms_tester_soundwrite, 0, -1);
if (need_read_resampler == TRUE) {
ms_tester_destroy_filter(&read_resampler);
}
if (need_write_resampler == TRUE) {
ms_tester_destroy_filter(&write_resampler);
}
ms_filter_log_statistics();
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
}
test_t sound_card_tests[] = {
{ "dtmfgen-soundwrite", dtmfgen_soundwrite },
......@@ -276,7 +358,8 @@ test_t sound_card_tests[] = {
{ "fileplay-soundwrite-44100-mono", fileplay_soundwrite_44100_mono },
{ "fileplay-soundwrite-16000-mono", fileplay_soundwrite_16000_mono },
{ "fileplay-soundwrite-8000-mono", fileplay_soundwrite_8000_mono },
{ "soundread-soundwrite", soundread_soundwrite }
{ "soundread-soundwrite", soundread_soundwrite },
{ "soundread-speexenc-speexdec-soundwrite", soundread_speexenc_speexdec_soundwrite }
};
test_suite_t sound_card_test_suite = {
......
......@@ -55,6 +55,7 @@ MSFilter *ms_tester_rtpsend = NULL;
MSFilter *ms_tester_resampler = NULL;
MSFilter *ms_tester_soundwrite = NULL;
MSFilter *ms_tester_soundread = NULL;
char *ms_tester_codec_mime = "pcmu";
unsigned char ms_tester_tone_detected;
......@@ -86,6 +87,13 @@ void ms_tester_destroy_ticker(void) {
CU_ASSERT_PTR_NOT_NULL_FATAL(filter); \
}
void ms_tester_create_filter(MSFilter **filter, MSFilterId id) {
CU_ASSERT_PTR_NOT_NULL(filter);
CU_ASSERT_PTR_NULL(*filter);
*filter = ms_filter_new(id);
CU_ASSERT_PTR_NOT_NULL_FATAL(*filter);
}
void ms_tester_create_filters(unsigned int filter_mask) {
MSSndCardManager *manager;
MSSndCard *playcard;
......@@ -97,8 +105,16 @@ void ms_tester_create_filters(unsigned int filter_mask) {
CREATE_FILTER(FILTER_MASK_TONEDET, ms_tester_tonedet, MS_TONE_DETECTOR_ID);
CREATE_FILTER(FILTER_MASK_VOIDSOURCE, ms_tester_voidsource, MS_VOID_SOURCE_ID);
CREATE_FILTER(FILTER_MASK_VOIDSINK, ms_tester_voidsink, MS_VOID_SINK_ID);
CREATE_FILTER(FILTER_MASK_ENCODER, ms_tester_encoder, MS_ALAW_ENC_ID);
CREATE_FILTER(FILTER_MASK_DECODER, ms_tester_decoder, MS_ALAW_DEC_ID);
if (filter_mask & FILTER_MASK_ENCODER) {
CU_ASSERT_PTR_NULL(ms_tester_encoder);
ms_tester_encoder = ms_filter_create_encoder(ms_tester_codec_mime);
CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_encoder);
}
if (filter_mask & FILTER_MASK_DECODER) {
CU_ASSERT_PTR_NULL(ms_tester_decoder);
ms_tester_decoder = ms_filter_create_decoder(ms_tester_codec_mime);
CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_decoder);
}
CREATE_FILTER(FILTER_MASK_RTPRECV, ms_tester_rtprecv, MS_RTP_RECV_ID);
CREATE_FILTER(FILTER_MASK_RTPSEND, ms_tester_rtpsend, MS_RTP_SEND_ID);
CREATE_FILTER(FILTER_MASK_RESAMPLER, ms_tester_resampler, MS_RESAMPLE_ID);
......@@ -126,6 +142,14 @@ void ms_tester_create_filters(unsigned int filter_mask) {
} \
filter = NULL
void ms_tester_destroy_filter(MSFilter **filter) {
CU_ASSERT_PTR_NOT_NULL(filter);
if (*filter != NULL) {
ms_filter_destroy(*filter);
*filter = NULL;
}
}
void ms_tester_destroy_filters(unsigned int filter_mask) {
DESTROY_FILTER(FILTER_MASK_FILEPLAY, ms_tester_fileplay);
DESTROY_FILTER(FILTER_MASK_FILEREC, ms_tester_filerec);
......
......@@ -46,6 +46,7 @@ extern MSFilter *ms_tester_rtpsend;
extern MSFilter *ms_tester_resampler;
extern MSFilter *ms_tester_soundwrite;
extern MSFilter *ms_tester_soundread;
extern char *ms_tester_codec_mime;
enum {
FILTER_MASK_FILEPLAY = (1 << 0),
......@@ -69,7 +70,9 @@ extern unsigned char ms_tester_tone_detected;
void ms_tester_create_ticker(void);
void ms_tester_destroy_ticker(void);
void ms_tester_create_filter(MSFilter **filter, MSFilterId id);
void ms_tester_create_filters(unsigned int filter_mask);
void ms_tester_destroy_filter(MSFilter **filter);
void ms_tester_destroy_filters(unsigned int filter_mask);
void ms_tester_tone_generation_loop(void);
void ms_tester_tone_detection_loop(void);
......
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