コード例 #1
0
ファイル: toxav_basic_test.c プロジェクト: AWeinb/toxcore
void callback_call_started ( void *av, int32_t call_index, void *_arg )
{
    Status *cast = _arg;

    if (cast->Alice.av == av) {
        printf("Call started on Alices side...\n");
        cast->Alice.status = InCall;
        toxav_prepare_transmission(av, call_index, 1);
    } else if (cast->Bob.av == av) {
        printf("Call started on Bob side...\n");
        cast->Bob.status = InCall;
        toxav_prepare_transmission(av, call_index, 1);
    }
}
コード例 #2
0
ファイル: coreav.cpp プロジェクト: sanool/qTox
void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled)
{
    qDebug() << QString("Core: preparing call %1").arg(callId);
    calls[callId].callId = callId;
    calls[callId].friendId = friendId;
    calls[callId].muteMic = false;
    // the following three lines are also now redundant from startCall, but are
    // necessary there for outbound and here for inbound
    calls[callId].codecSettings = av_DefaultSettings;
    calls[callId].codecSettings.max_video_width = TOXAV_MAX_VIDEO_WIDTH;
    calls[callId].codecSettings.max_video_height = TOXAV_MAX_VIDEO_HEIGHT;
    calls[callId].videoEnabled = videoEnabled;
    toxav_prepare_transmission(toxav, callId, av_jbufdc, av_VADd, videoEnabled);

    // Audio
    alGenSources(1, &calls[callId].alSource);
    alcCaptureStart(alInDev);

    // Go
    calls[callId].active = true;
    calls[callId].sendAudioTimer->setInterval(5);
    calls[callId].sendAudioTimer->setSingleShot(true);
    connect(calls[callId].sendAudioTimer, &QTimer::timeout, [=](){sendCallAudio(callId,toxav);});
    calls[callId].sendAudioTimer->start();
    calls[callId].sendVideoTimer->setInterval(50);
    calls[callId].sendVideoTimer->setSingleShot(true);
    if (calls[callId].videoEnabled)
    {
        calls[callId].sendVideoTimer->start();
        Widget::getInstance()->getCamera()->suscribe();
    }
}
コード例 #3
0
ファイル: audio_call.c プロジェクト: chu888chu888/toxic
int start_transmission(ToxWindow *self)
{
    if ( !ASettins.av || self->call_idx == -1 ) return -1;
    
    /* Don't provide support for video */
    if ( 0 != toxav_prepare_transmission(ASettins.av, self->call_idx, av_jbufdc * 2, av_VADd, 0) ) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Could not prepare transmission");
    }
    
    if ( !toxav_capability_supported(ASettins.av, self->call_idx, AudioDecoding) ||
         !toxav_capability_supported(ASettins.av, self->call_idx, AudioEncoding) )
        return -1;
    
    set_call(&ASettins.calls[self->call_idx], _True);
        
    ToxAvCSettings csettings;
    toxav_get_peer_csettings(ASettins.av, self->call_idx, 0, &csettings);
    
    if ( open_primary_device(input, &ASettins.calls[self->call_idx].in_idx,
            csettings.audio_sample_rate, csettings.audio_frame_duration, csettings.audio_channels) != de_None ) 
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open input device!");
    
    if ( register_device_callback(self->call_idx, ASettins.calls[self->call_idx].in_idx, 
         read_device_callback, &self->call_idx, _True) != de_None) 
        /* Set VAD as true for all; TODO: Make it more dynamic */
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to register input handler!");
    
    if ( open_primary_device(output, &ASettins.calls[self->call_idx].out_idx, 
            csettings.audio_sample_rate, csettings.audio_frame_duration, csettings.audio_channels) != de_None ) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open output device!");
        ASettins.calls[self->call_idx].has_output = 0;
    }
    
    return 0;
}
コード例 #4
0
ファイル: toxav_basic_test.c プロジェクト: kyconny/toxcore
void callback_recv_starting ( int32_t call_index, void *_arg )
{
    Status *cast = _arg;

    /* Alice always sends invite */
    printf("Call started on Alice side...\n");
    cast->Alice.status = InCall;
    toxav_prepare_transmission(cast->Alice.av, call_index, &muhcaps, 1);
}
コード例 #5
0
ファイル: toxav_basic_test.c プロジェクト: CowInAPie/toxcore
void callback_call_started ( void *av, int32_t call_index, void *_arg )
{
    Status *cast = _arg;

    /* Alice always sends invite */
    printf("Call started on Bob side...\n");
    cast->Bob.status = InCall;
    toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1);
}
コード例 #6
0
void callback_call_started ( void *_arg )
{
    Status *cast = _arg;

    /* Alice always sends invite */
    printf("Call started on Bob side...\n");
    cast->Bob.status = InCall;
    toxav_prepare_transmission(cast->Bob.av, 1);
}
コード例 #7
0
ファイル: coreav.cpp プロジェクト: cmcsun/qTox
void Core::prepareCall(uint32_t friendId, int32_t callId, ToxAv* toxav, bool videoEnabled)
{
    qDebug() << QString("Core: preparing call %1").arg(callId);

    if (!videobuf)
        videobuf = new uint8_t[videobufsize];

    calls[callId].callId = callId;
    calls[callId].friendId = friendId;
    calls[callId].muteMic = false;
    calls[callId].muteVol = false;
    // the following three lines are also now redundant from startCall, but are
    // necessary there for outbound and here for inbound
    calls[callId].codecSettings = av_DefaultSettings;
    calls[callId].codecSettings.max_video_width = TOXAV_MAX_VIDEO_WIDTH;
    calls[callId].codecSettings.max_video_height = TOXAV_MAX_VIDEO_HEIGHT;
    calls[callId].videoEnabled = videoEnabled;
    int r = toxav_prepare_transmission(toxav, callId, videoEnabled);
    if (r < 0)
        qWarning() << QString("Error starting call %1: toxav_prepare_transmission failed with %2").arg(callId).arg(r);

    // Audio
    Audio::suscribeInput();

    // Go
    calls[callId].active = true;
    calls[callId].sendAudioTimer->setInterval(5);
    calls[callId].sendAudioTimer->setSingleShot(true);
    connect(calls[callId].sendAudioTimer, &QTimer::timeout, [=](){sendCallAudio(callId,toxav);});
    calls[callId].sendAudioTimer->start();
    calls[callId].sendVideoTimer->setInterval(50);
    calls[callId].sendVideoTimer->setSingleShot(true);
    if (calls[callId].videoEnabled)
    {
        calls[callId].sendVideoTimer->start();
        Camera::getInstance()->subscribe();
    }

#ifdef QTOX_FILTER_AUDIO
    if (Settings::getInstance().getFilterAudio())
    {
        filterer[callId] = new AudioFilterer();
        filterer[callId]->startFilter(48000);
    }
    else
    {
        delete filterer[callId];
        filterer[callId] = nullptr;
    }
#endif
}
コード例 #8
0
ファイル: phone.c プロジェクト: aarvay/ProjectTox-Core
int phone_startmedia_loop ( ToxAv *arg )
{
    if ( !arg ) {
        return -1;
    }

    toxav_prepare_transmission(arg, 1);

    /*
     * Rise all threads
     */
#ifdef TOX_FFMPEG

    /* Only checks for last peer */
    if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo &&
            0 > event.rise(encode_video_thread, _phone) ) {
        INFO("Error while starting encode_video_thread()");
        return -1;
    }

