improve DLL export

This commit is contained in:
Christian R. Helmrich 2020-01-26 16:00:49 +01:00
parent ea83d1b439
commit 7d115dcc3c
6 changed files with 70 additions and 48 deletions

View File

@ -71,6 +71,9 @@ edit the "Command Arguments" entry on the right-hand side as needed.
For fastest encoding speed, please select `Release` and `x64` before
building the solution. This will create a release-mode 64-bit binary.
If you would like to build a dynamically linked library (DLL) of the
exhale source instead of an application binary, select `Release DLL`
instead of `Release`, rightclick on `exhaleLib`, and select `Build`.
Usage

View File

@ -32,6 +32,7 @@
<li><h3>compilation fixes and executable printout changes for Linux and MacOS&trade; platform</h3></li>
<li><h3>exhaleApp: fixed reading of WAVE files including metadata after the &laquo;data&raquo; chunk</h3></li>
<li><h3>exhaleLib: some tuning of transform and noise level detection for transient signals</h3></li>
<li><h3>exhaleLib: support for export as DLL on Microsoft Windows&trade; (not tested, though)</h3></li>
</ul>
<h3>&nbsp; &nbsp;Version <b>1.0RC <span class="gray">Dec. 2019</span></b></h3>
<ul>
@ -48,7 +49,6 @@
<h3>&nbsp; &nbsp;If you are in need of an additional library or application feature <b>not</b> mentioned below, please contact ecodis or a contributor with a request, and we will see what we can do.</h3>
<ul>
<li><h3>support for MPEG-D DRC-style peak-level and loudness metadata, no version plan</h3></li>
<li><h3>support for compiling as dynamically linked library on Windows&trade;, no version plan</h3></li>
<li><h3>support for coding with a core coder frame length of 768 samples, no version plan</h3></li>
<li><h3>exhaleLib: quality tuning and bug fixing for low-bitrate mono coding, version 1.0.1</h3></li>
<li><h3>exhaleLib: finalized integration of joint-channel coding functionality, version 1.0.2</h3></li>

View File

@ -11,22 +11,41 @@
#ifndef _EXHALE_DECL_H_
#define _EXHALE_DECL_H_
#include "../src/lib/exhaleEnc.h"
#include <stdint.h> // for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t
// DLL constructor
extern "C" EXHALE_DECL ExhaleEncoder* exhaleCreate (int32_t* const, unsigned char* const, const unsigned, const unsigned,
const unsigned, const unsigned, const unsigned, const bool, const bool);
#if defined (_WIN32) || defined (WIN32) || defined (_WIN64) || defined (WIN64)
# ifdef EXHALE_DYN_LINK
# define EXHALE_DECL __declspec (dllexport)
# else
# define EXHALE_DECL __declspec (dllimport)
# endif
#else
# define EXHALE_DECL
#endif
// DLL destructor
extern "C" EXHALE_DECL unsigned exhaleDelete (ExhaleEncoder*);
struct ExhaleEncAPI
{
// initializer
virtual unsigned initEncoder (unsigned char* const audioConfigBuffer, uint32_t* const audioConfigBytes = nullptr) = 0;
// lookahead encoder
virtual unsigned encodeLookahead () = 0;
// frame encoder
virtual unsigned encodeFrame () = 0;
};
// DLL initializer
extern "C" EXHALE_DECL unsigned exhaleInitEncoder (ExhaleEncoder*, unsigned char* const, uint32_t* const);
// C constructor
extern "C" EXHALE_DECL ExhaleEncAPI* exhaleCreate (int32_t* const, unsigned char* const, const unsigned, const unsigned,
const unsigned, const unsigned, const unsigned, const bool, const bool);
// C destructor
extern "C" EXHALE_DECL unsigned exhaleDelete (ExhaleEncAPI*);
// DLL lookahead encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeLookahead (ExhaleEncoder*);
// C initializer
extern "C" EXHALE_DECL unsigned exhaleInitEncoder (ExhaleEncAPI*, unsigned char* const, uint32_t* const);
// DLL frame encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeFrame (ExhaleEncoder*);
// C lookahead encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeLookahead (ExhaleEncAPI*);
// C frame encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeFrame (ExhaleEncAPI*);
#endif // _EXHALE_DECL_H_

