1 frontend/audio.c | 11 +++++-
2 frontend/faad.sln | 16 ++++----
3 frontend/main.c | 89 ++++++++++++++++++++++++++++++++---------
4 frontend/unicode_support.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++
5 frontend/unicode_support.h | 21 ++++++++++
6 include/neaacdec.h | 6 +--
7 libfaad/common.h | 4 +-
8 libfaad/decoder.c | 6 +--
9 libfaad/lt_predict.c | 2 +-
10 libfaad/output.c | 36 ++++++++---------
11 10 files changed, 233 insertions(+), 56 deletions(-)
13 diff --git a/frontend/audio.c b/frontend/audio.c
14 index 9ab7a2a..20f92a2 100644
15 --- a/frontend/audio.c
16 +++ b/frontend/audio.c
21 +#include "unicode_support.h"
24 audio_file *open_audio_file(char *infile, int samplerate, int channels,
25 int outputFormat, int fileType, long channelMask)
29 audio_file *aufile = malloc(sizeof(audio_file));
31 aufile->outputFormat = outputFormat;
32 @@ -80,7 +83,13 @@ audio_file *open_audio_file(char *infile, int samplerate, int channels,
36 - aufile->sndfile = fopen(infile, "wb");
37 + aufile->sndfile = NULL;
38 + fileNameW = utf8_to_utf16(infile);
41 + aufile->sndfile = _wfopen(fileNameW, L"wb");
46 if (aufile->sndfile == NULL)
47 diff --git a/frontend/faad.sln b/frontend/faad.sln
48 index a47200b..ddbea6d 100644
49 --- a/frontend/faad.sln
50 +++ b/frontend/faad.sln
53 -Microsoft Visual Studio Solution File, Format Version 9.00
55 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "faad", "faad.vcproj", "{2BD8CBB3-DFC9-4A6A-9B7A-07ED749BED58}"
56 - ProjectSection(ProjectDependencies) = postProject
57 - {F470BB4A-7675-4D6A-B310-41F33AC6F987} = {F470BB4A-7675-4D6A-B310-41F33AC6F987}
58 - {BC3EFE27-9015-4C9C-AD3C-72B3B7ED2114} = {BC3EFE27-9015-4C9C-AD3C-72B3B7ED2114}
60 +Microsoft Visual Studio Solution File, Format Version 12.00
62 +VisualStudioVersion = 14.0.25420.1
63 +MinimumVisualStudioVersion = 10.0.40219.1
64 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "faad", "faad.vcxproj", "{2BD8CBB3-DFC9-4A6A-9B7A-07ED749BED58}"
66 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfaad", "..\libfaad\libfaad.vcproj", "{BC3EFE27-9015-4C9C-AD3C-72B3B7ED2114}"
67 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfaad", "..\libfaad\libfaad.vcxproj", "{BC3EFE27-9015-4C9C-AD3C-72B3B7ED2114}"
69 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mp4ff", "..\common\mp4ff\mp4ff.vcproj", "{F470BB4A-7675-4D6A-B310-41F33AC6F987}"
70 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mp4ff", "..\common\mp4ff\mp4ff.vcxproj", "{F470BB4A-7675-4D6A-B310-41F33AC6F987}"
73 GlobalSection(SolutionConfigurationPlatforms) = preSolution
74 diff --git a/frontend/main.c b/frontend/main.c
75 index f943d9d..e4294d0 100644
88 +#include "unicode_support.h"
91 #define min(a,b) ( (a) < (b) ? (a) : (b) )
92 @@ -71,6 +73,8 @@ static void faad_fprintf(FILE *stream, const char *fmt, ...)
93 vfprintf(stream, fmt, ap);
101 @@ -450,7 +454,7 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
102 NeAACDecFrameInfo frameInfo;
103 NeAACDecConfigurationPtr config;
105 - char percents[200];
106 + char percents[300];
107 int percent, old_percent = -1;
110 @@ -463,11 +467,19 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
114 + wchar_t *fileNameW;
116 memset(&b, 0, sizeof(aac_buffer));
120 - adtsFile = fopen(adts_fn, "wb");
122 + fileNameW = utf8_to_utf16(adts_fn);
125 + adtsFile = _wfopen(fileNameW, L"wb");
128 if (adtsFile == NULL)
130 faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
131 @@ -477,20 +489,26 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
133 if (0 == strcmp(aacfile, "-"))
138 setmode(fileno(stdin), O_BINARY);
145 - b.infile = fopen(aacfile, "rb");
146 - if (b.infile == NULL)
148 - /* unable to open file */
149 - faad_fprintf(stderr, "Error opening file: %s\n", aacfile);
153 + fileNameW = utf8_to_utf16(aacfile);
156 + b.infile = _wfopen(fileNameW, L"rb");
159 + if (b.infile == NULL)
161 + /* unable to open file */
162 + faad_fprintf(stderr, "Error opening file: %s\n", aacfile);
167 retval = fseek(b.infile, 0, SEEK_END);
168 @@ -715,7 +733,7 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
169 if (percent > old_percent)
171 old_percent = percent;
172 - sprintf(percents, "%d%% decoding %s.", percent, aacfile);
173 + _snprintf_s(percents, 300, _TRUNCATE, "[%d%%] decoding %s.", percent, aacfile);
174 faad_fprintf(stderr, "%s\r", percents);
176 SetConsoleTitle(percents);
177 @@ -817,7 +835,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
178 unsigned char *buffer;
181 - char percents[200];
182 + char percents[300];
183 int percent, old_percent = -1;
186 @@ -828,6 +846,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
187 unsigned int framesize;
188 unsigned long timescale;
190 + wchar_t *fileNameW;
192 /* initialise the callback structure */
193 mp4ff_callback_t *mp4cb = malloc(sizeof(mp4ff_callback_t));
194 @@ -837,7 +856,14 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
198 - mp4File = fopen(mp4file, "rb");
200 + fileNameW = utf8_to_utf16(mp4file);
203 + mp4File = _wfopen(fileNameW, L"rb");
207 mp4cb->read = read_callback;
208 mp4cb->seek = seek_callback;
209 mp4cb->user_data = mp4File;
210 @@ -854,7 +880,13 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
214 - adtsFile = fopen(adts_fn, "wb");
216 + fileNameW = utf8_to_utf16(adts_fn);
219 + adtsFile = _wfopen(fileNameW, L"wb");
222 if (adtsFile == NULL)
224 faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
225 @@ -1060,7 +1092,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
226 if (percent > old_percent)
228 old_percent = percent;
229 - sprintf(percents, "%d%% decoding %s.", percent, mp4file);
230 + _snprintf_s(percents, 300, _TRUNCATE, "[%d%%] decoding %s.", percent, mp4file);
231 faad_fprintf(stderr, "%s\r", percents);
233 SetConsoleTitle(percents);
234 @@ -1098,7 +1130,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
235 return frameInfo.error;
238 -int main(int argc, char *argv[])
239 +int faad_main(int argc, char *argv[])
243 @@ -1122,6 +1154,7 @@ int main(int argc, char *argv[])
244 unsigned char header[8];
247 + wchar_t *fileNameW;
249 /* System dependant types */
251 @@ -1352,7 +1385,13 @@ int main(int argc, char *argv[])
255 - hMP4File = fopen(aacFileName, "rb");
257 + fileNameW = utf8_to_utf16(aacFileName);
260 + hMP4File = _wfopen(fileNameW, L"rb");
265 faad_fprintf(stderr, "Error opening file: %s\n", aacFileName);
266 @@ -1415,3 +1454,15 @@ int main(int argc, char *argv[])
271 +int wmain(int argc, wchar_t **argv_utf16)
274 + char **argv_utf8 = NULL;
276 + init_commandline_arguments_utf8(argc, &argv_utf8, argv_utf16);
277 + result = faad_main(argc, argv_utf8);
278 + free_commandline_arguments_utf8(argc, &argv_utf8);
282 diff --git a/frontend/unicode_support.c b/frontend/unicode_support.c
284 index 0000000..21ecd5c
286 +++ b/frontend/unicode_support.c
288 +#include "unicode_support.h"
291 +#include <windows.h>
293 +char *utf16_to_utf8(const wchar_t *input)
296 + int BuffSize, Result;
298 + BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
299 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
303 + fprintf(stderr, "Error in utf16_to_utf8: Memory allocation failed!\n");
307 + Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
308 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
311 +wchar_t *utf8_to_utf16(const char *input)
314 + int BuffSize, Result;
316 + BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
317 + Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
321 + fprintf(stderr, "Error in utf8_to_utf16: Memory allocation failed!\n");
325 + Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
326 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
329 +void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16)
333 + *argv_utf8 = (char**) malloc(argc * sizeof(char*));
336 + fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
340 + for(i = 0; i < argc; i++)
342 + (*argv_utf8)[i] = utf16_to_utf8(argv_utf16[i]);
343 + if(!(*argv_utf8)[i])
345 + fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
351 +void free_commandline_arguments_utf8(int argc, char ***argv_utf8)
355 + if(*argv_utf8 != NULL)
357 + for(i = 0; i < argc; i++)
359 + if((*argv_utf8)[i] != NULL)
361 + free((*argv_utf8)[i]);
362 + (*argv_utf8)[i] = NULL;
370 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
373 + wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
374 + wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
376 + if(filename_utf16 && mode_utf16)
378 + ret = _wfopen(filename_utf16, mode_utf16);
381 + if(filename_utf16) free(filename_utf16);
382 + if(mode_utf16) free(mode_utf16);
386 diff --git a/frontend/unicode_support.h b/frontend/unicode_support.h
388 index 0000000..cc13fd9
390 +++ b/frontend/unicode_support.h
392 +#ifndef UNICODE_SUPPORT_H_INCLUDED
393 +#define UNICODE_SUPPORT_H_INCLUDED
403 +char *utf16_to_utf8(const wchar_t *input);
404 +wchar_t *utf8_to_utf16(const char *input);
405 +void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16);
406 +void free_commandline_arguments_utf8(int argc, char ***argv_utf8);
407 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
413 \ No newline at end of file
414 diff --git a/include/neaacdec.h b/include/neaacdec.h
415 index 610a00b..7904175 100644
416 --- a/include/neaacdec.h
417 +++ b/include/neaacdec.h
418 @@ -202,7 +202,7 @@ typedef struct NeAACDecFrameInfo
422 -char NEAACDECAPI *NeAACDecGetErrorMessage(unsigned char errcode);
423 +char* NEAACDECAPI NeAACDecGetErrorMessage(unsigned char errcode);
425 unsigned long NEAACDECAPI NeAACDecGetCapabilities(void);
427 @@ -235,12 +235,12 @@ void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, long frame);
429 void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder);
431 -void NEAACDECAPI *NeAACDecDecode(NeAACDecHandle hDecoder,
432 +void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
433 NeAACDecFrameInfo *hInfo,
434 unsigned char *buffer,
435 unsigned long buffer_size);
437 -void NEAACDECAPI *NeAACDecDecode2(NeAACDecHandle hDecoder,
438 +void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
439 NeAACDecFrameInfo *hInfo,
440 unsigned char *buffer,
441 unsigned long buffer_size,
442 diff --git a/libfaad/common.h b/libfaad/common.h
443 index 897a0f0..74f4a56 100644
444 --- a/libfaad/common.h
445 +++ b/libfaad/common.h
446 @@ -316,7 +316,7 @@ char *strchr(), *strrchr();
447 #if defined(_WIN32) && !defined(_WIN64) && !defined(__MINGW32__)
450 - static INLINE int lrintf(float f)
451 + static INLINE int FAAD_lrintf(float f)
455 @@ -332,7 +332,7 @@ char *strchr(), *strrchr();
458 // from http://www.stereopsis.com/FPU.html
459 - static INLINE int lrintf(float f)
460 + static INLINE int FAAD_lrintf(float f)
463 __asm__ __volatile__ (
464 diff --git a/libfaad/decoder.c b/libfaad/decoder.c
465 index 42bbc84..67feb9d 100644
466 --- a/libfaad/decoder.c
467 +++ b/libfaad/decoder.c
468 @@ -64,7 +64,7 @@ static void create_channel_config(NeAACDecStruct *hDecoder,
469 NeAACDecFrameInfo *hInfo);
472 -char NEAACDECAPI *NeAACDecGetErrorMessage(unsigned char errcode)
473 +char* NEAACDECAPI NeAACDecGetErrorMessage(unsigned char errcode)
475 if (errcode >= NUM_ERROR_MESSAGES)
477 @@ -790,7 +790,7 @@ static void create_channel_config(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *h
481 -void NEAACDECAPI *NeAACDecDecode(NeAACDecHandle hpDecoder,
482 +void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hpDecoder,
483 NeAACDecFrameInfo *hInfo,
484 unsigned char *buffer,
485 unsigned long buffer_size)
486 @@ -799,7 +799,7 @@ void NEAACDECAPI *NeAACDecDecode(NeAACDecHandle hpDecoder,
487 return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0);
490 -void NEAACDECAPI *NeAACDecDecode2(NeAACDecHandle hpDecoder,
491 +void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hpDecoder,
492 NeAACDecFrameInfo *hInfo,
493 unsigned char *buffer,
494 unsigned long buffer_size,
495 diff --git a/libfaad/lt_predict.c b/libfaad/lt_predict.c
496 index 2be18ae..aa02fb0 100644
497 --- a/libfaad/lt_predict.c
498 +++ b/libfaad/lt_predict.c
499 @@ -166,7 +166,7 @@ static INLINE int16_t real_to_int16(real_t sig_in)
503 - return lrintf(sig_in);
504 + return FAAD_lrintf(sig_in);
508 diff --git a/libfaad/output.c b/libfaad/output.c
509 index 4245627..1aeb747 100644
510 --- a/libfaad/output.c
511 +++ b/libfaad/output.c
512 @@ -103,7 +103,7 @@ static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
514 CLIP(inp, 32767.0f, -32768.0f);
516 - (*sample_buffer)[i] = (int16_t)lrintf(inp);
517 + (*sample_buffer)[i] = (int16_t)FAAD_lrintf(inp);
521 @@ -116,8 +116,8 @@ static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
523 CLIP(inp0, 32767.0f, -32768.0f);
525 - (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
526 - (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
527 + (*sample_buffer)[(i*2)+0] = (int16_t)FAAD_lrintf(inp0);
528 + (*sample_buffer)[(i*2)+1] = (int16_t)FAAD_lrintf(inp0);
531 ch = hDecoder->internal_channel[0];
532 @@ -130,8 +130,8 @@ static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
533 CLIP(inp0, 32767.0f, -32768.0f);
534 CLIP(inp1, 32767.0f, -32768.0f);
536 - (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
537 - (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
538 + (*sample_buffer)[(i*2)+0] = (int16_t)FAAD_lrintf(inp0);
539 + (*sample_buffer)[(i*2)+1] = (int16_t)FAAD_lrintf(inp1);
543 @@ -144,7 +144,7 @@ static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
545 CLIP(inp, 32767.0f, -32768.0f);
547 - (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
548 + (*sample_buffer)[(i*channels)+ch] = (int16_t)FAAD_lrintf(inp);
552 @@ -169,7 +169,7 @@ static void to_PCM_24bit(NeAACDecStruct *hDecoder, real_t **input,
554 CLIP(inp, 8388607.0f, -8388608.0f);
556 - (*sample_buffer)[i] = (int32_t)lrintf(inp);
557 + (*sample_buffer)[i] = (int32_t)FAAD_lrintf(inp);
561 @@ -183,8 +183,8 @@ static void to_PCM_24bit(NeAACDecStruct *hDecoder, real_t **input,
563 CLIP(inp0, 8388607.0f, -8388608.0f);
565 - (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
566 - (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
567 + (*sample_buffer)[(i*2)+0] = (int32_t)FAAD_lrintf(inp0);
568 + (*sample_buffer)[(i*2)+1] = (int32_t)FAAD_lrintf(inp0);
571 ch = hDecoder->internal_channel[0];
572 @@ -199,8 +199,8 @@ static void to_PCM_24bit(NeAACDecStruct *hDecoder, real_t **input,
573 CLIP(inp0, 8388607.0f, -8388608.0f);
574 CLIP(inp1, 8388607.0f, -8388608.0f);
576 - (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
577 - (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
578 + (*sample_buffer)[(i*2)+0] = (int32_t)FAAD_lrintf(inp0);
579 + (*sample_buffer)[(i*2)+1] = (int32_t)FAAD_lrintf(inp1);
583 @@ -214,7 +214,7 @@ static void to_PCM_24bit(NeAACDecStruct *hDecoder, real_t **input,
585 CLIP(inp, 8388607.0f, -8388608.0f);
587 - (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
588 + (*sample_buffer)[(i*channels)+ch] = (int32_t)FAAD_lrintf(inp);
592 @@ -239,7 +239,7 @@ static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
594 CLIP(inp, 2147483647.0f, -2147483648.0f);
596 - (*sample_buffer)[i] = (int32_t)lrintf(inp);
597 + (*sample_buffer)[i] = (int32_t)FAAD_lrintf(inp);
601 @@ -253,8 +253,8 @@ static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
603 CLIP(inp0, 2147483647.0f, -2147483648.0f);
605 - (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
606 - (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
607 + (*sample_buffer)[(i*2)+0] = (int32_t)FAAD_lrintf(inp0);
608 + (*sample_buffer)[(i*2)+1] = (int32_t)FAAD_lrintf(inp0);
611 ch = hDecoder->internal_channel[0];
612 @@ -269,8 +269,8 @@ static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
613 CLIP(inp0, 2147483647.0f, -2147483648.0f);
614 CLIP(inp1, 2147483647.0f, -2147483648.0f);
616 - (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
617 - (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
618 + (*sample_buffer)[(i*2)+0] = (int32_t)FAAD_lrintf(inp0);
619 + (*sample_buffer)[(i*2)+1] = (int32_t)FAAD_lrintf(inp1);
623 @@ -284,7 +284,7 @@ static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
625 CLIP(inp, 2147483647.0f, -2147483648.0f);
627 - (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
628 + (*sample_buffer)[(i*channels)+ch] = (int32_t)FAAD_lrintf(inp);