pjsipua-win 0.1.26

Rust library PJSUA2
// src/ffi.rs - Complete FFI bindings
use libc::{c_char, c_int};

// FFI function declarations
extern "C" {
    // Endpoint management
    pub fn pjsua2_create_endpoint() -> c_int;
    pub fn pjsua2_init_endpoint(log_level: c_int) -> c_int;
    pub fn pjsua2_create_transport(port: c_int) -> c_int;
    pub fn pjsua2_start() -> c_int;
    pub fn pjsua2_destroy();

    // Account management
    pub fn pjsua2_create_account(
        id_uri: *const c_char,
        registrar_uri: *const c_char,
        username: *const c_char,
        password: *const c_char,
        on_reg_state: Option<extern "C" fn(is_registered: c_int)>,
        on_incoming_call: Option<extern "C" fn(call_id: c_int, remote_uri: *const c_char)>,
    ) -> c_int;

    pub fn pjsua2_create_account_simple(
        id_uri: *const c_char,
        registrar_uri: *const c_char,
        username: *const c_char,
        password: *const c_char,
    ) -> c_int;

    // Call management
    pub fn pjsua2_make_call(
        acc_id: c_int,
        dst_uri: *const c_char,
    ) -> c_int;

    pub fn pjsua2_answer_call(call_id: c_int, code: c_int) -> c_int;
    pub fn pjsua2_hangup_call(call_id: c_int) -> c_int;

    // Hold/Unhold management
    pub fn pjsua2_hold_call(call_id: c_int) -> c_int;
    pub fn pjsua2_unhold_call(call_id: c_int) -> c_int;
    pub fn pjsua2_is_call_on_hold(call_id: c_int) -> c_int;

    // Mute/Unmute management
    pub fn pjsua2_mute_call(call_id: c_int, mute: c_int) -> c_int;
    pub fn pjsua2_is_call_muted(call_id: c_int) -> c_int;

    // DTMF
    pub fn pjsua2_send_dtmf(call_id: c_int, digits: *const c_char) -> c_int;

    // Conference management
    pub fn pjsua2_conference_calls(call_id1: c_int, call_id2: c_int) -> c_int;
    pub fn pjsua2_get_conf_port(call_id: c_int) -> c_int;

    // Get detailed call info
    pub fn pjsua2_get_call_detailed_info(
        call_id: c_int,
        is_on_hold: *mut c_int,
        is_muted: *mut c_int,
        conf_port: *mut c_int,
    ) -> c_int;

    // Audio device management
    pub fn pjsua2_get_audio_device_count() -> c_int;
    pub fn pjsua2_get_audio_device_info(
        index: c_int,
        name: *mut c_char,
        name_size: c_int,
        is_capture: *mut c_int,
        is_playback: *mut c_int,
    ) -> c_int;
    pub fn pjsua2_set_audio_devices(capture_dev: c_int, playback_dev: c_int) -> c_int;

    // Callbacks
    pub fn pjsua2_set_callbacks(
        on_reg_state: Option<extern "C" fn(acc_id: c_int, is_registered: c_int)>,
        on_incoming_call: Option<extern "C" fn(acc_id: c_int, call_id: c_int, remote_uri: *const c_char)>,
        on_call_state: Option<extern "C" fn(call_id: c_int, state: c_int)>,
        on_call_media_state: Option<extern "C" fn(call_id: c_int, state: c_int)>,
    );

    // Call quality and statistics
    pub fn pjsua2_get_call_quality(
        call_id: c_int,
        rx_level: *mut f64,
        tx_level: *mut f64,
        rx_quality: *mut f64,
        rx_loss_percent: *mut f64,
        rtt_ms: *mut c_int,
        jitter_ms: *mut f64,
        mos_score: *mut f64,
        codec_name: *mut c_char,
        codec_name_size: c_int,
    ) -> c_int;

    // Get current audio devices for a call
    pub fn pjsua2_get_call_audio_devices(
        call_id: c_int,
        capture_dev: *mut c_int,
        playback_dev: *mut c_int,
    ) -> c_int;

    // Check if call has active media
    pub fn pjsua2_call_has_media(call_id: c_int) -> c_int;

    // Enhanced answer with audio device logging
    pub fn pjsua2_answer_call_with_audio_info(call_id: c_int, code: c_int) -> c_int;

    // Get active call count
    pub fn pjsua2_get_active_call_count() -> c_int;

    // Clean up orphaned calls
    pub fn pjsua2_cleanup_calls() -> c_int;
    pub fn pjsua2_check_ready() -> c_int;

    // Test functions
    pub fn pjsua2_test_basic() -> c_int;
    pub fn pjsua2_test_object_creation() -> c_int;
    pub fn pjsua2_test_account_config() -> c_int;
    pub fn pjsua2_test_create_account() -> c_int;
    pub fn pjsua2_test_endpoint_state() -> c_int;
}

// Call state constants
pub const PJSIP_INV_STATE_NULL: c_int = 0;
pub const PJSIP_INV_STATE_CALLING: c_int = 1;
pub const PJSIP_INV_STATE_INCOMING: c_int = 2;
pub const PJSIP_INV_STATE_EARLY: c_int = 3;
pub const PJSIP_INV_STATE_CONNECTING: c_int = 4;
pub const PJSIP_INV_STATE_CONFIRMED: c_int = 5;
pub const PJSIP_INV_STATE_DISCONNECTED: c_int = 6;

// PJSUA states
pub const PJSUA_STATE_NULL: c_int = 0;
pub const PJSUA_STATE_CREATED: c_int = 1;
pub const PJSUA_STATE_INIT: c_int = 2;
pub const PJSUA_STATE_STARTING: c_int = 3;
pub const PJSUA_STATE_RUNNING: c_int = 4;
pub const PJSUA_STATE_CLOSING: c_int = 5;

// SIP response codes
pub const PJSIP_SC_TRYING: c_int = 100;
pub const PJSIP_SC_RINGING: c_int = 180;
pub const PJSIP_SC_OK: c_int = 200;
pub const PJSIP_SC_BUSY_HERE: c_int = 486;
pub const PJSIP_SC_DECLINE: c_int = 603;