player_tester.c 2.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
    liblinphone_tester - liblinphone test suite
    Copyright (C) 2013  Belledonne Communications SARL

    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, see <http://www.gnu.org/licenses/>.
*/

19
#include "liblinphone_tester.h"
20
#include <mediastreamer2/mediastream.h>
21

22 23
static bool_t wait_for_eof(bool_t *eof, int *time,int time_refresh, int timeout) {
	while(*time < timeout && !*eof) {
Simon Morlat's avatar
Simon Morlat committed
24
		ms_usleep(time_refresh * 1000U);
25 26 27 28 29 30 31 32 33 34
		*time += time_refresh;
	}
	return *time < timeout;
}

static void eof_callback(LinphonePlayer *player, void *user_data) {
	bool_t *eof = (bool_t *)user_data;
	*eof = TRUE;
}

35
static void play_file(const char *filename, bool_t unsupported_format, const char *audio_mime, const char *video_mime) {
36 37 38 39 40 41
	LinphoneCoreManager *lc_manager;
	LinphonePlayer *player;
	int res, time = 0;
	bool_t eof = FALSE;

	lc_manager = linphone_core_manager_new("marie_rc");
42
	BC_ASSERT_PTR_NOT_NULL(lc_manager);
43 44
	if(lc_manager == NULL) return;

45
	player = linphone_core_create_local_player(lc_manager->lc, ms_snd_card_manager_get_default_card(ms_snd_card_manager_get()), video_stream_get_default_video_renderer(), 0);
46
	BC_ASSERT_PTR_NOT_NULL(player);
47 48
	if(player == NULL) goto fail;

49
	res = linphone_player_open(player, filename, eof_callback, &eof);
50 51 52 53
	if(unsupported_format
			|| (audio_mime == NULL && video_mime == NULL)
			|| (video_mime == NULL && audio_mime && !ms_filter_codec_supported(audio_mime))
			|| (audio_mime == NULL && video_mime && !ms_filter_codec_supported(video_mime))) {
54
		BC_ASSERT_EQUAL(res, -1, int, "%d");
55
	} else {
56
		BC_ASSERT_EQUAL(res, 0, int, "%d");
57
	}
58 59
	if(res == -1) goto fail;

60
	res = linphone_player_start(player);
61
	BC_ASSERT_EQUAL(res, 0, int, "%d");
62 63
	if(res == -1) goto fail;

64
	BC_ASSERT_TRUE(wait_for_eof(&eof, &time, 100, 13000));
65 66 67 68

	linphone_player_close(player);

	fail:
69
	if(player) linphone_player_destroy(player);
70 71 72
	if(lc_manager) linphone_core_manager_destroy(lc_manager);
}

73
static void playing_test(void) {
74
	char *filename = bc_tester_res("sounds/hello_opus_h264.mkv");
75 76 77
	const char *audio_mime = "opus";
	const char *video_mime = "h264";
	play_file(filename, !linphone_local_player_matroska_supported(), audio_mime, video_mime);
78
	ms_free(filename);
79 80
}

81
test_t player_tests[] = {
82
	{	"Local MKV file"	,	playing_test	}
83 84
};

85 86
test_suite_t player_test_suite = {"Player", NULL, NULL, liblinphone_tester_before_each, NULL,
								  sizeof(player_tests) / sizeof(test_t), player_tests};