1
0

atom_sdp.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is MPEG4IP.
  13. *
  14. * The Initial Developer of the Original Code is Cisco Systems Inc.
  15. * Portions created by Cisco Systems Inc. are
  16. * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
  17. *
  18. * Contributor(s):
  19. * Dave Mackie [email protected]
  20. */
  21. #include "mp4common.h"
  22. MP4SdpAtom::MP4SdpAtom() : MP4Atom("sdp ")
  23. {
  24. AddProperty(
  25. new MP4StringProperty("sdpText"));
  26. }
  27. void MP4SdpAtom::Read()
  28. {
  29. // read sdp string, length is implicit in size of atom
  30. u_int64_t size = GetEnd() - m_pFile->GetPosition();
  31. char* data = (char*)MP4Malloc(size + 1);
  32. ASSERT(data != NULL);
  33. m_pFile->ReadBytes((u_int8_t*)data, size);
  34. data[size] = '\0';
  35. ((MP4StringProperty*)m_pProperties[0])->SetValue(data);
  36. MP4Free(data);
  37. }
  38. void MP4SdpAtom::Write()
  39. {
  40. // since length of string is implicit in size of atom
  41. // we need to handle this specially, and not write the terminating \0
  42. MP4StringProperty* pSdp = (MP4StringProperty*)m_pProperties[0];
  43. const char* sdpText = pSdp->GetValue();
  44. if (sdpText) {
  45. pSdp->SetFixedLength((u_int32_t)strlen(sdpText));
  46. }
  47. MP4Atom::Write();
  48. pSdp->SetFixedLength(0);
  49. }