dref.c
上传用户:luping1608
上传日期:2007-01-06
资源大小:38k
文件大小:3k
源码类别:

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_dref_table_init(quicktime_dref_table_t *table)
  3. {
  4. table->size = 0;
  5. table->type[0] = 'a';
  6. table->type[1] = 'l';
  7. table->type[2] = 'i';
  8. table->type[3] = 's';
  9. table->version = 0;
  10. table->flags = 0x0001;
  11. table->data_reference = malloc(256);
  12. table->data_reference[0] = 0;
  13. }
  14. int quicktime_dref_table_delete(quicktime_dref_table_t *table)
  15. {
  16. if(table->data_reference) free(table->data_reference);
  17. table->data_reference = 0;
  18. }
  19. int quicktime_read_dref_table(quicktime_t *file, quicktime_dref_table_t *table)
  20. {
  21. table->size = quicktime_read_int32(file);
  22. quicktime_read_char32(file, table->type);
  23. table->version = quicktime_read_char(file);
  24. table->flags = quicktime_read_int24(file);
  25. if(table->data_reference) free(table->data_reference);
  26. table->data_reference = malloc(table->size);
  27. if(table->size > 12)
  28. quicktime_read_data(file, table->data_reference, table->size - 12);
  29. table->data_reference[table->size - 12] = 0;
  30. }
  31. int quicktime_write_dref_table(quicktime_t *file, quicktime_dref_table_t *table)
  32. {
  33. int len = strlen(table->data_reference);
  34. quicktime_write_int32(file, 12 + len);
  35. quicktime_write_char32(file, table->type);
  36. quicktime_write_char(file, table->version);
  37. quicktime_write_int24(file, table->flags);
  38. if(len)
  39. quicktime_write_data(file, table->data_reference, len);
  40. }
  41. int quicktime_dref_table_dump(quicktime_dref_table_t *table)
  42. {
  43. printf("      data reference table (dref)n");
  44. printf("       type %c%c%c%cn", table->type[0], table->type[1], table->type[2], table->type[3]);
  45. printf("       version %dn", table->version);
  46. printf("       flags %dn", table->flags);
  47. printf("       data %sn", table->data_reference);
  48. }
  49. int quicktime_dref_init(quicktime_dref_t *dref)
  50. {
  51. dref->version = 0;
  52. dref->flags = 0;
  53. dref->total_entries = 0;
  54. dref->table = 0;
  55. }
  56. int quicktime_dref_init_all(quicktime_dref_t *dref)
  57. {
  58. if(!dref->total_entries)
  59. {
  60. dref->total_entries = 1;
  61. dref->table = (quicktime_dref_table_t *)malloc(sizeof(quicktime_dref_table_t) * dref->total_entries);
  62. quicktime_dref_table_init(&(dref->table[0]));
  63. }
  64. }
  65. int quicktime_dref_delete(quicktime_dref_t *dref)
  66. {
  67. if(dref->table)
  68. {
  69. int i;
  70. for(i = 0; i < dref->total_entries; i++)
  71. quicktime_dref_table_delete(&(dref->table[i]));
  72. free(dref->table);
  73. }
  74. dref->total_entries = 0;
  75. }
  76. int quicktime_dref_dump(quicktime_dref_t *dref)
  77. {
  78. int i;
  79. printf("     data reference (dref)n");
  80. printf("      version %dn", dref->version);
  81. printf("      flags %dn", dref->flags);
  82. for(i = 0; i < dref->total_entries; i++)
  83. {
  84. quicktime_dref_table_dump(&(dref->table[i]));
  85. }
  86. }
  87. int quicktime_read_dref(quicktime_t *file, quicktime_dref_t *dref)
  88. {
  89. int i;
  90. dref->version = quicktime_read_char(file);
  91. dref->flags = quicktime_read_int24(file);
  92. dref->total_entries = quicktime_read_int32(file);
  93. dref->table = (quicktime_dref_table_t*)malloc(sizeof(quicktime_dref_table_t) * dref->total_entries);
  94. for(i = 0; i < dref->total_entries; i++)
  95. {
  96. quicktime_dref_table_init(&(dref->table[i]));
  97. quicktime_read_dref_table(file, &(dref->table[i]));
  98. }
  99. }
  100. int quicktime_write_dref(quicktime_t *file, quicktime_dref_t *dref)
  101. {
  102. int i;
  103. quicktime_atom_t atom;
  104. quicktime_atom_write_header(file, &atom, "dref");
  105. quicktime_write_char(file, dref->version);
  106. quicktime_write_int24(file, dref->flags);
  107. quicktime_write_int32(file, dref->total_entries);
  108. for(i = 0; i < dref->total_entries; i++)
  109. {
  110. quicktime_write_dref_table(file, &(dref->table[i]));
  111. }
  112. quicktime_atom_write_footer(file, &atom);
  113. }