Commit d46bdda7 authored by Ghislain MARY's avatar Ghislain MARY

Reorganize unit tests.

parent e24d78e2
......@@ -5,8 +5,8 @@ noinst_PROGRAMS=mediastreamer2_tester
TESTS=mediastreamer2_tester
mediastreamer2_tester_SOURCES= \
mediastreamer2_tester.c mediastreamer2_tester.h\
mediastreamer2_dtmfgen_tester.c
mediastreamer2_tester.c mediastreamer2_tester.h mediastreamer2_tester_private.c mediastreamer2_tester_private.h \
mediastreamer2_basic_audio_tester.c mediastreamer2_sound_card_tester.c
mediastreamer2_tester_CFLAGS=$(CUNIT_CFLAGS) $(STRICT_OPTIONS) $(ORTP_CFLAGS)
......
/*
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 "private.h"
#include "mediastreamer2_tester.h"
#include "mediastreamer2_tester_private.h"
#include <stdio.h>
#include "CUnit/Basic.h"
#ifdef _MSC_VER
#define unlink _unlink
#endif
static int basic_audio_tester_init(void) {
ms_init();
ms_filter_enable_statistics(TRUE);
ortp_init();
return 0;
}
static int basic_audio_tester_cleanup(void) {
ms_exit();
return 0;
}
static void tone_detected_cb(void *data, MSFilter *f, unsigned int event_id, MSToneDetectorEvent *ev) {
MS_UNUSED(data), MS_UNUSED(f), MS_UNUSED(event_id), MS_UNUSED(ev);
ms_tester_tone_detected = TRUE;
}
static void dtmfgen_tonedet(void) {
MSConnectionHelper h;
unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK;
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_create_filters(filter_mask);
ms_filter_set_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_link(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_link(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_link(&h, ms_tester_voidsink, 0, -1);
ms_ticker_attach(ms_tester_ticker, ms_tester_voidsource);
ms_tester_tone_generation_and_detection_loop();
ms_ticker_detach(ms_tester_ticker, ms_tester_voidsource);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_unlink(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1);
ms_filter_log_statistics();
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
}
static void dtmfgen_enc_dec_tonedet(void) {
MSConnectionHelper h;
unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_ENCODER
| FILTER_MASK_DECODER | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK;
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_create_filters(filter_mask);
ms_filter_set_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_link(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_link(&h, ms_tester_encoder, 0, 0);
ms_connection_helper_link(&h, ms_tester_decoder, 0, 0);
ms_connection_helper_link(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_link(&h, ms_tester_voidsink, 0, -1);
ms_ticker_attach(ms_tester_ticker, ms_tester_voidsource);
ms_tester_tone_generation_and_detection_loop();
ms_ticker_detach(ms_tester_ticker, ms_tester_voidsource);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_unlink(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_encoder, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_decoder, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1);
ms_filter_log_statistics();
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
}
static void dtmfgen_enc_rtp_dec_tonedet(void) {
MSConnectionHelper h;
RtpSession *rtps;
unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_ENCODER
| FILTER_MASK_RTPSEND | FILTER_MASK_RTPRECV | FILTER_MASK_DECODER | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK;
ms_filter_reset_statistics();
ms_tester_create_ticker();
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);
rtp_session_set_remote_addr_full(rtps, "127.0.0.1", 50060, NULL, 0);
rtp_session_set_payload_type(rtps, 8);
rtp_session_enable_rtcp(rtps,FALSE);
ms_filter_call_method(ms_tester_rtprecv, MS_RTP_RECV_SET_SESSION, rtps);
ms_filter_call_method(ms_tester_rtpsend, MS_RTP_SEND_SET_SESSION, rtps);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_link(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_link(&h, ms_tester_encoder, 0, 0);
ms_connection_helper_link(&h, ms_tester_rtpsend, 0, -1);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_rtprecv, -1, 0);
ms_connection_helper_link(&h, ms_tester_decoder, 0, 0);
ms_connection_helper_link(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_link(&h, ms_tester_voidsink, 0, -1);
ms_ticker_attach_multiple(ms_tester_ticker, ms_tester_voidsource, ms_tester_rtprecv, NULL);
ms_tester_tone_generation_and_detection_loop();
ms_ticker_detach(ms_tester_ticker, ms_tester_voidsource);
ms_ticker_detach(ms_tester_ticker, ms_tester_rtprecv);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_unlink(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_encoder, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_rtpsend, 0, -1);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, ms_tester_rtprecv, -1, 0);
ms_connection_helper_unlink(&h, ms_tester_decoder, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1);
ms_filter_log_statistics();
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
rtp_session_destroy(rtps);
}
#define DTMFGEN_FILE_NAME "dtmfgen_file.raw"
static void dtmfgen_filerec_fileplay_tonedet(void) {
MSConnectionHelper h;
unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_FILEREC
| FILTER_MASK_FILEPLAY | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK;
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_create_filters(filter_mask);
ms_filter_set_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL);
// Generate tones and save them to a file
ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_CLOSE);
ms_filter_call_method(ms_tester_filerec, MS_FILE_REC_OPEN, DTMFGEN_FILE_NAME);
ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_START);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_link(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_link(&h, ms_tester_filerec, 0, -1);
ms_ticker_attach(ms_tester_ticker, ms_tester_voidsource);
ms_tester_tone_generation_loop();
ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_CLOSE);
ms_ticker_detach(ms_tester_ticker, ms_tester_voidsource);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, ms_tester_voidsource, -1, 0);
ms_connection_helper_unlink(&h, ms_tester_dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_filerec, 0, -1);
// Read the previous file and detect the tones
ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE);
ms_filter_call_method(ms_tester_fileplay, MS_FILE_PLAYER_OPEN, DTMFGEN_FILE_NAME);
ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_START);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_fileplay, -1, 0);
ms_connection_helper_link(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_link(&h, ms_tester_voidsink, 0, -1);
ms_ticker_attach(ms_tester_ticker, ms_tester_fileplay);
ms_tester_tone_detection_loop();
ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE);
ms_ticker_detach(ms_tester_ticker, ms_tester_fileplay);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, ms_tester_fileplay, -1, 0);
ms_connection_helper_unlink(&h, ms_tester_tonedet, 0, 0);
ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1);
ms_filter_log_statistics();
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
unlink(DTMFGEN_FILE_NAME);
}
test_t basic_audio_tests[] = {
{ "dtmfgen-tonedet", dtmfgen_tonedet },
{ "dtmfgen-enc-dec-tonedet", dtmfgen_enc_dec_tonedet },
{ "dtmfgen-enc-rtp-dec-tonedet", dtmfgen_enc_rtp_dec_tonedet },
{ "dtmfgen-filerec-fileplay-tonedet", dtmfgen_filerec_fileplay_tonedet }
};
test_suite_t basic_audio_test_suite = {
"Basic Audio",
basic_audio_tester_init,
basic_audio_tester_cleanup,
sizeof(basic_audio_tests) / sizeof(basic_audio_tests[0]),
basic_audio_tests
};
/*
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 "private.h"
#include <stdio.h>
#include "CUnit/Basic.h"
#ifdef _MSC_VER
#define unlink _unlink
#endif
typedef struct {
MSDtmfGenCustomTone generated_tone;
MSToneDetectorDef expected_tone;
} tone_test_def_t;
static tone_test_def_t tone_definition[] = {
{ { 400, 2000, 0.6f, 0 }, { "", 2000, 300, 0.5f } },
{ { 600, 1500, 1.0f, 0 }, { "", 1500, 500, 0.9f } },
{ { 500, 941, 0.8f, 0 }, { "", 941, 400, 0.7f } }
};
static MSTicker *ticker = NULL;
static MSFilter *fileplay = NULL;
static MSFilter *filerec = NULL;
static MSFilter *dtmfgen = NULL;
static MSFilter *tonedet = NULL;
static MSFilter *voidsource = NULL;
static MSFilter *voidsink = NULL;
static MSFilter *encoder = NULL;
static MSFilter *decoder = NULL;
static MSFilter *rtprecv = NULL;
static MSFilter *rtpsend = NULL;
static MSFilter *resampler = NULL;
static MSFilter *soundwrite = NULL;
static unsigned char tone_detected;
static int dtmfgen_tester_init(void) {
ms_init();
ms_filter_enable_statistics(TRUE);
ortp_init();
return 0;
}
static int dtmfgen_tester_cleanup(void) {
ms_exit();
return 0;
}
static MSTicker * create_ticker(void) {
MSTickerParams params = { 0 };
params.name = "Tester MSTicker";
params.prio = MS_TICKER_PRIO_NORMAL;
return ms_ticker_new_with_params(&params);
}
static void tone_detected_cb(void *data, MSFilter *f, unsigned int event_id, MSToneDetectorEvent *ev) {
MS_UNUSED(data), MS_UNUSED(f), MS_UNUSED(event_id), MS_UNUSED(ev);
tone_detected = TRUE;
}
static void common_init(void) {
ms_filter_reset_statistics();
ticker = create_ticker();
CU_ASSERT_PTR_NOT_NULL_FATAL(ticker);
voidsource = ms_filter_new(MS_VOID_SOURCE_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(voidsource);
dtmfgen = ms_filter_new(MS_DTMF_GEN_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(dtmfgen);
tonedet = ms_filter_new(MS_TONE_DETECTOR_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(tonedet);
ms_filter_set_notify_callback(tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL);
voidsink = ms_filter_new(MS_VOID_SINK_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(voidsink);
}
static void common_uninit(void) {
ms_filter_destroy(voidsink);
ms_filter_destroy(tonedet);
ms_filter_destroy(dtmfgen);
ms_filter_destroy(voidsource);
ms_ticker_destroy(ticker);
ms_filter_log_statistics();
}
static void tone_generation_loop(void) {
unsigned int i;
for (i = 0; i < (sizeof(tone_definition) / sizeof(tone_definition[0])); i++) {
ms_filter_call_method(dtmfgen, MS_DTMF_GEN_PLAY_CUSTOM, &tone_definition[i].generated_tone);
ms_sleep(1);
}
}
static void tone_detection_loop(void) {
unsigned int i;
for (i = 0; i < (sizeof(tone_definition) / sizeof(tone_definition[0])); i++) {
tone_detected = FALSE;
ms_filter_call_method(tonedet, MS_TONE_DETECTOR_CLEAR_SCANS, NULL);
ms_filter_call_method(tonedet, MS_TONE_DETECTOR_ADD_SCAN, &tone_definition[i].expected_tone);
ms_sleep(1);
CU_ASSERT_EQUAL(tone_detected, TRUE);
}
}
static void tone_generation_and_detection_loop(void) {
unsigned int i;
for (i = 0; i < (sizeof(tone_definition) / sizeof(tone_definition[0])); i++) {
tone_detected = FALSE;
ms_filter_call_method(tonedet, MS_TONE_DETECTOR_CLEAR_SCANS, NULL);
ms_filter_call_method(tonedet, MS_TONE_DETECTOR_ADD_SCAN, &tone_definition[i].expected_tone);
ms_filter_call_method(dtmfgen, MS_DTMF_GEN_PLAY_CUSTOM, &tone_definition[i].generated_tone);
ms_sleep(1);
CU_ASSERT_EQUAL(tone_detected, TRUE);
}
}
static void configure_resampler(MSFilter *resampler, MSFilter *from, MSFilter *to) {
int from_rate = 0, to_rate = 0;
int from_channels = 0, to_channels = 0;
ms_filter_call_method(from, MS_FILTER_GET_SAMPLE_RATE, &from_rate);
ms_filter_call_method(to, MS_FILTER_GET_SAMPLE_RATE, &to_rate);
ms_filter_call_method(resampler, MS_FILTER_SET_SAMPLE_RATE, &from_rate);
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);
ms_filter_call_method(resampler, MS_FILTER_SET_NCHANNELS, &from_channels);
ms_filter_call_method(resampler, MS_FILTER_SET_OUTPUT_NCHANNELS, &to_channels);
}
static void dtmfgen_direct(void) {
MSConnectionHelper h;
common_init();
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, voidsource, -1, 0);
ms_connection_helper_link(&h, dtmfgen, 0, 0);
ms_connection_helper_link(&h, tonedet, 0, 0);
ms_connection_helper_link(&h, voidsink, 0, -1);
ms_ticker_attach(ticker, voidsource);
tone_generation_and_detection_loop();
ms_ticker_detach(ticker, voidsource);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, voidsource, -1, 0);
ms_connection_helper_unlink(&h, dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, tonedet, 0, 0);
ms_connection_helper_unlink(&h, voidsink, 0, -1);
common_uninit();
}
static void dtmfgen_codec(void) {
MSConnectionHelper h;
common_init();
encoder = ms_filter_new(MS_ALAW_ENC_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(encoder);
decoder = ms_filter_new(MS_ALAW_DEC_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(decoder);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, voidsource, -1, 0);
ms_connection_helper_link(&h, dtmfgen, 0, 0);
ms_connection_helper_link(&h, encoder, 0, 0);
ms_connection_helper_link(&h, decoder, 0, 0);
ms_connection_helper_link(&h, tonedet, 0, 0);
ms_connection_helper_link(&h, voidsink, 0, -1);
ms_ticker_attach(ticker, voidsource);
tone_generation_and_detection_loop();
ms_ticker_detach(ticker, voidsource);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, voidsource, -1, 0);
ms_connection_helper_unlink(&h, dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, encoder, 0, 0);
ms_connection_helper_unlink(&h, decoder, 0, 0);
ms_connection_helper_unlink(&h, tonedet, 0, 0);
ms_connection_helper_unlink(&h, voidsink, 0, -1);
ms_filter_destroy(decoder);
ms_filter_destroy(encoder);
common_uninit();
}
static void dtmfgen_rtp(void) {
MSConnectionHelper h;
RtpSession *rtps;
common_init();
rtps = create_duplex_rtpsession(50060, 0, FALSE);
rtp_session_set_remote_addr_full(rtps, "127.0.0.1", 50060, NULL, 0);
rtp_session_set_payload_type(rtps, 8);
rtp_session_enable_rtcp(rtps,FALSE);
encoder = ms_filter_new(MS_ALAW_ENC_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(encoder);
decoder = ms_filter_new(MS_ALAW_DEC_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(decoder);
rtprecv = ms_filter_new(MS_RTP_RECV_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(rtprecv);
ms_filter_call_method(rtprecv, MS_RTP_RECV_SET_SESSION, rtps);
rtpsend = ms_filter_new(MS_RTP_SEND_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(rtpsend);
ms_filter_call_method(rtpsend, MS_RTP_SEND_SET_SESSION, rtps);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, voidsource, -1, 0);
ms_connection_helper_link(&h, dtmfgen, 0, 0);
ms_connection_helper_link(&h, encoder, 0, 0);
ms_connection_helper_link(&h, rtpsend, 0, -1);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, rtprecv, -1, 0);
ms_connection_helper_link(&h, decoder, 0, 0);
ms_connection_helper_link(&h, tonedet, 0, 0);
ms_connection_helper_link(&h, voidsink, 0, -1);
ms_ticker_attach_multiple(ticker, voidsource, rtprecv, NULL);
tone_generation_and_detection_loop();
ms_ticker_detach(ticker, voidsource);
ms_ticker_detach(ticker, rtprecv);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, voidsource, -1, 0);
ms_connection_helper_unlink(&h, dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, encoder, 0, 0);
ms_connection_helper_unlink(&h, rtpsend, 0, -1);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, rtprecv, -1, 0);
ms_connection_helper_unlink(&h, decoder, 0, 0);
ms_connection_helper_unlink(&h, tonedet, 0, 0);
ms_connection_helper_unlink(&h, voidsink, 0, -1);
ms_filter_destroy(rtpsend);
ms_filter_destroy(rtprecv);
ms_filter_destroy(decoder);
ms_filter_destroy(encoder);
rtp_session_destroy(rtps);
common_uninit();
}
#define DTMFGEN_FILE_NAME "dtmfgen_file.raw"
static void dtmfgen_file(void) {
MSConnectionHelper h;
common_init();
filerec = ms_filter_new(MS_FILE_REC_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(filerec);
fileplay = ms_filter_new(MS_FILE_PLAYER_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(fileplay);
// Generate tones and save them to a file
ms_filter_call_method_noarg(filerec, MS_FILE_REC_CLOSE);
ms_filter_call_method(filerec, MS_FILE_REC_OPEN, DTMFGEN_FILE_NAME);
ms_filter_call_method_noarg(filerec, MS_FILE_REC_START);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, voidsource, -1, 0);
ms_connection_helper_link(&h, dtmfgen, 0, 0);
ms_connection_helper_link(&h, filerec, 0, -1);
ms_ticker_attach(ticker, voidsource);
tone_generation_loop();
ms_filter_call_method_noarg(filerec, MS_FILE_REC_CLOSE);
ms_ticker_detach(ticker, voidsource);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, voidsource, -1, 0);
ms_connection_helper_unlink(&h, dtmfgen, 0, 0);
ms_connection_helper_unlink(&h, filerec, 0, -1);
// Read the previous file and detect the tones
ms_filter_call_method_noarg(fileplay, MS_FILE_PLAYER_CLOSE);
ms_filter_call_method(fileplay, MS_FILE_PLAYER_OPEN, DTMFGEN_FILE_NAME);
ms_filter_call_method_noarg(fileplay, MS_FILE_PLAYER_START);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, fileplay, -1, 0);
ms_connection_helper_link(&h, tonedet, 0, 0);
ms_connection_helper_link(&h, voidsink, 0, -1);
ms_ticker_attach(ticker, fileplay);
tone_detection_loop();
ms_filter_call_method_noarg(fileplay, MS_FILE_PLAYER_CLOSE);
ms_ticker_detach(ticker, fileplay);
ms_connection_helper_start(&h);
ms_connection_helper_unlink(&h, fileplay, -1, 0);
ms_connection_helper_unlink(&h, tonedet, 0, 0);
ms_connection_helper_unlink(&h, voidsink, 0, -1);
ms_filter_destroy(filerec);
common_uninit();
unlink(DTMFGEN_FILE_NAME);
}
static void dtmfgen_soundwrite(void) {
MSConnectionHelper h;
MSSndCardManager *manager;
MSSndCard *playcard;
bool_t need_resampler = FALSE;
int sample_rate = 8000;
int nchannels = 1;
common_init();
manager = ms_snd_card_manager_get();
playcard = ms_snd_card_manager_get_default_playback_card(manager);
CU_ASSERT_PTR_NOT_NULL_FATAL(playcard);
soundwrite = ms_snd_card_create_writer(playcard);
CU_ASSERT_PTR_NOT_NULL_FATAL(soundwrite);
ms_filter_call_method(voidsource, MS_FILTER_SET_BITRATE, &sample_rate);
ms_filter_call_method(voidsource, MS_FILTER_SET_NCHANNELS, &nchannels);
ms_filter_call_method(dtmfgen, MS_FILTER_SET_BITRATE, &sample_rate);
ms_filter_call_method(dtmfgen, MS_FILTER_SET_NCHANNELS, &nchannels);
if (ms_filter_call_method(soundwrite, MS_FILTER_SET_BITRATE, &sample_rate) != 0) {
need_resampler = TRUE;
}
if (ms_filter_call_method(soundwrite, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) {
need_resampler = TRUE;
}
if (need_resampler == TRUE) {
resampler = ms_filter_new(MS_RESAMPLE_ID);
CU_ASSERT_PTR_NOT_NULL_FATAL(resampler);
configure_resampler(resampler, dtmfgen, soundwrite);
}
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, voidsource, -1, 0);
ms_connection_helper_link(&h, dtmfgen, 0, 0);
if (need_resampler == TRUE) {