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

📄 liveresource.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
#include "baseresource.h"

namespace NPLayer1 {

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

	// 第一次开始下载的初始化
	P2P_RETURN_TYPE Init(
		string resname,				// 资源名
		string hashcode,			// 资源的Hash码
		string strSPList,			// SuperPeer列表的IP地址
		float bitRate);				// 频道的码率

	P2P_RETURN_TYPE GetData(
		SampleHeader& header,	// out, 数据头
		PBYTE& pData,			// out, 存储数据的缓冲区
		const UINT maxSize,		// in, 缓冲区的长度
		const bool bAudio,		// in, 获取音频还是视频
		const bool bKeySample	// in, 是否寻找关键帧
		);

	BOOL SeekToTime(LONGLONG& targetTime);

	// 添加一个区间对应的媒体类型
	void AddMediaInterval(const MediaInterval&);
	// 获取一个Block所在区间的媒体类型
	bool GetMediaInterval(const UINT blockID, MediaInterval&);

	float GetBitRate() { return bitRate;};
	UINT16 GetBufferCount();
	UINT16 GetBufferTime();
	UINT16 GetBufferingTime();

	// 获取节目名字
	string GetProgramName();
	// 获取节目时间长度,单位是秒
	UINT32 GetProgramTimeInSeconds();
	// 获取频道名字
	string GetChannelName();
	// 获取数据中sample的原始时间
	LONGLONG GetOriginTime() {return max(A_last_OriginTime, V_last_OriginTime);};

	SPUpdate GetSPUpdate() { return spUpdate;};
	BYTE GetSPUpdateSum() {return spUpdateSum;};
	void SetSPUpdate(const SPUpdate& update, BYTE sum);

	// derived from BaseReSource
	UINT GetPlayingBlock(bool max=true);
	int GetBufferPercent();
	bool EnlargeBuffer();
	void PrintStatus();
	BOOL SetPlayingBlock(UINT blockID);
	void SetDefaultCP();
	P2P_RETURN_TYPE PutBlock(UINT blockID, UINT blockSize, PBYTE data);

protected:
	void Uninit(bool force);

	P2P_RETURN_TYPE InitBroadcastMember(float bitRate);
	P2P_RETURN_TYPE LoadSample(
		SampleHeader& header,	// Sample头
		PBYTE& sampleData,		// Sample数据
		UINT sampleOff,			// 已经读取的长度
		const UINT maxSize,		// Sample最大长度
		const bool isAudio,		// 视频还是音频
		bool& bMediaTypeSample	// 是否媒体类型的特殊Sample
		);
	// 获取此Block末尾一个Sample被截断后,在下一个Block所残留的长度,返回值表示此Block是否数据正确
	bool GetUnfinishedSampleSize(PBYTE& blockData, UINT& unfinishedSize);
	// 检查此Block是否新节目的第一块
	bool IsFirstBlockOfNewProgram(PBYTE& blockData);

private:
	enum PROGRAM_STATE {
		PS_BOTH_BEGINS, 
		PS_VIDEO_BEGINS, 
		PS_AUDIO_BEGINS,
	};
	enum {
		TIME_BETWEEN_PROGRAM = 1*10000000, // 节目间隔时间,单位是10^-7s
	};

	float				bitRate;				// 频道码率
	SPUpdate			spUpdate;				// SP发送的广播
	BYTE				spUpdateSum;

	UINT				V_currBlockID;			// 当前视频块的编号
	BYTE*				V_currBlock;			// 当前视频块的数据
	UINT				V_leftDataInCurrBlock;	// 当前视频块的剩余数据大小
	LONGLONG			V_lastSampleTime;		// 最近一个视频Sample的start time
	LONGLONG			V_last_OriginTime;		// 最近一个视频Sample的原始时间
	DWORD				V_lastGetSampleFailedTime;// 最近一次GetSample失败的时间,此刻与下次EnlargeBuffer的时间差就是本次Buffer所用的时间

	UINT				A_currBlockID;			// 当前音频块的编号
	BYTE*				A_currBlock;			// 当前音频块的数据
	UINT				A_leftDataInCurrBlock;	// 当前音频块的剩余数据大小
	LONGLONG			A_lastSampleTime;		// 最近一个音频Sample的start time
	LONGLONG			A_last_OriginTime;		// 最近一个音频Sample的原始时间
	DWORD				A_lastGetSampleFailedTime;// 最近一次GetSample失败的时间,此刻与下次EnlargeBuffer的时间差就是本次Buffer所用的时间

	BYTE*				tmpBlockData;			// 检查Block数据是否正确时,使用的临时空间
	
	LONGLONG			programStartTime;		// 当前节目的开始时间
	PROGRAM_STATE		programState;			// 节目状态,在新节目开始的时候可能需要进行视音频的同步

	UINT				totalBufferCount;		// 用户播放过程中发生了多少次缓冲
	UINT				totalBufferTime;		// 用户总共用了多少时间等待缓冲完毕

	MediaArray			mediaArray;				// 编码类型与BlockInterval的对应列表
	MediaArray			V_sentArray;			// 已经提交给上层的列表
	MediaArray			A_sentArray;			// 已经提交给上层的列表
};
}

⌨️ 快捷键说明

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