shithub: aacenc

Download patch

ref: 9e1393efa662f09abfe09242e13a34e33330d137
parent: dde8b0caba069abd0e1b3cbc0ed7f5c25eb1a8ff
author: Michael Fink <michael.fink@asamnet.de>
date: Thu Sep 26 16:23:03 EDT 2019

ported over ac2ver tool to generate PACKAGE_VERSION when compiling with Visual Studio

diff: cannot open b/utils/win32//null: file does not exist: 'b/utils/win32//null' diff: cannot open b/utils//null: file does not exist: 'b/utils//null'
--- a/.gitignore
+++ b/.gitignore
@@ -36,3 +36,4 @@
 /project/msvc/bin/
 /project/msvc/intermediate/
 *.user
+/libfaac/win32_ver.h
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -32,6 +32,10 @@
 #include "tns.h"
 #include "stereo.h"
 
+#if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined(PACKAGE_VERSION)
+#include "win32_ver.h"
+#endif
+
 static char *libfaacName = PACKAGE_VERSION;
 static char *libCopyright =
   "FAAC - Freeware Advanced Audio Coder (http://faac.sourceforge.net/)\n"
@@ -220,7 +224,7 @@
 			hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
 			hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
 			hEncoder->srInfo->num_cb_short);
-	
+
 	/* load channel_map */
 	for( i = 0; i < MAX_CHANNELS; i++ )
 		hEncoder->config.channel_map[i] = config->channel_map[i];
@@ -291,7 +295,7 @@
     /* find correct sampling rate depending parameters */
     hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];
 
