~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to libmpdemux/aviheader.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:
20
20
 
21
21
static MainAVIHeader avih;
22
22
 
23
 
extern void print_avih(MainAVIHeader *h);
24
 
extern void print_avih_flags(MainAVIHeader *h);
25
 
extern void print_strh(AVIStreamHeader *h);
26
 
extern void print_wave_header(WAVEFORMATEX *h);
27
 
extern void print_video_header(BITMAPINFOHEADER *h);
28
 
extern void print_index(AVIINDEXENTRY *idx,int idx_size);
29
 
extern void print_avistdindex_chunk(avistdindex_chunk *h);
30
 
extern void print_avisuperindex_chunk(avisuperindex_chunk *h);
31
 
extern void print_vprp(VideoPropHeader *vprp);
 
23
extern void print_avih(MainAVIHeader *h, int verbose_level);
 
24
extern void print_avih_flags(MainAVIHeader *h, int verbose_level);
 
25
extern void print_strh(AVIStreamHeader *h, int verbose_level);
 
26
extern void print_wave_header(WAVEFORMATEX *h, int verbose_level);
 
27
extern void print_video_header(BITMAPINFOHEADER *h, int verbose_level);
 
28
extern void print_index(AVIINDEXENTRY *idx,int idx_size, int verbose_level);
 
29
extern void print_avistdindex_chunk(avistdindex_chunk *h, int verbose_level);
 
30
extern void print_avisuperindex_chunk(avisuperindex_chunk *h, int verbose_level);
 
31
extern void print_vprp(VideoPropHeader *vprp, int verbose_level);
32
32
 
33
33
static int odml_get_vstream_id(int id, unsigned char res[])
34
34
{
185
185
      stream_read(demuxer->stream,(char*) &avih,MIN(size2,sizeof(avih)));
186
186
      le2me_MainAVIHeader(&avih); // swap to machine endian
187
187
      chunksize-=MIN(size2,sizeof(avih));
188
 
      if(verbose>0) print_avih(&avih); // else print_avih_flags(&avih);
 
188
      if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_avih(&avih,MSGL_V); // else print_avih_flags(&avih,MSGL_V);
189
189
      break;
190
190
    case ckidSTREAMHEADER: {      // read 'strh'
191
191
      AVIStreamHeader h;
202
202
        memcpy(&sh_audio->audio,&h,sizeof(h));
203
203
      }
204
204
      last_fccType=h.fccType;
205
 
      if(verbose>=1) print_strh(&h);
 
205
      if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_strh(&h,MSGL_V);
206
206
      break; }
207
207
    case mmioFOURCC('i', 'n', 'd', 'x'): {
208
208
      uint32_t i;
209
 
      unsigned msize = 0;
210
209
      avisuperindex_chunk *s;
 
210
      if(chunksize<=24){
 
211
        break;
 
212
      }
211
213
      priv->suidx_size++;
212
 
      priv->suidx = realloc(priv->suidx, priv->suidx_size * sizeof (avisuperindex_chunk));
 
214
      priv->suidx = realloc_struct(priv->suidx, priv->suidx_size, sizeof (avisuperindex_chunk));
213
215
      s = &priv->suidx[priv->suidx_size-1];
214
216
 
215
217
      chunksize-=24;
223
225
      stream_read(demuxer->stream, (char *)s->dwReserved, 3*4);
224
226
      memset(s->dwReserved, 0, 3*4);
225
227
          
226
 
      print_avisuperindex_chunk(s);
 
228
      print_avisuperindex_chunk(s,MSGL_V);
 
229
      
 
230
      if( ((chunksize/4)/s->wLongsPerEntry) < s->nEntriesInUse){
 
231
        mp_msg (MSGT_HEADER, MSGL_WARN, "Broken super index chunk\n");
 
232
        s->nEntriesInUse = (chunksize/4)/s->wLongsPerEntry;
 
233
      }
227
234
 
228
 
      msize = sizeof (uint32_t) * s->wLongsPerEntry * s->nEntriesInUse;
229
 
      s->aIndex = malloc(msize);
230
 
      memset (s->aIndex, 0, msize);
231
 
      s->stdidx = malloc (s->nEntriesInUse * sizeof (avistdindex_chunk));
232
 
      memset (s->stdidx, 0, s->nEntriesInUse * sizeof (avistdindex_chunk));
 
235
      // Check and fix this useless crap
 
236
      if(s->wLongsPerEntry != sizeof (avisuperindex_entry)/4) {
 
237
          mp_msg (MSGT_HEADER, MSGL_WARN, "Broken super index chunk size: %u\n",s->wLongsPerEntry);
 
238
          s->wLongsPerEntry = sizeof(avisuperindex_entry)/4;
 
239
      }
 
240
      s->aIndex = calloc(s->nEntriesInUse, sizeof (avisuperindex_entry));
 
241
      s->stdidx = calloc(s->nEntriesInUse, sizeof (avistdindex_chunk));
233
242
 
234
243
      // now the real index of indices
235
244
      for (i=0; i<s->nEntriesInUse; i++) {
254
263
        // fixup MS-RLE header (seems to be broken for <256 color files)
255
264
        if(sh_video->bih->biCompression<=1 && sh_video->bih->biSize==40)
256
265
            sh_video->bih->biSize=chunksize;
257
 
        if(verbose>=1) print_video_header(sh_video->bih);
 
266
        if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh_video->bih,MSGL_V);
258
267
        chunksize=0;
259
268
//        sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
260
269
//        sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
309
318
            sh_audio->wf=realloc(sh_audio->wf, sizeof(WAVEFORMATEX)+sh_audio->wf->cbSize);
310
319
        }
