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

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_stco_init(quicktime_stco_t *stco)
  3. {
  4. stco->version = 0;
  5. stco->flags = 0;
  6. stco->total_entries = 0;
  7. stco->entries_allocated = 0;
  8. }
  9. int quicktime_stco_delete(quicktime_stco_t *stco)
  10. {
  11. if(stco->total_entries) free(stco->table);
  12. stco->total_entries = 0;
  13. stco->entries_allocated = 0;
  14. }
  15. int quicktime_stco_init_common(quicktime_t *file, quicktime_stco_t *stco)
  16. {
  17. if(!stco->entries_allocated)
  18. {
  19. stco->entries_allocated = 2000;
  20. stco->total_entries = 0;
  21. stco->table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
  22. //printf("quicktime_stco_init_common %xn", stco->table);
  23. }
  24. }
  25. int quicktime_stco_dump(quicktime_stco_t *stco)
  26. {
  27. int i;
  28. printf("     chunk offsetn");
  29. printf("      version %dn", stco->version);
  30. printf("      flags %dn", stco->flags);
  31. printf("      total_entries %dn", stco->total_entries);
  32. for(i = 0; i < stco->total_entries; i++)
  33. {
  34. printf("       offset %dn", stco->table[i].offset);
  35. }
  36. }
  37. int quicktime_read_stco(quicktime_t *file, quicktime_stco_t *stco)
  38. {
  39. int i;
  40. stco->version = quicktime_read_char(file);
  41. stco->flags = quicktime_read_int24(file);
  42. stco->total_entries = quicktime_read_int32(file);
  43. //printf("stco->total_entries %d %xn", stco->total_entries, stco);
  44. stco->entries_allocated = stco->total_entries;
  45. stco->table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
  46. for(i = 0; i < stco->total_entries; i++)
  47. {
  48. stco->table[i].offset = quicktime_read_int32(file);
  49. }
  50. }
  51. int quicktime_write_stco(quicktime_t *file, quicktime_stco_t *stco)
  52. {
  53. int i;
  54. quicktime_atom_t atom;
  55. quicktime_atom_write_header(file, &atom, "stco");
  56. quicktime_write_char(file, stco->version);
  57. quicktime_write_int24(file, stco->flags);
  58. quicktime_write_int32(file, stco->total_entries);
  59. for(i = 0; i < stco->total_entries; i++)
  60. {
  61. quicktime_write_int32(file, stco->table[i].offset);
  62. }
  63. quicktime_atom_write_footer(file, &atom);
  64. }
  65. int quicktime_update_stco(quicktime_stco_t *stco, long chunk, long offset)
  66. {
  67. quicktime_stco_table_t *new_table;
  68. long i;
  69. //printf("quicktime_update_stco %ldn", chunk);
  70. if(chunk > stco->entries_allocated)
  71. {
  72. stco->entries_allocated = chunk * 2;
  73. new_table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
  74. for(i = 0; i < stco->total_entries; i++) new_table[i].offset = stco->table[i].offset;
  75. //printf("quicktime_update_stco stco %x stco->table %x entries_allocated %ldn", stco, stco->table, stco->entries_allocated);
  76. free(stco->table);
  77. //printf("stco->table = new_tablen");
  78. stco->table = new_table;
  79. }
  80. stco->table[chunk - 1].offset = offset;
  81. if(chunk > stco->total_entries) stco->total_entries = chunk;
  82. }