ZZLFileReader.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
- class CTVStreamSource;
- class ZZLFileReader
- {
- public:
- ZZLFileReader();
- virtual ~ZZLFileReader(void);
- bool Init(const char* filename);
- void Uninit();
- STDMETHODIMP GetAvailable(LONGLONG& pEarliest,LONGLONG& pLatest);
- STDMETHODIMP GetDuration(LONGLONG& pDuration);
- STDMETHODIMP GetStopPosition(LONGLONG& pStop);
- //
- LONGLONG GetStartTime()
- {
- if(IsInited())
- return m_startTime;
- //
- return 0;
- }
- LONGLONG GetEndTime()
- {
- if(IsInited())
- return m_endTime;
- //
- return 0;
- }
- //尝试获得精确的结束时间。这是通过获得的sample计算的,所以越接近终结就越准确
- LONGLONG TryGetExplictEndTime(bool isAudio)
- {
- if(isAudio)
- return m_AudioEndTime;
- else
- return m_VideoEndTime;
- }
- // 获取媒体类型
- int GetMediaType(TVMEDIATYPESECTION&, BOOL isAudio);
- // 获取媒体数据
- int GetMediaData(PBYTE, BOOL isAudio);
- // 获取Sample.
- // startTime != _I64_MAX的话,寻找startTime之后的第一个Sample,
- // 视频Sample的话还要满足是关键帧的条件
- P2P_RETURN_TYPE GetSample(
- SampleHeader& header, // Sample头
- PBYTE& pData, // Sample数据
- const UINT maxSize, // Sample的最大值
- LONGLONG seekTime); // Seek的目标时间
- // Seek到某个时间
- bool SeekTo(LONGLONG seekTime, int pin = 3); // 目标时间
- bool SeekVideoTo(LONGLONG seekTime);
- bool SeekAudioTo(LONGLONG seekTime);
- private:
- P2P_RETURN_TYPE LoadSample(
- SampleHeader& header, // Sample头
- PBYTE& sampleData, // Sample数据
- UINT sampleOff, // 已经读取的长度
- const UINT maxSize, // Sample最大长度
- const bool isAudio); // 视频还是音频
- // http下载线程
- static void __stdcall RunHttpDownload(ZZLFileReader*);
- // 读取文件头
- bool ReadFileHeader();
- // 如果headerSize已经已知,则说明已经读取过文件头,初始化成功了
- bool IsInited() {return m_iHeaderSize > 0;};
- private:
- HANDLE m_hDownThread; // 下载线程
- bool m_isStopped; // 是否已经停止
- HANDLE m_hFile; // 打开文件的句柄
- UINT m_iFileSize; // 文件大小
- UINT m_iDownloadedSize; // 对于HTTP的zzl,已经下载的长度
- UINT m_iHeaderSize; // 文件头的长度
- TVMEDIATYPESECTION m_VideoType;
- TVMEDIATYPESECTION m_AudioType;
- //
- BYTE* m_pVideoFormat;
- BYTE* m_pAudioFormat;
- LONGLONG m_startTime;
- LONGLONG m_endTime;
- LONGLONG m_VideoEndTime;
- LONGLONG m_AudioEndTime; //具有10^7精度的媒体时间
- //
- LONGLONG m_llSeekTo;
- BYTE A_currBlock[BLOCK_SIZE];
- BYTE V_currBlock[BLOCK_SIZE];
- //
- UINT A_currBlockID;
- UINT V_currBlockID;
- //
- UINT A_iLeftDataInCurrBlock;
- UINT V_iLeftDataInCurrBlock;
- // CTVStreamSource* m_pFilter;
- //
- CCritSec m_pLock;
- const float FILE_VERSION; // 支持的zzl文件的版本
- const float LIMIT_DOWN_SPEED; // 限制下载速度的最大值
- const UINT MAX_HEADER_SIZE; // zzl header的最大长度(用来检查zzl header是否已经下载)
- };