Exemplo n.º 1
0
int start_transmission(ToxWindow *self, Call *call)
{
    if ( !self || !CallControl.av ) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to prepare transmission");
        return -1;
    }

    if (set_call(call, true) == -1)
        return -1;

    DeviceError error = open_primary_device(input, &call->in_idx,
            CallControl.audio_sample_rate, CallControl.audio_frame_duration, CallControl.audio_channels);

    if ( error != de_None ) {
        if ( error == de_FailedStart)
            line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to start input device");

        if ( error == de_InternalError )
            line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Internal error with opening input device");
    }

    if ( register_device_callback(self->num, call->in_idx,
            read_device_callback, &self->num, 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, &call->out_idx,
            CallControl.audio_sample_rate, CallControl.audio_frame_duration, CallControl.audio_channels) != de_None ) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open output device!");
        call->has_output = 0;
    }

    return 0;
}
Exemplo n.º 2
0
int stop_transmission(Call *call, uint32_t friend_number)
{
    if ( call->ttas ) {
        TOXAV_ERR_CALL_CONTROL error = TOXAV_ERR_CALL_CONTROL_OK;

        if ( CallControl.call_state != TOXAV_FRIEND_CALL_STATE_FINISHED )
            toxav_call_control(CallControl.av, friend_number, TOXAV_CALL_CONTROL_CANCEL, &error);

        if ( error == TOXAV_ERR_CALL_CONTROL_OK ) {
            call->ttas = false;

            if ( call->in_idx != -1 )
                close_device(input, call->in_idx);

            if ( call->out_idx != -1 )
                close_device(output, call->out_idx);

            if ( set_call(call, false) == -1 )
                return -1;

            return 0;
        } else {

            return -1;
        }
    }

    return -1;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
int stop_transmission(int call_index)
{    
    if ( ASettins.calls[call_index].ttas ) {
        toxav_kill_transmission(ASettins.av, call_index);
        ASettins.calls[call_index].ttas = _False;
        
        if ( ASettins.calls[call_index].in_idx != -1 )
            close_device(input, ASettins.calls[call_index].in_idx);
        
        if ( ASettins.calls[call_index].out_idx != -1 )
            close_device(output, ASettins.calls[call_index].out_idx);
        
        set_call(&ASettins.calls[call_index], _False);
        return 0;
    }
    
    return -1;
}
Exemplo n.º 5
0
int stop_transmission(Call *call, int32_t call_index)
{
    if ( call->ttas ) {
        toxav_kill_transmission(ASettins.av, call_index);
        call->ttas = false;

        if ( call->in_idx != -1 )
            close_device(input, call->in_idx);

        if ( call->out_idx != -1 )
            close_device(output, call->out_idx);

        if (set_call(call, false) == -1)
            return -1;

        return 0;
    }

    return -1;
}
Exemplo n.º 6
0
    SEXP CallProxy::eval(){
        if( TYPEOF(call) == LANGSXP ){

            if( can_simplify(call) ){
                SlicingIndex indices(0,subsets.nrows()) ;
                while(simplified(indices)) ;
                set_call(call) ;
            }

            int n = proxies.size() ;
            for( int i=0; i<n; i++){
                proxies[i].set( subsets[proxies[i].symbol] ) ;
            }
            return call.eval(env) ;
        } else if( TYPEOF(call) == SYMSXP) {
            // SYMSXP
            if( subsets.count(call) ) return subsets.get_variable(call) ;
            return call.eval(env) ;
        }
        return call ;
    }
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
void *transmission(void *arg)
{
#define lock pthread_mutex_lock(&this_call->mutex)
#define unlock pthread_mutex_unlock(&this_call->mutex)

    ToxWindow* self = arg;
    int32_t call_index = self->call_idx;

    /* Missing audio support */
    if ( !ASettins.av ) _cbend;

    Call* this_call = &ASettins.calls[call_index];

    int32_t dec_frame_len;
    int16_t PCM[frame_size];
    this_call->has_output = 1;
    
    if ( open_primary_device(input, &this_call->in_idx) != de_None ) 
        line_info_add(self, NULL, NULL, NULL, "Failed to open input device!", SYS_MSG, 0, 0);
    if ( register_device_callback(call_index, this_call->in_idx, read_device_callback, &call_index, _True) != de_None) 
        /* Set VAD as true for all; TODO: Make it more dynamic */
        line_info_add(self, NULL, NULL, NULL, "Failed to register input handler!", SYS_MSG, 0, 0);
    
    if ( open_primary_device(output, &this_call->out_idx) != de_None ) {
        line_info_add(self, NULL, NULL, NULL, "Failed to open output device!", SYS_MSG, 0, 0);
        this_call->has_output = 0;
    }
    /* Start transmission */
    while (this_call->ttas) {
        
        lock;
        if ( this_call->has_output ) {
            
            if (playback_device_ready(this_call->out_idx) == de_Busy) {
                unlock;
                continue;
            }
            
            dec_frame_len = toxav_recv_audio(ASettins.av, call_index, frame_size, PCM);

            /* Play the packet */
            if (dec_frame_len > 0) {
                write_out(this_call->out_idx, PCM, dec_frame_len, av_DefaultSettings.audio_channels);
            }
            else if (dec_frame_len != 0) {
                /* >implying it'll ever get an error */
            }
            
        }
        unlock;
        
        usleep(1000);
    }

cleanup:
    if ( this_call->in_idx != -1 ) if ( close_device(input, this_call->in_idx) != de_None )
        line_info_add(self, NULL, NULL, NULL, "Failed to close input device!", SYS_MSG, 0, 0);
    
    if ( this_call->out_idx != -1 ) if ( close_device(output, this_call->out_idx) != de_None )
        line_info_add(self, NULL, NULL, NULL, "Failed to close output device!", SYS_MSG, 0, 0);
    
    set_call(this_call, _False);
    
    _cbend;
}