Ejemplo n.º 1
0
void CToxProto::UninitToxCore()
{
	if (tox)
	{
		for (size_t i = 0; i < transfers.Count(); i++)
		{
			FileTransferParam *transfer = transfers.GetAt(i);
			tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
			ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0);
			transfers.Remove(transfer);
		}

		//if (IsToxCoreInited())
		//{
		//	ptrA nickname(mir_utf8encodeW(ptrT(getTStringA("Nick"))));
		//	tox_set_name(tox, (uint8_t*)(char*)nickname, mir_strlen(nickname));

		//	//temporary
		//	ptrA statusmes(mir_utf8encodeW(ptrT(getTStringA("StatusMsg"))));
		//	tox_set_status_message(tox, (uint8_t*)(char*)statusmes, mir_strlen(statusmes));
		//}

		if (toxAv)
			toxav_kill(toxAv);

		SaveToxProfile();
		if (password != NULL)
		{
			mir_free(password);
			password = NULL;
		}
		tox_kill(tox);
		tox = NULL;
	}
}
Ejemplo n.º 2
0
void terminate_audio()
{
    int i;
    for (i = 0; i < MAX_CALLS; ++i)
        stop_transmission(&CallControl.calls[i], i);

    if ( CallControl.av )
        toxav_kill(CallControl.av);

    terminate_devices();
}
Ejemplo n.º 3
0
void terminate_audio()
{
    int i;
    for (i = 0; i < MAX_CALLS; i ++)
        stop_transmission(i);

    if ( ASettins.av )
        toxav_kill(ASettins.av);
    
    terminate_devices();
}
Ejemplo n.º 4
0
CoreAV::~CoreAV()
{
    for (const auto& call : calls) {
        cancelCall(call.first);
    }
    killTimerFromThread();
    toxav_kill(toxav);
    coreavThread->exit(0);
    while (coreavThread->isRunning()) {
        qApp->processEvents();
        coreavThread->wait(100);
    }
}
Ejemplo n.º 5
0
CoreAV::~CoreAV()
{
    for (const ToxFriendCall& call : calls)
        cancelCall(call.callId);
    killTimerFromThread();
    toxav_kill(toxav);
    coreavThread->exit(0);
    while (coreavThread->isRunning())
    {
        qApp->processEvents();
        coreavThread->wait(100);
    }
}
Ejemplo n.º 6
0
void Core::deadifyTox()
{
    if (toxav)
    {
        toxav_kill(toxav);
        toxav = nullptr;
    }
    if (tox)
    {
        tox_kill(tox);
        tox = nullptr;
    }
}
Ejemplo n.º 7
0
ToxAV *init_audio(ToxWindow *self, Tox *tox)
{
    TOXAV_ERR_NEW error;
    CallControl.audio_errors = ae_None;
    CallControl.prompt = self;
    CallControl.pending_call = false;

    CallControl.av = toxav_new(tox, &error);

    CallControl.audio_enabled = true;
    CallControl.audio_bit_rate = 48;
    CallControl.audio_sample_rate = 48000;
    CallControl.audio_frame_duration = 10;
    CallControl.audio_channels = 1;

#ifndef VIDEO
    CallControl.video_enabled = false;
    CallControl.video_bit_rate = 0;
    CallControl.video_frame_duration = 0;
#endif /* VIDEO */

    memset(CallControl.calls, 0, sizeof(CallControl.calls));

    if ( !CallControl.av ) {
        CallControl.audio_errors |= ae_StartingCoreAudio;
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init ToxAV");

        return NULL;
    }

    if ( init_devices(CallControl.av) == de_InternalError ) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");
        toxav_kill(CallControl.av);

        return CallControl.av = NULL;
    }

    toxav_callback_call(CallControl.av, call_cb, tox);
    toxav_callback_call_state(CallControl.av, callstate_cb, NULL);
    toxav_callback_audio_receive_frame(CallControl.av, receive_audio_frame_cb, NULL);

    return CallControl.av;
}
Ejemplo n.º 8
0
ToxAv *init_audio(ToxWindow *self, Tox *tox)
{    
    ASettins.cs = av_DefaultSettings;
    ASettins.cs.max_video_height = ASettins.cs.max_video_width = 0;
    
    ASettins.errors = ae_None;
    
    memset(ASettins.calls, 0, sizeof(Call) * 10);

    
    /* Streaming stuff from core */

    ASettins.av = toxav_new(tox, MAX_CALLS);

    if ( !ASettins.av ) {
        ASettins.errors |= ae_StartingCoreAudio;
        return NULL;
    }
    
    if ( init_devices(ASettins.av) == de_InternalError ) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");
        toxav_kill(ASettins.av);
        return ASettins.av = NULL;
    }

    toxav_register_callstate_callback(ASettins.av, callback_call_started, av_OnStart, self);
    toxav_register_callstate_callback(ASettins.av, callback_call_canceled, av_OnCancel, self);
    toxav_register_callstate_callback(ASettins.av, callback_call_rejected, av_OnReject, self);
    toxav_register_callstate_callback(ASettins.av, callback_call_ended, av_OnEnd, self);
    toxav_register_callstate_callback(ASettins.av, callback_recv_invite, av_OnInvite, self);

    toxav_register_callstate_callback(ASettins.av, callback_recv_ringing, av_OnRinging, self);
    toxav_register_callstate_callback(ASettins.av, callback_recv_starting, av_OnStarting, self);
    toxav_register_callstate_callback(ASettins.av, callback_recv_ending, av_OnEnding, self);

    toxav_register_callstate_callback(ASettins.av, callback_requ_timeout, av_OnRequestTimeout, self);
    toxav_register_callstate_callback(ASettins.av, callback_peer_timeout, av_OnPeerTimeout, self);
    toxav_register_callstate_callback(ASettins.av, callback_media_change, av_OnMediaChange, self);
    
    toxav_register_audio_recv_callback(ASettins.av, write_device_callback, NULL);

    return ASettins.av;
}
Ejemplo n.º 9
0
int av_terminate_session(av_session_t *_phone)
{
    toxav_hangup(_phone->av);

    free(_phone->_friends);
    pthread_mutex_destroy ( &_phone->_mutex );

    Tox *_p = _phone->_messenger;
    _phone->_messenger = NULL;
    usleep(100000); /* Wait for tox_poll to end */

    tox_kill(_p);
    toxav_kill(_phone->av);

    free(_phone);

    printf("\r[i] Quit!\n");
    return 0;
}
Ejemplo n.º 10
0
int av_terminate_session(av_session_t *_phone)
{
    _phone->running_decaud = 0;
    usleep(100000); /* Wait for tox_poll to end */
    
    toxav_kill(_phone->av);
    printf("\r[i] KILLED AV ARGH!\n");
    
    usleep(1000000); /* Wait for cancel request to be sent */
    Tox *_p = _phone->_messenger;
    _phone->_messenger = NULL;
    tox_kill(_p);

    
    free(_phone->_friends);
    pthread_mutex_destroy ( &_phone->_mutex );
    
    free(_phone);

    printf("\r[i] Quit!\n");
    return 0;
}
Ejemplo n.º 11
0
Core::~Core()
{
    if (tox) {
        saveConfiguration();
        toxav_kill(toxav);
        tox_kill(tox);
    }

    if (videobuf)
    {
        delete[] videobuf;
        videobuf=nullptr;
    }

    if (alContext)
    {
        alcMakeContextCurrent(nullptr);
        alcDestroyContext(alContext);
    }
    if (alOutDev)
        alcCloseDevice(alOutDev);
    if (alInDev)
        alcCaptureCloseDevice(alInDev);
}
Ejemplo n.º 12
0
Archivo: tox.c Proyecto: Boerde/uTox
void tox_thread(void *UNUSED(args))
{
    Tox *tox;
    ToxAv *av;
    uint8_t id[TOX_FRIEND_ADDRESS_SIZE];

TOP:;
    debug("new tox object ipv6: %u no_udp: %u proxy: %u %s %u\n", options.ipv6enabled, options.udp_disabled, options.proxy_enabled, options.proxy_address, options.proxy_port);
    if((tox = tox_new(&options)) == NULL) {
        debug("trying without proxy\n");
        if(!options.proxy_enabled || (options.proxy_enabled = 0, (tox = tox_new(&options)) == NULL)) {
            debug("trying without ipv6\n");
            if(!options.ipv6enabled || (options.ipv6enabled = 0, (tox = tox_new(&options)) == NULL)) {
                debug("tox_new() failed\n");
                exit(1);
            }
            dropdown_ipv6.selected = dropdown_ipv6.over = 1;
        }
        dropdown_proxy.selected = dropdown_proxy.over = 0;
    }

    if(!load_save(tox)) {
        debug("No save file, using defaults\n");
        load_defaults(tox);
    }

    edit_setstr(&edit_name, self.name, self.name_length);
    edit_setstr(&edit_status, self.statusmsg, self.statusmsg_length);

    tox_get_address(tox, id);
    id_to_string(self.id, id);

    debug("Tox ID: %.*s\n", (int)sizeof(self.id), self.id);

    set_callbacks(tox);

    do_bootstrap(tox);

    av = toxav_new(tox, MAX_CALLS);

    set_av_callbacks(av);


    global_av = av;
    tox_thread_init = 1;

    thread(audio_thread, av);
    thread(video_thread, av);
    thread(toxav_thread, av);

    _Bool connected = 0, reconfig;
    uint64_t last_save = get_time(), time;
    while(1) {
        tox_do(tox);

        if(tox_isconnected(tox) != connected) {
            connected = !connected;
            postmessage(DHT_CONNECTED, connected, 0, NULL);

            debug("Connected to DHT: %u\n", connected);
        }

        time = get_time();

        if(time - last_save >= (uint64_t)10 * 1000 * 1000 * 1000) {
            last_save = time;

            if(!connected) {
                do_bootstrap(tox);
            }

            write_save(tox);
        }

        if(tox_thread_msg) {
            TOX_MSG *msg = &tox_msg;
            if(!msg->msg) {
                reconfig = msg->param1;
                tox_thread_msg = 0;
                break;
            }
            tox_thread_message(tox, av, time, msg->msg, msg->param1, msg->param2, msg->data);
            tox_thread_msg = 0;
        }

        utox_thread_work_for_transfers(tox, time);
        utox_thread_work_for_typing_notifications(tox, time);

        uint32_t interval = tox_do_interval(tox);
        yieldcpu((interval > 20) ? 20 : interval);
    }

    write_save(tox);

    while(audio_thread_init || video_thread_init || toxav_thread_init) {
        yieldcpu(1);
    }

    debug("av_thread exit, tox thread ending\n");

    toxav_kill(av);
    tox_kill(tox);

    if(reconfig) {
        goto TOP;
    }

    tox_thread_init = 0;
}