atom_ohdr.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /** \file atom_ohdr.cpp
  2. \author Danijel Kopcinovic ([email protected])
  3. */
  4. #include "mp4common.h"
  5. /*! \brief Patch class for read/write operations when string is 0-length.
  6. We want to use string property, but mpeg4ip doesn't support ohdr way of
  7. encoding of string (in ohdr atom we first have 3 lengths of 3 strings and
  8. then their string values, and it cannot be simulated with any of the
  9. current mpeg4ip string property parameters), so we have to write our own
  10. Read() and Write() routines.
  11. */
  12. class OhdrMP4StringProperty: public MP4StringProperty {
  13. public:
  14. /*! \brief Constructor.
  15. \param name name of the property.
  16. \param useCountedFormat counted format flag.
  17. \param useUnicode unicode flag.
  18. */
  19. OhdrMP4StringProperty(char* name, bool useCountedFormat = false,
  20. bool useUnicode = false): MP4StringProperty(name, useCountedFormat,
  21. useUnicode) {
  22. }
  23. /*! \brief Read property from file.
  24. \param pFile input, file handle.
  25. \param index input, index to read.
  26. */
  27. void Read(MP4File* pFile, u_int32_t index = 0) {
  28. MP4Free(m_values[index]);
  29. m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
  30. (void)pFile->ReadBytes((u_int8_t*)m_values[index], m_fixedLength);
  31. }
  32. /*! \brief Write property to file.
  33. \param pFile input, file handle.
  34. \param index input, index to write.
  35. */
  36. void Write(MP4File* pFile, u_int32_t index = 0) {
  37. pFile->WriteBytes((u_int8_t*)m_values[index], m_fixedLength);
  38. }
  39. };
  40. /*! \brief OMA DRM headers atom.
  41. Contained in OMA DRM key management atom. It must contain content identifier.
  42. */
  43. /*! \brief Constructor.
  44. */
  45. MP4OhdrAtom::MP4OhdrAtom(): MP4Atom("ohdr") {
  46. AddVersionAndFlags();
  47. AddProperty(new MP4Integer8Property("EncryptionMethod"));
  48. AddProperty(new MP4Integer8Property("EncryptionPadding"));
  49. AddProperty(new MP4Integer64Property("PlaintextLength"));
  50. AddProperty(new MP4Integer16Property("ContentIDLength"));
  51. AddProperty(new MP4Integer16Property("RightsIssuerURLLength"));
  52. AddProperty(new MP4Integer16Property("TextualHeadersLength"));
  53. AddProperty(new OhdrMP4StringProperty("ContentID"));
  54. AddProperty(new OhdrMP4StringProperty("RightsIssuerURL"));
  55. AddProperty(new MP4BytesProperty("TextualHeaders"));
  56. }
  57. MP4OhdrAtom::~MP4OhdrAtom() {
  58. }
  59. /*! \brief Read atom.
  60. */
  61. void MP4OhdrAtom::Read() {
  62. ReadProperties(0, 8);
  63. MP4Property* lProperty;
  64. MP4Property* property;
  65. lProperty = GetProperty(5);
  66. property = GetProperty(8);
  67. ((OhdrMP4StringProperty*)property)->SetFixedLength(
  68. ((MP4Integer16Property*)lProperty)->GetValue());
  69. lProperty = GetProperty(6);
  70. property = GetProperty(9);
  71. ((OhdrMP4StringProperty*)property)->SetFixedLength(
  72. ((MP4Integer16Property*)lProperty)->GetValue());
  73. lProperty = GetProperty(7);
  74. property = GetProperty(10);
  75. ((MP4BytesProperty*)property)->SetFixedSize(
  76. ((MP4Integer16Property*)lProperty)->GetValue());
  77. ReadProperties(8, 3);
  78. }