"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/avi_idx1.c" (9 Jan 2007, 4232 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 
    7 typedef struct
    8 {
    9     char tag[4];
   10     int32_t flags;
   11     int32_t offset;
   12     int32_t size;
   13 } avi_tag_t;
   14 
   15 
   16 
   17 static int is_keyframe(quicktime_trak_t *trak, int frame)
   18 {
   19     int i;
   20     quicktime_stss_t *stss = &trak->mdia.minf.stbl.stss;
   21     frame++;
   22     for(i = 0; i < stss->total_entries; i++)
   23     {
   24         if(stss->table[i].sample == frame) return 1;
   25     }
   26     return 0;
   27 }
   28 
   29 
   30 void quicktime_delete_idx1(quicktime_idx1_t *idx1)
   31 {
   32     if(idx1->table) free(idx1->table);
   33 }
   34 
   35 void quicktime_read_idx1(quicktime_t *file, 
   36     quicktime_riff_t *riff,
   37     quicktime_atom_t *parent_atom)
   38 {
   39     int i;
   40     quicktime_riff_t *first_riff = file->riff[0];
   41     quicktime_hdrl_t *hdrl = &first_riff->hdrl;
   42     quicktime_idx1_t *idx1 = &riff->idx1;
   43 
   44 //printf("quicktime_read_idx1 1 %llx\n", quicktime_position(file));
   45 
   46 // Allocate table.
   47     idx1->table_size = (parent_atom->end - quicktime_position(file)) / 16;
   48     idx1->table_allocation = idx1->table_size;
   49     idx1->table = calloc(sizeof(quicktime_idx1table_t), idx1->table_size);
   50 //printf("quicktime_read_idx1 10\n");
   51 
   52 // Store it in idx1 table now.
   53 // Wait for full ix table discovery before converting to stco.
   54     for(i = 0; i < idx1->table_size; i++)
   55     {
   56         quicktime_idx1table_t *idx1table = idx1->table + i;
   57 
   58         quicktime_read_data(file, idx1table->tag, 4);
   59         idx1table->flags = quicktime_read_int32_le(file);
   60         idx1table->offset = quicktime_read_int32_le(file);
   61         idx1table->size = quicktime_read_int32_le(file);
   62     }
   63 
   64 //printf("quicktime_read_idx1 100\n");
   65 
   66 
   67 
   68 
   69 
   70 
   71 
   72 }
   73 
   74 void quicktime_write_idx1(quicktime_t *file, 
   75     quicktime_idx1_t *idx1)
   76 {
   77     int i;
   78     quicktime_idx1table_t *table = idx1->table;
   79     int table_size = idx1->table_size;
   80 
   81 
   82 
   83 // Write table
   84     quicktime_atom_write_header(file, &idx1->atom, "idx1");
   85 
   86     for(i = 0; i < table_size; i++)
   87     {
   88         quicktime_idx1table_t *entry = &table[i];
   89         quicktime_write_char32(file, entry->tag);
   90         quicktime_write_int32_le(file, entry->flags);
   91         quicktime_write_int32_le(file, entry->offset);
   92         quicktime_write_int32_le(file, entry->size);
   93     }
   94 
   95 
   96     quicktime_atom_write_footer(file, &idx1->atom);
   97 }
   98 
   99 void quicktime_set_idx1_keyframe(quicktime_t *file, 
  100     quicktime_trak_t *trak,
  101     int new_keyframe)
  102 {
  103     quicktime_riff_t *riff = file->riff[0];
  104     quicktime_hdrl_t *hdrl = &riff->hdrl;
  105     quicktime_strl_t *strl = hdrl->strl[trak->tkhd.track_id - 1];
  106     char *tag = strl->tag;
  107     quicktime_idx1_t *idx1 = &riff->idx1;
  108     int i;
  109     int counter = -1;
  110 
  111 // Search through entire index for right numbered tag.
  112 // Since all the tracks are combined in the same index, this is unavoidable.
  113     for(i = 0; i < idx1->table_size; i++)
  114     {
  115         quicktime_idx1table_t *idx1_table = &idx1->table[i];
  116         if(!memcmp(idx1_table->tag, tag, 4))
  117         {
  118             counter++;
  119             if(counter == new_keyframe)
  120             {
  121                 idx1_table->flags |= AVI_KEYFRAME;
  122                 break;
  123             }
  124         }
  125     }
  126 }
  127 
  128 void quicktime_update_idx1table(quicktime_t *file, 
  129     quicktime_trak_t *trak, 
  130     int offset,
  131     int size)
  132 {
  133     quicktime_riff_t *riff = file->riff[0];
  134     quicktime_hdrl_t *hdrl = &riff->hdrl;
  135     quicktime_strl_t *strl = hdrl->strl[trak->tkhd.track_id - 1];
  136     char *tag = strl->tag;
  137     quicktime_idx1_t *idx1 = &riff->idx1;
  138     quicktime_movi_t *movi = &riff->movi;
  139     quicktime_idx1table_t *idx1_table;
  140     quicktime_stss_t *stss = &trak->mdia.minf.stbl.stss;
  141     uint32_t flags = 0;
  142     int i;
  143     int keyframe_frame = idx1->table_size + 1;
  144 
  145 // Set flag for keyframe
  146     for(i = stss->total_entries - 1; i >= 0; i--)
  147     {
  148         if(stss->table[i].sample == keyframe_frame)
  149         {
  150             flags |= AVI_KEYFRAME;
  151             break;
  152         }
  153         else
  154         if(stss->table[i].sample < keyframe_frame)
  155         {
  156             break;
  157         }
  158     }
  159 
  160 
  161 // Allocation
  162     if(idx1->table_size >= idx1->table_allocation)
  163     {
  164         quicktime_idx1table_t *old_table = idx1->table;
  165         int new_allocation = idx1->table_allocation * 2;
  166         if(new_allocation < 1) new_allocation = 1;
  167         idx1->table = calloc(1, sizeof(quicktime_idx1table_t) * new_allocation);
  168         if(old_table)
  169         {
  170             memcpy(idx1->table, old_table, sizeof(quicktime_idx1table_t) * idx1->table_size);
  171             free(old_table);
  172         }
  173         idx1->table_allocation = new_allocation;
  174     }
  175 
  176 
  177 // Appendage
  178     idx1_table = &idx1->table[idx1->table_size];
  179     memcpy(idx1_table->tag, tag, 4);
  180     idx1_table->flags = flags;
  181     idx1_table->offset = offset - 8 - movi->atom.start;
  182     idx1_table->size = size;
  183     idx1->table_size++;
  184 }
  185 
  186 
  187 
  188