OSDN Git Service

Updated OggEnc2 binaries to v2.87 using libvorbis v1.3.5 and aoTuV v6.03_2015 (2014...
[lamexp/LameXP.git] / etc / Patches / fhgaacenc-Git20120806-DLLPath.diff
1  fhgaacenc.sln           |    6 ++---
2  fhgaacenc/common.h      |    3 ++-
3  fhgaacenc/fhgaacenc.cpp |   67 +++++++++++++++++++++++++++++++++++++++--------
4  3 files changed, 61 insertions(+), 15 deletions(-)
5
6 diff --git a/fhgaacenc/common.h b/fhgaacenc/common.h
7 index e7221be..b7d1bf7 100644
8 --- a/fhgaacenc/common.h
9 +++ b/fhgaacenc/common.h
10 @@ -6,7 +6,7 @@
11  
12  #pragma once
13  
14 -#define VERSION 20120624
15 +#define VERSION 20120806
16  
17  #ifdef _MSC_VER
18  #define fseeko _fseeki64
19 @@ -34,6 +34,7 @@ typedef struct
20  {
21         _TCHAR *inFile;
22         _TCHAR *outFile;
23 +       _TCHAR *dllFile;
24         codecMode mode;
25         int modeQuality;
26         codecProfile profile;
27 diff --git a/fhgaacenc/fhgaacenc.cpp b/fhgaacenc/fhgaacenc.cpp
28 index 1ee1036..a817f17 100644
29 --- a/fhgaacenc/fhgaacenc.cpp
30 +++ b/fhgaacenc/fhgaacenc.cpp
31 @@ -8,6 +8,8 @@
32  #include "common.h"
33  #include "FhGAACEncoder.h"
34  
35 +typedef BOOL (WINAPI *SetDllDirectoryFun)(__in_opt LPCWSTR lpPathName);
36 +
37  bool getPathForWinAmp(_TCHAR *path, unsigned int length)
38  {
39         if(!path) return false;
40 @@ -45,6 +47,7 @@ static void printUsage(void)
41         fprintf(stderr,"  Other options \n");
42         fprintf(stderr,"\t--ignorelength : ignore the size of data chunk when encoding from pipe\n");
43         fprintf(stderr,"\t--quiet        : don't print the progress\n");
44 +       fprintf(stderr,"\t--dll <path>   : overwrite path to the \"enc_fhgaac.dll\" library\n");
45  }
46  
47  static void replaceSlashWithBackSlash(_TCHAR *str)
48 @@ -60,6 +63,11 @@ static int parseArguments(int argc, _TCHAR* argv[], encodingParameters *params)
49         int i;
50         for(i=1;i<argc;i++) {
51                 if(!_tcscmp(argv[i],_T("--quiet"))) params->quiet = true;
52 +               else if(!_tcscmp(argv[i],_T("--dll"))) {
53 +                       if(++i<argc) {
54 +                               params->dllFile = argv[i];
55 +                       }
56 +               }
57                 else if(!_tcscmp(argv[i],_T("--cbr"))) {
58                         params->mode = kModeCBR;
59                         if(++i<argc) {
60 @@ -111,16 +119,51 @@ int _tmain(int argc, _TCHAR* argv[])
61  {
62         _tsetlocale(LC_ALL, _T(""));
63  
64 -       if(argc==1) {
65 +       if(argc<2) {
66 +               printUsage();
67 +               return 0;
68 +       }
69 +
70 +       encodingParameters params;
71 +       memset(&params,0,sizeof(encodingParameters));
72 +       params.modeQuality = 4;
73 +       if(parseArguments(argc, argv, &params)) {
74 +               if(argc>1)fprintf(stderr,"Error while parsing arguments\n");
75                 printUsage();
76                 return 0;
77         }
78  
79 -       HMODULE h = LoadLibrary(_T("enc_fhgaac.dll"));
80 +       fprintf(stderr,"fhgaacenc version %d by tmkk\n\n", VERSION);
81 +
82 +       SetDllDirectoryFun SetDllDirectoryPtr = NULL;
83 +       HMODULE hKernel32 = GetModuleHandle(L"kernel32.dll");
84 +       if(hKernel32 != NULL)
85 +       {
86 +               SetDllDirectoryPtr = (SetDllDirectoryFun) GetProcAddress(hKernel32, "SetDllDirectoryW");
87 +               if(SetDllDirectoryPtr != NULL) SetDllDirectoryPtr(L"");
88 +       }
89 +       
90 +       if((params.dllFile != NULL) && (SetDllDirectoryPtr != NULL))
91 +       {
92 +               _TCHAR tmp[MAX_PATH+1];
93 +               wcsncpy(tmp, params.dllFile, MAX_PATH+1);
94 +               tmp[MAX_PATH] = L'\0';
95 +               size_t len = wcslen(tmp);
96 +               if(len > 0)
97 +               {
98 +                       for(size_t i = len-1; i > 0; i--)
99 +                       {
100 +                               if((tmp[i] == L'\\') || (tmp[i] == L'/')) { tmp[i] = L'\0'; break; }
101 +                       }
102 +               }
103 +               if(wcslen(tmp) > 0) SetDllDirectoryPtr(tmp);
104 +       }
105 +
106 +       HMODULE h = LoadLibrary((params.dllFile != NULL) ? params.dllFile : _T("enc_fhgaac.dll"));
107         if(!h) {
108                 _TCHAR tmp[MAX_PATH+1];
109                 if(getPathForWinAmp(tmp,MAX_PATH+1)) {
110 -                       SetDllDirectory(tmp);
111 +                       if(SetDllDirectoryPtr != NULL) SetDllDirectoryPtr(tmp);
112                         _sntprintf_s(tmp,MAX_PATH+1,_TRUNCATE,_T("%s\\Plugins\\enc_fhgaac.dll"),tmp);
113                         h = LoadLibrary(tmp);
114                 }
115 @@ -130,6 +173,16 @@ int _tmain(int argc, _TCHAR* argv[])
116                 }
117         }
118  
119 +       if(h)
120 +       {
121 +               _TCHAR tmp[MAX_PATH+1];
122 +               DWORD ret = GetModuleFileName(h, tmp, MAX_PATH+1);
123 +               if((ret > 0) && ret <= MAX_PATH)
124 +               {
125 +                       fwprintf(stderr, L"Using encoder DLL:\n%s\n\n", tmp);
126 +               }
127 +       }
128 +
129         FhGAACEncoder *fhgenc = new FhGAACEncoder();
130  
131         *(void **)&(fhgenc->createAudio3) = (void *)GetProcAddress(h, "CreateAudio3");
132 @@ -147,14 +200,6 @@ int _tmain(int argc, _TCHAR* argv[])
133                 return 0;
134         }
135  
136 -       encodingParameters params;
137 -       memset(&params,0,sizeof(encodingParameters));
138 -       params.modeQuality = 4;
139 -       if(parseArguments(argc, argv, &params)) {
140 -               if(argc>1)fprintf(stderr,"Error while parsing arguments\n");
141 -               printUsage();
142 -               return 0;
143 -       }
144         /*
145         if(params.mode == kModeVBR && params.adtsMode) {
146                 fprintf(stderr,"Error: only CBR is supported in ADTS AAC encoder.\n");