commit 9dd141c0313050f6ebb19b66ef6473c29e9b209c Author: Dmytro Bogovych Date: Thu Jun 28 18:06:51 2018 +0300 - initial import diff --git a/crashrpt/bin/CrashSender1403.exe b/crashrpt/bin/CrashSender1403.exe new file mode 100644 index 0000000..2a8c81f Binary files /dev/null and b/crashrpt/bin/CrashSender1403.exe differ diff --git a/crashrpt/bin/crashrpt_lang.ini b/crashrpt/bin/crashrpt_lang.ini new file mode 100644 index 0000000..e276530 Binary files /dev/null and b/crashrpt/bin/crashrpt_lang.ini differ diff --git a/crashrpt/bin/dbghelp.dll b/crashrpt/bin/dbghelp.dll new file mode 100644 index 0000000..25520df Binary files /dev/null and b/crashrpt/bin/dbghelp.dll differ diff --git a/crashrpt/include/CrashRpt.h b/crashrpt/include/CrashRpt.h new file mode 100644 index 0000000..f86a1c8 --- /dev/null +++ b/crashrpt/include/CrashRpt.h @@ -0,0 +1,1805 @@ +/************************************************************************************* +This file is a part of CrashRpt library. +Copyright (c) 2003-2013 The CrashRpt project authors. All Rights Reserved. + +Use of this source code is governed by a BSD-style license +that can be found in the License.txt file in the root of the source +tree. All contributing project authors may +be found in the Authors.txt file in the root of the source tree. +***************************************************************************************/ + +/*! \file CrashRpt.h +* \brief Defines the interface for the CrashRpt.DLL. +* \date 2003 +* \author Michael Carruth +* \author Oleg Krivtsov (zeXspectrum) +*/ + +#ifndef _CRASHRPT_H_ +#define _CRASHRPT_H_ + +#include +#include + +// Define SAL macros to be empty if some old Visual Studio used +#ifndef __reserved +#define __reserved +#endif +#ifndef __in +#define __in +#endif +#ifndef __in_opt +#define __in_opt +#endif +#ifndef __out_ecount_z +#define __out_ecount_z(x) +#endif + +#ifdef __cplusplus +#define CRASHRPT_EXTERNC extern "C" +#else +#define CRASHRPT_EXTERNC +#endif + +#define CRASHRPTAPI(rettype) CRASHRPT_EXTERNC rettype WINAPI + +//! Current CrashRpt version +#define CRASHRPT_VER 1403 + +/*! \defgroup CrashRptAPI CrashRpt Functions */ +/*! \defgroup DeprecatedAPI Obsolete Functions */ +/*! \defgroup CrashRptStructs CrashRpt Structures */ +/*! \defgroup CrashRptWrappers CrashRpt Wrapper Classes */ + +/*! \ingroup DeprecatedAPI +* \brief Client crash callback function prototype +* \param[in] lpvState Must be set to NULL. +* +* \remarks +* +* This function is deprecated, it is recommended to use \ref PFNCRASHCALLBACK() +* instead. +* +* The crash callback function is called when crash occurs. This way client application is +* notified about the crash. +* +* It is generally unsafe to do complex actions (e.g. memory allocation, heap operations) inside of this callback. +* The application state may be unstable. +* +* One reason the application may use this callback for is to close handles to open log files that the +* application plans to include into the error report. Files should be accessible for reading, otherwise +* CrashRpt won't be able to include them into error report. +* +* It is also possible (but not recommended) to add files, properties, desktop screenshots, +* registry keys inside of the crash callback function. +* +* The crash callback function should typically return \c TRUE to allow generate error report. +* Returning \c FALSE will prevent crash report generation. +* +* The following example shows how to use the crash callback function. +* +* \code +* // define the crash callback +* BOOL CALLBACK CrashCallback(LPVOID lpvState) +* { +* // Do something... +* +* return TRUE; +* } +* \endcode +* +* \sa crAddFile2(), PFNCRASHCALLBACK() +*/ +typedef BOOL (CALLBACK *LPGETLOGFILE) (__reserved LPVOID lpvState); + +// Exception types used in CR_EXCEPTION_INFO::exctype structure member. +#define CR_SEH_EXCEPTION 0 //!< SEH exception. +#define CR_CPP_TERMINATE_CALL 1 //!< C++ terminate() call. +#define CR_CPP_UNEXPECTED_CALL 2 //!< C++ unexpected() call. +#define CR_CPP_PURE_CALL 3 //!< C++ pure virtual function call (VS .NET and later). +#define CR_CPP_NEW_OPERATOR_ERROR 4 //!< C++ new operator fault (VS .NET and later). +#define CR_CPP_SECURITY_ERROR 5 //!< Buffer overrun error (VS .NET only). +#define CR_CPP_INVALID_PARAMETER 6 //!< Invalid parameter exception (VS 2005 and later). +#define CR_CPP_SIGABRT 7 //!< C++ SIGABRT signal (abort). +#define CR_CPP_SIGFPE 8 //!< C++ SIGFPE signal (flotating point exception). +#define CR_CPP_SIGILL 9 //!< C++ SIGILL signal (illegal instruction). +#define CR_CPP_SIGINT 10 //!< C++ SIGINT signal (CTRL+C). +#define CR_CPP_SIGSEGV 11 //!< C++ SIGSEGV signal (invalid storage access). +#define CR_CPP_SIGTERM 12 //!< C++ SIGTERM signal (termination request). + + +/*! \ingroup CrashRptStructs +* \brief This structure contains information about the crash. +* +* The information provided by this structure includes the exception type, exception code, +* exception pointers and so on. These are needed to generate crash minidump file and +* provide the developer with other information about the error. This structure is used by +* the crGenerateErrorReport() function. Pointer to this structure is also passed to the +* crash callback function (see the \ref PFNCRASHCALLBACK() function prototype). +* +* Structure members details are provided below: +* +* \b cb [in] +* +* This must contain the size of this structure in bytes. +* +* \b pexcptrs [in, optional] +* +* Should contain the exception pointers. If this parameter is NULL, +* the current CPU state is used to generate exception pointers. +* +* \b exctype [in] +* +* The type of exception. This parameter may be one of the following: +* - \ref CR_SEH_EXCEPTION SEH (Structured Exception Handling) exception +* - \ref CR_CPP_TERMINATE_CALL C++ terminate() function call +* - \ref CR_CPP_UNEXPECTED_CALL C++ unexpected() function call +* - \ref CR_CPP_PURE_CALL Pure virtual method call (Visual Studio .NET 2003 and later) +* - \ref CR_CPP_NEW_OPERATOR_ERROR C++ 'new' operator error (Visual Studio .NET 2003 and later) +* - \ref CR_CPP_SECURITY_ERROR Buffer overrun (Visual Studio .NET 2003 only) +* - \ref CR_CPP_INVALID_PARAMETER Invalid parameter error (Visual Studio 2005 and later) +* - \ref CR_CPP_SIGABRT C++ SIGABRT signal +* - \ref CR_CPP_SIGFPE C++ floating point exception +* - \ref CR_CPP_SIGILL C++ illegal instruction +* - \ref CR_CPP_SIGINT C++ SIGINT signal +* - \ref CR_CPP_SIGSEGV C++ invalid storage access +* - \ref CR_CPP_SIGTERM C++ termination request +* +* \b code [in, optional] +* +* Used if \a exctype is \ref CR_SEH_EXCEPTION and represents the SEH exception code. +* If \a pexptrs is NULL, this value is used when generating exception information for initializing +* \c pexptrs->ExceptionRecord->ExceptionCode member, otherwise it is ignored. +* +* \b fpe_subcode [in, optional] +* +* Used if \a exctype is equal to \ref CR_CPP_SIGFPE. It defines the floating point +* exception subcode (see \c signal() function ducumentation in MSDN). +* +* \b expression, \b function, \b file and \b line [in, optional] +* +* These parameters are used when \a exctype is \ref CR_CPP_INVALID_PARAMETER. +* These members are typically non-zero when using debug version of CRT. +* +* \b bManual [in] +* +* Since v.1.2.4, \a bManual parameter should be equal to TRUE if the report is generated manually. +* The value of \a bManual parameter affects the automatic application restart behavior. If the application +* restart is requested by the \ref CR_INST_APP_RESTART flag of CR_INSTALL_INFO::dwFlags structure member, +* and if \a bManual is FALSE, the application will be +* restarted after error report generation. If \a bManual is TRUE, the application won't be restarted. +* +* \b hSenderProcess [out] +* +* As of v.1.2.8, \a hSenderProcess parameter will contain the handle to the CrashSender.exe process when +* \ref crGenerateErrorReport function returns. The caller may use this handle to wait until CrashSender.exe +* process exits and check the exit code. When the handle is not needed anymore, release it with the \b CloseHandle() function. +*/ + +typedef struct tagCR_EXCEPTION_INFO +{ + WORD cb; //!< Size of this structure in bytes; should be initialized before using. + PEXCEPTION_POINTERS pexcptrs; //!< Exception pointers. + int exctype; //!< Exception type. + DWORD code; //!< Code of SEH exception. + unsigned int fpe_subcode; //!< Floating point exception subcode. + const wchar_t* expression; //!< Assertion expression. + const wchar_t* function; //!< Function in which assertion happened. + const wchar_t* file; //!< File in which assertion happened. + unsigned int line; //!< Line number. + BOOL bManual; //!< Flag telling if the error report is generated manually or not. + HANDLE hSenderProcess; //!< Handle to the CrashSender.exe process. +} +CR_EXCEPTION_INFO; + +typedef CR_EXCEPTION_INFO* PCR_EXCEPTION_INFO; + +// Stages of crash report generation (used by the crash callback function). +#define CR_CB_STAGE_PREPARE 10 //!< Stage after exception pointers've been retrieved. +#define CR_CB_STAGE_FINISH 20 //!< Stage after the launch of CrashSender.exe process. + +/*! \ingroup CrashRptStructs +* \struct CR_CRASH_CALLBACK_INFOW() +* \brief This structure contains information passed to crash callback function PFNCRASHCALLBACK(). +* +* \remarks +* +* The information contained in this structure may be used by the crash callback function +* to determine what type of crash has occurred and perform some action. For example, +* the client application may prefer to continue its execution on some type of crash, and +* terminate itself on another type of crash. +* +* Below, the stucture fields are described: +* +* \b cb [in] +* +* This contains the size of this structure in bytes. +* +* \b nStage [in] +* +* This field specifies the crash report generation stage. The callback function +* can be called once per each stage (depending on callback function's return value). +* Currently, there are two stages: +* - \ref CR_CB_STAGE_PREPARE Stage after exception pointers've been retrieved. +* - \ref CR_CB_STAGE_FINISH Stage after the launch of CrashSender.exe process. +* +* \b pszErrorReportFolder [in] +* +* This field contains the absolute path to the directory containing uncompressed +* crash report files. +* +* \b pExceptionInfo [in] +* +* This field contains a pointer to \ref CR_EXCEPTION_INFO structure. +* +* \b pUserParam [in, optional] +* +* This is a pointer to user-specified data passed to the crSetCrashCallback() function +* as \b pUserParam argument. +* +* \b bContinueExecution [in, out] +* +* This field is set to FALSE by default. The crash callback function may set it +* to true if it wants to continue its execution after crash report generation +* (otherwise the program will be terminated). +* +* \ref CR_CRASH_CALLBACK_INFOW and \ref CR_CRASH_CALLBACK_INFOA are +* wide-character and multi-byte character versions of \ref CR_CRASH_CALLBACK_INFO +* structure. In your program, use the \ref CR_CRASH_CALLBACK_INFO typedef which +* is a character-set-independent version of the structure name. +* +* \sa PFNCRASHCALLBACK() +*/ +typedef struct tagCR_CRASH_CALLBACK_INFOW +{ + WORD cb; //!< Size of this structure in bytes. + int nStage; //!< Stage. + LPCWSTR pszErrorReportFolder; //!< Directory where crash report files are located. + CR_EXCEPTION_INFO* pExceptionInfo; //!< Pointer to information about the crash. + LPVOID pUserParam; //!< Pointer to user-defined data. + BOOL bContinueExecution; //!< Whether to terminate the process (the default) or to continue program execution. +} +CR_CRASH_CALLBACK_INFOW; + +/*! \ingroup CrashRptStructs +* \struct CR_CRASH_CALLBACK_INFOA +* \copydoc CR_CRASH_CALLBACK_INFOW +*/ +typedef struct tagCR_CRASH_CALLBACK_INFOA +{ + WORD cb; //!< Size of this structure in bytes. + int nStage; //!< Stage. + LPCSTR pszErrorReportFolder; //!< Directory where crash report files are located. + CR_EXCEPTION_INFO* pExceptionInfo; //!< Pointer to information about the crash. + LPVOID pUserParam; //!< Pointer to user-defined data. + BOOL bContinueExecution; //!< Whether to terminate the process (the default) or to continue program execution. +} +CR_CRASH_CALLBACK_INFOA; + +/*! \brief Character set-independent mapping of CR_CRASH_CALLBACK_INFOW and CR_CRASH_CALLBACK_INFOA structures. +* \ingroup CrashRptStructs +*/ +#ifdef UNICODE +typedef CR_CRASH_CALLBACK_INFOW CR_CRASH_CALLBACK_INFO; +#else +typedef CR_CRASH_CALLBACK_INFOA CR_CRASH_CALLBACK_INFO; +#endif // UNICODE + +// Constants that may be returned by the crash callback function. +#define CR_CB_CANCEL 0 //!< Cancel crash report generation on the current stage. +#define CR_CB_DODEFAULT 1 //!< Proceed to the next stages of crash report generation without calling crash callback function. +#define CR_CB_NOTIFY_NEXT_STAGE 2 //!< Proceed and call the crash callback for the next stage. + +/*! \ingroup CrashRptAPI +* \brief Client crash callback function prototype. +* \param[in] pInfo Points to information about the crash. +* +* \remarks +* +* The crash callback function is called when a crash occurs. This way client application is +* notified about the crash. +* +* Crash information is passed by CrashRpt to the callback function through the \b pInfo parameter as +* a pointer to \ref CR_CRASH_CALLBACK_INFO structure. See below for a code example. +* +* It is generally unsafe to do complex actions (e.g. memory allocation, heap operations) inside of this callback. +* The application state may be unstable. +* +* One reason the application may use this callback for is to close handles to open log files that the +* application plans to include into the error report. Files should be accessible for reading, otherwise +* CrashRpt won't be able to include them into error report. +* +* It is also possible (but not recommended) to add files (see crAddFile2()), +* properties (see crAddProperty()), desktop screenshots (see crAddScreenshot2()) +* and registry keys (see crAddRegKey()) inside of the crash callback function. +* +* By default, CrashRpt terminates the client application after crash report generation and +* launching the CrashSender.exe process. However, it is possible to continue program +* execution after crash report generation by seting \ref CR_CRASH_CALLBACK_INFO::bContinueExecution +* structure field to \a TRUE. +* +* The crash report generation consists of several stages. First, exception pointers are retrieved +* and the callback function is called for the first time. The callback function may check the +* retrieved exception information and decide wheter to proceed with crash report generation or to +* continue client program execution. On the next stage, the \a CrashSender.exe +* process is launched and the crash callback function is (optionally) called for the second time. +* Further crash report data collection and delivery work is performed in \a CrashSender.exe process. +* The crash callback may use the provided handle to \a CrashSender.exe process to wait until it exits. +* +* The crash callback function should typically return \ref CR_CB_DODEFAULT constant to proceed +* with error report generation without being called back on the next stage(s). Returning the +* \ref CR_CB_NOTIFY_NEXT_STAGE constant causes CrashRpt to call the crash callback function on the next +* stage, too. Returning \ref CR_CB_CANCEL constant will prevent further stage(s) of crash report generation. +* +* \ref PFNCRASHCALLBACKW() and \ref PFNCRASHCALLBACKA() are +* wide-character and multi-byte character versions of \ref PFNCRASHCALLBACK() +* function. +* +* The following code example shows the simplest way of using the crash callback function: +* +* \code +* // Define the crash callback +* int CALLBACK CrashCallback(CR_CRASH_CALLBACK_INFO* pInfo) +* { +* +* // Do something... +* +* // Proceed with crash report generation. +* // This return code also makes CrashRpt to not call this callback function for +* // the next crash report generation stage. +* return CR_CB_DODEFAULT; +* } +* \endcode +* +* The following code example shows how to use the crash callback function to be notified +* on every stage of crash report generation: +* +* \code +* // Define the crash callback +* int CALLBACK CrashCallback(CR_CRASH_CALLBACK_INFO* pInfo) +* { +* +* // We want to continue program execution after crash report generation +* pInfo->bContinueExecution = TRUE; +* +* switch(pInfo->nStage) +* { +* case CR_CB_STAGE_PREPARE: +* // do something +* break; +* case CR_CB_STAGE_FINISH: +* // do something +* break; +* } +* +* // Proceed to the next stage. +* return CR_CB_NOTIFY_NEXT_STAGE; +* } +* \endcode +* +* \sa CR_CRASH_CALLBACK_INFO, crSetCrashCallback(), crAddFile2(), crAddProperty(), crAddScreenshot2(), crAddRegKey() +*/ +typedef int (CALLBACK *PFNCRASHCALLBACKW) (CR_CRASH_CALLBACK_INFOW* pInfo); + +/*! \ingroup CrashRptAPI +* \copydoc PFNCRASHCALLBACKW() +*/ +typedef int (CALLBACK *PFNCRASHCALLBACKA) (CR_CRASH_CALLBACK_INFOA* pInfo); + +/*! \brief Character set-independent mapping of \ref PFNCRASHCALLBACKW() and \ref PFNCRASHCALLBACKA() function prototrypes. +* \ingroup CrashRptStructs +*/ +#ifdef UNICODE +typedef PFNCRASHCALLBACKW PFNCRASHCALLBACK; +#else +typedef PFNCRASHCALLBACKA PFNCRASHCALLBACK; +#endif // UNICODE + +/*! \ingroup CrashRptAPI +* \brief Sets the crash callback function. +* +* \return This function returns zero if succeeded. Use crGetLastErrorMsg() to retrieve the error message on fail. +* +* \param[in] pfnCallbackFunc Pointer to the crash callback function. +* \param[in] lpParam User defined parameter. Optional. +* +* \remarks +* +* Use this to set the crash callback function that will be called on crash. This function +* is available since v.1.4.0. +* +* For the crash callback function prototype, see documentation for PFNCRASHCALLBACK(). +* +* Optional \b lpParam parameter can be a pointer to user-defined data. It will be passed to the +* crash callback function as \ref CR_CRASH_CALLBACK_INFO::pUserParam structure member. +* +* \sa +* PFNCRASHCALLBACK() +*/ + +CRASHRPTAPI(int) +crSetCrashCallbackW( + PFNCRASHCALLBACKW pfnCallbackFunc, + LPVOID lpParam + ); + + +/*! \ingroup CrashRptAPI +* \copydoc crSetCrashCallbackW() +*/ +CRASHRPTAPI(int) +crSetCrashCallbackA( + PFNCRASHCALLBACKA pfnCallbackFunc, + LPVOID lpParam + ); + + +/*! \brief Character set-independent mapping of crSetCrashCallbackW() and crSetCrashCallbackA() functions. +* \ingroup CrashRptAPI +*/ +#ifdef UNICODE +#define crSetCrashCallback crSetCrashCallbackW +#else +#define crSetCrashCallback crSetCrashCallbackA +#endif //UNICODE + +// Array indices for CR_INSTALL_INFO::uPriorities. +#define CR_HTTP 0 //!< Send error report via HTTP (or HTTPS) connection. +#define CR_SMTP 1 //!< Send error report via SMTP connection. +#define CR_SMAPI 2 //!< Send error report via simple MAPI (using default mail client). + +//! Special priority constant that allows to skip certain delivery method. +#define CR_NEGATIVE_PRIORITY ((UINT)-1) + +// Flags for CR_INSTALL_INFO::dwFlags +#define CR_INST_STRUCTURED_EXCEPTION_HANDLER 0x1 //!< Install SEH handler (deprecated name, use \ref CR_INST_SEH_EXCEPTION_HANDLER instead). +#define CR_INST_SEH_EXCEPTION_HANDLER 0x1 //!< Install SEH handler. +#define CR_INST_TERMINATE_HANDLER 0x2 //!< Install terminate handler. +#define CR_INST_UNEXPECTED_HANDLER 0x4 //!< Install unexpected handler. +#define CR_INST_PURE_CALL_HANDLER 0x8 //!< Install pure call handler (VS .NET and later). +#define CR_INST_NEW_OPERATOR_ERROR_HANDLER 0x10 //!< Install new operator error handler (VS .NET and later). +#define CR_INST_SECURITY_ERROR_HANDLER 0x20 //!< Install security error handler (VS .NET and later). +#define CR_INST_INVALID_PARAMETER_HANDLER 0x40 //!< Install invalid parameter handler (VS 2005 and later). +#define CR_INST_SIGABRT_HANDLER 0x80 //!< Install SIGABRT signal handler. +#define CR_INST_SIGFPE_HANDLER 0x100 //!< Install SIGFPE signal handler. +#define CR_INST_SIGILL_HANDLER 0x200 //!< Install SIGILL signal handler. +#define CR_INST_SIGINT_HANDLER 0x400 //!< Install SIGINT signal handler. +#define CR_INST_SIGSEGV_HANDLER 0x800 //!< Install SIGSEGV signal handler. +#define CR_INST_SIGTERM_HANDLER 0x1000 //!< Install SIGTERM signal handler. + +#define CR_INST_ALL_POSSIBLE_HANDLERS 0x1FFF //!< Install all possible exception handlers. +#define CR_INST_CRT_EXCEPTION_HANDLERS 0x1FFE //!< Install exception handlers for the linked CRT module. + +#define CR_INST_NO_GUI 0x2000 //!< Do not show GUI, send report silently (use for non-GUI apps only). +#define CR_INST_HTTP_BINARY_ENCODING 0x4000 //!< Deprecated, do not use. +#define CR_INST_DONT_SEND_REPORT 0x8000 //!< Don't send error report immediately, just save it locally. +#define CR_INST_APP_RESTART 0x10000 //!< Restart the application on crash. +#define CR_INST_NO_MINIDUMP 0x20000 //!< Do not include minidump file to crash report. +#define CR_INST_SEND_QUEUED_REPORTS 0x40000 //!< CrashRpt should send error reports that are waiting to be delivered. +#define CR_INST_STORE_ZIP_ARCHIVES 0x80000 //!< CrashRpt should store both uncompressed error report files and ZIP archives. +#define CR_INST_SEND_MANDATORY 0x100000 //!< This flag removes the "Close" and "Other actions" buttons from Error Report dialog, thus making the sending procedure mandatory for user. +#define CR_INST_SHOW_ADDITIONAL_INFO_FIELDS 0x200000 //!< Makes "Your E-mail" and "Describe what you were doing when the problem occurred" fields of Error Report dialog always visible. +#define CR_INST_ALLOW_ATTACH_MORE_FILES 0x400000 //!< Adds an ability for user to attach more files to crash report by clicking "Attach More File(s)" item from context menu of Error Report Details dialog. +#define CR_INST_AUTO_THREAD_HANDLERS 0x800000 //!< If this flag is set, installs exception handlers for newly created threads automatically. + +/*! \ingroup CrashRptStructs +* \struct CR_INSTALL_INFOW() +* \brief This structure defines the general information used by crInstallW() function. +* +* \remarks +* +* \ref CR_INSTALL_INFOW and \ref CR_INSTALL_INFOA structures are wide-character and multi-byte character +* versions of \ref CR_INSTALL_INFO. \ref CR_INSTALL_INFO typedef defines character set independent mapping. +* +* Below, structure members are described in details. Required parameters must always be specified, while optional +* ones may be set with 0 (zero) or NULL. Most of parameters are optional. +* +* \b cb [in, required] +* +* This must contain the size of this structure in bytes. +* +* \b pszAppName [in, optional] +* +* This is the friendly name of the client application. The application name is +* displayed in the Error Report dialog. If this parameter is NULL, the name of EXE file +* that was used to start caller process becomes the application name. +* +* \b pszAppVersion [in, optional] +* +* Should be the application version. Example: "1.0.1". +* +* If this equals to NULL, product version is extracted from the executable file which started +* the caller process, and this product version is used as application version. If the executable file +* doesn's have a version info resource, the \ref crInstall() function will fail. +* +* \b pszEmailTo [in, optional] +* +* This is the email address of the recipient of error reports (or several E-mail adresses separated with semicolon), +* for example "name@example.com" or "person1@example.com;person2@someserver.com". If several E-mail addresses are +* specified, error report will be delivered to each of them. If this parameter equals to NULL, +* the crash report won't be sent using E-mail client. +* +* Keep this NULL if you plan to use large error reports (more than several MB in size), because +* large emails may be rejected by the mail server. +* +* \b pszEmailSubject [in, optional] +* +* This is the subject of the email message. If this parameter is NULL, +* the default subject of form '[app_name] [app_version] Error Report' is generated. +* +* \a pszUrl is the URL of a server-side script that would receive crash report data via HTTP or HTTPS +* connection. If this parmeter is NULL, HTTP(S) connection won't be used to send crash reports. For +* example of a server-side script that can receive crash reports, see \ref sending_error_reports. +* +* HTTP(S) transport is the recommended way of sending large error reports (more than several MB in size). +* To define a custom port for HTTP(S) connection, use the following URL format: "http://example.com[:port]/crashrpt.php" or +* "https://example.com[:port]/crashrpt.php", where optional \a port is the placeholder for the port number. +* +* \b pszCrashSenderPath [in, optional] +* +* This is the absolute path to the directory where CrashSender.exe is located. +* The crash sender process is responsible for letting end user know about the crash and +* sending the error report. If this is NULL, it is assumed that CrashSender.exe is located in +* the same directory as CrashRpt.dll. +* +* +* \b uPriorities [in, optional] +* +* This is an array that defines the preferred methods of sending error reports. +* The available methods are: HTTP (or HTTPS) connection, SMTP connection or simple MAPI (default mail client). +* +* A priority is a non-negative integer number or special constant \ref CR_NEGATIVE_PRIORITY. +* The greater positive number defines the greater priority. +* Specify the \ref CR_NEGATIVE_PRIORITY to skip the given delivery method. +* +* The element having index \ref CR_HTTP defines priority for using HTML connection. +* The element having index \ref CR_SMTP defines priority for using SMTP connection. +* The element having index \ref CR_SMAPI defines priority for using the default mail client. +* +* The methods having greater priority will be tried first. If priorities are equal to each other, HTTP (or HTTPS) +* connection will be tried the first, SMTP connection will be tried the second and simple MAPI will be tried +* the last. +* +* \b dwFlags [in, optional] +* +* Since v1.1.2, \a dwFlags can be used to define behavior parameters. This can be a combination of the following values: +* +* +*
Use the combination of the following constants to specify what exception handlers to install: +*
\ref CR_INST_ALL_POSSIBLE_HANDLERS Install all available exception handlers. +*
\ref CR_INST_SEH_EXCEPTION_HANDLER Install SEH exception handler. +*
\ref CR_INST_PURE_CALL_HANDLER Install pure call handler (VS .NET and later). +*
\ref CR_INST_NEW_OPERATOR_ERROR_HANDLER Install new operator error handler (VS .NET and later). +*
\ref CR_INST_SECURITY_ERROR_HANDLER Install security errror handler (VS .NET and later). +*
\ref CR_INST_INVALID_PARAMETER_HANDLER Install invalid parameter handler (VS 2005 and later). +*
\ref CR_INST_SIGABRT_HANDLER Install SIGABRT signal handler. +*
\ref CR_INST_SIGINT_HANDLER Install SIGINT signal handler. +*
\ref CR_INST_SIGTERM_HANDLER Install SIGTERM signal handler. +*
Use the combination of the following constants to define behavior parameters: +*
\ref CR_INST_NO_GUI +* Available since v.1.2.2 Do not show GUI. +* +* It is not recommended to use this flag for regular GUI-based applications. +* Use this only for services that have no GUI. +*
\ref CR_INST_DONT_SEND_REPORT +* Available since v.1.2.2 This parameter means 'do not send error report immediately on crash, just save it locally'. +* Use this if you have direct access to the machine where crash happens and do not need +* to send report over the Internet. You can use this in couple with \ref CR_INST_STORE_ZIP_ARCHIVES flag to store zipped error reports +* along with uncompressed error report files. +*
\ref CR_INST_APP_RESTART +* Available since v.1.2.4 This parameter allows to automatically restart the application on crash. The command line +* for the application is taken from \a pszRestartCmdLine parameter. To avoid cyclic restarts of an application which crashes on startup, +* the application is restarted only if at least 60 seconds elapsed since its start. +*
\ref CR_INST_NO_MINIDUMP +* Available since v.1.2.4 Specify this parameter if you want minidump file not to be included into crash report. The default +* behavior is to include the minidump file. +* +*
\ref CR_INST_SEND_QUEUED_REPORTS +* Available since v.1.2.5 Specify this parameter to send all queued reports. Those +* report files are by default stored in %LOCAL_APPDATA%\\CrashRpt\\UnsentCrashReports\\%AppName%_%AppVersion% folder. +* If this is specified, CrashRpt checks if it's time to remind user about recent errors in the application and offers to send +* all queued error reports. +* +*
\ref CR_INST_STORE_ZIP_ARCHIVES +* Available since v.1.2.7 This parameter can be used in couple with \ref CR_INST_DONT_SEND_REPORT flag to store not only uncompressed +* error report files, but also ZIP archives. By default (if this flag omitted) CrashRpt stores all error report files +* in uncompressed state. +* +*
\ref CR_INST_SEND_MANDATORY +* Available since v.1.3.1 This parameter makes sending procedure mandatory by removing the "Close" button +* and "Other actions..." button from the Error Report dialog. Typically, it is not recommended to use this flag, +* unless you intentionally want users to always send error reports for your application. +*
\ref CR_INST_SHOW_ADDITIONAL_INFO_FIELDS +* Available since v.1.3.1 This parameter makes "Your E-mail" and "Describe what you were doing when the +* problem occurred" fields of Error Report dialog always visible. By default (when this parameter not specified), +* these fields are hidden and user needs to click the "Provide additional info (recommended)" link to show them. +* +*
\ref CR_INST_ALLOW_ATTACH_MORE_FILES +* Available since v.1.3.1 Adds an ability for user to attach more files to crash report by choosing +* "Attach More File(s)" item from context menu of Error Report Details dialog. By default this feature is disabled. +* +*
\ref CR_INST_AUTO_THREAD_HANDLERS +* Available since v.1.4.2 Specifying this flag results in automatic installation of all available exception handlers to +* all threads that will be created in the future. This flag only works if CrashRpt is compiled as a DLL, it does +* not work if you compile CrashRpt as static library. +*
+* +* \b pszPrivacyPolicyURL [in, optional] +* +* This parameter defines the URL for the Privacy Policy hyperlink of the +* Error Report dialog. If this parameter is NULL, the link is not displayed. For information on +* the Privacy Policy, see \ref error_report. This parameter is available since v1.1.2. +* +* \b pszDebugHelpDLL [in, optional] +* +* This parameter defines the location of the dbghelp.dll to load. +* If this parameter is NULL, the dbghelp.dll is searched using the default search sequence. +* This parameter is available since v1.2.1. +* +* \b uMiniDumpType [in, optional] +* +* This parameter defines the minidump type. For the list of available minidump +* types, see the documentation for the MiniDumpWriteDump() function in MSDN. +* Parameter is available since v.1.2.1. +* +* It is recommended to set this +* parameter with zero (equivalent of MiniDumpNormal constant). Other values may increase the minidump +* size significantly. +* +* \b pszErrorReportSaveDir [in, optional] +* +* This parameter defines the directory where to save the error reports. +* If this is NULL, the default directory is used (%%LOCAL_APP_DATA%\\CrashRpt\\UnsentCrashReports\\%%AppName%%_%%AppVersion%). +* This parameter is available since v.1.2.2. +* +* \b pszRestartCmdLine [in, optional] +* +* This parameter defines the string that specifies the +* command-line arguments for the application when it is restarted (when using \ref CR_INST_APP_RESTART flag). +* Do not include the name of the executable in the command line; it is added automatically. This parameter +* can be NULL. Available since v.1.2.4. +* +* \b pszLangFilePath [in, optional] +* +* This parameter defines the absolute path (including file name) for language file. +* If this is NULL, the lang file is assumed to be located in the same dir as CrashSender.exe file and have +* the name crashrpt_lang.ini. +* This parameter is available since v.1.2.4. +* +* \b pszEmailText [in, optional] +* +* This parameter defines the custom E-mail text that is used when deliverying error report +* as E-mail. If this is NULL, the default E-mail text is used. It is recommended to set this parameter with NULL. +* This parameter is available since v.1.2.4. +* +* \b pszSmtpProxy [in, optional] +* +* This parameter defines the network address (IP or domain) and, optionally, port formatted as "address[:port]" +* of SMTP server. Examples: "192.168.1.1:2525", "mail.example.com:25". +* If this parameter is NULL, the SMTP server address is resolved using the MX record of recipient's mailbox. +* You should typically set this parameter with NULL, except in the +* case when your software is a server and custom SMTP configuration is required. This parameter is available since v.1.2.4. +* +* \b pszCustomSenderIcon [in, optional] +* +* This parameter can be used to define a custom icon for Error Report dialog. This parameter is +* available since v.1.2.8. +* +* The value of this parameter should be absolute path to the module containing the icon resource, followed +* by resource identifier separated by comma. You can set this parameter with NULL to use the default icon. +* +* The resource identifier is a zero-based index of the icon to retrieve. For example, if this value is 0, +* the first icon in the specified file is used. If the identifier is a negative number not equal to -1, +* the icon in the specified file whose resource identifier is equal to the absolute value of the resource +* identifier is used. +* Example: "D:\MyApp\Resources.dll, -128". +* +* \b pszSmtpLogin [in, optional] +* +* This parameter defines the login name for SMTP authentication. It is typically used together with +* \ref pszSmtpProxy and \ref pszSmtpPassword parameter. +* If this parameter is ommitted (NULL), no SMTP autentication is used. This parameter is available since v.1.3.1. +* +* \b pszSmtpPassword [in, optional] +* +* This parameter defines the password for SMTP authentication. It is used in pair with \ref pszSmtpLogin parameter. +* This parameter is available since v.1.3.1. +* +* \b nRestartTimeout [in, optional] +* +* This parameter defines the timeout (in seconds) for the application restart (when using \ref CR_INST_APP_RESTART flag). +* It is recommended to set this with zero (in such a case, the default restart timeout of 60 seconds is applied). +* Available since v.1.4.3. +*/ + +typedef struct tagCR_INSTALL_INFOW +{ + WORD cb; //!< Size of this structure in bytes; must be initialized before using! + LPCWSTR pszAppName; //!< Name of application. + LPCWSTR pszAppVersion; //!< Application version. + LPCWSTR pszEmailTo; //!< E-mail address of crash reports recipient. + LPCWSTR pszEmailSubject; //!< Subject of crash report e-mail. + LPCWSTR pszUrl; //!< URL of server-side script (used in HTTP connection). + LPCWSTR pszCrashSenderPath; //!< Directory name where CrashSender.exe is located. + LPGETLOGFILE pfnCrashCallback; //!< Deprecated, do not use. + UINT uPriorities[5]; //!< Array of error sending transport priorities. + DWORD dwFlags; //!< Flags. + LPCWSTR pszPrivacyPolicyURL; //!< URL of privacy policy agreement. + LPCWSTR pszDebugHelpDLL; //!< File name or folder of Debug help DLL. + MINIDUMP_TYPE uMiniDumpType; //!< Minidump type. + LPCWSTR pszErrorReportSaveDir; //!< Directory where to save error reports. + LPCWSTR pszRestartCmdLine; //!< Command line for application restart (without executable name). + LPCWSTR pszLangFilePath; //!< Path to the language file (including file name). + LPCWSTR pszEmailText; //!< Custom E-mail text (used when deliverying report as E-mail). + LPCWSTR pszSmtpProxy; //!< Network address and port to be used as SMTP proxy. + LPCWSTR pszCustomSenderIcon; //!< Custom icon used for Error Report dialog. + LPCWSTR pszSmtpLogin; //!< Login name used for SMTP authentication when sending error report as E-mail. + LPCWSTR pszSmtpPassword; //!< Password used for SMTP authentication when sending error report as E-mail. + int nRestartTimeout; //!< Timeout for application restart. +} +CR_INSTALL_INFOW; + +typedef CR_INSTALL_INFOW* PCR_INSTALL_INFOW; + +/*! \ingroup CrashRptStructs +* \struct CR_INSTALL_INFOA +* \copydoc CR_INSTALL_INFOW +*/ + +typedef struct tagCR_INSTALL_INFOA +{ + WORD cb; //!< Size of this structure in bytes; must be initialized before using! + LPCSTR pszAppName; //!< Name of application. + LPCSTR pszAppVersion; //!< Application version. + LPCSTR pszEmailTo; //!< E-mail address of crash reports recipient. + LPCSTR pszEmailSubject; //!< Subject of crash report e-mail. + LPCSTR pszUrl; //!< URL of server-side script (used in HTTP connection). + LPCSTR pszCrashSenderPath; //!< Directory name where CrashSender.exe is located. + LPGETLOGFILE pfnCrashCallback; //!< Deprecated, do not use. + UINT uPriorities[5]; //!< Array of error sending transport priorities. + DWORD dwFlags; //!< Flags. + LPCSTR pszPrivacyPolicyURL; //!< URL of privacy policy agreement. + LPCSTR pszDebugHelpDLL; //!< File name or folder of Debug help DLL. + MINIDUMP_TYPE uMiniDumpType; //!< Mini dump type. + LPCSTR pszErrorReportSaveDir; //!< Directory where to save error reports. + LPCSTR pszRestartCmdLine; //!< Command line for application restart (without executable name). + LPCSTR pszLangFilePath; //!< Path to the language file (including file name). + LPCSTR pszEmailText; //!< Custom E-mail text (used when deliverying report as E-mail). + LPCSTR pszSmtpProxy; //!< Network address and port to be used as SMTP proxy. + LPCSTR pszCustomSenderIcon; //!< Custom icon used for Error Report dialog. + LPCSTR pszSmtpLogin; //!< Login name used for SMTP authentication when sending error report as E-mail. + LPCSTR pszSmtpPassword; //!< Password used for SMTP authentication when sending error report as E-mail. + int nRestartTimeout; //!< Timeout for application restart. +} +CR_INSTALL_INFOA; + +typedef CR_INSTALL_INFOA* PCR_INSTALL_INFOA; + +/*! \brief Character set-independent mapping of CR_INSTALL_INFOW and CR_INSTALL_INFOA structures. +* \ingroup CrashRptStructs +*/ +#ifdef UNICODE +typedef CR_INSTALL_INFOW CR_INSTALL_INFO; +typedef PCR_INSTALL_INFOW PCR_INSTALL_INFO; +#else +typedef CR_INSTALL_INFOA CR_INSTALL_INFO; +typedef PCR_INSTALL_INFOA PCR_INSTALL_INFO; +#endif // UNICODE + +/*! \ingroup CrashRptAPI +* \brief Installs exception handlers for the caller process. +* +* \return +* This function returns zero if succeeded. +* +* \param[in] pInfo General congiration information. +* +* \remarks +* +* This function installs unhandled exception filter for the caller process. +* It also installs various CRT exception/error handlers that function for all threads of the caller process. +* For more information, see \ref exception_handling +* +* Below is the list of installed handlers: +* - Top-level SEH exception filter [ \c SetUnhandledExceptionFilter() ] +* - C++ pure virtual call handler (Visual Studio .NET 2003 and later) [ \c _set_purecall_handler() ] +* - C++ invalid parameter handler (Visual Studio .NET 2005 and later) [ \c _set_invalid_parameter_handler() ] +* - C++ new operator error handler (Visual Studio .NET 2003 and later) [ \c _set_new_handler() ] +* - C++ buffer overrun handler (Visual Studio .NET 2003 only) [ \c _set_security_error_handler() ] +* - C++ abort handler [ \c signal(SIGABRT) ] +* - C++ illegal instruction handler [ \c signal(SIGINT) ] +* - C++ termination request [ \c signal(SIGTERM) ] +* +* In a multithreaded program, additionally use crInstallToCurrentThread2() function for each execution +* thread, except the main one. +* +* The \a pInfo parameter contains all required information needed to install CrashRpt. +* +* This function fails when \a pInfo->pszCrashSenderPath doesn't contain valid path to CrashSender.exe +* or when \a pInfo->pszCrashSenderPath is equal to NULL, but \b CrashSender.exe is not located in the +* directory where \b CrashRpt.dll located. +* +* On crash, the crash minidump file is created, which contains CPU information and +* stack trace information. Also XML file is created that contains additional +* information that may be helpful for crash analysis. These files along with several additional +* files added with crAddFile2() are packed to a single ZIP file. +* +* When crash information is collected, another process, CrashSender.exe, is launched +* and the process where crash had occured is terminated. The CrashSender process is +* responsible for letting the user know about the crash and send the error report. +* +* The error report can be sent over E-mail using address and subject passed to the +* function as \ref CR_INSTALL_INFO structure members. Another way of sending error report is an HTTP +* request using \a pszUrl member of \ref CR_INSTALL_INFO. +* +* This function may fail if an appropriate language file (\b crashrpt_lang.ini) is not found +* in the directory where the \b CrashSender.exe file is located. +* +* If this function fails, use crGetLastErrorMsg() to retrieve the error message. +* +* crInstallW() and crInstallA() are wide-character and multi-byte character versions of crInstall() +* function. The \ref crInstall macro defines character set independent mapping for these functions. +* +* For code example, see \ref simple_example. +* +* \sa crInstallW(), crInstallA(), crInstall(), CR_INSTALL_INFOW, +* CR_INSTALL_INFOA, CR_INSTALL_INFO, crUninstall(), +* CrAutoInstallHelper +*/ + +CRASHRPTAPI(int) +crInstallW( + __in PCR_INSTALL_INFOW pInfo + ); + +/*! \ingroup CrashRptAPI +* \copydoc crInstallW() +*/ + +CRASHRPTAPI(int) +crInstallA( + __in PCR_INSTALL_INFOA pInfo + ); + +/*! \brief Character set-independent mapping of crInstallW() and crInstallA() functions. +* \ingroup CrashRptAPI +*/ +#ifdef UNICODE +#define crInstall crInstallW +#else +#define crInstall crInstallA +#endif //UNICODE + +/*! \ingroup CrashRptAPI +* \brief Uninitializes the CrashRpt library and unsinstalls exception handlers previously installed with crInstall(). +* +* \return +* This function returns zero if succeeded. +* +* \remarks +* +* Call this function on application exit to uninitialize the library and uninstall exception +* handlers previously installed with crInstall(). After function call, the exception handlers +* are restored to states they had before calling crInstall(). +* +* This function fails if crInstall() wasn't previously called in context of the +* caller process. +* +* When this function fails, use the crGetLastErrorMsg() function to retrieve the error message. +* +* \sa crInstallW(), crInstallA(), crInstall(), +* CrAutoInstallHelper +*/ + +CRASHRPTAPI(int) +crUninstall(); + +/*! \ingroup CrashRptAPI +* \brief Installs exception handlers to the caller thread. +* \return This function returns zero if succeeded. +* \param[in] dwFlags Flags. +* +* \remarks +* +* This function is available since v.1.1.2. +* +* The function sets exception handlers for the caller thread. If you have +* several execution threads, you ought to call the function for each thread, +* except the main one. +* +* \a dwFlags defines what exception handlers to install. Use zero value +* to install all possible exception handlers. Or use a combination of the following constants: +* +* - \ref CR_INST_TERMINATE_HANDLER Install terminate handler +* - \ref CR_INST_UNEXPECTED_HANDLER Install unexpected handler +* - \ref CR_INST_SIGFPE_HANDLER Install SIGFPE signal handler +* - \ref CR_INST_SIGILL_HANDLER Install SIGILL signal handler +* - \ref CR_INST_SIGSEGV_HANDLER Install SIGSEGV signal handler +* +* Example: +* +* \code +* DWORD WINAPI ThreadProc(LPVOID lpParam) +* { +* // Install exception handlers +* crInstallToCurrentThread2(0); +* +* // Your code... +* +* // Uninstall exception handlers +* crUninstallFromCurrentThread(); +* +* return 0; +* } +* \endcode +* +* \sa +* crInstall() +*/ + +CRASHRPTAPI(int) +crInstallToCurrentThread2(DWORD dwFlags); + +/*! \ingroup CrashRptAPI +* \brief Uninstalls C++ exception handlers from the current thread. +* \return This function returns zero if succeeded. +* +* \remarks +* +* This function unsets exception handlers from the caller thread. If you have +* several execution threads, you ought to call the function for each thread. +* After calling this function, the exception handlers for current thread are +* replaced with the handlers that were before call of crInstallToCurrentThread2(). +* +* This function fails if crInstallToCurrentThread2() wasn't called for current thread. +* +* When this function fails, use crGetLastErrorMsg() to retrieve the error message. +* +* No need to call this function for the main execution thread. The crUninstall() +* will automatically uninstall C++ exception handlers for the main thread. +* +* \sa crInstallToCurrentThread2(), +* crUninstallFromCurrentThread(), CrThreadAutoInstallHelper +*/ + +CRASHRPTAPI(int) +crUninstallFromCurrentThread(); + +// Flags for crAddFile2() function. + +#define CR_AF_TAKE_ORIGINAL_FILE 0 //!< Take the original file (do not copy it to the error report folder). +#define CR_AF_MAKE_FILE_COPY 1 //!< Copy the file to the error report folder. +#define CR_AF_FILE_MUST_EXIST 0 //!< Function will fail if file doesn't exist at the moment of function call. +#define CR_AF_MISSING_FILE_OK 2 //!< Do not fail if file is missing (assume it will be created later). +#define CR_AF_ALLOW_DELETE 4 //!< If this flag is specified, the file will be deletable from context menu of Error Report Details dialog. + +/*! \ingroup CrashRptAPI +* \brief Adds a file to crash report. +* +* \return This function returns zero if succeeded. +* +* \param[in] pszFile Absolute path to the file (or file search pattern) to add to crash report, required. +* \param[in] pszDestFile Destination file name, optional. +* \param[in] pszDesc File description (used in Error Report Details dialog), optional. +* \param[in] dwFlags Flags, optional. +* +* This function can be called anytime after crInstall() to add one or more +* files to the generated crash report. +* +* When this function is called, the file is marked to be added to the error report, +* then the function returns control to the caller. +* When a crash occurs, all marked files are added to the report by the \b CrashSender.exe process. +* If a file is locked by someone for exclusive access, the file won't be included. +* Inside of \ref PFNCRASHCALLBACK() crash callback, +* close open file handles and ensure files to be included are acessible for reading. +* +* \a pszFile should be either a valid absolute path to the file or a file search +* pattern (e.g. "*.log") to be added to crash report. +* +* \a pszDestFile should be the name of destination file. This parameter can be used +* to specify different file name for the file in ZIP archive. If this parameter is NULL, the pszFile +* file name is used as destination file name. If \a pszFile is a search pattern, this argument +* is ignored. +* +* \a pszDesc is a short description of the file. It can be NULL. +* +* \a dwFlags parameter defines the behavior of the function. This can be a combination of the following flags: +* - \ref CR_AF_TAKE_ORIGINAL_FILE On crash, the \b CrashSender.exe process will try to locate the file from its original location. This behavior is the default one. +* - \ref CR_AF_MAKE_FILE_COPY On crash, the \b CrashSender.exe process will make a copy of the file and save it to the error report folder. +* +* - \ref CR_AF_FILE_MUST_EXIST The function will fail if file doesn't exist at the moment of function call (the default behavior). +* - \ref CR_AF_MISSING_FILE_OK The function will not fail if file is missing (assume it will be created later). +* +* - \ref CR_AF_ALLOW_DELETE If this flag is specified, the user will be able to delete the file from error report using context menu of Error Report Details dialog. +* +* If you do not use error report delivery (\ref CR_INST_DONT_SEND_REPORT flag) or if you use postponed error report delivery +* (if you specify \ref CR_INST_SEND_QUEUED_REPORTS flag) +* you must also specify the \ref CR_AF_MAKE_FILE_COPY as \a dwFlags parameter value. This will +* guarantee that a snapshot of your file at the moment of crash is taken and saved to the error report folder. +* The error report folder is a folder where files included into the crash report are stored +* until they are sent to recipient. +* +* This function fails if \a pszFile doesn't exist at the moment of function call, +* unless you specify \ref CR_AF_MISSING_FILE_OK flag. +* +* The crAddFile2W() and crAddFile2A() are wide-character and multibyte-character +* versions of crAddFile2() function. The crAddFile2() macro defines character set +* independent mapping. +* +* Usage example: +* +* \code +* +* // Add the error.log file to crash report. At the moment of crash, +* // the file will be copied to crash report folder. The end user +* // will be able to delete the file using CrashRpt GUI. +* int nResult = crAddFile2( +* _T("C:\\Program Files (x86)\MyApp\\error.log"), +* _T("error.log"), +* _T("Log file"), +* CR_AF_MAKE_FILE_COPY|CR_AF_ALLOW_DELETE); +* if(nResult!=0) +* { +* // Get the status message +* TCHAR szErrorMsg[256]; +* crGetLastErrorMsg(szErrorMsg, 256); +* } +* +* // Add all *.txt files found in the folder. At the moment of crash, +* // the file(s) will be copied to crash report folder. The end user +* // won't be able to delete the file(s). +* crAddFile2(_T("C:\\Program Files (x86)\MyApp\\*.txt"), +* NULL, _T("TXT file"), CR_AF_MAKE_FILE_COPY); +* +* \endcode +* +* \sa crAddFile2W(), crAddFile2A(), crAddFile2() +*/ + +CRASHRPTAPI(int) +crAddFile2W( + LPCWSTR pszFile, + LPCWSTR pszDestFile, + LPCWSTR pszDesc, + DWORD dwFlags + ); + +/*! \ingroup CrashRptAPI +* \copydoc crAddFile2W() +*/ + +CRASHRPTAPI(int) +crAddFile2A( + LPCSTR pszFile, + LPCSTR pszDestFile, + LPCSTR pszDesc, + DWORD dwFlags + ); + +/*! \brief Character set-independent mapping of crAddFile2W() and crAddFile2A() functions. +* \ingroup CrashRptAPI +*/ +#ifdef UNICODE +#define crAddFile2 crAddFile2W +#else +#define crAddFile2 crAddFile2A +#endif //UNICODE + + +// Flags for crAddScreenshot function. +#define CR_AS_VIRTUAL_SCREEN 0 //!< Take a screenshot of the virtual screen. +#define CR_AS_MAIN_WINDOW 1 //!< Take a screenshot of application's main window. +#define CR_AS_PROCESS_WINDOWS 2 //!< Take a screenshot of all visible process windows. +#define CR_AS_GRAYSCALE_IMAGE 4 //!< Make a grayscale image instead of a full-color one. +#define CR_AS_USE_JPEG_FORMAT 8 //!< Store screenshots as JPG files. +#define CR_AS_ALLOW_DELETE 16 //!< If this flag is specified, the file will be deletable from context menu of Error Report Details dialog. + +/*! \ingroup DeprecatedAPI +* \brief Adds a screenshot to the crash report. +* +* \return This function returns zero if succeeded. Use crGetLastErrorMsg() to retrieve the error message on fail. +* +* \param[in] dwFlags Flags, optional. +* +* \remarks +* +* As of v.1.3.1, this function is deprecated and may be removed in one of the next releases. Use +* \ref crAddScreenshot2() function instead. +* +* This function can be used to take a screenshot at the moment of crash and add it to the error report. +* Screenshot information may help the developer to better understand the state of the application +* at the moment of crash and reproduce the error. +* +* When this function is called, screenshot flags are saved, +* then the function returns control to the caller. +* When crash occurs, screenshot is made by the \b CrashSender.exe process and added to the report. +* +* \b dwFlags +* +* - \ref CR_AS_ALLOW_DELETE If this flag is specified, the user will be able to delete the file from error report using context menu of Error Report Details dialog. +* +* Use one of the following constants to specify what part of virtual screen to capture: +* - \ref CR_AS_VIRTUAL_SCREEN Use this to take a screenshot of the whole desktop (virtual screen). +* - \ref CR_AS_MAIN_WINDOW Use this to take a screenshot of the application's main window. +* - \ref CR_AS_PROCESS_WINDOWS Use this to take a screenshot of all visible windows that belong to the process. +* +* The main application window is a window that has a caption (\b WS_CAPTION), system menu (\b WS_SYSMENU) and +* the \b WS_EX_APPWINDOW extended style. If CrashRpt doesn't find such window, it considers the first found process window as +* the main window. +* +* Screenshots are added in form of PNG files by default. You can specify the \ref CR_AS_USE_JPEG_FORMAT flag to save +* screenshots as JPEG files instead. +* +* In addition, you can specify the \ref CR_AS_GRAYSCALE_IMAGE flag to make a grayscale screenshot +* (by default color image is made). Grayscale image gives smaller file size. +* +* If you use JPEG image format, you may better use the \ref crAddScreenshot2() function, that allows to +* define JPEG image quality. +* +* When capturing entire desktop consisting of several monitors, +* one screenshot file is added per each monitor. +* +* You should be careful when using this feature, because screenshots may contain user-identifying +* or private information. Always specify purposes you will use collected +* information for in your Privacy Policy. +* +* \sa +* crAddFile2() +*/ + +CRASHRPTAPI(int) +crAddScreenshot( + DWORD dwFlags + ); + +/*! \ingroup CrashRptAPI +* \brief Adds a screenshot to the crash report. +* +* \return This function returns zero if succeeded. Use crGetLastErrorMsg() to retrieve the error message on fail. +* +* \param[in] dwFlags Flags, optional. +* \param[in] nJpegQuality Defines the JPEG image quality, optional. +* +* \remarks +* +* This function can be used to take a screenshot at the moment of crash and add it to the error report. +* Screenshot information may help the developer to better understand state of the application +* at the moment of crash and reproduce the error. +* +* When this function is called, screenshot flags are saved, then the function returns control to the caller. +* When crash occurs, screenshot is made by the \b CrashSender.exe process and added to the report. +* +* \b dwFlags +* +* Use one of the following constants to specify what part of virtual screen to capture: +* - \ref CR_AS_VIRTUAL_SCREEN Use this to take a screenshot of the whole desktop (virtual screen). +* - \ref CR_AS_MAIN_WINDOW Use this to take a screenshot of the main application main window. +* - \ref CR_AS_PROCESS_WINDOWS Use this to take a screenshot of all visible windows that belong to the process. +* +* The main application window is a window that has a caption (\b WS_CAPTION), system menu (\b WS_SYSMENU) and +* the \b WS_EX_APPWINDOW extended style. If CrashRpt doesn't find such window, it considers the first found process window as +* the main window. +* +* Screenshots are added in form of PNG files by default. You can specify the \ref CR_AS_USE_JPEG_FORMAT flag to save +* screenshots as JPEG files instead. +* +* If you use JPEG format, you can use the \a nJpegQuality parameter to define the JPEG image quality. +* This should be the number between 0 and 100, inclusively. The bigger the number, the better the quality and the bigger the JPEG file size. +* If you use PNG file format, this parameter is ignored. +* +* In addition, you can specify the \ref CR_AS_GRAYSCALE_IMAGE flag to make a grayscale screenshot +* (by default color image is made). Grayscale image gives smaller file size. +* +* When capturing entire desktop consisting of several monitors, +* one screenshot file is added per each monitor. +* +* You should be careful when using this feature, because screenshots may contain user-identifying +* or private information. Always specify purposes you will use collected +* information for in your Privacy Policy. +* +* \sa +* crAddFile2() +*/ + +CRASHRPTAPI(int) +crAddScreenshot2( + DWORD dwFlags, + int nJpegQuality + ); + +// Flags for crAddVideo function. +#define CR_AV_VIRTUAL_SCREEN 0 //!< Capture the whole virtual screen. +#define CR_AV_MAIN_WINDOW 1 //!< Capture the area of application's main window. +#define CR_AV_PROCESS_WINDOWS 2 //!< Capture all visible process windows. +#define CR_AV_QUALITY_LOW 0 //!< Low quality video encoding, smaller file size. +#define CR_AV_QUALITY_GOOD 4 //!< Good encoding quality, larger file size. +#define CR_AV_QUALITY_BEST 8 //!< The best encoding quality, the largest file size. +#define CR_AV_NO_GUI 16 //!< Do not display the notification dialog. +#define CR_AV_ALLOW_DELETE 32 //!< If this flag is specified, the file will be deletable from context menu of Error Report Details dialog. + +/*! \ingroup CrashRptAPI +* \brief Allows to record what happened before crash to a video file and include the file to crash report. +* +* \return This function returns zero if succeeded. Use \ref crGetLastErrorMsg() to retrieve the error message on failure. +* +* \param[in] dwFlags Flags, optional. +* \param[in] nDuration Video duration (in milliseconds). Optional. +* \param[in] nFrameInterval Interval between subsequent frames (in milliseconds). Optional. +* \param[in] pDesiredFrameSize Defines the desired video frame size, optional. +* \param[in] hWndParent Window that becomes the parent for GUI displayed by this function. Optional. +* +* \remarks +* +* This function is available as of v.1.4.0. +* +* \b dwFlags can be a combination of the following constants: +* +* - use one of the following constants to specify what part of virtual screen to capture: +* - \ref CR_AV_VIRTUAL_SCREEN Use this to capture the whole desktop (virtual screen). This is the default. +* - \ref CR_AV_MAIN_WINDOW Use this to capture the application's main window. +* - \ref CR_AV_PROCESS_WINDOWS Use this to capture all visible windows that belong to the process. +* +* - use one of the following constants to define the desired video encoding quality: +* - \ref CR_AV_QUALITY_LOW Low-quality video encoding. This is the default. +* - \ref CR_AV_QUALITY_GOOD Good encoding quality, larger file. +* - \ref CR_AV_QUALITY_BEST The best encoding quality, the largest file. +* +* - use the \ref CR_AV_ALLOW_DELETE to allow the user to delete the recorded video file from error report using context menu of Error Report Details dialog. +* +* The main application window is a window that has a caption (\b WS_CAPTION), system menu (\b WS_SYSMENU) and +* the \b WS_EX_APPWINDOW extended style. If CrashRpt doesn't find such a window, it considers the first found process window as +* the main window. +* +* When the function is called, it displays a dialog notifying the user about video recording. +* The displayed dialog's parent window can be specified with the \b hWndParent argument. +* If the \b hWndParent is \a NULL, the currently active process window becomes the parent. +* If you do not want to display the dialog, specify the \ref CR_AV_NO_GUI flag for \b dwFlags argument. +* +* The recorded video will be maximum \b nDuration milliseconds long with \b nFrameInterval +* milliseconds interval between subsequent video frames. If \b nDuration and\or \b nFrameInterval +* are set to zero (0), the default implementation-defined duration and frame interval are used. +* +* The \b pDesiredFrameSize parameter allows to define the desired video frame size. +* Frame width and height must be a multiple of 16 (OGG Theora video codec's requirement). +* If they are not, they are modified automatically to be a multiple of 16. +* +* To preserve correct aspect ratio of the captured area, set \b pDesiredFrameSize->cx or \b pDesiredFrameSize->cy +* to zero. For example, setting \b pDesiredFrameSize->cx=640 and \b pDesiredFrameSize->cy=0 +* results in video frames whose width is 640 pixels and height is calculated to preserve the +* correct aspect ratio of the captured area. If both \b cx and \b cy are specified, the aspect ratio +* of the captured area is not preserved. +* +* Setting the \b pDesiredFrameSize +* parameter to \a NULL makes the function to determine the best video frame size automatically. +* +* This function can be used to record the state of end user's desktop just before the moment +* of crash and add the video file to the error report. The recorded information may help the +* software vendor to better understand the state of the client application at the moment of +* crash and reproduce the error. +* +* When this function is called, CrashRpt launches another process named \b CrashSender.exe. +* The \b CrashSender.exe process then continuously captures the desktop screenshots in background +* mode and stores them to disk as image files. To avoid high CPU load, image files are stored +* in uncompressed state as raw bitmap (BMP) files. When the count of screenshot files exceeds +* the predefined maximum number, the old screenshot files are reused cyclically. +* +* If the client application does not crash and its main code or main window loop exits successfully, +* the captured desktop screenshot files are removed by the \ref crUninstall() function call and +* \b CrashSender.exe process is terminated. +* +* If the client application crashes at some moment of time, the recorded screenshot files are compressed by +* OGG Theora video codec and written into an .OGG file. The +* uncompressed temporary screenshots are then removed, and the resulting +* OGG file is included into crash report archive. +* +* The OGG video format is a widely used +* video container provided by the open-source OGG Project. +* OGG files can be opened in a browser like Google Chrome or Mozilla Firefox or in +* another video player understanding this format, like ffmpeg. +* +* Use this function only when necessary, because it may cause end user's computer performance +* loss. It also requires some amount of free disk space. +* +* The recorded video may contain user-identifying or private information. Always +* specify the purposes you will use collected information for in your Privacy Policy. +* +* Usage example: +* +* \code +* +* // First install CrashRpt with crInstall() function +* +* ... +* +* SIZE FrameSize = {0, 600}; // Frames 600 px in height +* // Frame width is calculated automatically +* +* // Start capturing desktop. Desktop capture video will +* // be added to crash report on crash +* int nResult = crAddVideo( +* CR_AV_VIRTUAL_SCREEN|CR_AV_QUALITY_GOOD, // Capture entire desktop +* // Good encoding quality +* 10000, // 10 seconds long video +* 300, // 300 msec between frames (3.33 FPS) +* &FrameSize, +* NULL +* ); +* +* \endcode +* +* \sa +* crAddFile2(), crAddScreenshot2(), crAddRegKey(), crUninstall(). +*/ + +CRASHRPTAPI(int) +crAddVideo( + DWORD dwFlags, + int nDuration, + int nFrameInterval, + PSIZE pDesiredFrameSize, + HWND hWndParent + ); + +/*! \ingroup CrashRptAPI +* \brief Adds a string property to the crash report. +* +* \return This function returns zero if succeeded. Use crGetLastErrorMsg() to retrieve the error message on fail. +* +* \param[in] pszPropName Name of the property, required. +* \param[in] pszPropValue Value of the property, required. +* +* \remarks +* +* Use this function to add a string property to the crash description XML file. +* User-added properties are listed under \ tag of the XML file. +* In the XML file properties are ordered by names in alphabetic order. +* +* The following example shows how to add information about the amount of free disk space +* to the crash description XML file: +* +* \code +* // It is assumed that you already calculated the amount of free disk space, +* // converted it to text and stored it as szFreeSpace string. +* LPCTSTR szFreeSpace = _T("0 Kb"); +* crAddProperty(_T("FreeDiskSpace"), szFreeSpace); +* +* \endcode +* +* \sa +* crAddFile2(), crAddScreenshot() +*/ + +CRASHRPTAPI(int) +crAddPropertyW( + LPCWSTR pszPropName, + LPCWSTR pszPropValue + ); + +/*! \ingroup CrashRptAPI +* \copydoc crAddPropertyW() +*/ + +CRASHRPTAPI(int) +crAddPropertyA( + LPCSTR pszPropName, + LPCSTR pszPropValue + ); + +/*! \brief Character set-independent mapping of crAddPropertyW() and crAddPropertyA() functions. +* \ingroup CrashRptAPI +*/ +#ifdef UNICODE +#define crAddProperty crAddPropertyW +#else +#define crAddProperty crAddPropertyA +#endif //UNICODE + +// Flags that can be passed to crAddRegKey() function +#define CR_AR_ALLOW_DELETE 0x1 //!< If this flag is specified, the file will be deletable from context menu of Error Report Details dialog. + +/*! \ingroup CrashRptAPI +* \brief Adds a registry key dump to the crash report. +* +* \return This function returns zero if succeeded. Use crGetLastErrorMsg() to retrieve the error message on fail. +* +* \param[in] pszRegKey Registry key to dump, required. +* \param[in] pszDstFileName Name of the destination file, required. +* \param[in] dwFlags Flags, reserved. +* +* \remarks +* +* Use this function to add a dump of a Windows registry key into the crash report. This function +* is available since v.1.2.6. +* +* The \a pszRegKey parameter must be the name of the registry key. The key name should begin with "HKEY_CURRENT_USER" +* or "HKEY_LOCAL_MACHINE". Other root keys are not supported. +* +* The content of the key specified by the \a pszRegKey parameter will be stored in a human-readable XML +* format and included into the error report as \a pszDstFileName destination file. You can dump multiple registry keys +* to the same destination file. +* +* The \a dwFlags parameter can be either set to zero (no flags) or with the following constant: +* +* - \ref CR_AR_ALLOW_DELETE allows the user to delete the file from error report using context menu of Error Report Details dialog. +* +* The following example shows how to dump two registry keys to a single \a regkey.xml file: +* +* \code +* +* crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\MyApp"), _T("regkey.xml"), 0); +* crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\MyApp"), _T("regkey.xml"), 0); +* +* \endcode +* +* \sa +* crAddFile2(), crAddScreenshot(), crAddProperty() +*/ + +CRASHRPTAPI(int) +crAddRegKeyW( + LPCWSTR pszRegKey, + LPCWSTR pszDstFileName, + DWORD dwFlags + ); + +/*! \ingroup CrashRptAPI +* \copydoc crAddRegKeyW() +*/ + +CRASHRPTAPI(int) +crAddRegKeyA( + LPCSTR pszRegKey, + LPCSTR pszDstFileName, + DWORD dwFlags + ); + +/*! \brief Character set-independent mapping of crAddRegKeyW() and crAddRegKeyA() functions. +* \ingroup CrashRptAPI +*/ +#ifdef UNICODE +#define crAddRegKey crAddRegKeyW +#else +#define crAddRegKey crAddRegKeyA +#endif //UNICODE + +/*! \ingroup CrashRptAPI +* \brief Manually generates an error report. +* +* \return This function returns zero if succeeded. When failed, it returns a non-zero value. +* Use crGetLastErrorMsg() function to retrieve the error message. +* +* \param[in] pExceptionInfo Exception information. +* +* \remarks +* +* Call this function to manually generate a crash report. When crash information is collected, +* control is returned to the caller. The crGenerateErrorReport() doesn't terminate the caller process. +* +* The crash report may contain the crash minidump file, crash description file in XML format and +* additional custom files added with a function like crAddFile2(). +* +* The exception information should be passed using \ref CR_EXCEPTION_INFO structure. +* +* The following example shows how to use crGenerateErrorReport() function. +* +* \code +* CR_EXCEPTION_INFO ei; +* memset(&ei, 0, sizeof(CR_EXCEPTION_INFO)); +* ei.cb = sizeof(CR_EXCEPTION_INFO); +* ei.exctype = CR_SEH_EXCEPTION; +* ei.code = 1234; +* ei.pexcptrs = NULL; +* +* int result = crGenerateErrorReport(&ei); +* +* if(result!=0) +* { +* // If goes here, crGenerateErrorReport() has failed +* // Get the last error message +* TCHAR szErrorMsg[256]; +* crGetLastErrorMsg(szErrorMsg, 256); +* } +* +* // Manually terminate program +* ExitProcess(0); +* +* \endcode +*/ + +CRASHRPTAPI(int) +crGenerateErrorReport( + __in_opt CR_EXCEPTION_INFO* pExceptionInfo + ); + +/*! \ingroup CrashRptAPI +* \brief Can be used as a SEH exception filter. +* +* \return This function returns \c EXCEPTION_EXECUTE_HANDLER if succeeds; otherwise \c EXCEPTION_CONTINUE_SEARCH. +* +* \param[in] code Exception code. +* \param[in] ep Exception pointers. +* +* \remarks +* +* This function can be called instead of a SEH exception filter +* inside of __try{}__except(Expression){} construction. The function generates an error report +* and returns control to the exception handler block. +* +* The exception code is usually retrieved with \b GetExceptionCode() intrinsic function +* and the exception pointers are retrieved with \b GetExceptionInformation() intrinsic +* function. +* +* If an error occurs, this function returns \c EXCEPTION_CONTINUE_SEARCH. +* Use crGetLastErrorMsg() to retrieve the error message on fail. +* +* The following example shows how to use crExceptionFilter(). +* +* \code +* int* p = NULL; // pointer to NULL +* __try +* { +* *p = 13; // causes an access violation exception; +* } +* __except(crExceptionFilter(GetExceptionCode(), GetExceptionInformation())) +* { +* // Terminate program +* ExitProcess(1); +* } +* +* \endcode +*/ + +CRASHRPTAPI(int) +crExceptionFilter( + unsigned int code, + __in_opt struct _EXCEPTION_POINTERS* ep); + + +// Flags used by crEmulateCrash() function +#define CR_NONCONTINUABLE_EXCEPTION 32 //!< Non continuable sofware exception. +#define CR_THROW 33 //!< Throw C++ typed exception. +#define CR_STACK_OVERFLOW 34 //!< Stack overflow. + +/*! \ingroup CrashRptAPI +* \brief Emulates a predefined crash situation. +* +* \return This function doesn't return if succeded. If failed, returns non-zero value. Call crGetLastErrorMsg() +* to get the last error message. +* +* \param[in] ExceptionType Type of crash. +* +* \remarks +* +* This function uses some a priori incorrect or vulnerable code or raises a C++ signal or raises an uncontinuable +* software exception to cause crash. +* +* This function can be used to test if CrashRpt handles a crash situation correctly. +* +* CrashRpt will intercept an error or exception if crInstall() and/or crInstallToCurrentThread2() +* were previously called. crInstall() installs exception handlers that function on per-process basis. +* crInstallToCurrentThread2() installs exception handlers that function on per-thread basis. +* +* \a ExceptionType can be one of the following constants: +* - \ref CR_SEH_EXCEPTION This will generate a null pointer exception. +* - \ref CR_CPP_TERMINATE_CALL This results in call of terminate() C++ function. +* - \ref CR_CPP_UNEXPECTED_CALL This results in call of unexpected() C++ function. +* - \ref CR_CPP_PURE_CALL This emulates a call of pure virtual method call of a C++ class instance (Visual Studio .NET 2003 and later). +* - \ref CR_CPP_NEW_OPERATOR_ERROR This emulates C++ new operator failure (Visual Studio .NET 2003 and later). +* - \ref CR_CPP_SECURITY_ERROR This emulates copy of large amount of data to a small buffer (Visual Studio .NET 2003 only). +* - \ref CR_CPP_INVALID_PARAMETER This emulates an invalid parameter C++ exception (Visual Studio 2005 and later). +* - \ref CR_CPP_SIGABRT This raises SIGABRT signal (abnormal program termination). +* - \ref CR_CPP_SIGFPE This causes floating point exception. +* - \ref CR_CPP_SIGILL This raises SIGILL signal (illegal instruction signal). +* - \ref CR_CPP_SIGINT This raises SIGINT signal. +* - \ref CR_CPP_SIGSEGV This raises SIGSEGV signal. +* - \ref CR_CPP_SIGTERM This raises SIGTERM signal (program termination request). +* - \ref CR_NONCONTINUABLE_EXCEPTION This raises a noncontinuable software exception (expected result +* is the same as in \ref CR_SEH_EXCEPTION). +* - \ref CR_THROW This throws a C++ typed exception (expected result is the same as in \ref CR_CPP_TERMINATE_CALL). +* - \ref CR_STACK_OVERFLOW This causes stack overflow. +* +* The \ref CR_SEH_EXCEPTION uses null pointer write operation to cause the access violation. +* +* The \ref CR_NONCONTINUABLE_EXCEPTION has the same effect as \ref CR_SEH_EXCEPTION, but it uses +* \b RaiseException() WinAPI function to raise noncontinuable software exception. +* +* The following example shows how to use crEmulateCrash() function. +* +* \code +* // emulate null pointer exception (access violation) +* crEmulateCrash(CR_SEH_EXCEPTION); +* \endcode +* +*/ + +CRASHRPTAPI(int) +crEmulateCrash( + unsigned ExceptionType) throw (...); + + + +/*! \ingroup CrashRptAPI +* \brief Gets the last CrashRpt error message. +* +* \return This function returns length of error message in characters. If output buffer is invalid, returns a negative number. +* +* \param[out] pszBuffer Pointer to the buffer. +* \param[in] uBuffSize Size of buffer in characters. +* +* \remarks +* +* This function gets the last CrashRpt error message. You can use this function +* to retrieve the text status of the last called CrashRpt function. +* +* If buffer is too small for the error message, the message is truncated. +* +* crGetLastErrorMsgW() and crGetLastErrorMsgA() are wide-character and multi-byte character versions +* of crGetLastErrorMsg(). The crGetLastErrorMsg() macro defines character set independent mapping. +* +* The following example shows how to use crGetLastErrorMsg() function. +* +* \code +* +* // .. call some CrashRpt function +* +* // Get the status message +* TCHAR szErrorMsg[256]; +* crGetLastErrorMsg(szErrorMsg, 256); +* \endcode +* +* \sa crGetLastErrorMsgA(), crGetLastErrorMsgW(), crGetLastErrorMsg() +*/ + +CRASHRPTAPI(int) +crGetLastErrorMsgW( + __out_ecount_z(uBuffSize) LPWSTR pszBuffer, + UINT uBuffSize); + +/*! \ingroup CrashRptAPI +* \copydoc crGetLastErrorMsgW() +* +*/ + +CRASHRPTAPI(int) +crGetLastErrorMsgA( + __out_ecount_z(uBuffSize) LPSTR pszBuffer, + UINT uBuffSize); + +/*! \brief Defines character set-independent mapping for crGetLastErrorMsgW() and crGetLastErrorMsgA(). +* \ingroup CrashRptAPI +*/ + +#ifdef UNICODE +#define crGetLastErrorMsg crGetLastErrorMsgW +#else +#define crGetLastErrorMsg crGetLastErrorMsgA +#endif //UNICODE + + +//// Helper wrapper classes + +#ifndef _CRASHRPT_NO_WRAPPERS + +/*! \class CrAutoInstallHelper +* \ingroup CrashRptWrappers +* \brief Installs exception handlers in constructor and uninstalls in destructor. +* \remarks +* Use this class to easily install/uninstall exception handlers in you \b main() +* or \b WinMain() function. +* +* This wrapper class calls crInstall() in its constructor and calls crUninstall() in +* its destructor. +* +* Use CrAutoInstallHelper::m_nInstallStatus member to check the return status of crInstall(). +* +* Example: +* +* \code +* #include +* +* void main() +* { +* CR_INSTALL_INFO info; +* memset(&info, 0, sizeof(CR_INSTALL_INFO)); +* info.cb = sizeof(CR_INSTALL_INFO); +* info.pszAppName = _T("My App Name"); +* info.pszAppVersion = _T("1.2.3"); +* info.pszEmailSubject = "Error Report from My App v.1.2.3"; +* // The address to send reports by E-mail +* info.pszEmailTo = _T("myname@hotmail.com"); +* // The URL to send reports via HTTP connection +* info.pszUrl = _T("http://myappname.com/utils/crashrpt.php"); +* info.pfnCrashCallback = CrashCallback; +* info.uPriorities[CR_HTTP] = 3; // Try HTTP first +* info.uPriorities[CR_SMTP] = 2; // Try SMTP second +* info.uPriorities[CR_SMAPI] = 1; // Try system email program last +* +* // Install crash reporting +* CrAutoInstallHelper cr_install_helper(&info); +* // Check that installed OK +* assert(cr_install_helper.m_nInstallStatus==0); +* +* // Your code follows here ... +* +* } +* \endcode +*/ + +class CrAutoInstallHelper +{ +public: + + //! Installs exception handlers to the caller process + CrAutoInstallHelper(__in PCR_INSTALL_INFOA pInfo) + { + m_nInstallStatus = crInstallA(pInfo); + } + + //! Installs exception handlers to the caller process + CrAutoInstallHelper(__in PCR_INSTALL_INFOW pInfo) + { + m_nInstallStatus = crInstallW(pInfo); + } + + //! Uninstalls exception handlers from the caller process + ~CrAutoInstallHelper() + { + if(m_nInstallStatus==0) + crUninstall(); + } + + //! Install status + int m_nInstallStatus; +}; + +/*! \class CrThreadAutoInstallHelper +* \ingroup CrashRptWrappers +* \brief Installs (uninstalls) exception handlers for the caller thread in class' constructor (destructor). +* +* \remarks +* +* This wrapper class calls crInstallToCurrentThread2() in its constructor and +* calls crUninstallFromCurrentThread() in its destructor. +* +* Use CrThreadAutoInstallHelper::m_nInstallStatus member to check +* the return status of crInstallToCurrentThread2(). +* +* Example: +* +* \code +* DWORD WINAPI ThreadProc(LPVOID lpParam) +* { +* CrThreadAutoInstallHelper cr_thread_install_helper(); +* assert(cr_thread_install_helper.m_nInstallStatus==0); +* +* // Your code follows here ... +* } +* \endcode +*/ + +class CrThreadAutoInstallHelper +{ +public: + + //! Installs exception handlers to the caller thread + CrThreadAutoInstallHelper(DWORD dwFlags=0) + { + m_nInstallStatus = crInstallToCurrentThread2(dwFlags); + } + + //! Uninstalls exception handlers from the caller thread + ~CrThreadAutoInstallHelper() + { + if (m_nInstallStatus == 0) + crUninstallFromCurrentThread(); + } + + //! Install status + int m_nInstallStatus; +}; + +#endif //!_CRASHRPT_NO_WRAPPERS + +#endif //_CRASHRPT_H_ + + diff --git a/crashrpt/include/CrashRptProbe.h b/crashrpt/include/CrashRptProbe.h new file mode 100644 index 0000000..13bbb91 --- /dev/null +++ b/crashrpt/include/CrashRptProbe.h @@ -0,0 +1,470 @@ +/************************************************************************************* +This file is a part of CrashRpt library. +Copyright (c) 2003-2013 The CrashRpt project authors. All Rights Reserved. + +Use of this source code is governed by a BSD-style license +that can be found in the License.txt file in the root of the source +tree. All contributing project authors may +be found in the Authors.txt file in the root of the source tree. +***************************************************************************************/ + +/*! \file CrashRptProbe.h +* \brief Defines the interface for the CrashRptProbe.DLL. +* \date 2009-2011 +* \author zexspectrum +*/ + +#ifndef __CRASHRPT_PROBE_H__ +#define __CRASHRPT_PROBE_H__ + +#ifdef __cplusplus +#define CRASHRPTPROBE_EXTERNC extern "C" +#else +#define CRASHRPTPROBE_EXTERNC +#endif + +// Define SAL macros to be empty if some old Visual Studio used +#ifndef __reserved +#define __reserved +#endif +#ifndef __in +#define __in +#endif +#ifndef __in_opt +#define __in_opt +#endif +#ifndef __out +#define __out +#endif +#ifndef __out_ecount +#define __out_ecount(x) +#endif +#ifndef __out_ecount_z +#define __out_ecount_z(x) +#endif + +#define CRASHRPTPROBE_API(rettype) CRASHRPTPROBE_EXTERNC rettype WINAPI + +//! Handle to an opened error report. +typedef int CrpHandle; + +/*! \defgroup CrashRptProbeAPI CrashRptProbe Functions*/ + +/*! \ingroup CrashRptProbeAPI +* \brief Opens a zipped crash report file. +* +* \return This function returns zero on success. +* +* \param[in] pszFileName Zipped report file name. +* \param[in] pszMd5Hash String containing MD5 hash for the ZIP file data. +* \param[in] pszSymSearchPath Symbol files (PDB) search path. +* \param[in] dwFlags Flags, reserved for future use. +* \param[out] phReport Handle to the opened crash report. +* +* \remarks +* +* Use this function to open a ZIP archive containing an error report. The error report typically contains +* several compressed files, such as XML crash description file, crash minidump file, and (optionally) +* application-defined files. +* +* \a pszFileName should be the name of the error report (ZIP file) to open. Absolute or relative path accepted. +* This parameter is required. +* +* \a pszMd5Hash is a string containing the MD5 hash calculated for \a pszFileName. The MD5 +* hash is a sequence of 16 characters being used for integrity checks. +* If this parameter is NULL, integrity check is not performed. +* +* If the error report is delivered by HTTP, the MD5 hash can be extracted by server-side script from the +* 'md5' parameter. When the error report is delivered by email, the MD5 hash is attached to the mail message. +* The integrity check can be performed to ensure the error report was not corrupted during delivery. +* For more information, see \ref sending_error_reports. +* +* \a pszSymSearchPath parameter defines where to look for symbols files (*.PDB). You can specify the list of +* semicolon-separated directories to search in. If this parameter is NULL, the default search sequence is used. +* For the default search sequence, see the documentation for \b SymInitialize() function in MSDN. +* +* Symbol files are required for crash report processing. They contain various information used by the debugger. +* For more information about saving symbol files, see \ref preparing_to_software_release. +* +* \a dwFlags is currently not used, should be zero. +* +* \a phReport parameter receives the handle to the opened crash report. If the function fails, +* this parameter becomes zero. +* +* This function does the following when opening report file: +* - It performs integrity checks for the error report being opened, if MD5 hash is specified. +* - It searches for crashrpt.xml and crashdump.dml files inside of ZIP archive, if such files +* do not present, it assumes the report was generated by CrashRpt v1.0. In such case it searches for +* any file having *.dmp or *.xml extension and assumes these are valid XML and DMP file. +* - It extracts and loads the XML file and checks its structure. +* - It extracts the minidump file to the temporary location. +* +* On failure, use crpGetLastErrorMsg() function to get the last error message. +* +* Use the crpCloseErrorReport() function to close the opened error report. +* +* \note +* +* The crpOpenErrorReportW() and crpOpenErrorReportA() are wide character and multibyte +* character versions of crpOpenErrorReport(). +* +* +* \sa +* crpCloseErrorReport() +*/ + +CRASHRPTPROBE_API(int) +crpOpenErrorReportW( + __in LPCWSTR pszFileName, + __in_opt LPCWSTR pszMd5Hash, + __in_opt LPCWSTR pszSymSearchPath, + __reserved DWORD dwFlags, + __out CrpHandle* phReport + ); + +/*! \ingroup CrashRptProbeAPI +* \copydoc crpOpenErrorReportW() +* +*/ + +CRASHRPTPROBE_API(int) +crpOpenErrorReportA( + __in LPCSTR pszFileName, + __in_opt LPCSTR pszMd5Hash, + __in_opt LPCSTR pszSymSearchPath, + __reserved DWORD dwFlags, + __out CrpHandle* phReport + ); + +/*! \brief Character set-independent mapping of crpOpenErrorReportW() and crpOpenErrorReportA() functions. +* \ingroup CrashRptProbeAPI +*/ + +#ifdef UNICODE +#define crpOpenErrorReport crpOpenErrorReportW +#else +#define crpOpenErrorReport crpOpenErrorReportA +#endif //UNICODE + +/*! \ingroup CrashRptProbeAPI +* \brief Closes the crash report. +* \return This function returns zero on success. +* \param[in] hReport Handle to the opened error report. +* +* \remarks +* +* Use this function to close the error report previously opened with crpOpenErrorReport() +* function. +* +* If this function fails, use crpGetLastErrorMsg() function to get the error message. +* +* \sa +* crpOpenErrorReport(), crpOpenErrorReportW(), crpOpenErrorReportA(), crpGetLastErrorMsg() +*/ + +CRASHRPTPROBE_API(int) +crpCloseErrorReport( + CrpHandle hReport + ); + +/* Table names passed to crpGetProperty() function. */ + +#define CRP_TBL_XMLDESC_MISC _T("XmlDescMisc") //!< Table: Miscellaneous info contained in crash description XML file. +#define CRP_TBL_XMLDESC_FILE_ITEMS _T("XmlDescFileItems") //!< Table: The list of file items contained in error report. +#define CRP_TBL_XMLDESC_CUSTOM_PROPS _T("XmlDescCustomProps") //!< Table: The list of application-defined properties (available since v.1.2.1). +#define CRP_TBL_MDMP_MISC _T("MdmpMisc") //!< Table: Miscellaneous info contained in crash minidump file. +#define CRP_TBL_MDMP_MODULES _T("MdmpModules") //!< Table: The list of loaded modules. +#define CRP_TBL_MDMP_THREADS _T("MdmpThreads") //!< Table: The list of threads. +#define CRP_TBL_MDMP_LOAD_LOG _T("MdmpLoadLog") //!< Table: Minidump loading log. + +/* Meta information */ + +#define CRP_META_ROW_COUNT _T("RowCount") //!< Row count in the table. + +/* Column names passed to crpGetProperty() function. */ + +// Columns IDs of the CRP_XMLDESC_MISC table +#define CRP_COL_CRASHRPT_VERSION _T("CrashRptVersion") //!< Column: Version of CrashRpt library that generated the report. +#define CRP_COL_CRASH_GUID _T("CrashGUID") //!< Column: Globally unique identifier (GUID) of the error report. +#define CRP_COL_APP_NAME _T("AppName") //!< Column: Application name. +#define CRP_COL_APP_VERSION _T("AppVersion") //!< Column: Application version. +#define CRP_COL_IMAGE_NAME _T("ImageName") //!< Column: Path to the executable file. +#define CRP_COL_OPERATING_SYSTEM _T("OperatingSystem") //!< Column: Opration system name, including build number and service pack. +#define CRP_COL_SYSTEM_TIME_UTC _T("SystemTimeUTC") //!< Column: Time (UTC) when the crash occured. +#define CRP_COL_EXCEPTION_TYPE _T("ExceptionType") //!< Column: Code of exception handler that cought the exception. +#define CRP_COL_EXCEPTION_CODE _T("ExceptionCode") //!< Column: Exception code; for the structured exceptions only. +#define CRP_COL_INVPARAM_FUNCTION _T("InvParamFunction") //!< Column: Function name; for invalid parameter errors only. +#define CRP_COL_INVPARAM_EXPRESSION _T("InvParamExpression") //!< Column: Expression; for invalid parameter errors only. +#define CRP_COL_INVPARAM_FILE _T("InvParamFile") //!< Column: Source file name; for invalid parameter errors only. +#define CRP_COL_INVPARAM_LINE _T("InvParamLine") //!< Column: Source line; for invalid parameter errors only. +#define CRP_COL_FPE_SUBCODE _T("FPESubcode") //!< Column: Subcode of floating point exception; for FPE exceptions only. +#define CRP_COL_USER_EMAIL _T("UserEmail") //!< Column: Email of the user who sent this report. +#define CRP_COL_PROBLEM_DESCRIPTION _T("ProblemDescription") //!< Column: User-provided problem description. +#define CRP_COL_MEMORY_USAGE_KBYTES _T("MemoryUsageKbytes") //!< Column: Memory usage at the moment of crash (in KB). +#define CRP_COL_GUI_RESOURCE_COUNT _T("GUIResourceCount") //!< Column: Count of used GUI resources at the moment of crash. +#define CRP_COL_OPEN_HANDLE_COUNT _T("OpenHandleCount") //!< Column: Count of open handles at the moment of crash. +#define CRP_COL_OS_IS_64BIT _T("OSIs64Bit") //!< Column: Operating system is 64-bit. +#define CRP_COL_GEO_LOCATION _T("GeoLocation") //!< Column: Geographic location of the error report sender. + +// Column IDs of the CRP_XMLDESC_FILE_ITEMS table +#define CRP_COL_FILE_ITEM_NAME _T("FileItemName") //!< Column: File list: Name of the file contained in the report. +#define CRP_COL_FILE_ITEM_DESCRIPTION _T("FileItemDescription") //!< Column: File list: Description of the file contained in the report. + +// Column IDs of the CRP_XMLDESC_CUSTOM_PROPS table +#define CRP_COL_PROPERTY_NAME _T("PropertyName") //!< Column: Name of the application-defined property. +#define CRP_COL_PROPERTY_VALUE _T("PropertyValue") //!< Column: Value of the application-defined property. + +// Column IDs of the CRP_MDMP_MISC table +#define CRP_COL_CPU_ARCHITECTURE _T("CPUArchitecture") //!< Column: Processor architecture. +#define CRP_COL_CPU_COUNT _T("CPUCount") //!< Column: Number of processors. +#define CRP_COL_PRODUCT_TYPE _T("ProductType") //!< Column: Type of system (server or workstation). +#define CRP_COL_OS_VER_MAJOR _T("OSVerMajor") //!< Column: OS major version. +#define CRP_COL_OS_VER_MINOR _T("OSVerMinor") //!< Column: OS minor version. +#define CRP_COL_OS_VER_BUILD _T("OSVerBuild") //!< Column: OS build number. +#define CRP_COL_OS_VER_CSD _T("OSVerCSD") //!< Column: The latest service pack installed. +#define CRP_COL_EXCPTRS_EXCEPTION_CODE _T("ExptrsExceptionCode") //!< Column: Code of the structured exception. +#define CRP_COL_EXCEPTION_ADDRESS _T("ExceptionAddress") //!< Column: Exception address. +#define CRP_COL_EXCEPTION_THREAD_ROWID _T("ExceptionThreadROWID") //!< Column: ROWID in \ref CRP_TBL_MDMP_THREADS of the thread in which exception occurred. +#define CRP_COL_EXCEPTION_THREAD_STACK_MD5 _T("ExceptionThreadStackMD5") //!< Column: MD5 hash of the stack trace of the thread where exception occurred. +#define CRP_COL_EXCEPTION_MODULE_ROWID _T("ExceptionModuleROWID") //!< Column: ROWID in \ref CRP_TBL_MDMP_MODULES of the module in which exception occurred. + +// Column IDs of the CRP_MDMP_MODULES table +#define CRP_COL_MODULE_NAME _T("ModuleName") //!< Column: Module name. +#define CRP_COL_MODULE_IMAGE_NAME _T("ModuleImageName") //!< Column: Image name containing full path. +#define CRP_COL_MODULE_BASE_ADDRESS _T("ModuleBaseAddress") //!< Column: Module base load address. +#define CRP_COL_MODULE_SIZE _T("ModuleSize") //!< Column: Module size. +#define CRP_COL_MODULE_LOADED_PDB_NAME _T("LoadedPDBName") //!< Column: The full path and file name of the .pdb file. +#define CRP_COL_MODULE_LOADED_IMAGE_NAME _T("LoadedImageName") //!< Column: The full path and file name of executable file. +#define CRP_COL_MODULE_SYM_LOAD_STATUS _T("ModuleSymLoadStatus") //!< Column: Symbol load status for the module. + +// Column IDs of the CRP_MDMP_THREADS table +#define CRP_COL_THREAD_ID _T("ThdeadID") //!< Column: Thread ID. +#define CRP_COL_THREAD_STACK_TABLEID _T("ThreadStackTABLEID") //!< Column: The table ID of the table containing stack trace for this thread. + +// Column IDs of a stack trace table +#define CRP_COL_STACK_MODULE_ROWID _T("StackModuleROWID") //!< Column: Stack trace: ROWID of the module in the CRP_TBL_MODULES table. +#define CRP_COL_STACK_SYMBOL_NAME _T("StackSymbolName") //!< Column: Stack trace: symbol name. +#define CRP_COL_STACK_OFFSET_IN_SYMBOL _T("StackOffsetInSymbol") //!< Column: Stack trace: offset in symbol, hexadecimal. +#define CRP_COL_STACK_SOURCE_FILE _T("StackSourceFile") //!< Column: Stack trace: source file name. +#define CRP_COL_STACK_SOURCE_LINE _T("StackSourceLine") //!< Column: Stack trace: source file line number. +#define CRP_COL_STACK_ADDR_PC_OFFSET _T("StackAddrPCOffset") //!< Column: Stack trace: AddrPC offset. + +// Column IDs of the CRP_MDMP_LOAD_LOG table +#define CRP_COL_LOAD_LOG_ENTRY _T("LoadLogEntry") //!< Column: A entry of the minidump loading log. + +/*! \ingroup CrashRptProbeAPI +* \brief Retrieves a string property from crash report. +* \return This function returns zero on success, with one exception (see Remarks for more information). +* +* \param[in] hReport Handle to the previously opened crash report. +* \param[in] lpszTableId Table ID. +* \param[in] lpszColumnId Column ID. +* \param[in] nRowIndex Index of the row in the table. +* \param[out] lpszBuffer Output buffer. +* \param[in] cchBuffSize Size of the output buffer in characters. +* \param[out] pcchCount Count of characters written to the buffer. +* +* \remarks +* +* Use this function to retrieve data from the crash report that was previously opened with the +* crpOpenErrorReport() function. +* +* Properties are organized into tables having rows and columns. For the list of available tables, +* see \ref using_crashrptprobe_api. +* +* To get the number of rows in a table, pass the constant \ref CRP_META_ROW_COUNT as column ID. In this case the +* function returns number of rows as its return value, or negative value on failure. +* +* In all other cases the function returns zero on success. +* +* Some properties are loaded from crash description XML file, while others are loaded from crash minidump file. +* The minidump is loaded once when you retrive a property from it. This reduces the overall processing time. +* +* \a hReport should be the handle to the opened error report. +* +* \a lpszTableId represente the ID of the table. +* +* \a lpszColumnId represents the ID of the column in the table. +* +* \a nRowIndex defines the zero-based index of the row in the table. +* +* \a lpszBuffer defines the buffer where retrieved property value will be placed. If this parameter +* is NULL, it is ignored and \a pcchCount is set with the required size in characters of the buffer. +* +* \a cchBuffSize defines the buffer size in characters. To calculate required buffer size, set \a lpszBuffer with NULL, +* the function will set \a pcchCount with the number of characters required. +* +* \a pcchCount is set with the actual count of characters copied to the \a lpszBuffer. If this parameter is NULL, +* it is ignored. +* +* If this function fails, use crpGetLastErrorMsg() function to get the error message. +* +* For code examples of using this function, see \ref crashrptprobe_api_examples. +* +* \note +* The crpGetPropertyW() and crpGetPropertyA() are wide character and multibyte +* character versions of crpGetProperty(). +* +* \sa +* crpGetPropertyW(), crpGetPropertyA(), crpOpenErrorReport(), crpGetLastErrorMsg() +*/ + +CRASHRPTPROBE_API(int) +crpGetPropertyW( + CrpHandle hReport, + LPCWSTR lpszTableId, + LPCWSTR lpszColumnId, + INT nRowIndex, + __out_ecount_z(pcchBuffSize) LPWSTR lpszBuffer, + ULONG cchBuffSize, + __out PULONG pcchCount + ); + +/*! \ingroup CrashRptProbeAPI +* \copydoc crpGetPropertyW() +* +*/ + +CRASHRPTPROBE_API(int) +crpGetPropertyA( + CrpHandle hReport, + LPCSTR lpszTableId, + LPCSTR lpszColumnId, + INT nRowIndex, + __out_ecount_z(pcchBuffSize) LPSTR lpszBuffer, + ULONG cchBuffSize, + __out PULONG pcchCount + ); + +/*! \brief Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions. +* \ingroup CrashRptProbeAPI +*/ + +#ifdef UNICODE +#define crpGetProperty crpGetPropertyW +#else +#define crpGetProperty crpGetPropertyA +#endif //UNICODE + +/*! \ingroup CrashRptProbeAPI +* \brief Extracts a file from the opened error report. +* \return This function returns zero if succeeded. +* +* \param[in] hReport Handle to the opened error report. +* \param[in] lpszFileName The name of the file to extract. +* \param[in] lpszFileSaveAs The resulting name of the extracted file. +* \param[in] bOverwriteExisting Overwrite the destination file if it already exists? +* +* \remarks +* +* Use this function to extract a compressed file from the error report (ZIP) file. +* +* \a lpszFileName parameter should be the name of the file to extract. For more information +* about enumerating file names, see \ref crashrptprobe_api_examples. +* +* \a lpszFileSaveAs defines the name of the file to extract to. +* +* \a bOverwriteExisting flag defines the behavior when the destination file already exists. +* If this parameter is TRUE, the file is overwritten, otherwise the function fails. +* +* If this function fails, use crpGetLastErrorMsg() to retrieve the error message. +* +* \note +* The crpExtractFileW() and crpExtractFileA() are wide character and multibyte +* character versions of crpExtractFile(). +* +* \sa +* crpExtractFileA(), crpExtractFileW(), crpExtractFile() +*/ + +CRASHRPTPROBE_API(int) +crpExtractFileW( + CrpHandle hReport, + LPCWSTR lpszFileName, + LPCWSTR lpszFileSaveAs, + BOOL bOverwriteExisting + ); + +/*! \ingroup CrashRptProbeAPI +* \copydoc crpExtractFileW() +*/ + +CRASHRPTPROBE_API(int) +crpExtractFileA( + CrpHandle hReport, + LPCSTR lpszFileName, + LPCSTR lpszFileSaveAs, + BOOL bOverwriteExisting + ); + +/*! \brief Character set-independent mapping of crpExtractFileW() and crpExtractFileA() functions. +* \ingroup CrashRptProbeAPI +*/ + +#ifdef UNICODE +#define crpExtractFile crpExtractFileW +#else +#define crpExtractFile crpExtractFileA +#endif //UNICODE + +/*! \ingroup CrashRptProbeAPI +* \brief Gets the last CrashRptProbe error message. +* +* \return This function returns length of error message in characters. +* +* \param[out] pszBuffer Pointer to the buffer. +* \param[in] cchBuffSize Size of buffer in characters. +* +* \remarks +* +* This function gets the last CrashRptProbe error message. You can use this function +* to retrieve the text status of the last called CrashRptProbe function. +* +* If buffer is too small for the error message, the message is truncated. +* +* \note +* crpGetLastErrorMsgW() and crpGetLastErrorMsgA() are wide-character and multi-byte character versions +* of crpGetLastErrorMsg(). The crpGetLastErrorMsg() macro defines character set independent mapping. +* +* The following example shows how to use crpGetLastErrorMsg() function. +* +* \code +* +* // .. call some CrashRptProbe function +* +* // Get the status message +* TCHAR szErrorMsg[256]; +* crpGetLastErrorMsg(szErrorMsg, 256); +* \endcode +* +* \sa crpGetLastErrorMsgA(), crpGetLastErrorMsgW(), crpGetLastErrorMsg() +*/ + +CRASHRPTPROBE_API(int) +crpGetLastErrorMsgW( + __out_ecount(cchBuffSize) LPWSTR pszBuffer, + __in UINT cchBuffSize); + +/*! \ingroup CrashRptProbeAPI +* \copydoc crpGetLastErrorMsgW() +* +*/ + +CRASHRPTPROBE_API(int) +crpGetLastErrorMsgA( + __out_ecount(cchBuffSize) LPSTR pszBuffer, + __in UINT cchBuffSize); + +/*! \brief Defines character set-independent mapping for crpGetLastErrorMsgW() and crpGetLastErrorMsgA(). +* \ingroup CrashRptProbeAPI +*/ + +#ifdef UNICODE +#define crpGetLastErrorMsg crpGetLastErrorMsgW +#else +#define crpGetLastErrorMsg crpGetLastErrorMsgA +#endif //UNICODE + + +#endif __CRASHRPT_PROBE_H__ + diff --git a/crashrpt/lib/dll/CrashRpt.dll b/crashrpt/lib/dll/CrashRpt.dll new file mode 100644 index 0000000..bcb4a46 Binary files /dev/null and b/crashrpt/lib/dll/CrashRpt.dll differ diff --git a/crashrpt/lib/dll/CrashRpt.lib b/crashrpt/lib/dll/CrashRpt.lib new file mode 100644 index 0000000..5633cb4 Binary files /dev/null and b/crashrpt/lib/dll/CrashRpt.lib differ diff --git a/crashrpt/lib/dll/CrashRptD.dll b/crashrpt/lib/dll/CrashRptD.dll new file mode 100644 index 0000000..956d2ca Binary files /dev/null and b/crashrpt/lib/dll/CrashRptD.dll differ diff --git a/crashrpt/lib/dll/CrashRptD.lib b/crashrpt/lib/dll/CrashRptD.lib new file mode 100644 index 0000000..7cdf692 Binary files /dev/null and b/crashrpt/lib/dll/CrashRptD.lib differ diff --git a/crashrpt/lib/dll/readme.txt b/crashrpt/lib/dll/readme.txt new file mode 100644 index 0000000..3fad904 --- /dev/null +++ b/crashrpt/lib/dll/readme.txt @@ -0,0 +1 @@ +Built with VS 2015 and dynamic runtime libraries \ No newline at end of file diff --git a/crashrpt/lib/static/CrashRptLIB.lib b/crashrpt/lib/static/CrashRptLIB.lib new file mode 100644 index 0000000..b1d59b8 Binary files /dev/null and b/crashrpt/lib/static/CrashRptLIB.lib differ diff --git a/crashrpt/lib/static/CrashRptLIBd.lib b/crashrpt/lib/static/CrashRptLIBd.lib new file mode 100644 index 0000000..5b51992 Binary files /dev/null and b/crashrpt/lib/static/CrashRptLIBd.lib differ diff --git a/crashrpt/lib/static/readme.txt b/crashrpt/lib/static/readme.txt new file mode 100644 index 0000000..d9af81c --- /dev/null +++ b/crashrpt/lib/static/readme.txt @@ -0,0 +1 @@ +Built with VS 2015 and static runtime libraries \ No newline at end of file diff --git a/portaudio/include/pa_asio.h b/portaudio/include/pa_asio.h new file mode 100644 index 0000000..9c606a9 --- /dev/null +++ b/portaudio/include/pa_asio.h @@ -0,0 +1,150 @@ +#ifndef PA_ASIO_H +#define PA_ASIO_H +/* + * $Id$ + * PortAudio Portable Real-Time Audio Library + * ASIO specific extensions + * + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + + +/** @file + @ingroup public_header + @brief ASIO-specific PortAudio API extension header file. +*/ + +#include "portaudio.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + +/** Retrieve legal native buffer sizes for the specificed device, in sample frames. + + @param device The global index of the device about which the query is being made. + @param minBufferSizeFrames A pointer to the location which will receive the minimum buffer size value. + @param maxBufferSizeFrames A pointer to the location which will receive the maximum buffer size value. + @param preferredBufferSizeFrames A pointer to the location which will receive the preferred buffer size value. + @param granularity A pointer to the location which will receive the "granularity". This value determines + the step size used to compute the legal values between minBufferSizeFrames and maxBufferSizeFrames. + If granularity is -1 then available buffer size values are powers of two. + + @see ASIOGetBufferSize in the ASIO SDK. + + @note: this function used to be called PaAsio_GetAvailableLatencyValues. There is a + #define that maps PaAsio_GetAvailableLatencyValues to this function for backwards compatibility. +*/ +PaError PaAsio_GetAvailableBufferSizes( PaDeviceIndex device, + long *minBufferSizeFrames, long *maxBufferSizeFrames, long *preferredBufferSizeFrames, long *granularity ); + + +/** Backwards compatibility alias for PaAsio_GetAvailableBufferSizes + + @see PaAsio_GetAvailableBufferSizes +*/ +#define PaAsio_GetAvailableLatencyValues PaAsio_GetAvailableBufferSizes + + +/** Display the ASIO control panel for the specified device. + + @param device The global index of the device whose control panel is to be displayed. + @param systemSpecific On Windows, the calling application's main window handle, + on Macintosh this value should be zero. +*/ +PaError PaAsio_ShowControlPanel( PaDeviceIndex device, void* systemSpecific ); + + + + +/** Retrieve a pointer to a string containing the name of the specified + input channel. The string is valid until Pa_Terminate is called. + + The string will be no longer than 32 characters including the null terminator. +*/ +PaError PaAsio_GetInputChannelName( PaDeviceIndex device, int channelIndex, + const char** channelName ); + + +/** Retrieve a pointer to a string containing the name of the specified + input channel. The string is valid until Pa_Terminate is called. + + The string will be no longer than 32 characters including the null terminator. +*/ +PaError PaAsio_GetOutputChannelName( PaDeviceIndex device, int channelIndex, + const char** channelName ); + + +/** Set the sample rate of an open paASIO stream. + + @param stream The stream to operate on. + @param sampleRate The new sample rate. + + Note that this function may fail if the stream is alredy running and the + ASIO driver does not support switching the sample rate of a running stream. + + Returns paIncompatibleStreamHostApi if stream is not a paASIO stream. +*/ +PaError PaAsio_SetStreamSampleRate( PaStream* stream, double sampleRate ); + + +#define paAsioUseChannelSelectors (0x01) + +typedef struct PaAsioStreamInfo{ + unsigned long size; /**< sizeof(PaAsioStreamInfo) */ + PaHostApiTypeId hostApiType; /**< paASIO */ + unsigned long version; /**< 1 */ + + unsigned long flags; + + /* Support for opening only specific channels of an ASIO device. + If the paAsioUseChannelSelectors flag is set, channelSelectors is a + pointer to an array of integers specifying the device channels to use. + When used, the length of the channelSelectors array must match the + corresponding channelCount parameter to Pa_OpenStream() otherwise a + crash may result. + The values in the selectors array must specify channels within the + range of supported channels for the device or paInvalidChannelCount will + result. + */ + int *channelSelectors; +}PaAsioStreamInfo; + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* PA_ASIO_H */ diff --git a/portaudio/include/pa_jack.h b/portaudio/include/pa_jack.h new file mode 100644 index 0000000..99ef833 --- /dev/null +++ b/portaudio/include/pa_jack.h @@ -0,0 +1,77 @@ +#ifndef PA_JACK_H +#define PA_JACK_H + +/* + * $Id: + * PortAudio Portable Real-Time Audio Library + * JACK-specific extensions + * + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + * @ingroup public_header + * @brief JACK-specific PortAudio API extension header file. + */ + +#include "portaudio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Set the JACK client name. + * + * During Pa_Initialize, When PA JACK connects as a client of the JACK server, it requests a certain + * name, which is for instance prepended to port names. By default this name is "PortAudio". The + * JACK server may append a suffix to the client name, in order to avoid clashes among clients that + * try to connect with the same name (e.g., different PA JACK clients). + * + * This function must be called before Pa_Initialize, otherwise it won't have any effect. Note that + * the string is not copied, but instead referenced directly, so it must not be freed for as long as + * PA might need it. + * @sa PaJack_GetClientName + */ +PaError PaJack_SetClientName( const char* name ); + +/** Get the JACK client name used by PA JACK. + * + * The caller is responsible for freeing the returned pointer. + */ +PaError PaJack_GetClientName(const char** clientName); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/portaudio/include/pa_linux_alsa.h b/portaudio/include/pa_linux_alsa.h new file mode 100644 index 0000000..7ac6736 --- /dev/null +++ b/portaudio/include/pa_linux_alsa.h @@ -0,0 +1,107 @@ +#ifndef PA_LINUX_ALSA_H +#define PA_LINUX_ALSA_H + +/* + * $Id$ + * PortAudio Portable Real-Time Audio Library + * ALSA-specific extensions + * + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + * @ingroup public_header + * @brief ALSA-specific PortAudio API extension header file. + */ + +#include "portaudio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PaAlsaStreamInfo +{ + unsigned long size; + PaHostApiTypeId hostApiType; + unsigned long version; + + const char *deviceString; +} +PaAlsaStreamInfo; + +/** Initialize host API specific structure, call this before setting relevant attributes. */ +void PaAlsa_InitializeStreamInfo( PaAlsaStreamInfo *info ); + +/** Instruct whether to enable real-time priority when starting the audio thread. + * + * If this is turned on by the stream is started, the audio callback thread will be created + * with the FIFO scheduling policy, which is suitable for realtime operation. + **/ +void PaAlsa_EnableRealtimeScheduling( PaStream *s, int enable ); + +#if 0 +void PaAlsa_EnableWatchdog( PaStream *s, int enable ); +#endif + +/** Get the ALSA-lib card index of this stream's input device. */ +PaError PaAlsa_GetStreamInputCard( PaStream *s, int *card ); + +/** Get the ALSA-lib card index of this stream's output device. */ +PaError PaAlsa_GetStreamOutputCard( PaStream *s, int *card ); + +/** Set the number of periods (buffer fragments) to configure devices with. + * + * By default the number of periods is 4, this is the lowest number of periods that works well on + * the author's soundcard. + * @param numPeriods The number of periods. + */ +PaError PaAlsa_SetNumPeriods( int numPeriods ); + +/** Set the maximum number of times to retry opening busy device (sleeping for a + * short interval inbetween). + */ +PaError PaAlsa_SetRetriesBusy( int retries ); + +/** Set the path and name of ALSA library file if PortAudio is configured to load it dynamically (see + * PA_ALSA_DYNAMIC). This setting will overwrite the default name set by PA_ALSA_PATHNAME define. + * @param pathName Full path with filename. Only filename can be used, but dlopen() will lookup default + * searchable directories (/usr/lib;/usr/local/lib) then. + */ +void PaAlsa_SetLibraryPathName( const char *pathName ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/portaudio/include/pa_mac_core.h b/portaudio/include/pa_mac_core.h new file mode 100644 index 0000000..83e40a6 --- /dev/null +++ b/portaudio/include/pa_mac_core.h @@ -0,0 +1,191 @@ +#ifndef PA_MAC_CORE_H +#define PA_MAC_CORE_H +/* + * PortAudio Portable Real-Time Audio Library + * Macintosh Core Audio specific extensions + * portaudio.h should be included before this file. + * + * Copyright (c) 2005-2006 Bjorn Roche + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + * @ingroup public_header + * @brief CoreAudio-specific PortAudio API extension header file. + */ + +#include "portaudio.h" + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * A pointer to a paMacCoreStreamInfo may be passed as + * the hostApiSpecificStreamInfo in the PaStreamParameters struct + * when opening a stream or querying the format. Use NULL, for the + * defaults. Note that for duplex streams, flags for input and output + * should be the same or behaviour is undefined. + */ +typedef struct +{ + unsigned long size; /**size of whole structure including this header */ + PaHostApiTypeId hostApiType; /**host API for which this data is intended */ + unsigned long version; /**structure version */ + unsigned long flags; /** flags to modify behaviour */ + SInt32 const * channelMap; /** Channel map for HAL channel mapping , if not needed, use NULL;*/ + unsigned long channelMapSize; /** Channel map size for HAL channel mapping , if not needed, use 0;*/ +} PaMacCoreStreamInfo; + +/** + * Functions + */ + + +/** Use this function to initialize a paMacCoreStreamInfo struct + * using the requested flags. Note that channel mapping is turned + * off after a call to this function. + * @param data The datastructure to initialize + * @param flags The flags to initialize the datastructure with. +*/ +void PaMacCore_SetupStreamInfo( PaMacCoreStreamInfo *data, unsigned long flags ); + +/** call this after pa_SetupMacCoreStreamInfo to use channel mapping as described in notes.txt. + * @param data The stream info structure to assign a channel mapping to + * @param channelMap The channel map array, as described in notes.txt. This array pointer will be used directly (ie the underlying data will not be copied), so the caller should not free the array until after the stream has been opened. + * @param channelMapSize The size of the channel map array. + */ +void PaMacCore_SetupChannelMap( PaMacCoreStreamInfo *data, const SInt32 * const channelMap, unsigned long channelMapSize ); + +/** + * Retrieve the AudioDeviceID of the input device assigned to an open stream + * + * @param s The stream to query. + * + * @return A valid AudioDeviceID, or NULL if an error occurred. + */ +AudioDeviceID PaMacCore_GetStreamInputDevice( PaStream* s ); + +/** + * Retrieve the AudioDeviceID of the output device assigned to an open stream + * + * @param s The stream to query. + * + * @return A valid AudioDeviceID, or NULL if an error occurred. + */ +AudioDeviceID PaMacCore_GetStreamOutputDevice( PaStream* s ); + +/** + * Returns a statically allocated string with the device's name + * for the given channel. NULL will be returned on failure. + * + * This function's implemenation is not complete! + * + * @param device The PortAudio device index. + * @param channel The channel number who's name is requested. + * @return a statically allocated string with the name of the device. + * Because this string is statically allocated, it must be + * coppied if it is to be saved and used by the user after + * another call to this function. + * + */ +const char *PaMacCore_GetChannelName( int device, int channelIndex, bool input ); + + +/** Retrieve the range of legal native buffer sizes for the specificed device, in sample frames. + + @param device The global index of the PortAudio device about which the query is being made. + @param minBufferSizeFrames A pointer to the location which will receive the minimum buffer size value. + @param maxBufferSizeFrames A pointer to the location which will receive the maximum buffer size value. + + @see kAudioDevicePropertyBufferFrameSizeRange in the CoreAudio SDK. + */ +PaError PaMacCore_GetBufferSizeRange( PaDeviceIndex device, + long *minBufferSizeFrames, long *maxBufferSizeFrames ); + + +/** + * Flags + */ + +/** + * The following flags alter the behaviour of PA on the mac platform. + * they can be ORed together. These should work both for opening and + * checking a device. + */ + +/** Allows PortAudio to change things like the device's frame size, + * which allows for much lower latency, but might disrupt the device + * if other programs are using it, even when you are just Querying + * the device. */ +#define paMacCoreChangeDeviceParameters (0x01) + +/** In combination with the above flag, + * causes the stream opening to fail, unless the exact sample rates + * are supported by the device. */ +#define paMacCoreFailIfConversionRequired (0x02) + +/** These flags set the SR conversion quality, if required. The wierd ordering + * allows Maximum Quality to be the default.*/ +#define paMacCoreConversionQualityMin (0x0100) +#define paMacCoreConversionQualityMedium (0x0200) +#define paMacCoreConversionQualityLow (0x0300) +#define paMacCoreConversionQualityHigh (0x0400) +#define paMacCoreConversionQualityMax (0x0000) + +/** + * Here are some "preset" combinations of flags (above) to get to some + * common configurations. THIS IS OVERKILL, but if more flags are added + * it won't be. + */ + +/**This is the default setting: do as much sample rate conversion as possible + * and as little mucking with the device as possible. */ +#define paMacCorePlayNice (0x00) +/**This setting is tuned for pro audio apps. It allows SR conversion on input + and output, but it tries to set the appropriate SR on the device.*/ +#define paMacCorePro (0x01) +/**This is a setting to minimize CPU usage and still play nice.*/ +#define paMacCoreMinimizeCPUButPlayNice (0x0100) +/**This is a setting to minimize CPU usage, even if that means interrupting the device. */ +#define paMacCoreMinimizeCPU (0x0101) + + +#ifdef __cplusplus +} +#endif /** __cplusplus */ + +#endif /** PA_MAC_CORE_H */ diff --git a/portaudio/include/pa_win_ds.h b/portaudio/include/pa_win_ds.h new file mode 100644 index 0000000..5d38641 --- /dev/null +++ b/portaudio/include/pa_win_ds.h @@ -0,0 +1,95 @@ +#ifndef PA_WIN_DS_H +#define PA_WIN_DS_H +/* + * $Id: $ + * PortAudio Portable Real-Time Audio Library + * DirectSound specific extensions + * + * Copyright (c) 1999-2007 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + @ingroup public_header + @brief DirectSound-specific PortAudio API extension header file. +*/ + +#include "portaudio.h" +#include "pa_win_waveformat.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + +#define paWinDirectSoundUseLowLevelLatencyParameters (0x01) +#define paWinDirectSoundUseChannelMask (0x04) + + +typedef struct PaWinDirectSoundStreamInfo{ + unsigned long size; /**< sizeof(PaWinDirectSoundStreamInfo) */ + PaHostApiTypeId hostApiType; /**< paDirectSound */ + unsigned long version; /**< 2 */ + + unsigned long flags; /**< enable other features of this struct */ + + /** + low-level latency setting support + Sets the size of the DirectSound host buffer. + When flags contains the paWinDirectSoundUseLowLevelLatencyParameters + this size will be used instead of interpreting the generic latency + parameters to Pa_OpenStream(). If the flag is not set this value is ignored. + + If the stream is a full duplex stream the implementation requires that + the values of framesPerBuffer for input and output match (if both are specified). + */ + unsigned long framesPerBuffer; + + /** + support for WAVEFORMATEXTENSIBLE channel masks. If flags contains + paWinDirectSoundUseChannelMask this allows you to specify which speakers + to address in a multichannel stream. Constants for channelMask + are specified in pa_win_waveformat.h + + */ + PaWinWaveFormatChannelMask channelMask; + +}PaWinDirectSoundStreamInfo; + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* PA_WIN_DS_H */ diff --git a/portaudio/include/pa_win_wasapi.h b/portaudio/include/pa_win_wasapi.h new file mode 100644 index 0000000..1d86896 --- /dev/null +++ b/portaudio/include/pa_win_wasapi.h @@ -0,0 +1,443 @@ +#ifndef PA_WIN_WASAPI_H +#define PA_WIN_WASAPI_H +/* + * $Id: $ + * PortAudio Portable Real-Time Audio Library + * DirectSound specific extensions + * + * Copyright (c) 1999-2007 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + @ingroup public_header + @brief WASAPI-specific PortAudio API extension header file. +*/ + +#include "portaudio.h" +#include "pa_win_waveformat.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + +/* Setup flags */ +typedef enum PaWasapiFlags +{ + /* puts WASAPI into exclusive mode */ + paWinWasapiExclusive = (1 << 0), + + /* allows to skip internal PA processing completely */ + paWinWasapiRedirectHostProcessor = (1 << 1), + + /* assigns custom channel mask */ + paWinWasapiUseChannelMask = (1 << 2), + + /* selects non-Event driven method of data read/write + Note: WASAPI Event driven core is capable of 2ms latency!!!, but Polling + method can only provide 15-20ms latency. */ + paWinWasapiPolling = (1 << 3), + + /* forces custom thread priority setting, must be used if PaWasapiStreamInfo::threadPriority + is set to a custom value */ + paWinWasapiThreadPriority = (1 << 4) +} +PaWasapiFlags; +#define paWinWasapiExclusive (paWinWasapiExclusive) +#define paWinWasapiRedirectHostProcessor (paWinWasapiRedirectHostProcessor) +#define paWinWasapiUseChannelMask (paWinWasapiUseChannelMask) +#define paWinWasapiPolling (paWinWasapiPolling) +#define paWinWasapiThreadPriority (paWinWasapiThreadPriority) + + +/* Host processor. Allows to skip internal PA processing completely. + You must set paWinWasapiRedirectHostProcessor flag to PaWasapiStreamInfo::flags member + in order to have host processor redirected to your callback. + Use with caution! inputFrames and outputFrames depend solely on final device setup. + To query maximal values of inputFrames/outputFrames use PaWasapi_GetFramesPerHostBuffer. +*/ +typedef void (*PaWasapiHostProcessorCallback) (void *inputBuffer, long inputFrames, + void *outputBuffer, long outputFrames, + void *userData); + +/* Device role. */ +typedef enum PaWasapiDeviceRole +{ + eRoleRemoteNetworkDevice = 0, + eRoleSpeakers, + eRoleLineLevel, + eRoleHeadphones, + eRoleMicrophone, + eRoleHeadset, + eRoleHandset, + eRoleUnknownDigitalPassthrough, + eRoleSPDIF, + eRoleHDMI, + eRoleUnknownFormFactor +} +PaWasapiDeviceRole; + + +/* Jack connection type. */ +typedef enum PaWasapiJackConnectionType +{ + eJackConnTypeUnknown, + eJackConnType3Point5mm, + eJackConnTypeQuarter, + eJackConnTypeAtapiInternal, + eJackConnTypeRCA, + eJackConnTypeOptical, + eJackConnTypeOtherDigital, + eJackConnTypeOtherAnalog, + eJackConnTypeMultichannelAnalogDIN, + eJackConnTypeXlrProfessional, + eJackConnTypeRJ11Modem, + eJackConnTypeCombination +} +PaWasapiJackConnectionType; + + +/* Jack geometric location. */ +typedef enum PaWasapiJackGeoLocation +{ + eJackGeoLocUnk = 0, + eJackGeoLocRear = 0x1, /* matches EPcxGeoLocation::eGeoLocRear */ + eJackGeoLocFront, + eJackGeoLocLeft, + eJackGeoLocRight, + eJackGeoLocTop, + eJackGeoLocBottom, + eJackGeoLocRearPanel, + eJackGeoLocRiser, + eJackGeoLocInsideMobileLid, + eJackGeoLocDrivebay, + eJackGeoLocHDMI, + eJackGeoLocOutsideMobileLid, + eJackGeoLocATAPI, + eJackGeoLocReserved5, + eJackGeoLocReserved6, +} +PaWasapiJackGeoLocation; + + +/* Jack general location. */ +typedef enum PaWasapiJackGenLocation +{ + eJackGenLocPrimaryBox = 0, + eJackGenLocInternal, + eJackGenLocSeparate, + eJackGenLocOther +} +PaWasapiJackGenLocation; + + +/* Jack's type of port. */ +typedef enum PaWasapiJackPortConnection +{ + eJackPortConnJack = 0, + eJackPortConnIntegratedDevice, + eJackPortConnBothIntegratedAndJack, + eJackPortConnUnknown +} +PaWasapiJackPortConnection; + + +/* Thread priority. */ +typedef enum PaWasapiThreadPriority +{ + eThreadPriorityNone = 0, + eThreadPriorityAudio, //!< Default for Shared mode. + eThreadPriorityCapture, + eThreadPriorityDistribution, + eThreadPriorityGames, + eThreadPriorityPlayback, + eThreadPriorityProAudio, //!< Default for Exclusive mode. + eThreadPriorityWindowManager +} +PaWasapiThreadPriority; + + +/* Stream descriptor. */ +typedef struct PaWasapiJackDescription +{ + unsigned long channelMapping; + unsigned long color; /* derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */ + PaWasapiJackConnectionType connectionType; + PaWasapiJackGeoLocation geoLocation; + PaWasapiJackGenLocation genLocation; + PaWasapiJackPortConnection portConnection; + unsigned int isConnected; +} +PaWasapiJackDescription; + + +/** Stream category. + Note: + - values are equal to WASAPI AUDIO_STREAM_CATEGORY enum + - supported since Windows 8.0, noop on earler versions + - values 1,2 are deprecated on Windows 10 and not included into enumeration + + @version Available as of 19.6.0 +*/ +typedef enum PaWasapiStreamCategory +{ + eAudioCategoryOther = 0, + eAudioCategoryCommunications = 3, + eAudioCategoryAlerts = 4, + eAudioCategorySoundEffects = 5, + eAudioCategoryGameEffects = 6, + eAudioCategoryGameMedia = 7, + eAudioCategoryGameChat = 8, + eAudioCategorySpeech = 9, + eAudioCategoryMovie = 10, + eAudioCategoryMedia = 11 +} +PaWasapiStreamCategory; + + +/** Stream option. + Note: + - values are equal to WASAPI AUDCLNT_STREAMOPTIONS enum + - supported since Windows 8.1, noop on earler versions + + @version Available as of 19.6.0 +*/ +typedef enum PaWasapiStreamOption +{ + eStreamOptionNone = 0, //!< default + eStreamOptionRaw = 1, //!< bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1 + eStreamOptionMatchFormat = 2 //!< force WASAPI Audio Engine into a stream format, supported since Windows 10 +} +PaWasapiStreamOption; + + +/* Stream descriptor. */ +typedef struct PaWasapiStreamInfo +{ + unsigned long size; /**< sizeof(PaWasapiStreamInfo) */ + PaHostApiTypeId hostApiType; /**< paWASAPI */ + unsigned long version; /**< 1 */ + + unsigned long flags; /**< collection of PaWasapiFlags */ + + /** Support for WAVEFORMATEXTENSIBLE channel masks. If flags contains + paWinWasapiUseChannelMask this allows you to specify which speakers + to address in a multichannel stream. Constants for channelMask + are specified in pa_win_waveformat.h. Will be used only if + paWinWasapiUseChannelMask flag is specified. + */ + PaWinWaveFormatChannelMask channelMask; + + /** Delivers raw data to callback obtained from GetBuffer() methods skipping + internal PortAudio processing inventory completely. userData parameter will + be the same that was passed to Pa_OpenStream method. Will be used only if + paWinWasapiRedirectHostProcessor flag is specified. + */ + PaWasapiHostProcessorCallback hostProcessorOutput; + PaWasapiHostProcessorCallback hostProcessorInput; + + /** Specifies thread priority explicitly. Will be used only if paWinWasapiThreadPriority flag + is specified. + + Please note, if Input/Output streams are opened simultaniously (Full-Duplex mode) + you shall specify same value for threadPriority or othervise one of the values will be used + to setup thread priority. + */ + PaWasapiThreadPriority threadPriority; + + /** Stream category. + @see PaWasapiStreamCategory + @version Available as of 19.6.0 + */ + PaWasapiStreamCategory streamCategory; + + /** Stream option. + @see PaWasapiStreamOption + @version Available as of 19.6.0 + */ + PaWasapiStreamOption streamOption; +} +PaWasapiStreamInfo; + + +/** Returns default sound format for device. Format is represented by PaWinWaveFormat or + WAVEFORMATEXTENSIBLE structure. + + @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure. + @param nFormatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes. + @param nDevice Device index. + + @return Non-negative value indicating the number of bytes copied into format decriptor + or, a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. +*/ +int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, PaDeviceIndex nDevice ); + + +/** Returns device role (PaWasapiDeviceRole enum). + + @param nDevice device index. + + @return Non-negative value indicating device role or, a PaErrorCode (which are always negative) + if PortAudio is not initialized or an error is encountered. +*/ +int/*PaWasapiDeviceRole*/ PaWasapi_GetDeviceRole( PaDeviceIndex nDevice ); + + +/** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread + which makes calls to Pa_WriteStream/Pa_ReadStream. + + @param hTask Handle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority + method to revert thread priority to initial state. + + @param nPriorityClass Id of thread priority of PaWasapiThreadPriority type. Specifying + eThreadPriorityNone does nothing. + + @return Error code indicating success or failure. + @see PaWasapi_RevertThreadPriority +*/ +PaError PaWasapi_ThreadPriorityBoost( void **hTask, PaWasapiThreadPriority nPriorityClass ); + + +/** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread + which makes calls to Pa_WriteStream/Pa_ReadStream. + + @param hTask Task handle obtained by PaWasapi_BoostThreadPriority method. + @return Error code indicating success or failure. + @see PaWasapi_BoostThreadPriority +*/ +PaError PaWasapi_ThreadPriorityRevert( void *hTask ); + + +/** Get number of frames per host buffer. This is maximal value of frames of WASAPI buffer which + can be locked for operations. Use this method as helper to findout maximal values of + inputFrames/outputFrames of PaWasapiHostProcessorCallback. + + @param pStream Pointer to PaStream to query. + @param nInput Pointer to variable to receive number of input frames. Can be NULL. + @param nOutput Pointer to variable to receive number of output frames. Can be NULL. + @return Error code indicating success or failure. + @see PaWasapiHostProcessorCallback +*/ +PaError PaWasapi_GetFramesPerHostBuffer( PaStream *pStream, unsigned int *nInput, unsigned int *nOutput ); + + +/** Get number of jacks associated with a WASAPI device. Use this method to determine if + there are any jacks associated with the provided WASAPI device. Not all audio devices + will support this capability. This is valid for both input and output devices. + @param nDevice device index. + @param jcount Number of jacks is returned in this variable + @return Error code indicating success or failure + @see PaWasapi_GetJackDescription + */ +PaError PaWasapi_GetJackCount(PaDeviceIndex nDevice, int *jcount); + + +/** Get the jack description associated with a WASAPI device and jack number + Before this function is called, use PaWasapi_GetJackCount to determine the + number of jacks associated with device. If jcount is greater than zero, then + each jack from 0 to jcount can be queried with this function to get the jack + description. + @param nDevice device index. + @param jindex Which jack to return information + @param KSJACK_DESCRIPTION This structure filled in on success. + @return Error code indicating success or failure + @see PaWasapi_GetJackCount + */ +PaError PaWasapi_GetJackDescription(PaDeviceIndex nDevice, int jindex, PaWasapiJackDescription *pJackDescription); + + +/* + IMPORTANT: + + WASAPI is implemented for Callback and Blocking interfaces. It supports Shared and Exclusive + share modes. + + Exclusive Mode: + + Exclusive mode allows to deliver audio data directly to hardware bypassing + software mixing. + Exclusive mode is specified by 'paWinWasapiExclusive' flag. + + Callback Interface: + + Provides best audio quality with low latency. Callback interface is implemented in + two versions: + + 1) Event-Driven: + This is the most powerful WASAPI implementation which provides glitch-free + audio at around 3ms latency in Exclusive mode. Lowest possible latency for this mode is + 3 ms for HD Audio class audio chips. For the Shared mode latency can not be + lower than 20 ms. + + 2) Poll-Driven: + Polling is another 2-nd method to operate with WASAPI. It is less efficient than Event-Driven + and provides latency at around 10-13ms. Polling must be used to overcome a system bug + under Windows Vista x64 when application is WOW64(32-bit) and Event-Driven method simply + times out (event handle is never signalled on buffer completion). Please note, such WOW64 bug + does not exist in Vista x86 or Windows 7. + Polling can be setup by speciying 'paWinWasapiPolling' flag. Our WASAPI implementation detects + WOW64 bug and sets 'paWinWasapiPolling' automatically. + + Thread priority: + + Normally thread priority is set automatically and does not require modification. Although + if user wants some tweaking thread priority can be modified by setting 'paWinWasapiThreadPriority' + flag and specifying 'PaWasapiStreamInfo::threadPriority' with value from PaWasapiThreadPriority + enum. + + Blocking Interface: + + Blocking interface is implemented but due to above described Poll-Driven method can not + deliver lowest possible latency. Specifying too low latency in Shared mode will result in + distorted audio although Exclusive mode adds stability. + + Pa_IsFormatSupported: + + To check format with correct Share Mode (Exclusive/Shared) you must supply + PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of + PaStreamParameters::hostApiSpecificStreamInfo structure. + + Pa_OpenStream: + + To set desired Share Mode (Exclusive/Shared) you must supply + PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of + PaStreamParameters::hostApiSpecificStreamInfo structure. +*/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* PA_WIN_WASAPI_H */ diff --git a/portaudio/include/pa_win_waveformat.h b/portaudio/include/pa_win_waveformat.h new file mode 100644 index 0000000..2c00267 --- /dev/null +++ b/portaudio/include/pa_win_waveformat.h @@ -0,0 +1,199 @@ +#ifndef PA_WIN_WAVEFORMAT_H +#define PA_WIN_WAVEFORMAT_H + +/* + * PortAudio Portable Real-Time Audio Library + * Windows WAVEFORMAT* data structure utilities + * portaudio.h should be included before this file. + * + * Copyright (c) 2007 Ross Bencina + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + @ingroup public_header + @brief Windows specific PortAudio API extension and utilities header file. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + The following #defines for speaker channel masks are the same + as those in ksmedia.h, except with PAWIN_ prepended, KSAUDIO_ removed + in some cases, and casts to PaWinWaveFormatChannelMask added. +*/ + +typedef unsigned long PaWinWaveFormatChannelMask; + +/* Speaker Positions: */ +#define PAWIN_SPEAKER_FRONT_LEFT ((PaWinWaveFormatChannelMask)0x1) +#define PAWIN_SPEAKER_FRONT_RIGHT ((PaWinWaveFormatChannelMask)0x2) +#define PAWIN_SPEAKER_FRONT_CENTER ((PaWinWaveFormatChannelMask)0x4) +#define PAWIN_SPEAKER_LOW_FREQUENCY ((PaWinWaveFormatChannelMask)0x8) +#define PAWIN_SPEAKER_BACK_LEFT ((PaWinWaveFormatChannelMask)0x10) +#define PAWIN_SPEAKER_BACK_RIGHT ((PaWinWaveFormatChannelMask)0x20) +#define PAWIN_SPEAKER_FRONT_LEFT_OF_CENTER ((PaWinWaveFormatChannelMask)0x40) +#define PAWIN_SPEAKER_FRONT_RIGHT_OF_CENTER ((PaWinWaveFormatChannelMask)0x80) +#define PAWIN_SPEAKER_BACK_CENTER ((PaWinWaveFormatChannelMask)0x100) +#define PAWIN_SPEAKER_SIDE_LEFT ((PaWinWaveFormatChannelMask)0x200) +#define PAWIN_SPEAKER_SIDE_RIGHT ((PaWinWaveFormatChannelMask)0x400) +#define PAWIN_SPEAKER_TOP_CENTER ((PaWinWaveFormatChannelMask)0x800) +#define PAWIN_SPEAKER_TOP_FRONT_LEFT ((PaWinWaveFormatChannelMask)0x1000) +#define PAWIN_SPEAKER_TOP_FRONT_CENTER ((PaWinWaveFormatChannelMask)0x2000) +#define PAWIN_SPEAKER_TOP_FRONT_RIGHT ((PaWinWaveFormatChannelMask)0x4000) +#define PAWIN_SPEAKER_TOP_BACK_LEFT ((PaWinWaveFormatChannelMask)0x8000) +#define PAWIN_SPEAKER_TOP_BACK_CENTER ((PaWinWaveFormatChannelMask)0x10000) +#define PAWIN_SPEAKER_TOP_BACK_RIGHT ((PaWinWaveFormatChannelMask)0x20000) + +/* Bit mask locations reserved for future use */ +#define PAWIN_SPEAKER_RESERVED ((PaWinWaveFormatChannelMask)0x7FFC0000) + +/* Used to specify that any possible permutation of speaker configurations */ +#define PAWIN_SPEAKER_ALL ((PaWinWaveFormatChannelMask)0x80000000) + +/* DirectSound Speaker Config */ +#define PAWIN_SPEAKER_DIRECTOUT 0 +#define PAWIN_SPEAKER_MONO (PAWIN_SPEAKER_FRONT_CENTER) +#define PAWIN_SPEAKER_STEREO (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT) +#define PAWIN_SPEAKER_QUAD (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \ + PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT) +#define PAWIN_SPEAKER_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \ + PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_BACK_CENTER) +#define PAWIN_SPEAKER_5POINT1 (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \ + PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \ + PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT) +#define PAWIN_SPEAKER_7POINT1 (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \ + PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \ + PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT | \ + PAWIN_SPEAKER_FRONT_LEFT_OF_CENTER | PAWIN_SPEAKER_FRONT_RIGHT_OF_CENTER) +#define PAWIN_SPEAKER_5POINT1_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \ + PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \ + PAWIN_SPEAKER_SIDE_LEFT | PAWIN_SPEAKER_SIDE_RIGHT) +#define PAWIN_SPEAKER_7POINT1_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \ + PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \ + PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT | \ + PAWIN_SPEAKER_SIDE_LEFT | PAWIN_SPEAKER_SIDE_RIGHT) +/* + According to the Microsoft documentation: + The following are obsolete 5.1 and 7.1 settings (they lack side speakers). Note this means + that the default 5.1 and 7.1 settings (KSAUDIO_SPEAKER_5POINT1 and KSAUDIO_SPEAKER_7POINT1 are + similarly obsolete but are unchanged for compatibility reasons). +*/ +#define PAWIN_SPEAKER_5POINT1_BACK PAWIN_SPEAKER_5POINT1 +#define PAWIN_SPEAKER_7POINT1_WIDE PAWIN_SPEAKER_7POINT1 + +/* DVD Speaker Positions */ +#define PAWIN_SPEAKER_GROUND_FRONT_LEFT PAWIN_SPEAKER_FRONT_LEFT +#define PAWIN_SPEAKER_GROUND_FRONT_CENTER PAWIN_SPEAKER_FRONT_CENTER +#define PAWIN_SPEAKER_GROUND_FRONT_RIGHT PAWIN_SPEAKER_FRONT_RIGHT +#define PAWIN_SPEAKER_GROUND_REAR_LEFT PAWIN_SPEAKER_BACK_LEFT +#define PAWIN_SPEAKER_GROUND_REAR_RIGHT PAWIN_SPEAKER_BACK_RIGHT +#define PAWIN_SPEAKER_TOP_MIDDLE PAWIN_SPEAKER_TOP_CENTER +#define PAWIN_SPEAKER_SUPER_WOOFER PAWIN_SPEAKER_LOW_FREQUENCY + + +/* + PaWinWaveFormat is defined here to provide compatibility with + compilation environments which don't have headers defining + WAVEFORMATEXTENSIBLE (e.g. older versions of MSVC, Borland C++ etc. + + The fields for WAVEFORMATEX and WAVEFORMATEXTENSIBLE are declared as an + unsigned char array here to avoid clients who include this file having + a dependency on windows.h and mmsystem.h, and also to to avoid having + to write separate packing pragmas for each compiler. +*/ +#define PAWIN_SIZEOF_WAVEFORMATEX 18 +#define PAWIN_SIZEOF_WAVEFORMATEXTENSIBLE (PAWIN_SIZEOF_WAVEFORMATEX + 22) + +typedef struct{ + unsigned char fields[ PAWIN_SIZEOF_WAVEFORMATEXTENSIBLE ]; + unsigned long extraLongForAlignment; /* ensure that compiler aligns struct to DWORD */ +} PaWinWaveFormat; + +/* + WAVEFORMATEXTENSIBLE fields: + + union { + WORD wValidBitsPerSample; + WORD wSamplesPerBlock; + WORD wReserved; + } Samples; + DWORD dwChannelMask; + GUID SubFormat; +*/ + +#define PAWIN_INDEXOF_WVALIDBITSPERSAMPLE (PAWIN_SIZEOF_WAVEFORMATEX+0) +#define PAWIN_INDEXOF_DWCHANNELMASK (PAWIN_SIZEOF_WAVEFORMATEX+2) +#define PAWIN_INDEXOF_SUBFORMAT (PAWIN_SIZEOF_WAVEFORMATEX+6) + + +/* + Valid values to pass for the waveFormatTag PaWin_InitializeWaveFormatEx and + PaWin_InitializeWaveFormatExtensible functions below. These must match + the standard Windows WAVE_FORMAT_* values. +*/ +#define PAWIN_WAVE_FORMAT_PCM (1) +#define PAWIN_WAVE_FORMAT_IEEE_FLOAT (3) +#define PAWIN_WAVE_FORMAT_DOLBY_AC3_SPDIF (0x0092) +#define PAWIN_WAVE_FORMAT_WMA_SPDIF (0x0164) + + +/* + returns PAWIN_WAVE_FORMAT_PCM or PAWIN_WAVE_FORMAT_IEEE_FLOAT + depending on the sampleFormat parameter. +*/ +int PaWin_SampleFormatToLinearWaveFormatTag( PaSampleFormat sampleFormat ); + +/* + Use the following two functions to initialize the waveformat structure. +*/ + +void PaWin_InitializeWaveFormatEx( PaWinWaveFormat *waveFormat, + int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate ); + + +void PaWin_InitializeWaveFormatExtensible( PaWinWaveFormat *waveFormat, + int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate, + PaWinWaveFormatChannelMask channelMask ); + + +/* Map a channel count to a speaker channel mask */ +PaWinWaveFormatChannelMask PaWin_DefaultChannelMask( int numChannels ); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* PA_WIN_WAVEFORMAT_H */ \ No newline at end of file diff --git a/portaudio/include/pa_win_wdmks.h b/portaudio/include/pa_win_wdmks.h new file mode 100644 index 0000000..3592962 --- /dev/null +++ b/portaudio/include/pa_win_wdmks.h @@ -0,0 +1,137 @@ +#ifndef PA_WIN_WDMKS_H +#define PA_WIN_WDMKS_H +/* + * $Id$ + * PortAudio Portable Real-Time Audio Library + * WDM/KS specific extensions + * + * Copyright (c) 1999-2007 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + @ingroup public_header + @brief WDM Kernel Streaming-specific PortAudio API extension header file. +*/ + + +#include "portaudio.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + /** Flags to indicate valid fields in PaWinWDMKSInfo. + @see PaWinWDMKSInfo + @version Available as of 19.5.0. + */ + typedef enum PaWinWDMKSFlags + { + /** Makes WDMKS use the supplied latency figures instead of relying on the frame size reported + by the WaveCyclic device. Use at own risk! + */ + paWinWDMKSOverrideFramesize = (1 << 0), + + /** Makes WDMKS (output stream) use the given channelMask instead of the default. + @version Available as of 19.5.0. + */ + paWinWDMKSUseGivenChannelMask = (1 << 1), + + } PaWinWDMKSFlags; + + typedef struct PaWinWDMKSInfo{ + unsigned long size; /**< sizeof(PaWinWDMKSInfo) */ + PaHostApiTypeId hostApiType; /**< paWDMKS */ + unsigned long version; /**< 1 */ + + /** Flags indicate which fields are valid. + @see PaWinWDMKSFlags + @version Available as of 19.5.0. + */ + unsigned long flags; + + /** The number of packets to use for WaveCyclic devices, range is [2, 8]. Set to zero for default value of 2. */ + unsigned noOfPackets; + + /** If paWinWDMKSUseGivenChannelMask bit is set in flags, use this as channelMask instead of default. + @see PaWinWDMKSFlags + @version Available as of 19.5.0. + */ + unsigned channelMask; + } PaWinWDMKSInfo; + + typedef enum PaWDMKSType + { + Type_kNotUsed, + Type_kWaveCyclic, + Type_kWaveRT, + Type_kCnt, + } PaWDMKSType; + + typedef enum PaWDMKSSubType + { + SubType_kUnknown, + SubType_kNotification, + SubType_kPolled, + SubType_kCnt, + } PaWDMKSSubType; + + typedef struct PaWinWDMKSDeviceInfo { + wchar_t filterPath[MAX_PATH]; /**< KS filter path in Unicode! */ + wchar_t topologyPath[MAX_PATH]; /**< Topology filter path in Unicode! */ + PaWDMKSType streamingType; + GUID deviceProductGuid; /**< The product GUID of the device (if supported) */ + } PaWinWDMKSDeviceInfo; + + typedef struct PaWDMKSDirectionSpecificStreamInfo + { + PaDeviceIndex device; + unsigned channels; /**< No of channels the device is opened with */ + unsigned framesPerHostBuffer; /**< No of frames of the device buffer */ + int endpointPinId; /**< Endpoint pin ID (on topology filter if topologyName is not empty) */ + int muxNodeId; /**< Only valid for input */ + PaWDMKSSubType streamingSubType; /**< Not known until device is opened for streaming */ + } PaWDMKSDirectionSpecificStreamInfo; + + typedef struct PaWDMKSSpecificStreamInfo { + PaWDMKSDirectionSpecificStreamInfo input; + PaWDMKSDirectionSpecificStreamInfo output; + } PaWDMKSSpecificStreamInfo; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* PA_WIN_DS_H */ diff --git a/portaudio/include/pa_win_wmme.h b/portaudio/include/pa_win_wmme.h new file mode 100644 index 0000000..f84b68b --- /dev/null +++ b/portaudio/include/pa_win_wmme.h @@ -0,0 +1,185 @@ +#ifndef PA_WIN_WMME_H +#define PA_WIN_WMME_H +/* + * $Id$ + * PortAudio Portable Real-Time Audio Library + * MME specific extensions + * + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + @ingroup public_header + @brief WMME-specific PortAudio API extension header file. +*/ + +#include "portaudio.h" +#include "pa_win_waveformat.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + +/* The following are flags which can be set in + PaWinMmeStreamInfo's flags field. +*/ + +#define paWinMmeUseLowLevelLatencyParameters (0x01) +#define paWinMmeUseMultipleDevices (0x02) /* use mme specific multiple device feature */ +#define paWinMmeUseChannelMask (0x04) + +/* By default, the mme implementation drops the processing thread's priority + to THREAD_PRIORITY_NORMAL and sleeps the thread if the CPU load exceeds 100% + This flag disables any priority throttling. The processing thread will always + run at THREAD_PRIORITY_TIME_CRITICAL. +*/ +#define paWinMmeDontThrottleOverloadedProcessingThread (0x08) + +/* Flags for non-PCM spdif passthrough. +*/ +#define paWinMmeWaveFormatDolbyAc3Spdif (0x10) +#define paWinMmeWaveFormatWmaSpdif (0x20) + + +typedef struct PaWinMmeDeviceAndChannelCount{ + PaDeviceIndex device; + int channelCount; +}PaWinMmeDeviceAndChannelCount; + + +typedef struct PaWinMmeStreamInfo{ + unsigned long size; /**< sizeof(PaWinMmeStreamInfo) */ + PaHostApiTypeId hostApiType; /**< paMME */ + unsigned long version; /**< 1 */ + + unsigned long flags; + + /* low-level latency setting support + These settings control the number and size of host buffers in order + to set latency. They will be used instead of the generic parameters + to Pa_OpenStream() if flags contains the PaWinMmeUseLowLevelLatencyParameters + flag. + + If PaWinMmeStreamInfo structures with PaWinMmeUseLowLevelLatencyParameters + are supplied for both input and output in a full duplex stream, then the + input and output framesPerBuffer must be the same, or the larger of the + two must be a multiple of the smaller, otherwise a + paIncompatibleHostApiSpecificStreamInfo error will be returned from + Pa_OpenStream(). + */ + unsigned long framesPerBuffer; + unsigned long bufferCount; /* formerly numBuffers */ + + /* multiple devices per direction support + If flags contains the PaWinMmeUseMultipleDevices flag, + this functionality will be used, otherwise the device parameter to + Pa_OpenStream() will be used instead. + If devices are specified here, the corresponding device parameter + to Pa_OpenStream() should be set to paUseHostApiSpecificDeviceSpecification, + otherwise an paInvalidDevice error will result. + The total number of channels accross all specified devices + must agree with the corresponding channelCount parameter to + Pa_OpenStream() otherwise a paInvalidChannelCount error will result. + */ + PaWinMmeDeviceAndChannelCount *devices; + unsigned long deviceCount; + + /* + support for WAVEFORMATEXTENSIBLE channel masks. If flags contains + paWinMmeUseChannelMask this allows you to specify which speakers + to address in a multichannel stream. Constants for channelMask + are specified in pa_win_waveformat.h + + */ + PaWinWaveFormatChannelMask channelMask; + +}PaWinMmeStreamInfo; + + +/** Retrieve the number of wave in handles used by a PortAudio WinMME stream. + Returns zero if the stream is output only. + + @return A non-negative value indicating the number of wave in handles + or, a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + @see PaWinMME_GetStreamInputHandle +*/ +int PaWinMME_GetStreamInputHandleCount( PaStream* stream ); + + +/** Retrieve a wave in handle used by a PortAudio WinMME stream. + + @param stream The stream to query. + @param handleIndex The zero based index of the wave in handle to retrieve. This + should be in the range [0, PaWinMME_GetStreamInputHandleCount(stream)-1]. + + @return A valid wave in handle, or NULL if an error occurred. + + @see PaWinMME_GetStreamInputHandle +*/ +HWAVEIN PaWinMME_GetStreamInputHandle( PaStream* stream, int handleIndex ); + + +/** Retrieve the number of wave out handles used by a PortAudio WinMME stream. + Returns zero if the stream is input only. + + @return A non-negative value indicating the number of wave out handles + or, a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + @see PaWinMME_GetStreamOutputHandle +*/ +int PaWinMME_GetStreamOutputHandleCount( PaStream* stream ); + + +/** Retrieve a wave out handle used by a PortAudio WinMME stream. + + @param stream The stream to query. + @param handleIndex The zero based index of the wave out handle to retrieve. + This should be in the range [0, PaWinMME_GetStreamOutputHandleCount(stream)-1]. + + @return A valid wave out handle, or NULL if an error occurred. + + @see PaWinMME_GetStreamOutputHandleCount +*/ +HWAVEOUT PaWinMME_GetStreamOutputHandle( PaStream* stream, int handleIndex ); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* PA_WIN_WMME_H */ diff --git a/portaudio/include/portaudio.h b/portaudio/include/portaudio.h new file mode 100644 index 0000000..8a94aaf --- /dev/null +++ b/portaudio/include/portaudio.h @@ -0,0 +1,1225 @@ +#ifndef PORTAUDIO_H +#define PORTAUDIO_H +/* + * $Id$ + * PortAudio Portable Real-Time Audio Library + * PortAudio API Header File + * Latest version available at: http://www.portaudio.com/ + * + * Copyright (c) 1999-2002 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The text above constitutes the entire PortAudio license; however, + * the PortAudio community also makes the following non-binding requests: + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the + * license above. + */ + +/** @file + @ingroup public_header + @brief The portable PortAudio API. +*/ + + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** Retrieve the release number of the currently running PortAudio build. + For example, for version "19.5.1" this will return 0x00130501. + + @see paMakeVersionNumber +*/ +int Pa_GetVersion( void ); + +/** Retrieve a textual description of the current PortAudio build, + e.g. "PortAudio V19.5.0-devel, revision 1952M". + The format of the text may change in the future. Do not try to parse the + returned string. + + @deprecated As of 19.5.0, use Pa_GetVersionInfo()->versionText instead. +*/ +const char* Pa_GetVersionText( void ); + +/** + Generate a packed integer version number in the same format used + by Pa_GetVersion(). Use this to compare a specified version number with + the currently running version. For example: + + @code + if( Pa_GetVersion() < paMakeVersionNumber(19,5,1) ) {} + @endcode + + @see Pa_GetVersion, Pa_GetVersionInfo + @version Available as of 19.5.0. +*/ +#define paMakeVersionNumber(major, minor, subminor) \ + (((major)&0xFF)<<16 | ((minor)&0xFF)<<8 | ((subminor)&0xFF)) + + +/** + A structure containing PortAudio API version information. + @see Pa_GetVersionInfo, paMakeVersionNumber + @version Available as of 19.5.0. +*/ +typedef struct PaVersionInfo { + int versionMajor; + int versionMinor; + int versionSubMinor; + /** + This is currently the Git revision hash but may change in the future. + The versionControlRevision is updated by running a script before compiling the library. + If the update does not occur, this value may refer to an earlier revision. + */ + const char *versionControlRevision; + /** Version as a string, for example "PortAudio V19.5.0-devel, revision 1952M" */ + const char *versionText; +} PaVersionInfo; + +/** Retrieve version information for the currently running PortAudio build. + @return A pointer to an immutable PaVersionInfo structure. + + @note This function can be called at any time. It does not require PortAudio + to be initialized. The structure pointed to is statically allocated. Do not + attempt to free it or modify it. + + @see PaVersionInfo, paMakeVersionNumber + @version Available as of 19.5.0. +*/ +const PaVersionInfo* Pa_GetVersionInfo(); + + +/** Error codes returned by PortAudio functions. + Note that with the exception of paNoError, all PaErrorCodes are negative. +*/ + +typedef int PaError; +typedef enum PaErrorCode +{ + paNoError = 0, + + paNotInitialized = -10000, + paUnanticipatedHostError, + paInvalidChannelCount, + paInvalidSampleRate, + paInvalidDevice, + paInvalidFlag, + paSampleFormatNotSupported, + paBadIODeviceCombination, + paInsufficientMemory, + paBufferTooBig, + paBufferTooSmall, + paNullCallback, + paBadStreamPtr, + paTimedOut, + paInternalError, + paDeviceUnavailable, + paIncompatibleHostApiSpecificStreamInfo, + paStreamIsStopped, + paStreamIsNotStopped, + paInputOverflowed, + paOutputUnderflowed, + paHostApiNotFound, + paInvalidHostApi, + paCanNotReadFromACallbackStream, + paCanNotWriteToACallbackStream, + paCanNotReadFromAnOutputOnlyStream, + paCanNotWriteToAnInputOnlyStream, + paIncompatibleStreamHostApi, + paBadBufferPtr +} PaErrorCode; + + +/** Translate the supplied PortAudio error code into a human readable + message. +*/ +const char *Pa_GetErrorText( PaError errorCode ); + + +/** Library initialization function - call this before using PortAudio. + This function initializes internal data structures and prepares underlying + host APIs for use. With the exception of Pa_GetVersion(), Pa_GetVersionText(), + and Pa_GetErrorText(), this function MUST be called before using any other + PortAudio API functions. + + If Pa_Initialize() is called multiple times, each successful + call must be matched with a corresponding call to Pa_Terminate(). + Pairs of calls to Pa_Initialize()/Pa_Terminate() may overlap, and are not + required to be fully nested. + + Note that if Pa_Initialize() returns an error code, Pa_Terminate() should + NOT be called. + + @return paNoError if successful, otherwise an error code indicating the cause + of failure. + + @see Pa_Terminate +*/ +PaError Pa_Initialize( void ); + + +/** Library termination function - call this when finished using PortAudio. + This function deallocates all resources allocated by PortAudio since it was + initialized by a call to Pa_Initialize(). In cases where Pa_Initialise() has + been called multiple times, each call must be matched with a corresponding call + to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically + close any PortAudio streams that are still open. + + Pa_Terminate() MUST be called before exiting a program which uses PortAudio. + Failure to do so may result in serious resource leaks, such as audio devices + not being available until the next reboot. + + @return paNoError if successful, otherwise an error code indicating the cause + of failure. + + @see Pa_Initialize +*/ +PaError Pa_Terminate( void ); + + + +/** The type used to refer to audio devices. Values of this type usually + range from 0 to (Pa_GetDeviceCount()-1), and may also take on the PaNoDevice + and paUseHostApiSpecificDeviceSpecification values. + + @see Pa_GetDeviceCount, paNoDevice, paUseHostApiSpecificDeviceSpecification +*/ +typedef int PaDeviceIndex; + + +/** A special PaDeviceIndex value indicating that no device is available, + or should be used. + + @see PaDeviceIndex +*/ +#define paNoDevice ((PaDeviceIndex)-1) + + +/** A special PaDeviceIndex value indicating that the device(s) to be used + are specified in the host api specific stream info structure. + + @see PaDeviceIndex +*/ +#define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2) + + +/* Host API enumeration mechanism */ + +/** The type used to enumerate to host APIs at runtime. Values of this type + range from 0 to (Pa_GetHostApiCount()-1). + + @see Pa_GetHostApiCount +*/ +typedef int PaHostApiIndex; + + +/** Retrieve the number of available host APIs. Even if a host API is + available it may have no devices available. + + @return A non-negative value indicating the number of available host APIs + or, a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + @see PaHostApiIndex +*/ +PaHostApiIndex Pa_GetHostApiCount( void ); + + +/** Retrieve the index of the default host API. The default host API will be + the lowest common denominator host API on the current platform and is + unlikely to provide the best performance. + + @return A non-negative value ranging from 0 to (Pa_GetHostApiCount()-1) + indicating the default host API index or, a PaErrorCode (which are always + negative) if PortAudio is not initialized or an error is encountered. +*/ +PaHostApiIndex Pa_GetDefaultHostApi( void ); + + +/** Unchanging unique identifiers for each supported host API. This type + is used in the PaHostApiInfo structure. The values are guaranteed to be + unique and to never change, thus allowing code to be written that + conditionally uses host API specific extensions. + + New type ids will be allocated when support for a host API reaches + "public alpha" status, prior to that developers should use the + paInDevelopment type id. + + @see PaHostApiInfo +*/ +typedef enum PaHostApiTypeId +{ + paInDevelopment=0, /* use while developing support for a new host API */ + paDirectSound=1, + paMME=2, + paASIO=3, + paSoundManager=4, + paCoreAudio=5, + paOSS=7, + paALSA=8, + paAL=9, + paBeOS=10, + paWDMKS=11, + paJACK=12, + paWASAPI=13, + paAudioScienceHPI=14 +} PaHostApiTypeId; + + +/** A structure containing information about a particular host API. */ + +typedef struct PaHostApiInfo +{ + /** this is struct version 1 */ + int structVersion; + /** The well known unique identifier of this host API @see PaHostApiTypeId */ + PaHostApiTypeId type; + /** A textual description of the host API for display on user interfaces. */ + const char *name; + + /** The number of devices belonging to this host API. This field may be + used in conjunction with Pa_HostApiDeviceIndexToDeviceIndex() to enumerate + all devices for this host API. + @see Pa_HostApiDeviceIndexToDeviceIndex + */ + int deviceCount; + + /** The default input device for this host API. The value will be a + device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice + if no default input device is available. + */ + PaDeviceIndex defaultInputDevice; + + /** The default output device for this host API. The value will be a + device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice + if no default output device is available. + */ + PaDeviceIndex defaultOutputDevice; + +} PaHostApiInfo; + + +/** Retrieve a pointer to a structure containing information about a specific + host Api. + + @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) + + @return A pointer to an immutable PaHostApiInfo structure describing + a specific host API. If the hostApi parameter is out of range or an error + is encountered, the function returns NULL. + + The returned structure is owned by the PortAudio implementation and must not + be manipulated or freed. The pointer is only guaranteed to be valid between + calls to Pa_Initialize() and Pa_Terminate(). +*/ +const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi ); + + +/** Convert a static host API unique identifier, into a runtime + host API index. + + @param type A unique host API identifier belonging to the PaHostApiTypeId + enumeration. + + @return A valid PaHostApiIndex ranging from 0 to (Pa_GetHostApiCount()-1) or, + a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + The paHostApiNotFound error code indicates that the host API specified by the + type parameter is not available. + + @see PaHostApiTypeId +*/ +PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type ); + + +/** Convert a host-API-specific device index to standard PortAudio device index. + This function may be used in conjunction with the deviceCount field of + PaHostApiInfo to enumerate all devices for the specified host API. + + @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) + + @param hostApiDeviceIndex A valid per-host device index in the range + 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1) + + @return A non-negative PaDeviceIndex ranging from 0 to (Pa_GetDeviceCount()-1) + or, a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. + + A paInvalidHostApi error code indicates that the host API index specified by + the hostApi parameter is out of range. + + A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter + is out of range. + + @see PaHostApiInfo +*/ +PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, + int hostApiDeviceIndex ); + + + +/** Structure used to return information about a host error condition. +*/ +typedef struct PaHostErrorInfo{ + PaHostApiTypeId hostApiType; /**< the host API which returned the error code */ + long errorCode; /**< the error code returned */ + const char *errorText; /**< a textual description of the error if available, otherwise a zero-length string */ +}PaHostErrorInfo; + + +/** Return information about the last host error encountered. The error + information returned by Pa_GetLastHostErrorInfo() will never be modified + asynchronously by errors occurring in other PortAudio owned threads + (such as the thread that manages the stream callback.) + + This function is provided as a last resort, primarily to enhance debugging + by providing clients with access to all available error information. + + @return A pointer to an immutable structure constraining information about + the host error. The values in this structure will only be valid if a + PortAudio function has previously returned the paUnanticipatedHostError + error code. +*/ +const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void ); + + + +/* Device enumeration and capabilities */ + +/** Retrieve the number of available devices. The number of available devices + may be zero. + + @return A non-negative value indicating the number of available devices or, + a PaErrorCode (which are always negative) if PortAudio is not initialized + or an error is encountered. +*/ +PaDeviceIndex Pa_GetDeviceCount( void ); + + +/** Retrieve the index of the default input device. The result can be + used in the inputDevice parameter to Pa_OpenStream(). + + @return The default input device index for the default host API, or paNoDevice + if no default input device is available or an error was encountered. +*/ +PaDeviceIndex Pa_GetDefaultInputDevice( void ); + + +/** Retrieve the index of the default output device. The result can be + used in the outputDevice parameter to Pa_OpenStream(). + + @return The default output device index for the default host API, or paNoDevice + if no default output device is available or an error was encountered. + + @note + On the PC, the user can specify a default device by + setting an environment variable. For example, to use device #1. +
+ set PA_RECOMMENDED_OUTPUT_DEVICE=1
+
+ The user should first determine the available device ids by using + the supplied application "pa_devs". +*/ +PaDeviceIndex Pa_GetDefaultOutputDevice( void ); + + +/** The type used to represent monotonic time in seconds. PaTime is + used for the fields of the PaStreamCallbackTimeInfo argument to the + PaStreamCallback and as the result of Pa_GetStreamTime(). + + PaTime values have unspecified origin. + + @see PaStreamCallback, PaStreamCallbackTimeInfo, Pa_GetStreamTime +*/ +typedef double PaTime; + + +/** A type used to specify one or more sample formats. Each value indicates + a possible format for sound data passed to and from the stream callback, + Pa_ReadStream and Pa_WriteStream. + + The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8 + and aUInt8 are usually implemented by all implementations. + + The floating point representation (paFloat32) uses +1.0 and -1.0 as the + maximum and minimum respectively. + + paUInt8 is an unsigned 8 bit format where 128 is considered "ground" + + The paNonInterleaved flag indicates that audio data is passed as an array + of pointers to separate buffers, one buffer for each channel. Usually, + when this flag is not used, audio data is passed as a single buffer with + all channels interleaved. + + @see Pa_OpenStream, Pa_OpenDefaultStream, PaDeviceInfo + @see paFloat32, paInt16, paInt32, paInt24, paInt8 + @see paUInt8, paCustomFormat, paNonInterleaved +*/ +typedef unsigned long PaSampleFormat; + + +#define paFloat32 ((PaSampleFormat) 0x00000001) /**< @see PaSampleFormat */ +#define paInt32 ((PaSampleFormat) 0x00000002) /**< @see PaSampleFormat */ +#define paInt24 ((PaSampleFormat) 0x00000004) /**< Packed 24 bit format. @see PaSampleFormat */ +#define paInt16 ((PaSampleFormat) 0x00000008) /**< @see PaSampleFormat */ +#define paInt8 ((PaSampleFormat) 0x00000010) /**< @see PaSampleFormat */ +#define paUInt8 ((PaSampleFormat) 0x00000020) /**< @see PaSampleFormat */ +#define paCustomFormat ((PaSampleFormat) 0x00010000) /**< @see PaSampleFormat */ + +#define paNonInterleaved ((PaSampleFormat) 0x80000000) /**< @see PaSampleFormat */ + +/** A structure providing information and capabilities of PortAudio devices. + Devices may support input, output or both input and output. +*/ +typedef struct PaDeviceInfo +{ + int structVersion; /* this is struct version 2 */ + const char *name; + PaHostApiIndex hostApi; /**< note this is a host API index, not a type id*/ + + int maxInputChannels; + int maxOutputChannels; + + /** Default latency values for interactive performance. */ + PaTime defaultLowInputLatency; + PaTime defaultLowOutputLatency; + /** Default latency values for robust non-interactive applications (eg. playing sound files). */ + PaTime defaultHighInputLatency; + PaTime defaultHighOutputLatency; + + double defaultSampleRate; +} PaDeviceInfo; + + +/** Retrieve a pointer to a PaDeviceInfo structure containing information + about the specified device. + @return A pointer to an immutable PaDeviceInfo structure. If the device + parameter is out of range the function returns NULL. + + @param device A valid device index in the range 0 to (Pa_GetDeviceCount()-1) + + @note PortAudio manages the memory referenced by the returned pointer, + the client must not manipulate or free the memory. The pointer is only + guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate(). + + @see PaDeviceInfo, PaDeviceIndex +*/ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device ); + + +/** Parameters for one direction (input or output) of a stream. +*/ +typedef struct PaStreamParameters +{ + /** A valid device index in the range 0 to (Pa_GetDeviceCount()-1) + specifying the device to be used or the special constant + paUseHostApiSpecificDeviceSpecification which indicates that the actual + device(s) to use are specified in hostApiSpecificStreamInfo. + This field must not be set to paNoDevice. + */ + PaDeviceIndex device; + + /** The number of channels of sound to be delivered to the + stream callback or accessed by Pa_ReadStream() or Pa_WriteStream(). + It can range from 1 to the value of maxInputChannels in the + PaDeviceInfo record for the device specified by the device parameter. + */ + int channelCount; + + /** The sample format of the buffer provided to the stream callback, + a_ReadStream() or Pa_WriteStream(). It may be any of the formats described + by the PaSampleFormat enumeration. + */ + PaSampleFormat sampleFormat; + + /** The desired latency in seconds. Where practical, implementations should + configure their latency based on these parameters, otherwise they may + choose the closest viable latency instead. Unless the suggested latency + is greater than the absolute upper limit for the device implementations + should round the suggestedLatency up to the next practical value - ie to + provide an equal or higher latency than suggestedLatency wherever possible. + Actual latency values for an open stream may be retrieved using the + inputLatency and outputLatency fields of the PaStreamInfo structure + returned by Pa_GetStreamInfo(). + @see default*Latency in PaDeviceInfo, *Latency in PaStreamInfo + */ + PaTime suggestedLatency; + + /** An optional pointer to a host api specific data structure + containing additional information for device setup and/or stream processing. + hostApiSpecificStreamInfo is never required for correct operation, + if not used it should be set to NULL. + */ + void *hostApiSpecificStreamInfo; + +} PaStreamParameters; + + +/** Return code for Pa_IsFormatSupported indicating success. */ +#define paFormatIsSupported (0) + +/** Determine whether it would be possible to open a stream with the specified + parameters. + + @param inputParameters A structure that describes the input parameters used to + open a stream. The suggestedLatency field is ignored. See PaStreamParameters + for a description of these parameters. inputParameters must be NULL for + output-only streams. + + @param outputParameters A structure that describes the output parameters used + to open a stream. The suggestedLatency field is ignored. See PaStreamParameters + for a description of these parameters. outputParameters must be NULL for + input-only streams. + + @param sampleRate The required sampleRate. For full-duplex streams it is the + sample rate for both input and output + + @return Returns 0 if the format is supported, and an error code indicating why + the format is not supported otherwise. The constant paFormatIsSupported is + provided to compare with the return value for success. + + @see paFormatIsSupported, PaStreamParameters +*/ +PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, + const PaStreamParameters *outputParameters, + double sampleRate ); + + + +/* Streaming types and functions */ + + +/** + A single PaStream can provide multiple channels of real-time + streaming audio input and output to a client application. A stream + provides access to audio hardware represented by one or more + PaDevices. Depending on the underlying Host API, it may be possible + to open multiple streams using the same device, however this behavior + is implementation defined. Portable applications should assume that + a PaDevice may be simultaneously used by at most one PaStream. + + Pointers to PaStream objects are passed between PortAudio functions that + operate on streams. + + @see Pa_OpenStream, Pa_OpenDefaultStream, Pa_OpenDefaultStream, Pa_CloseStream, + Pa_StartStream, Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive, + Pa_GetStreamTime, Pa_GetStreamCpuLoad + +*/ +typedef void PaStream; + + +/** Can be passed as the framesPerBuffer parameter to Pa_OpenStream() + or Pa_OpenDefaultStream() to indicate that the stream callback will + accept buffers of any size. +*/ +#define paFramesPerBufferUnspecified (0) + + +/** Flags used to control the behavior of a stream. They are passed as + parameters to Pa_OpenStream or Pa_OpenDefaultStream. Multiple flags may be + ORed together. + + @see Pa_OpenStream, Pa_OpenDefaultStream + @see paNoFlag, paClipOff, paDitherOff, paNeverDropInput, + paPrimeOutputBuffersUsingStreamCallback, paPlatformSpecificFlags +*/ +typedef unsigned long PaStreamFlags; + +/** @see PaStreamFlags */ +#define paNoFlag ((PaStreamFlags) 0) + +/** Disable default clipping of out of range samples. + @see PaStreamFlags +*/ +#define paClipOff ((PaStreamFlags) 0x00000001) + +/** Disable default dithering. + @see PaStreamFlags +*/ +#define paDitherOff ((PaStreamFlags) 0x00000002) + +/** Flag requests that where possible a full duplex stream will not discard + overflowed input samples without calling the stream callback. This flag is + only valid for full duplex callback streams and only when used in combination + with the paFramesPerBufferUnspecified (0) framesPerBuffer parameter. Using + this flag incorrectly results in a paInvalidFlag error being returned from + Pa_OpenStream and Pa_OpenDefaultStream. + + @see PaStreamFlags, paFramesPerBufferUnspecified +*/ +#define paNeverDropInput ((PaStreamFlags) 0x00000004) + +/** Call the stream callback to fill initial output buffers, rather than the + default behavior of priming the buffers with zeros (silence). This flag has + no effect for input-only and blocking read/write streams. + + @see PaStreamFlags +*/ +#define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008) + +/** A mask specifying the platform specific bits. + @see PaStreamFlags +*/ +#define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000) + +/** + Timing information for the buffers passed to the stream callback. + + Time values are expressed in seconds and are synchronised with the time base used by Pa_GetStreamTime() for the associated stream. + + @see PaStreamCallback, Pa_GetStreamTime +*/ +typedef struct PaStreamCallbackTimeInfo{ + PaTime inputBufferAdcTime; /**< The time when the first sample of the input buffer was captured at the ADC input */ + PaTime currentTime; /**< The time when the stream callback was invoked */ + PaTime outputBufferDacTime; /**< The time when the first sample of the output buffer will output the DAC */ +} PaStreamCallbackTimeInfo; + + +/** + Flag bit constants for the statusFlags to PaStreamCallback. + + @see paInputUnderflow, paInputOverflow, paOutputUnderflow, paOutputOverflow, + paPrimingOutput +*/ +typedef unsigned long PaStreamCallbackFlags; + +/** In a stream opened with paFramesPerBufferUnspecified, indicates that + input data is all silence (zeros) because no real data is available. In a + stream opened without paFramesPerBufferUnspecified, it indicates that one or + more zero samples have been inserted into the input buffer to compensate + for an input underflow. + @see PaStreamCallbackFlags +*/ +#define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001) + +/** In a stream opened with paFramesPerBufferUnspecified, indicates that data + prior to the first sample of the input buffer was discarded due to an + overflow, possibly because the stream callback is using too much CPU time. + Otherwise indicates that data prior to one or more samples in the + input buffer was discarded. + @see PaStreamCallbackFlags +*/ +#define paInputOverflow ((PaStreamCallbackFlags) 0x00000002) + +/** Indicates that output data (or a gap) was inserted, possibly because the + stream callback is using too much CPU time. + @see PaStreamCallbackFlags +*/ +#define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004) + +/** Indicates that output data will be discarded because no room is available. + @see PaStreamCallbackFlags +*/ +#define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008) + +/** Some of all of the output data will be used to prime the stream, input + data may be zero. + @see PaStreamCallbackFlags +*/ +#define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010) + +/** + Allowable return values for the PaStreamCallback. + @see PaStreamCallback +*/ +typedef enum PaStreamCallbackResult +{ + paContinue=0, /**< Signal that the stream should continue invoking the callback and processing audio. */ + paComplete=1, /**< Signal that the stream should stop invoking the callback and finish once all output samples have played. */ + paAbort=2 /**< Signal that the stream should stop invoking the callback and finish as soon as possible. */ +} PaStreamCallbackResult; + + +/** + Functions of type PaStreamCallback are implemented by PortAudio clients. + They consume, process or generate audio in response to requests from an + active PortAudio stream. + + When a stream is running, PortAudio calls the stream callback periodically. + The callback function is responsible for processing buffers of audio samples + passed via the input and output parameters. + + The PortAudio stream callback runs at very high or real-time priority. + It is required to consistently meet its time deadlines. Do not allocate + memory, access the file system, call library functions or call other functions + from the stream callback that may block or take an unpredictable amount of + time to complete. + + In order for a stream to maintain glitch-free operation the callback + must consume and return audio data faster than it is recorded and/or + played. PortAudio anticipates that each callback invocation may execute for + a duration approaching the duration of frameCount audio frames at the stream + sample rate. It is reasonable to expect to be able to utilise 70% or more of + the available CPU time in the PortAudio callback. However, due to buffer size + adaption and other factors, not all host APIs are able to guarantee audio + stability under heavy CPU load with arbitrary fixed callback buffer sizes. + When high callback CPU utilisation is required the most robust behavior + can be achieved by using paFramesPerBufferUnspecified as the + Pa_OpenStream() framesPerBuffer parameter. + + @param input and @param output are either arrays of interleaved samples or; + if non-interleaved samples were requested using the paNonInterleaved sample + format flag, an array of buffer pointers, one non-interleaved buffer for + each channel. + + The format, packing and number of channels used by the buffers are + determined by parameters to Pa_OpenStream(). + + @param frameCount The number of sample frames to be processed by + the stream callback. + + @param timeInfo Timestamps indicating the ADC capture time of the first sample + in the input buffer, the DAC output time of the first sample in the output buffer + and the time the callback was invoked. + See PaStreamCallbackTimeInfo and Pa_GetStreamTime() + + @param statusFlags Flags indicating whether input and/or output buffers + have been inserted or will be dropped to overcome underflow or overflow + conditions. + + @param userData The value of a user supplied pointer passed to + Pa_OpenStream() intended for storing synthesis data etc. + + @return + The stream callback should return one of the values in the + ::PaStreamCallbackResult enumeration. To ensure that the callback continues + to be called, it should return paContinue (0). Either paComplete or paAbort + can be returned to finish stream processing, after either of these values is + returned the callback will not be called again. If paAbort is returned the + stream will finish as soon as possible. If paComplete is returned, the stream + will continue until all buffers generated by the callback have been played. + This may be useful in applications such as soundfile players where a specific + duration of output is required. However, it is not necessary to utilize this + mechanism as Pa_StopStream(), Pa_AbortStream() or Pa_CloseStream() can also + be used to stop the stream. The callback must always fill the entire output + buffer irrespective of its return value. + + @see Pa_OpenStream, Pa_OpenDefaultStream + + @note With the exception of Pa_GetStreamCpuLoad() it is not permissible to call + PortAudio API functions from within the stream callback. +*/ +typedef int PaStreamCallback( + const void *input, void *output, + unsigned long frameCount, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ); + + +/** Opens a stream for either input, output or both. + + @param stream The address of a PaStream pointer which will receive + a pointer to the newly opened stream. + + @param inputParameters A structure that describes the input parameters used by + the opened stream. See PaStreamParameters for a description of these parameters. + inputParameters must be NULL for output-only streams. + + @param outputParameters A structure that describes the output parameters used by + the opened stream. See PaStreamParameters for a description of these parameters. + outputParameters must be NULL for input-only streams. + + @param sampleRate The desired sampleRate. For full-duplex streams it is the + sample rate for both input and output + + @param framesPerBuffer The number of frames passed to the stream callback + function, or the preferred block granularity for a blocking read/write stream. + The special value paFramesPerBufferUnspecified (0) may be used to request that + the stream callback will receive an optimal (and possibly varying) number of + frames based on host requirements and the requested latency settings. + Note: With some host APIs, the use of non-zero framesPerBuffer for a callback + stream may introduce an additional layer of buffering which could introduce + additional latency. PortAudio guarantees that the additional latency + will be kept to the theoretical minimum however, it is strongly recommended + that a non-zero framesPerBuffer value only be used when your algorithm + requires a fixed number of frames per stream callback. + + @param streamFlags Flags which modify the behavior of the streaming process. + This parameter may contain a combination of flags ORed together. Some flags may + only be relevant to certain buffer formats. + + @param streamCallback A pointer to a client supplied function that is responsible + for processing and filling input and output buffers. If this parameter is NULL + the stream will be opened in 'blocking read/write' mode. In blocking mode, + the client can receive sample data using Pa_ReadStream and write sample data + using Pa_WriteStream, the number of samples that may be read or written + without blocking is returned by Pa_GetStreamReadAvailable and + Pa_GetStreamWriteAvailable respectively. + + @param userData A client supplied pointer which is passed to the stream callback + function. It could for example, contain a pointer to instance data necessary + for processing the audio buffers. This parameter is ignored if streamCallback + is NULL. + + @return + Upon success Pa_OpenStream() returns paNoError and places a pointer to a + valid PaStream in the stream argument. The stream is inactive (stopped). + If a call to Pa_OpenStream() fails, a non-zero error code is returned (see + PaError for possible error codes) and the value of stream is invalid. + + @see PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream, + Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable +*/ +PaError Pa_OpenStream( PaStream** stream, + const PaStreamParameters *inputParameters, + const PaStreamParameters *outputParameters, + double sampleRate, + unsigned long framesPerBuffer, + PaStreamFlags streamFlags, + PaStreamCallback *streamCallback, + void *userData ); + + +/** A simplified version of Pa_OpenStream() that opens the default input + and/or output devices. + + @param stream The address of a PaStream pointer which will receive + a pointer to the newly opened stream. + + @param numInputChannels The number of channels of sound that will be supplied + to the stream callback or returned by Pa_ReadStream. It can range from 1 to + the value of maxInputChannels in the PaDeviceInfo record for the default input + device. If 0 the stream is opened as an output-only stream. + + @param numOutputChannels The number of channels of sound to be delivered to the + stream callback or passed to Pa_WriteStream. It can range from 1 to the value + of maxOutputChannels in the PaDeviceInfo record for the default output device. + If 0 the stream is opened as an output-only stream. + + @param sampleFormat The sample format of both the input and output buffers + provided to the callback or passed to and from Pa_ReadStream and Pa_WriteStream. + sampleFormat may be any of the formats described by the PaSampleFormat + enumeration. + + @param sampleRate Same as Pa_OpenStream parameter of the same name. + @param framesPerBuffer Same as Pa_OpenStream parameter of the same name. + @param streamCallback Same as Pa_OpenStream parameter of the same name. + @param userData Same as Pa_OpenStream parameter of the same name. + + @return As for Pa_OpenStream + + @see Pa_OpenStream, PaStreamCallback +*/ +PaError Pa_OpenDefaultStream( PaStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + PaStreamCallback *streamCallback, + void *userData ); + + +/** Closes an audio stream. If the audio stream is active it + discards any pending buffers as if Pa_AbortStream() had been called. +*/ +PaError Pa_CloseStream( PaStream *stream ); + + +/** Functions of type PaStreamFinishedCallback are implemented by PortAudio + clients. They can be registered with a stream using the Pa_SetStreamFinishedCallback + function. Once registered they are called when the stream becomes inactive + (ie once a call to Pa_StopStream() will not block). + A stream will become inactive after the stream callback returns non-zero, + or when Pa_StopStream or Pa_AbortStream is called. For a stream providing audio + output, if the stream callback returns paComplete, or Pa_StopStream() is called, + the stream finished callback will not be called until all generated sample data + has been played. + + @param userData The userData parameter supplied to Pa_OpenStream() + + @see Pa_SetStreamFinishedCallback +*/ +typedef void PaStreamFinishedCallback( void *userData ); + + +/** Register a stream finished callback function which will be called when the + stream becomes inactive. See the description of PaStreamFinishedCallback for + further details about when the callback will be called. + + @param stream a pointer to a PaStream that is in the stopped state - if the + stream is not stopped, the stream's finished callback will remain unchanged + and an error code will be returned. + + @param streamFinishedCallback a pointer to a function with the same signature + as PaStreamFinishedCallback, that will be called when the stream becomes + inactive. Passing NULL for this parameter will un-register a previously + registered stream finished callback function. + + @return on success returns paNoError, otherwise an error code indicating the cause + of the error. + + @see PaStreamFinishedCallback +*/ +PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); + + +/** Commences audio processing. +*/ +PaError Pa_StartStream( PaStream *stream ); + + +/** Terminates audio processing. It waits until all pending + audio buffers have been played before it returns. +*/ +PaError Pa_StopStream( PaStream *stream ); + + +/** Terminates audio processing immediately without waiting for pending + buffers to complete. +*/ +PaError Pa_AbortStream( PaStream *stream ); + + +/** Determine whether the stream is stopped. + A stream is considered to be stopped prior to a successful call to + Pa_StartStream and after a successful call to Pa_StopStream or Pa_AbortStream. + If a stream callback returns a value other than paContinue the stream is NOT + considered to be stopped. + + @return Returns one (1) when the stream is stopped, zero (0) when + the stream is running or, a PaErrorCode (which are always negative) if + PortAudio is not initialized or an error is encountered. + + @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive +*/ +PaError Pa_IsStreamStopped( PaStream *stream ); + + +/** Determine whether the stream is active. + A stream is active after a successful call to Pa_StartStream(), until it + becomes inactive either as a result of a call to Pa_StopStream() or + Pa_AbortStream(), or as a result of a return value other than paContinue from + the stream callback. In the latter case, the stream is considered inactive + after the last buffer has finished playing. + + @return Returns one (1) when the stream is active (ie playing or recording + audio), zero (0) when not playing or, a PaErrorCode (which are always negative) + if PortAudio is not initialized or an error is encountered. + + @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped +*/ +PaError Pa_IsStreamActive( PaStream *stream ); + + + +/** A structure containing unchanging information about an open stream. + @see Pa_GetStreamInfo +*/ + +typedef struct PaStreamInfo +{ + /** this is struct version 1 */ + int structVersion; + + /** The input latency of the stream in seconds. This value provides the most + accurate estimate of input latency available to the implementation. It may + differ significantly from the suggestedLatency value passed to Pa_OpenStream(). + The value of this field will be zero (0.) for output-only streams. + @see PaTime + */ + PaTime inputLatency; + + /** The output latency of the stream in seconds. This value provides the most + accurate estimate of output latency available to the implementation. It may + differ significantly from the suggestedLatency value passed to Pa_OpenStream(). + The value of this field will be zero (0.) for input-only streams. + @see PaTime + */ + PaTime outputLatency; + + /** The sample rate of the stream in Hertz (samples per second). In cases + where the hardware sample rate is inaccurate and PortAudio is aware of it, + the value of this field may be different from the sampleRate parameter + passed to Pa_OpenStream(). If information about the actual hardware sample + rate is not available, this field will have the same value as the sampleRate + parameter passed to Pa_OpenStream(). + */ + double sampleRate; + +} PaStreamInfo; + + +/** Retrieve a pointer to a PaStreamInfo structure containing information + about the specified stream. + @return A pointer to an immutable PaStreamInfo structure. If the stream + parameter is invalid, or an error is encountered, the function returns NULL. + + @param stream A pointer to an open stream previously created with Pa_OpenStream. + + @note PortAudio manages the memory referenced by the returned pointer, + the client must not manipulate or free the memory. The pointer is only + guaranteed to be valid until the specified stream is closed. + + @see PaStreamInfo +*/ +const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream ); + + +/** Returns the current time in seconds for a stream according to the same clock used + to generate callback PaStreamCallbackTimeInfo timestamps. The time values are + monotonically increasing and have unspecified origin. + + Pa_GetStreamTime returns valid time values for the entire life of the stream, + from when the stream is opened until it is closed. Starting and stopping the stream + does not affect the passage of time returned by Pa_GetStreamTime. + + This time may be used for synchronizing other events to the audio stream, for + example synchronizing audio to MIDI. + + @return The stream's current time in seconds, or 0 if an error occurred. + + @see PaTime, PaStreamCallback, PaStreamCallbackTimeInfo +*/ +PaTime Pa_GetStreamTime( PaStream *stream ); + + +/** Retrieve CPU usage information for the specified stream. + The "CPU Load" is a fraction of total CPU time consumed by a callback stream's + audio processing routines including, but not limited to the client supplied + stream callback. This function does not work with blocking read/write streams. + + This function may be called from the stream callback function or the + application. + + @return + A floating point value, typically between 0.0 and 1.0, where 1.0 indicates + that the stream callback is consuming the maximum number of CPU cycles possible + to maintain real-time operation. A value of 0.5 would imply that PortAudio and + the stream callback was consuming roughly 50% of the available CPU time. The + return value may exceed 1.0. A value of 0.0 will always be returned for a + blocking read/write stream, or if an error occurs. +*/ +double Pa_GetStreamCpuLoad( PaStream* stream ); + + +/** Read samples from an input stream. The function doesn't return until + the entire buffer has been filled - this may involve waiting for the operating + system to supply the data. + + @param stream A pointer to an open stream previously created with Pa_OpenStream. + + @param buffer A pointer to a buffer of sample frames. The buffer contains + samples in the format specified by the inputParameters->sampleFormat field + used to open the stream, and the number of channels specified by + inputParameters->numChannels. If non-interleaved samples were requested using + the paNonInterleaved sample format flag, buffer is a pointer to the first element + of an array of buffer pointers, one non-interleaved buffer for each channel. + + @param frames The number of frames to be read into buffer. This parameter + is not constrained to a specific range, however high performance applications + will want to match this parameter to the framesPerBuffer parameter used + when opening the stream. + + @return On success PaNoError will be returned, or PaInputOverflowed if input + data was discarded by PortAudio after the previous call and before this call. +*/ +PaError Pa_ReadStream( PaStream* stream, + void *buffer, + unsigned long frames ); + + +/** Write samples to an output stream. This function doesn't return until the + entire buffer has been written - this may involve waiting for the operating + system to consume the data. + + @param stream A pointer to an open stream previously created with Pa_OpenStream. + + @param buffer A pointer to a buffer of sample frames. The buffer contains + samples in the format specified by the outputParameters->sampleFormat field + used to open the stream, and the number of channels specified by + outputParameters->numChannels. If non-interleaved samples were requested using + the paNonInterleaved sample format flag, buffer is a pointer to the first element + of an array of buffer pointers, one non-interleaved buffer for each channel. + + @param frames The number of frames to be written from buffer. This parameter + is not constrained to a specific range, however high performance applications + will want to match this parameter to the framesPerBuffer parameter used + when opening the stream. + + @return On success PaNoError will be returned, or paOutputUnderflowed if + additional output data was inserted after the previous call and before this + call. +*/ +PaError Pa_WriteStream( PaStream* stream, + const void *buffer, + unsigned long frames ); + + +/** Retrieve the number of frames that can be read from the stream without + waiting. + + @return Returns a non-negative value representing the maximum number of frames + that can be read from the stream without blocking or busy waiting or, a + PaErrorCode (which are always negative) if PortAudio is not initialized or an + error is encountered. +*/ +signed long Pa_GetStreamReadAvailable( PaStream* stream ); + + +/** Retrieve the number of frames that can be written to the stream without + waiting. + + @return Returns a non-negative value representing the maximum number of frames + that can be written to the stream without blocking or busy waiting or, a + PaErrorCode (which are always negative) if PortAudio is not initialized or an + error is encountered. +*/ +signed long Pa_GetStreamWriteAvailable( PaStream* stream ); + + +/* Miscellaneous utilities */ + + +/** Retrieve the size of a given sample format in bytes. + + @return The size in bytes of a single sample in the specified format, + or paSampleFormatNotSupported if the format is not supported. +*/ +PaError Pa_GetSampleSize( PaSampleFormat format ); + + +/** Put the caller to sleep for at least 'msec' milliseconds. This function is + provided only as a convenience for authors of portable code (such as the tests + and examples in the PortAudio distribution.) + + The function may sleep longer than requested so don't rely on this for accurate + musical timing. +*/ +void Pa_Sleep( long msec ); + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* PORTAUDIO_H */ diff --git a/portaudio/macos/libportaudio.2.dylib b/portaudio/macos/libportaudio.2.dylib new file mode 100755 index 0000000..d7db3ed Binary files /dev/null and b/portaudio/macos/libportaudio.2.dylib differ diff --git a/portaudio/macos/libportaudio.a b/portaudio/macos/libportaudio.a new file mode 100644 index 0000000..df68ec1 Binary files /dev/null and b/portaudio/macos/libportaudio.a differ diff --git a/portaudio/win32/portaudio.lib b/portaudio/win32/portaudio.lib new file mode 100644 index 0000000..20e2a69 Binary files /dev/null and b/portaudio/win32/portaudio.lib differ diff --git a/portaudio/win32/portaudio_x86.dll b/portaudio/win32/portaudio_x86.dll new file mode 100644 index 0000000..1e06466 Binary files /dev/null and b/portaudio/win32/portaudio_x86.dll differ diff --git a/sndfile/include/sndfile.h b/sndfile/include/sndfile.h new file mode 100644 index 0000000..db6b868 --- /dev/null +++ b/sndfile/include/sndfile.h @@ -0,0 +1,857 @@ +/* +** Copyright (C) 1999-2016 Erik de Castro Lopo +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU Lesser General Public License as published by +** the Free Software Foundation; either version 2.1 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +/* +** sndfile.h -- system-wide definitions +** +** API documentation is in the doc/ directory of the source code tarball +** and at http://www.mega-nerd.com/libsndfile/api.html. +*/ + +#ifndef SNDFILE_H +#define SNDFILE_H + +/* This is the version 1.0.X header file. */ +#define SNDFILE_1 + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* The following file types can be read and written. +** A file type would consist of a major type (ie SF_FORMAT_WAV) bitwise +** ORed with a minor type (ie SF_FORMAT_PCM). SF_FORMAT_TYPEMASK and +** SF_FORMAT_SUBMASK can be used to separate the major and minor file +** types. +*/ + +enum +{ /* Major formats. */ + SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */ + SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */ + SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */ + SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */ + SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */ + SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */ + SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */ + SF_FORMAT_VOC = 0x080000, /* VOC files. */ + SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */ + SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */ + SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */ + SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */ + SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */ + SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */ + SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */ + SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */ + SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */ + SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */ + SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */ + SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */ + SF_FORMAT_CAF = 0x180000, /* Core Audio File format */ + SF_FORMAT_WVE = 0x190000, /* Psion WVE format */ + SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */ + SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */ + SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */ + + /* Subtypes from here on. */ + + SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */ + SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */ + SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */ + SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */ + + SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */ + + SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */ + SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */ + + SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */ + SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */ + SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */ + SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */ + + SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */ + SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */ + + SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */ + SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */ + SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */ + + SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */ + SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */ + SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */ + SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */ + + SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */ + SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */ + + SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */ + + SF_FORMAT_ALAC_16 = 0x0070, /* Apple Lossless Audio Codec (16 bit). */ + SF_FORMAT_ALAC_20 = 0x0071, /* Apple Lossless Audio Codec (20 bit). */ + SF_FORMAT_ALAC_24 = 0x0072, /* Apple Lossless Audio Codec (24 bit). */ + SF_FORMAT_ALAC_32 = 0x0073, /* Apple Lossless Audio Codec (32 bit). */ + + /* Endian-ness options. */ + + SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */ + SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */ + SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */ + SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */ + + SF_FORMAT_SUBMASK = 0x0000FFFF, + SF_FORMAT_TYPEMASK = 0x0FFF0000, + SF_FORMAT_ENDMASK = 0x30000000 +} ; + +/* +** The following are the valid command numbers for the sf_command() +** interface. The use of these commands is documented in the file +** command.html in the doc directory of the source code distribution. +*/ + +enum +{ SFC_GET_LIB_VERSION = 0x1000, + SFC_GET_LOG_INFO = 0x1001, + SFC_GET_CURRENT_SF_INFO = 0x1002, + + + SFC_GET_NORM_DOUBLE = 0x1010, + SFC_GET_NORM_FLOAT = 0x1011, + SFC_SET_NORM_DOUBLE = 0x1012, + SFC_SET_NORM_FLOAT = 0x1013, + SFC_SET_SCALE_FLOAT_INT_READ = 0x1014, + SFC_SET_SCALE_INT_FLOAT_WRITE = 0x1015, + + SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020, + SFC_GET_SIMPLE_FORMAT = 0x1021, + + SFC_GET_FORMAT_INFO = 0x1028, + + SFC_GET_FORMAT_MAJOR_COUNT = 0x1030, + SFC_GET_FORMAT_MAJOR = 0x1031, + SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032, + SFC_GET_FORMAT_SUBTYPE = 0x1033, + + SFC_CALC_SIGNAL_MAX = 0x1040, + SFC_CALC_NORM_SIGNAL_MAX = 0x1041, + SFC_CALC_MAX_ALL_CHANNELS = 0x1042, + SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043, + SFC_GET_SIGNAL_MAX = 0x1044, + SFC_GET_MAX_ALL_CHANNELS = 0x1045, + + SFC_SET_ADD_PEAK_CHUNK = 0x1050, + SFC_SET_ADD_HEADER_PAD_CHUNK = 0x1051, + + SFC_UPDATE_HEADER_NOW = 0x1060, + SFC_SET_UPDATE_HEADER_AUTO = 0x1061, + + SFC_FILE_TRUNCATE = 0x1080, + + SFC_SET_RAW_START_OFFSET = 0x1090, + + SFC_SET_DITHER_ON_WRITE = 0x10A0, + SFC_SET_DITHER_ON_READ = 0x10A1, + + SFC_GET_DITHER_INFO_COUNT = 0x10A2, + SFC_GET_DITHER_INFO = 0x10A3, + + SFC_GET_EMBED_FILE_INFO = 0x10B0, + + SFC_SET_CLIPPING = 0x10C0, + SFC_GET_CLIPPING = 0x10C1, + + SFC_GET_CUE_COUNT = 0x10CD, + SFC_GET_CUE = 0x10CE, + SFC_SET_CUE = 0x10CF, + + SFC_GET_INSTRUMENT = 0x10D0, + SFC_SET_INSTRUMENT = 0x10D1, + + SFC_GET_LOOP_INFO = 0x10E0, + + SFC_GET_BROADCAST_INFO = 0x10F0, + SFC_SET_BROADCAST_INFO = 0x10F1, + + SFC_GET_CHANNEL_MAP_INFO = 0x1100, + SFC_SET_CHANNEL_MAP_INFO = 0x1101, + + SFC_RAW_DATA_NEEDS_ENDSWAP = 0x1110, + + /* Support for Wavex Ambisonics Format */ + SFC_WAVEX_SET_AMBISONIC = 0x1200, + SFC_WAVEX_GET_AMBISONIC = 0x1201, + + /* + ** RF64 files can be set so that on-close, writable files that have less + ** than 4GB of data in them are converted to RIFF/WAV, as per EBU + ** recommendations. + */ + SFC_RF64_AUTO_DOWNGRADE = 0x1210, + + SFC_SET_VBR_ENCODING_QUALITY = 0x1300, + SFC_SET_COMPRESSION_LEVEL = 0x1301, + + /* Cart Chunk support */ + SFC_SET_CART_INFO = 0x1400, + SFC_GET_CART_INFO = 0x1401, + + /* Following commands for testing only. */ + SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001, + + /* + ** SFC_SET_ADD_* values are deprecated and will disappear at some + ** time in the future. They are guaranteed to be here up to and + ** including version 1.0.8 to avoid breakage of existing software. + ** They currently do nothing and will continue to do nothing. + */ + SFC_SET_ADD_DITHER_ON_WRITE = 0x1070, + SFC_SET_ADD_DITHER_ON_READ = 0x1071 +} ; + + +/* +** String types that can be set and read from files. Not all file types +** support this and even the file types which support one, may not support +** all string types. +*/ + +enum +{ SF_STR_TITLE = 0x01, + SF_STR_COPYRIGHT = 0x02, + SF_STR_SOFTWARE = 0x03, + SF_STR_ARTIST = 0x04, + SF_STR_COMMENT = 0x05, + SF_STR_DATE = 0x06, + SF_STR_ALBUM = 0x07, + SF_STR_LICENSE = 0x08, + SF_STR_TRACKNUMBER = 0x09, + SF_STR_GENRE = 0x10 +} ; + +/* +** Use the following as the start and end index when doing metadata +** transcoding. +*/ + +#define SF_STR_FIRST SF_STR_TITLE +#define SF_STR_LAST SF_STR_GENRE + +enum +{ /* True and false */ + SF_FALSE = 0, + SF_TRUE = 1, + + /* Modes for opening files. */ + SFM_READ = 0x10, + SFM_WRITE = 0x20, + SFM_RDWR = 0x30, + + SF_AMBISONIC_NONE = 0x40, + SF_AMBISONIC_B_FORMAT = 0x41 +} ; + +/* Public error values. These are guaranteed to remain unchanged for the duration +** of the library major version number. +** There are also a large number of private error numbers which are internal to +** the library which can change at any time. +*/ + +enum +{ SF_ERR_NO_ERROR = 0, + SF_ERR_UNRECOGNISED_FORMAT = 1, + SF_ERR_SYSTEM = 2, + SF_ERR_MALFORMED_FILE = 3, + SF_ERR_UNSUPPORTED_ENCODING = 4 +} ; + + +/* Channel map values (used with SFC_SET/GET_CHANNEL_MAP). +*/ + +enum +{ SF_CHANNEL_MAP_INVALID = 0, + SF_CHANNEL_MAP_MONO = 1, + SF_CHANNEL_MAP_LEFT, /* Apple calls this 'Left' */ + SF_CHANNEL_MAP_RIGHT, /* Apple calls this 'Right' */ + SF_CHANNEL_MAP_CENTER, /* Apple calls this 'Center' */ + SF_CHANNEL_MAP_FRONT_LEFT, + SF_CHANNEL_MAP_FRONT_RIGHT, + SF_CHANNEL_MAP_FRONT_CENTER, + SF_CHANNEL_MAP_REAR_CENTER, /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */ + SF_CHANNEL_MAP_REAR_LEFT, /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */ + SF_CHANNEL_MAP_REAR_RIGHT, /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */ + SF_CHANNEL_MAP_LFE, /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */ + SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */ + SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */ + SF_CHANNEL_MAP_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */ + SF_CHANNEL_MAP_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */ + SF_CHANNEL_MAP_TOP_CENTER, /* Apple calls this 'Top Center Surround' */ + SF_CHANNEL_MAP_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */ + SF_CHANNEL_MAP_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */ + SF_CHANNEL_MAP_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */ + SF_CHANNEL_MAP_TOP_REAR_LEFT, /* Apple and MS call this 'Top Back Left' */ + SF_CHANNEL_MAP_TOP_REAR_RIGHT, /* Apple and MS call this 'Top Back Right' */ + SF_CHANNEL_MAP_TOP_REAR_CENTER, /* Apple and MS call this 'Top Back Center' */ + + SF_CHANNEL_MAP_AMBISONIC_B_W, + SF_CHANNEL_MAP_AMBISONIC_B_X, + SF_CHANNEL_MAP_AMBISONIC_B_Y, + SF_CHANNEL_MAP_AMBISONIC_B_Z, + + SF_CHANNEL_MAP_MAX +} ; + + +/* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */ + +typedef struct SNDFILE_tag SNDFILE ; + +/* The following typedef is system specific and is defined when libsndfile is +** compiled. sf_count_t will be a 64 bit value when the underlying OS allows +** 64 bit file offsets. +** On windows, we need to allow the same header file to be compiler by both GCC +** and the Microsoft compiler. +*/ + +#if (defined (_MSCVER) || defined (_MSC_VER) && (_MSC_VER < 1310)) +typedef __int64 sf_count_t ; +#define SF_COUNT_MAX 0x7fffffffffffffffi64 +#else +typedef long long sf_count_t ; +#define SF_COUNT_MAX 0x7FFFFFFFFFFFFFFFLL +#endif + + +/* A pointer to a SF_INFO structure is passed to sf_open () and filled in. +** On write, the SF_INFO structure is filled in by the user and passed into +** sf_open (). +*/ + +struct SF_INFO +{ sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */ + int samplerate ; + int channels ; + int format ; + int sections ; + int seekable ; +} ; + +typedef struct SF_INFO SF_INFO ; + +/* The SF_FORMAT_INFO struct is used to retrieve information about the sound +** file formats libsndfile supports using the sf_command () interface. +** +** Using this interface will allow applications to support new file formats +** and encoding types when libsndfile is upgraded, without requiring +** re-compilation of the application. +** +** Please consult the libsndfile documentation (particularly the information +** on the sf_command () interface) for examples of its use. +*/ + +typedef struct +{ int format ; + const char *name ; + const char *extension ; +} SF_FORMAT_INFO ; + +/* +** Enums and typedefs for adding dither on read and write. +** See the html documentation for sf_command(), SFC_SET_DITHER_ON_WRITE +** and SFC_SET_DITHER_ON_READ. +*/ + +enum +{ SFD_DEFAULT_LEVEL = 0, + SFD_CUSTOM_LEVEL = 0x40000000, + + SFD_NO_DITHER = 500, + SFD_WHITE = 501, + SFD_TRIANGULAR_PDF = 502 +} ; + +typedef struct +{ int type ; + double level ; + const char *name ; +} SF_DITHER_INFO ; + +/* Struct used to retrieve information about a file embedded within a +** larger file. See SFC_GET_EMBED_FILE_INFO. +*/ + +typedef struct +{ sf_count_t offset ; + sf_count_t length ; +} SF_EMBED_FILE_INFO ; + +/* +** Struct used to retrieve cue marker information from a file +*/ + +typedef struct +{ int32_t indx ; + uint32_t position ; + int32_t fcc_chunk ; + int32_t chunk_start ; + int32_t block_start ; + uint32_t sample_offset ; + char name [256] ; +} SF_CUE_POINT ; + +#define SF_CUES_VAR(count) \ + struct \ + { uint32_t cue_count ; \ + SF_CUE_POINT cue_points [count] ; \ + } + +typedef SF_CUES_VAR (100) SF_CUES ; + +/* +** Structs used to retrieve music sample information from a file. +*/ + +enum +{ /* + ** The loop mode field in SF_INSTRUMENT will be one of the following. + */ + SF_LOOP_NONE = 800, + SF_LOOP_FORWARD, + SF_LOOP_BACKWARD, + SF_LOOP_ALTERNATING +} ; + +typedef struct +{ int gain ; + char basenote, detune ; + char velocity_lo, velocity_hi ; + char key_lo, key_hi ; + int loop_count ; + + struct + { int mode ; + uint32_t start ; + uint32_t end ; + uint32_t count ; + } loops [16] ; /* make variable in a sensible way */ +} SF_INSTRUMENT ; + + + +/* Struct used to retrieve loop information from a file.*/ +typedef struct +{ + short time_sig_num ; /* any positive integer > 0 */ + short time_sig_den ; /* any positive power of 2 > 0 */ + int loop_mode ; /* see SF_LOOP enum */ + + int num_beats ; /* this is NOT the amount of quarter notes !!!*/ + /* a full bar of 4/4 is 4 beats */ + /* a full bar of 7/8 is 7 beats */ + + float bpm ; /* suggestion, as it can be calculated using other fields:*/ + /* file's length, file's sampleRate and our time_sig_den*/ + /* -> bpms are always the amount of _quarter notes_ per minute */ + + int root_key ; /* MIDI note, or -1 for None */ + int future [6] ; +} SF_LOOP_INFO ; + + +/* Struct used to retrieve broadcast (EBU) information from a file. +** Strongly (!) based on EBU "bext" chunk format used in Broadcast WAVE. +*/ +#define SF_BROADCAST_INFO_VAR(coding_hist_size) \ + struct \ + { char description [256] ; \ + char originator [32] ; \ + char originator_reference [32] ; \ + char origination_date [10] ; \ + char origination_time [8] ; \ + uint32_t time_reference_low ; \ + uint32_t time_reference_high ; \ + short version ; \ + char umid [64] ; \ + char reserved [190] ; \ + uint32_t coding_history_size ; \ + char coding_history [coding_hist_size] ; \ + } + +/* SF_BROADCAST_INFO is the above struct with coding_history field of 256 bytes. */ +typedef SF_BROADCAST_INFO_VAR (256) SF_BROADCAST_INFO ; + +struct SF_CART_TIMER +{ char usage [4] ; + int32_t value ; +} ; + +typedef struct SF_CART_TIMER SF_CART_TIMER ; + +#define SF_CART_INFO_VAR(p_tag_text_size) \ + struct \ + { char version [4] ; \ + char title [64] ; \ + char artist [64] ; \ + char cut_id [64] ; \ + char client_id [64] ; \ + char category [64] ; \ + char classification [64] ; \ + char out_cue [64] ; \ + char start_date [10] ; \ + char start_time [8] ; \ + char end_date [10] ; \ + char end_time [8] ; \ + char producer_app_id [64] ; \ + char producer_app_version [64] ; \ + char user_def [64] ; \ + int32_t level_reference ; \ + SF_CART_TIMER post_timers [8] ; \ + char reserved [276] ; \ + char url [1024] ; \ + uint32_t tag_text_size ; \ + char tag_text [p_tag_text_size] ; \ + } + +typedef SF_CART_INFO_VAR (256) SF_CART_INFO ; + +/* Virtual I/O functionality. */ + +typedef sf_count_t (*sf_vio_get_filelen) (void *user_data) ; +typedef sf_count_t (*sf_vio_seek) (sf_count_t offset, int whence, void *user_data) ; +typedef sf_count_t (*sf_vio_read) (void *ptr, sf_count_t count, void *user_data) ; +typedef sf_count_t (*sf_vio_write) (const void *ptr, sf_count_t count, void *user_data) ; +typedef sf_count_t (*sf_vio_tell) (void *user_data) ; + +struct SF_VIRTUAL_IO +{ sf_vio_get_filelen get_filelen ; + sf_vio_seek seek ; + sf_vio_read read ; + sf_vio_write write ; + sf_vio_tell tell ; +} ; + +typedef struct SF_VIRTUAL_IO SF_VIRTUAL_IO ; + + +/* Open the specified file for read, write or both. On error, this will +** return a NULL pointer. To find the error number, pass a NULL SNDFILE +** to sf_strerror (). +** All calls to sf_open() should be matched with a call to sf_close(). +*/ + +SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ; + + +/* Use the existing file descriptor to create a SNDFILE object. If close_desc +** is TRUE, the file descriptor will be closed when sf_close() is called. If +** it is FALSE, the descriptor will not be closed. +** When passed a descriptor like this, the library will assume that the start +** of file header is at the current file offset. This allows sound files within +** larger container files to be read and/or written. +** On error, this will return a NULL pointer. To find the error number, pass a +** NULL SNDFILE to sf_strerror (). +** All calls to sf_open_fd() should be matched with a call to sf_close(). + +*/ + +SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ; + +SNDFILE* sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ; + + +/* sf_error () returns a error number which can be translated to a text +** string using sf_error_number(). +*/ + +int sf_error (SNDFILE *sndfile) ; + + +/* sf_strerror () returns to the caller a pointer to the current error message for +** the given SNDFILE. +*/ + +const char* sf_strerror (SNDFILE *sndfile) ; + + +/* sf_error_number () allows the retrieval of the error string for each internal +** error number. +** +*/ + +const char* sf_error_number (int errnum) ; + + +/* The following two error functions are deprecated but they will remain in the +** library for the foreseeable future. The function sf_strerror() should be used +** in their place. +*/ + +int sf_perror (SNDFILE *sndfile) ; +int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ; + + +/* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */ + +int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ; + + +/* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */ + +int sf_format_check (const SF_INFO *info) ; + + +/* Seek within the waveform data chunk of the SNDFILE. sf_seek () uses +** the same values for whence (SEEK_SET, SEEK_CUR and SEEK_END) as +** stdio.h function fseek (). +** An offset of zero with whence set to SEEK_SET will position the +** read / write pointer to the first data sample. +** On success sf_seek returns the current position in (multi-channel) +** samples from the start of the file. +** Please see the libsndfile documentation for moving the read pointer +** separately from the write pointer on files open in mode SFM_RDWR. +** On error all of these functions return -1. +*/ + +enum +{ SF_SEEK_SET = SEEK_SET, + SF_SEEK_CUR = SEEK_CUR, + SF_SEEK_END = SEEK_END +} ; + +sf_count_t sf_seek (SNDFILE *sndfile, sf_count_t frames, int whence) ; + + +/* Functions for retrieving and setting string data within sound files. +** Not all file types support this features; AIFF and WAV do. For both +** functions, the str_type parameter must be one of the SF_STR_* values +** defined above. +** On error, sf_set_string() returns non-zero while sf_get_string() +** returns NULL. +*/ + +int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ; + +const char* sf_get_string (SNDFILE *sndfile, int str_type) ; + + +/* Return the library version string. */ + +const char * sf_version_string (void) ; + +/* Return the current byterate at this point in the file. The byte rate in this +** case is the number of bytes per second of audio data. For instance, for a +** stereo, 18 bit PCM encoded file with an 16kHz sample rate, the byte rate +** would be 2 (stereo) * 2 (two bytes per sample) * 16000 => 64000 bytes/sec. +** For some file formats the returned value will be accurate and exact, for some +** it will be a close approximation, for some it will be the average bitrate for +** the whole file and for some it will be a time varying value that was accurate +** when the file was most recently read or written. +** To get the bitrate, multiple this value by 8. +** Returns -1 for unknown. +*/ +int sf_current_byterate (SNDFILE *sndfile) ; + +/* Functions for reading/writing the waveform data of a sound file. +*/ + +sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ; +sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ; + + +/* Functions for reading and writing the data chunk in terms of frames. +** The number of items actually read/written = frames * number of channels. +** sf_xxxx_raw read/writes the raw data bytes from/to the file +** sf_xxxx_short passes data in the native short format +** sf_xxxx_int passes data in the native int format +** sf_xxxx_float passes data in the native float format +** sf_xxxx_double passes data in the native double format +** All of these read/write function return number of frames read/written. +*/ + +sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ; +sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ; + +sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ; +sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ; + +sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ; +sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ; + +sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ; +sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ; + + +/* Functions for reading and writing the data chunk in terms of items. +** Otherwise similar to above. +** All of these read/write function return number of items read/written. +*/ + +sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ; +sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ; + +sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ; +sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ; + +sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ; +sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ; + +sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ; +sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ; + + +/* Close the SNDFILE and clean up all memory allocations associated with this +** file. +** Returns 0 on success, or an error number. +*/ + +int sf_close (SNDFILE *sndfile) ; + + +/* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file +** to force the writing of data to disk. If the file is opened SFM_READ +** no action is taken. +*/ + +void sf_write_sync (SNDFILE *sndfile) ; + + + +/* The function sf_wchar_open() is Windows Only! +** Open a file passing in a Windows Unicode filename. Otherwise, this is +** the same as sf_open(). +** +** In order for this to work, you need to do the following: +** +** #include +** #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 +** #including +*/ + +#if (defined (ENABLE_SNDFILE_WINDOWS_PROTOTYPES) && ENABLE_SNDFILE_WINDOWS_PROTOTYPES) +SNDFILE* sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo) ; +#endif + + + + +/* Getting and setting of chunks from within a sound file. +** +** These functions allow the getting and setting of chunks within a sound file +** (for those formats which allow it). +** +** These functions fail safely. Specifically, they will not allow you to overwrite +** existing chunks or add extra versions of format specific reserved chunks but +** should allow you to retrieve any and all chunks (may not be implemented for +** all chunks or all file formats). +*/ + +struct SF_CHUNK_INFO +{ char id [64] ; /* The chunk identifier. */ + unsigned id_size ; /* The size of the chunk identifier. */ + unsigned datalen ; /* The size of that data. */ + void *data ; /* Pointer to the data. */ +} ; + +typedef struct SF_CHUNK_INFO SF_CHUNK_INFO ; + +/* Set the specified chunk info (must be done before any audio data is written +** to the file). This will fail for format specific reserved chunks. +** The chunk_info->data pointer must be valid until the file is closed. +** Returns SF_ERR_NO_ERROR on success or non-zero on failure. +*/ +int sf_set_chunk (SNDFILE * sndfile, const SF_CHUNK_INFO * chunk_info) ; + +/* +** An opaque structure to an iterator over the all chunks of a given id +*/ +typedef struct SF_CHUNK_ITERATOR SF_CHUNK_ITERATOR ; + +/* Get an iterator for all chunks matching chunk_info. +** The iterator will point to the first chunk matching chunk_info. +** Chunks are matching, if (chunk_info->id) matches the first +** (chunk_info->id_size) bytes of a chunk found in the SNDFILE* handle. +** If chunk_info is NULL, an iterator to all chunks in the SNDFILE* handle +** is returned. +** The values of chunk_info->datalen and chunk_info->data are ignored. +** If no matching chunks are found in the sndfile, NULL is returned. +** The returned iterator will stay valid until one of the following occurs: +** a) The sndfile is closed. +** b) A new chunk is added using sf_set_chunk(). +** c) Another chunk iterator function is called on the same SNDFILE* handle +** that causes the iterator to be modified. +** The memory for the iterator belongs to the SNDFILE* handle and is freed when +** sf_close() is called. +*/ +SF_CHUNK_ITERATOR * +sf_get_chunk_iterator (SNDFILE * sndfile, const SF_CHUNK_INFO * chunk_info) ; + +/* Iterate through chunks by incrementing the iterator. +** Increments the iterator and returns a handle to the new one. +** After this call, iterator will no longer be valid, and you must use the +** newly returned handle from now on. +** The returned handle can be used to access the next chunk matching +** the criteria as defined in sf_get_chunk_iterator(). +** If iterator points to the last chunk, this will free all resources +** associated with iterator and return NULL. +** The returned iterator will stay valid until sf_get_chunk_iterator_next +** is called again, the sndfile is closed or a new chunk us added. +*/ +SF_CHUNK_ITERATOR * +sf_next_chunk_iterator (SF_CHUNK_ITERATOR * iterator) ; + + +/* Get the size of the specified chunk. +** If the specified chunk exists, the size will be returned in the +** datalen field of the SF_CHUNK_INFO struct. +** Additionally, the id of the chunk will be copied to the id +** field of the SF_CHUNK_INFO struct and it's id_size field will +** be updated accordingly. +** If the chunk doesn't exist chunk_info->datalen will be zero, and the +** id and id_size fields will be undefined. +** The function will return SF_ERR_NO_ERROR on success or non-zero on +** failure. +*/ +int +sf_get_chunk_size (const SF_CHUNK_ITERATOR * it, SF_CHUNK_INFO * chunk_info) ; + +/* Get the specified chunk data. +** If the specified chunk exists, up to chunk_info->datalen bytes of +** the chunk data will be copied into the chunk_info->data buffer +** (allocated by the caller) and the chunk_info->datalen field +** updated to reflect the size of the data. The id and id_size +** field will be updated according to the retrieved chunk +** If the chunk doesn't exist chunk_info->datalen will be zero, and the +** id and id_size fields will be undefined. +** The function will return SF_ERR_NO_ERROR on success or non-zero on +** failure. +*/ +int +sf_get_chunk_data (const SF_CHUNK_ITERATOR * it, SF_CHUNK_INFO * chunk_info) ; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* SNDFILE_H */ + diff --git a/sndfile/include/sndfile.hh b/sndfile/include/sndfile.hh new file mode 100644 index 0000000..0e1c1c2 --- /dev/null +++ b/sndfile/include/sndfile.hh @@ -0,0 +1,446 @@ +/* +** Copyright (C) 2005-2012 Erik de Castro Lopo +** +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the author nor the names of any contributors may be used +** to endorse or promote products derived from this software without +** specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* +** The above modified BSD style license (GPL and LGPL compatible) applies to +** this file. It does not apply to libsndfile itself which is released under +** the GNU LGPL or the libsndfile test suite which is released under the GNU +** GPL. +** This means that this header file can be used under this modified BSD style +** license, but the LGPL still holds for the libsndfile library itself. +*/ + +/* +** sndfile.hh -- A lightweight C++ wrapper for the libsndfile API. +** +** All the methods are inlines and all functionality is contained in this +** file. There is no separate implementation file. +** +** API documentation is in the doc/ directory of the source code tarball +** and at http://www.mega-nerd.com/libsndfile/api.html. +*/ + +#ifndef SNDFILE_HH +#define SNDFILE_HH + +#include + +#include +#include // for std::nothrow + +class SndfileHandle +{ private : + struct SNDFILE_ref + { SNDFILE_ref (void) ; + ~SNDFILE_ref (void) ; + + SNDFILE *sf ; + SF_INFO sfinfo ; + int ref ; + } ; + + SNDFILE_ref *p ; + + public : + /* Default constructor */ + SndfileHandle (void) : p (NULL) {} ; + SndfileHandle (const char *path, int mode = SFM_READ, + int format = 0, int channels = 0, int samplerate = 0) ; + SndfileHandle (std::string const & path, int mode = SFM_READ, + int format = 0, int channels = 0, int samplerate = 0) ; + SndfileHandle (int fd, bool close_desc, int mode = SFM_READ, + int format = 0, int channels = 0, int samplerate = 0) ; + SndfileHandle (SF_VIRTUAL_IO &sfvirtual, void *user_data, int mode = SFM_READ, + int format = 0, int channels = 0, int samplerate = 0) ; + +#ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES + SndfileHandle (LPCWSTR wpath, int mode = SFM_READ, + int format = 0, int channels = 0, int samplerate = 0) ; +#endif + + ~SndfileHandle (void) ; + + SndfileHandle (const SndfileHandle &orig) ; + SndfileHandle & operator = (const SndfileHandle &rhs) ; + + /* Mainly for debugging/testing. */ + int refCount (void) const { return (p == NULL) ? 0 : p->ref ; } + + operator bool () const { return (p != NULL) ; } + + bool operator == (const SndfileHandle &rhs) const { return (p == rhs.p) ; } + + sf_count_t frames (void) const { return p ? p->sfinfo.frames : 0 ; } + int format (void) const { return p ? p->sfinfo.format : 0 ; } + int channels (void) const { return p ? p->sfinfo.channels : 0 ; } + int samplerate (void) const { return p ? p->sfinfo.samplerate : 0 ; } + + int error (void) const ; + const char * strError (void) const ; + + int command (int cmd, void *data, int datasize) ; + + sf_count_t seek (sf_count_t frames, int whence) ; + + void writeSync (void) ; + + int setString (int str_type, const char* str) ; + + const char* getString (int str_type) const ; + + static int formatCheck (int format, int channels, int samplerate) ; + + sf_count_t read (short *ptr, sf_count_t items) ; + sf_count_t read (int *ptr, sf_count_t items) ; + sf_count_t read (float *ptr, sf_count_t items) ; + sf_count_t read (double *ptr, sf_count_t items) ; + + sf_count_t write (const short *ptr, sf_count_t items) ; + sf_count_t write (const int *ptr, sf_count_t items) ; + sf_count_t write (const float *ptr, sf_count_t items) ; + sf_count_t write (const double *ptr, sf_count_t items) ; + + sf_count_t readf (short *ptr, sf_count_t frames) ; + sf_count_t readf (int *ptr, sf_count_t frames) ; + sf_count_t readf (float *ptr, sf_count_t frames) ; + sf_count_t readf (double *ptr, sf_count_t frames) ; + + sf_count_t writef (const short *ptr, sf_count_t frames) ; + sf_count_t writef (const int *ptr, sf_count_t frames) ; + sf_count_t writef (const float *ptr, sf_count_t frames) ; + sf_count_t writef (const double *ptr, sf_count_t frames) ; + + sf_count_t readRaw (void *ptr, sf_count_t bytes) ; + sf_count_t writeRaw (const void *ptr, sf_count_t bytes) ; + + /**< Raw access to the handle. SndfileHandle keeps ownership. */ + SNDFILE * rawHandle (void) ; + + /**< Take ownership of handle, if reference count is 1. */ + SNDFILE * takeOwnership (void) ; +} ; + +/*============================================================================== +** Nothing but implementation below. +*/ + +inline +SndfileHandle::SNDFILE_ref::SNDFILE_ref (void) +: sf (NULL), sfinfo (), ref (1) +{} + +inline +SndfileHandle::SNDFILE_ref::~SNDFILE_ref (void) +{ if (sf != NULL) sf_close (sf) ; } + +inline +SndfileHandle::SndfileHandle (const char *path, int mode, int fmt, int chans, int srate) +: p (NULL) +{ + p = new (std::nothrow) SNDFILE_ref () ; + + if (p != NULL) + { p->ref = 1 ; + + p->sfinfo.frames = 0 ; + p->sfinfo.channels = chans ; + p->sfinfo.format = fmt ; + p->sfinfo.samplerate = srate ; + p->sfinfo.sections = 0 ; + p->sfinfo.seekable = 0 ; + + p->sf = sf_open (path, mode, &p->sfinfo) ; + } ; + + return ; +} /* SndfileHandle const char * constructor */ + +inline +SndfileHandle::SndfileHandle (std::string const & path, int mode, int fmt, int chans, int srate) +: p (NULL) +{ + p = new (std::nothrow) SNDFILE_ref () ; + + if (p != NULL) + { p->ref = 1 ; + + p->sfinfo.frames = 0 ; + p->sfinfo.channels = chans ; + p->sfinfo.format = fmt ; + p->sfinfo.samplerate = srate ; + p->sfinfo.sections = 0 ; + p->sfinfo.seekable = 0 ; + + p->sf = sf_open (path.c_str (), mode, &p->sfinfo) ; + } ; + + return ; +} /* SndfileHandle std::string constructor */ + +inline +SndfileHandle::SndfileHandle (int fd, bool close_desc, int mode, int fmt, int chans, int srate) +: p (NULL) +{ + if (fd < 0) + return ; + + p = new (std::nothrow) SNDFILE_ref () ; + + if (p != NULL) + { p->ref = 1 ; + + p->sfinfo.frames = 0 ; + p->sfinfo.channels = chans ; + p->sfinfo.format = fmt ; + p->sfinfo.samplerate = srate ; + p->sfinfo.sections = 0 ; + p->sfinfo.seekable = 0 ; + + p->sf = sf_open_fd (fd, mode, &p->sfinfo, close_desc) ; + } ; + + return ; +} /* SndfileHandle fd constructor */ + +inline +SndfileHandle::SndfileHandle (SF_VIRTUAL_IO &sfvirtual, void *user_data, int mode, int fmt, int chans, int srate) +: p (NULL) +{ + p = new (std::nothrow) SNDFILE_ref () ; + + if (p != NULL) + { p->ref = 1 ; + + p->sfinfo.frames = 0 ; + p->sfinfo.channels = chans ; + p->sfinfo.format = fmt ; + p->sfinfo.samplerate = srate ; + p->sfinfo.sections = 0 ; + p->sfinfo.seekable = 0 ; + + p->sf = sf_open_virtual (&sfvirtual, mode, &p->sfinfo, user_data) ; + } ; + + return ; +} /* SndfileHandle std::string constructor */ + +inline +SndfileHandle::~SndfileHandle (void) +{ if (p != NULL && --p->ref == 0) + delete p ; +} /* SndfileHandle destructor */ + + +inline +SndfileHandle::SndfileHandle (const SndfileHandle &orig) +: p (orig.p) +{ if (p != NULL) + ++p->ref ; +} /* SndfileHandle copy constructor */ + +inline SndfileHandle & +SndfileHandle::operator = (const SndfileHandle &rhs) +{ + if (&rhs == this) + return *this ; + if (p != NULL && --p->ref == 0) + delete p ; + + p = rhs.p ; + if (p != NULL) + ++p->ref ; + + return *this ; +} /* SndfileHandle assignment operator */ + +inline int +SndfileHandle::error (void) const +{ return sf_error (p->sf) ; } + +inline const char * +SndfileHandle::strError (void) const +{ return sf_strerror (p->sf) ; } + +inline int +SndfileHandle::command (int cmd, void *data, int datasize) +{ return sf_command (p->sf, cmd, data, datasize) ; } + +inline sf_count_t +SndfileHandle::seek (sf_count_t frame_count, int whence) +{ return sf_seek (p->sf, frame_count, whence) ; } + +inline void +SndfileHandle::writeSync (void) +{ sf_write_sync (p->sf) ; } + +inline int +SndfileHandle::setString (int str_type, const char* str) +{ return sf_set_string (p->sf, str_type, str) ; } + +inline const char* +SndfileHandle::getString (int str_type) const +{ return sf_get_string (p->sf, str_type) ; } + +inline int +SndfileHandle::formatCheck (int fmt, int chans, int srate) +{ + SF_INFO sfinfo ; + + sfinfo.frames = 0 ; + sfinfo.channels = chans ; + sfinfo.format = fmt ; + sfinfo.samplerate = srate ; + sfinfo.sections = 0 ; + sfinfo.seekable = 0 ; + + return sf_format_check (&sfinfo) ; +} + +/*---------------------------------------------------------------------*/ + +inline sf_count_t +SndfileHandle::read (short *ptr, sf_count_t items) +{ return sf_read_short (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::read (int *ptr, sf_count_t items) +{ return sf_read_int (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::read (float *ptr, sf_count_t items) +{ return sf_read_float (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::read (double *ptr, sf_count_t items) +{ return sf_read_double (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::write (const short *ptr, sf_count_t items) +{ return sf_write_short (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::write (const int *ptr, sf_count_t items) +{ return sf_write_int (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::write (const float *ptr, sf_count_t items) +{ return sf_write_float (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::write (const double *ptr, sf_count_t items) +{ return sf_write_double (p->sf, ptr, items) ; } + +inline sf_count_t +SndfileHandle::readf (short *ptr, sf_count_t frame_count) +{ return sf_readf_short (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::readf (int *ptr, sf_count_t frame_count) +{ return sf_readf_int (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::readf (float *ptr, sf_count_t frame_count) +{ return sf_readf_float (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::readf (double *ptr, sf_count_t frame_count) +{ return sf_readf_double (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::writef (const short *ptr, sf_count_t frame_count) +{ return sf_writef_short (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::writef (const int *ptr, sf_count_t frame_count) +{ return sf_writef_int (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::writef (const float *ptr, sf_count_t frame_count) +{ return sf_writef_float (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::writef (const double *ptr, sf_count_t frame_count) +{ return sf_writef_double (p->sf, ptr, frame_count) ; } + +inline sf_count_t +SndfileHandle::readRaw (void *ptr, sf_count_t bytes) +{ return sf_read_raw (p->sf, ptr, bytes) ; } + +inline sf_count_t +SndfileHandle::writeRaw (const void *ptr, sf_count_t bytes) +{ return sf_write_raw (p->sf, ptr, bytes) ; } + +inline SNDFILE * +SndfileHandle::rawHandle (void) +{ return (p ? p->sf : NULL) ; } + +inline SNDFILE * +SndfileHandle::takeOwnership (void) +{ + if (p == NULL || (p->ref != 1)) + return NULL ; + + SNDFILE * sf = p->sf ; + p->sf = NULL ; + delete p ; + p = NULL ; + return sf ; +} + +#ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES + +inline +SndfileHandle::SndfileHandle (LPCWSTR wpath, int mode, int fmt, int chans, int srate) +: p (NULL) +{ + p = new (std::nothrow) SNDFILE_ref () ; + + if (p != NULL) + { p->ref = 1 ; + + p->sfinfo.frames = 0 ; + p->sfinfo.channels = chans ; + p->sfinfo.format = fmt ; + p->sfinfo.samplerate = srate ; + p->sfinfo.sections = 0 ; + p->sfinfo.seekable = 0 ; + + p->sf = sf_wchar_open (wpath, mode, &p->sfinfo) ; + } ; + + return ; +} /* SndfileHandle const wchar_t * constructor */ + +#endif + +#endif /* SNDFILE_HH */ + diff --git a/sndfile/macos/libsndfile.a b/sndfile/macos/libsndfile.a new file mode 100644 index 0000000..ce52d49 Binary files /dev/null and b/sndfile/macos/libsndfile.a differ diff --git a/sndfile/win32/flac++.dll b/sndfile/win32/flac++.dll new file mode 100644 index 0000000..d4a98de Binary files /dev/null and b/sndfile/win32/flac++.dll differ diff --git a/sndfile/win32/flac++.lib b/sndfile/win32/flac++.lib new file mode 100644 index 0000000..01045e6 Binary files /dev/null and b/sndfile/win32/flac++.lib differ diff --git a/sndfile/win32/flac.dll b/sndfile/win32/flac.dll new file mode 100644 index 0000000..85659bc Binary files /dev/null and b/sndfile/win32/flac.dll differ diff --git a/sndfile/win32/flac.lib b/sndfile/win32/flac.lib new file mode 100644 index 0000000..406de18 Binary files /dev/null and b/sndfile/win32/flac.lib differ diff --git a/sndfile/win32/libsndfile-1.dll b/sndfile/win32/libsndfile-1.dll new file mode 100644 index 0000000..dd4ee21 Binary files /dev/null and b/sndfile/win32/libsndfile-1.dll differ diff --git a/sndfile/win32/libsndfile-1.lib b/sndfile/win32/libsndfile-1.lib new file mode 100644 index 0000000..2c30838 Binary files /dev/null and b/sndfile/win32/libsndfile-1.lib differ diff --git a/sndfile/win32/ogg.dll b/sndfile/win32/ogg.dll new file mode 100644 index 0000000..b5291b3 Binary files /dev/null and b/sndfile/win32/ogg.dll differ diff --git a/sndfile/win32/ogg.lib b/sndfile/win32/ogg.lib new file mode 100644 index 0000000..7ef6bc6 Binary files /dev/null and b/sndfile/win32/ogg.lib differ diff --git a/sndfile/win32/vorbis.dll b/sndfile/win32/vorbis.dll new file mode 100644 index 0000000..d7da84f Binary files /dev/null and b/sndfile/win32/vorbis.dll differ diff --git a/sndfile/win32/vorbis.lib b/sndfile/win32/vorbis.lib new file mode 100644 index 0000000..cdc6516 Binary files /dev/null and b/sndfile/win32/vorbis.lib differ diff --git a/sndfile/win32/vorbisenc.dll b/sndfile/win32/vorbisenc.dll new file mode 100644 index 0000000..74014ba Binary files /dev/null and b/sndfile/win32/vorbisenc.dll differ diff --git a/sndfile/win32/vorbisenc.lib b/sndfile/win32/vorbisenc.lib new file mode 100644 index 0000000..32438c4 Binary files /dev/null and b/sndfile/win32/vorbisenc.lib differ diff --git a/sndfile/win32/vorbisfile.dll b/sndfile/win32/vorbisfile.dll new file mode 100644 index 0000000..d5afd95 Binary files /dev/null and b/sndfile/win32/vorbisfile.dll differ diff --git a/sndfile/win32/vorbisfile.lib b/sndfile/win32/vorbisfile.lib new file mode 100644 index 0000000..572c37e Binary files /dev/null and b/sndfile/win32/vorbisfile.lib differ