Esempio 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;
}
Esempio n. 2
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;
}
Esempio n. 3
0
void cmd_ccur_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    const char *error_str;

    if ( argc != 2 ) {
        if ( argc < 1 ) error_str = "Type must be specified!";
        else if ( argc < 2 ) error_str = "Must have id!";
        else error_str = "Only two arguments allowed!";

        goto on_error;
    }

    DeviceType type;

    if ( strcmp(argv[1], "in") == 0 ) /* Input devices */
        type = input;

    else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */
        type = output;

    else {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
        return;
    }


    char *end;
    long int selection = strtol(argv[2], &end, 10);

    if ( *end ) {
        error_str = "Invalid input";
        goto on_error;
    }

    if ( selection_valid(type, selection) == de_InvalidSelection ) {
        error_str="Invalid selection!";
        goto on_error;
    }

    /* If call is active, change device */
    if ( self->is_call ) {
        Call* this_call = &CallControl.calls[self->num];
        if ( this_call->ttas ) {


            if ( type == output ) {
                pthread_mutex_lock(&this_call->mutex);
                close_device(output, this_call->out_idx);
                this_call->has_output = open_device(output, selection, &this_call->out_idx,
                    CallControl.audio_sample_rate, CallControl.audio_frame_duration, CallControl.audio_channels)
                    == de_None ? 1 : 0;
                pthread_mutex_unlock(&this_call->mutex);
            }
            else {
                /* TODO: check for failure */
                close_device(input, this_call->in_idx);
                open_device(input, selection, &this_call->in_idx, CallControl.audio_sample_rate,
                    CallControl.audio_frame_duration, CallControl.audio_channels);
                /* Set VAD as true for all; TODO: Make it more dynamic */
                register_device_callback(self->num, this_call->in_idx, read_device_callback, &self->num, true);
            }
        }
    }

    self->device_selection[type] = selection;

    return;
    on_error:
    print_err (self, error_str);
}
Esempio n. 4
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;
}