- Main Page
- Classes
- Files

# 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 ReadPartial(void*     buffer,
    00048                                    AP4_Size  bytes_to_read,
    00049                                    AP4_Size& bytes_read) = 0;
    00050     AP4_Result Read(void* buffer, AP4_Size bytes_to_read);
    00051     AP4_Result ReadDouble(double& value);
    00052     AP4_Result ReadUI64(AP4_UI64& value);
    00053     AP4_Result ReadUI32(AP4_UI32& value);
    00054     AP4_Result ReadUI24(AP4_UI32& value);
    00055     AP4_Result ReadUI16(AP4_UI16& value);
    00056     AP4_Result ReadUI08(AP4_UI08& value);
    00057     AP4_Result ReadString(char* buffer, AP4_Size size);
    00058     virtual AP4_Result WritePartial(const void* buffer,
    00059                                     AP4_Size    bytes_to_write,
    00060                                     AP4_Size&   bytes_written) = 0;
    00061     AP4_Result Write(const void* buffer, AP4_Size bytes_to_write);
    00062     AP4_Result WriteString(const char* string_buffer);
    00063     AP4_Result WriteDouble(double value);
    00064     AP4_Result WriteUI64(AP4_UI64 value);
    00065     AP4_Result WriteUI32(AP4_UI32 value);
    00066     AP4_Result WriteUI24(AP4_UI32 value);
    00067     AP4_Result WriteUI16(AP4_UI16 value);
    00068     AP4_Result WriteUI08(AP4_UI08 value);
    00069     virtual AP4_Result Seek(AP4_Position position) = 0;
    00070     virtual AP4_Result Tell(AP4_Position& position) = 0;
    00071     virtual AP4_Result GetSize(AP4_LargeSize& size) = 0;
    00072     virtual AP4_Result CopyTo(AP4_ByteStream& stream, AP4_LargeSize size);
    00073     virtual AP4_Result Flush() { return AP4_SUCCESS; }
    00074 };
    00075
    00076 /*----------------------------------------------------------------------
    00077 |   AP4_SubStream
    00078 +---------------------------------------------------------------------*/
    00079 class AP4_SubStream : public AP4_ByteStream
    00080 {
    00081  public:
    00082     AP4_SubStream(AP4_ByteStream& container,
    00083                   AP4_Position    position,
    00084                   AP4_LargeSize   size);
    00085
    00086     // AP4_ByteStream methods
    00087     AP4_Result ReadPartial(void*     buffer,
    00088                            AP4_Size  bytes_to_read,
    00089                            AP4_Size& bytes_read);
    00090     AP4_Result WritePartial(const void* buffer,
    00091                             AP4_Size    bytes_to_write,
    00092                             AP4_Size&   bytes_written);
    00093     AP4_Result Seek(AP4_Position position);
    00094     AP4_Result Tell(AP4_Position& position) {
    00095         position = m_Position;
    00096         return AP4_SUCCESS;
    00097     }
    00098     AP4_Result GetSize(AP4_LargeSize& size) {
    00099         size = m_Size;
    00100         return AP4_SUCCESS;
    00101     }
    00102
    00103     // AP4_Referenceable methods
    00104     void AddReference();
    00105     void Release();
    00106
    00107  protected:
    00108     virtual ~AP4_SubStream();
    00109
    00110  private:
    00111     AP4_ByteStream& m_Container;
    00112     AP4_Position    m_Offset;
    00113     AP4_LargeSize   m_Size;
    00114     AP4_Position    m_Position;
    00115     AP4_Cardinal    m_ReferenceCount;
    00116 };
    00117
    00118 /*----------------------------------------------------------------------
    00119 |   AP4_MemoryByteStream
    00120 +---------------------------------------------------------------------*/
    00121 class AP4_MemoryByteStream : public AP4_ByteStream
    00122 {
    00123 public:
    00124     AP4_MemoryByteStream(AP4_Size size = 0); // filled with zeros
    00125     AP4_MemoryByteStream(const AP4_UI08* buffer, AP4_Size size);
    00126     AP4_MemoryByteStream(AP4_DataBuffer& data_buffer); // data is read/written from/to supplied buffer
    00127
    00128     // AP4_ByteStream methods
    00129     AP4_Result ReadPartial(void*     buffer,
    00130                            AP4_Size  bytes_to_read,
    00131                            AP4_Size& bytes_read);
    00132     AP4_Result WritePartial(const void* buffer,
    00133                             AP4_Size    bytes_to_write,
    00134                             AP4_Size&   bytes_written);
    00135     AP4_Result Seek(AP4_Position position);
    00136     AP4_Result Tell(AP4_Position& position) {
    00137         position = m_Position;
    00138         return AP4_SUCCESS;
    00139     }
    00140     AP4_Result GetSize(AP4_LargeSize& size) {
    00141         size = m_Buffer->GetDataSize();
    00142         return AP4_SUCCESS;
    00143     }
    00144
    00145     // AP4_Referenceable methods
    00146     void AddReference();
    00147     void Release();
    00148
    00149     // methods
    00150     const AP4_UI08* GetData()     { return m_Buffer->GetData(); }
    00151     AP4_UI08*       UseData()     { return m_Buffer->UseData(); }
    00152     AP4_Size        GetDataSize() { return m_Buffer->GetDataSize(); }
    00153
    00154 protected:
    00155     virtual ~AP4_MemoryByteStream();
    00156
    00157 private:
    00158     AP4_DataBuffer* m_Buffer;
    00159     bool            m_BufferIsLocal;
    00160     AP4_Position    m_Position;
    00161     AP4_Cardinal    m_ReferenceCount;
    00162 };
    00163
    00164 #endif // _AP4_BYTE_STREAM_H_