comparison libmpdemux/demux_mov.c @ 5206:2ca5a9bfaa98

allow sh_audio struct to be initialized by demuxer, add parsing of mp4 esds header to mov demuxer, init faad from info from mov header
author atmos4
date Tue, 19 Mar 2002 21:48:55 +0000
parents 3d558414320f
children 12f7cbbe7022
comparison
equal deleted inserted replaced
5205:47259a4f3216 5206:2ca5a9bfaa98
560 priv->tracks[priv->track_db]=trak; 560 priv->tracks[priv->track_db]=trak;
561 lschunks(demuxer,level+1,pos+len,trak); 561 lschunks(demuxer,level+1,pos+len,trak);
562 mov_build_index(trak); 562 mov_build_index(trak);
563 switch(trak->type){ 563 switch(trak->type){
564 case MOV_TRAK_AUDIO: { 564 case MOV_TRAK_AUDIO: {
565 #if 0
566 struct {
567 int16_t version; // 0 or 1 (version 1 is qt3.0+)
568 int16_t revision; // 0
569 int32_t vendor_id; // 0
570 int16_t channels; // 1 or 2 (Mono/Stereo)
571 int16_t samplesize; // 8 or 16 (8Bit/16Bit)
572 int16_t compression_id; // if version 0 then 0
573 // if version 1 and vbr then -2 else 0
574 int16_t packet_size; // 0
575 uint32_t sample_rate; // samplerate (Hz)
576 // qt3.0+ (version == 1)
577 uint32_t samples_per_packet; // 0 or num uncompressed samples in a packet
578 // if 0 below three values are also 0
579 uint32_t bytes_per_packet; // 0 or num compressed bytes for one channel
580 uint32_t bytes_per_frame; // 0 or num compressed bytes for all channels
581 // (channels * bytes_per_packet)
582 uint32_t bytes_per_sample; // 0 or size of uncompressed sample
583 // if samples_per_packet and bytes_per_packet are constant (CBR)
584 // then bytes_per_frame and bytes_per_sample must be 0 (else is VBR)
585 // ---
586 // optional additional atom-based fields
587 // ([int32_t size,int32_t type,some data ],repeat)
588 } my_stdata;
589 #endif
565 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db); 590 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db);
566 sh->format=trak->fourcc; 591 sh->format=trak->fourcc;
567 592
593 // assumptions for below table: short is 16bit, int is 32bit
594 // short values are usually one byte leftpadded by zero
595 // int values are usually two byte leftpadded by zero
568 // stdata[]: 596 // stdata[]:
569 // 8 short version 597 // 8 short version
570 // 10 short revision 598 // 10 short revision
571 // 12 int vendor_id 599 // 12 int vendor_id
572 // 16 short channels 600 // 16 short channels
577 // ---- qt3.0+ 605 // ---- qt3.0+
578 // 28 int samples_per_packet 606 // 28 int samples_per_packet
579 // 32 int bytes_per_packet 607 // 32 int bytes_per_packet
580 // 36 int bytes_per_frame 608 // 36 int bytes_per_frame
581 // 40 int bytes_per_sample 609 // 40 int bytes_per_sample
582 610 // my recoveries from .mp4 files with correct index (counting from 0):
583 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]); 611 // it's always start with padding/real start
612 // 8/ 9 short version
613 // 10/11 short revision
614 // 12/14 int vendor_id
615 // 16/17 short channels
616 // 18/19 short samplesize
617 // 20/21 short compression_id
618 // 22/23 short packet_size (XXX: this overlaps with sample_rate ?)
619 // 22/24 int sample_rate
620 // esds atom:
621 // 28/31 int atom size (bytes of int size, int type and data)
622 // 32/32 int atom type (fourc charater code -> esds)
623 // 62/63 int compressed datarate (Bits)
624
625 #define char2short(x,y) ((x[y]<<8)|x[y+1])
626 #define char2int(x,y) ((x[y]<<24)|(x[y+1]<<16)|(x[y+2]<<8)|x[y+3])
627
628 sh->samplesize=char2short(trak->stdata,18)/8;
629 sh->channels=char2short(trak->stdata,16);
630 sh->samplerate=char2short(trak->stdata,24);
631
632 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio bits: %d chans: %d\n",
633 trak->stdata[19],trak->stdata[17]);
634 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio sample rate: %d\n",
635 char2short(trak->stdata,24));
636 if((trak->stdata[9]==0) && trak->stdata_len >= 36) { // version 0 with extra atoms
637 int atom_len = char2int(trak->stdata,28);
638 switch(char2int(trak->stdata,32)) { // atom type
639 case MOV_FOURCC('e','s','d','s'):
640 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: MP4 esds audio atom found (%d)!\n", atom_len);
641 if(atom_len >= 28)
642 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio compressed datarate: %dkbit/s\n",
643 char2int(trak->stdata,62)/1000);
644 sh->i_bps=char2int(trak->stdata,62)/8;
645 break;
646 default:
647 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: unknown audio atom %c%c%c%c found (%d)!\n",
648 trak->stdata[32],trak->stdata[33],trak->stdata[34],trak->stdata[35],
649 atom_len);
650 }
651 }
584 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s\n",&trak->fourcc); 652 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s\n",&trak->fourcc);
585 #if 0 653 #if 0
586 { FILE* f=fopen("stdata.dat","wb"); 654 { FILE* f=fopen("stdata.dat","wb");
587 fwrite(trak->stdata,trak->stdata_len,1,f); 655 fwrite(trak->stdata,trak->stdata_len,1,f);
588 fclose(f); } 656 fclose(f); }