00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _AP4_BYTE_STREAM_H_
00030 #define _AP4_BYTE_STREAM_H_
00031
00032
00033
00034
00035 #include "Ap4Types.h"
00036 #include "Ap4Interfaces.h"
00037 #include "Ap4Results.h"
00038
00039
00040
00041
00042 class AP4_ByteStream : public AP4_Referenceable
00043 {
00044 public:
00045
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
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
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
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
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
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
00137 void AddReference();
00138 void Release();
00139
00140
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_