"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/avi_indx.c" (9 Jan 2007, 4335 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 #include <string.h>
    4 
    5 
    6 void quicktime_delete_indx(quicktime_indx_t *indx)
    7 {
    8     int i;
    9     if(indx->table)
   10     {
   11         for(i = 0; i < indx->table_size; i++)
   12         {
   13             quicktime_indxtable_t *indx_table = &indx->table[i];
   14             if(indx_table->ix) quicktime_delete_ix(indx_table->ix);
   15         }
   16         free(indx->table);
   17     }
   18 }
   19 
   20 void quicktime_init_indx(quicktime_t *file, 
   21     quicktime_indx_t *indx, 
   22     quicktime_strl_t *strl)
   23 {
   24     indx->longs_per_entry = 4;
   25     indx->index_subtype = 0;
   26     indx->index_type = AVI_INDEX_OF_INDEXES;
   27     memcpy(indx->chunk_id, strl->tag, 4);
   28 }
   29 
   30 void quicktime_update_indx(quicktime_t *file, 
   31     quicktime_indx_t *indx, 
   32     quicktime_ix_t *ix)
   33 {
   34     quicktime_indxtable_t *indx_table;
   35 
   36 /* Allocate */
   37     if(indx->table_size >= indx->table_allocation)
   38     {
   39         quicktime_indxtable_t *old_table = indx->table;
   40         int new_allocation = indx->table_allocation * 2;
   41         if(new_allocation < 1) new_allocation = 1;
   42         indx->table = calloc(1, sizeof(quicktime_indxtable_t) * new_allocation);
   43         if(old_table)
   44         {
   45             memcpy(indx->table, old_table, sizeof(quicktime_indxtable_t) * indx->table_size);
   46             free(old_table);
   47         }
   48         indx->table_allocation = new_allocation;
   49     }
   50 
   51 /* Append */
   52     indx_table = &indx->table[indx->table_size++];
   53     indx_table->index_offset = ix->atom.start - 8;
   54     indx_table->index_size = ix->atom.size;
   55     indx_table->duration = ix->table_size;
   56 }
   57 
   58 
   59 
   60 void quicktime_finalize_indx(quicktime_t *file)
   61 {
   62     int i, j;
   63     quicktime_riff_t *riff = file->riff[0];
   64     quicktime_hdrl_t *hdrl = &riff->hdrl;
   65     quicktime_strl_t *strl;
   66     quicktime_indx_t *indx;
   67     quicktime_atom_t junk_atom;
   68     int junk_size;
   69 
   70 
   71     for(i = 0; i < file->moov.total_tracks; i++)
   72     {
   73         strl = hdrl->strl[i];
   74         indx = &strl->indx;
   75 
   76 /* Write indx */
   77         quicktime_set_position(file, strl->indx_offset);
   78         quicktime_atom_write_header(file, &indx->atom, "indx");
   79 /* longs per entry */
   80         quicktime_write_int16_le(file, indx->longs_per_entry);
   81 /* index sub type */
   82         quicktime_write_char(file, indx->index_subtype);
   83 /* index type */
   84         quicktime_write_char(file, indx->index_type);
   85 /* entries in use */
   86         quicktime_write_int32_le(file, indx->table_size);
   87 /* chunk ID */
   88         quicktime_write_char32(file, indx->chunk_id);
   89 /* reserved */
   90         quicktime_write_int32_le(file, 0);
   91         quicktime_write_int32_le(file, 0);
   92         quicktime_write_int32_le(file, 0);
   93 
   94 /* table */
   95         for(j = 0; j < indx->table_size; j++)
   96         {
   97             quicktime_indxtable_t *indx_table = &indx->table[j];
   98             quicktime_write_int64_le(file, indx_table->index_offset);
   99             quicktime_write_int32_le(file, indx_table->index_size);
  100             quicktime_write_int32_le(file, indx_table->duration);
  101         }
  102 
  103         quicktime_atom_write_footer(file, &indx->atom);
  104 
  105 
  106 
  107 /* Rewrite JUNK less indx size and indx header size */
  108         junk_size = strl->padding_size - indx->atom.size - 8;
  109 /*
  110  *      quicktime_atom_write_header(file, &junk_atom, "JUNK");
  111  *      for(j = 0; j < junk_size; j += 4)
  112  *          quicktime_write_int32_le(file, 0);
  113  *      quicktime_atom_write_footer(file, &junk_atom);
  114  */
  115     }
  116 }
  117 
  118 
  119 
  120 
  121 
  122 
  123 
  124 
  125 
  126 void quicktime_read_indx(quicktime_t *file, 
  127     quicktime_strl_t *strl, 
  128     quicktime_atom_t *parent_atom)
  129 {
  130     quicktime_indx_t *indx = &strl->indx;
  131     quicktime_indxtable_t *indx_table;
  132     quicktime_ix_t *ix;
  133     int i;
  134     int64_t offset;
  135 
  136     indx->longs_per_entry = quicktime_read_int16_le(file);
  137     indx->index_subtype = quicktime_read_char(file);
  138     indx->index_type = quicktime_read_char(file);
  139     indx->table_size = quicktime_read_int32_le(file);
  140     quicktime_read_char32(file, indx->chunk_id);
  141     quicktime_read_int32_le(file);
  142     quicktime_read_int32_le(file);
  143     quicktime_read_int32_le(file);
  144 
  145 
  146 //  file->is_odml = 1;
  147 
  148 //printf("quicktime_read_indx 1\n");
  149 /* Read indx entries */
  150     indx->table = calloc(indx->table_size, sizeof(quicktime_indxtable_t));
  151     for(i = 0; i < indx->table_size; i++)
  152     {
  153         indx_table = &indx->table[i];
  154         indx_table->index_offset = quicktime_read_int64_le(file);
  155         indx_table->index_size = quicktime_read_int32_le(file);
  156         indx_table->duration = quicktime_read_int32_le(file);
  157         offset = quicktime_position(file);
  158 
  159         indx_table->ix = calloc(indx->table_size, sizeof(quicktime_ix_t*));
  160 
  161 /* Now read the partial index */
  162         ix = indx_table->ix = calloc(1, sizeof(quicktime_ix_t));
  163         quicktime_set_position(file, indx_table->index_offset);
  164         quicktime_read_ix(file, ix);
  165         quicktime_set_position(file, offset);
  166     }
  167 //printf("quicktime_read_indx 100\n");
  168 
  169 }
  170 
  171 
  172 
  173