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

📄 baseresource.h

📁 mysee网络直播源代码Mysee Lite是Mysee独立研发的网络视频流媒体播放系统。在应有了P2P技术和一系列先进流媒体技术之后
💻 H
字号:
/*
 *  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

namespace NPLayer1 {
class Communicator;
class BufferMgr;

class BaseResource {
public:
	BaseResource(Communicator*);
	virtual ~BaseResource(void);

	void DeleteResFile() {
		Uninit(false);
	};

	// 在虚拟缓冲区寻找空块或者可以替换的块,返回其在虚拟缓冲区的位置
	UINT GetReplacableBlock(const UINT newBlockID, UINT& replacedBlockID);

	// 针对某个NP的区间列表,获取可以下载的区间列表
	void GetDownloadableArray(const IntervalArray& anotherNP, IntervalArray& result);

	P2P_RETURN_TYPE GetBlock(UINT blockID, UINT& blockSize, LPVOID data);
	P2P_RETURN_TYPE PutBlock(UINT blockID, UINT blockSize, PBYTE data);
	void DelBlock(UINT blockID);

	bool FindBlock(UINT blockID) { return allIntervals.FindBlock(blockID);};
	UINT GetMinBlockID() { return allIntervals.GetMinBlockID();};
	UINT GetMaxBlockID() { return allIntervals.GetMaxBlockID();};
	// 复制全部区间列表
	void GetAllIntervals(BlockInterval* targetArray, UINT8& size) ;
	// 发送给TS/NP的区间列表
	void GetDiffIntervals(BlockInterval* targetArray, UINT8& size, bool forTS, bool getInc);
	// 清空发送给TS/NP的增量区间列表
	void ClearDiffIntervals(bool forTS);

	string GetHashCode() { return hashcode;};	// 取得资源的Hash Code
	string GetResName() { return resname;};	
	UINT8 GetSPListSize() { return spIPListSize;};
	NormalAddress* GetSPList() { return spIPList;};

	virtual UINT GetPlayingBlock(bool max=true) = 0;
	virtual int GetBufferPercent() = 0;
	virtual bool EnlargeBuffer() = 0;
	virtual void PrintStatus() = 0;
	virtual BOOL SetPlayingBlock(UINT blockID) = 0;
	virtual void SetDefaultCP() = 0;

protected:
	virtual void Uninit(bool force) = 0;
	void UninitEx();

	P2P_RETURN_TYPE ParseSPList(string strSPList);
	UINT FindBlockIndex(UINT blockID);

protected:
	string				resname;				// 资源名
	string				hashcode;				// 请求资源的MD5码
	NormalAddress*		spIPList;				// SuperPeer列表的IP地址
	UINT8				spIPListSize;			// SuperPeer列表的大小

	UINT*				blockIDArray;			// 虚拟缓冲区中对应的BlockID
	UINT*				blockMapArray;			// 虚拟缓冲区与真正缓冲区(BufferMgr)的对应表
	UINT				blockMapSize;			// 虚拟缓冲区中块的个数
	IntervalArray	allIntervals;			// 所有已下载块的区间列表
	IntervalArray	csIncIntervals;			// 发送给TS的增量区间列表(增加的)
	IntervalArray	csDecIntervals;			// 发送给TS的增量区间列表(减少的)
	IntervalArray	p2pIncIntervals;		// 发送给NP的增量区间列表(增加的)
	IntervalArray	p2pDecIntervals;		// 发送给NP的增量区间列表(减少的)

	UINT				blocks4Play;			// 有一定的块,开始或者继续播放

	BOOL				bInited;				// 是否已经初始化
	CriticalSection		dataLocker;				// 数据访问的互斥变量

	BufferMgr*			bufferMgr;
	Communicator*		comm;

protected:
	enum {
		// 默认使用最大 DEFAULT_SPACE Bytes 的磁盘空间
		DEFAULT_SPACE = 1048576*20, 
		// 每次开始播放前,需要缓冲TIME_FOR_PLAY秒的数据
		TIME_FOR_PLAY = 45, 

		// 选择开始播放的位置,在SPUpdate.maxBlockID之前TIME_BEGIN_PLAY秒的块
		TIME_BEGIN_PLAY = 45,
	};
};

}

⌨️ 快捷键说明

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