diff options
author | 2005-05-12 17:35:58 +0000 | |
---|---|---|
committer | 2005-05-12 17:35:58 +0000 | |
commit | 3d450d038916ebc7ab4673a246086b1bb5042a9e (patch) | |
tree | 1d0100cb842e0144c28f7195cd262f64e3eac726 /libmpdemux | |
parent | 4515c02ea4caf7742edf3ae4c9cd226f4079ff1b (diff) |
vorbis extradata is now passed from demuxer to decoder in matroska's way
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15421 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r-- | libmpdemux/demux_mkv.c | 51 | ||||
-rw-r--r-- | libmpdemux/demux_ogg.c | 83 |
2 files changed, 86 insertions, 48 deletions
diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index 7bba3b4d95..3d27043add 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -1781,48 +1781,8 @@ demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track) track->a_formattag = mmioFOURCC('M', 'P', '4', 'A'); else if (!strcmp(track->codec_id, MKV_A_VORBIS)) { - unsigned char *c; - uint32_t offset, length; - if (track->private_data == NULL) return 1; - - c = (unsigned char *) track->private_data; - if (*c != 2) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not " - "contain valid headers.\n"); - return 1; - } - - offset = 1; - for (i=0; i < 2; i++) - { - length = 0; - while (c[offset] == (unsigned char) 0xFF - && length < track->private_size) - { - length += 255; - offset++; - } - if (offset >= (track->private_size - 1)) - { - mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track " - "does not contain valid headers.\n"); - return 1; - } - length += c[offset]; - offset++; - track->header_sizes[i] = length; - } - - track->headers[0] = &c[offset]; - track->headers[1] = &c[offset + track->header_sizes[0]]; - track->headers[2] = &c[offset + track->header_sizes[0] + - track->header_sizes[1]]; - track->header_sizes[2] = track->private_size - offset - - track->header_sizes[0] - track->header_sizes[1]; - track->a_formattag = mmioFOURCC('v', 'r', 'b', 's'); } else if (!strcmp(track->codec_id, MKV_A_QDMC)) @@ -1954,14 +1914,9 @@ demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track) } else if (track->a_formattag == mmioFOURCC('v', 'r', 'b', 's')) /* VORBIS */ { - for (i=0; i < 3; i++) - { - dp = new_demux_packet (track->header_sizes[i]); - memcpy (dp->buffer,track->headers[i],track->header_sizes[i]); - dp->pts = 0; - dp->flags = 0; - ds_add_packet (demuxer->audio, dp); - } + sh_a->wf->cbSize = track->private_size; + sh_a->wf = (WAVEFORMATEX*)realloc(sh_a->wf, sizeof(WAVEFORMATEX) + sh_a->wf->cbSize); + memcpy((unsigned char *) (sh_a->wf+1), track->private_data, sh_a->wf->cbSize); } else if (track->private_size >= sizeof(real_audio_v4_props_t) && !strncmp (track->codec_id, MKV_A_REALATRC, 7)) diff --git a/libmpdemux/demux_ogg.c b/libmpdemux/demux_ogg.c index d1a5fbd72d..7bf8c72b88 100644 --- a/libmpdemux/demux_ogg.c +++ b/libmpdemux/demux_ogg.c @@ -736,6 +736,86 @@ char *demux_ogg_sub_lang(demuxer_t *demuxer, int index) { void demux_close_ogg(demuxer_t* demuxer); +static inline unsigned int store_ughvlc(unsigned char *s, unsigned int v) +{ + unsigned int n = 0; + + while(v >= 0xff) + { + *s++ = 0xff; + v -= 0xff; + n++; + } + *s = v; + n++; + + return n; +} + +static void fixup_vorbis_wf(sh_audio_t *sh) +{ + int i, k, offset; + ogg_packet op[3]; + unsigned char *buf[3]; + unsigned char *ptr; + + for(i = 0; i < 3; i++) { + op[i].bytes = ds_get_packet(sh->ds, &(op[i].packet)); + mp_msg(MSGT_DEMUX,MSGL_V, "fixup_vorbis_wf: i=%d, size=%d\n", i, op[i].bytes); + if(op[i].bytes < 0) { + mp_msg(MSGT_DEMUX,MSGL_ERR,"Ogg demuxer error!, fixup_vorbis_wf: bad packet n. %d\n", i); + return; + } + buf[i] = malloc(op[i].bytes); + if(!buf[i]) + return; + memcpy(buf[i], op[i].packet, op[i].bytes); + } + + sh->wf = (WAVEFORMATEX*)calloc(1, sizeof(WAVEFORMATEX) + op[0].bytes + op[1].bytes + op[2].bytes + 64); + ptr = (unsigned char*) (sh->wf+1); + + ptr[0] = 2; + offset = 1; + offset += store_ughvlc(&ptr[offset], op[0].bytes); + mp_msg(MSGT_DEMUX,MSGL_V,"demux_ogg, offset after 1st len = %d\n", offset); + offset += store_ughvlc(&ptr[offset], op[1].bytes); + mp_msg(MSGT_DEMUX,MSGL_V,"demux_ogg, offset after 2nd len = %d\n", offset); + for(i = 0; i < 3; i++) { + mp_msg(MSGT_DEMUX,MSGL_V,"demux_ogg, i=%d\n", op[i].bytes, offset, i); + memcpy(&ptr[offset], buf[i], op[i].bytes); + offset += op[i].bytes; + } + sh->wf->cbSize = offset; + mp_msg(MSGT_DEMUX,MSGL_V, "demux_ogg, extradata size: %d\n", sh->wf->cbSize); + sh->wf = (WAVEFORMATEX*)realloc(sh->wf, sizeof(WAVEFORMATEX) + sh->wf->cbSize); + + if(op[0].bytes >= 29) { + unsigned int br, nombr, minbr, maxbr; + ptr = buf[0]; + sh->channels = ptr[11]; + sh->samplerate = sh->wf->nSamplesPerSec = get_uint32(&ptr[12]); + maxbr = get_uint32(&ptr[16]); //max + nombr = get_uint32(&ptr[20]); //nominal + minbr = get_uint32(&ptr[24]); //minimum + br = maxbr / 8; + if(!br) + br = nombr / 8; + if(!br) + br = minbr / 8; + sh->wf->nAvgBytesPerSec = br; + sh->wf->wBitsPerSample = 16; + sh->samplesize = (sh->wf->wBitsPerSample+7)/8; + + 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", + sh->channels, sh->samplerate, sh->wf->nAvgBytesPerSec, maxbr, nombr, minbr); + } + free(buf[2]); + free(buf[1]); + free(buf[0]); +} + + /// Open an ogg physical stream int demux_ogg_open(demuxer_t* demuxer) { ogg_demuxer_t* ogg_d; @@ -1107,6 +1187,9 @@ int demux_ogg_open(demuxer_t* demuxer) { 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":""); + if(sh_a->format == FOURCC_VORBIS) + fixup_vorbis_wf(sh_a); + return 1; err_out: |