⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gloab.h

📁 基于Nucleus的RTSP协议的简单实例
💻 H
字号:
#ifndef _GLOAB_H
#define _GLOAB_H
#include "stdio.h"
#include "Nucleus.h"
#include "string.h" 
#include "stdlib.h"
#include "time.h"
#include <assert.h>
#define BUFFER_LEN  100
#define OPTIONS       1000
#define SETUP         1001
#define PLAY          1002
#define TEARDOWN      1003
#define SET_PARAMETER 1004
#define DESCRIBE      1005
extern NU_MEMORY_POOL  dm_memory;
extern HANDLE		Con_Apl;
CHAR request[100];
CHAR response[100];
typedef struct RtspRequest_struct
{
	char		*Method;
	char		*FilePath;
	char        *Ver;
	char		*Cseq;
	char		*SessionId;
}	RtspRequest;
INT ParseRequestLine(RtspRequest* rtspreq, INT* len)
{
	STATUS isEnd = 0;		//RequestLine是否结束

	CHAR request_line[BUFFER_LEN];	//临时存储Request_line
	CHAR buf[BUFFER_LEN];			

	INT req_line_idx = 0;
	INT req_idx = 0;
	INT idx;
	INT wi;
	INT method_Type;

	assert(rtspreq != NULL);

	if (request[0] <= 'A' || request[0] >= 'Z')
	{//方法的第一个字符不是大写字母,不能解析
		return -1;
	}

	//开始解析RequestLine
	while (!isEnd)
	{//首先拷贝RequestLine到缓存request_line中
		if (request[req_idx] == '\r' && request[req_idx + 1] == '\n')
		{//Request Line结束
			isEnd = 1;

			req_idx += 2;

			break;
		}

		request_line[req_line_idx++] = request[req_idx++];		
	}

	*len = req_idx;

	//首先提取Method
	idx = 0;
	wi = 0;
	while (wi < req_line_idx && request_line[wi] != ' ')
	{
		buf[idx++] = request_line[wi++];		
	}

	buf[idx] = '\0';
	NU_Allocate_Memory(&dm_memory, &rtspreq->Method, idx, NU_NO_SUSPEND);

	//判断Method的类型

	/*
	if (strcmp(buf, "OPTIONS") == 0)
	{
	*method_type = OPTIONS;
	}
	else if (strcmp(buf, "SETUP") == 0)
	{
	*method_type = SETUP;
	}
	else if (strcmp(buf, "PLAY") == 0)
	{
	*method_type = PLAY;
	}
	else if (strcmp(buf, "TEARDOWN") == 0)
	{
	*method_type = TEARDOWN;
	}
	else if (strcmp(buf, "SET_PARAMETER") == 0)
	{
	*method_type = SET_PARAMETER;
	}
	else if (strcmp(buf, "DESCRIBE") == 0)
	{
	*method_type = DESCRIBE;
	}*/

	if (rtspreq->Method != NULL)
	{
		if (strcmp(buf, "OPTIONS") == 0)
		{
			strcpy(rtspreq->Method, "OPTIONS");
			method_Type = OPTIONS;
		}
		else if (strcmp(buf, "SETUP") == 0)
		{
			strcpy(rtspreq->Method, "SETUP");
			method_Type = SETUP;
		}
		else if (strcmp(buf, "PLAY") == 0)
		{
			strcpy(rtspreq->Method, "PLAY");
			method_Type = PLAY;
		}
		else if (strcmp(buf, "TEARDOWN") == 0)
		{
			strcpy(rtspreq->Method, "TEARDOWN");
			method_Type = TEARDOWN;
		}
		else if (strcmp(buf, "SET_PARAMETER") == 0)
		{
			strcpy(rtspreq->Method, "SET_PARAMETER");
			method_Type = SET_PARAMETER;
		}
		else if (strcmp(buf, "DESCRIBE") == 0)
		{
			strcpy(rtspreq->Method, "DESCRIBE");
			method_Type = DESCRIBE;
		}
		else
		{
			return -1;
		}
	}

	//提取Path
	idx = 0;
	wi++;
	while (wi < req_line_idx && request_line[wi] != ' ')
	{
		buf[idx++] = request_line[wi++];		
	}

	buf[idx] = '\0';
	NU_Allocate_Memory(&dm_memory, &rtspreq->FilePath, idx, NU_NO_SUSPEND);

	if (rtspreq->FilePath != NULL)
	{
		strcpy(rtspreq->FilePath, buf);
	}

	//提取版本
	idx = 0;
	wi++;
	while (wi < req_line_idx && request_line[wi] != ' ' && request_line[wi] != '\r')
	{
		buf[idx++] = request_line[wi++];		
	}

	buf[idx] = '\0';
	NU_Allocate_Memory(&dm_memory, &rtspreq->Ver, idx, NU_NO_SUSPEND);

	if (rtspreq->FilePath != NULL)
	{
		strcpy(rtspreq->Ver, buf);
	}


	return method_Type;
}
INT ParaseRequestHeader(RtspRequest* rtspreq, INT startIdx)
{
	INT isEnd = 0;
	INT newLine = 0;
	INT index = startIdx;
	INT bufIdx = 0;
	CHAR tmpc;

	CHAR buf[BUFFER_LEN];

//	DWORD NumWritten;

	assert(startIdx > 0 && startIdx <  BUFFER_LEN - 1 && rtspreq != NULL);

	//开始解析头,循环一次解析一行
	while (!isEnd && index < BUFFER_LEN - 1)
	{
		//一行的开头就是回车换行符,结束解析
		if (request[index] == '\r' && request[index + 1] == '\n' && newLine == 1)
		{
			break;
		}

		newLine = 0;
		bufIdx = 0;

		//解析Header
		while ((tmpc = request[index++]) != ':')
		{
			buf[bufIdx++] = tmpc;
		}


		buf[bufIdx] = '\0';

		index++;

		if (strcmp(buf, "CSeq") == 0)
		{//解析头CSeq
			bufIdx = 0;

			while (request[index] != '\r' && request[index + 1] != '\n')
			{
				buf[bufIdx++] = request[index++];
			}

			buf[bufIdx] = '\0';


			NU_Allocate_Memory(&dm_memory, &rtspreq->Cseq, bufIdx, NU_NO_SUSPEND);

			//存储CSeq头
			if (rtspreq->Cseq != NULL)
			{
				strcpy(rtspreq->Cseq, buf);
			}

			newLine = 1;
			index += 2;
			continue;
		}
		else if (strcmp(buf, "Session") == 0)
		{
			bufIdx = 0;


			while (request[index] != '\r' && request[index + 1] != '\n')
			{
				buf[bufIdx++] = request[index++];
			}

			buf[bufIdx] = '\0';

			NU_Allocate_Memory(&dm_memory, &rtspreq->SessionId, bufIdx, NU_NO_SUSPEND);

			//存储CSeq头
			if (rtspreq->SessionId != NULL)
			{
				strcpy(rtspreq->SessionId, buf);
			}

			newLine = 1;
			index += 2;
			continue;
		}
	}

	return 1;
}

char Method_Code[6][15]={"OPTIONS","SETUP","PLAY","TEARDOWN","SET_PARAMETER","DESCRIBE"};
/*rtsp消息包结构*/

///*应答状态代码,不全*/
//#define RTSP_200_STATUS			200;
//#define RTSP_201_STATUS			201;
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -