1 /*
2 * Tracked MOD demuxer (libopenmpt)
3 * Copyright (c) 2016 Josh de Kock
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <libopenmpt/libopenmpt.h>
23 #include <libopenmpt/libopenmpt_stream_callbacks_file.h>
24 #include <libopenmpt/libopenmpt_version.h>
25 /* Shims to support libopenmpt < 0.3.0 (as documented by libopenmpt) */
26 #if !defined(OPENMPT_API_VERSION_MAKE)
27 #define OPENMPT_API_VERSION_MAKE(major, minor, patch) (((major)<<24)|((minor)<<16)|((patch)<<0))
28 #endif
29 #if !defined(OPENMPT_API_VERSION_AT_LEAST)
30 #define OPENMPT_API_VERSION_AT_LEAST(major, minor, patch) (OPENMPT_API_VERSION >= OPENMPT_API_VERSION_MAKE((major), (minor), (patch)))
31 #endif
32
38
42
44 /* options */
49
50 #define OFFSET(x) offsetof(OpenMPTContext, x)
51 #define A AV_OPT_FLAG_AUDIO_PARAM
52 #define D AV_OPT_FLAG_DECODING_PARAM
60 };
61
63 {
67 }
69 }
70
71 #define add_meta(s, name, meta) \
72 do { \
73 const char *value = meta; \
74 if (value && value[0]) \
75 av_dict_set(&s->metadata, name, value, 0); \
76 openmpt_free_string(value); \
77 } while(0)
78
80 {
84 char *buf;
85 #if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
87 #endif
89
94 if (!buf)
101 }
102
103 #if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
104 error = OPENMPT_ERROR_OK;
108 if (
error == OPENMPT_ERROR_OUT_OF_MEMORY)
110 else if (
error >= OPENMPT_ERROR_GENERAL)
112 else
114 }
115 #else
120 #endif
121
122 if (openmpt->
subsong >= openmpt_module_get_num_subsongs(openmpt->
module)) {
125 }
126
130 }
135 }
136 }
137
138 openmpt->
duration = openmpt_module_get_duration_seconds(openmpt->
module);
139
140 add_meta(
s,
"artist", openmpt_module_get_metadata(openmpt->
module,
"artist"));
141 add_meta(
s,
"title", openmpt_module_get_metadata(openmpt->
module,
"title"));
142 add_meta(
s,
"encoder", openmpt_module_get_metadata(openmpt->
module,
"tracker"));
143 add_meta(
s,
"comment", openmpt_module_get_metadata(openmpt->
module,
"message"));
144 add_meta(
s,
"date", openmpt_module_get_metadata(openmpt->
module,
"date"));
145
147 if (!st)
151
158
159 return 0;
160 }
161
162 #define AUDIO_PKT_SIZE 2048
163
165 {
169
172
174 case 1:
176 n_samples, (
float *)
pkt->
data);
177 break;
178 case 2:
180 n_samples, (
float *)
pkt->
data);
181 break;
182 case 4:
184 n_samples, (
float *)
pkt->
data);
185 break;
186 default:
189 }
190
194 }
195
197
198 return 0;
199 }
200
202 {
205 openmpt_module_destroy(openmpt->
module);
207 }
208 return 0;
209 }
210
212 {
215 return 0;
216 }
217
219 {
220 const char *ext;
223 if (ext && strlen(ext + 1) > 0) {
224 ext++; /* skip '.' */
225 if (openmpt_is_extension_supported(ext) == 1)
227 }
228 }
229 return 0;
230 }
231
233 {
234 #if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
235 int probe_result;
237 probe_result = openmpt_probe_file_header_without_filesize(
238 OPENMPT_PROBE_FILE_HEADER_FLAGS_DEFAULT,
241 if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS) {
242 /* As probing here relies on code external to FFmpeg, do not return
243 * AVPROBE_SCORE_MAX in order to reduce the impact in the rare
244 * cases of false positives.
245 */
247 } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) {
250 } else {
251 if (p->
buf_size >= openmpt_probe_file_header_get_recommended_size()) {
252 /* We have already received the recommended amount of data
253 * and still cannot decide. Return a rather low score.
254 */
256 } else {
257 /* The file extension is unknown and we have very few data
258 * bytes available. libopenmpt cannot decide anything here,
259 * and returning any score > 0 would result in successful
260 * probing of random data.
261 */
262 return 0;
263 }
264 }
265 } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_FAILURE) {
266 return 0;
267 }
268 }
269 #endif
270 /* for older libopenmpt, fall back to file extension probing */
272 }
273
279 };
280
282 .
name =
"libopenmpt",
293 .extensions = "669,amf,ams,dbm,digi,dmf,dsm,dtm,far,gdm,ice,imf,it,j2b,m15,mdl,med,mmcmp,mms,mo3,mod,mptm,mt2,mtm,nst,okt,plm,ppm,psm,pt36,ptm,s3m,sfx,sfx2,st26,stk,stm,stp,ult,umx,wow,xm,xpk",
294 #else
295 .extensions = "669,amf,ams,dbm,digi,dmf,dsm,far,gdm,ice,imf,it,j2b,m15,mdl,med,mmcmp,mms,mo3,mod,mptm,mt2,mtm,nst,okt,plm,ppm,psm,pt36,ptm,s3m,sfx,sfx2,st26,stk,stm,ult,umx,wow,xm,xpk",
296 #endif
297 };