-    for (channel = 0; channel < numChannels; channel++) 
+    for (channel = 0; channel < numChannels; channel++)
 	{
         hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
         hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
@@ -306,7 +310,7 @@
 
     /* Initialize coder functions */
 	fft_initialize( &hEncoder->fft_tables );
-    
+
 	hEncoder->psymodel->PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
         hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
         hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
@@ -333,7 +337,7 @@
     fft_terminate(&hEncoder->fft_tables);
 
     /* Free remaining buffer memory */
-    for (channel = 0; channel < hEncoder->numChannels; channel++) 
+    for (channel = 0; channel < hEncoder->numChannels; channel++)
 	{
 		if (hEncoder->sampleBuff[channel])
 			FreeMemory(hEncoder->sampleBuff[channel]);
@@ -346,7 +350,7 @@
     }
 
     /* Free handle */
-    if (hEncoder) 
+    if (hEncoder)
 		FreeMemory(hEncoder);
 
     BlocStat();
@@ -397,7 +401,7 @@
     GetChannelInfo(channelInfo, numChannels, useLfe);
 
     /* Update current sample buffers */
-    for (channel = 0; channel < numChannels; channel++) 
+    for (channel = 0; channel < numChannels; channel++)
 	{
 		double *tmp;
 
@@ -404,7 +408,7 @@
 
 		if (!hEncoder->sampleBuff[channel])
 			hEncoder->sampleBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
-		
+
 		tmp = hEncoder->sampleBuff[channel];
 
         hEncoder->sampleBuff[channel]		= hEncoder->nextSampleBuff[channel];
@@ -440,7 +444,7 @@
                 case FAAC_INPUT_32BIT:
 					{
 						int32_t *input_channel = (int32_t*)inputBuffer + hEncoder->config.channel_map[channel];
-						
+
 						for (i = 0; i < samples_per_channel; i++)
 						{
 							hEncoder->next3SampleBuff[channel][i] = (1.0/256) * (double)*input_channel;
@@ -475,11 +479,11 @@
 		/* LFE psychoacoustic can run without it */
 		if (!channelInfo[channel].lfe || channelInfo[channel].cpe)
 		{
-			hEncoder->psymodel->PsyBufferUpdate( 
-					&hEncoder->fft_tables, 
-					&hEncoder->gpsyInfo, 
+			hEncoder->psymodel->PsyBufferUpdate(
+					&hEncoder->fft_tables,
+					&hEncoder->gpsyInfo,
 					&hEncoder->psyInfo[channel],
-					hEncoder->next3SampleBuff[channel], 
+					hEncoder->next3SampleBuff[channel],
 					bandWidth,
 					hEncoder->srInfo->cb_width_short,
 					hEncoder->srInfo->num_cb_short);
--- a/project/msvc/libfaac.vcxproj
+++ b/project/msvc/libfaac.vcxproj
@@ -60,6 +60,10 @@
     <Lib>
       <SuppressStartupBanner>true</SuppressStartupBanner>
     </Lib>
+    <PreBuildEvent>
+      <Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
+      <Message>Retrieving package version...</Message>
+    </PreBuildEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -76,6 +80,10 @@
     <Lib>
       <SuppressStartupBanner>true</SuppressStartupBanner>
     </Lib>
+    <PreBuildEvent>
+      <Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
+      <Message>Retrieving package version...</Message>
+    </PreBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\..\libfaac\bitstream.c" />
@@ -107,7 +115,7 @@
     <ClInclude Include="..\..\libfaac\stereo.h" />
     <ClInclude Include="..\..\libfaac\tns.h" />
     <ClInclude Include="..\..\libfaac\util.h" />
-    <ClInclude Include="..\..\libfaac\version.h" />
+    <ClInclude Include="..\..\libfaac\win32_ver.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
--- a/project/msvc/libfaac.vcxproj.filters
+++ b/project/msvc/libfaac.vcxproj.filters
@@ -79,9 +79,6 @@
     <ClInclude Include="..\..\libfaac\util.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\..\libfaac\version.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="..\..\include\faac.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -95,6 +92,9 @@
       <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\..\libfaac\stereo.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\libfaac\win32_ver.h">
       <Filter>Header Files</Filter>
     </ClInclude>
   </ItemGroup>
--- a/project/msvc/libfaac_dll.vcxproj
+++ b/project/msvc/libfaac_dll.vcxproj
@@ -66,6 +66,10 @@
       <ModuleDefinitionFile>.\libfaac.def</ModuleDefinitionFile>
       <TargetMachine>MachineX86</TargetMachine>
     </Link>
+    <PreBuildEvent>
+      <Message>Retrieving package version...</Message>
+      <Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
+    </PreBuildEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -86,6 +90,10 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <TargetMachine>MachineX86</TargetMachine>
     </Link>
+    <PreBuildEvent>
+      <Message>Retrieving package version...</Message>
+      <Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
+    </PreBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\..\libfaac\bitstream.c" />
@@ -117,6 +125,7 @@
     <ClInclude Include="..\..\libfaac\stereo.h" />
     <ClInclude Include="..\..\libfaac\tns.h" />
     <ClInclude Include="..\..\libfaac\util.h" />
+    <ClInclude Include="..\..\libfaac\win32_ver.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="libfaac.def" />
--- a/project/msvc/libfaac_dll.vcxproj.filters
+++ b/project/msvc/libfaac_dll.vcxproj.filters
@@ -94,6 +94,9 @@
     <ClInclude Include="..\..\libfaac\stereo.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\libfaac\win32_ver.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="libfaac.def">
--- a/project/msvc/libfaac_dll_drm.vcxproj
+++ b/project/msvc/libfaac_dll_drm.vcxproj
@@ -67,6 +67,10 @@
       <TargetMachine>MachineX86</TargetMachine>
       <ImportLibrary>$(OutDir)libfaacdrm.lib</ImportLibrary>
     </Link>
+    <PreBuildEvent>
+      <Message>Retrieving package version...</Message>
+      <Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
+    </PreBuildEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -88,6 +92,10 @@
       <TargetMachine>MachineX86</TargetMachine>
       <ImportLibrary>$(OutDir)libfaacdrm.lib</ImportLibrary>
     </Link>
+    <PreBuildEvent>
+      <Message>Retrieving package version...</Message>
+      <Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
+    </PreBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\..\libfaac\bitstream.c" />
@@ -125,7 +133,7 @@
     <ClInclude Include="..\..\libfaac\stereo.h" />
     <ClInclude Include="..\..\libfaac\tns.h" />
     <ClInclude Include="..\..\libfaac\util.h" />
-    <ClInclude Include="..\..\libfaac\version.h" />
+    <ClInclude Include="..\..\libfaac\win32_ver.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="libfaac.def" />
--- a/project/msvc/libfaac_dll_drm.vcxproj.filters
+++ b/project/msvc/libfaac_dll_drm.vcxproj.filters
@@ -118,6 +118,9 @@
     <ClInclude Include="..\..\libfaac\stereo.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\libfaac\win32_ver.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="libfaac.def">
--- /dev/null
+++ b/utils/win32/ac2ver.c
@@ -1,0 +1,103 @@
+/*
+** AC2VER - extract version number from AC_INIT macro (configure.ac)
+** Copyright (C) 2017 LoRd_MuldeR <mulder2@GMX.de>
+**  
+** This software is released under the CC0 1.0 Universal [CC0 1.0] licence!
+** https://creativecommons.org/publicdomain/zero/1.0/legalcode
+**/
+
+#define BUFF_SIZE 4096
+#define _CRT_SECURE_NO_WARNINGS 1
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+static int clean_string(char *const str)
+{
+	size_t i = 0, j = 0;
+	while(str[i])
+	{
+		if(isalnum(str[i]) || strchr("._-", str[i]))
+		{
+			if(i != j)
+			{
+				str[j] = str[i];
+			}
+			++j;
+		}
+		++i;
+	}
+	str[j] = '\0';
+	return !!j;
+}
+
+static int parse_version(FILE *const input, const char *const format, char *const version)
+{
+	char buffer[BUFF_SIZE];
+
+	while(!(feof(input) || ferror(input)))
+	{
+		const char *line = fgets(buffer, BUFF_SIZE, input);
+		if(line)
+		{
+			while((*line) && (isspace(*line)))
+			{
+				++line; /*skip space*/
+			}
+			if(sscanf(line, format, version) == 1)
+			{
+				if(clean_string(version))
+				{
+					return 1; /*found!*/
+				}
+			}
+		}
+	}
+
+	version[0] = '\0';
+	return 0;
+}
+
+static int get_version(const wchar_t *const lib_name, const wchar_t *const file_name)
+{
+	char format[128], version[BUFF_SIZE];
+
+	FILE *const input = _wfopen(file_name, L"r");
+	if(!input)
+	{
+		fprintf(stderr, "Error: Failed to open input file!\n%S\n\n", file_name);
+		return 0;
+	}
+
+	_snprintf(format, 128, "AC_INIT ( %S , %%s", lib_name);
+	//printf("<%s>\n", format);
+
+	if(parse_version(input, format, version))
+	{
+		printf("#define PACKAGE_VERSION \"%s\"\n", version);
+		fclose(input);
+		return 1;
+	}
+	else
+	{
+		fprintf(stderr, "Error: Version string could not be found!\n\n");
+		fclose(input);
+		return 0;
+	}
+}
+
+int wmain(int argc, wchar_t* argv[])
+{
+	if((argc != 3) || (!argv[1][0]) || (!argv[2][0]))
+	{
+		wchar_t file_name[_MAX_FNAME], file_ext[_MAX_EXT];
+		_wsplitpath(argv[0], NULL, NULL, file_name, file_ext);
+		fprintf(stderr, "AC2VER [%s]\n\n", __DATE__);
+		fprintf(stderr, "Usage: %S%S <lib_name> <path/to/configure.ac>\n\n", file_name, file_ext);
+		return EXIT_FAILURE;
+	}
+
+	return get_version(argv[1], argv[2]) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
binary files /dev/null b/utils/win32/ac2ver.exe differ