Line 0
Link Here
|
|
|
1 |
--- plugins/mpc/mpcdecode.cpp.orig 2006-11-18 11:51:08.000000000 +0100 |
2 |
+++ plugins/mpc/mpcdecode.cpp 2010-09-11 11:46:56.335821789 +0200 |
3 |
@@ -29,8 +29,9 @@ |
4 |
#include <assert.h> |
5 |
#include <time.h> |
6 |
#include "fileio.h" |
7 |
+#include "config.h" |
8 |
|
9 |
-#include <mpcdec/mpcdec.h> |
10 |
+#include <mpc/mpcdec.h> |
11 |
|
12 |
extern char *mpcErrorString; |
13 |
|
14 |
@@ -40,35 +41,35 @@ |
15 |
} reader_data; |
16 |
|
17 |
static mpc_int32_t |
18 |
-read_impl(void *data, void *ptr, mpc_int32_t size) |
19 |
+read_impl(mpc_reader *data, void *ptr, mpc_int32_t size) |
20 |
{ |
21 |
- reader_data *d = (reader_data *) data; |
22 |
+ reader_data *d = (reader_data *) data->data; |
23 |
return tread(ptr, 1, size, d->file); |
24 |
} |
25 |
|
26 |
static mpc_bool_t |
27 |
-seek_impl(void *data, mpc_int32_t offset) |
28 |
+seek_impl(mpc_reader *data, mpc_int32_t offset) |
29 |
{ |
30 |
- reader_data *d = (reader_data *) data; |
31 |
+ reader_data *d = (reader_data *) data->data; |
32 |
return !tseek(d->file, offset, SEEK_SET); |
33 |
} |
34 |
|
35 |
static mpc_int32_t |
36 |
-tell_impl(void *data) |
37 |
+tell_impl(mpc_reader *data) |
38 |
{ |
39 |
- reader_data *d = (reader_data *) data; |
40 |
+ reader_data *d = (reader_data *) data->data; |
41 |
return ttell(d->file); |
42 |
} |
43 |
|
44 |
static mpc_int32_t |
45 |
-get_size_impl(void *data) |
46 |
+get_size_impl(mpc_reader *data) |
47 |
{ |
48 |
- reader_data *d = (reader_data *) data; |
49 |
+ reader_data *d = (reader_data *) data->data; |
50 |
return d->size; |
51 |
} |
52 |
|
53 |
static mpc_bool_t |
54 |
-canseek_impl(void *data) |
55 |
+canseek_impl(mpc_reader *data) |
56 |
{ |
57 |
return true; |
58 |
} |
59 |
@@ -76,7 +77,7 @@ |
60 |
typedef struct mpc_decode_struct_t { |
61 |
TFILE *file; |
62 |
reader_data rdata; |
63 |
- mpc_decoder decoder; |
64 |
+ mpc_demux *decoder; |
65 |
mpc_reader reader; |
66 |
mpc_streaminfo info; |
67 |
MPC_SAMPLE_FORMAT buffer[MPC_DECODER_BUFFER_LENGTH]; |
68 |
@@ -114,27 +115,21 @@ |
69 |
ds->reader.canseek = canseek_impl; |
70 |
ds->reader.data = &ds->rdata; |
71 |
|
72 |
- /* read file's streaminfo data */ |
73 |
- mpc_streaminfo_init(&ds->info); |
74 |
- if (mpc_streaminfo_read(&ds->info, &ds->reader) != ERROR_CODE_OK) { |
75 |
- mpcErrorString = "Not a valid Musepack file."; |
76 |
- goto error; |
77 |
- } |
78 |
- |
79 |
- /* instantiate a decoder with our file reader */ |
80 |
- mpc_decoder_setup(&ds->decoder, &ds->reader); |
81 |
- if (!mpc_decoder_initialize(&ds->decoder, &ds->info)) { |
82 |
- mpcErrorString = "Error initializing decoder."; |
83 |
- goto error; |
84 |
- } |
85 |
- |
86 |
+ ds->decoder = mpc_demux_init(&ds->reader); |
87 |
+ if (!ds->decoder) { |
88 |
+ mpcErrorString = "Error initializing decoder."; |
89 |
+ goto error; |
90 |
+ } |
91 |
+ |
92 |
+ mpc_demux_get_info(ds->decoder, &ds->info); |
93 |
+ |
94 |
return ds; |
95 |
|
96 |
error: |
97 |
- if (ds) |
98 |
- delete ds; |
99 |
- |
100 |
- return NULL; |
101 |
+ if (ds) { |
102 |
+ mpc_demux_exit(ds->decoder); |
103 |
+ delete ds; |
104 |
+ } |
105 |
} |
106 |
|
107 |
extern "C" int |
108 |
@@ -144,7 +139,8 @@ |
109 |
return 0; |
110 |
|
111 |
if (duration) |
112 |
- *duration = (ds->info.pcm_samples * 1000) / ds->info.sample_freq; |
113 |
+ *duration = ((ds->info.samples - ds->info.beg_silence) * 1000) |
114 |
+ / ds->info.sample_freq; |
115 |
if (samplesPerSecond) |
116 |
*samplesPerSecond = ds->info.sample_freq; |
117 |
if (bitsPerSample) |
118 |
@@ -173,6 +169,8 @@ |
119 |
return -1; |
120 |
|
121 |
unsigned status, maxSamples = maxBytes / 2 / ds->info.channels, samples, offset; |
122 |
+ mpc_frame_info frame; |
123 |
+ mpc_status err; |
124 |
|
125 |
if (ds->samples > 0) { |
126 |
samples = ds->samples; |
127 |
@@ -182,15 +180,18 @@ |
128 |
goto convert; |
129 |
} |
130 |
|
131 |
- status = mpc_decoder_decode(&ds->decoder, ds->buffer, 0, 0); |
132 |
- |
133 |
- if (status == (unsigned)(-1)) { //decode error |
134 |
- mpcErrorString = "Error decoding file."; |
135 |
- return -1; |
136 |
+ frame.buffer = ds->buffer; |
137 |
+ err = mpc_demux_decode(ds->decoder, &frame); |
138 |
+ |
139 |
+ if (err != MPC_STATUS_OK) { //decode error |
140 |
+ mpcErrorString = "Error decoding file."; |
141 |
+ return -1; |
142 |
} |
143 |
- else if (status == 0) { //EOF |
144 |
- return 0; |
145 |
+ else if (frame.bits == -1) { //EOF |
146 |
+ return 0; |
147 |
} |
148 |
+ |
149 |
+ status = frame.samples; |
150 |
|
151 |
if (status > maxSamples) { |
152 |
ds->samples = status - maxSamples; |
153 |
@@ -230,8 +231,10 @@ |
154 |
extern "C" void |
155 |
mpcDecodeEnd(mpc_decode_struct_t *ds) |
156 |
{ |
157 |
- if (ds) |
158 |
- delete ds; |
159 |
+ if (ds) { |
160 |
+ mpc_demux_exit(ds->decoder); |
161 |
+ delete ds; |
162 |
+ } |
163 |
} |
164 |
|
165 |
|