id3_header.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // The authors have released ID3Lib as Public Domain (PD) and claim no copyright,
  2. // patent or other intellectual property protection in this work. This means that
  3. // it may be modified, redistributed and used in commercial and non-commercial
  4. // software and hardware without restrictions. ID3Lib is distributed on an "AS IS"
  5. // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  6. //
  7. // The ID3Lib authors encourage improvements and optimisations to be sent to the
  8. // ID3Lib coordinator, currently Dirk Mahoney ([email protected]). Approved
  9. // submissions may be altered, and will be included and released under these terms.
  10. //
  11. // Mon Nov 23 18:34:01 1998
  12. #include <string.h>
  13. #include <memory.h>
  14. #include "id3_header.h"
  15. #include "id3_error.h"
  16. static ID3_HeaderInfo ID3_VersionInfo[4][3] =
  17. {
  18. // SIZEOF SIZEOF SIZEOF EXT EXT EXPERIM
  19. // VER REV FRID FRSZ FRFL HEADER SIZE BIT
  20. {
  21. { 2, 0, 3, 3, 0, false, 0, false },
  22. { 2, 1, 3, 3, 0, true, 8, true },
  23. {0,},
  24. },
  25. {
  26. { 3, 0, 4, 4, 2, false, 10, false },
  27. {0,},
  28. },
  29. {
  30. { 4, 0, 4, 4, 2, false, 10, false },
  31. {0,},
  32. },
  33. { 0 }
  34. };
  35. ID3_HeaderInfo *ID3_LookupHeaderInfo(uchar ver, uchar rev)
  36. {
  37. ID3_HeaderInfo *info = NULL;
  38. size_t v=0,r=0;
  39. while (ID3_VersionInfo[v][0].version != 0)
  40. {
  41. r=0;
  42. if (ID3_VersionInfo[v][0].version == ver)
  43. {
  44. while (ID3_VersionInfo[v][r].version != 0)
  45. {
  46. if (ID3_VersionInfo[v][r].revision == rev)
  47. {
  48. goto found;
  49. }
  50. else
  51. r++;
  52. }
  53. // later revision. still backwards compat so we'll stick with it.
  54. r--;
  55. goto found;
  56. }
  57. else
  58. v++;
  59. }
  60. found:
  61. if (ID3_VersionInfo[v][r].version != 0)
  62. info = &ID3_VersionInfo[v][r];
  63. return info;
  64. }
  65. ID3_Header::ID3_Header(void)
  66. {
  67. SetVersion(ID3_TAGVERSION, ID3_TAGREVISION);
  68. dataSize = 0;
  69. flags = 0;
  70. }
  71. void ID3_Header::SetVersion(uchar ver, uchar rev)
  72. {
  73. version = ver;
  74. revision = rev;
  75. info = ID3_LookupHeaderInfo(version, revision);
  76. }
  77. void ID3_Header::SetDataSize(luint newSize)
  78. {
  79. dataSize = newSize;
  80. }
  81. void ID3_Header::SetFlags(luint newFlags)
  82. {
  83. flags = newFlags;
  84. }