ringtoneplayer.c 3.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
linphone
Copyright (C) 2000  Simon MORLAT (simon.morlat@linphone.org)
Copyright (C) 2010  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, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 20
*/

21
#include "private.h"
22
#include <mediastreamer2/msfactory.h>
23

24 25 26 27
#if __APPLE__
#include "TargetConditionals.h"
#endif

28
LinphoneStatus linphone_ringtoneplayer_start(MSFactory *factory, LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms) {
29
	return linphone_ringtoneplayer_start_with_cb(factory, rp, card, ringtone, loop_pause_ms, NULL, NULL);
30 31
}

32
#if TARGET_OS_IPHONE
33

34
#include "ringtoneplayer_ios.h"
35 36 37 38 39 40 41 42 43

LinphoneRingtonePlayer* linphone_ringtoneplayer_new() {
	return linphone_ringtoneplayer_ios_new();
}

void linphone_ringtoneplayer_destroy(LinphoneRingtonePlayer* rp) {
	linphone_ringtoneplayer_ios_destroy(rp);
}

Brieuc Viel's avatar
Brieuc Viel committed
44
int linphone_ringtoneplayer_start_with_cb(MSFactory* f, LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms, LinphoneRingtonePlayerFunc end_of_ringtone, void * user_data) {
45 46 47 48 49 50 51 52
	if (linphone_ringtoneplayer_is_started(rp)) {
		ms_message("the local ringtone is already started");
		return 2;
	}
	if (ringtone){
		return linphone_ringtoneplayer_ios_start_with_cb(rp, ringtone, loop_pause_ms, end_of_ringtone, user_data);
	}
	return 3;
53 54 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 84 85 86 87 88 89 90
}

bool_t linphone_ringtoneplayer_is_started(LinphoneRingtonePlayer* rp) {
	return linphone_ringtoneplayer_ios_is_started(rp);
}

int linphone_ringtoneplayer_stop(LinphoneRingtonePlayer* rp) {
	return linphone_ringtoneplayer_ios_stop(rp);
}


#else

struct _LinphoneRingtonePlayer {
	RingStream *ringstream;
	LinphoneRingtonePlayerFunc end_of_ringtone;
	void* end_of_ringtone_ud;
};

LinphoneRingtonePlayer* linphone_ringtoneplayer_new() {
	LinphoneRingtonePlayer* rp = ms_new0(LinphoneRingtonePlayer, 1);
	return rp;
}

void linphone_ringtoneplayer_destroy(LinphoneRingtonePlayer* rp) {
	if (rp->ringstream) {
		linphone_ringtoneplayer_stop(rp);
	}
	ms_free(rp);
}

static void notify_end_of_ringtone(void *ud, MSFilter *f, unsigned int event, void *arg){
	LinphoneRingtonePlayer *rp=(LinphoneRingtonePlayer*)ud;
	if (event==MS_PLAYER_EOF && rp->end_of_ringtone){
		rp->end_of_ringtone(rp, rp->end_of_ringtone_ud, 0);
	}
}

91
LinphoneStatus linphone_ringtoneplayer_start_with_cb(MSFactory *factory, LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms, LinphoneRingtonePlayerFunc end_of_ringtone, void * user_data) {
92 93 94 95 96 97 98 99
	if (linphone_ringtoneplayer_is_started(rp)) {
		ms_message("the local ringtone is already started");
		return 2;
	}
	if (card!=NULL && ringtone){
		ms_message("Starting local ringtone...");
		rp->end_of_ringtone = end_of_ringtone;
		rp->end_of_ringtone_ud = user_data;
100
		rp->ringstream=ring_start_with_cb(factory, ringtone,loop_pause_ms,card,notify_end_of_ringtone,rp);
101 102 103 104 105 106 107 108 109
		return rp->ringstream != NULL ? 0 : 1;
	}
	return 3;
}

bool_t linphone_ringtoneplayer_is_started(LinphoneRingtonePlayer* rp) {
	return (rp->ringstream!=NULL);
}

110
LinphoneStatus linphone_ringtoneplayer_stop(LinphoneRingtonePlayer* rp) {
111 112 113 114 115 116 117
	if (rp->ringstream) {
		ring_stop(rp->ringstream);
		rp->ringstream = NULL;
	}
	return 0;
}
#endif