"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/stco.c" (9 Jan 2007, 3104 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include "funcprotos.h"
    2 #include "quicktime.h"
    3 
    4 
    5 
    6 void quicktime_stco_init(quicktime_stco_t *stco)
    7 {
    8     stco->version = 0;
    9     stco->flags = 0;
   10     stco->total_entries = 0;
   11     stco->entries_allocated = 0;
   12 }
   13 
   14 void quicktime_stco_delete(quicktime_stco_t *stco)
   15 {
   16     if(stco->total_entries) free(stco->table);
   17     stco->total_entries = 0;
   18     stco->entries_allocated = 0;
   19 }
   20 
   21 void quicktime_stco_init_common(quicktime_t *file, quicktime_stco_t *stco)
   22 {
   23     if(!stco->entries_allocated)
   24     {
   25         stco->entries_allocated = 2048;
   26         stco->total_entries = 0;
   27         stco->table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
   28 /*printf("quicktime_stco_init_common %x\n", stco->table); */
   29     }
   30 }
   31 
   32 void quicktime_stco_dump(quicktime_stco_t *stco)
   33 {
   34     int i;
   35     printf("     chunk offset\n");
   36     printf("      version %d\n", stco->version);
   37     printf("      flags %d\n", stco->flags);
   38     printf("      total_entries %d\n", stco->total_entries);
   39     for(i = 0; i < stco->total_entries; i++)
   40     {
   41         printf("       offset %d %llx\n", i, stco->table[i].offset);
   42     }
   43 }
   44 
   45 void quicktime_read_stco(quicktime_t *file, quicktime_stco_t *stco)
   46 {
   47     int i;
   48     stco->version = quicktime_read_char(file);
   49     stco->flags = quicktime_read_int24(file);
   50     stco->total_entries = quicktime_read_int32(file);
   51     stco->entries_allocated = stco->total_entries;
   52     stco->table = (quicktime_stco_table_t*)calloc(1, 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_uint32(file);
   56     }
   57 }
   58 
   59 void quicktime_read_stco64(quicktime_t *file, quicktime_stco_t *stco)
   60 {
   61     int i;
   62     stco->version = quicktime_read_char(file);
   63     stco->flags = quicktime_read_int24(file);
   64     stco->total_entries = quicktime_read_int32(file);
   65     stco->entries_allocated = stco->total_entries;
   66     stco->table = (quicktime_stco_table_t*)calloc(1, sizeof(quicktime_stco_table_t) * stco->entries_allocated);
   67     for(i = 0; i < stco->total_entries; i++)
   68     {
   69         stco->table[i].offset = quicktime_read_int64(file);
   70     }
   71 }
   72 
   73 void quicktime_write_stco(quicktime_t *file, quicktime_stco_t *stco)
   74 {
   75     int i;
   76     quicktime_atom_t atom;
   77 //  quicktime_atom_write_header(file, &atom, "stco");
   78     quicktime_atom_write_header(file, &atom, "co64");
   79 
   80     quicktime_write_char(file, stco->version);
   81     quicktime_write_int24(file, stco->flags);
   82     quicktime_write_int32(file, stco->total_entries);
   83     for(i = 0; i < stco->total_entries; i++)
   84     {
   85         quicktime_write_int64(file, stco->table[i].offset);
   86     }
   87 
   88     quicktime_atom_write_footer(file, &atom);
   89 }
   90 
   91 // Chunk starts at 1
   92 void quicktime_update_stco(quicktime_stco_t *stco, long chunk, int64_t offset)
   93 {
   94     long i;
   95     if(chunk <= 0)
   96         printf("quicktime_update_stco chunk must start at 1. chunk=%d\n",
   97             chunk);
   98 
   99     if(chunk > stco->entries_allocated)
  100     {
  101         stco->entries_allocated = chunk * 2;
  102 //printf("quicktime_update_stco 1\n");
  103         stco->table = (quicktime_stco_table_t*)realloc(stco->table, 
  104             sizeof(quicktime_stco_table_t) * stco->entries_allocated);
  105 //printf("quicktime_update_stco 2\n");
  106     }
  107     
  108     stco->table[chunk - 1].offset = offset;
  109     if(chunk > stco->total_entries) stco->total_entries = chunk;
  110 }
  111