Commit 1d38074b authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Allow mediastreamer2 tests to run on devices with dynamic app location (not just ".").

This allows iOS tests to perform, as well as (soon) android.
parent 6371c224
......@@ -68,10 +68,10 @@ static int tester_cleanup(void) {
return 0;
}
#define HELLO_8K_1S_FILE SOUND_FILE_PATH "hello8000-1s.wav"
#define HELLO_16K_1S_FILE SOUND_FILE_PATH "hello16000-1s.wav"
#define RECORDED_8K_1S_FILE WRITE_FILE_PATH "recorded_hello8000-1s.wav"
#define RECORDED_16K_1S_FILE WRITE_FILE_PATH "recorded_hello16000-1s.wav"
#define HELLO_8K_1S_FILE "hello8000-1s.wav"
#define HELLO_16K_1S_FILE "hello16000-1s.wav"
#define RECORDED_8K_1S_FILE "recorded_hello8000-1s.wav"
#define RECORDED_16K_1S_FILE "recorded_hello16000-1s.wav"
typedef struct _stream_manager_t {
MSFormatType type;
......@@ -90,6 +90,8 @@ typedef struct _stream_manager_t {
float congestion_bw_estim;
} adaptive_stats;
void* user_data;
} stream_manager_t ;
stream_manager_t * stream_manager_new(MSFormatType type) {
......@@ -97,6 +99,7 @@ stream_manager_t * stream_manager_new(MSFormatType type) {
mgr->type=type;
mgr->local_rtp=(rand() % ((2^16)-1024) + 1024) & ~0x1;
mgr->local_rtcp=mgr->local_rtp+1;
mgr->user_data = 0;
if (mgr->type==MSAudio){
mgr->audio_stream=audio_stream_new (mgr->local_rtp, mgr->local_rtcp,FALSE);
......@@ -114,7 +117,10 @@ stream_manager_t * stream_manager_new(MSFormatType type) {
static void stream_manager_delete(stream_manager_t * mgr) {
if (mgr->type==MSAudio){
unlink(RECORDED_16K_1S_FILE);
if( mgr->user_data){
unlink((char*)mgr->user_data);
// don't reset user_data, it is up to the user to free() it
}
audio_stream_stop(mgr->audio_stream);
}else{
......@@ -198,6 +204,11 @@ void start_adaptive_stream(MSFormatType type, stream_manager_t ** pmarielle, str
#endif
stream_manager_t *marielle=*pmarielle=stream_manager_new(type);
stream_manager_t *margaux=*pmargaux=stream_manager_new(type);
char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_16K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_16K_1S_FILE);
marielle->user_data = recorded_file;
params.enabled=TRUE;
params.loss_rate=loss_rate;
params.max_bandwidth=max_bw;
......@@ -222,10 +233,10 @@ void start_adaptive_stream(MSFormatType type, stream_manager_t ** pmarielle, str
rtp_session_set_duplication_ratio(marielle_ms->sessions.rtp_session, dup_ratio);
if (marielle->type == MSAudio){
audio_manager_start(marielle,payload,margaux->local_rtp,initial_bitrate,HELLO_16K_1S_FILE,NULL);
audio_manager_start(marielle,payload,margaux->local_rtp,initial_bitrate,file,NULL);
ms_filter_call_method(marielle->audio_stream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
audio_manager_start(margaux,payload,marielle->local_rtp,0,NULL,RECORDED_16K_1S_FILE);
audio_manager_start(margaux,payload,marielle->local_rtp,0,NULL,recorded_file);
}else{
#if VIDEO_ENABLED
video_manager_start(marielle,payload,margaux->local_rtp,0,marielle_webcam);
......@@ -241,6 +252,10 @@ void start_adaptive_stream(MSFormatType type, stream_manager_t ** pmarielle, str
qos_analyzer_on_action_suggested,
*pmarielle);
rtp_session_enable_network_simulation(margaux_ms->sessions.rtp_session,&params);
ms_free(recorded_file);
ms_free(file);
}
static void iterate_adaptive_stream(stream_manager_t * marielle, stream_manager_t * margaux,
......
......@@ -65,10 +65,10 @@ static int tester_cleanup(void) {
#define MARGAUX_RTCP_PORT 9865
#define MARGAUX_IP "127.0.0.1"
#define HELLO_8K_1S_FILE SOUND_FILE_PATH "hello8000-1s.wav"
#define HELLO_16K_1S_FILE SOUND_FILE_PATH "hello16000-1s.wav"
#define RECORDED_8K_1S_FILE WRITE_FILE_PATH "recorded_hello8000-1s.wav"
#define RECORDED_16K_1S_FILE WRITE_FILE_PATH "recorded_hello16000-1s.wav"
#define HELLO_8K_1S_FILE "hello8000-1s.wav"
#define HELLO_16K_1S_FILE "hello16000-1s.wav"
#define RECORDED_8K_1S_FILE "recorded_hello8000-1s.wav"
#define RECORDED_16K_1S_FILE "recorded_hello16000-1s.wav"
typedef struct _stats_t {
......@@ -101,12 +101,16 @@ static void basic_audio_stream() {
AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE);
stats_t margaux_stats;
RtpProfile* profile = rtp_profile_new("default profile");
char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE);
reset_stats(&marielle_stats);
reset_stats(&margaux_stats);
rtp_profile_set_payload (profile,0,&payload_type_pcmu8000);
CU_ASSERT_EQUAL(audio_stream_start_full(margaux
, profile
, MARIELLE_IP
......@@ -116,7 +120,7 @@ static void basic_audio_stream() {
, 0
, 50
, NULL
, RECORDED_8K_1S_FILE
, recorded_file
, NULL
, NULL
, 0),0);
......@@ -129,7 +133,7 @@ static void basic_audio_stream() {
, MARGAUX_RTCP_PORT
, 0
, 50
, HELLO_8K_1S_FILE
, hello_file
, NULL
, NULL
, NULL
......@@ -148,7 +152,9 @@ static void basic_audio_stream() {
audio_stream_stop(marielle);
audio_stream_stop(margaux);
unlink(RECORDED_8K_1S_FILE);
unlink(recorded_file);
ms_free(recorded_file);
ms_free(hello_file);
}
#if 0
......
......@@ -197,13 +197,16 @@ static void dtmfgen_enc_rtp_dec_tonedet(void) {
rtp_session_destroy(rtps);
}
#define DTMFGEN_FILE_NAME WRITE_FILE_PATH "dtmfgen_file.raw"
#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;
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), DTMFGEN_FILE_NAME);
ms_filter_reset_statistics();
ms_tester_create_ticker();
ms_tester_create_filters(filter_mask);
......@@ -211,7 +214,7 @@ static void dtmfgen_filerec_fileplay_tonedet(void) {
// 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(ms_tester_filerec, MS_FILE_REC_OPEN, recorded_file);
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);
......@@ -228,7 +231,7 @@ static void dtmfgen_filerec_fileplay_tonedet(void) {
// 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(ms_tester_fileplay, MS_FILE_PLAYER_OPEN, recorded_file);
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);
......@@ -245,7 +248,8 @@ static void dtmfgen_filerec_fileplay_tonedet(void) {
ms_filter_log_statistics();
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
unlink(DTMFGEN_FILE_NAME);
unlink(recorded_file);
ms_free(recorded_file);
}
......
......@@ -245,8 +245,9 @@ static void inner_product_test(void) {
// we expect the result to be very similar and at least 5 times faster with NEON
CU_ASSERT(percent_off < 1.0);
CU_ASSERT(fast_enough);
ms_message("NEON = %llu ms, SOFT: %llu ms", neon_ms, soft_ms);
if( !fast_enough ){
ms_error("NEON not fast enough it seems: NEON = %llu ms, SOFT: %llu ms", neon_ms, soft_ms);
ms_error("NEON not fast enough it seems");
}
......
......@@ -117,36 +117,42 @@ static void play_file(const char *filepath, bool_t unsupported_format, bool_t se
ms_media_player_free(file_player);
}
static void play_root_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, bool_t play_twice, int timeout){
char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), filepath);
play_file(file, FALSE, FALSE, FALSE, 20000);
ms_free(file);
}
static void play_hello_8000_wav(void) {
play_file("./sounds/hello8000.wav", FALSE, FALSE, FALSE, 20000);
play_root_file("./sounds/hello8000.wav", FALSE, FALSE, FALSE, 20000);
}
static void play_hello_16000_wav(void) {
play_file("./sounds/hello16000.wav", FALSE, FALSE, FALSE, 20000);
play_root_file("./sounds/hello16000.wav", FALSE, FALSE, FALSE, 20000);
}
static void play_hello_pcmu_mka(void) {
play_file("./sounds/hello_pcmu.mka", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
play_root_file("./sounds/hello_pcmu.mka", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
}
static void play_hello_opus_mka(void) {
play_file("./sounds/hello_opus.mka", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
play_root_file("./sounds/hello_opus.mka", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
}
static void play_hello_pcmu_h264_mkv(void) {
play_file("./sounds/hello_pcmu_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
play_root_file("./sounds/hello_pcmu_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
}
static void play_hello_opus_h264_mkv(void) {
play_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
play_root_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
}
static void seeking_test(void) {
play_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), TRUE, FALSE, 15000);
play_root_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), TRUE, FALSE, 15000);
}
static void playing_twice_test(void) {
play_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, TRUE, 15000);
play_root_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, TRUE, 15000);
}
static test_t tests[] = {
......
......@@ -108,14 +108,14 @@ static void dtmfgen_soundwrite(void) {
ms_tester_destroy_ticker();
}
#define CHIMES_48000_STEREO_FILE_NAME SOUND_FILE_PATH "chimes_48000_stereo.wav"
#define BIRD_44100_STEREO_FILE_NAME SOUND_FILE_PATH "bird_44100_stereo.wav"
#define PUNCH_16000_STEREO_FILE_NAME SOUND_FILE_PATH "punch_16000_stereo.wav"
#define PIANO_8000_STEREO_FILE_NAME SOUND_FILE_PATH "piano_8000_stereo.wav"
#define NYLON_48000_MONO_FILE_NAME SOUND_FILE_PATH "nylon_48000_mono.wav"
#define OWL_44100_MONO_FILE_NAME SOUND_FILE_PATH "owl_44100_mono.wav"
#define LASERROCKET_16000_MONO_FILE_NAME SOUND_FILE_PATH "laserrocket_16000_mono.wav"
#define ARPEGGIO_8000_MONO_FILE_NAME SOUND_FILE_PATH "arpeggio_8000_mono.wav"
#define CHIMES_48000_STEREO_FILE_NAME "chimes_48000_stereo.wav"
#define BIRD_44100_STEREO_FILE_NAME "bird_44100_stereo.wav"
#define PUNCH_16000_STEREO_FILE_NAME "punch_16000_stereo.wav"
#define PIANO_8000_STEREO_FILE_NAME "piano_8000_stereo.wav"
#define NYLON_48000_MONO_FILE_NAME "nylon_48000_mono.wav"
#define OWL_44100_MONO_FILE_NAME "owl_44100_mono.wav"
#define LASERROCKET_16000_MONO_FILE_NAME "laserrocket_16000_mono.wav"
#define ARPEGGIO_8000_MONO_FILE_NAME "arpeggio_8000_mono.wav"
static void fileplay_eof(void *user_data, MSFilter *f, unsigned int event, void *event_data) {
if (event == MS_FILE_PLAYER_EOF) {
......@@ -184,36 +184,42 @@ static void fileplay_soundwrite(const char *filename) {
ms_tester_destroy_ticker();
}
static void fileplay_soundwrite_from_file(const char *filepath){
char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), filepath);
fileplay_soundwrite(file);
ms_free(file);
}
static void fileplay_soundwrite_48000_stereo(void) {
fileplay_soundwrite(CHIMES_48000_STEREO_FILE_NAME);
fileplay_soundwrite_from_file(CHIMES_48000_STEREO_FILE_NAME);
}
static void fileplay_soundwrite_44100_stereo(void) {
fileplay_soundwrite(BIRD_44100_STEREO_FILE_NAME);
fileplay_soundwrite_from_file(BIRD_44100_STEREO_FILE_NAME);
}
static void fileplay_soundwrite_16000_stereo(void) {
fileplay_soundwrite(PUNCH_16000_STEREO_FILE_NAME);
fileplay_soundwrite_from_file(PUNCH_16000_STEREO_FILE_NAME);
}
static void fileplay_soundwrite_8000_stereo(void) {
fileplay_soundwrite(PIANO_8000_STEREO_FILE_NAME);
fileplay_soundwrite_from_file(PIANO_8000_STEREO_FILE_NAME);
}
static void fileplay_soundwrite_48000_mono(void) {
fileplay_soundwrite(NYLON_48000_MONO_FILE_NAME);
fileplay_soundwrite_from_file(NYLON_48000_MONO_FILE_NAME);
}
static void fileplay_soundwrite_44100_mono(void) {
fileplay_soundwrite(OWL_44100_MONO_FILE_NAME);
fileplay_soundwrite_from_file(OWL_44100_MONO_FILE_NAME);
}
static void fileplay_soundwrite_16000_mono(void) {
fileplay_soundwrite(LASERROCKET_16000_MONO_FILE_NAME);
fileplay_soundwrite_from_file(LASERROCKET_16000_MONO_FILE_NAME);
}
static void fileplay_soundwrite_8000_mono(void) {
fileplay_soundwrite(ARPEGGIO_8000_MONO_FILE_NAME);
fileplay_soundwrite_from_file(ARPEGGIO_8000_MONO_FILE_NAME);
}
static void soundread_soundwrite(void) {
......@@ -347,7 +353,7 @@ static void soundread_speexenc_speexdec_soundwrite(void) {
ms_tester_destroy_ticker();
}
#define SOUNDREAD_FILE_NAME WRITE_FILE_PATH "soundread_file.raw"
#define SOUNDREAD_FILE_NAME "soundread_file.raw"
static void soundread_filerec_fileplay_soundwrite(void) {
MSConnectionHelper h;
......@@ -356,6 +362,7 @@ static void soundread_filerec_fileplay_soundwrite(void) {
int playback_sample_rate = 8000;
int capture_nchannels = 1;
int playback_nchannels = 1;
char *writable_filename = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), SOUNDREAD_FILE_NAME);
ms_filter_reset_statistics();
ms_tester_create_ticker();
......@@ -367,7 +374,7 @@ static void soundread_filerec_fileplay_soundwrite(void) {
ms_filter_call_method(ms_tester_filerec, MS_FILTER_SET_SAMPLE_RATE, &capture_sample_rate);
ms_filter_call_method(ms_tester_filerec, MS_FILTER_SET_NCHANNELS, &capture_nchannels);
ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_CLOSE);
ms_filter_call_method(ms_tester_filerec, MS_FILE_REC_OPEN, SOUNDREAD_FILE_NAME);
ms_filter_call_method(ms_tester_filerec, MS_FILE_REC_OPEN, writable_filename);
ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_START);
ms_connection_helper_start(&h);
ms_connection_helper_link(&h, ms_tester_soundread, -1, 0);
......@@ -389,7 +396,7 @@ static void soundread_filerec_fileplay_soundwrite(void) {
ms_tester_create_filter(&ms_tester_resampler, MS_RESAMPLE_ID);
}
ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE);
ms_filter_call_method(ms_tester_fileplay, MS_FILE_PLAYER_OPEN, SOUNDREAD_FILE_NAME);
ms_filter_call_method(ms_tester_fileplay, MS_FILE_PLAYER_OPEN, writable_filename);
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);
......@@ -417,7 +424,8 @@ static void soundread_filerec_fileplay_soundwrite(void) {
ms_tester_destroy_filters(filter_mask);
ms_tester_destroy_ticker();
unlink(SOUNDREAD_FILE_NAME);
unlink(writable_filename);
ms_free(writable_filename);
}
......
......@@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mediastreamer2_tester.h"
#include "mediastreamer2_tester_private.h"
#include <mediastreamer2/mediastream.h>
#if HAVE_CONFIG_H
......@@ -36,6 +37,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static test_suite_t **test_suite = NULL;
static int nb_test_suites = 0;
static const char* tester_fileroot = SOUND_FILE_PATH;
static const char* tester_writable_dir= WRITE_FILE_PATH;
#if HAVE_CU_CURSES
......@@ -96,6 +100,23 @@ static void list_suites() {
}
#endif
const char* mediastreamer2_tester_get_file_root(){
return tester_fileroot;
}
void mediastreamer2_tester_set_file_root(const char* fileroot){
tester_fileroot = fileroot;
}
const char* mediastreamer2_tester_get_writable_dir(){
return tester_writable_dir;
}
void mediastreamer2_tester_set_writable_dir(const char* writable_dir){
tester_writable_dir = writable_dir;
}
int mediastreamer2_tester_nb_test_suites(void) {
return nb_test_suites;
}
......
......@@ -70,6 +70,12 @@ extern void mediastreamer2_tester_init(void);
extern void mediastreamer2_tester_uninit(void);
extern int mediastreamer2_tester_run_tests(const char *suite_name, const char *test_name);
extern const char* mediastreamer2_tester_get_file_root();
/* without / at the end */
extern void mediastreamer2_tester_set_file_root(const char* fileroot);
extern const char* mediastreamer2_tester_get_writable_dir();
extern void mediastreamer2_tester_set_writable_dir(const char* writable_dir);
#if TARGET_OS_MAC || TARGET_OS_IPHONE
int apple_main(int argc, char *argv[]);
#endif
......
......@@ -33,7 +33,18 @@ void stop_handler(int sig) {
}
static void* _apple_main(void* data) {
NSString *bundlePath = [[[NSBundle mainBundle] bundlePath] retain];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [[paths objectAtIndex:0] retain];
NSLog(@"Bundle path: %@", bundlePath);
NSLog(@"Document path: %@", documentPath);
mediastreamer2_tester_set_file_root( [bundlePath UTF8String] );
mediastreamer2_tester_set_writable_dir( [documentPath UTF8String] );
apple_main(g_argc,g_argv);
[bundlePath release];
[documentPath release];
return NULL;
}
int main(int argc, char * argv[]) {
......
......@@ -41,7 +41,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#if __QNX__
#define WRITE_FILE_PATH "./tmp/"
#else
#define WRITE_FILE_PATH
#define WRITE_FILE_PATH "."
#endif
......
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