title: How to set RTSP Uri in Server , which will expect exact uri to match from client
body: <p>I am trying to develop RTSP server, and since I am a beginner to this, I don't know how to set RTSP URI in server side. I found the below code, but I don't understand exactly how RTSP URI is being set.</p>
  
  <p>This is the function in which the URI is set. Could anyone please explain how it works, and if possible give me some pointers for changes that will make it more easy to understand.</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>uint16_t app_rtsp_string_cb(char *pc, int iAction, int iMaxChar)
   {
      uint16_t len = 0;
      uint16_t len_sdp;
      uint16_t len_uri;
      ip_addr_t ia;
      char uri[36];
      char *dstring;
      char *pend;
  
      const char *uri_str = "rtsp://%s:%d/";
      const char *sdp_description =
              "Content-Base: %s\r\n"
              "Content-Type: application/sdp\r\n"
              "Content-Length: %d\r\n"
              "\r\n";
   #define TEXTIFY(A) #A
   #if PAYLOAD_TYPE == CAMERA_FORMAT_UNCOMPRESSED
   #define VIDEO_DESCRIBE(A,B,C) \
          "m=video 0 RTP/AVP " TEXTIFY(C) "\r\n" \
          "a=control:%s\r\n" \
          "a=rtpmap:" TEXTIFY(C) " raw/90000\r\n" \
          "a=fmtp:" TEXTIFY(C) " sampling=YCbCr-4:2:2;" \
          "width=" TEXTIFY(A) ";height=" TEXTIFY(B) ";depth=16;" \
          "rate=90000;colorimetry=BT709-2\r\n"
   #elif PAYLOAD_TYPE == CAMERA_FORMAT_MJPEG
   #define VIDEO_DESCRIBE(A,B,C) \
          "m=video 0 RTP/AVP " TEXTIFY(C) "\r\n" \
          "a=control:%s\r\n" \
          "a=rtpmap:" TEXTIFY(C) " JPEG/90000\r\n" \
          /*"width=" TEXTIFY(A) ";height=" TEXTIFY(B) ";depth=16;" */ \
          /*"rate=90000;colorimetry=BT709-2\r\n"*/
   #endif
  
      const char *sdp_video = VIDEO_DESCRIBE(FRAME_WIDTH, FRAME_HEIGHT, FRAME_PT);
  
      ia = net_get_ip();
      dstring = ipaddr_ntoa(&amp;ia);
  
      // Space for terminating character.
      iMaxChar--;
  
      switch (iAction)
      {
      case RTSP_HANDLER_ACTION_DESCRIBE:
          len_uri = sprintf(uri, uri_str, dstring, RTSP_SERVER_PORT);
          // Work out length of content - the sdp_uncompressed_video part.
          len_sdp = strlen(sdp_video);
          // remove %s from a=control:%s\r\n
          len_sdp -= 2;
          // add in control URI
          len_sdp += len_uri;
          len = snprintf(pc, iMaxChar, sdp_description, uri, len_sdp);
          if (len + len_sdp &lt; iMaxChar)
          {
              pend = &amp;pc[len];
              snprintf(pend, iMaxChar - len, sdp_video, uri);
          }
          break;
      case RTSP_HANDLER_ACTION_URI:
          len = snprintf(pc, iMaxChar, uri_str, dstring, RTSP_SERVER_PORT);
          break;
      default:
          *pc = '\0';
      }
      pc[iMaxChar] = '\0';
  
      len = strlen(pc);
  
      return len;
   }
  </code></pre>