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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - sdp Atoms 
  4. |
  5. |    Copyright 2002-2005 Gilles Boccon-Gibod & Julien Boeuf
  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. /*----------------------------------------------------------------------
  29. |       includes
  30. +---------------------------------------------------------------------*/
  31. #include "Ap4.h"
  32. #include "Ap4SdpAtom.h"
  33. #include "Ap4AtomFactory.h"
  34. #include "Ap4Utils.h"
  35. /*----------------------------------------------------------------------
  36. |       AP4_SdpAtom::AP4_SdpAtom
  37. +---------------------------------------------------------------------*/
  38. AP4_SdpAtom::AP4_SdpAtom(const char* sdp_text) :
  39.     AP4_Atom(AP4_ATOM_TYPE_SDP, AP4_ATOM_HEADER_SIZE, false),
  40.     m_SdpText(sdp_text)
  41. {
  42.     m_Size += m_SdpText.length()+1;
  43. }
  44. /*----------------------------------------------------------------------
  45. |       AP4_SdpAtom::AP4_SdpAtom
  46. +---------------------------------------------------------------------*/
  47. AP4_SdpAtom::AP4_SdpAtom(AP4_Size size, AP4_ByteStream& stream) :
  48.     AP4_Atom(AP4_ATOM_TYPE_SDP, size, false, stream)
  49. {
  50.     // sdptext
  51.     AP4_Size str_size = size-AP4_ATOM_HEADER_SIZE;
  52.     if (str_size > 0) {
  53.         char* str = new char[str_size+1];
  54.         stream.Read(str, str_size);
  55.         str[str_size] = ''; // force null-termination
  56.         m_SdpText = str;
  57.         delete[] str;
  58.     }
  59. }
  60. /*----------------------------------------------------------------------
  61. |       AP4_SdpAtom::WriteFields
  62. +---------------------------------------------------------------------*/
  63. AP4_Result
  64. AP4_SdpAtom::WriteFields(AP4_ByteStream& stream)
  65. {
  66.     // sdptext
  67.     AP4_Result result = stream.Write(m_SdpText.c_str(), m_SdpText.length());
  68.     if (AP4_FAILED(result)) return result;
  69.     // pad with zeros if necessary
  70.     AP4_Size padding = m_Size-(AP4_ATOM_HEADER_SIZE+m_SdpText.length());
  71.     while (padding--) stream.WriteUI08(0);
  72.     
  73.     return AP4_SUCCESS;
  74. }
  75. /*----------------------------------------------------------------------
  76. |       AP4_SdpAtom::InspectFields
  77. +---------------------------------------------------------------------*/
  78. AP4_Result
  79. AP4_SdpAtom::InspectFields(AP4_AtomInspector& inspector)
  80. {
  81.     inspector.AddField("sdp_text", m_SdpText.c_str());
  82.     return AP4_SUCCESS;
  83. }
  84. /*----------------------------------------------------------------------
  85. |       AP4_SdpAtom::GetSdpText
  86. +---------------------------------------------------------------------*/
  87. const AP4_String&
  88. AP4_SdpAtom::GetSdpText() const
  89. {
  90.     return m_SdpText;
  91. }