annotate libmpdemux/demux_mpc.c @ 23428:c45f009ce3a7

Get rid of superfluous MPLAYER #define, it was always enabled and cluttered the code. Blessed by Reimar.
author diego
date Sat, 02 Jun 2007 12:24:35 +0000
parents 4d81dbdf46b9
children d4fe6e23283e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
22507
a46ab26b2d5e Source files should not contain non-ASCII characters.
diego
parents: 21507
diff changeset
3 * by Reimar Doeffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>
16074
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
fdb6bc2b891f Use a more stable URL.
diego
parents: 16074
diff changeset
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"
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 18885
diff changeset
14 #include "libavutil/common.h"
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
15 #include "mpbswap.h"
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 22507
diff changeset
16 #include "stream/stream.h"
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
17 #include "demuxer.h"
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
18 #include "stheader.h"
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
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
21 #define HDR_SIZE (6 * 4)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
22
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
23 typedef struct da_priv {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
24 float last_pts;
16745
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
25 float pts_per_packet;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
26 uint32_t dword;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
27 int pos;
16612
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
28 float length;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
29 } da_priv_t;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
30
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
31 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
32 uint32_t out = priv->dword;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
33 uint32_t mask = (1 << bits) - 1;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
34 priv->pos += bits;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
35 if (priv->pos < 32) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
36 out >>= (32 - priv->pos);
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 else {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
39 stream_read(s, (void *)&priv->dword, 4);
16149
5a97461d9ada 10l, incorrect usage of le2me_*
reimar
parents: 16093
diff changeset
40 priv->dword = le2me_32(priv->dword);
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
41 priv->pos -= 32;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
42 if (priv->pos) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
43 out <<= priv->pos;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
44 out |= priv->dword >> (32 - priv->pos);
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 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
47 return out & mask;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
48 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
49
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
50 static int demux_mpc_check(demuxer_t* demuxer) {
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
51 stream_t *s = demuxer->stream;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
52 uint8_t hdr[HDR_SIZE];
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
53 int i;
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 if (stream_read(s, hdr, HDR_SIZE) != HDR_SIZE)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
56 return 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
57 for (i = 0; i < 30000 && !s->eof; i++) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
58 if (hdr[0] == 'M' && hdr[1] == 'P' && hdr[2] == '+')
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
59 break;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
60 memmove(hdr, &hdr[1], HDR_SIZE - 1);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
61 stream_read(s, &hdr[HDR_SIZE - 1], 1);
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 if (hdr[0] != 'M' || hdr[1] != 'P' || hdr[2] != '+')
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
65 return 0;
16414
cdb7069d57b0 better bitrate calculation
reimar
parents: 16411
diff changeset
66 demuxer->movi_start = stream_tell(s) - HDR_SIZE;
cdb7069d57b0 better bitrate calculation
reimar
parents: 16411
diff changeset
67 demuxer->movi_end = s->end_pos;
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
68 demuxer->priv = malloc(HDR_SIZE);
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
69 memcpy(demuxer->priv, hdr, HDR_SIZE);
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
70 return DEMUXER_TYPE_MPC;
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
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
73 static demuxer_t *demux_mpc_open(demuxer_t* demuxer) {
16612
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
74 float seconds = 0;
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
75 stream_t *s = demuxer->stream;
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
76 sh_audio_t* sh_audio;
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
77 da_priv_t* priv = demuxer->priv;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
78
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
79 sh_audio = new_sh_audio(demuxer,0);
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 {
18885
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 18710
diff changeset
82 char *wf = calloc(1, sizeof(WAVEFORMATEX) + HDR_SIZE);
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
83 char *header = &wf[sizeof(WAVEFORMATEX)];
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
84 const int freqs[4] = {44100, 48000, 37800, 32000};
16414
cdb7069d57b0 better bitrate calculation
reimar
parents: 16411
diff changeset
85 int frames;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
86 sh_audio->format = mmioFOURCC('M', 'P', 'C', ' ');
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
87 memcpy(header, priv, HDR_SIZE);
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
88 free(priv);
16414
cdb7069d57b0 better bitrate calculation
reimar
parents: 16411
diff changeset
89 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
90 sh_audio->wf = (WAVEFORMATEX *)wf;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
91 sh_audio->wf->wFormatTag = sh_audio->format;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
92 sh_audio->wf->nChannels = 2;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
93 sh_audio->wf->nSamplesPerSec = freqs[header[10] & 3];
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
94 sh_audio->wf->nBlockAlign = 32 * 36;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
95 sh_audio->wf->wBitsPerSample = 16;
16612
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
96 seconds = 1152 * frames / (float)sh_audio->wf->nSamplesPerSec;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
97 if (demuxer->movi_end > demuxer->movi_start && seconds > 1)
16414
cdb7069d57b0 better bitrate calculation
reimar
parents: 16411
diff changeset
98 sh_audio->wf->nAvgBytesPerSec = (demuxer->movi_end - demuxer->movi_start) / seconds;
cdb7069d57b0 better bitrate calculation
reimar
parents: 16411
diff changeset
99 else
cdb7069d57b0 better bitrate calculation
reimar
parents: 16411
diff changeset
100 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
101 sh_audio->wf->cbSize = HDR_SIZE;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
102 demuxer->movi_start = stream_tell(s);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
103 demuxer->movi_end = s->end_pos;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
104 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
105
18885
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 18710
diff changeset
106 priv = malloc(sizeof(da_priv_t));
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
107 priv->last_pts = -1;
16745
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
108 priv->pts_per_packet = (32 * 36) / (float)sh_audio->wf->nSamplesPerSec;
16612
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
109 priv->length = seconds;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
110 priv->dword = 0;
16743
ea5de6cb209b Bigendian bug
reimar
parents: 16612
diff changeset
111 priv->pos = 32; // empty bit buffer
ea5de6cb209b Bigendian bug
reimar
parents: 16612
diff changeset
112 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
113 demuxer->priv = priv;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
114 demuxer->audio->id = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
115 demuxer->audio->sh = sh_audio;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
116 sh_audio->ds = demuxer->audio;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
117 sh_audio->samplerate = sh_audio->wf->nSamplesPerSec;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
118 sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
119 sh_audio->audio.dwSampleSize = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
120 sh_audio->audio.dwScale = 32 * 36;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
121 sh_audio->audio.dwRate = sh_audio->samplerate;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
122
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
123 return demuxer;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
124 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
125
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
126 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
127 int l;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
128 int bit_len;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
129 demux_packet_t* dp;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
130 sh_audio_t* sh_audio = ds->sh;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
131 da_priv_t* priv = demux->priv;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
132 stream_t* s = demux->stream;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
133 sh_audio = ds->sh;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
134
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
135 if (s->eof)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
136 return 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
137
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
138 bit_len = get_bits(priv, s, 20);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
139 dp = new_demux_packet((bit_len + 7) / 8);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
140 for (l = 0; l < (bit_len / 8); l++)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
141 dp->buffer[l] = get_bits(priv, s, 8);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
142 bit_len %= 8;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
143 if (bit_len)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
144 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
145 if (priv->last_pts < 0)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
146 priv->last_pts = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
147 else
16745
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
148 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
149 dp->pts = priv->last_pts;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
150 ds_add_packet(ds, dp);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
151 return 1;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
152 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
153
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 16877
diff changeset
154 static void demux_mpc_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
16745
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
155 sh_audio_t* sh_audio = demuxer->audio->sh;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
156 da_priv_t* priv = demuxer->priv;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
157 stream_t* s = demuxer->stream;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
158 float target = rel_seek_secs;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
159 if (flags & 2)
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
160 target *= priv->length;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
161 if (!(flags & 1))
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
162 target += priv->last_pts;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
163 if (target < priv->last_pts) {
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
164 stream_seek(s, demuxer->movi_start);
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
165 priv->pos = 32; // empty bit buffer
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
166 get_bits(priv, s, 8); // discard first 8 bits
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
167 priv->last_pts = 0;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
168 }
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
169 while (target > priv->last_pts) {
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
170 int bit_len = get_bits(priv, s, 20);
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
171 if (bit_len > 32) {
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
172 stream_skip(s, bit_len / 32 * 4 - 4);
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
173 get_bits(priv, s, 32); // make sure dword is reloaded
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
174 }
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
175 get_bits(priv, s, bit_len % 32);
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
176 priv->last_pts += priv->pts_per_packet;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
177 if (s->eof) break;
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
178 }
a1e105d71db4 Implement seeking
reimar
parents: 16743
diff changeset
179 if (!sh_audio) return;
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
180 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
181
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
182 static void demux_close_mpc(demuxer_t* demuxer) {
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
183 da_priv_t* priv = demuxer->priv;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
184
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
185 if(!priv)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
186 return;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
187 free(priv);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
188 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
189
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
190 static int demux_mpc_control(demuxer_t *demuxer,int cmd, void *arg){
16612
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
191 da_priv_t* priv = demuxer->priv;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
192 switch (cmd) {
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
193 case DEMUXER_CTRL_GET_TIME_LENGTH:
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
194 if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
195 *((double *)arg) = priv->length;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
196 return DEMUXER_CTRL_OK;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
197 case DEMUXER_CTRL_GET_PERCENT_POS:
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
198 if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
199 *((int *)arg) = priv->last_pts * 100 / priv->length;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
200 return DEMUXER_CTRL_OK;
e94616c973e3 Report total time
reimar
parents: 16424
diff changeset
201 }
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
202 return DEMUXER_CTRL_NOTIMPL;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
203 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
204
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
205
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
206 demuxer_desc_t demuxer_desc_mpc = {
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
207 "Musepack demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
208 "mpc",
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
209 "MPC",
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
210 "Reza Jelveh, Reimar Doeffinger",
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
211 "supports v7 bitstream only",
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
212 DEMUXER_TYPE_MPC,
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
213 0, // unsafe autodetect
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
214 demux_mpc_check,
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
215 demux_mpc_fill_buffer,
16411
719f5f7094c9 Changes forgotten during demuxer API change, introduce a check function.
reimar
parents: 16175
diff changeset
216 demux_mpc_open,
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
217 demux_close_mpc,
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
218 demux_mpc_seek,
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
219 demux_mpc_control
6b86089c2edd Demuxer modularization
rtognimp
parents: 16149
diff changeset
220 };