MediaPinType.cpp
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:3k
源码类别:
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
- *
- */
- #include "stdafx.h"
- #include ".mediapintype.h"
- SampleBuffer::SampleBuffer(void):m_buffer(NULL)
- {
- }
- SampleBuffer::~SampleBuffer()
- {
- delete[] m_buffer;
- }
- bool SampleBuffer::IsAnyDataSaved()
- {
- return m_buffer != NULL;
- }
- void SampleBuffer::SaveData(const SampleHeader& header, const BYTE* pData, const UINT maxSize)
- {
- if(m_buffer != NULL)
- Clean();
- if(header.size == 0)
- {
- m_size = maxSize;
- }
- else
- m_size = header.size;
- m_buffer = new BYTE[sizeof(SampleHeader) + m_size];
- memcpy(m_buffer, &header, sizeof(SampleHeader));
- memcpy(m_buffer + sizeof(SampleHeader), pData, m_size);
- }
- bool SampleBuffer::PeerData(SampleHeader& header, BYTE* pData, const UINT maxSize) const
- {
- if(m_buffer == NULL)
- return false;
- memcpy(&header, m_buffer, sizeof(SampleHeader));
- UINT datalen;
- if(m_size > maxSize)
- {
- datalen = maxSize;
- }
- else
- datalen = m_size;
- memcpy(pData, m_buffer + sizeof(SampleHeader), datalen);
- return true;
- }
- bool SampleBuffer::GetData(SampleHeader& header, BYTE* pData, const UINT maxSize)
- {
- if(!PeerData(header, pData, maxSize))
- return false;
- Clean();
- return true;
- }
- bool SampleBuffer::Alloc(SampleHeader* &pHeaderbuf, BYTE* &pDatabuf, const size)
- {
- Clean();
- m_size = size;
- m_buffer = new BYTE[sizeof(SampleHeader) + m_size];
- pHeaderbuf = reinterpret_cast<SampleHeader*>(m_buffer);
- pDatabuf = m_buffer + sizeof(SampleHeader);
- return true;
- }
- void SampleBuffer::Clean()
- {
- delete[] m_buffer;
- m_buffer = NULL;
- }
- MediaPinType::MediaPinType(void)
- {
- }
- MediaPinType::~MediaPinType(void)
- {
- }
- void MediaPinType::SaveMediaTypeData(const SampleHeader& header, const BYTE* pData, const UINT maxSize)
- {
- UINT len;
- if(maxSize < 256)
- len = maxSize;
- else
- len = 256;
- SaveData(header, pData, len);
- }
- bool MediaPinType::RestoreMediaTypeData(SampleHeader& header, BYTE* pData, const UINT maxSize) const
- {
- UINT len;
- if(maxSize < 256)
- len = maxSize;
- else
- len = 256;
- return PeerData(header, pData, len);
- }