311
320
        chunksize=0;
312
 
        if(verbose>=1) print_wave_header(sh_audio->wf);
 
321
        if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf,MSGL_V);
313
322
        ++priv->audio_streams;
314
323
//        if(demuxer->audio->id==-1) demuxer->audio->id=stream_id;
315
324
      }
332
341
        if (sh_video) {
333
342
                sh_video->aspect = GET_AVI_ASPECT(vprp->dwFrameAspectRatio);
334
343
        }
335
 
        if(verbose>=1) print_vprp(vprp);
 
344
        if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_vprp(vprp,MSGL_V);
336
345
        free(vprp);
337
346
        break;
338
347
    }
368
377
        entry->dwFlags&=0xffff;
369
378
      }
370
379
      chunksize-=priv->idx_size<<4;
371
 
      if(verbose>=2) print_index(priv->idx,priv->idx_size);
 
380
      if( mp_msg_test(MSGT_HEADER,MSGL_DBG2) ) print_index(priv->idx,priv->idx_size,MSGL_DBG2);
372
381
    }
373
382
    break;
374
383
    /* added May 2002 */
432
441
    priv->isodml = 1;
433
442
}
434
443
 
435
 
if (priv->isodml && (index_mode==-1 || index_mode==0)) {
 
444
if (priv->isodml && (index_mode==-1 || index_mode==0 || index_mode==1)) {
436
445
    int i, j, k;
437
446
    int safety=1000;
438
447
 
465
474
            }
466
475
 
467
476
            le2me_AVISTDIDXCHUNK(&cx->stdidx[j]);
468
 
            print_avistdindex_chunk(&cx->stdidx[j]);
 
477
            print_avistdindex_chunk(&cx->stdidx[j],MSGL_V);
469
478
            priv->idx_size += cx->stdidx[j].nEntriesInUse;
470
479
            cx->stdidx[j].aIndex = malloc(cx->stdidx[j].nEntriesInUse*sizeof(avistdindex_entry));
471
480
            stream_read(demuxer->stream, (char *)cx->stdidx[j].aIndex, 
539
548
        }
540
549
    }
541
550
 
542
 
    if (verbose>=2) print_index(priv->idx, priv->idx_size);
 
551
    if ( mp_msg_test(MSGT_HEADER,MSGL_DBG2) ) print_index(priv->idx, priv->idx_size,MSGL_DBG2);
543
552
 
544
553
    demuxer->movi_end=demuxer->stream->end_pos;
545
554
 
636
645
    
637
646
    c=stream_read_dword(demuxer->stream);
638
647
 
 
648
    if(!len) idx->dwFlags&=~AVIIF_KEYFRAME;
 
649
 
639
650
    // Fix keyframes for DivX files:
640
651
    if(idxfix_divx)
641
652
      if(avi_stream_id(id)==idxfix_videostream){
677
688
  }
678
689
  priv->idx_size=priv->idx_pos;
679
690
  mp_msg(MSGT_HEADER,MSGL_INFO,MSGTR_MPDEMUX_AVIHDR_IdxGeneratedForHowManyChunks,priv->idx_size);
680
 
  if(verbose>=2) print_index(priv->idx,priv->idx_size);
 
691
  if( mp_msg_test(MSGT_HEADER,MSGL_DBG2) ) print_index(priv->idx,priv->idx_size,MSGL_DBG2);
681
692
 
682
693
  /* Write generated index to a file */
683
694
  if (index_file_save) {