-------------------------------------------------------------------------------------------------------------------------------------------------
杂学杂记·重要声明
-------------------------------------------------------------------------------------------------------------------------------------------------
《 杂学杂记》系列是笔者在工作时遇到的一些问题的解决方法,和一些笔者认为比较重要或者有用的知识,仅可作为读者参考之用,不能用于商业或其他用途,里面如有涉及公司代码未经本人同意不可挪用,如有违规者后果自负!
--------------------------------------------------------------------------------------------------------------------------------------------------
根据以下所给包头格式对数据封装:
Buf起始地址 | 类型 | 字节数 | 内容说明 |
Buf | BYTE | 1 | PP_VER = 1版本号 |
Buf+1 | BYTE | 1 | PP_0_LEN = 0 |
Buf+2 | short | 2 | PP_RSV = 0 预留空间 音频:buf+2:采样率Buf+3:采样位数 |
Buf+4 | RTP_DT_T | 4 | DateTime记录当前时间戳 |
Buf+8 | INT | 4 | TicketCount时间标记ms |
Buf+12 | INT | 4 | Len+3 包长度 |
Buf+16 | BYTE | 1 | Vsize视频大小音频:通道数 |
Buf+17 | BYTE | 1 | Frate帧率音频为压缩类型:GSM,G729A |
Buf+18 | BYTE | 1 | Iskey是否关键帧 |
代码如下:
#define PP_VER 1
#define PP_VER_2 2
#define PP_O_LEN 0
#define PP_RSV 0
.....
......
BYTE buf[19];
RTP_DT_T dataTime;
dataTime.year = sysTm.wYear-2000;
dataTime.month = sysTm.wMonth;
dataTime.day = sysTm.wDay;
dataTime.hour = sysTm.wHour;
dataTime.minute = sysTm.wMinute;
dataTime.second = sysTm.wSecond;
int idataTime;
memcpy((char *)&idataTime, (char *)&dataTime, 4);
//create head info of this frame
buf[0] = PP_VER_2;
buf[1] = PP_O_LEN;
WriteShort(buf + 2, PP_RSV);
WriteInt(buf + 4, idataTime);
WriteInt(buf + 8, GetTickCount());
WriteInt (buf + 12, len + 3);
buf[16] = vSize;
buf[17] = fRate;
buf[18] = isKey;
//write head info and frame data
output.Write(buf,19);
output.Write(data,len);
output.Close();