From 8ffcdad009e4d410f92fabc4e322a76a0be3a69d Mon Sep 17 00:00:00 2001 From: Daniel Rugerio <50124185+darugeri@users.noreply.github.com> Date: Fri, 28 Jun 2019 16:08:54 -0700 Subject: Update audio samples (#387) * Update SysVAD public sample. * Add WaveTest public sample. --- .../KeywordDetectorContosoAdapter.cpp | 261 ++++++++++++++++++--- .../KeywordDetectorContosoAdapter.idl | 11 + .../KeywordDetectorContosoAdapter.vcxproj | 96 -------- audio/sysvad/KeywordDetectorAdapter/sources | 53 ----- 4 files changed, 243 insertions(+), 178 deletions(-) delete mode 100644 audio/sysvad/KeywordDetectorAdapter/sources (limited to 'audio/sysvad/KeywordDetectorAdapter') diff --git a/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.cpp b/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.cpp index 088c0751..c88b1ae0 100644 --- a/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.cpp +++ b/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.cpp @@ -23,12 +23,12 @@ public: } STDMETHODIMP KeywordDetectorContosoAdapter::GetCapabilities( - BOOL* SupportsUserModels, - KEYWORDID** KeywordIds, - ULONG* NumKeywords, - LANGID** LangIds, - ULONG* NumLanguages, - IMFMediaType* *ppMediaType) + _Out_ BOOL* SupportsUserModels, + _Outptr_ KEYWORDID** KeywordIds, + _Out_ ULONG* NumKeywords, + _Outptr_ LANGID** LangIds, + _Out_ ULONG* NumLanguages, + _Outptr_ IMFMediaType* *ppMediaType) { HRESULT hr; ComPtr spMFType; @@ -63,15 +63,20 @@ public: } } + if (*ppMediaType == nullptr) + { + return E_FAIL; + } + return hr; } STDMETHODIMP VerifyUserKeyword( - IStream* ModelData, - KEYWORDID KeywordId, - LANGID LangId, - LONG KeywordEndBytePos, - IMFMediaBuffer* UserRecording) + _In_ IStream* ModelData, + _In_ KEYWORDID KeywordId, + _In_ LANGID LangId, + _In_ LONG KeywordEndBytePos, + _In_ IMFMediaBuffer* UserRecording) { UNREFERENCED_PARAMETER(ModelData); UNREFERENCED_PARAMETER(KeywordId); @@ -83,11 +88,11 @@ public: } STDMETHODIMP ComputeAndAddUserModelData( - IStream* ModelData, - KEYWORDSELECTOR KeywordSelector, - LONG *KeywordEndBytePos, - IMFMediaBuffer **UserRecordings, - ULONG NumUserRecordings) + _Inout_ IStream* ModelData, + _In_ KEYWORDSELECTOR KeywordSelector, + _In_ LONG *KeywordEndBytePos, + _In_ IMFMediaBuffer **UserRecordings, + _In_ ULONG NumUserRecordings) { UNREFERENCED_PARAMETER(ModelData); UNREFERENCED_PARAMETER(KeywordSelector); @@ -99,10 +104,10 @@ public: } STDMETHODIMP BuildArmingPatternData( - IStream *ModelData, - KEYWORDSELECTOR *KeywordSelectors, - ULONG NumKeywordSelectors, - SOUNDDETECTOR_PATTERNHEADER **ppPatternData) + _In_ IStream *ModelData, + _In_ KEYWORDSELECTOR *KeywordSelectors, + _In_ ULONG NumKeywordSelectors, + _Outptr_ SOUNDDETECTOR_PATTERNHEADER **ppPatternData) { CONTOSO_KEYWORDCONFIGURATION *pPatternData = nullptr; @@ -135,15 +140,15 @@ public: } STDMETHODIMP ParseDetectionResultData( - IStream *ModelData, - SOUNDDETECTOR_PATTERNHEADER *Result, // ISSUE-2015/1/14-frankye should be const - KEYWORDID* KeywordId, - LANGID* LangId, - BOOL *pIsUserMatch, - ULONG64 *KeywordStartPerformanceCounterValue, - ULONG64 *KeywordEndPerformanceCounterValue) + _In_ IStream *ModelData, + _In_ SOUNDDETECTOR_PATTERNHEADER *Result, // ISSUE-2015/1/14-frankye should be const + _Out_ KEYWORDID* KeywordId, + _Out_ LANGID* LangId, + _Out_ BOOL *pIsUserMatch, + _Out_ ULONG64 *KeywordStartPerformanceCounterValue, + _Out_ ULONG64 *KeywordEndPerformanceCounterValue) { - const CONTOSO_KEYWORDDETECTIONRESULT *contosoResult; + // const CONTOSO_KEYWORDDETECTIONRESULT *contosoResult; UNREFERENCED_PARAMETER(ModelData); @@ -152,7 +157,7 @@ public: return E_INVALIDARG; } - contosoResult = (CONTOSO_KEYWORDDETECTIONRESULT*)Result; + // contosoResult = (CONTOSO_KEYWORDDETECTIONRESULT*)Result; // Do something with the result data to determine return parameters // PostProcessResult(contosoResult->ContosoDetectorResultData, contosoResult->KeywordStartTimestamp, contosoResult->KeywordStopTimestamp); @@ -169,3 +174,201 @@ public: }; CoCreatableClass(KeywordDetectorContosoAdapter); + +class EventDetectorContosoAdapter : public RuntimeClass, IEventDetectorOemAdapter> +{ +public: + EventDetectorContosoAdapter() + { + } + + STDMETHODIMP GetCapabilities( + _Out_ EVENTFEATURES* GlobalFeatureSupport, + _Outptr_ LANGID** LangIds, + _Out_ ULONG* NumLanguages, + _Out_ ULONG* NumUserRecordings, + _Outptr_ WAVEFORMATEX** ppFormat) + { + const WAVEFORMATEX waveFormat = { WAVE_FORMAT_PCM, 1, 16000, 32000, 2, 16, 0 }; + + *ppFormat = (WAVEFORMATEX *)CoTaskMemAlloc(sizeof(WAVEFORMATEX)); + if (*ppFormat == nullptr) + { + return E_OUTOFMEMORY; + } + + memcpy(*ppFormat, &waveFormat, sizeof(WAVEFORMATEX)); + + *GlobalFeatureSupport = EVENTFEATURES_NoEventFeatures; + + *LangIds = (LANGID *)CoTaskMemAlloc(sizeof(LANGID)); + + if (*LangIds == nullptr) + { + return E_OUTOFMEMORY; + } + + **LangIds = 0x0409; + *NumLanguages = 1; + *NumUserRecordings = 0; + + return S_OK; + } + + STDMETHODIMP GetCapabilitiesForLanguage( + _In_ LANGID LangId, + _Outptr_ DETECTIONEVENT** EventIds, + _Out_ ULONG* NumEvents) + { + if (LangId == 0x0409) + { + DETECTIONEVENT events[] = { { CONTOSO_KEYWORD1, EVENTFEATURES_NoEventFeatures, {0}, L"Contoso 1", TRUE }, + { CONTOSO_KEYWORD2, EVENTFEATURES_NoEventFeatures, {0}, L"Contoso 2", TRUE } }; + + *EventIds = (DETECTIONEVENT *)CoTaskMemAlloc(sizeof(events)); + if (*EventIds == nullptr) + { + return E_OUTOFMEMORY; + } + + memcpy(*EventIds, &events, sizeof(events)); + *NumEvents = 2; + } + else + { + return E_INVALIDARG; + } + + return S_OK; + } + + STDMETHODIMP VerifyUserEventData( + _In_ IStream* ModelData, + _In_ WAVEFORMATEX* UserRecording, + _In_ DETECTIONEVENTSELECTOR EventSelector, + _In_ LONG EventEndBytePos) + { + UNREFERENCED_PARAMETER(ModelData); + UNREFERENCED_PARAMETER(UserRecording); + UNREFERENCED_PARAMETER(EventSelector); + UNREFERENCED_PARAMETER(EventEndBytePos); + + return E_NOTIMPL; + } + + STDMETHODIMP ComputeAndAddUserModelData( + _Inout_ IStream* ModelData, + _In_ DETECTIONEVENTSELECTOR EventSelector, + _In_ LONG* EventEndBytePos, + _In_ WAVEFORMATEX** UserRecordings, + _In_ ULONG NumUserRecordings) + { + UNREFERENCED_PARAMETER(ModelData); + UNREFERENCED_PARAMETER(EventSelector); + UNREFERENCED_PARAMETER(EventEndBytePos); + UNREFERENCED_PARAMETER(UserRecordings); + UNREFERENCED_PARAMETER(NumUserRecordings); + + return E_NOTIMPL; + } + + STDMETHODIMP BuildArmingPatternData( + _In_ IStream* UserModelData, + _In_ DETECTIONEVENTSELECTOR* EventSelectors, + _In_ ULONG NumEventSelectors, + _Outptr_ SOUNDDETECTOR_PATTERNHEADER** ppPatternData) + { + CONTOSO_KEYWORDCONFIGURATION *pPatternData = nullptr; + + UNREFERENCED_PARAMETER(UserModelData); + + if (NumEventSelectors > 2) + { + return E_INVALIDARG; + } + + if ((EventSelectors[0].Event.EventId != CONTOSO_KEYWORD1 && EventSelectors[0].Event.EventId != CONTOSO_KEYWORD2) || + (EventSelectors[0].UserId != 0) || (EventSelectors[0].LangId != 0x0409)) + { + return E_INVALIDARG; + } + + pPatternData = (CONTOSO_KEYWORDCONFIGURATION*)CoTaskMemAlloc(sizeof(CONTOSO_KEYWORDCONFIGURATION)); + if (pPatternData == nullptr) + { + return E_OUTOFMEMORY; + } + + pPatternData->Header.Size = sizeof(*pPatternData); + pPatternData->Header.PatternType = CONTOSO_KEYWORDCONFIGURATION_IDENTIFIER2; + pPatternData->ContosoDetectorConfigurationData = 0x12345678; + + *ppPatternData = &pPatternData->Header; + pPatternData = nullptr; + + return S_OK; + } + + STDMETHODIMP ParseDetectionResultData( + _In_ IStream* UserModelData, + _In_ SOUNDDETECTOR_PATTERNHEADER* Result, + _Outptr_ SOUNDDETECTOR_PATTERNHEADER** AssistantContext, + _Out_ DETECTIONEVENTSELECTOR* EventSelector, + _Out_ EVENTACTION* EventAction, + _Out_ ULONG64* EventStartPerformanceCounterValue, + _Out_ ULONG64* EventEndPerformanceCounterValue, + _Outptr_ WCHAR** DebugOutput) + { + const CONTOSO_KEYWORDDETECTIONRESULT *contosoResult; + + UNREFERENCED_PARAMETER(UserModelData); + UNREFERENCED_PARAMETER(DebugOutput); + UNREFERENCED_PARAMETER(AssistantContext); + + if (Result->PatternType != CONTOSO_KEYWORDCONFIGURATION_IDENTIFIER2 || Result->Size < sizeof(CONTOSO_KEYWORDDETECTIONRESULT)) + { + return E_INVALIDARG; + } + + contosoResult = (CONTOSO_KEYWORDDETECTIONRESULT*)Result; + + if (CONTOSO_KEYWORD1 == contosoResult->EventId) + { + wcscpy_s(EventSelector->Event.DisplayName, L"Contoso 1"); + } + else if (CONTOSO_KEYWORD2 == contosoResult->EventId) + { + wcscpy_s(EventSelector->Event.DisplayName, L"Contoso 2"); + } + else + { + return E_INVALIDARG; + } + + // Fill in event action information for the actual detection, based on what has been armed. + EventSelector->Event.EventId = contosoResult->EventId; + EventSelector->Armed = TRUE; + EventSelector->UserId = 0; + EventSelector->LangId = 0x0409; + + EventAction->EventdActionType = EVENTACTIONTYPE_Accept; + EventAction->EventActionContextType = EVENTACTIONCONTEXTTYPE_None; + + // Retrieve the event start/stop times for the payload + *EventStartPerformanceCounterValue = contosoResult->KeywordStartTimestamp; + *EventEndPerformanceCounterValue = contosoResult->KeywordStopTimestamp; + + return S_OK; + } + + STDMETHODIMP_(void) ReportOSDetectionResult( + _In_ DETECTIONEVENTSELECTOR EventSelector, + _In_ EVENTACTION EventAction) + { + UNREFERENCED_PARAMETER(EventSelector); + UNREFERENCED_PARAMETER(EventAction); + } +}; + +CoCreatableClass(EventDetectorContosoAdapter); + diff --git a/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.idl b/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.idl index 47431ce7..80c6342d 100644 --- a/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.idl +++ b/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.idl @@ -2,6 +2,7 @@ import "oaidl.idl"; import "ocidl.idl"; import "KeywordDetectorOemAdapter.idl"; +import "EventDetectorOemAdapter.idl"; [uuid(9D3E6826-CB8E-4D86-8B14-89F0D7EFCD01), version(1.0)] library KeywordDetectorContosoAdapterLib @@ -13,4 +14,14 @@ library KeywordDetectorContosoAdapterLib { [default] interface IKeywordDetectorOemAdapter; } + + // The class's uuid (i.e. the COM CLSID) must match that of the pattern + // type GUID returned by the audio driver + // 0x207f3d0c, 0x5c79, 0x496f, 0xa9, 0x4c, 0xd3, 0xd2, 0x93, 0x4d, 0xbf, 0xa9 + [uuid(207F3D0C-5C79-496F-A94C-D3D2934DBFA9), version(1.0)] + coclass EventDetectorContosoAdapter + { + [default] interface IKeywordDetectorOemAdapter; + } }; + diff --git a/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.vcxproj b/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.vcxproj index 898fa184..d1675201 100644 --- a/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.vcxproj +++ b/audio/sysvad/KeywordDetectorAdapter/KeywordDetectorContosoAdapter.vcxproj @@ -1,10 +1,6 @@  - - Debug - ARM - Debug ARM64 @@ -13,10 +9,6 @@ Debug Win32 - - Release - ARM - Release ARM64 @@ -84,14 +76,6 @@ WindowsApplicationForDrivers10.0 DynamicLibrary - - Windows10 - False - Universal - - WindowsApplicationForDrivers10.0 - DynamicLibrary - Windows10 True @@ -100,14 +84,6 @@ WindowsApplicationForDrivers10.0 DynamicLibrary - - Windows10 - True - Universal - - WindowsApplicationForDrivers10.0 - DynamicLibrary - $(IntDir) @@ -127,15 +103,9 @@ - - - - - - KeywordDetectorContosoAdapter @@ -152,15 +122,9 @@ KeywordDetectorContosoAdapter - - KeywordDetectorContosoAdapter - KeywordDetectorContosoAdapter - - KeywordDetectorContosoAdapter - _DllMainCRTStartup@12 @@ -191,24 +155,12 @@ _DllMainCRTStartup - - - _DllMainCRTStartup@12 - _DllMainCRTStartup - - _DllMainCRTStartup@12 _DllMainCRTStartup - - - _DllMainCRTStartup@12 - _DllMainCRTStartup - - MultiThreaded @@ -329,30 +281,6 @@ KeywordDetectorContosoAdapter.def - - - MultiThreaded - MultiThreadedDebug - true - Level4 - %(PreprocessorDefinitions);_WINDLL;_USRDLL;UNICODE;_UNICODE - %(AdditionalIncludeDirectories);$(DDK_INC_PATH);..\inc;..\ - - - - - %(PreprocessorDefinitions);_WINDLL;_USRDLL;UNICODE;_UNICODE - %(AdditionalIncludeDirectories);$(DDK_INC_PATH);..\inc;..\ - - - %(PreprocessorDefinitions);_WINDLL;_USRDLL;UNICODE;_UNICODE - %(AdditionalIncludeDirectories);$(DDK_INC_PATH);..\inc;..\ - - - %(AdditionalDependencies);Kernel32.lib;ole32.lib;oleaut32.lib;advapi32.lib;user32.lib;uuid.lib;mfplat.lib;runtimeobject.lib - KeywordDetectorContosoAdapter.def - - MultiThreaded @@ -377,30 +305,6 @@ KeywordDetectorContosoAdapter.def - - - MultiThreaded - MultiThreadedDebug - true - Level4 - %(PreprocessorDefinitions);_WINDLL;_USRDLL;UNICODE;_UNICODE - %(AdditionalIncludeDirectories);$(DDK_INC_PATH);..\inc;..\ - - - - - %(PreprocessorDefinitions);_WINDLL;_USRDLL;UNICODE;_UNICODE - %(AdditionalIncludeDirectories);$(DDK_INC_PATH);..\inc;..\ - - - %(PreprocessorDefinitions);_WINDLL;_USRDLL;UNICODE;_UNICODE - %(AdditionalIncludeDirectories);$(DDK_INC_PATH);..\inc;..\ - - - %(AdditionalDependencies);Kernel32.lib;ole32.lib;oleaut32.lib;advapi32.lib;user32.lib;uuid.lib;mfplat.lib;runtimeobject.lib - KeywordDetectorContosoAdapter.def - - diff --git a/audio/sysvad/KeywordDetectorAdapter/sources b/audio/sysvad/KeywordDetectorAdapter/sources deleted file mode 100644 index 8b17ac8b..00000000 --- a/audio/sysvad/KeywordDetectorAdapter/sources +++ /dev/null @@ -1,53 +0,0 @@ -TARGETTYPE=DYNLINK -TARGETNAME=KeywordDetectorContosoAdapter - -DLLENTRY=_DllMainCRTStartup -DLLDEF=KeywordDetectorContosoAdapter.def -#USE_ATL=1 - - -USE_LIBCMT=1 - -MSC_WARNING_LEVEL=-W4 \ - -WX - -C_DEFINES=$(C_DEFINES) \ - -D_WINDLL \ - -D_USRDLL \ - -DUNICODE \ - -D_UNICODE - -# -# Indicate to the WDK that this sample only supports Win10[+] -# -MINIMUM_NT_TARGET_VERSION=$(_NT_TARGET_VERSION_WINTHRESHOLD) - -# Indicate that this DLL must be included in the driver package -DDK_NO_PACKAGE_PROJECT=0 -DDK_INCLUDE_PACKAGE_PROJECT=1 - -INCLUDES= \ - $(DDK_INC_PATH); \ - ..\inc;..\; \ - -SOURCES=KeywordDetectorContosoAdapter.idl \ - KeywordDetectorContosoAdapter.rc \ - dllmain.cpp \ - KeywordDetectorContosoAdapter.cpp \ - stdafx.cpp \ - - -TARGETLIBS= \ - $(SDK_LIB_PATH)\onecore_downlevel.lib \ - $(SDK_LIB_PATH)\onecore_downlevel.lib \ - $(SDK_LIB_PATH)\oleaut32.lib \ - \ - $(ONECORE_PRIV_SDK_LIB_PATH)\OneCore_Forwarder_user32.lib \ - $(INTERNAL_SDK_LIB_PATH)\onecoreuapuuid.lib \ - $(SDK_LIB_PATH)\mfplat.lib \ - $(SDK_LIB_PATH)\runtimeobject.lib \ - - - -MUI_VERIFY_NO_LOC_RESOURCE=1 - -- cgit v1.3.1