Exemplo n.º 1
0
S32 rtsp_play(S32 cur_conn_num)
{
	CHAR *p = NULL;
	CHAR  trash[255];
	
	if(!rtsp[cur_conn_num]->in_buffer) {
		return -1;
	}
	/**** Parse the input message ****/

	if(check_rtsp_url(cur_conn_num) < 0){
		return -1;
	}

	if(get_rtsp_cseg(cur_conn_num) < 0){
		return -1;
	}
	if(check_rtsp_filename(cur_conn_num) < 0){
		return -1;
	}
	
	// If we get a Session hdr, then we have an aggregate control
	if ((p = strstr(rtsp[cur_conn_num]->in_buffer, HDR_SESSION)) != NULL) {
		if (sscanf(p, "%254s %d", trash, &rtsp[cur_conn_num]->session_id) != 2) {
			send_reply(454,cur_conn_num);	/* Session Not Found */
			return -1;
		}
	} else {
		send_reply(400,cur_conn_num);	/* bad request */
		return -1;
	}

	if(send_play_reply(200,cur_conn_num)!=-1)
		return 1;

	return 0;
}
Exemplo n.º 2
0
int RTSP_play(RTSP_buffer * pRtsp)
{
	char *pStr;
	char pTrash[128];
	long int s32SessionId;
	RTSP_session *pRtspSesn;
	RTP_session *pRtpSesn;

	//获取CSeq
	if ((pStr = strstr(pRtsp->in_buffer, HDR_CSEQ)) == NULL)
	{
		send_reply(400, 0, pRtsp);   /* Bad Request */
		printf("get CSeq!!400");
		return ERR_NOERROR;
	}
	else
	{
		if (sscanf(pStr, "%254s %d", pTrash, &(pRtsp->rtsp_cseq)) != 2)
		{
			send_reply(400, 0, pRtsp);    /* Bad Request */
			printf("get CSeq!! 2 400");
			return ERR_NOERROR;
		}
	}

	//获取session
	if ((pStr = strstr(pRtsp->in_buffer, HDR_SESSION)) != NULL)
	{
		if (sscanf(pStr, "%254s %ld", pTrash, &s32SessionId) != 2)
		{
			send_reply(454, 0, pRtsp);// Session Not Found
			printf("Session Not Found");
			return ERR_NOERROR;
		}
	}
	else
	{
		send_reply(400, 0, pRtsp);// bad request
		printf("Session Not Found bad request");
		return ERR_NOERROR;
	}

	//时间参数,假设都是 0-0,不做设置
/*	if ((pStr = strstr(pRtsp->in_buffer, HDR_RANGE)) != NULL)
	{
		if((pStrTime = strstr(pRtsp->in_buffer, "npt")) != NULL)
		{
			if((pStrTime = strstr(pStrTime, "=")) == NULL)
			{
				send_reply(400, 0, pRtsp);// Bad Request
				return ERR_NOERROR;
			}

		}
		else
		{

		}
	}
*/
	//播放list指向的rtp session
	pRtspSesn = pRtsp->session_list;
	if (pRtspSesn != NULL)
	{
		if (pRtspSesn->session_id == s32SessionId)
		{
			//查找RTP session,播放list中所有的session,本例程只有一个成员.
			for (pRtpSesn = pRtspSesn->rtp_session; pRtpSesn != NULL; pRtpSesn = pRtpSesn->next)
			{
				//播放所有演示
				if (!pRtpSesn->started)
				{
					//开始新的播放
					printf("\t+++++++++++++++++++++\n");
					printf("\tstart to play %d now!\n", pRtpSesn->sched_id);
					printf("\t+++++++++++++++++++++\n");

					if (schedule_start(pRtpSesn->sched_id, NULL) == ERR_ALLOC)
					{
						return ERR_ALLOC;
					}
				}
				else
				{
					//恢复暂停,播放
					if (!pRtpSesn->pause)
					{
						//fnc_log(FNC_LOG_INFO,"PLAY: already playing\n");
					}
					else
					{
//						schedule_resume(pRtpSesn->sched_id, NULL);
					}
				}

			}
		}
		else
		{
			send_reply(454, 0, pRtsp);	// Session not found
			return ERR_NOERROR;
		}
	}
	else
	{
		send_reply(415, 0, pRtsp);  // Internal server error
		return ERR_GENERIC;
	}

	send_play_reply(pRtsp, pRtspSesn);

	return ERR_NOERROR;
}