1
0
mirror of https://github.com/danog/php-libtgvoip.git synced 2024-11-26 20:04:48 +01:00

recursion

This commit is contained in:
Daniil Gentili 2017-07-18 20:46:22 +02:00
parent 9c68351925
commit 9cda5e42c8
3 changed files with 45 additions and 27 deletions

View File

@ -10,12 +10,12 @@
include $(CLEAR_VARS)
DEFINES = -DLIBTGVOIP_CUSTOM -DWEBRTC_POSIX -DTGVOIP_USE_DESKTOP_DSP -DWEBRTC_APM_DEBUG_DUMP=0
INCLUDES = -Ilibtgvoip -I/usr/include/opus -I/usr/local/ssl/include/ -Ilibtgvoip/webrtc_dsp -pthread $(shell php-config --includes)
LDINCLUDES = -L/usr/local/ssl/lib $(shell php-config --ldflags)
CXXFLAGS = ${INCLUDES} -O0 -Wall -c -std=c++11 -fpic -finline-functions -ffast-math -fno-strict-aliasing -DUSE_KISS_FFT -DFIXED_POINT -DPHP_LIBTGVOIP -DWEBRTC_POSIX -DTGVOIP_USE_DESKTOP_DSP -DWEBRTC_APM_DEBUG_DUMP=0 -g -DTGVOIP_USE_CXX11_LIB -DTGVOIP_OTHER ${DEFINES} -o
CFLAGS = ${INCLUDES} -O0 -DUSE_KISS_FFT -fexceptions -fpic ${DEFINES} -g
INCLUDES = -Ilibtgvoip -I/usr/include/opus -I/usr/local/ssl/include/ -Ilibtgvoip/webrtc_dsp -pthread
LDINCLUDES = -L/usr/local/ssl/lib
CXXFLAGS = ${INCLUDES} -O3 -Wall -c -std=c++11 -fpic -finline-functions -ffast-math -fno-strict-aliasing -DUSE_KISS_FFT -DFIXED_POINT -DPHP_LIBTGVOIP -DWEBRTC_POSIX -DTGVOIP_USE_DESKTOP_DSP -DWEBRTC_APM_DEBUG_DUMP=0 -g -DTGVOIP_USE_CXX11_LIB -DTGVOIP_OTHER ${DEFINES} -o
CFLAGS = ${INCLUDES} -O3 -DUSE_KISS_FFT -fexceptions -fpic ${DEFINES} -g
LFLAGS = -shared ${LDINCLUDES} -lphpcpp -lopus -lpthread -lstdc++ -lcrypto -lssl -pthread $(shell php-config --libs) -Wl,-z,defs -Wl,-undefined,_emalloc
LFLAGS = -shared ${LDINCLUDES} -lphpcpp -lopus -lpthread -lstdc++ -lcrypto -lssl -pthread -Wl,-z,defs
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
CXXFLAGS += -mfloat-abi=softfp -mfpu=neon

View File

