metadata_utils.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:22k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* test_libFLAC - Unit tester for libFLAC
  2.  * Copyright (C) 2002,2003,2004,2005  Josh Coalson
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  */
  18. /*
  19.  * These are not tests, just utility functions used by the metadata tests
  20.  */
  21. #include "metadata_utils.h"
  22. #include "FLAC/metadata.h"
  23. #include <stdio.h>
  24. #include <stdlib.h> /* for malloc() */
  25. #include <string.h> /* for memcmp() */
  26. FLAC__bool mutils__compare_block_data_streaminfo(const FLAC__StreamMetadata_StreamInfo *block, const FLAC__StreamMetadata_StreamInfo *blockcopy)
  27. {
  28. if(blockcopy->min_blocksize != block->min_blocksize) {
  29. printf("FAILED, min_blocksize mismatch, expected %u, got %un", block->min_blocksize, blockcopy->min_blocksize);
  30. return false;
  31. }
  32. if(blockcopy->max_blocksize != block->max_blocksize) {
  33. printf("FAILED, max_blocksize mismatch, expected %u, got %un", block->max_blocksize, blockcopy->max_blocksize);
  34. return false;
  35. }
  36. if(blockcopy->min_framesize != block->min_framesize) {
  37. printf("FAILED, min_framesize mismatch, expected %u, got %un", block->min_framesize, blockcopy->min_framesize);
  38. return false;
  39. }
  40. if(blockcopy->max_framesize != block->max_framesize) {
  41. printf("FAILED, max_framesize mismatch, expected %u, got %un", block->max_framesize, blockcopy->max_framesize);
  42. return false;
  43. }
  44. if(blockcopy->sample_rate != block->sample_rate) {
  45. printf("FAILED, sample_rate mismatch, expected %u, got %un", block->sample_rate, blockcopy->sample_rate);
  46. return false;
  47. }
  48. if(blockcopy->channels != block->channels) {
  49. printf("FAILED, channels mismatch, expected %u, got %un", block->channels, blockcopy->channels);
  50. return false;
  51. }
  52. if(blockcopy->bits_per_sample != block->bits_per_sample) {
  53. printf("FAILED, bits_per_sample mismatch, expected %u, got %un", block->bits_per_sample, blockcopy->bits_per_sample);
  54. return false;
  55. }
  56. if(blockcopy->total_samples != block->total_samples) {
  57. printf("FAILED, total_samples mismatch, expected %llu, got %llun", block->total_samples, blockcopy->total_samples);
  58. return false;
  59. }
  60. if(0 != memcmp(blockcopy->md5sum, block->md5sum, sizeof(block->md5sum))) {
  61. printf("FAILED, md5sum mismatch, expected %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X, got %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02Xn",
  62. (unsigned)block->md5sum[0],
  63. (unsigned)block->md5sum[1],
  64. (unsigned)block->md5sum[2],
  65. (unsigned)block->md5sum[3],
  66. (unsigned)block->md5sum[4],
  67. (unsigned)block->md5sum[5],
  68. (unsigned)block->md5sum[6],
  69. (unsigned)block->md5sum[7],
  70. (unsigned)block->md5sum[8],
  71. (unsigned)block->md5sum[9],
  72. (unsigned)block->md5sum[10],
  73. (unsigned)block->md5sum[11],
  74. (unsigned)block->md5sum[12],
  75. (unsigned)block->md5sum[13],
  76. (unsigned)block->md5sum[14],
  77. (unsigned)block->md5sum[15],
  78. (unsigned)blockcopy->md5sum[0],
  79. (unsigned)blockcopy->md5sum[1],
  80. (unsigned)blockcopy->md5sum[2],
  81. (unsigned)blockcopy->md5sum[3],
  82. (unsigned)blockcopy->md5sum[4],
  83. (unsigned)blockcopy->md5sum[5],
  84. (unsigned)blockcopy->md5sum[6],
  85. (unsigned)blockcopy->md5sum[7],
  86. (unsigned)blockcopy->md5sum[8],
  87. (unsigned)blockcopy->md5sum[9],
  88. (unsigned)blockcopy->md5sum[10],
  89. (unsigned)blockcopy->md5sum[11],
  90. (unsigned)blockcopy->md5sum[12],
  91. (unsigned)blockcopy->md5sum[13],
  92. (unsigned)blockcopy->md5sum[14],
  93. (unsigned)blockcopy->md5sum[15]
  94. );
  95. return false;
  96. }
  97. return true;
  98. }
  99. FLAC__bool mutils__compare_block_data_padding(const FLAC__StreamMetadata_Padding *block, const FLAC__StreamMetadata_Padding *blockcopy, unsigned block_length)
  100. {
  101. /* we don't compare the padding guts */
  102. (void)block, (void)blockcopy, (void)block_length;
  103. return true;
  104. }
  105. FLAC__bool mutils__compare_block_data_application(const FLAC__StreamMetadata_Application *block, const FLAC__StreamMetadata_Application *blockcopy, unsigned block_length)
  106. {
  107. if(block_length < sizeof(block->id)) {
  108. printf("FAILED, bad block length = %un", block_length);
  109. return false;
  110. }
  111. if(0 != memcmp(blockcopy->id, block->id, sizeof(block->id))) {
  112. printf("FAILED, id mismatch, expected %02X%02X%02X%02X, got %02X%02X%02X%02Xn",
  113. (unsigned)block->id[0],
  114. (unsigned)block->id[1],
  115. (unsigned)block->id[2],
  116. (unsigned)block->id[3],
  117. (unsigned)blockcopy->id[0],
  118. (unsigned)blockcopy->id[1],
  119. (unsigned)blockcopy->id[2],
  120. (unsigned)blockcopy->id[3]
  121. );
  122. return false;
  123. }
  124. if(0 == block->data || 0 == blockcopy->data) {
  125. if(block->data != blockcopy->data) {
  126. printf("FAILED, data mismatch (%s's data pointer is null)n", 0==block->data?"original":"copy");
  127. return false;
  128. }
  129. else if(block_length - sizeof(block->id) > 0) {
  130. printf("FAILED, data pointer is null but block length is not 0n");
  131. return false;
  132. }
  133. }
  134. else {
  135. if(block_length - sizeof(block->id) == 0) {
  136. printf("FAILED, data pointer is not null but block length is 0n");
  137. return false;
  138. }
  139. else if(0 != memcmp(blockcopy->data, block->data, block_length - sizeof(block->id))) {
  140. printf("FAILED, data mismatchn");
  141. return false;
  142. }
  143. }
  144. return true;
  145. }
  146. FLAC__bool mutils__compare_block_data_seektable(const FLAC__StreamMetadata_SeekTable *block, const FLAC__StreamMetadata_SeekTable *blockcopy)
  147. {
  148. unsigned i;
  149. if(blockcopy->num_points != block->num_points) {
  150. printf("FAILED, num_points mismatch, expected %u, got %un", block->num_points, blockcopy->num_points);
  151. return false;
  152. }
  153. for(i = 0; i < block->num_points; i++) {
  154. if(blockcopy->points[i].sample_number != block->points[i].sample_number) {
  155. printf("FAILED, points[%u].sample_number mismatch, expected %llu, got %llun", i, block->points[i].sample_number, blockcopy->points[i].sample_number);
  156. return false;
  157. }
  158. if(blockcopy->points[i].stream_offset != block->points[i].stream_offset) {
  159. printf("FAILED, points[%u].stream_offset mismatch, expected %llu, got %llun", i, block->points[i].stream_offset, blockcopy->points[i].stream_offset);
  160. return false;
  161. }
  162. if(blockcopy->points[i].frame_samples != block->points[i].frame_samples) {
  163. printf("FAILED, points[%u].frame_samples mismatch, expected %u, got %un", i, block->points[i].frame_samples, blockcopy->points[i].frame_samples);
  164. return false;
  165. }
  166. }
  167. return true;
  168. }
  169. FLAC__bool mutils__compare_block_data_vorbiscomment(const FLAC__StreamMetadata_VorbisComment *block, const FLAC__StreamMetadata_VorbisComment *blockcopy)
  170. {
  171. unsigned i;
  172. if(blockcopy->vendor_string.length != block->vendor_string.length) {
  173. printf("FAILED, vendor_string.length mismatch, expected %u, got %un", block->vendor_string.length, blockcopy->vendor_string.length);
  174. return false;
  175. }
  176. if(0 == block->vendor_string.entry || 0 == blockcopy->vendor_string.entry) {
  177. if(block->vendor_string.entry != blockcopy->vendor_string.entry) {
  178. printf("FAILED, vendor_string.entry mismatchn");
  179. return false;
  180. }
  181. }
  182. else if(0 != memcmp(blockcopy->vendor_string.entry, block->vendor_string.entry, block->vendor_string.length)) {
  183. printf("FAILED, vendor_string.entry mismatchn");
  184. return false;
  185. }
  186. if(blockcopy->num_comments != block->num_comments) {
  187. printf("FAILED, num_comments mismatch, expected %u, got %un", block->num_comments, blockcopy->num_comments);
  188. return false;
  189. }
  190. for(i = 0; i < block->num_comments; i++) {
  191. if(blockcopy->comments[i].length != block->comments[i].length) {
  192. printf("FAILED, comments[%u].length mismatch, expected %u, got %un", i, block->comments[i].length, blockcopy->comments[i].length);
  193. return false;
  194. }
  195. if(0 == block->comments[i].entry || 0 == blockcopy->comments[i].entry) {
  196. if(block->comments[i].entry != blockcopy->comments[i].entry) {
  197. printf("FAILED, comments[%u].entry mismatchn", i);
  198. return false;
  199. }
  200. }
  201. else {
  202. if(0 != memcmp(blockcopy->comments[i].entry, block->comments[i].entry, block->comments[i].length)) {
  203. printf("FAILED, comments[%u].entry mismatchn", i);
  204. return false;
  205. }
  206. }
  207. }
  208. return true;
  209. }
  210. FLAC__bool mutils__compare_block_data_cuesheet(const FLAC__StreamMetadata_CueSheet *block, const FLAC__StreamMetadata_CueSheet *blockcopy)
  211. {
  212. unsigned i, j;
  213. if(0 != strcmp(blockcopy->media_catalog_number, block->media_catalog_number)) {
  214. printf("FAILED, media_catalog_number mismatch, expected %s, got %sn", block->media_catalog_number, blockcopy->media_catalog_number);
  215. return false;
  216. }
  217. if(blockcopy->lead_in != block->lead_in) {
  218. printf("FAILED, lead_in mismatch, expected %llu, got %llun", block->lead_in, blockcopy->lead_in);
  219. return false;
  220. }
  221. if(blockcopy->is_cd != block->is_cd) {
  222. printf("FAILED, is_cd mismatch, expected %u, got %un", (unsigned)block->is_cd, (unsigned)blockcopy->is_cd);
  223. return false;
  224. }
  225. if(blockcopy->num_tracks != block->num_tracks) {
  226. printf("FAILED, num_tracks mismatch, expected %u, got %un", block->num_tracks, blockcopy->num_tracks);
  227. return false;
  228. }
  229. for(i = 0; i < block->num_tracks; i++) {
  230. if(blockcopy->tracks[i].offset != block->tracks[i].offset) {
  231. printf("FAILED, tracks[%u].offset mismatch, expected %llu, got %llun", i, block->tracks[i].offset, blockcopy->tracks[i].offset);
  232. return false;
  233. }
  234. if(blockcopy->tracks[i].number != block->tracks[i].number) {
  235. printf("FAILED, tracks[%u].number mismatch, expected %u, got %un", i, (unsigned)block->tracks[i].number, (unsigned)blockcopy->tracks[i].number);
  236. return false;
  237. }
  238. if(blockcopy->tracks[i].num_indices != block->tracks[i].num_indices) {
  239. printf("FAILED, tracks[%u].num_indices mismatch, expected %u, got %un", i, (unsigned)block->tracks[i].num_indices, (unsigned)blockcopy->tracks[i].num_indices);
  240. return false;
  241. }
  242. /* num_indices == 0 means lead-out track so only the track offset and number are valid */
  243. if(block->tracks[i].num_indices > 0) {
  244. if(0 != strcmp(blockcopy->tracks[i].isrc, block->tracks[i].isrc)) {
  245. printf("FAILED, tracks[%u].isrc mismatch, expected %s, got %sn", i, block->tracks[i].isrc, blockcopy->tracks[i].isrc);
  246. return false;
  247. }
  248. if(blockcopy->tracks[i].type != block->tracks[i].type) {
  249. printf("FAILED, tracks[%u].type mismatch, expected %u, got %un", i, (unsigned)block->tracks[i].type, (unsigned)blockcopy->tracks[i].type);
  250. return false;
  251. }
  252. if(blockcopy->tracks[i].pre_emphasis != block->tracks[i].pre_emphasis) {
  253. printf("FAILED, tracks[%u].pre_emphasis mismatch, expected %u, got %un", i, (unsigned)block->tracks[i].pre_emphasis, (unsigned)blockcopy->tracks[i].pre_emphasis);
  254. return false;
  255. }
  256. if(0 == block->tracks[i].indices || 0 == blockcopy->tracks[i].indices) {
  257. if(block->tracks[i].indices != blockcopy->tracks[i].indices) {
  258. printf("FAILED, tracks[%u].indices mismatchn", i);
  259. return false;
  260. }
  261. }
  262. else {
  263. for(j = 0; j < block->tracks[i].num_indices; j++) {
  264. if(blockcopy->tracks[i].indices[j].offset != block->tracks[i].indices[j].offset) {
  265. printf("FAILED, tracks[%u].indices[%u].offset mismatch, expected %llu, got %llun", i, j, block->tracks[i].indices[j].offset, blockcopy->tracks[i].indices[j].offset);
  266. return false;
  267. }
  268. if(blockcopy->tracks[i].indices[j].number != block->tracks[i].indices[j].number) {
  269. printf("FAILED, tracks[%u].indices[%u].number mismatch, expected %u, got %un", i, j, (unsigned)block->tracks[i].indices[j].number, (unsigned)blockcopy->tracks[i].indices[j].number);
  270. return false;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. return true;
  277. }
  278. FLAC__bool mutils__compare_block_data_unknown(const FLAC__StreamMetadata_Unknown *block, const FLAC__StreamMetadata_Unknown *blockcopy, unsigned block_length)
  279. {
  280. if(0 == block->data || 0 == blockcopy->data) {
  281. if(block->data != blockcopy->data) {
  282. printf("FAILED, data mismatch (%s's data pointer is null)n", 0==block->data?"original":"copy");
  283. return false;
  284. }
  285. else if(block_length > 0) {
  286. printf("FAILED, data pointer is null but block length is not 0n");
  287. return false;
  288. }
  289. }
  290. else {
  291. if(block_length == 0) {
  292. printf("FAILED, data pointer is not null but block length is 0n");
  293. return false;
  294. }
  295. else if(0 != memcmp(blockcopy->data, block->data, block_length)) {
  296. printf("FAILED, data mismatchn");
  297. return false;
  298. }
  299. }
  300. return true;
  301. }
  302. FLAC__bool mutils__compare_block(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy)
  303. {
  304. if(blockcopy->type != block->type) {
  305. printf("FAILED, type mismatch, expected %s, got %sn", FLAC__MetadataTypeString[block->type], FLAC__MetadataTypeString[blockcopy->type]);
  306. return false;
  307. }
  308. if(blockcopy->is_last != block->is_last) {
  309. printf("FAILED, is_last mismatch, expected %u, got %un", (unsigned)block->is_last, (unsigned)blockcopy->is_last);
  310. return false;
  311. }
  312. if(blockcopy->length != block->length) {
  313. printf("FAILED, length mismatch, expected %u, got %un", block->length, blockcopy->length);
  314. return false;
  315. }
  316. switch(block->type) {
  317. case FLAC__METADATA_TYPE_STREAMINFO:
  318. return mutils__compare_block_data_streaminfo(&block->data.stream_info, &blockcopy->data.stream_info);
  319. case FLAC__METADATA_TYPE_PADDING:
  320. return mutils__compare_block_data_padding(&block->data.padding, &blockcopy->data.padding, block->length);
  321. case FLAC__METADATA_TYPE_APPLICATION:
  322. return mutils__compare_block_data_application(&block->data.application, &blockcopy->data.application, block->length);
  323. case FLAC__METADATA_TYPE_SEEKTABLE:
  324. return mutils__compare_block_data_seektable(&block->data.seek_table, &blockcopy->data.seek_table);
  325. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  326. return mutils__compare_block_data_vorbiscomment(&block->data.vorbis_comment, &blockcopy->data.vorbis_comment);
  327. case FLAC__METADATA_TYPE_CUESHEET:
  328. return mutils__compare_block_data_cuesheet(&block->data.cue_sheet, &blockcopy->data.cue_sheet);
  329. default:
  330. return mutils__compare_block_data_unknown(&block->data.unknown, &blockcopy->data.unknown, block->length);
  331. }
  332. }
  333. static void *malloc_or_die_(size_t size)
  334. {
  335. void *x = malloc(size);
  336. if(0 == x) {
  337. fprintf(stderr, "ERROR: out of memory allocating %u bytesn", (unsigned)size);
  338. exit(1);
  339. }
  340. return x;
  341. }
  342. static void *calloc_or_die_(size_t n, size_t size)
  343. {
  344. void *x = calloc(n, size);
  345. if(0 == x) {
  346. fprintf(stderr, "ERROR: out of memory allocating %u bytesn", (unsigned)n * (unsigned)size);
  347. exit(1);
  348. }
  349. return x;
  350. }
  351. void mutils__init_metadata_blocks(
  352. FLAC__StreamMetadata *streaminfo,
  353. FLAC__StreamMetadata *padding,
  354. FLAC__StreamMetadata *seektable,
  355. FLAC__StreamMetadata *application1,
  356. FLAC__StreamMetadata *application2,
  357. FLAC__StreamMetadata *vorbiscomment,
  358. FLAC__StreamMetadata *cuesheet,
  359. FLAC__StreamMetadata *unknown
  360. )
  361. {
  362. /*
  363. most of the actual numbers and data in the blocks don't matter,
  364. we just want to make sure the decoder parses them correctly
  365. remember, the metadata interface gets tested after the decoders,
  366. so we do all the metadata manipulation here without it.
  367. */
  368. /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
  369. streaminfo->is_last = false;
  370. streaminfo->type = FLAC__METADATA_TYPE_STREAMINFO;
  371. streaminfo->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  372. streaminfo->data.stream_info.min_blocksize = 576;
  373. streaminfo->data.stream_info.max_blocksize = 576;
  374. streaminfo->data.stream_info.min_framesize = 0;
  375. streaminfo->data.stream_info.max_framesize = 0;
  376. streaminfo->data.stream_info.sample_rate = 44100;
  377. streaminfo->data.stream_info.channels = 1;
  378. streaminfo->data.stream_info.bits_per_sample = 8;
  379. streaminfo->data.stream_info.total_samples = 0;
  380. memset(streaminfo->data.stream_info.md5sum, 0, 16);
  381. padding->is_last = false;
  382. padding->type = FLAC__METADATA_TYPE_PADDING;
  383. padding->length = 1234;
  384. seektable->is_last = false;
  385. seektable->type = FLAC__METADATA_TYPE_SEEKTABLE;
  386. seektable->data.seek_table.num_points = 2;
  387. seektable->length = seektable->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  388. seektable->data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
  389. seektable->data.seek_table.points[0].sample_number = 0;
  390. seektable->data.seek_table.points[0].stream_offset = 0;
  391. seektable->data.seek_table.points[0].frame_samples = streaminfo->data.stream_info.min_blocksize;
  392. seektable->data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  393. seektable->data.seek_table.points[1].stream_offset = 1000;
  394. seektable->data.seek_table.points[1].frame_samples = streaminfo->data.stream_info.min_blocksize;
  395. application1->is_last = false;
  396. application1->type = FLAC__METADATA_TYPE_APPLICATION;
  397. application1->length = 8;
  398. memcpy(application1->data.application.id, "xfexdcxbax98", 4);
  399. application1->data.application.data = (FLAC__byte*)malloc_or_die_(4);
  400. memcpy(application1->data.application.data, "xf0xe1xd2xc3", 4);
  401. application2->is_last = false;
  402. application2->type = FLAC__METADATA_TYPE_APPLICATION;
  403. application2->length = 4;
  404. memcpy(application2->data.application.id, "x76x54x32x10", 4);
  405. application2->data.application.data = 0;
  406. {
  407. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  408. vorbiscomment->is_last = false;
  409. vorbiscomment->type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  410. vorbiscomment->length = (4 + vendor_string_length) + 4 + (4 + 5) + (4 + 0);
  411. vorbiscomment->data.vorbis_comment.vendor_string.length = vendor_string_length;
  412. vorbiscomment->data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(vendor_string_length+1);
  413. memcpy(vorbiscomment->data.vorbis_comment.vendor_string.entry, FLAC__VENDOR_STRING, vendor_string_length+1);
  414. vorbiscomment->data.vorbis_comment.num_comments = 2;
  415. vorbiscomment->data.vorbis_comment.comments = (FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment->data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
  416. vorbiscomment->data.vorbis_comment.comments[0].length = 5;
  417. vorbiscomment->data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(5+1);
  418. memcpy(vorbiscomment->data.vorbis_comment.comments[0].entry, "ab=cd", 5+1);
  419. vorbiscomment->data.vorbis_comment.comments[1].length = 0;
  420. vorbiscomment->data.vorbis_comment.comments[1].entry = 0;
  421. }
  422. cuesheet->is_last = false;
  423. cuesheet->type = FLAC__METADATA_TYPE_CUESHEET;
  424. cuesheet->length =
  425. /* cuesheet guts */
  426. (
  427. FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
  428. FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
  429. FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
  430. FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
  431. FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
  432. ) / 8 +
  433. /* 2 tracks */
  434. 3 * (
  435. FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
  436. FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
  437. FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
  438. FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
  439. FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
  440. FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
  441. FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
  442. ) / 8 +
  443. /* 3 index points */
  444. 3 * (
  445. FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
  446. FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
  447. FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
  448. ) / 8
  449. ;
  450. memset(cuesheet->data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet->data.cue_sheet.media_catalog_number));
  451. cuesheet->data.cue_sheet.media_catalog_number[0] = 'j';
  452. cuesheet->data.cue_sheet.media_catalog_number[1] = 'C';
  453. cuesheet->data.cue_sheet.lead_in = 2 * 44100;
  454. cuesheet->data.cue_sheet.is_cd = true;
  455. cuesheet->data.cue_sheet.num_tracks = 3;
  456. cuesheet->data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)calloc_or_die_(cuesheet->data.cue_sheet.num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track));
  457. cuesheet->data.cue_sheet.tracks[0].offset = 0;
  458. cuesheet->data.cue_sheet.tracks[0].number = 1;
  459. memcpy(cuesheet->data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet->data.cue_sheet.tracks[0].isrc));
  460. cuesheet->data.cue_sheet.tracks[0].type = 0;
  461. cuesheet->data.cue_sheet.tracks[0].pre_emphasis = 1;
  462. cuesheet->data.cue_sheet.tracks[0].num_indices = 2;
  463. cuesheet->data.cue_sheet.tracks[0].indices = (FLAC__StreamMetadata_CueSheet_Index*)malloc_or_die_(cuesheet->data.cue_sheet.tracks[0].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
  464. cuesheet->data.cue_sheet.tracks[0].indices[0].offset = 0;
  465. cuesheet->data.cue_sheet.tracks[0].indices[0].number = 0;
  466. cuesheet->data.cue_sheet.tracks[0].indices[1].offset = 123 * 588;
  467. cuesheet->data.cue_sheet.tracks[0].indices[1].number = 1;
  468. cuesheet->data.cue_sheet.tracks[1].offset = 1234 * 588;
  469. cuesheet->data.cue_sheet.tracks[1].number = 2;
  470. memcpy(cuesheet->data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet->data.cue_sheet.tracks[1].isrc));
  471. cuesheet->data.cue_sheet.tracks[1].type = 1;
  472. cuesheet->data.cue_sheet.tracks[1].pre_emphasis = 0;
  473. cuesheet->data.cue_sheet.tracks[1].num_indices = 1;
  474. cuesheet->data.cue_sheet.tracks[1].indices = (FLAC__StreamMetadata_CueSheet_Index*)malloc_or_die_(cuesheet->data.cue_sheet.tracks[1].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
  475. cuesheet->data.cue_sheet.tracks[1].indices[0].offset = 0;
  476. cuesheet->data.cue_sheet.tracks[1].indices[0].number = 1;
  477. cuesheet->data.cue_sheet.tracks[2].offset = 12345 * 588;
  478. cuesheet->data.cue_sheet.tracks[2].number = 170;
  479. cuesheet->data.cue_sheet.tracks[2].num_indices = 0;
  480. unknown->is_last = true;
  481. unknown->type = 127;
  482. unknown->length = 8;
  483. unknown->data.unknown.data = (FLAC__byte*)malloc_or_die_(unknown->length);
  484. memcpy(unknown->data.unknown.data, "xfexdcxbax98xf0xe1xd2xc3", unknown->length);
  485. }
  486. void mutils__free_metadata_blocks(
  487. FLAC__StreamMetadata *streaminfo,
  488. FLAC__StreamMetadata *padding,
  489. FLAC__StreamMetadata *seektable,
  490. FLAC__StreamMetadata *application1,
  491. FLAC__StreamMetadata *application2,
  492. FLAC__StreamMetadata *vorbiscomment,
  493. FLAC__StreamMetadata *cuesheet,
  494. FLAC__StreamMetadata *unknown
  495. )
  496. {
  497. (void)streaminfo, (void)padding, (void)application2;
  498. free(seektable->data.seek_table.points);
  499. free(application1->data.application.data);
  500. free(vorbiscomment->data.vorbis_comment.vendor_string.entry);
  501. free(vorbiscomment->data.vorbis_comment.comments[0].entry);
  502. free(vorbiscomment->data.vorbis_comment.comments);
  503. free(cuesheet->data.cue_sheet.tracks[0].indices);
  504. free(cuesheet->data.cue_sheet.tracks[1].indices);
  505. free(cuesheet->data.cue_sheet.tracks);
  506. free(unknown->data.unknown.data);
  507. }