Ejemplo n.º 1
0
/*
v=0
o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4
s=SDP Seminar
i=A Seminar on the session description protocol
u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps
[email protected] (Mark Handley)
c=IN IP4 224.2.17.12/127
t=2873397496 2873404696
a=recvonly
m=audio 3456 RTP/AVP 0
m=video 2232 RTP/AVP 31
m=whiteboard 32416 UDP WB
a=orient:portrait
*/
int rtsp_client_sdp(struct rtsp_client_t* rtsp, const char* content)
{
	int i, j, n, count;
	int formats[N_MEDIA_FORMAT];
	struct rtsp_media_t* media;
	void* sdp;

	sdp = sdp_parse(content);
	if (!sdp)
		return -1;

	count = sdp_media_count(sdp);
	if(count > N_MEDIA)
	{
		rtsp->media_ptr = (struct rtsp_media_t*)malloc(sizeof(struct rtsp_media_t)*(count-N_MEDIA));
		if(!rtsp->media_ptr)
		{
			sdp_destroy(sdp);
			return ENOMEM;
		}
		memset(rtsp->media_ptr, 0, sizeof(struct rtsp_media_t)*(count-N_MEDIA));
	}

	rtsp->media_count = count;

	// rfc 2326 C.1.1 Control URL (p80)
	// If found at the session level, the attribute indicates the URL for aggregate control
	rtsp->aggregate = rtsp_media_aggregate_control_enable(sdp);
	rtsp_get_session_uri(sdp, rtsp->aggregate_uri, sizeof(rtsp->aggregate_uri), rtsp->uri, rtsp->baseuri, rtsp->location);

	for(i = 0; i < count; i++)
	{
		media = rtsp_get_media(rtsp, i);
		//media->cseq = rand();

		// RTSP2326 C.1.1 Control URL
		rtsp_get_media_uri(sdp, i, media->uri, sizeof(media->uri), rtsp->aggregate_uri);

		n = sdp_media_formats(sdp, i, formats, N_MEDIA_FORMAT);
		media->avformat_count = n > N_MEDIA_FORMAT ? N_MEDIA_FORMAT : n;
		for(j = 0; j < media->avformat_count; j++)
		{
			media->avformats[j].fmt = formats[j];
		}

		// update media encoding
		sdp_media_attribute_list(sdp, i, NULL, rtsp_media_onattr, media);		
	}

	sdp_destroy(sdp);
	return 0;
}
Ejemplo n.º 2
0
/*
v=0
o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4
s=SDP Seminar
i=A Seminar on the session description protocol
u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps
[email protected] (Mark Handley)
c=IN IP4 224.2.17.12/127
t=2873397496 2873404696
a=recvonly
m=audio 3456 RTP/AVP 0
m=video 2232 RTP/AVP 31
m=whiteboard 32416 UDP WB
a=orient:portrait
*/
int rtsp_client_sdp(struct rtsp_client_context_t* ctx, void* sdp)
{
	int i, count;
	int formats[N_MEDIA_FORMAT];
	struct rtsp_media_t* media;

	assert(sdp);
	count = sdp_media_count(sdp);
	if(count > N_MEDIA)
	{
		ctx->media_ptr = (struct rtsp_media_t*)malloc(sizeof(struct rtsp_media_t)*(count-N_MEDIA));
		if(!ctx->media_ptr)
			return -1;
		memset(ctx->media_ptr, 0, sizeof(struct rtsp_media_t)*(count-N_MEDIA));
	}

	ctx->media_count = count;

	// rfc 2326 C.1.1 Control URL (p80)
	// If found at the session level, the attribute indicates the URL for aggregate control
	ctx->aggregate = rtsp_media_aggregate_control_enable(sdp);
	rtsp_get_session_uri(sdp, ctx->aggregate_uri, sizeof(ctx->aggregate_uri), ctx->uri, ctx->baseuri, ctx->location);

	for(i = 0; i < count; i++)
	{
		int j, n;
		media = rtsp_get_media(ctx, i);
		media->cseq = rand();

		// RTSP2326 C.1.1 Control URL
		rtsp_get_media_uri(sdp, i, media->uri, sizeof(media->uri), ctx->aggregate_uri);

		n = sdp_media_formats(sdp, i, formats, N_MEDIA_FORMAT);
		media->avformat_count = n > N_MEDIA_FORMAT ? N_MEDIA_FORMAT : n;
		for(j = 0; j < media->avformat_count; j++)
		{
			media->avformats[j].pt = formats[j];
		}

		// update media encoding
		sdp_media_attribute_list(sdp, i, NULL, rtsp_media_onattr, media);		
	}

	return 0;
}