Commit 57785176 authored by Ghislain MARY's avatar Ghislain MARY

Add soundread-soundwrite unit test.

parent daa8d61f
......@@ -204,6 +204,57 @@ static void fileplay_soundwrite_8000_mono(void) {
fileplay_soundwrite(ARPEGGIO_8000_MONO_FILE_NAME);
}
static void soundread_soundwrite(void) {
MSConnectionHelper h;
bool_t need_resampler = FALSE;
unsigned int filter_mask = FILTER_MASK_SOUNDREAD | FILTER_MASK_SOUNDWRITE;
int sample_rate = 8000;
int nchannels = 1;
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_create_filters(filter_mask);
ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_SAMPLE_RATE, &sample_rate);
ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_NCHANNELS, &nchannels);
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_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_resampler = TRUE;
}
if (need_resampler == TRUE) {
ms_tester_create_filters(FILTER_MASK_RESAMPLER);
configure_resampler(ms_tester_resampler, ms_tester_soundread, ms_tester_soundwrite);
}
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_soundread, -1, 0);
if (need_resampler == TRUE) {
ms_connection_helper_link(&h, ms_tester_resampler, 0, 0);
}
ms_connection_helper_link(&h, ms_tester_soundwrite, 0, -1);
ms_ticker_attach(ms_tester_ticker, ms_tester_soundread);
ms_sleep(3);
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_resampler == TRUE) {
ms_connection_helper_unlink(&h, ms_tester_resampler, 0, 0);
}
ms_connection_helper_unlink(&h, ms_tester_soundwrite, 0, -1);
if (need_resampler == TRUE) {
ms_tester_destroy_filters(FILTER_MASK_RESAMPLER);
}
ms_filter_log_statistics();
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
}
test_t sound_card_tests[] = {
{ "dtmfgen-soundwrite", dtmfgen_soundwrite },
......@@ -212,7 +263,8 @@ test_t sound_card_tests[] = {
{ "fileplay-soundwrite-8000-stereo", fileplay_soundwrite_8000_stereo },
{ "fileplay-soundwrite-48000-mono", fileplay_soundwrite_48000_mono },
{ "fileplay-soundwrite-16000-mono", fileplay_soundwrite_16000_mono },
{ "fileplay-soundwrite-8000-mono", fileplay_soundwrite_8000_mono }
{ "fileplay-soundwrite-8000-mono", fileplay_soundwrite_8000_mono },
{ "soundread-soundwrite", soundread_soundwrite }
};
test_suite_t sound_card_test_suite = {
......
......@@ -54,6 +54,7 @@ MSFilter *ms_tester_rtprecv = NULL;
MSFilter *ms_tester_rtpsend = NULL;
MSFilter *ms_tester_resampler = NULL;
MSFilter *ms_tester_soundwrite = NULL;
MSFilter *ms_tester_soundread = NULL;
unsigned char ms_tester_tone_detected;
......@@ -88,6 +89,7 @@ void ms_tester_destroy_ticker(void) {
void ms_tester_create_filters(unsigned int filter_mask) {
MSSndCardManager *manager;
MSSndCard *playcard;
MSSndCard *captcard;
CREATE_FILTER(FILTER_MASK_FILEPLAY, ms_tester_fileplay, MS_FILE_PLAYER_ID);
CREATE_FILTER(FILTER_MASK_FILEREC, ms_tester_filerec, MS_FILE_REC_ID);
......@@ -108,6 +110,14 @@ void ms_tester_create_filters(unsigned int filter_mask) {
ms_tester_soundwrite = ms_snd_card_create_writer(playcard);
CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_soundwrite);
}
if (filter_mask & FILTER_MASK_SOUNDREAD) {
CU_ASSERT_PTR_NULL(ms_tester_soundread);
manager = ms_snd_card_manager_get();
captcard = ms_snd_card_manager_get_default_capture_card(manager);
CU_ASSERT_PTR_NOT_NULL_FATAL(captcard);
ms_tester_soundread = ms_snd_card_create_reader(captcard);
CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_soundread);
}
}
#define DESTROY_FILTER(mask, filter) \
......@@ -129,6 +139,7 @@ void ms_tester_destroy_filters(unsigned int filter_mask) {
DESTROY_FILTER(FILTER_MASK_RTPSEND, ms_tester_rtpsend);
DESTROY_FILTER(FILTER_MASK_RESAMPLER, ms_tester_resampler);
DESTROY_FILTER(FILTER_MASK_SOUNDWRITE, ms_tester_soundwrite);
DESTROY_FILTER(FILTER_MASK_SOUNDREAD, ms_tester_soundread);
}
void ms_tester_tone_generation_loop(void) {
......
......@@ -45,6 +45,7 @@ extern MSFilter *ms_tester_rtprecv;
extern MSFilter *ms_tester_rtpsend;
extern MSFilter *ms_tester_resampler;
extern MSFilter *ms_tester_soundwrite;
extern MSFilter *ms_tester_soundread;
enum {
FILTER_MASK_FILEPLAY = (1 << 0),
......@@ -58,7 +59,8 @@ enum {
FILTER_MASK_RTPRECV = (1 << 8),
FILTER_MASK_RTPSEND = (1 << 9),
FILTER_MASK_RESAMPLER = (1 << 10),
FILTER_MASK_SOUNDWRITE = (1 << 11)
FILTER_MASK_SOUNDWRITE = (1 << 11),
FILTER_MASK_SOUNDREAD = (1 << 12)
} filter_mask_enum;
......
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