Structs.h
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:4k
源码类别:
P2P编程
开发平台:
Visual C++
- /*
- * Openmysee
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
- // 系统通用的数据结构以及部分常量的定义
- #pragma once
- enum {
- TS4NP_PORT = 53, // TS接受NP访问的默认端口
- CP4NP_PORT = 80, // CP接受NP访问的默认端口
- MD5_LEN = 32, // MD5值的长度
- BLOCK_SIZE = 16384, // 默认分块大小
- };
- // 普通网络的IP地址信息,精简版,大小8字节
- // 不能直接当做sockaddr使用,只能赋值给一个sockaddr
- class NormalAddress {
- public:
- NormalAddress() {
- memset(this, 0, sizeof(NormalAddress));
- sin_family = AF_INET;
- };
- bool operator == (const NormalAddress& addr) const {
- return ((addr.sin_addr.s_addr == sin_addr.s_addr) &&
- (addr.sin_port == sin_port));
- };
- short sin_family;
- u_short sin_port;
- struct in_addr sin_addr;
- };
- // P2P网络的Peer地址信息, 精简版,大小16字节
- class P2PAddress {
- public:
- BOOL IsNAT() const { return !(0xffffffff == subnetIP.sin_addr.s_addr);};
- // 外网用户的本机IP和发送段口,内网用户的出口网关IP和发送段口
- NormalAddress outerIP;
- // 外网用户为"255.255.255.255"和监听段口,内网用户的内网IP和监听端口
- NormalAddress subnetIP;
- // P2PAddress不需要比较外网的端口
- bool operator == (const P2PAddress& addr) const {
- return ((addr.outerIP.sin_addr.s_addr == outerIP.sin_addr.s_addr) && (addr.subnetIP == subnetIP));
- };
- };
- // 这是P2P网络中最需要交流的信息,将来还可能进行扩充,目前大小4字节
- class CorePeerInfo {
- public:
- CorePeerInfo() {memset(this, 0, sizeof(CorePeerInfo));};
- unsigned layer:8; // 在P2P网络中位于第几层(最大256)
- unsigned isMaxIn:1; // 是否达到最大连入的连接数
- unsigned isMaxOut:1; // 是否达到最大连出的连接数
- unsigned isMaxFreeIn:1; // 是否达到最大连入的连接数(作贡献)
- unsigned isMaxFreeOut:1;// 是否达到最大连出的连接数(作贡献)
- unsigned isCachePeer:1; // 是CachePeer还是NormalPeer
- unsigned :19; // 空位域,留作以后使用
- };
- // 加上Peer地址的PeerInfo, 目前大小20字节
- class PeerInfoWithAddr : public CorePeerInfo, public P2PAddress {};
- // 数据传输的相关信息,目前大小32字节
- class TransferInfo {
- public:
- TransferInfo() { memset(this, 0, sizeof(TransferInfo)); };
- LONGLONG totalDownBytes; // 总共下载字节
- LONGLONG totalUpBytes; // 总共上传字节
- float currDownSpeed; // 当前下载速度
- float currUpSpeed; // 当前上传速度
- float avgDownSpeed; // 平均下载速度
- float avgUpSpeed; // 平均上传速度
- };
- // DirectShow初始化需要的媒体类型数据,大小56字节
- struct MediaType {
- GUID majortype;
- GUID subtype;
- GUID formattype;
- ULONG lSampleSize;
- unsigned bFixedSizeSamples:1;
- unsigned bTemporalCompression:1;
- unsigned bThisPinOnly:1;
- unsigned cbFormat:16;
- unsigned :13;
- };
- // Sample头的大小,共16字节
- // 如果length和start都等于-1,则此Sample是节目开始的标志,不包含任何数据
- // 如果length和start都等于0, 则此Sample是媒体类型数据,bAudioSample表示音频或者视频
- struct SampleHeader {
- unsigned size:28; // 此Sample大小
- unsigned bDiscontinuity:1; // Sample属性
- unsigned bPreroll:1; // Sample属性
- unsigned bSyncPoint:1; // 是否关键帧
- unsigned bAudioSample:1; // 是否音频Sample
- UINT length; // 时间跨度
- LONGLONG start; // 起始时间
- };
- // SP发送的更新,要在NP之间传播, 大小24字节
- class SPUpdate {
- public:
- SPUpdate() : minKeySample(0x7fffffffffffffff), maxKeySample(0),
- minBlockID(0xffffffff), maxBlockID(0){};
- LONGLONG minKeySample; // SP上最小的KeySample时间
- LONGLONG maxKeySample; // SP上最大的KeySample时间
- UINT minBlockID; // SP上最小的块编号
- UINT maxBlockID; // SP上最大的块编号
- };