InfAnime.cpp
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:4k
源码类别:
P2P编程
开发平台:
Visual C++
- #include "stdafx.h"
- #include ".infanime.h"
- #include "zzlfilereader.h"
- extern HANDLE g_hModule;
- InfAnime::InfAnime(void):
- m_useproxymedia(true),pTipFileReader(NULL),m_animetype(REQUEST_NOPP),m_needvideotype(false),m_needaudiotype(false),
- m_accumulatevideotime(0) ,m_accumulateaudiotime(0)
- {
- }
- InfAnime::~InfAnime(void)
- {
- delete pTipFileReader;
- }
- bool InfAnime::IsProxyAvaible()
- {
- return m_useproxymedia;
- }
- bool InfAnime::StartProxy(ANIME_TYPE anime_type)
- {
- if(!m_useproxymedia)
- return false;
- if(m_animetype == anime_type)
- return true;
- delete pTipFileReader;
- pTipFileReader = new ZZLFileReader();
- bool ret = false;
- TCHAR lpModulePath[MAX_PATH_EX] = _T("");
- DWORD dwLen = GetModuleFileName((HMODULE)g_hModule, lpModulePath, MAX_PATH_EX);
- if(dwLen == 0)
- return false;
- TCHAR* idx = _tcsrchr(lpModulePath, _T('\'));
- if(idx == NULL)
- return false;
- *(idx+1) = _T(' ');
- string path = lpModulePath;
- path += _T("\clip01.zzl");
- switch(anime_type)
- {
- case REQUEST_FAIL:
- ret = pTipFileReader->Init(path.data());
- break;
- case REQUEST_PROCESS:
- ret = pTipFileReader->Init(path.data());
- break;
- case REQUEST_BUFFER:
- ret = pTipFileReader->Init(path.data());
- break;
- default:
- assert(0);
- return false;
- }
- if(ret == false)
- {
- delete pTipFileReader;
- pTipFileReader = NULL;
- return false;
- }
- m_needvideotype = true;
- m_needaudiotype = true;
- m_animetype = anime_type;
- return true;
- }
- void InfAnime::EndProxy()
- {
- m_animetype = REQUEST_NOPP;
- }
- P2P_RETURN_TYPE InfAnime::SetProxyMediaType(SampleHeader& header, PBYTE& pData, const UINT maxSize, const bool bAudio, const bool bKeySample)
- {
- memset(&header, 0, sizeof(SampleHeader));
- if(maxSize < sizeof(TVMEDIATYPESECTION))
- {
- assert(0);
- return PRT_SYS;
- }
- if(pTipFileReader->GetMediaType(*((TVMEDIATYPESECTION*) pData), bAudio) == FALSE)
- return PRT_SYS;
- TVMEDIATYPESECTION* ptvmedia = (TVMEDIATYPESECTION*) pData;
- header.size = sizeof(TVMEDIATYPESECTION) + ptvmedia->cbFormat;
- if(maxSize < header.size)
- {
- assert(0);
- return PRT_SYS;
- }
- if(pTipFileReader->GetMediaData(pData + sizeof(TVMEDIATYPESECTION), bAudio) == FALSE)
- return PRT_SYS;
- m_accumulateaudiotime = 0;
- m_accumulatevideotime = 0;
- if(bAudio)
- m_needaudiotype = false;
- else
- m_needvideotype = false;
- return PRT_OK;
- }
- P2P_RETURN_TYPE InfAnime::ProxyGetData(SampleHeader& header, PBYTE& pData, const UINT maxSize, const bool bAudio, const bool bKeySample)
- {
- if(!m_useproxymedia || pTipFileReader == NULL)
- return PRT_SYS;
- if(bAudio && m_needaudiotype) //如果是刚刚重新初始化, 需要把媒体类型送出以进行切换
- {
- return SetProxyMediaType(header, pData, maxSize, bAudio, bKeySample);
- }
- if((!bAudio) && m_needvideotype)
- {
- return SetProxyMediaType(header, pData, maxSize, bAudio, bKeySample);
- }
- header.bAudioSample = bAudio;
- P2P_RETURN_TYPE ret = pTipFileReader->GetSample(header, pData, maxSize, _I64_MAX);
- if(ret >= PRT_OK)
- {
- //将时间戳加上累积循环播放的时间
- if(bAudio)
- header.start += m_accumulateaudiotime;
- else
- header.start += m_accumulatevideotime;
- return PRT_OK;
- }
- else if(ret == PRT_ENDOFFILE) //已经到头了
- {
- LONGLONG tmp = 0;
- if(bAudio)
- {
- m_accumulateaudiotime += pTipFileReader->TryGetExplictEndTime(bAudio);
- pTipFileReader->SeekAudioTo(tmp);
- }
- else
- {
- m_accumulatevideotime += pTipFileReader->TryGetExplictEndTime(bAudio);
- pTipFileReader->SeekVideoTo(tmp);
- }
- header.bAudioSample = bAudio;
- return ProxyGetData(header, pData, maxSize, bAudio, bKeySample);
- }
- else
- {
- return PRT_SYS;
- }
- }