CPI_Stream_LocalFile.c
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:3k
源码类别:
VC书籍
开发平台:
Visual C++
- #include "stdafx.h"
- #include "globals.h"
- #include "CPI_Stream.h"
- typedef struct _CPs_InStream_File
- {
- HANDLE m_hFile;
- } CPs_InStream_File;
- //
- void CPSLOCAL_Uninitialise(CPs_InStream* pStream);
- BOOL CPSLOCAL_Read(CPs_InStream* pStream, void* pDestBuffer, const unsigned int iBytesToRead, unsigned int* piBytesRead);
- void CPSLOCAL_Seek(CPs_InStream* pStream, const unsigned int iNewOffset);
- unsigned int CPSLOCAL_GetLength(CPs_InStream* pStream);
- BOOL CPSLOCAL_IsSeekable(CPs_InStream* pStream);
- unsigned int CPSLOCAL_Tell(CPs_InStream* pStream);
- CPs_InStream* CP_CreateInStream_LocalFile(const char* pcFlexiURL, HWND hWndOwner)
- {
- HANDLE hFile;
- hFile = CreateFile(pcFlexiURL, GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
- OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);
- if(hFile == INVALID_HANDLE_VALUE)
- return NULL;
- {
- CPs_InStream* pNewStream = (CPs_InStream*)malloc(sizeof(CPs_InStream));
- CPs_InStream_File* pContext = (CPs_InStream_File*)malloc(sizeof(CPs_InStream_File));
- pNewStream->Uninitialise = CPSLOCAL_Uninitialise;
- pNewStream->Read = CPSLOCAL_Read;
- pNewStream->Seek = CPSLOCAL_Seek;
- pNewStream->Tell = CPSLOCAL_Tell;
- pNewStream->GetLength = CPSLOCAL_GetLength;
- pNewStream->IsSeekable = CPSLOCAL_IsSeekable;
- pNewStream->m_pModuleCookie = pContext;
- pContext->m_hFile = hFile;
- return pNewStream;
- }
- }
- //
- void CPSLOCAL_Uninitialise(CPs_InStream* pStream)
- {
- CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
- CP_CHECKOBJECT(pContext);
- CloseHandle(pContext->m_hFile);
- free(pContext);
- free(pStream);
- }
- //
- BOOL CPSLOCAL_Read(CPs_InStream* pStream, void* pDestBuffer, const unsigned int iBytesToRead, unsigned int* piBytesRead)
- {
- CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
- CP_CHECKOBJECT(pContext);
- return ReadFile(pContext->m_hFile, pDestBuffer, iBytesToRead, piBytesRead, 0);
- }
- //
- void CPSLOCAL_Seek(CPs_InStream* pStream, const unsigned int iNewOffset)
- {
- CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
- CP_CHECKOBJECT(pContext);
- SetFilePointer(pContext->m_hFile, iNewOffset, 0, FILE_BEGIN);
- }
- //
- unsigned int CPSLOCAL_GetLength(CPs_InStream* pStream)
- {
- CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
- CP_CHECKOBJECT(pContext);
- return GetFileSize(pContext->m_hFile, NULL);
- }
- //
- BOOL CPSLOCAL_IsSeekable(CPs_InStream* pStream)
- {
- return TRUE;
- }
- //
- #define GetFilePointer(hFile) SetFilePointer(hFile, 0, NULL, FILE_CURRENT)
- unsigned int CPSLOCAL_Tell(CPs_InStream* pStream)
- {
- CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
- CP_CHECKOBJECT(pContext);
- return GetFilePointer(pContext->m_hFile);
- }