@ -40,7 +40,8 @@ void VoIP::__construct(Php::Parameters &params)
self["internalStorage"]["created"] = params[1];
self["internalStorage"]["otherID"] = params[2];
self["internalStorage"]["callID"] = params[3];
self["internalStorage"]["callState"] = CALL_STATE_NONE;
self["internalStorage"]["madeline"] = params[4];
self["internalStorage"]["callState"] = params[5];
initVoIPController();
}
@ -53,18 +54,37 @@ void VoIP::initVoIPController() {
inst->SetStateCallback([](VoIPController *controller, int state) {
((VoIP *)controller->implData)->state = state;
if (state == STATE_FAILED) {
((VoIP *)controller->implData)->__destruct();
((VoIP *)controller->implData)->deinitVoIPController();
}
});
inst->Start();
}
void VoIP::__destruct() {
discard();
}
void VoIP::__destruct()
void VoIP::deinitVoIPController() {
if (inst) {
self["internalStorage"]["callState"] = CALL_STATE_ENDED;
delete inst;
}
}
void VoIP::discard()
{
destroyed = true;
delete inst;
self["internalStorage"]["madeline"].value().call("discard_call", self["internalStorage"]["callID"].value());
deinitVoIPController();
}
void VoIP::accept()
{
self["internalStorage"]["madeline"].value().call("accept_call", self["internalStorage"]["callID"].value());
deinitVoIPController();
}
void VoIP::__wakeup()
{
Php::Value self(this);
@ -153,7 +173,7 @@ void VoIP::parseConfig() {
char *key = (char *) malloc(256);
memcpy(key, self["configuration"]["auth_key"], 256);
inst->SetEncryptionKey(key, (bool) self["configuration"]["outgoing"]);
inst->SetEncryptionKey(key, (bool) self["internalStorage"]["creator"]);
free(key);
vector<Endpoint> eps;
@ -162,7 +182,6 @@ void VoIP::parseConfig() {
{
string ip = endpoints[i]["ip"];
string ipv6 = endpoints[i]["ipv6"];
string peer_tag = endpoints[i]["peer_tag"];
IPv4Address v4addr(ip);
IPv6Address v6addr("::0");
@ -173,9 +192,9 @@ void VoIP::parseConfig() {
v6addr = IPv6Address(ipv6);
}
if (peer_tag != "")
if (endpoints[i]["peer_tag"])
{
memcpy(pTag, peer_tag.c_str(), 16);
memcpy(pTag, endpoints[i]["peer_tag"], 16);
}
eps.push_back(Endpoint(endpoints[i]["id"], (int32_t)endpoints[i]["port"], v4addr, v6addr, EP_TYPE_UDP_RELAY, pTag));
@ -265,11 +284,6 @@ Php::Value VoIP::getState()
return state;
}
Php::Value VoIP::isDestroyed()
{
return destroyed;
}
Php::Value VoIP::isPlaying()
{
return playing;
@ -344,15 +358,16 @@ PHPCPP_EXPORT void *get_module()
voip.method<&VoIP::isCreator>("isCreator", Php::Public | Php::Final);
voip.method<&VoIP::whenCreated>("whenCreated", Php::Public | Php::Final);
voip.method<&VoIP::isPlaying>("isPlaying", Php::Public | Php::Final);
voip.method<&VoIP::isDestroyed>("isDestroyed", Php::Public | Php::Final);
voip.method<&VoIP::getOutputState>("getOutputState", Php::Public | Php::Final);
voip.method<&VoIP::getInputState>("getInputState", Php::Public | Php::Final);
voip.method<&VoIP::getOutputParams>("getOutputParams", Php::Public | Php::Final);
voip.method<&VoIP::getInputParams>("getInputParams", Php::Public | Php::Final);
voip.method<&VoIP::__destruct>("__destruct", Php::Public | Php::Final);
voip.method<&VoIP::discard>("discard", Php::Public | Php::Final);
voip.method<&VoIP::accept>("accept", Php::Public | Php::Final);
voip.method<&VoIP::__construct>("__construct", Php::Public | Php::Final, {
Php::ByVal("creator", Php::Type::Bool), Php::ByVal("created", Php::Type::Numeric), Php::ByVal("otherID", Php::Type::Numeric), Php::ByVal("callID")
Php::ByVal("creator", Php::Type::Bool), Php::ByVal("created", Php::Type::Numeric), Php::ByVal("otherID", Php::Type::Numeric), Php::ByVal("callID"), Php::ByRef("madeline", Php::Type::Object), Php::ByVal("callState", Php::Type::Numeric)
});
voip.method<&VoIP::__wakeup>("__wakeup", Php::Public | Php::Final);
voip.method<&VoIP::setMicMute>("setMicMute", Php::Public | Php::Final, {
@ -419,8 +434,8 @@ PHPCPP_EXPORT void *get_module()
voip.constant("AUDIO_STATE_CONFIGURED", AUDIO_STATE_CONFIGURED);
voip.constant("AUDIO_STATE_RUNNING", AUDIO_STATE_RUNNING);
voip.constant("CALL_STATE_NONE", CALL_STATE_NONE);
voip.constant("CALL_STATE_REQUESTED", CALL_STATE_REQUESTED);
voip.constant("CALL_STATE_INCOMING", CALL_STATE_INCOMING);
voip.constant("CALL_STATE_ACCEPTED", CALL_STATE_ACCEPTED);
voip.constant("CALL_STATE_CONFIRMED", CALL_STATE_CONFIRMED);
voip.constant("CALL_STATE_READY", CALL_STATE_READY);

13
main.h
View File

@ -26,12 +26,12 @@ If not, see <http://www.gnu.org/licenses/>.
#define AUDIO_STATE_CONFIGURED 1
#define AUDIO_STATE_RUNNING 2
#define CALL_STATE_NONE -1
#define CALL_STATE_REQUESTED 0
#define CALL_STATE_ACCEPTED 1
#define CALL_STATE_CONFIRMED 2
#define CALL_STATE_READY 3
#define CALL_STATE_ENDED 4
#define CALL_STATE_INCOMING 1
#define CALL_STATE_ACCEPTED 2
#define CALL_STATE_CONFIRMED 3
#define CALL_STATE_READY 4
#define CALL_STATE_ENDED 5
using namespace tgvoip;
using namespace tgvoip::audio;
@ -50,6 +50,9 @@ public:
void __construct(Php::Parameters &params);
void initVoIPController();
void __destruct();
void discard();
void accept();
void deinitVoIPController();
void __wakeup();
void startTheMagic();