pjsip ringing tones and answer codes












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.










share|improve this question


















  • 1





    have you tried this stackoverflow.com/questions/19047771/… ?

    – tesla
    Dec 4 '15 at 13:38











  • what you mean by "a list of the codes i can give on answering an incoming call" ?

    – tesla
    Dec 4 '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] (pjsip.org/docs/latest/pjsip/docs/html/…) here is described that Status code has range 100-699. But not explained what they mean or a link to documentation of it.

    – MrNice
    Dec 4 '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.

    – MrNice
    Dec 7 '15 at 12:24
















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.










share|improve this question


















  • 1





    have you tried this stackoverflow.com/questions/19047771/… ?

    – tesla
    Dec 4 '15 at 13:38











  • what you mean by "a list of the codes i can give on answering an incoming call" ?

    – tesla
    Dec 4 '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] (pjsip.org/docs/latest/pjsip/docs/html/…) here is described that Status code has range 100-699. But not explained what they mean or a link to documentation of it.

    – MrNice
    Dec 4 '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.

    – MrNice
    Dec 7 '15 at 12:24














1












1








1


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.










share|improve this question














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.







c sip voip raspberry-pi2 pjsip






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 4 '15 at 13:26









MrNiceMrNice

295318




295318








  • 1





    have you tried this stackoverflow.com/questions/19047771/… ?

    – tesla
    Dec 4 '15 at 13:38











  • what you mean by "a list of the codes i can give on answering an incoming call" ?

    – tesla
    Dec 4 '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] (pjsip.org/docs/latest/pjsip/docs/html/…) here is described that Status code has range 100-699. But not explained what they mean or a link to documentation of it.

    – MrNice
    Dec 4 '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.

    – MrNice
    Dec 7 '15 at 12:24














  • 1





    have you tried this stackoverflow.com/questions/19047771/… ?

    – tesla
    Dec 4 '15 at 13:38











  • what you mean by "a list of the codes i can give on answering an incoming call" ?

    – tesla
    Dec 4 '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] (pjsip.org/docs/latest/pjsip/docs/html/…) here is described that Status code has range 100-699. But not explained what they mean or a link to documentation of it.

    – MrNice
    Dec 4 '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.

    – MrNice
    Dec 7 '15 at 12:24








1




1





have you tried this stackoverflow.com/questions/19047771/… ?

– tesla
Dec 4 '15 at 13:38





have you tried this stackoverflow.com/questions/19047771/… ?

– tesla
Dec 4 '15 at 13:38













what you mean by "a list of the codes i can give on answering an incoming call" ?

– tesla
Dec 4 '15 at 13:38





what you mean by "a list of the codes i can give on answering an incoming call" ?

– tesla
Dec 4 '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] (pjsip.org/docs/latest/pjsip/docs/html/…) here is described that Status code has range 100-699. But not explained what they mean or a link to documentation of it.

– MrNice
Dec 4 '15 at 13:57





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] (pjsip.org/docs/latest/pjsip/docs/html/…) here is described that Status code has range 100-699. But not explained what they mean or a link to documentation of it.

– MrNice
Dec 4 '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.

– MrNice
Dec 7 '15 at 12:24





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.

– MrNice
Dec 7 '15 at 12:24












2 Answers
2






active

oldest

votes


















2














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








share|improve this answer































    1














    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 connectedn");
    return PJ_SUCCESS;
    }

    printf("Starting ringtonen");
    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 disconnectedn");
    return PJ_SUCCESS;
    }

    printf("Stopping ringtonen");
    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)






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34089453%2fpjsip-ringing-tones-and-answer-codes%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      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








      share|improve this answer




























        2














        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








        share|improve this answer


























          2












          2








          2







          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








          share|improve this answer













          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









          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 4 '15 at 14:09









          teslatesla

          5,39212641




          5,39212641

























              1














              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 connectedn");
              return PJ_SUCCESS;
              }

              printf("Starting ringtonen");
              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 disconnectedn");
              return PJ_SUCCESS;
              }

              printf("Stopping ringtonen");
              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)






              share|improve this answer




























                1














                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 connectedn");
                return PJ_SUCCESS;
                }

                printf("Starting ringtonen");
                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 disconnectedn");
                return PJ_SUCCESS;
                }

                printf("Stopping ringtonen");
                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)






                share|improve this answer


























                  1












                  1








                  1







                  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 connectedn");
                  return PJ_SUCCESS;
                  }

                  printf("Starting ringtonen");
                  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 disconnectedn");
                  return PJ_SUCCESS;
                  }

                  printf("Stopping ringtonen");
                  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)






                  share|improve this answer













                  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 connectedn");
                  return PJ_SUCCESS;
                  }

                  printf("Starting ringtonen");
                  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 disconnectedn");
                  return PJ_SUCCESS;
                  }

                  printf("Stopping ringtonen");
                  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)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 28 '18 at 22:53









                  KyleKyle

                  111




                  111






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34089453%2fpjsip-ringing-tones-and-answer-codes%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Contact image not getting when fetch all contact list from iPhone by CNContact

                      count number of partitions of a set with n elements into k subsets

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks