player_tester.c 3.99 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) {
24
		ms_usleep(time_refresh * 1000U);
25 26 27 28 29
		*time += time_refresh;
	}
	return *time < timeout;
}

30 31 32
static void eof_callback(LinphonePlayer *player) {
	LinphonePlayerCbs *cbs = linphone_player_get_callbacks(player);
	bool_t *eof = (bool_t *)linphone_player_cbs_get_user_data(cbs);
33 34 35
	*eof = TRUE;
}

36
static void play_file(const char *filename, bool_t supported_format, const char *audio_mime, const char *video_mime) {
37
	LinphoneCoreManager *lc_manager = linphone_core_manager_new("marie_rc");
38
	LinphonePlayer *player;
39
	LinphonePlayerCbs *cbs;
40
	int res, timer = 0;
41 42
	bool_t eof = FALSE;

43 44 45
	bool_t audio_codec_supported = (audio_mime && ms_factory_get_decoder(linphone_core_get_ms_factory((void *)lc_manager->lc), audio_mime));
	bool_t video_codec_supported = (video_mime && ms_factory_get_decoder(linphone_core_get_ms_factory((void *)lc_manager->lc), video_mime));
	int expected_res = (supported_format && (audio_codec_supported || video_codec_supported)) ? 0 : -1;
46

47
	player = linphone_core_create_local_player(lc_manager->lc, linphone_core_get_ringer_device(lc_manager->lc), video_stream_get_default_video_renderer(), 0);
48
	BC_ASSERT_PTR_NOT_NULL(player);
49 50
	if(player == NULL) goto fail;

51 52 53 54
	cbs = linphone_player_get_callbacks(player);
	linphone_player_cbs_set_eof_reached(cbs, eof_callback);
	linphone_player_cbs_set_user_data(cbs, &eof);
	res = linphone_player_open(player, filename);
55 56
	BC_ASSERT_EQUAL(res, expected_res, int, "%d");

57 58
	if(res == -1) goto fail;

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

63
	BC_ASSERT_TRUE(wait_for_eof(&eof, &timer, 100, (int)(linphone_player_get_duration(player) * 1.05)));
64 65 66 67

	linphone_player_close(player);

	fail:
68
	if(player) linphone_player_unref(player);
69 70 71
	if(lc_manager) linphone_core_manager_destroy(lc_manager);
}

72
static void sintel_trailer_opus_h264_test(void) {
73
	char *filename = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv");
74
	const char *audio_mime = "opus";
75
	const char *video_mime = "H264";
76
	play_file(filename, linphone_local_player_matroska_supported(), audio_mime, video_mime);
77 78 79 80 81 82 83
	ms_free(filename);
}

static void sintel_trailer_pcmu_h264_test(void) {
	char *filename = bc_tester_res("sounds/sintel_trailer_pcmu_h264.mkv");
	const char *audio_mime = "pcmu";
	const char *video_mime = "H264";
84
	play_file(filename, linphone_local_player_matroska_supported(), audio_mime, video_mime);
85 86 87 88 89 90 91
	ms_free(filename);
}

static void sintel_trailer_opus_vp8_test(void) {
	char *filename = bc_tester_res("sounds/sintel_trailer_opus_vp8.mkv");
	const char *audio_mime = "opus";
	const char *video_mime = "VP8";
92
	play_file(filename, linphone_local_player_matroska_supported(), audio_mime, video_mime);
93
	ms_free(filename);
94 95
}

96
test_t player_tests[] = {
97 98 99
	TEST_NO_TAG("Sintel trailer opus/h264", sintel_trailer_opus_h264_test),
	TEST_NO_TAG("Sintel trailer pcmu/h264", sintel_trailer_pcmu_h264_test),
	TEST_NO_TAG("Sintel trailer opus/VP8", sintel_trailer_opus_vp8_test)
100 101
};

102
test_suite_t player_test_suite = {"Player", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
103
								  sizeof(player_tests) / sizeof(test_t), player_tests};