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 / stsz.c < prev    next >
C/C++ Source or Header  |  2000-11-29  |  4KB  |  138 lines

  1. #include "quicktime.h"
  2.  
  3.  
  4.  
  5. void quicktime_stsz_init(quicktime_stsz_t *stsz)
  6. {
  7.     stsz->version = 0;
  8.     stsz->flags = 0;
  9.     stsz->sample_size = 0;
  10.     stsz->total_entries = 0;
  11.     stsz->entries_allocated = 0;
  12. }
  13.  
  14. void quicktime_stsz_init_video(quicktime_t *file, quicktime_stsz_t *stsz)
  15. {
  16.     stsz->sample_size = 0;
  17.     if(!stsz->entries_allocated)
  18.     {
  19.         stsz->entries_allocated = 2000;
  20.         stsz->total_entries = 0;
  21.         stsz->table = (quicktime_stsz_table_t*)malloc(sizeof(quicktime_stsz_table_t) * stsz->entries_allocated);
  22.     }
  23. }
  24.  
  25. void quicktime_stsz_init_audio(quicktime_t *file, quicktime_stsz_t *stsz, int channels, int bits)
  26. {
  27.     /*stsz->sample_size = channels * bits / 8; */
  28.     stsz->sample_size = 1;   /* ? */
  29.     stsz->total_entries = 0;   /* set this when closing */
  30.     stsz->entries_allocated = 0;
  31. }
  32.  
  33. void quicktime_stsz_delete(quicktime_stsz_t *stsz)
  34. {
  35.     if(!stsz->sample_size && stsz->total_entries) free(stsz->table);
  36.     stsz->total_entries = 0;
  37.     stsz->entries_allocated = 0;
  38. }
  39.  
  40. void quicktime_stsz_dump(quicktime_stsz_t *stsz)
  41. {
  42.     int i;
  43.     printf("     sample size\n");
  44.     printf("      version %d\n", stsz->version);
  45.     printf("      flags %d\n", stsz->flags);
  46.     printf("      sample_size %d\n", stsz->sample_size);
  47.     printf("      total_entries %d\n", stsz->total_entries);
  48.     
  49.     if(!stsz->sample_size)
  50.     {
  51.         for(i = 0; i < stsz->total_entries; i++)
  52.         {
  53.             printf("       sample_size %x\n", stsz->table[i].size);
  54.         }
  55.     }
  56. }
  57.  
  58. void quicktime_read_stsz(quicktime_t *file, quicktime_stsz_t *stsz)
  59. {
  60.     int i;
  61.     stsz->version = quicktime_read_char(file);
  62.     stsz->flags = quicktime_read_int24(file);
  63.     stsz->sample_size = quicktime_read_int32(file);
  64.     stsz->total_entries = quicktime_read_int32(file);
  65.     stsz->entries_allocated = stsz->total_entries;
  66.     if(!stsz->sample_size)
  67.     {
  68.         stsz->table = (quicktime_stsz_table_t*)malloc(sizeof(quicktime_stsz_table_t) * stsz->entries_allocated);
  69.         for(i = 0; i < stsz->total_entries; i++)
  70.         {
  71.             stsz->table[i].size = quicktime_read_int32(file);
  72.         }
  73.     }
  74. }
  75.  
  76. void quicktime_write_stsz(quicktime_t *file, quicktime_stsz_t *stsz)
  77. {
  78.     int i, result;
  79.     quicktime_atom_t atom;
  80.     quicktime_atom_write_header(file, &atom, "stsz");
  81.  
  82. /* optimize if possible */
  83. /* Xanim requires an unoptimized table for video. */
  84. /*     if(!stsz->sample_size) */
  85. /*     { */
  86. /*         for(i = 0, result = 0; i < stsz->total_entries && !result; i++) */
  87. /*         { */
  88. /*             if(stsz->table[i].size != stsz->table[0].size) result = 1; */
  89. /*         } */
  90. /*          */
  91. /*         if(!result) */
  92. /*         { */
  93. /*             stsz->sample_size = stsz->table[0].size; */
  94. /*             stsz->total_entries = 0; */
  95. /*             free(stsz->table); */
  96. /*         } */
  97. /*     } */
  98.  
  99.     quicktime_write_char(file, stsz->version);
  100.     quicktime_write_int24(file, stsz->flags);
  101.     quicktime_write_int32(file, stsz->sample_size);
  102.     if(stsz->sample_size)
  103.     {
  104.         quicktime_write_int32(file, stsz->total_entries);
  105.     }
  106.     else
  107.     {
  108.         quicktime_write_int32(file, stsz->total_entries);
  109.         for(i = 0; i < stsz->total_entries; i++)
  110.         {
  111.             quicktime_write_int32(file, stsz->table[i].size);
  112.         }
  113.     }
  114.  
  115.     quicktime_atom_write_footer(file, &atom);
  116. }
  117.  
  118. void quicktime_update_stsz(quicktime_stsz_t *stsz, long sample, long sample_size)
  119. {
  120.     quicktime_stsz_table_t *new_table;
  121.     int i;
  122.  
  123.     if(!stsz->sample_size)
  124.     {
  125.         if(sample >= stsz->entries_allocated)
  126.         {
  127.             stsz->entries_allocated = sample * 2;
  128.             new_table = (quicktime_stsz_table_t*)malloc(sizeof(quicktime_stsz_table_t) * stsz->entries_allocated);
  129.             for(i = 0; i < stsz->total_entries; i++) new_table[i] = stsz->table[i];
  130.             free(stsz->table);
  131.             stsz->table = new_table;
  132.         }
  133.  
  134.         stsz->table[sample].size = sample_size;
  135.         if(sample >= stsz->total_entries) stsz->total_entries = sample + 1;
  136.     }
  137. }
  138.