Ap4ByteStream.h

Go to the documentation of this file.
00001 /*****************************************************************
00002 |
00003 |    AP4 - ByteStream Interface
00004 |
00005 |    Copyright 2002-2006 Gilles Boccon-Gibod & Julien Boeuf
00006 |
00007 |
00008 |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
00009 |
00010 |    Unless you have obtained Bento4 under a difference license,
00011 |    this version of Bento4 is Bento4|GPL.
00012 |    Bento4|GPL is free software; you can redistribute it and/or modify
00013 |    it under the terms of the GNU General Public License as published by
00014 |    the Free Software Foundation; either version 2, or (at your option)
00015 |    any later version.
00016 |
00017 |    Bento4|GPL is distributed in the hope that it will be useful,
00018 |    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 |    GNU General Public License for more details.
00021 |
00022 |    You should have received a copy of the GNU General Public License
00023 |    along with Bento4|GPL; see the file COPYING.  If not, write to the
00024 |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
00025 |    02111-1307, USA.
00026 |
00027  ****************************************************************/
00028 
00029 #ifndef _AP4_BYTE_STREAM_H_
00030 #define _AP4_BYTE_STREAM_H_
00031 
00032 /*----------------------------------------------------------------------
00033 |   includes
00034 +---------------------------------------------------------------------*/
00035 #include "Ap4Types.h"
00036 #include "Ap4Interfaces.h"
00037 #include "Ap4Results.h"
00038 #include "Ap4DataBuffer.h"
00039 
00040 /*----------------------------------------------------------------------
00041 |   AP4_ByteStream
00042 +---------------------------------------------------------------------*/
00043 class AP4_ByteStream : public AP4_Referenceable
00044 {
00045  public:
00046     // methods
00047     virtual AP4_Result Read(void*     buffer, 
00048                             AP4_Size  bytes_to_read, 
00049                             AP4_Size* bytes_read = 0) = 0;
00050     AP4_Result ReadUI64(AP4_UI64& value);
00051     AP4_Result ReadUI32(AP4_UI32& value);
00052     AP4_Result ReadUI24(AP4_UI32& value);
00053     AP4_Result ReadUI16(AP4_UI16& value);
00054     AP4_Result ReadUI08(AP4_UI08& value);
00055     AP4_Result ReadString(char* buffer, AP4_Size size);
00056     virtual AP4_Result Write(const void* buffer, 
00057                              AP4_Size    bytes_to_write, 
00058                              AP4_Size*   bytes_written = 0) = 0;
00059     AP4_Result WriteString(const char* stringBuffer);
00060     AP4_Result WriteUI64(AP4_UI64 value);
00061     AP4_Result WriteUI32(AP4_UI32 value);
00062     AP4_Result WriteUI24(AP4_UI32 value);
00063     AP4_Result WriteUI16(AP4_UI16 value);
00064     AP4_Result WriteUI08(AP4_UI08 value);
00065     virtual AP4_Result Seek(AP4_Position position) = 0;
00066     virtual AP4_Result Tell(AP4_Position& position) = 0;
00067     virtual AP4_Result GetSize(AP4_LargeSize& size) = 0;
00068     virtual AP4_Result CopyTo(AP4_ByteStream& stream, AP4_LargeSize size);
00069 };
00070 
00071 /*----------------------------------------------------------------------
00072 |   AP4_SubStream
00073 +---------------------------------------------------------------------*/
00074 class AP4_SubStream : public AP4_ByteStream
00075 {
00076  public:
00077     AP4_SubStream(AP4_ByteStream& container, AP4_Position position, AP4_Size size);
00078 
00079     // AP4_ByteStream methods
00080     AP4_Result Read(void*    buffer, 
00081                     AP4_Size  bytes_to_read, 
00082                     AP4_Size* bytes_read = 0);
00083     AP4_Result Write(const void* buffer, 
00084                      AP4_Size    bytes_to_write, 
00085                      AP4_Size*   bytes_written = 0);
00086     AP4_Result Seek(AP4_Position position);
00087     AP4_Result Tell(AP4_Position& position) {
00088         position = m_Position;
00089         return AP4_SUCCESS;
00090     }
00091     AP4_Result GetSize(AP4_LargeSize& size) {
00092         size = m_Size;
00093         return AP4_SUCCESS;
00094     }
00095 
00096     // AP4_Referenceable methods
00097     void AddReference();
00098     void Release();
00099 
00100  protected:
00101     virtual ~AP4_SubStream();
00102 
00103  private:
00104     AP4_ByteStream& m_Container;
00105     AP4_Position    m_Offset;
00106     AP4_LargeSize   m_Size;
00107     AP4_Position    m_Position;
00108     AP4_Cardinal    m_ReferenceCount;
00109 };
00110 
00111 /*----------------------------------------------------------------------
00112 |   AP4_MemoryByteStream
00113 +---------------------------------------------------------------------*/
00114 class AP4_MemoryByteStream : public AP4_ByteStream
00115 {
00116 public:
00117     AP4_MemoryByteStream(AP4_Size size = 0); // filled with zeros
00118     AP4_MemoryByteStream(AP4_UI08* buffer, AP4_Size size);
00119 
00120     // AP4_ByteStream methods
00121     AP4_Result Read(void*     buffer, 
00122                     AP4_Size  bytes_to_read, 
00123                     AP4_Size* bytes_read = 0);
00124     AP4_Result Write(const void* buffer, 
00125                      AP4_Size    bytes_to_write, 
00126                      AP4_Size*   bytes_written = 0);
00127     AP4_Result Seek(AP4_Position position);
00128     AP4_Result Tell(AP4_Position& position) {
00129         position = m_Position;
00130         return AP4_SUCCESS;
00131     }
00132     AP4_Result GetSize(AP4_LargeSize& size) {
00133         size = m_Buffer.GetDataSize();
00134         return AP4_SUCCESS;
00135     }
00136 
00137     // AP4_Referenceable methods
00138     void AddReference();
00139     void Release();
00140 
00141     // methods
00142     const AP4_UI08* GetData() { return m_Buffer.GetData(); }
00143     AP4_UI08*       UseData() { return m_Buffer.UseData(); }
00144     AP4_Size        GetSize() { return m_Buffer.GetDataSize(); }
00145 
00146 protected:
00147     virtual ~AP4_MemoryByteStream() {};
00148 
00149 private:
00150     AP4_DataBuffer m_Buffer;
00151     AP4_Position   m_Position;
00152     AP4_Cardinal   m_ReferenceCount;
00153 };
00154 
00155 #endif // _AP4_BYTE_STREAM_H_

Generated on Thu Mar 15 16:06:10 2007 for Bento4 MP4 SDK by  doxygen 1.5.1-p1