- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# Ap4ByteStream.h

    00001 /*****************************************************************
    00002 |
    00003 |    AP4 - ByteStream Interface
    00004 |
    00005 |    Copyright 2002 Gilles Boccon-Gibod
    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
    00039 /*----------------------------------------------------------------------
    00040 |       AP4_ByteStream
    00041 +---------------------------------------------------------------------*/
    00042 class AP4_ByteStream : public AP4_Referenceable
    00043 {
    00044  public:
    00045     // methods
    00046     virtual AP4_Result Read(void*     buffer,
    00047                             AP4_Size  bytes_to_read,
    00048                             AP4_Size* bytes_read = 0) = 0;
    00049     virtual AP4_Result ReadUI64(AP4_UI64& value);
    00050     virtual AP4_Result ReadUI32(AP4_UI32& value);
    00051     virtual AP4_Result ReadUI24(AP4_UI32& value);
    00052     virtual AP4_Result ReadUI16(AP4_UI16& value);
    00053     virtual AP4_Result ReadUI08(AP4_UI08& value);
    00054     virtual AP4_Result ReadString(char* buffer, AP4_Size size);
    00055     virtual AP4_Result Write(const void* buffer,
    00056                              AP4_Size    bytes_to_write,
    00057                              AP4_Size*   bytes_written = 0) = 0;
    00058     virtual AP4_Result WriteString(const char* stringBuffer);
    00059     virtual AP4_Result WriteUI64(AP4_UI64 value);
    00060     virtual AP4_Result WriteUI32(AP4_UI32 value);
    00061     virtual AP4_Result WriteUI24(AP4_UI32 value);
    00062     virtual AP4_Result WriteUI16(AP4_UI16 value);
    00063     virtual AP4_Result WriteUI08(AP4_UI08 value);
    00064     virtual AP4_Result Seek(AP4_Offset offset) = 0;
    00065     virtual AP4_Result Tell(AP4_Offset& offset) = 0;
    00066     virtual AP4_Result GetSize(AP4_Size& size) = 0;
    00067     virtual AP4_Result CopyTo(AP4_ByteStream& stream, AP4_Size size);
    00068 };
    00069
    00070 /*----------------------------------------------------------------------
    00071 |       AP4_SubStream
    00072 +---------------------------------------------------------------------*/
    00073 class AP4_SubStream : public AP4_ByteStream
    00074 {
    00075  public:
    00076     AP4_SubStream(AP4_ByteStream& container, AP4_Offset offset, AP4_Size size);
    00077
    00078     // AP4_ByteStream methods
    00079     AP4_Result Read(void*    buffer,
    00080                     AP4_Size  bytes_to_read,
    00081                     AP4_Size* bytes_read = 0);
    00082     AP4_Result Write(const void* buffer,
    00083                      AP4_Size    bytes_to_write,
    00084                      AP4_Size*   bytes_written = 0);
    00085     AP4_Result Seek(AP4_Offset offset);
    00086     AP4_Result Tell(AP4_Offset& offset) {
    00087         offset = m_Position;
    00088         return AP4_SUCCESS;
    00089     }
    00090     AP4_Result GetSize(AP4_Size& size) {
    00091         size = m_Size;
    00092         return AP4_SUCCESS;
    00093     }
    00094
    00095     // AP4_Referenceable methods
    00096     void AddReference();
    00097     void Release();
    00098
    00099  protected:
    00100     virtual ~AP4_SubStream();
    00101
    00102  private:
    00103     AP4_ByteStream& m_Container;
    00104     AP4_Offset      m_Offset;
    00105     AP4_Size        m_Size;
    00106     AP4_Offset      m_Position;
    00107     AP4_Cardinal    m_ReferenceCount;
    00108 };
    00109
    00110 /*----------------------------------------------------------------------
    00111 |       AP4_MemoryByteStream
    00112 +---------------------------------------------------------------------*/
    00113 class AP4_MemoryByteStream : public AP4_ByteStream
    00114 {
    00115 public:
    00116     AP4_MemoryByteStream(AP4_Size size);
    00117     AP4_MemoryByteStream(AP4_UI08* buffer, AP4_Size size);
    00118
    00119     // AP4_ByteStream methods
    00120     AP4_Result Read(void*     buffer,
    00121                     AP4_Size  bytes_to_read,
    00122                     AP4_Size* bytes_read = 0);
    00123     AP4_Result Write(const void* buffer,
    00124                      AP4_Size    bytes_to_write,
    00125                      AP4_Size*   bytes_written = 0);
    00126     AP4_Result Seek(AP4_Offset offset);
    00127     AP4_Result Tell(AP4_Offset& offset) {
    00128         offset = m_Position;
    00129         return AP4_SUCCESS;
    00130     }
    00131     AP4_Result GetSize(AP4_Size& size) {
    00132         size = m_Size;
    00133         return AP4_SUCCESS;
    00134     }
    00135
    00136     // AP4_Referenceable methods
    00137     void AddReference();
    00138     void Release();
    00139
    00140     // methods
    00141     AP4_UI08* GetBuffer() { return m_Buffer; }
    00142
    00143 protected:
    00144     virtual ~AP4_MemoryByteStream();
    00145
    00146 private:
    00147     bool         m_BufferIsLocal;
    00148     AP4_UI08*    m_Buffer;
    00149     AP4_Size     m_Size;
    00150     AP4_Offset   m_Position;
    00151     AP4_Cardinal m_ReferenceCount;
    00152 };
    00153
    00154 #endif // _AP4_BYTE_STREAM_H_