示例#1
0
char *get_SDP_version(char *buffer)
{
	buffer[0]='\0';	
	sprintf(buffer,"%.0f",NTP_time(time(NULL)));
	return buffer;
}
/**
 * @brief Create description for an SDP session
 *
 * @param uri URI of the resource to describe
 *
 * @return A new GString containing the complete description of the
 *         session or NULL if the resource was not found or no demuxer
 *         was found to handle it.
 */
static GString *sdp_session_descr(RTSP_Client *rtsp, RFC822_Request *req)
{
    URI *uri = req->uri;
    GString *descr = NULL;
    double duration;

    float currtime_float, restime_float;

    Resource *resource;

    char *path;

    const char *inet_family;

    if ( rtsp->peer_sa == NULL ) {
        xlog(LOG_ERR, "unable to identify address family for connection");
        return NULL;
    }

    inet_family = rtsp->peer_sa->sa_family == AF_INET6 ? "IP6" : "IP4";
    path = g_uri_unescape_string(uri->path, "/");

    xlog(LOG_DBG, "[SDP] opening %s", path);
    if ( !(resource = r_open(path)) ) {
        xlog(LOG_ERR, "[SDP] %s not found", path);
        g_free(path);
        return NULL;
    }
    g_free(path);

    descr = g_string_new("v=0"SDP_EL);

    /* Near enough approximation to run it now */
    currtime_float = NTP_time(time(NULL));
    restime_float = resource->mtime ? NTP_time(resource->mtime) : currtime_float;

    /* Network type: Internet; Address type: IP4. */
    g_string_append_printf(descr, "o=- %.0f %.0f IN %s %s"SDP_EL,
                           currtime_float, restime_float,
                           inet_family,
                           uri->host);

    /* We might want to provide a better name */
    g_string_append(descr, "s=RTSP Session\r\n");

    g_string_append_printf(descr,
                           "c=IN %s %s"SDP_EL,
                           inet_family,
                           rtsp->local_host);

    g_string_append(descr, "t=0 0"SDP_EL);

    // type attribute. We offer only broadcast
    g_string_append(descr, "a=type:broadcast"SDP_EL);

    /* Server signature; the same as the Server: header */
    g_string_append_printf(descr, "a=tool:%s"SDP_EL,
                           feng_signature);

    // control attribute. We should look if aggregate metod is supported?
    g_string_append(descr, "a=control:*"SDP_EL);

    if ((duration = resource->duration) > 0 &&
        duration != HUGE_VAL)
        g_string_append_printf(descr, "a=range:npt=0-%f"SDP_EL, duration);

    g_list_foreach(resource->tracks,
                   sdp_track_descr,
                   descr);

    r_close(resource);

    xlog(LOG_INF, "[SDP] description:\n%s", descr->str);

    return descr;
}