#endif

    /* Always send audio */
    /*if ( 0 > event.rise(encode_audio_thread, toxav_get_agent_handler(arg)) ) {
        INFO("Error while starting encode_audio_thread()");
        return -1;
    } */

    /* Only checks for last peer */
    if ( toxav_get_peer_transmission_type(arg, 0) == TypeVideo &&
        0 > event.rise(decode_video_thread, _phone) ) {
        INFO("Error while starting decode_video_thread()");
        return -1;
    }

    /*if ( 0 > event.rise(decode_audio_thread, toxav_get_agent_handler(arg)) ) {
        INFO("Error while starting decode_audio_thread()");
        return -1;
    } */


    /* One threaded audio */
    
    if ( 0 > event.rise(one_threaded_audio, _phone) ) {
        INFO ("Shit-head");
        return -1;
    }
     
    return 0;
}
コード例 #9
0
ファイル: av.cpp プロジェクト: Nokius/cyanide
void callback_av_start(ToxAv *av, int32_t call_index, void *that)
{
    qDebug() << "was called";
    Cyanide *cyanide = (Cyanide*)that;
    ToxAvCSettings peer_settings;
    int fid = toxav_get_peer_id(av, call_index, 0);
    toxav_get_peer_csettings(av, call_index, 0, &peer_settings);
    bool video = peer_settings.call_type == av_TypeVideo;
    if(toxav_prepare_transmission(av, call_index, 1) == 0) {
        // call started
    } else {
        qDebug() << "toxav_prepare_transmission() failed";
        return;
    }
}
コード例 #10
0
ファイル: audio_call.c プロジェクト: h4ck3rm1k3/toxic
int start_transmission(ToxWindow *self)
{
    if ( !ASettins.av || self->call_idx == -1 ) return -1;
    
    /* Don't provide support for video */
    if ( 0 != toxav_prepare_transmission(ASettins.av, self->call_idx, &ASettins.cs, 0) ) {
        line_info_add(self, NULL, NULL, NULL, "Could not prepare transmission", SYS_MSG, 0, 0);
    }
    
    if ( !toxav_capability_supported(ASettins.av, self->call_idx, AudioDecoding) ||
         !toxav_capability_supported(ASettins.av, self->call_idx, AudioEncoding) )
        return -1;

    set_call(&ASettins.calls[self->call_idx], _True);
    
    if ( 0 != pthread_create(&ASettins.calls[self->call_idx].ttid, NULL, transmission, self ) &&
         0 != pthread_detach(ASettins.calls[self->call_idx].ttid) ) {
        return -1;
    }

    return 0;
}
コード例 #11
0
ファイル: toxav_many_test.c プロジェクト: AWeinb/toxcore
void *in_thread_call (void *arg)
{
#define call_print(call, what, args...) printf("[%d] " what "\n", call, ##args)

    ACall *this_call = arg;
    uint64_t start = 0;
    int step = 0;
    int call_idx;

    const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
    int16_t sample_payload[frame_size];
    randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size);

    uint8_t prepared_payload[RTP_PAYLOAD_SIZE];

    register_callbacks(this_call->Caller.av, &status_control);
    register_callbacks(this_call->Callee.av, arg);

    /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */
    pthread_mutex_lock(&muhmutex);

    while (call_running[this_call->idx]) {

        pthread_mutex_unlock(&muhmutex);

        switch ( step ) {
            case 0: /* CALLER */
                toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, &av_DefaultSettings, 10);
                call_print(call_idx, "Calling ...");
                step++;
                break;

            case 1: /* CALLEE */
                pthread_mutex_lock(&muhmutex);

                if (this_call->Caller.status == Ringing) {
                    call_print(call_idx, "Callee answers ...");
                    pthread_mutex_unlock(&muhmutex);
                    toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings);
                    step++;
                    start = time(NULL);
                    pthread_mutex_lock(&muhmutex);
                }

                pthread_mutex_unlock(&muhmutex);
                break;

            case 2: /* Rtp transmission */
                pthread_mutex_lock(&muhmutex);

                if (this_call->Caller.status == InCall) { /* I think this is okay */
                    call_print(call_idx, "Sending rtp ...");
                    pthread_mutex_unlock(&muhmutex);

                    c_sleep(1000); /* We have race condition here */
                    toxav_prepare_transmission(this_call->Callee.av, 0, 1);
                    toxav_prepare_transmission(this_call->Caller.av, call_idx, 1);

                    int payload_size = toxav_prepare_audio_frame(this_call->Caller.av, call_idx, prepared_payload, RTP_PAYLOAD_SIZE,
                                       sample_payload, frame_size);

                    if ( payload_size < 0 ) {
                        ck_assert_msg ( 0, "Failed to encode payload" );
                    }


                    while (time(NULL) - start < 10) { /* 10 seconds */
                        /* Both send */
                        toxav_send_audio(this_call->Caller.av, call_idx, prepared_payload, payload_size);

                        toxav_send_audio(this_call->Callee.av, 0, prepared_payload, payload_size);

                        /* Both receive */
                        int16_t storage[RTP_PAYLOAD_SIZE];
                        int recved;

                        c_sleep(20);
                    }

                    step++; /* This terminates the loop */

                    pthread_mutex_lock(&muhmutex);
                    toxav_kill_transmission(this_call->Callee.av, 0);
                    toxav_kill_transmission(this_call->Caller.av, call_idx);
                    pthread_mutex_unlock(&muhmutex);

                    /* Call over CALLER hangs up */
                    toxav_hangup(this_call->Caller.av, call_idx);
                    call_print(call_idx, "Hanging up ...");

                    pthread_mutex_lock(&muhmutex);
                }

                pthread_mutex_unlock(&muhmutex);
                break;

            case 3: /* Wait for Both to have status ended */
                pthread_mutex_lock(&muhmutex);

                if (this_call->Caller.status == Ended) {
                    pthread_mutex_unlock(&muhmutex);
                    c_sleep(1000); /* race condition */
                    pthread_mutex_lock(&muhmutex);
                    this_call->Callee.status = Ended;
                    call_running[this_call->idx] = 0;
                }

                pthread_mutex_unlock(&muhmutex);

                break;

        }

        c_sleep(20);

        pthread_mutex_lock(&muhmutex);
    }

    pthread_mutex_unlock(&muhmutex);
    call_print(call_idx, "Call ended successfully!");
    pthread_exit(NULL);
}