1 frontend/audio.c | 11 +++++-
2 frontend/main.c | 89 ++++++++++++++++++++++++++++++++---------
3 frontend/unicode_support.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++
4 frontend/unicode_support.h | 21 ++++++++++
5 include/neaacdec.h | 6 +--
6 5 files changed, 202 insertions(+), 23 deletions(-)
8 diff --git a/frontend/audio.c b/frontend/audio.c
9 index 067ac20..a502c6e 100644
10 --- a/frontend/audio.c
11 +++ b/frontend/audio.c
16 +#include "unicode_support.h"
19 audio_file *open_audio_file(char *infile, int samplerate, int channels,
20 int outputFormat, int fileType, long channelMask)
24 audio_file *aufile = malloc(sizeof(audio_file));
26 aufile->outputFormat = outputFormat;
27 @@ -78,7 +81,13 @@ audio_file *open_audio_file(char *infile, int samplerate, int channels,
31 - aufile->sndfile = fopen(infile, "wb");
32 + aufile->sndfile = NULL;
33 + fileNameW = utf8_to_utf16(infile);
36 + aufile->sndfile = _wfopen(fileNameW, L"wb");
41 if (aufile->sndfile == NULL)
42 diff --git a/frontend/main.c b/frontend/main.c
43 index 04e2058..01a5b7a 100644
56 +#include "unicode_support.h"
59 #define min(a,b) ( (a) < (b) ? (a) : (b) )
60 @@ -71,6 +73,8 @@ static void faad_fprintf(FILE *stream, const char *fmt, ...)
61 vfprintf(stream, fmt, ap);
69 @@ -443,7 +447,7 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
70 NeAACDecFrameInfo frameInfo;
71 NeAACDecConfigurationPtr config;
75 int percent, old_percent = -1;
78 @@ -456,11 +460,19 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
84 memset(&b, 0, sizeof(aac_buffer));
88 - adtsFile = fopen(adts_fn, "wb");
90 + fileNameW = utf8_to_utf16(adts_fn);
93 + adtsFile = _wfopen(fileNameW, L"wb");
98 faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
99 @@ -470,20 +482,26 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
101 if (0 == strcmp(aacfile, "-"))
106 setmode(fileno(stdin), O_BINARY);
113 - b.infile = fopen(aacfile, "rb");
114 - if (b.infile == NULL)
116 - /* unable to open file */
117 - faad_fprintf(stderr, "Error opening file: %s\n", aacfile);
121 + fileNameW = utf8_to_utf16(aacfile);
124 + b.infile = _wfopen(fileNameW, L"rb");
127 + if (b.infile == NULL)
129 + /* unable to open file */
130 + faad_fprintf(stderr, "Error opening file: %s\n", aacfile);
135 retval = fseek(b.infile, 0, SEEK_END);
136 @@ -708,7 +726,7 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
137 if (percent > old_percent)
139 old_percent = percent;
140 - sprintf(percents, "%d%% decoding %s.", percent, aacfile);
141 + _snprintf_s(percents, 300, _TRUNCATE, "[%d%%] decoding %s.", percent, aacfile);
142 faad_fprintf(stderr, "%s\r", percents);
144 SetConsoleTitle(percents);
145 @@ -810,7 +828,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
146 unsigned char *buffer;
149 - char percents[200];
150 + char percents[300];
151 int percent, old_percent = -1;
154 @@ -821,6 +839,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
155 unsigned int framesize;
156 unsigned long timescale;
158 + wchar_t *fileNameW;
160 /* initialise the callback structure */
161 mp4ff_callback_t *mp4cb = malloc(sizeof(mp4ff_callback_t));
162 @@ -830,7 +849,14 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
166 - mp4File = fopen(mp4file, "rb");
168 + fileNameW = utf8_to_utf16(mp4file);
171 + mp4File = _wfopen(fileNameW, L"rb");
175 mp4cb->read = read_callback;
176 mp4cb->seek = seek_callback;
177 mp4cb->user_data = mp4File;
178 @@ -847,7 +873,13 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
182 - adtsFile = fopen(adts_fn, "wb");
184 + fileNameW = utf8_to_utf16(adts_fn);
187 + adtsFile = _wfopen(fileNameW, L"wb");
190 if (adtsFile == NULL)
192 faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
193 @@ -1053,7 +1085,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
194 if (percent > old_percent)
196 old_percent = percent;
197 - sprintf(percents, "%d%% decoding %s.", percent, mp4file);
198 + _snprintf_s(percents, 300, _TRUNCATE, "[%d%%] decoding %s.", percent, mp4file);
199 faad_fprintf(stderr, "%s\r", percents);
201 SetConsoleTitle(percents);
202 @@ -1091,7 +1123,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
203 return frameInfo.error;
206 -int main(int argc, char *argv[])
207 +int faad_main(int argc, char *argv[])
211 @@ -1115,6 +1147,7 @@ int main(int argc, char *argv[])
212 unsigned char header[8];
215 + wchar_t *fileNameW;
217 /* System dependant types */
219 @@ -1345,7 +1378,13 @@ int main(int argc, char *argv[])
223 - hMP4File = fopen(aacFileName, "rb");
225 + fileNameW = utf8_to_utf16(aacFileName);
228 + hMP4File = _wfopen(fileNameW, L"rb");
233 faad_fprintf(stderr, "Error opening file: %s\n", aacFileName);
234 @@ -1408,3 +1447,15 @@ int main(int argc, char *argv[])
239 +int wmain(int argc, wchar_t **argv_utf16)
242 + char **argv_utf8 = NULL;
244 + init_commandline_arguments_utf8(argc, &argv_utf8, argv_utf16);
245 + result = faad_main(argc, argv_utf8);
246 + free_commandline_arguments_utf8(argc, &argv_utf8);
250 diff --git a/frontend/unicode_support.c b/frontend/unicode_support.c
252 index 0000000..21ecd5c
254 +++ b/frontend/unicode_support.c
256 +#include "unicode_support.h"
259 +#include <windows.h>
261 +char *utf16_to_utf8(const wchar_t *input)
264 + int BuffSize, Result;
266 + BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
267 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
271 + fprintf(stderr, "Error in utf16_to_utf8: Memory allocation failed!\n");
275 + Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
276 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
279 +wchar_t *utf8_to_utf16(const char *input)
282 + int BuffSize, Result;
284 + BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
285 + Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
289 + fprintf(stderr, "Error in utf8_to_utf16: Memory allocation failed!\n");
293 + Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
294 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
297 +void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16)
301 + *argv_utf8 = (char**) malloc(argc * sizeof(char*));
304 + fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
308 + for(i = 0; i < argc; i++)
310 + (*argv_utf8)[i] = utf16_to_utf8(argv_utf16[i]);
311 + if(!(*argv_utf8)[i])
313 + fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
319 +void free_commandline_arguments_utf8(int argc, char ***argv_utf8)
323 + if(*argv_utf8 != NULL)
325 + for(i = 0; i < argc; i++)
327 + if((*argv_utf8)[i] != NULL)
329 + free((*argv_utf8)[i]);
330 + (*argv_utf8)[i] = NULL;
338 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
341 + wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
342 + wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
344 + if(filename_utf16 && mode_utf16)
346 + ret = _wfopen(filename_utf16, mode_utf16);
349 + if(filename_utf16) free(filename_utf16);
350 + if(mode_utf16) free(mode_utf16);
354 diff --git a/frontend/unicode_support.h b/frontend/unicode_support.h
356 index 0000000..cc13fd9
358 +++ b/frontend/unicode_support.h
360 +#ifndef UNICODE_SUPPORT_H_INCLUDED
361 +#define UNICODE_SUPPORT_H_INCLUDED
371 +char *utf16_to_utf8(const wchar_t *input);
372 +wchar_t *utf8_to_utf16(const char *input);
373 +void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16);
374 +void free_commandline_arguments_utf8(int argc, char ***argv_utf8);
375 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
381 \ No newline at end of file
382 diff --git a/include/neaacdec.h b/include/neaacdec.h
383 index 610a00b..7904175 100644
384 --- a/include/neaacdec.h
385 +++ b/include/neaacdec.h
386 @@ -202,7 +202,7 @@ typedef struct NeAACDecFrameInfo
390 -char NEAACDECAPI *NeAACDecGetErrorMessage(unsigned char errcode);
391 +char* NEAACDECAPI NeAACDecGetErrorMessage(unsigned char errcode);
393 unsigned long NEAACDECAPI NeAACDecGetCapabilities(void);
395 @@ -235,12 +235,12 @@ void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, long frame);
397 void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder);
399 -void NEAACDECAPI *NeAACDecDecode(NeAACDecHandle hDecoder,
400 +void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
401 NeAACDecFrameInfo *hInfo,
402 unsigned char *buffer,
403 unsigned long buffer_size);
405 -void NEAACDECAPI *NeAACDecDecode2(NeAACDecHandle hDecoder,
406 +void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
407 NeAACDecFrameInfo *hInfo,
408 unsigned char *buffer,
409 unsigned long buffer_size,