home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / quicktime / stco.c < prev    next >
C/C++ Source or Header  |  2000-11-29  |  3KB  |  94 lines

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