frame.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. #include "frame.h"
  2. #include "util.h"
  3. #ifdef _WIN32
  4. #include "zlib/zlib.h"
  5. #else
  6. #include "zlib/zlib.h"
  7. #endif
  8. #include "frames.h"
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include "nu/ByteReader.h"
  12. #include "nu/ByteWriter.h"
  13. #include "foundation/error.h"
  14. #include "nsid3v2.h"
  15. /* === ID3v2 common === */
  16. ID3v2::Frame::Frame()
  17. {
  18. data = 0;
  19. data_size = 0;
  20. }
  21. ID3v2::Frame::~Frame()
  22. {
  23. free(data);
  24. }
  25. int ID3v2::Frame::GetData(const void **_data, size_t *data_len) const
  26. {
  27. if (data)
  28. {
  29. *_data = data;
  30. *data_len = data_size;
  31. return NErr_Success;
  32. }
  33. else
  34. return NErr_NullPointer;
  35. }
  36. size_t ID3v2::Frame::GetDataSize() const
  37. {
  38. return data_size;
  39. }
  40. int ID3v2::Frame::NewData(size_t new_len, void **_data, size_t *_data_len)
  41. {
  42. // we DO NOT update the header, as its meant to hold the original data
  43. void *new_data = realloc(data, new_len);
  44. if (new_data)
  45. {
  46. data = new_data;
  47. data_size = new_len;
  48. *_data = data;
  49. *_data_len = data_size;
  50. return NErr_Success;
  51. }
  52. else
  53. return NErr_OutOfMemory;
  54. }
  55. bool ID3v2::Frame::Encrypted() const
  56. {
  57. return false;
  58. }
  59. bool ID3v2::Frame::Compressed() const
  60. {
  61. return false;
  62. }
  63. bool ID3v2::Frame::Grouped() const
  64. {
  65. return false;
  66. }
  67. bool ID3v2::Frame::ReadOnly() const
  68. {
  69. return false;
  70. }
  71. bool ID3v2::Frame::FrameUnsynchronised() const
  72. {
  73. return false;
  74. }
  75. bool ID3v2::Frame::DataLengthIndicated() const
  76. {
  77. return false;
  78. }
  79. bool ID3v2::Frame::TagAlterPreservation() const
  80. {
  81. return false;
  82. }
  83. bool ID3v2::Frame::FileAlterPreservation() const
  84. {
  85. return false;
  86. }
  87. static inline void Advance(const void *&data, size_t &len, size_t amount)
  88. {
  89. data = (const uint8_t *)data + amount;
  90. len -= amount;
  91. }
  92. static inline void AdvanceBoth(const void *&data, size_t &len, size_t &len2, size_t amount)
  93. {
  94. data = (const uint8_t *)data + amount;
  95. len -= amount;
  96. len2 -= amount;
  97. }
  98. /* === ID3v2.2 === */
  99. ID3v2_2::Frame::Frame(const ID3v2::Header &_header, const int8_t *id, int flags) : header(_header, id, flags)
  100. {
  101. }
  102. ID3v2_2::Frame::Frame(const FrameHeader &_header) : header(_header)
  103. {
  104. }
  105. int ID3v2_2::Frame::Parse(const void *_data, size_t len, size_t *read)
  106. {
  107. *read = 0;
  108. data_size = header.FrameSize(); // size of frame AFTER re-synchronization
  109. /* check to make sure that we have enough input data to read the data */
  110. if (header.Unsynchronised())
  111. {
  112. /* this is tricky, because the stored size reflects after re-synchronization,
  113. but the incoming data is unsynchronized */
  114. if (ID3v2::Util::UnsynchronisedInputSize(_data, data_size) > len)
  115. return 1;
  116. }
  117. else if (data_size > len)
  118. return 1;
  119. /* allocate memory (real data_size) */
  120. data = malloc(data_size);
  121. if (!data)
  122. return 1;
  123. /* === Read the data === */
  124. if (header.Unsynchronised())
  125. {
  126. *read += ID3v2::Util::UnsynchroniseTo(data, _data, data_size);
  127. }
  128. else // normal data
  129. {
  130. memcpy(data, _data, data_size);
  131. *read += data_size;
  132. }
  133. return NErr_Success;
  134. }
  135. int ID3v2_2::Frame::SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const
  136. {
  137. ID3v2_2::FrameHeader new_header(header, tag_header);
  138. // TODO: for now, we're not going to deal with compression
  139. new_header.SetSize(data_size);
  140. uint32_t current_length=0;
  141. new_header.SerializedSize(&current_length);
  142. if (new_header.Unsynchronised())
  143. {
  144. current_length += ID3v2::Util::SynchronisedSize(data, data_size);
  145. }
  146. else
  147. {
  148. current_length += new_header.FrameSize();
  149. }
  150. *length = current_length;
  151. return NErr_Success;
  152. }
  153. int ID3v2_2::Frame::Serialize(void *output, uint32_t *written, const ID3v2::Header &tag_header, int flags) const
  154. {
  155. size_t current_length = FrameHeader::SIZE;
  156. uint8_t *data_ptr = (uint8_t *)output;
  157. ID3v2_2::FrameHeader new_header(header, tag_header);
  158. new_header.SetSize(data_size);
  159. // write frame header
  160. new_header.Serialize(data_ptr);
  161. data_ptr += FrameHeader::SIZE;
  162. if (new_header.Unsynchronised())
  163. {
  164. current_length += ID3v2::Util::SynchroniseTo(data_ptr, data, data_size);
  165. }
  166. else
  167. {
  168. memcpy(data_ptr, data, data_size);
  169. current_length += data_size;
  170. }
  171. *written = current_length;
  172. return NErr_Success;
  173. }
  174. const int8_t *ID3v2_2::Frame::GetIdentifier() const
  175. {
  176. return header.GetIdentifier();
  177. }
  178. /* === ID3v2.3 === */
  179. ID3v2_3::Frame::Frame(const ID3v2::Header &_header, const int8_t *id, int flags) : header(_header, id, flags)
  180. {
  181. }
  182. ID3v2_3::Frame::Frame(const FrameHeader &_header) : header(_header)
  183. {
  184. }
  185. /* helper function
  186. reads num_bytes from input into output, dealing with re-synchronization and length checking
  187. increments input pointer
  188. increments bytes_read value by number of input bytes read (different from num_bytes when data is unsynchronized
  189. decrements input_len by bytes read
  190. decrements output_len by bytes written
  191. */
  192. bool ID3v2_3::Frame::ReadData(void *output, const void *&input, size_t &input_len, size_t &frame_len, size_t num_bytes, size_t *bytes_read) const
  193. {
  194. /* verify that we have enough data in the frame */
  195. if (num_bytes > frame_len)
  196. return false;
  197. /* verify that we have enough data in the buffer */
  198. size_t bytes_to_read;
  199. if (header.Unsynchronised())
  200. bytes_to_read = ID3v2::Util::UnsynchronisedInputSize(input, num_bytes);
  201. else
  202. bytes_to_read = num_bytes;
  203. if (bytes_to_read > input_len)
  204. return false;
  205. /* read data */
  206. if (header.Unsynchronised())
  207. {
  208. *bytes_read += ID3v2::Util::SynchroniseTo(&output, input, num_bytes);
  209. }
  210. else
  211. {
  212. *bytes_read += num_bytes;
  213. memcpy(output, input, num_bytes);
  214. }
  215. /* increment input pointer */
  216. input = (const uint8_t *)input + bytes_to_read;
  217. /* decrement sizes */
  218. frame_len -= num_bytes;
  219. input_len -= bytes_to_read;
  220. return true;
  221. }
  222. /* benski> this function is a bit complex
  223. we have two things to worry about, and can have any combination of the two
  224. 1) Is the data 'unsynchronized'
  225. 2) Is the data compressed (zlib)
  226. we keep track of three sizes:
  227. len - number of bytes in input buffer
  228. data_size - number of bytes of output data buffer
  229. frame_size - number of bytes of data in frame AFTER re-synchronization
  230. frame_size==data_size when compression is OFF
  231. */
  232. int ID3v2_3::Frame::Parse(const void *_data, size_t len, size_t *read)
  233. {
  234. *read = 0;
  235. size_t frame_size = header.FrameSize(); // size of frame AFTER re-synchronization
  236. if (header.Compressed())
  237. {
  238. // read 4 bytes of decompressed size
  239. uint8_t raw_size[4];
  240. if (ReadData(raw_size, _data, len, frame_size, 4, read) == false)
  241. return 1;
  242. bytereader_value_t byte_reader;
  243. bytereader_init(&byte_reader, raw_size, 4);
  244. data_size = bytereader_read_u32_be(&byte_reader);
  245. }
  246. /* Check for group identity. If this exists, we'll store it separate from the raw data */
  247. if (header.Grouped())
  248. {
  249. // read 1 byte for group identity
  250. if (ReadData(&group_identity, _data, len, frame_size, 1, read) == false)
  251. return 1;
  252. }
  253. if (!header.Compressed())
  254. {
  255. data_size = frame_size;
  256. }
  257. /* check to make sure that we have enough input data to read the data */
  258. if (!header.Compressed() && header.Unsynchronised())
  259. {
  260. /* this is tricky, because the stored size reflects after re-synchronization,
  261. but the incoming data is unsynchronized */
  262. if (ID3v2::Util::UnsynchronisedInputSize(_data, data_size) > len)
  263. return 1;
  264. }
  265. else if (frame_size > len)
  266. return 1;
  267. /* allocate memory (real data_size) */
  268. data = malloc(data_size);
  269. if (!data)
  270. return NErr_OutOfMemory;
  271. /* === Read the data === */
  272. if (header.Compressed())
  273. {
  274. if (header.Unsynchronised()) // compressed AND unsynchronized.. what a pain!!
  275. {
  276. // TODO: combined re-synchronization + inflation
  277. void *temp = malloc(frame_size);
  278. if (!temp)
  279. return NErr_OutOfMemory;
  280. *read += ID3v2::Util::UnsynchroniseTo(temp, _data, frame_size);
  281. uLongf uncompressedSize = data_size;
  282. int ret = uncompress((Bytef *)data, &uncompressedSize, (const Bytef *)temp, frame_size);
  283. free(temp);
  284. if (ret != Z_OK)
  285. return 1;
  286. }
  287. else
  288. {
  289. uLongf uncompressedSize = data_size;
  290. if (uncompress((Bytef *)data, &uncompressedSize, (const Bytef *)_data, frame_size) != Z_OK)
  291. return 1;
  292. *read += frame_size;
  293. }
  294. }
  295. else if (header.Unsynchronised())
  296. {
  297. *read += ID3v2::Util::UnsynchroniseTo(data, _data, data_size);
  298. }
  299. else // normal data
  300. {
  301. memcpy(data, _data, data_size);
  302. *read += data_size;
  303. }
  304. return NErr_Success;
  305. }
  306. int ID3v2_3::Frame::SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const
  307. {
  308. ID3v2_3::FrameHeader new_header(header, tag_header);
  309. // TODO: for now, we're not going to deal with compression
  310. new_header.ClearCompressed();
  311. new_header.SetSize(data_size);
  312. uint32_t current_length=0;
  313. new_header.SerializedSize(&current_length);
  314. if (new_header.Unsynchronised())
  315. {
  316. if (new_header.Compressed())
  317. {
  318. uint8_t data_length[4];
  319. bytewriter_s byte_writer;
  320. bytewriter_init(&byte_writer, data_length, 4);
  321. bytewriter_write_u32_be(&byte_writer, data_size);
  322. current_length += ID3v2::Util::SynchronisedSize(&data_length, 4);
  323. }
  324. if (new_header.Grouped())
  325. current_length += ID3v2::Util::SynchronisedSize(&group_identity, 1);
  326. current_length += ID3v2::Util::SynchronisedSize(data, data_size);
  327. }
  328. else
  329. {
  330. current_length += new_header.FrameSize();
  331. }
  332. *length = current_length;
  333. return NErr_Success;
  334. }
  335. int ID3v2_3::Frame::Serialize(void *output, uint32_t *written, const ID3v2::Header &tag_header, int flags) const
  336. {
  337. size_t current_length = FrameHeaderBase::SIZE;
  338. uint8_t *data_ptr = (uint8_t *)output;
  339. ID3v2_3::FrameHeader new_header(header, tag_header);
  340. // TODO: for now, we're not going to deal with compression
  341. new_header.ClearCompressed();
  342. new_header.SetSize(data_size);
  343. // write frame header
  344. uint32_t header_size;
  345. new_header.Serialize(data_ptr, &header_size);
  346. data_ptr += header_size;
  347. if (new_header.Unsynchronised())
  348. {
  349. if (new_header.Compressed())
  350. {
  351. uint8_t data_length[4];
  352. bytewriter_s byte_writer;
  353. bytewriter_init(&byte_writer, data_length, 4);
  354. bytewriter_write_u32_be(&byte_writer, data_size);
  355. current_length += ID3v2::Util::SynchroniseTo(data_ptr, &data_length, 4);
  356. data_ptr+=4;
  357. }
  358. if (new_header.Grouped())
  359. current_length += ID3v2::Util::SynchroniseTo(data_ptr++, &group_identity, 1);
  360. current_length += ID3v2::Util::SynchroniseTo(data_ptr, data, data_size);
  361. }
  362. else
  363. {
  364. if (new_header.Compressed())
  365. {
  366. bytewriter_s byte_writer;
  367. bytewriter_init(&byte_writer, data_ptr, 4);
  368. bytewriter_write_u32_be(&byte_writer, data_size);
  369. data_ptr+=4;
  370. }
  371. if (new_header.Grouped())
  372. {
  373. *data_ptr++ = group_identity;
  374. current_length++;
  375. }
  376. memcpy(data_ptr, data, data_size);
  377. current_length += data_size;
  378. }
  379. *written = current_length;
  380. return NErr_Success;
  381. }
  382. const int8_t *ID3v2_3::Frame::GetIdentifier() const
  383. {
  384. return header.GetIdentifier();
  385. }
  386. bool ID3v2_3::Frame::Encrypted() const
  387. {
  388. return header.Encrypted();
  389. }
  390. bool ID3v2_3::Frame::Compressed() const
  391. {
  392. return header.Compressed();
  393. }
  394. bool ID3v2_3::Frame::Grouped() const
  395. {
  396. return header.Grouped();
  397. }
  398. bool ID3v2_3::Frame::ReadOnly() const
  399. {
  400. return header.ReadOnly();
  401. }
  402. bool ID3v2_3::Frame::TagAlterPreservation() const
  403. {
  404. return header.TagAlterPreservation();
  405. }
  406. bool ID3v2_3::Frame::FileAlterPreservation() const
  407. {
  408. return header.FileAlterPreservation();
  409. }
  410. /* === ID3v2.4 === */
  411. ID3v2_4::Frame::Frame(const ID3v2::Header &_header, const int8_t *id, int flags) : header(_header, id, flags)
  412. {
  413. }
  414. ID3v2_4::Frame::Frame(const FrameHeader &_header) : header(_header)
  415. {
  416. }
  417. /* helper function
  418. reads num_bytes from input into output, dealing with re-synchronization and length checking
  419. increments input pointer
  420. increments bytes_read value by number of input bytes read (different from num_bytes when data is unsynchronized
  421. decrements input_len by bytes read
  422. decrements output_len by bytes written
  423. */
  424. bool ID3v2_4::Frame::ReadData(void *output, const void *&input, size_t &input_len, size_t &frame_len, size_t num_bytes, size_t *bytes_read) const
  425. {
  426. /* verify that we have enough data in the frame */
  427. if (num_bytes > frame_len)
  428. return false;
  429. /* verify that we have enough data in the buffer */
  430. size_t bytes_to_read = num_bytes;
  431. if (bytes_to_read > input_len)
  432. return false;
  433. /* read data */
  434. *bytes_read += num_bytes;
  435. memcpy(output, input, num_bytes);
  436. /* increment input pointer */
  437. input = (const uint8_t *)input + bytes_to_read;
  438. /* decrement sizes */
  439. frame_len -= num_bytes;
  440. input_len -= bytes_to_read;
  441. return true;
  442. }
  443. /* benski> this function is a bit complex
  444. we have two things to worry about, and can have any combination of the two
  445. 1) Is the data 'unsynchronized'
  446. 2) Is the data compressed (zlib)
  447. we keep track of three sizes:
  448. len - number of bytes in input buffer
  449. data_size - number of bytes of output data buffer
  450. frame_size - number of bytes of data in frame AFTER re-synchronization
  451. frame_size==data_size when compression is OFF
  452. */
  453. int ID3v2_4::Frame::Parse(const void *_data, size_t len, size_t *read)
  454. {
  455. *read = 0;
  456. size_t frame_size = header.FrameSize();
  457. // TODO: if frame_size >= 128, verify size. iTunes v2.4 parser bug ...
  458. /* Check for group identity. If this exists, we'll store it separate from the raw data */
  459. /* Note: ID3v2.4 puts group identity BEFORE data length indicator, where as v2.3 has it the other way */
  460. if (header.Grouped())
  461. {
  462. // read 1 byte for group identity
  463. if (ReadData(&group_identity, _data, len, frame_size, 1, read) == false)
  464. return 1;
  465. }
  466. if (header.Compressed() || header.DataLengthIndicated())
  467. {
  468. // read 4 bytes of decompressed size
  469. uint8_t raw_size[4];
  470. if (ReadData(raw_size, _data, len, frame_size, 4, read) == false)
  471. return 1;
  472. bytereader_value_t byte_reader;
  473. bytereader_init(&byte_reader, raw_size, 4);
  474. data_size = bytereader_read_u32_be(&byte_reader);
  475. }
  476. if (!(header.Compressed() || header.DataLengthIndicated()))
  477. {
  478. data_size = frame_size;
  479. }
  480. /* check to make sure that we have enough input data to read the data */
  481. if (frame_size > len)
  482. return 1;
  483. if (!header.Compressed() && header.Unsynchronised())
  484. {
  485. data_size = ID3v2::Util::UnsynchronisedOutputSize(_data, frame_size);
  486. }
  487. /* allocate memory (real data_size) */
  488. data = malloc(data_size);
  489. if (!data)
  490. return NErr_OutOfMemory;
  491. /* === Read the data === */
  492. if (header.Compressed())
  493. {
  494. if (header.Unsynchronised()) // compressed AND unsynchronized.. what a pain!!
  495. {
  496. // TODO: combined re-synchronization + inflation
  497. size_t sync_size = ID3v2::Util::UnsynchronisedOutputSize(_data, frame_size);
  498. void *temp = malloc(sync_size);
  499. if (!temp)
  500. return NErr_OutOfMemory;
  501. *read += ID3v2::Util::UnsynchroniseTo(temp, _data, sync_size);
  502. uLongf uncompressedSize = data_size;
  503. int ret = uncompress((Bytef *)data, &uncompressedSize, (const Bytef *)temp, sync_size);
  504. /* TODO: realloc and set data_size to uncompressedSize if uncompressedSize was actually lower */
  505. free(temp);
  506. if (ret != Z_OK)
  507. return 1;
  508. }
  509. else
  510. {
  511. uLongf uncompressedSize = data_size;
  512. if (uncompress((Bytef *)data, &uncompressedSize, (const Bytef *)_data, frame_size) != Z_OK)
  513. return 1;
  514. /* TODO: realloc and set data_size to uncompressedSize if uncompressedSize was actually lower */
  515. *read += frame_size;
  516. }
  517. }
  518. else if (header.Unsynchronised())
  519. {
  520. *read += ID3v2::Util::UnsynchroniseTo(data, _data, data_size);
  521. }
  522. else // normal data
  523. {
  524. memcpy(data, _data, data_size);
  525. *read += data_size;
  526. }
  527. return 0;
  528. }
  529. int ID3v2_4::Frame::SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const
  530. {
  531. ID3v2_4::FrameHeader new_header(header, tag_header);
  532. // TODO: for now, we're not going to deal with compression
  533. new_header.ClearCompressed();
  534. switch(flags & Serialize_UnsynchronizeMask)
  535. {
  536. case Serialize_Unsynchronize:
  537. // TODO:
  538. break;
  539. case Serialize_NoUnsynchronize:
  540. new_header.ClearUnsynchronized();
  541. break;
  542. }
  543. // TODO: this doesn't handle compression
  544. if (new_header.Unsynchronised())
  545. {
  546. size_t unsynchronized_data_size = ID3v2::Util::SynchronisedSize(data, data_size);
  547. new_header.SetSize(unsynchronized_data_size);
  548. }
  549. else
  550. {
  551. new_header.SetSize(data_size);
  552. }
  553. size_t current_length = ID3v2_4::FrameHeader::SIZE;
  554. if (new_header.Unsynchronised())
  555. {
  556. if (new_header.DataLengthIndicated() || new_header.Compressed())
  557. {
  558. current_length += 4;
  559. }
  560. if (new_header.Grouped())
  561. current_length += ID3v2::Util::SynchronisedSize(&group_identity, 1);
  562. current_length += ID3v2::Util::SynchronisedSize(data, data_size);
  563. }
  564. else
  565. {
  566. current_length += new_header.FrameSize();
  567. }
  568. *length = current_length;
  569. return NErr_Success;
  570. }
  571. int ID3v2_4::Frame::Serialize(void *output, uint32_t *written, const ID3v2::Header &tag_header, int flags) const
  572. {
  573. size_t current_length = ID3v2_4::FrameHeader::SIZE;
  574. uint8_t *data_ptr = (uint8_t *)output;
  575. ID3v2_4::FrameHeader new_header(header, tag_header);
  576. // TODO: for now, we're not going to deal with compression
  577. new_header.ClearCompressed();
  578. switch(flags & Serialize_UnsynchronizeMask)
  579. {
  580. case Serialize_Unsynchronize:
  581. // TODO:
  582. break;
  583. case Serialize_NoUnsynchronize:
  584. new_header.ClearUnsynchronized();
  585. break;
  586. }
  587. // TODO: this doesn't handle compression
  588. if (new_header.Unsynchronised())
  589. {
  590. size_t unsynchronized_data_size = ID3v2::Util::SynchronisedSize(data, data_size);
  591. new_header.SetSize(unsynchronized_data_size);
  592. }
  593. else
  594. {
  595. new_header.SetSize(data_size);
  596. }
  597. // write frame header
  598. uint32_t header_size;
  599. new_header.Serialize(data_ptr, &header_size);
  600. data_ptr += header_size;
  601. if (new_header.Compressed() || new_header.DataLengthIndicated())
  602. {
  603. bytewriter_s byte_writer;
  604. bytewriter_init(&byte_writer, data_ptr, 4);
  605. bytewriter_write_u32_be(&byte_writer, ID3v2::Util::Int32To28(data_size));
  606. data_ptr+=4;
  607. current_length+=4;
  608. }
  609. if (new_header.Unsynchronised())
  610. {
  611. if (Grouped())
  612. current_length += ID3v2::Util::SynchroniseTo(data_ptr++, &group_identity, 1);
  613. current_length += ID3v2::Util::SynchroniseTo(data_ptr, data, data_size);
  614. }
  615. else
  616. {
  617. if (new_header.Grouped())
  618. {
  619. *data_ptr++ = group_identity;
  620. current_length++;
  621. }
  622. memcpy(data_ptr, data, data_size);
  623. current_length += data_size;
  624. }
  625. *written = current_length;
  626. return NErr_Success;
  627. }
  628. const int8_t *ID3v2_4::Frame::GetIdentifier() const
  629. {
  630. return header.GetIdentifier();
  631. }
  632. bool ID3v2_4::Frame::Encrypted() const
  633. {
  634. return header.Encrypted();
  635. }
  636. bool ID3v2_4::Frame::Compressed() const
  637. {
  638. return header.Compressed();
  639. }
  640. bool ID3v2_4::Frame::Grouped() const
  641. {
  642. return header.Grouped();
  643. }
  644. bool ID3v2_4::Frame::ReadOnly() const
  645. {
  646. return header.ReadOnly();
  647. }
  648. bool ID3v2_4::Frame::FrameUnsynchronised() const
  649. {
  650. return header.FrameUnsynchronised();
  651. }
  652. bool ID3v2_4::Frame::DataLengthIndicated() const
  653. {
  654. return header.DataLengthIndicated();
  655. }
  656. bool ID3v2_4::Frame::TagAlterPreservation() const
  657. {
  658. return header.TagAlterPreservation();
  659. }
  660. bool ID3v2_4::Frame::FileAlterPreservation() const
  661. {
  662. return header.FileAlterPreservation();
  663. }