mediastreamer2_player_tester.c 3.31 KB
Newer Older
François Grisez's avatar
François Grisez committed
1 2 3 4
#include "mediastreamer2_tester.h"
#include "../include/mediastreamer2/fileplayer.h"

static int tester_init() {
5
	ortp_set_log_level_mask(ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL);
François Grisez's avatar
François Grisez committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	ms_init();
	return 0;
}

static int tester_cleanup() {
	ms_exit();
	return 0;
}

typedef struct _Eof {
	bool_t eof;
	int time_ms;
	ms_mutex_t mutex;
} Eof;

static void eof_init(Eof *obj) {
	obj->eof = FALSE;
	obj->time_ms = 0;
	ms_mutex_init(&obj->mutex, NULL);
}

static void eof_callback(void *user_data) {
	Eof *obj = (Eof *)user_data;
	ms_mutex_lock(&obj->mutex);
	obj->eof = TRUE;
	ms_mutex_unlock(&obj->mutex);
}

static void wait_for_eof(Eof *obj, int refresh_time_ms, int timeout_ms) {
	ms_mutex_lock(&obj->mutex);
	while(obj->time_ms < timeout_ms && !obj->eof) {
		ms_mutex_unlock(&obj->mutex);
38
		ms_usleep((useconds_t)(refresh_time_ms) * 1000U);
François Grisez's avatar
François Grisez committed
39 40 41 42 43 44
		obj->time_ms += refresh_time_ms;
		ms_mutex_lock(&obj->mutex);
	}
	ms_mutex_unlock(&obj->mutex);
}

François Grisez's avatar
François Grisez committed
45
static void play_file(const char *filepath, bool_t unsupported_format) {
François Grisez's avatar
François Grisez committed
46 47
	bool_t succeed;
	Eof eof;
48
	MSFilePlayer *file_player = NULL;
François Grisez's avatar
François Grisez committed
49
	MSSndCard *snd_card = ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
François Grisez's avatar
François Grisez committed
50 51 52 53
	const char *display_name = video_stream_get_default_video_renderer();

	eof_init(&eof);

54
	file_player = ms_file_player_new(snd_card, display_name, NULL);
François Grisez's avatar
François Grisez committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
	CU_ASSERT_PTR_NOT_NULL(file_player);
	if(file_player == NULL) return;

	ms_file_player_set_eof_callback(file_player, eof_callback, &eof);

	succeed = ms_file_player_open(file_player, filepath);
	if(unsupported_format) {
		CU_ASSERT_FALSE(succeed);
	} else {
		CU_ASSERT_TRUE(succeed);
	}
	if(!succeed) {
		ms_file_player_free(file_player);
		return;
	}

	succeed = ms_file_player_start(file_player);
	CU_ASSERT_TRUE(succeed);

	if(succeed) {
		wait_for_eof(&eof, 100, 20000);
	}

	ms_file_player_close(file_player);
	ms_file_player_free(file_player);
	CU_ASSERT_TRUE(eof.eof);
}

static void play_hello_8000_wav(void) {
François Grisez's avatar
François Grisez committed
84
	play_file("./sounds/hello8000.wav", FALSE);
François Grisez's avatar
François Grisez committed
85 86 87
}

static void play_hello_16000_wav(void) {
François Grisez's avatar
François Grisez committed
88
	play_file("./sounds/hello16000.wav", FALSE);
François Grisez's avatar
François Grisez committed
89 90 91
}

static void play_hello_pcmu_mka(void) {
François Grisez's avatar
François Grisez committed
92
	play_file("./sounds/hello_pcmu.mka", !ms_file_player_matroska_supported());
François Grisez's avatar
François Grisez committed
93 94 95
}

static void play_hello_opus_mka(void) {
François Grisez's avatar
François Grisez committed
96
	play_file("./sounds/hello_opus.mka", !ms_file_player_matroska_supported());
François Grisez's avatar
François Grisez committed
97 98 99
}

static void play_hello_pcmu_h264_mkv(void) {
François Grisez's avatar
François Grisez committed
100
	play_file("./sounds/hello_pcmu_h264.mkv", !ms_file_player_matroska_supported());
François Grisez's avatar
François Grisez committed
101 102 103
}

static void play_hello_opus_h264_mkv(void) {
François Grisez's avatar
François Grisez committed
104
	play_file("./sounds/hello_opus_h264.mkv", !ms_file_player_matroska_supported());
105 106 107
}

static void play_sintel(void) {
François Grisez's avatar
François Grisez committed
108
	play_file("./sounds/sintel.mkv", !ms_file_player_matroska_supported());
François Grisez's avatar
François Grisez committed
109 110 111
}

static test_t tests[] = {
112 113 114 115 116 117
	{	"Play hello8000.wav"                ,	play_hello_8000_wav               },
	{	"Play hello16000.wav"               ,	play_hello_16000_wav              },
	{	"Play hello_pcmu.mka"               ,	play_hello_pcmu_mka               },
	{	"Play hello_opus.mka"               ,	play_hello_opus_mka               },
	{	"Play hello_pcmu_h264.mkv"          ,	play_hello_pcmu_h264_mkv          },
	{	"Play hello_opus_h264.mkv"          ,	play_hello_opus_h264_mkv          },
François Grisez's avatar
François Grisez committed
118
	{	"Play sintel"                       ,	play_sintel                       }
François Grisez's avatar
François Grisez committed
119 120 121 122 123 124 125 126 127
};

test_suite_t player_test_suite = {
	"Player",
	tester_init,
	tester_cleanup,
	sizeof(tests)/sizeof(test_t),
	tests
};