~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to libmpdemux/muxer_avi.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:47:54 UTC
  • Revision ID: siretart@tauware.de-20060708084754-c3ff228cc9c2d8de
upgrade to pre8

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
    s->priv=si=malloc(sizeof(struct avi_stream_info));
110
110
    memset(si,0,sizeof(struct avi_stream_info));
111
111
    si->idxsize=256;
112
 
    si->idx=malloc(sizeof(struct avi_odmlidx_entry)*si->idxsize);
 
112
    si->idx=calloc(si->idxsize, sizeof(struct avi_odmlidx_entry));
113
113
    si->riffofssize=16;
114
 
    si->riffofs=malloc(sizeof(off_t)*(si->riffofssize+1));
 
114
    si->riffofs=calloc((si->riffofssize+1), sizeof(off_t));
115
115
    memset(si->riffofs, 0, sizeof(off_t)*si->riffofssize);
116
116
 
117
117
    switch(type){
174
174
    vsi->riffofspos++;
175
175
    if (vsi->riffofspos>=vsi->riffofssize) {
176
176
        vsi->riffofssize+=16;
177
 
        vsi->riffofs=realloc(vsi->riffofs,sizeof(off_t)*(vsi->riffofssize+1));
 
177
        vsi->riffofs=realloc_struct(vsi->riffofs,(vsi->riffofssize+1),sizeof(off_t));
178
178
    }
179
179
    vsi->riffofs[vsi->riffofspos] = ftello(f);
180
180
 
191
191
 
192
192
static void avifile_write_header(muxer_t *muxer);
193
193
 
194
 
static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
 
194
static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
195
195
    off_t rifflen;
196
196
    muxer_t *muxer=s->muxer;
197
197
    struct avi_stream_info *si = s->priv;
220
220
        // add to the traditional index:
221
221
        if(muxer->idx_pos>=muxer->idx_size){
222
222
            muxer->idx_size+=256; // 4kB
223
 
            muxer->idx=realloc(muxer->idx,16*muxer->idx_size);
 
223
            muxer->idx=realloc_struct(muxer->idx,muxer->idx_size,16);
224
224
        }
225
225
        muxer->idx[muxer->idx_pos].ckid=s->ckid;
226
226
        muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe?
232
232
    // add to odml index
233
233
    if(si->idxpos>=si->idxsize){
234
234
        si->idxsize+=256;
235
 
        si->idx=realloc(si->idx,sizeof(*si->idx)*si->idxsize);
 
235
        si->idx=realloc_struct(si->idx,si->idxsize,sizeof(*si->idx));
236
236
    }
237
237
    si->idx[si->idxpos].flags=(flags&AVIIF_KEYFRAME)?0:ODML_NOTKEYFRAME;
238
238
    si->idx[si->idxpos].ofs=muxer->file_end;
285
285
    mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: vprp aspect is %d:%d.\n", aspect >> 16, aspect & 0xffff);
286
286
  }
287
287
 
 
288
  /* deal with stream delays */
 
289
  for (i = 0; muxer->streams[i] && i < MUXER_MAX_STREAMS; ++i) {
 
290
      muxer_stream_t *s = muxer->streams[i];
 
291
      if (s->type == MUXER_TYPE_AUDIO && muxer->audio_delay_fix > 0.0) {
 
292
          s->h.dwStart = muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale;
 
293
          mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_SettingAudioDelay, (float)s->h.dwStart * s->h.dwScale/s->h.dwRate);
 
294
      }
 
295
      if (s->type == MUXER_TYPE_VIDEO && muxer->audio_delay_fix < 0.0) {
 
296
          s->h.dwStart = -muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale;
 
297
          mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_SettingVideoDelay, (float)s->h.dwStart * s->h.dwScale/s->h.dwRate);
 
298
      }
 
299
  }
 
300
  
288
301
  if (isodml) {
289
302
      unsigned int rifflen, movilen;
290
303
      int i;
586
599
                i, entries_per_subidx, si->superidxpos);
587
600
 
588
601
    si->superidxsize = si->superidxpos;
589
 
    si->superidx = malloc(sizeof(*si->superidx) * si->superidxsize);
 
602
    si->superidx = calloc(si->superidxsize, sizeof(*si->superidx));
590
603
    memset(si->superidx, 0, sizeof(*si->superidx) * si->superidxsize);
591
604
 
592
605
    idxpos = 0;
652
665
  }
653
666
}
654
667
 
 
668
static void avifile_fix_parameters(muxer_stream_t *s){
 
669
  /* adjust audio_delay_fix according to individual stream delay */
 
670
  if (s->type == MUXER_TYPE_AUDIO)
 
671
    s->muxer->audio_delay_fix -= (float)s->decoder_delay * s->h.dwScale/s->h.dwRate;
 
672
  if (s->type == MUXER_TYPE_VIDEO)
 
673
    s->muxer->audio_delay_fix += (float)s->decoder_delay * s->h.dwScale/s->h.dwRate;
 
674
}
 
675
 
655
676
int muxer_init_muxer_avi(muxer_t *muxer){
656
677
  muxer->cont_new_stream = &avifile_new_stream;
657
678
  muxer->cont_write_chunk = &avifile_write_chunk;
658
679
  muxer->cont_write_header = &avifile_write_header;
659
680
  muxer->cont_write_index = &avifile_write_index;
 
681
  muxer->fix_stream_parameters = &avifile_fix_parameters;
660
682
  return 1;
661
683
}