"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/avi_hdrl.c" (9 Jan 2007, 5239 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_delete_hdrl(quicktime_t *file, quicktime_hdrl_t *hdrl)
    7 {
    8     int i;
    9     for(i = 0; i < file->moov.total_tracks; i++)
   10     {
   11         quicktime_delete_strl(hdrl->strl[i]);
   12     }
   13 }
   14 
   15 
   16 void quicktime_read_hdrl(quicktime_t *file, 
   17     quicktime_hdrl_t *hdrl,
   18     quicktime_atom_t *parent_atom)
   19 {
   20     quicktime_atom_t leaf_atom;
   21     char data[4];
   22     int current_track = 0;
   23 
   24 //printf("quicktime_read_hdrl 1\n");
   25     do
   26     {
   27         quicktime_atom_read_header(file, &leaf_atom);
   28 
   29 /* Got LIST */
   30         if(quicktime_atom_is(&leaf_atom, "LIST"))
   31         {
   32             data[0] = data[1] = data[2] = data[3] = 0;
   33             quicktime_read_data(file, data, 4);
   34 
   35 /* Got strl */
   36             if(quicktime_match_32(data, "strl"))
   37             {
   38                 quicktime_strl_t *strl = 
   39                     hdrl->strl[current_track++] = 
   40                     quicktime_new_strl();
   41                 quicktime_read_strl(file, strl, &leaf_atom);
   42             }
   43         }
   44 
   45         quicktime_atom_skip(file, &leaf_atom);
   46     }while(quicktime_position(file) < parent_atom->end);
   47 
   48     quicktime_atom_skip(file, &leaf_atom);
   49 }
   50 
   51 void quicktime_init_hdrl(quicktime_t *file, quicktime_hdrl_t *hdrl)
   52 {
   53     int i;
   54     quicktime_atom_t avih_atom;
   55     int current_track;
   56 
   57 // LIST 'hdrl'
   58     quicktime_atom_write_header(file, &hdrl->atom, "LIST");
   59     quicktime_write_char32(file, "hdrl");
   60 
   61 
   62 // avih
   63     quicktime_atom_write_header(file, &avih_atom, "avih");
   64 
   65     if(file->total_vtracks)
   66         quicktime_write_int32_le(file, 
   67             (uint32_t)(1000000 / 
   68             quicktime_frame_rate(file, 0)));
   69     else
   70         quicktime_write_int32_le(file, 0);
   71 
   72     hdrl->bitrate_offset = quicktime_position(file);
   73     quicktime_write_int32_le(file, 0); /* bitrate in bytes */
   74     quicktime_write_int32_le(file, 0); /* padding */
   75     quicktime_write_int32_le(file, 
   76         AVI_TRUSTCKTYPE | 
   77         AVI_HASINDEX | 
   78         AVI_MUSTUSEINDEX | 
   79         AVI_ISINTERLEAVED); /* flags */
   80     hdrl->frames_offset = quicktime_position(file);
   81     quicktime_write_int32_le(file, 0); /* nb frames, filled later */
   82     quicktime_write_int32_le(file, 0); /* initial frame */
   83     quicktime_write_int32_le(file, file->moov.total_tracks); /* nb streams */
   84     quicktime_write_int32_le(file, 0); /* suggested buffer size */
   85 
   86     if(file->total_vtracks)
   87     {
   88         quicktime_write_int32_le(file, file->vtracks[0].track->tkhd.track_width);
   89         quicktime_write_int32_le(file, file->vtracks[0].track->tkhd.track_height);
   90     }
   91     else
   92     {
   93         quicktime_write_int32_le(file, 0);
   94         quicktime_write_int32_le(file, 0);
   95     }
   96     quicktime_write_int32_le(file, 0); /* reserved */
   97     quicktime_write_int32_le(file, 0); /* reserved */
   98     quicktime_write_int32_le(file, 0); /* reserved */
   99     quicktime_write_int32_le(file, 0); /* reserved */
  100 
  101     quicktime_atom_write_footer(file, &avih_atom);
  102 
  103 
  104 /* Write stream lists. */
  105 /* Need the track maps to get the WAV ID for audio. */
  106     current_track = 0;
  107     for(i = 0; i < file->total_vtracks; i++)
  108     {
  109         quicktime_video_map_t *video_map = &file->vtracks[i];
  110         quicktime_trak_t *trak = video_map->track;
  111         quicktime_strl_t *strl = 
  112             hdrl->strl[current_track++] = 
  113             quicktime_new_strl();
  114         quicktime_init_strl(file, 
  115             0, 
  116             video_map, 
  117             trak,
  118             strl);
  119     }
  120 
  121     for(i = 0; i < file->total_atracks; i++)
  122     {
  123         quicktime_audio_map_t *audio_map = &file->atracks[i];
  124         quicktime_trak_t *trak = audio_map->track;
  125         quicktime_strl_t *strl = 
  126             hdrl->strl[current_track++] = 
  127             quicktime_new_strl();
  128         quicktime_init_strl(file, 
  129             audio_map,
  130             0,
  131             trak,
  132             strl);
  133     }
  134 
  135 /*
  136  * for(i = 0; i < file->moov.total_tracks; i++)
  137  * {
  138  * printf("quicktime_init_hdrl 10 %d %p\n", i, file->riff[0]->hdrl.strl[i]->tag);
  139  * }
  140  */
  141 
  142 /* ODML header */
  143     quicktime_init_odml(file, hdrl);
  144     quicktime_atom_write_footer(file, &hdrl->atom);
  145 }
  146 
  147 
  148 void quicktime_finalize_hdrl(quicktime_t *file, quicktime_hdrl_t *hdrl)
  149 {
  150     int i;
  151     int64_t position = quicktime_position(file);
  152     int64_t total_frames = 0;
  153     double frame_rate = 0;
  154 
  155     for(i = 0; i < file->moov.total_tracks; i++)
  156     {
  157         quicktime_trak_t *trak = file->moov.trak[i];
  158         quicktime_strl_t *strl = hdrl->strl[i];
  159 
  160         if(trak->mdia.minf.is_video)
  161         {
  162             int length;
  163             quicktime_set_position(file, strl->length_offset);
  164             total_frames = length = quicktime_track_samples(file, trak);
  165             quicktime_write_int32_le(file, length);
  166             frame_rate = (double)trak->mdia.mdhd.time_scale /
  167                 trak->mdia.minf.stbl.stts.table[0].sample_duration;
  168         }
  169         else
  170         if(trak->mdia.minf.is_audio)
  171         {
  172             int length, samples_per_chunk;
  173             quicktime_set_position(file, strl->length_offset);
  174             length = quicktime_track_samples(file, trak);
  175             quicktime_write_int32_le(file, length);
  176             quicktime_set_position(file, strl->samples_per_chunk_offset);
  177 
  178             samples_per_chunk = quicktime_avg_chunk_samples(file, trak);
  179             quicktime_write_int32_le(file, 
  180                 samples_per_chunk);
  181             quicktime_write_int32_le(file, 
  182                 samples_per_chunk *
  183                 trak->mdia.minf.stbl.stsd.table[0].sample_rate);
  184 
  185             quicktime_set_position(file, strl->sample_size_offset);
  186             quicktime_write_int32_le(file, 
  187                 trak->mdia.minf.stbl.stsd.table[0].sample_size);
  188         }
  189     }
  190 
  191     if(total_frames)
  192     {
  193         quicktime_set_position(file, hdrl->bitrate_offset);
  194         quicktime_write_int32_le(file, 
  195             file->total_length / (total_frames / frame_rate));
  196         quicktime_set_position(file, hdrl->frames_offset);
  197         quicktime_write_int32_le(file, total_frames);
  198     }
  199 
  200     quicktime_set_position(file, position);
  201 }
  202 
  203 
  204 
  205 
  206 
  207 
  208