Liblinphone 5.2.0

Basic call

This program is a very simple usage example of liblinphone.

This program is a very simple usage example of liblinphone.

It just takes a sip-uri as first argument and attempts to call it

/*
* Copyright (c) 2010-2022 Belledonne Communications SARL.
*
* This file is part of Liblinphone
* (see https://gitlab.linphone.org/BC/public/liblinphone).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "linphone/core.h"
#include <signal.h>
static bool_t running=TRUE;
static void stop(int signum){
running=FALSE;
}
/*
* Call state notification callback
*/
static void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg){
switch(cstate){
case LinphoneCallOutgoingRinging:
printf("It is now ringing remotely !\n");
break;
case LinphoneCallOutgoingEarlyMedia:
printf("Receiving some early media\n");
break;
case LinphoneCallConnected:
printf("We are connected !\n");
break;
case LinphoneCallStreamsRunning:
printf("Media streams established !\n");
break;
case LinphoneCallEnd:
printf("Call is terminated.\n");
break;
case LinphoneCallError:
printf("Call failure !");
break;
default:
printf("Unhandled notification %i\n",cstate);
}
}
int main(int argc, char *argv[]){
LinphoneCoreVTable vtable={0};
LinphoneCore *lc;
LinphoneCall *call=NULL;
const char *dest=NULL;
/* take the destination sip uri from the command line arguments */
if (argc>1){
dest=argv[1];
}
signal(SIGINT,stop);
#ifdef DEBUG_LOGS
linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
#endif
/*
Fill the LinphoneCoreVTable with application callbacks.
All are optional. Here we only use the call_state_changed callbacks
in order to get notifications about the progress of the call.
*/
vtable.call_state_changed=call_state_changed;
/*
Instanciate a LinphoneCore object given the LinphoneCoreVTable
*/
lc=linphone_core_new(&vtable,NULL,NULL,NULL);
if (dest){
/*
Place an outgoing call
*/
call=linphone_core_invite(lc,dest);
if (call==NULL){
printf("Could not place call to %s\n",dest);
goto end;
}else printf("Call to %s is in progress...",dest);
linphone_call_ref(call);
}
/* main loop for receiving notifications and doing background linphonecore work: */
while(running){
linphone_core_iterate(lc);
ms_usleep(50000);
}
if (call && linphone_call_get_state(call)!=LinphoneCallEnd){
/* terminate the call */
printf("Terminating the call...\n");
linphone_core_terminate_call(lc,call);
/*at this stage we don't need the call object */
linphone_call_unref(call);
}
end:
printf("Shutting down...\n");
linphone_core_destroy(lc);
printf("Exited\n");
return 0;
}
linphone_core_terminate_call
MS2_DEPRECATED LinphoneStatus linphone_core_terminate_call(LinphoneCore *core, LinphoneCall *call)
Terminates a call.
linphone_core_invite
LinphoneCall * linphone_core_invite(LinphoneCore *core, const char *url)
Initiates an outgoing call.
linphone_call_get_state
LinphoneCallState linphone_call_get_state(const LinphoneCall *call)
Retrieves the call's current state.
LinphoneCall
struct _LinphoneCall LinphoneCall
This object represents a call issued or received by the LinphoneCore.
Definition c-types.h:254
LinphoneCallState
enum _LinphoneCallState LinphoneCallState
LinphoneCallState enum represents the different states a call can reach into.
linphone_call_ref
LinphoneCall * linphone_call_ref(LinphoneCall *call)
Acquire a reference to the call.
linphone_call_unref
void linphone_call_unref(LinphoneCall *call)
Release reference to the call.
linphone_core_iterate
void linphone_core_iterate(LinphoneCore *core)
Main loop function.
linphone_core_new
MS2_DEPRECATED LinphoneCore * linphone_core_new(const LinphoneCoreVTable *vtable, const char *config_path, const char *factory_config_path, void *userdata)
Instanciates a LinphoneCore object.
LinphoneCore
struct _LinphoneCore LinphoneCore
Main object to instanciate and on which to keep a reference.
Definition types.h:479
linphone_core_destroy
MS2_DEPRECATED void linphone_core_destroy(LinphoneCore *core)
Destroys a LinphoneCore.
_LinphoneCoreVTable
This structure holds all callbacks that the application should implement.
Definition core.h:215
_LinphoneCoreVTable::call_state_changed
LinphoneCoreCallStateChangedCb call_state_changed
Notifies call state changes.
Definition core.h:218