Ap4AsyncReaderStream.cpp

00001 #include "StdAfx.h"
00002 #include "Ap4AsyncReaderStream.h"
00003 
00004 AP4_AsyncReaderStream::AP4_AsyncReaderStream(CBaseSplitterFile* pFile) 
00005         : m_refs(1)
00006         , m_pFile(pFile)
00007 {
00008         ASSERT(pFile);
00009 }
00010 
00011 AP4_AsyncReaderStream::~AP4_AsyncReaderStream()
00012 {
00013         ASSERT(m_refs == 0);
00014 }
00015 
00016 void AP4_AsyncReaderStream::AddReference()
00017 {
00018         ASSERT(m_refs > 0); 
00019         ++m_refs;
00020 }
00021 
00022 void AP4_AsyncReaderStream::Release()
00023 {
00024         ASSERT(m_refs > 0); 
00025         if(--m_refs == 0) delete this;
00026 }
00027 
00028 AP4_Result AP4_AsyncReaderStream::Read(void* buffer, AP4_Size bytesToRead, AP4_Size* bytesRead)
00029 {
00030         AP4_Size bytesAvail = (AP4_Size)(m_pFile->GetLength() - m_pFile->GetPos());
00031 
00032         if(bytesAvail < bytesToRead)
00033         {
00034                 if(bytesRead) *bytesRead = bytesAvail;
00035                 bytesToRead = bytesAvail;
00036         }
00037 
00038         if(bytesAvail == 0)
00039         {
00040                 return AP4_ERROR_EOS;
00041         }
00042 
00043         if(FAILED(m_pFile->Read((BYTE*)buffer, bytesToRead)))
00044         {
00045                 if(bytesRead) *bytesRead = 0;
00046                 return AP4_ERROR_READ_FAILED;
00047         }
00048 
00049         if(bytesRead) *bytesRead = bytesToRead;
00050         return AP4_SUCCESS;
00051 }
00052 
00053 AP4_Result AP4_AsyncReaderStream::Write(const void* buffer, AP4_Size bytesToWrite, AP4_Size* bytesWritten)
00054 {
00055     return AP4_ERROR_WRITE_FAILED;
00056 }
00057 
00058 AP4_Result AP4_AsyncReaderStream::Seek(AP4_Offset offset)
00059 {
00060         m_pFile->Seek(offset);
00061         return m_pFile->GetPos() == offset ? AP4_SUCCESS : AP4_FAILURE;
00062 }
00063 
00064 AP4_Result AP4_AsyncReaderStream::Tell(AP4_Offset& offset)
00065 {
00066         offset = (AP4_Offset)m_pFile->GetPos();
00067         return AP4_SUCCESS;
00068 }
00069 
00070 AP4_Result AP4_AsyncReaderStream::GetSize(AP4_Size& size)
00071 {
00072         size = (AP4_Size)m_pFile->GetLength();
00073         return AP4_SUCCESS;
00074 }

Generated on Tue Dec 13 14:47:20 2005 for guliverkli by  doxygen 1.4.5