コード例 #1
0
ファイル: audio_call.c プロジェクト: SmoothDude/toxic
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;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: notify.c プロジェクト: dardevelin/toxic
/* Opens primary device */
int init_notify(int login_cooldown, int notification_timeout)
{
#ifdef _SOUND_NOTIFY
    alutInitWithoutContext(NULL, NULL);
    if (open_primary_device(output, &Control.device_idx, 48000, 20, 1) != de_None)
        return -1;
#endif /* _SOUND_NOTIFY */
        
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
    pthread_mutex_init(Control.poll_mutex, NULL);
    pthread_t thread;
    if (pthread_create(&thread, NULL, do_playing, NULL) != 0 || pthread_detach(thread) != 0 ) {
        pthread_mutex_destroy(Control.poll_mutex);
        return -1;
    }
    Control.poll_active = 1;
#endif
    
    Control.cooldown = time(NULL) + login_cooldown;
#ifdef _X11
    Control.display = XOpenDisplay(NULL);
    Control.this_window = get_focused_window_id();
#else
    Control.this_window = 1;
#endif /* _X11 */
    
    
#ifdef _BOX_NOTIFY
    notify_init("toxic");
#endif
    Control.notif_timeout = notification_timeout;
    return 1;
}
コード例 #4
0
ファイル: notify.c プロジェクト: aweltsch/toxic
/* Opens primary device. Returns true on succe*/
void m_open_device()
{
    last_opened_update = get_unix_time();

    if (device_opened) return;

    /* Blah error check */
    open_primary_device(output, &Control.device_idx, 48000, 20, 1);

    device_opened = true;
}
コード例 #5
0
ファイル: audio_call.c プロジェクト: h4ck3rm1k3/toxic
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;
}