Mercurial > mplayer.hg
comparison libmpdemux/demux_ogg.c @ 15420:f3cf481bbcda
vorbis extradata is now passed from demuxer to decoder in matroska's way
author | nicodvb |
---|---|
date | Thu, 12 May 2005 17:35:58 +0000 |
parents | 1568ad46dc78 |
children | 9ac14c8b99b3 |
comparison
equal
deleted
inserted
replaced
15419:da39fe11c872 | 15420:f3cf481bbcda |
---|---|
733 ogg_demuxer_t *ogg_d = (ogg_demuxer_t *)demuxer->priv; | 733 ogg_demuxer_t *ogg_d = (ogg_demuxer_t *)demuxer->priv; |
734 return (index < 0) ? NULL : (index >= ogg_d->n_text) ? NULL : ogg_d->text_langs[index]; | 734 return (index < 0) ? NULL : (index >= ogg_d->n_text) ? NULL : ogg_d->text_langs[index]; |
735 } | 735 } |
736 | 736 |
737 void demux_close_ogg(demuxer_t* demuxer); | 737 void demux_close_ogg(demuxer_t* demuxer); |
738 | |
739 static inline unsigned int store_ughvlc(unsigned char *s, unsigned int v) | |
740 { | |
741 unsigned int n = 0; | |
742 | |
743 while(v >= 0xff) | |
744 { | |
745 *s++ = 0xff; | |
746 v -= 0xff; | |
747 n++; | |
748 } | |
749 *s = v; | |
750 n++; | |
751 | |
752 return n; | |
753 } | |
754 | |
755 static void fixup_vorbis_wf(sh_audio_t *sh) | |
756 { | |
757 int i, k, offset; | |
758 ogg_packet op[3]; | |
759 unsigned char *buf[3]; | |
760 unsigned char *ptr; | |
761 | |
762 for(i = 0; i < 3; i++) { | |
763 op[i].bytes = ds_get_packet(sh->ds, &(op[i].packet)); | |
764 mp_msg(MSGT_DEMUX,MSGL_V, "fixup_vorbis_wf: i=%d, size=%d\n", i, op[i].bytes); | |
765 if(op[i].bytes < 0) { | |
766 mp_msg(MSGT_DEMUX,MSGL_ERR,"Ogg demuxer error!, fixup_vorbis_wf: bad packet n. %d\n", i); | |
767 return; | |
768 } | |
769 buf[i] = malloc(op[i].bytes); | |
770 if(!buf[i]) | |
771 return; | |
772 memcpy(buf[i], op[i].packet, op[i].bytes); | |
773 } | |
774 | |
775 sh->wf = (WAVEFORMATEX*)calloc(1, sizeof(WAVEFORMATEX) + op[0].bytes + op[1].bytes + op[2].bytes + 64); | |
776 ptr = (unsigned char*) (sh->wf+1); | |
777 | |
778 ptr[0] = 2; | |
779 offset = 1; | |
780 offset += store_ughvlc(&ptr[offset], op[0].bytes); | |
781 mp_msg(MSGT_DEMUX,MSGL_V,"demux_ogg, offset after 1st len = %d\n", offset); | |
782 offset += store_ughvlc(&ptr[offset], op[1].bytes); | |
783 mp_msg(MSGT_DEMUX,MSGL_V,"demux_ogg, offset after 2nd len = %d\n", offset); | |
784 for(i = 0; i < 3; i++) { | |
785 mp_msg(MSGT_DEMUX,MSGL_V,"demux_ogg, i=%d\n", op[i].bytes, offset, i); | |
786 memcpy(&ptr[offset], buf[i], op[i].bytes); | |
787 offset += op[i].bytes; | |
788 } | |
789 sh->wf->cbSize = offset; | |
790 mp_msg(MSGT_DEMUX,MSGL_V, "demux_ogg, extradata size: %d\n", sh->wf->cbSize); | |
791 sh->wf = (WAVEFORMATEX*)realloc(sh->wf, sizeof(WAVEFORMATEX) + sh->wf->cbSize); | |
792 | |
793 if(op[0].bytes >= 29) { | |
794 unsigned int br, nombr, minbr, maxbr; | |
795 ptr = buf[0]; | |
796 sh->channels = ptr[11]; | |
797 sh->samplerate = sh->wf->nSamplesPerSec = get_uint32(&ptr[12]); | |
798 maxbr = get_uint32(&ptr[16]); //max | |
799 nombr = get_uint32(&ptr[20]); //nominal | |
800 minbr = get_uint32(&ptr[24]); //minimum | |
801 br = maxbr / 8; | |
802 if(!br) | |
803 br = nombr / 8; | |
804 if(!br) | |
805 br = minbr / 8; | |
806 sh->wf->nAvgBytesPerSec = br; | |
807 sh->wf->wBitsPerSample = 16; | |
808 sh->samplesize = (sh->wf->wBitsPerSample+7)/8; | |
809 | |
810 mp_msg(MSGT_DEMUX,MSGL_V,"demux_ogg, vorbis stream features are: channels: %d, srate: %d, bitrate: %d, max: %u, nominal: %u, min: %u\n", | |
811 sh->channels, sh->samplerate, sh->wf->nAvgBytesPerSec, maxbr, nombr, minbr); | |
812 } | |
813 free(buf[2]); | |
814 free(buf[1]); | |
815 free(buf[0]); | |
816 } | |
817 | |
738 | 818 |
739 /// Open an ogg physical stream | 819 /// Open an ogg physical stream |
740 int demux_ogg_open(demuxer_t* demuxer) { | 820 int demux_ogg_open(demuxer_t* demuxer) { |
741 ogg_demuxer_t* ogg_d; | 821 ogg_demuxer_t* ogg_d; |
742 stream_t *s; | 822 stream_t *s; |
1104 demuxer->seekable = 1; | 1184 demuxer->seekable = 1; |
1105 demux_ogg_scan_stream(demuxer); | 1185 demux_ogg_scan_stream(demuxer); |
1106 } | 1186 } |
1107 | 1187 |
1108 mp_msg(MSGT_DEMUX,MSGL_V,"Ogg demuxer : found %d audio stream%s, %d video stream%s and %d text stream%s\n",n_audio,n_audio>1?"s":"",n_video,n_video>1?"s":"",ogg_d->n_text,ogg_d->n_text>1?"s":""); | 1188 mp_msg(MSGT_DEMUX,MSGL_V,"Ogg demuxer : found %d audio stream%s, %d video stream%s and %d text stream%s\n",n_audio,n_audio>1?"s":"",n_video,n_video>1?"s":"",ogg_d->n_text,ogg_d->n_text>1?"s":""); |
1189 | |
1190 if(sh_a->format == FOURCC_VORBIS) | |
1191 fixup_vorbis_wf(sh_a); | |
1109 | 1192 |
1110 return 1; | 1193 return 1; |
1111 | 1194 |
1112 err_out: | 1195 err_out: |
1113 return 0; | 1196 return 0; |