Ap4ByteStream.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:5k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - ByteStream Interface
  4. |
  5. |    Copyright 2002 Gilles Boccon-Gibod
  6. |
  7. |
  8. |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
  9. |
  10. |    Unless you have obtained Bento4 under a difference license,
  11. |    this version of Bento4 is Bento4|GPL.
  12. |    Bento4|GPL is free software; you can redistribute it and/or modify
  13. |    it under the terms of the GNU General Public License as published by
  14. |    the Free Software Foundation; either version 2, or (at your option)
  15. |    any later version.
  16. |
  17. |    Bento4|GPL is distributed in the hope that it will be useful,
  18. |    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. |    GNU General Public License for more details.
  21. |
  22. |    You should have received a copy of the GNU General Public License
  23. |    along with Bento4|GPL; see the file COPYING.  If not, write to the
  24. |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  25. |    02111-1307, USA.
  26. |
  27.  ****************************************************************/
  28. #ifndef _AP4_BYTE_STREAM_H_
  29. #define _AP4_BYTE_STREAM_H_
  30. /*----------------------------------------------------------------------
  31. |       includes
  32. +---------------------------------------------------------------------*/
  33. #include "Ap4Types.h"
  34. #include "Ap4Interfaces.h"
  35. #include "Ap4Results.h"
  36. /*----------------------------------------------------------------------
  37. |       AP4_ByteStream
  38. +---------------------------------------------------------------------*/
  39. class AP4_ByteStream : public AP4_Referenceable
  40. {
  41.  public:
  42.     // methods
  43.     virtual AP4_Result Read(void*     buffer, 
  44.                             AP4_Size  bytes_to_read, 
  45.                             AP4_Size* bytes_read = 0) = 0;
  46.     virtual AP4_Result ReadUI64(AP4_UI64& value);
  47.     virtual AP4_Result ReadUI32(AP4_UI32& value);
  48.     virtual AP4_Result ReadUI24(AP4_UI32& value);
  49.     virtual AP4_Result ReadUI16(AP4_UI16& value);
  50.     virtual AP4_Result ReadUI08(AP4_UI08& value);
  51.     virtual AP4_Result ReadString(char* buffer, AP4_Size size);
  52.     virtual AP4_Result Write(const void* buffer, 
  53.                              AP4_Size    bytes_to_write, 
  54.                              AP4_Size*   bytes_written = 0) = 0;
  55.     virtual AP4_Result WriteString(const char* stringBuffer);
  56.     virtual AP4_Result WriteUI64(AP4_UI64 value);
  57.     virtual AP4_Result WriteUI32(AP4_UI32 value);
  58.     virtual AP4_Result WriteUI24(AP4_UI32 value);
  59.     virtual AP4_Result WriteUI16(AP4_UI16 value);
  60.     virtual AP4_Result WriteUI08(AP4_UI08 value);
  61.     virtual AP4_Result Seek(AP4_Offset offset) = 0;
  62.     virtual AP4_Result Tell(AP4_Offset& offset) = 0;
  63.     virtual AP4_Result GetSize(AP4_Size& size) = 0;
  64.     virtual AP4_Result CopyTo(AP4_ByteStream& stream, AP4_Size size);
  65. };
  66. /*----------------------------------------------------------------------
  67. |       AP4_SubStream
  68. +---------------------------------------------------------------------*/
  69. class AP4_SubStream : public AP4_ByteStream
  70. {
  71.  public:
  72.     AP4_SubStream(AP4_ByteStream& container, AP4_Offset offset, AP4_Size size);
  73.     // AP4_ByteStream methods
  74.     AP4_Result Read(void*    buffer, 
  75.                     AP4_Size  bytes_to_read, 
  76.                     AP4_Size* bytes_read = 0);
  77.     AP4_Result Write(const void* buffer, 
  78.                      AP4_Size    bytes_to_write, 
  79.                      AP4_Size*   bytes_written = 0);
  80.     AP4_Result Seek(AP4_Offset offset);
  81.     AP4_Result Tell(AP4_Offset& offset) {
  82.         offset = m_Position;
  83.         return AP4_SUCCESS;
  84.     }
  85.     AP4_Result GetSize(AP4_Size& size) {
  86.         size = m_Size;
  87.         return AP4_SUCCESS;
  88.     }
  89.     // AP4_Referenceable methods
  90.     void AddReference();
  91.     void Release();
  92.  protected:
  93.     virtual ~AP4_SubStream();
  94.  private:
  95.     AP4_ByteStream& m_Container;
  96.     AP4_Offset      m_Offset;
  97.     AP4_Size        m_Size;
  98.     AP4_Offset      m_Position;
  99.     AP4_Cardinal    m_ReferenceCount;
  100. };
  101. /*----------------------------------------------------------------------
  102. |       AP4_MemoryByteStream
  103. +---------------------------------------------------------------------*/
  104. class AP4_MemoryByteStream : public AP4_ByteStream
  105. {
  106. public:
  107.     AP4_MemoryByteStream(AP4_Size size);
  108.     AP4_MemoryByteStream(AP4_UI08* buffer, AP4_Size size);
  109.     // AP4_ByteStream methods
  110.     AP4_Result Read(void*     buffer, 
  111.                     AP4_Size  bytes_to_read, 
  112.                     AP4_Size* bytes_read = 0);
  113.     AP4_Result Write(const void* buffer, 
  114.                      AP4_Size    bytes_to_write, 
  115.                      AP4_Size*   bytes_written = 0);
  116.     AP4_Result Seek(AP4_Offset offset);
  117.     AP4_Result Tell(AP4_Offset& offset) {
  118.         offset = m_Position;
  119.         return AP4_SUCCESS;
  120.     }
  121.     AP4_Result GetSize(AP4_Size& size) {
  122.         size = m_Size;
  123.         return AP4_SUCCESS;
  124.     }
  125.     // AP4_Referenceable methods
  126.     void AddReference();
  127.     void Release();
  128.     // methods
  129.     AP4_UI08* GetBuffer() { return m_Buffer; }
  130. protected:
  131.     virtual ~AP4_MemoryByteStream();
  132. private:
  133.     bool         m_BufferIsLocal;
  134.     AP4_UI08*    m_Buffer;
  135.     AP4_Size     m_Size;
  136.     AP4_Offset   m_Position;
  137.     AP4_Cardinal m_ReferenceCount;
  138. };
  139. #endif // _AP4_BYTE_STREAM_H_