Mercurial > mplayer.hg
annotate libmpdemux/demux_mpc.c @ 36673:1285e5ce2054
Prettify the skin browser.
Use the same design as with the other similar lists
(available audio and video drivers, playlist).
author | ib |
---|---|
date | Fri, 31 Jan 2014 17:08:39 +0000 |
parents | 8fa2f43cb760 |
children | 92dd1764392a |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
2 * demuxer for Musepack v7 bitstream |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
3 * copyright (c) 2005 Reimar Doeffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de> |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
4 * |
16074
f482bbb5fad9
Allow the ffmpeg people to use this code if they want.
reimar
parents:
15958
diff
changeset
|
5 * This code may be be relicensed under the terms of the GNU LGPL when it |
16093 | 6 * becomes part of the FFmpeg project (ffmpeg.org) |
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
7 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
8 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
9 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
10 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
13 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
14 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
15 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
18 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
19 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
20 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
21 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25883
diff
changeset
|
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
16074
f482bbb5fad9
Allow the ffmpeg people to use this code if they want.
reimar
parents:
15958
diff
changeset
|
23 */ |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
24 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
25 #include "config.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
26 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
27 #include <stdlib.h> |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
28 #include <stdio.h> |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
29 #include <string.h> |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
30 #include "mp_msg.h" |
21372 | 31 #include "libavutil/common.h" |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21372
diff
changeset
|
32 #include "mpbswap.h" |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
22507
diff
changeset
|
33 #include "stream/stream.h" |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
34 #include "demuxer.h" |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
35 #include "stheader.h" |
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 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
38 #define HDR_SIZE (6 * 4) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
39 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
40 typedef struct da_priv { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
41 float last_pts; |
16745 | 42 float pts_per_packet; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
43 uint32_t dword; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
44 int pos; |
16612 | 45 float length; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
46 } da_priv_t; |
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 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
|
49 uint32_t out = priv->dword; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
50 uint32_t mask = (1 << bits) - 1; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
51 priv->pos += bits; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
52 if (priv->pos < 32) { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
53 out >>= (32 - priv->pos); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
54 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
55 else { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
56 stream_read(s, (void *)&priv->dword, 4); |
16149 | 57 priv->dword = le2me_32(priv->dword); |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
58 priv->pos -= 32; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
59 if (priv->pos) { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
60 out <<= priv->pos; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
61 out |= priv->dword >> (32 - priv->pos); |
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 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
64 return out & mask; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
65 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
66 |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
67 static int demux_mpc_check(demuxer_t* demuxer) { |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
68 stream_t *s = demuxer->stream; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
69 uint8_t hdr[HDR_SIZE]; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
70 int i; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
71 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
72 if (stream_read(s, hdr, HDR_SIZE) != HDR_SIZE) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
73 return 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
74 for (i = 0; i < 30000 && !s->eof; i++) { |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
75 if (hdr[0] == 'M' && hdr[1] == 'P' && hdr[2] == '+') |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
76 break; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
77 memmove(hdr, &hdr[1], HDR_SIZE - 1); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
78 stream_read(s, &hdr[HDR_SIZE - 1], 1); |
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 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
81 if (hdr[0] != 'M' || hdr[1] != 'P' || hdr[2] != '+') |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
82 return 0; |
16414 | 83 demuxer->movi_start = stream_tell(s) - HDR_SIZE; |
84 demuxer->movi_end = s->end_pos; | |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
85 demuxer->priv = malloc(HDR_SIZE); |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
86 memcpy(demuxer->priv, hdr, HDR_SIZE); |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
87 return DEMUXER_TYPE_MPC; |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
88 } |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
89 |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
90 static demuxer_t *demux_mpc_open(demuxer_t* demuxer) { |
16612 | 91 float seconds = 0; |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
92 stream_t *s = demuxer->stream; |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
93 sh_audio_t* sh_audio; |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
94 da_priv_t* priv = demuxer->priv; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
95 |
31609
cd81fce1f010
Make the stream language an argument to the stream creation function
reimar
parents:
29238
diff
changeset
|
96 sh_audio = new_sh_audio(demuxer,0, NULL); |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
97 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
98 { |
18885 | 99 char *wf = calloc(1, sizeof(WAVEFORMATEX) + HDR_SIZE); |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
100 char *header = &wf[sizeof(WAVEFORMATEX)]; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
101 const int freqs[4] = {44100, 48000, 37800, 32000}; |
16414 | 102 int frames; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
103 sh_audio->format = mmioFOURCC('M', 'P', 'C', ' '); |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
104 memcpy(header, priv, HDR_SIZE); |
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
105 free(priv); |
16414 | 106 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
|
107 sh_audio->wf = (WAVEFORMATEX *)wf; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
108 sh_audio->wf->wFormatTag = sh_audio->format; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
109 sh_audio->wf->nChannels = 2; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
110 sh_audio->wf->nSamplesPerSec = freqs[header[10] & 3]; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
111 sh_audio->wf->nBlockAlign = 32 * 36; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
112 sh_audio->wf->wBitsPerSample = 16; |
16612 | 113 seconds = 1152 * frames / (float)sh_audio->wf->nSamplesPerSec; |
114 if (demuxer->movi_end > demuxer->movi_start && seconds > 1) | |
16414 | 115 sh_audio->wf->nAvgBytesPerSec = (demuxer->movi_end - demuxer->movi_start) / seconds; |
116 else | |
117 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
|
118 sh_audio->wf->cbSize = HDR_SIZE; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
119 demuxer->movi_start = stream_tell(s); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
120 demuxer->movi_end = s->end_pos; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
121 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
122 |
18885 | 123 priv = malloc(sizeof(da_priv_t)); |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
124 priv->last_pts = -1; |
16745 | 125 priv->pts_per_packet = (32 * 36) / (float)sh_audio->wf->nSamplesPerSec; |
16612 | 126 priv->length = seconds; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
127 priv->dword = 0; |
16743 | 128 priv->pos = 32; // empty bit buffer |
129 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
|
130 demuxer->priv = priv; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
131 demuxer->audio->id = 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
132 demuxer->audio->sh = sh_audio; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
133 sh_audio->ds = demuxer->audio; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
134 sh_audio->samplerate = sh_audio->wf->nSamplesPerSec; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
135 sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
136 sh_audio->audio.dwSampleSize = 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
137 sh_audio->audio.dwScale = 32 * 36; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
138 sh_audio->audio.dwRate = sh_audio->samplerate; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
139 |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
140 return demuxer; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
141 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
142 |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
143 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
|
144 int l; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
145 int bit_len; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
146 demux_packet_t* dp; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
147 sh_audio_t* sh_audio = ds->sh; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
148 da_priv_t* priv = demux->priv; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
149 stream_t* s = demux->stream; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
150 sh_audio = ds->sh; |
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 if (s->eof) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
153 return 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
154 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
155 bit_len = get_bits(priv, s, 20); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
156 dp = new_demux_packet((bit_len + 7) / 8); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
157 for (l = 0; l < (bit_len / 8); l++) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
158 dp->buffer[l] = get_bits(priv, s, 8); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
159 bit_len %= 8; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
160 if (bit_len) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
161 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
|
162 if (priv->last_pts < 0) |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
163 priv->last_pts = 0; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
164 else |
16745 | 165 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
|
166 dp->pts = priv->last_pts; |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
167 ds_add_packet(ds, dp); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
168 return 1; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
169 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
170 |
17636 | 171 static void demux_mpc_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ |
16745 | 172 sh_audio_t* sh_audio = demuxer->audio->sh; |
173 da_priv_t* priv = demuxer->priv; | |
174 stream_t* s = demuxer->stream; | |
175 float target = rel_seek_secs; | |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
176 if (flags & SEEK_FACTOR) |
16745 | 177 target *= priv->length; |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
178 if (!(flags & SEEK_ABSOLUTE)) |
16745 | 179 target += priv->last_pts; |
180 if (target < priv->last_pts) { | |
181 stream_seek(s, demuxer->movi_start); | |
182 priv->pos = 32; // empty bit buffer | |
183 get_bits(priv, s, 8); // discard first 8 bits | |
184 priv->last_pts = 0; | |
185 } | |
186 while (target > priv->last_pts) { | |
187 int bit_len = get_bits(priv, s, 20); | |
188 if (bit_len > 32) { | |
189 stream_skip(s, bit_len / 32 * 4 - 4); | |
190 get_bits(priv, s, 32); // make sure dword is reloaded | |
191 } | |
192 get_bits(priv, s, bit_len % 32); | |
193 priv->last_pts += priv->pts_per_packet; | |
194 if (s->eof) break; | |
195 } | |
196 if (!sh_audio) return; | |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
197 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
198 |
16175 | 199 static void demux_close_mpc(demuxer_t* demuxer) { |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
200 da_priv_t* priv = demuxer->priv; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
201 |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
202 free(priv); |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
203 } |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
204 |
16175 | 205 static int demux_mpc_control(demuxer_t *demuxer,int cmd, void *arg){ |
16612 | 206 da_priv_t* priv = demuxer->priv; |
207 switch (cmd) { | |
208 case DEMUXER_CTRL_GET_TIME_LENGTH: | |
209 if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW; | |
210 *((double *)arg) = priv->length; | |
211 return DEMUXER_CTRL_OK; | |
212 case DEMUXER_CTRL_GET_PERCENT_POS: | |
213 if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW; | |
214 *((int *)arg) = priv->last_pts * 100 / priv->length; | |
215 return DEMUXER_CTRL_OK; | |
216 } | |
15958
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
217 return DEMUXER_CTRL_NOTIMPL; |
087142ef3a2d
musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff
changeset
|
218 } |
16175 | 219 |
220 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
22605
diff
changeset
|
221 const demuxer_desc_t demuxer_desc_mpc = { |
16175 | 222 "Musepack demuxer", |
223 "mpc", | |
224 "MPC", | |
225 "Reza Jelveh, Reimar Doeffinger", | |
226 "supports v7 bitstream only", | |
227 DEMUXER_TYPE_MPC, | |
228 0, // unsafe autodetect | |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
229 demux_mpc_check, |
16175 | 230 demux_mpc_fill_buffer, |
16411
719f5f7094c9
Changes forgotten during demuxer API change, introduce a check function.
reimar
parents:
16175
diff
changeset
|
231 demux_mpc_open, |
16175 | 232 demux_close_mpc, |
233 demux_mpc_seek, | |
234 demux_mpc_control | |
235 }; |