Mercurial > mplayer.hg
annotate libmpdemux/demux_mpc.c @ 19540:70a5e89ea4cd
Get rid of demux_aid_vid_mismatch mess.
author | reimar |
---|---|
date | Sat, 26 Aug 2006 19:17:04 +0000 |
parents | 5c8acc972551 |
children | 1767c271d710 |
rev | line source |
---|---|
16074
f482bbb5fad9
Allow the ffmpeg people to use this code if they want.
reimar
parents:
15958
diff
changeset
|
1 /** |
f482bbb5fad9
Allow the ffmpeg people to use this code if they want.
reimar
parents:
15958
diff
changeset
|
2 * Demuxer for Musepack v7 bitstream |
f482bbb5fad9
Allow the ffmpeg people to use this code if they want.
reimar
parents:
15958
diff
changeset
|
3 * by Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de> |
f482bbb5fad9
Allow the ffmpeg people to use this code if they want.
reimar
parents:
15958
diff
changeset
|
4 * This code may be be relicensed under the terms of the GNU LGPL when it |
16093 | 5 * becomes part of the FFmpeg project (ffmpeg.org) |
16074
f482bbb5fad9
Allow the ffmpeg people to use this code if they want.
reimar
parents:
15958
diff
changeset
|
6 */ |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
7 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
8 #include "config.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
9 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
10 #include <stdlib.h> |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
11 #include <stdio.h> |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
12 #include <string.h> |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
13 #include "mp_msg.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
14 #include "bswap.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
15 #include "stream.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
16 #include "demuxer.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
17 #include "stheader.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
18 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
19 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
20 #define HDR_SIZE (6 * 4) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
21 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
22 typedef struct da_priv { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
23 float last_pts; |
16745 | 24 float pts_per_packet; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
25 uint32_t dword; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
26 int pos; |
16612 | 27 float length; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
28 } da_priv_t; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
29 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
30 static uint32_t get_bits(da_priv_t* priv, stream_t* s, int bits) { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
31 uint32_t out = priv->dword; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
32 uint32_t mask = (1 << bits) - 1; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
33 priv->pos += bits; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
34 if (priv->pos < 32) { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
35 out >>= (32 - priv->pos); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
36 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
37 else { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
38 stream_read(s, (void *)&priv->dword, 4); |
16149 | 39 priv->dword = le2me_32(priv->dword); |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
40 priv->pos -= 32; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
41 if (priv->pos) { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
42 out <<= priv->pos; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
43 out |= priv->dword >> (32 - priv->pos); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
44 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
45 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
46 return out & mask; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
47 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
48 |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
49 static int demux_mpc_check(demuxer_t* demuxer) { |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
50 stream_t *s = demuxer->stream; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
51 uint8_t hdr[HDR_SIZE]; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
52 int i; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
53 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
54 if (stream_read(s, hdr, HDR_SIZE) != HDR_SIZE) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
55 return 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
56 for (i = 0; i < 30000 && !s->eof; i++) { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
57 if (hdr[0] == 'M' && hdr[1] == 'P' && hdr[2] == '+') |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
58 break; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
59 memmove(hdr, &hdr[1], HDR_SIZE - 1); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
60 stream_read(s, &hdr[HDR_SIZE - 1], 1); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
61 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
62 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
63 if (hdr[0] != 'M' || hdr[1] != 'P' || hdr[2] != '+') |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
64 return 0; |
16414 | 65 demuxer->movi_start = stream_tell(s) - HDR_SIZE; |
66 demuxer->movi_end = s->end_pos; | |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
67 demuxer->priv = malloc(HDR_SIZE); |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
68 memcpy(demuxer->priv, hdr, HDR_SIZE); |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
69 return DEMUXER_TYPE_MPC; |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
70 } |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
71 |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
72 static demuxer_t *demux_mpc_open(demuxer_t* demuxer) { |
16612 | 73 float seconds = 0; |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
74 stream_t *s = demuxer->stream; |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
75 sh_audio_t* sh_audio; |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
76 da_priv_t* priv = demuxer->priv; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
77 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
78 sh_audio = new_sh_audio(demuxer,0); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
79 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
80 { |
18885 | 81 char *wf = calloc(1, sizeof(WAVEFORMATEX) + HDR_SIZE); |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
82 char *header = &wf[sizeof(WAVEFORMATEX)]; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
83 const int freqs[4] = {44100, 48000, 37800, 32000}; |
16414 | 84 int frames; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
85 sh_audio->format = mmioFOURCC('M', 'P', 'C', ' '); |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
86 memcpy(header, priv, HDR_SIZE); |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
87 free(priv); |
16414 | 88 frames = header[4] | header[5] << 8 | header[6] << 16 | header[7] << 24; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
89 sh_audio->wf = (WAVEFORMATEX *)wf; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
90 sh_audio->wf->wFormatTag = sh_audio->format; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
91 sh_audio->wf->nChannels = 2; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
92 sh_audio->wf->nSamplesPerSec = freqs[header[10] & 3]; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
93 sh_audio->wf->nBlockAlign = 32 * 36; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
94 sh_audio->wf->wBitsPerSample = 16; |
16612 | 95 seconds = 1152 * frames / (float)sh_audio->wf->nSamplesPerSec; |
96 if (demuxer->movi_end > demuxer->movi_start && seconds > 1) | |
16414 | 97 sh_audio->wf->nAvgBytesPerSec = (demuxer->movi_end - demuxer->movi_start) / seconds; |
98 else | |
99 sh_audio->wf->nAvgBytesPerSec = 32 * 1024; // dummy to make mencoder not hang | |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
100 sh_audio->wf->cbSize = HDR_SIZE; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
101 demuxer->movi_start = stream_tell(s); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
102 demuxer->movi_end = s->end_pos; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
103 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
104 |
18885 | 105 priv = malloc(sizeof(da_priv_t)); |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
106 priv->last_pts = -1; |
16745 | 107 priv->pts_per_packet = (32 * 36) / (float)sh_audio->wf->nSamplesPerSec; |
16612 | 108 priv->length = seconds; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
109 priv->dword = 0; |
16743 | 110 priv->pos = 32; // empty bit buffer |
111 get_bits(priv, s, 8); // discard first 8 bits | |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
112 demuxer->priv = priv; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
113 demuxer->audio->id = 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
114 demuxer->audio->sh = sh_audio; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
115 sh_audio->ds = demuxer->audio; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
116 sh_audio->samplerate = sh_audio->wf->nSamplesPerSec; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
117 sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
118 sh_audio->audio.dwSampleSize = 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
119 sh_audio->audio.dwScale = 32 * 36; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
120 sh_audio->audio.dwRate = sh_audio->samplerate; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
121 |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
122 return demuxer; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
123 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
124 |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
125 static int demux_mpc_fill_buffer(demuxer_t *demux, demux_stream_t *ds) { |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
126 int l; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
127 int bit_len; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
128 demux_packet_t* dp; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
129 sh_audio_t* sh_audio = ds->sh; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
130 da_priv_t* priv = demux->priv; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
131 stream_t* s = demux->stream; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
132 sh_audio = ds->sh; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
133 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
134 if (s->eof) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
135 return 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
136 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
137 bit_len = get_bits(priv, s, 20); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
138 dp = new_demux_packet((bit_len + 7) / 8); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
139 for (l = 0; l < (bit_len / 8); l++) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
140 dp->buffer[l] = get_bits(priv, s, 8); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
141 bit_len %= 8; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
142 if (bit_len) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
143 dp->buffer[l] = get_bits(priv, s, bit_len) << (8 - bit_len); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
144 if (priv->last_pts < 0) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
145 priv->last_pts = 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
146 else |
16745 | 147 priv->last_pts += priv->pts_per_packet; |
18710
c528c6c518f1
Clean up audio pts handling, make audio pts tracking in the audio-only
uau
parents:
18707
diff
changeset
|
148 dp->pts = priv->last_pts; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
149 ds_add_packet(ds, dp); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
150 return 1; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
151 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
152 |
17636 | 153 static void demux_mpc_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ |
16745 | 154 sh_audio_t* sh_audio = demuxer->audio->sh; |
155 da_priv_t* priv = demuxer->priv; | |
156 stream_t* s = demuxer->stream; | |
157 float target = rel_seek_secs; | |
158 if (flags & 2) | |
159 target *= priv->length; | |
160 if (!(flags & 1)) | |
161 target += priv->last_pts; | |
162 if (target < priv->last_pts) { | |
163 stream_seek(s, demuxer->movi_start); | |
164 priv->pos = 32; // empty bit buffer | |
165 get_bits(priv, s, 8); // discard first 8 bits | |
166 priv->last_pts = 0; | |
167 } | |
168 while (target > priv->last_pts) { | |
169 int bit_len = get_bits(priv, s, 20); | |
170 if (bit_len > 32) { | |
171 stream_skip(s, bit_len / 32 * 4 - 4); | |
172 get_bits(priv, s, 32); // make sure dword is reloaded | |
173 } | |
174 get_bits(priv, s, bit_len % 32); | |
175 priv->last_pts += priv->pts_per_packet; | |
176 if (s->eof) break; | |
177 } | |
178 if (!sh_audio) return; | |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
179 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
180 |
16175 | 181 static void demux_close_mpc(demuxer_t* demuxer) { |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
182 da_priv_t* priv = demuxer->priv; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
183 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
184 if(!priv) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
185 return; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
186 free(priv); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
187 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
188 |
16175 | 189 static int demux_mpc_control(demuxer_t *demuxer,int cmd, void *arg){ |
16612 | 190 da_priv_t* priv = demuxer->priv; |
191 switch (cmd) { | |
192 case DEMUXER_CTRL_GET_TIME_LENGTH: | |
193 if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW; | |
194 *((double *)arg) = priv->length; | |
195 return DEMUXER_CTRL_OK; | |
196 case DEMUXER_CTRL_GET_PERCENT_POS: | |
197 if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW; | |
198 *((int *)arg) = priv->last_pts * 100 / priv->length; | |
199 return DEMUXER_CTRL_OK; | |
200 } | |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
201 return DEMUXER_CTRL_NOTIMPL; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
202 } |
16175 | 203 |
204 | |
205 demuxer_desc_t demuxer_desc_mpc = { | |
206 "Musepack demuxer", | |
207 "mpc", | |
208 "MPC", | |
209 "Reza Jelveh, Reimar Doeffinger", | |
210 "supports v7 bitstream only", | |
211 DEMUXER_TYPE_MPC, | |
212 0, // unsafe autodetect | |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
213 demux_mpc_check, |
16175 | 214 demux_mpc_fill_buffer, |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
215 demux_mpc_open, |
16175 | 216 demux_close_mpc, |
217 demux_mpc_seek, | |
218 demux_mpc_control | |
219 }; |