1

I am writing a pjsip application and calling / answering works just fine. Now i want to implement that when i call someone i hear ringing, when i get a call its ringing.

I have searched for this but i only stumbled on answers who refer on the pjsua app in the example folders (pjproject-2.4.5/pjsip-apps/src/pjsua/) . So i tried to understand this program which contains multiple files (all in all about 3k lines of code) and special structs which just makes it harder to understand. So i could not figure out how to do this functionality and i would appreciate a hint to the right direction.

Another point would be a list of the codes i can give on answering an incoming call, since i could not find a one with descriptions what which code means.

appreciate your time.

Obi-Wan
  • 846
  • 1
  • 11
  • 26
  • 1
    have you tried this http://stackoverflow.com/questions/19047771/ios-pjsip-play-a-sound-during-sip-call ? – nsinvocation Dec 04 '15 at 13:38
  • what you mean by "a list of the codes i can give on answering an incoming call" ? – nsinvocation Dec 04 '15 at 13:38
  • i will look into it @hal9000 thanks for this, well it is possible to answer incoming call with different codes, like 200 wich just accepts the call and start the audio transmission. [link] (http://www.pjsip.org/docs/latest/pjsip/docs/html/group__PJSUA__LIB__CALL.htm#ga6dd4a80bd96c319398e218bbffda5153) here is described that Status code has range 100-699. But not explained what they mean or a link to documentation of it. – Obi-Wan Dec 04 '15 at 13:57
  • so i have looked into your link but this does not help me that much, because i don't want to play a sound while a call but before a call. So i accept a call with code 180 (for ringing) and while i don't accept the call it shall play a ringing sound. – Obi-Wan Dec 07 '15 at 12:24

2 Answers2

3

SIP response codes are splitted in 6 classes

  • 1xx: Provisional — request received, continuing to process the request; Provisional responses, also known as informational responses, indicate that the server contacted is performing some further action and does not yet have a definitive response. A server sends a 1xx response if it expects to take more than 200 ms to obtain a final response. Note that 1xx responses are not transmitted reliably. They never cause the client to send an ACK. Provisional (1xx) responses MAY contain message bodies, including session descriptions.

  • 2xx: Success — the action was successfully received, understood, and accepted;

  • 3xx: Redirection — further action needs to be taken in order to complete the request;

  • 4xx: Client Error — the request contains bad syntax or cannot be fulfilled at this server;

  • 5xx: Server Error — the server failed to fulfill an apparently valid request;

  • 6xx: Global Failure — the request cannot be fulfilled at any server.

    Here you can find PJSIP struct which holds these codes and SIP codes description

nsinvocation
  • 7,559
  • 3
  • 41
  • 46
3

Old question but posting my answers here for anyone who might stumble on it:

Playing a ringtone

Assuming your ringtone is a wav file, you need to create a wav player and connect its port to your output device. The wav file will loop until you disconnect the port, then start again when you reconnect it.

Calling init_ringtone_player should be done after calling pjsua_init. ringtone_port_info is a global struct to keep track of the port and ring state.

typedef struct _ringtone_port_info {
    int ring_on;
    int ring_slot;
    pjmedia_port *ring_port;
    pj_pool_t *pool;
} ringtone_port_info_t;

static ringtone_port_info_t ringtone_port_info;

static void init_ringtone_player() {

    int file_slot;
    pj_pool_t *pool;
    pjmedia_port *file_port;
    pj_status_t status;

    pool = pjsua_pool_create("wav", 4000, 4000);

    status = pjmedia_wav_player_port_create(pool, "ringtone.wav", 
        0, 0, 0, &file_port);

    if (status != PJ_SUCCESS) {
        error_exit("Error creating WAV player port", status);
        return;
    }

    status = pjsua_conf_add_port(pool, file_port, &file_slot);

    if (status != PJ_SUCCESS) {
        error_exit("Error adding port to conference", status);
        return;
    }

    ringtone_port_info = (ringtone_port_info_t) { .ring_on = 0, 
        .ring_slot = file_slot, .ring_port = file_port , .pool = pool };

}

Then, make functions to start and stop the ringtone as needed (i.e. during on_incoming_call, on_call_state or wherever). The important function call to note here is pjsua_conf_connect.

pj_status_t start_ring() {
    pj_status_t status;

    if (ringtone_port_info.ring_on) {
        printf("Ringtone port already connected\n");
        return PJ_SUCCESS;
    }

    printf("Starting ringtone\n");
    status = pjsua_conf_connect(ringtone_port_info.ring_slot, 0);
    ringtone_port_info.ring_on = 1;
    if (status != PJ_SUCCESS)
        error_exit("Error connecting ringtone port", status);
    return status;
}

pj_status_t stop_ring() {
    pj_status_t status;

    if (!ringtone_port_info.ring_on) {
        printf("Ringtone port already disconnected\n");
        return PJ_SUCCESS;
    }

    printf("Stopping ringtone\n");
    status = pjsua_conf_disconnect(ringtone_port_info.ring_slot, 0);
    ringtone_port_info.ring_on = 0;
    if (status != PJ_SUCCESS)
        error_exit("Error disconnecting ringtone port", status);
    return status;
}

Make sure you call pjsua_destroy when you're done to release the pool (or manually release it)

SIP response codes

See here for a list of status codes:

https://www.pjsip.org/pjsip/docs/html/group__PJSIP__MSG__LINE.htm#

You can use 200 to accept and 603 to decline (using pjsua_call_answer)

Kyle
  • 31
  • 1