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

📄 infanime.cpp

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

extern TCHAR	g_sAppPath[MAX_PATH];

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;
}

void InfAnime::DirectFileName(LPTSTR namebuffer)
{
    SYSTEMTIME systime;
    systime.wYear = 0;
    GetLocalTime(&systime);

    while(1)
    {
        //2006春节缓冲
        if((systime.wYear == 2006) && ((systime.wMonth == 1 && systime.wDay >= 28)
            || (systime.wMonth == 2 && systime.wDay <= 8)))
        {
            _tcscpy(namebuffer, _T("clip02.zzl"));
            return;
        }

        break;

    }

    //使用默认名
    _tcscpy(namebuffer, _T("clip01.zzl"));
}

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;

    CString path(g_sAppPath);
    TCHAR name[32];
    DirectFileName(name);
    path += _T("\\");
    path += name;

    switch(anime_type)
    {
    case 	REQUEST_FAIL:
        ret = pTipFileReader->Init(path);
        break;
    case    REQUEST_PROCESS:
        ret = pTipFileReader->Init(path);
        break;
    case    REQUEST_BUFFER:
        ret = pTipFileReader->Init(path);
        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_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;
        ret = pTipFileReader->GetSample(header, pData, maxSize, _I64_MAX);
//        if(ret == PRT_ENDOFFILE)
//          MessageBox(NULL, "two file end!", "", MB_OK);
    }

    if(ret == PRT_OK)
    {
         //将时间戳加上累积循环播放的时间
        if(bAudio)
            header.start += m_accumulateaudiotime;
        else
            header.start += m_accumulatevideotime;
        return PRT_OK;
    }
    else
        return PRT_SYS;
}

⌨️ 快捷键说明

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