View File

@ -11,7 +11,12 @@
#include "exhaleAppPch.h"
#include "basicMP4Writer.h"
#include "basicWavReader.h"
// #define USE_EXHALELIB_DLL (defined (_WIN32) || defined (WIN32) || defined (_WIN64) || defined (WIN64))
#ifdef USE_EXHALELIB_DLL
#include "exhaleDecl.h"
#else
#include "../lib/exhaleEnc.h"
#endif
#include "version.h"
#include <iostream>
@ -178,9 +183,9 @@ int main (const int argc, char* argv[])
else
{
#if XHE_AAC_LOW_DELAY
fprintf_s (stderr, " ERROR reading preset mode: character %s is not supported! Use 1-9, a-i, or A-I.\n\n", argv[1]);
fprintf_s (stderr, " ERROR reading preset mode: character %s is not supported! Use 1-9 or A-I.\n\n", argv[1]);
#else
fprintf_s (stderr, " ERROR reading preset mode: character %s is not supported! Use 1-9 or a-i.\n\n", argv[1]);
fprintf_s (stderr, " ERROR reading preset mode: character %s is not supported! Please use 1-9.\n\n", argv[1]);
#endif
return 16384; // preset isn't supported
}
@ -354,10 +359,14 @@ int main (const int argc, char* argv[])
const unsigned sampleRate = wavReader.getSampleRate ();
const unsigned indepPeriod = (sampleRate < 48000 ? sampleRate / frameLength : 45 /*for 50-Hz video, use 50 for 60-Hz video*/);
const unsigned mod3Percent = unsigned ((expectLength * (3 + coreSbrFrameLengthIndex)) >> 17);
// open & prepare ExhaleEncoder object
uint32_t byteCount = 0, bw = 0, bwMax = 0, br; // for bytes read and bit-rate
uint32_t headerRes = 0;
// open & prepare ExhaleEncoder object
#ifdef USE_EXHALELIB_DLL
ExhaleEncAPI& exhaleEnc = *exhaleCreate (inPcmData, outAuData, sampleRate, numChannels, frameLength, indepPeriod, variableCoreBitRateMode +
#else
ExhaleEncoder exhaleEnc (inPcmData, outAuData, sampleRate, numChannels, frameLength, indepPeriod, variableCoreBitRateMode +
#endif
(sampleRate > 24000 ? 0 : 1 - (variableCoreBitRateMode >> 2)) // compensate for low sampling rates
#if !RESTRICT_TO_AAC
, true /*noise filling*/, compatibleExtensionFlag > 0

View File

@ -11,6 +11,7 @@
#ifndef _EXHALE_ENC_H_
#define _EXHALE_ENC_H_
#include "exhaleDecl.h"
#include "exhaleLibPch.h"
#include "bitAllocation.h"
#include "bitStreamWriter.h"
@ -22,16 +23,6 @@
#include "specGapFilling.h"
#include "tempAnalysis.h"
#if defined (_WIN32) || defined (WIN32) || defined (_WIN64) || defined (WIN64)
# ifdef EXHALE_DYN_LINK
# define EXHALE_DECL __declspec (dllexport)
# else
# define EXHALE_DECL
# endif
#else
# define EXHALE_DECL
#endif
// constant and experimental macro
#define WIN_SCALE double (1 << 23)
#define EE_OPT_TNS_SPEC_RANGE 1
@ -66,7 +57,7 @@ typedef enum USAC_CCFL : short
} USAC_CCFL;
// overall xHE-AAC encoding class
class EXHALE_DECL ExhaleEncoder
class ExhaleEncoder : public ExhaleEncAPI
{
private:
@ -151,12 +142,12 @@ public:
}; // ExhaleEncoder
#ifdef EXHALE_DYN_LINK
// DLL constructor
extern "C" EXHALE_DECL ExhaleEncoder* exhaleCreate (int32_t* const inputPcmData, unsigned char* const outputAuData,
const unsigned sampleRate = 44100, const unsigned numChannels = 2,
const unsigned frameLength = 1024, const unsigned indepPeriod = 45,
const unsigned varBitRateMode = 3, const bool useNoiseFilling = true,
const bool useEcodisExt = false)
// C constructor
extern "C" EXHALE_DECL ExhaleEncAPI* exhaleCreate (int32_t* const inputPcmData, unsigned char* const outputAuData,
const unsigned sampleRate = 44100, const unsigned numChannels = 2,
const unsigned frameLength = 1024, const unsigned indepPeriod = 45,
const unsigned varBitRateMode = 3, const bool useNoiseFilling = true,
const bool useEcodisExt = false)
{
return new ExhaleEncoder (inputPcmData, outputAuData, sampleRate, numChannels, frameLength, indepPeriod, varBitRateMode
#if !RESTRICT_TO_AAC
@ -165,38 +156,38 @@ extern "C" EXHALE_DECL ExhaleEncoder* exhaleCreate (int32_t* const inputPcmData,
);
}
// DLL destructor
extern "C" EXHALE_DECL unsigned exhaleDelete (ExhaleEncoder* exhaleEnc)
// C destructor
extern "C" EXHALE_DECL unsigned exhaleDelete (ExhaleEncAPI* exhaleEnc)
{
if (exhaleEnc != nullptr) { exhaleEnc->~ExhaleEncoder (); return 0; }
if (exhaleEnc != NULL) { delete exhaleEnc; return 0; }
return USHRT_MAX; // error
}
// DLL initializer
extern "C" EXHALE_DECL unsigned exhaleInitEncoder (ExhaleEncoder* exhaleEnc, unsigned char* const audioConfigBuffer,
// C initializer
extern "C" EXHALE_DECL unsigned exhaleInitEncoder (ExhaleEncAPI* exhaleEnc, unsigned char* const audioConfigBuffer,
uint32_t* const audioConfigBytes = nullptr)
{
if (exhaleEnc != nullptr) return exhaleEnc->initEncoder (audioConfigBuffer, audioConfigBytes);
if (exhaleEnc != NULL) return exhaleEnc->initEncoder (audioConfigBuffer, audioConfigBytes);
return USHRT_MAX; // error
}
// DLL lookahead encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeLookahead (ExhaleEncoder* exhaleEnc)
// C lookahead encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeLookahead (ExhaleEncAPI* exhaleEnc)
{
if (exhaleEnc != nullptr) return exhaleEnc->encodeLookahead ();
if (exhaleEnc != NULL) return exhaleEnc->encodeLookahead ();
return USHRT_MAX; // error
}
// DLL frame encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeFrame (ExhaleEncoder* exhaleEnc)
// C frame encoder
extern "C" EXHALE_DECL unsigned exhaleEncodeFrame (ExhaleEncAPI* exhaleEnc)
{
if (exhaleEnc != nullptr) return exhaleEnc->encodeFrame ();
if (exhaleEnc != NULL) return exhaleEnc->encodeFrame ();
return USHRT_MAX; // error
}
#endif
#endif // EXHALE_DYN_LINK
#endif // _EXHALE_ENC_H_

View File

@ -192,7 +192,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>exhaleLibPch.h</PrecompiledHeaderFile>
<PreprocessorDefinitions>WIN32;NDEBUG;EXHALE_DYN_LINK;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWarningAsError>false</TreatWarningAsError>
<TreatWarningAsError>true</TreatWarningAsError>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
@ -211,7 +211,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>exhaleLibPch.h</PrecompiledHeaderFile>
<PreprocessorDefinitions>WIN32;NDEBUG;EXHALE_DYN_LINK;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWarningAsError>false</TreatWarningAsError>
<TreatWarningAsError>true</TreatWarningAsError>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>