1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
// KeywordDetectorContosoAdapter.cpp : Defines the exported functions for the DLL application.
//
// ISSUE-2015/1/14-frankye review all error codes
#include "stdafx.h"
#include <strsafe.h>
#include <mfapi.h>
#include <initguid.h>
#include "KeywordDetectorContosoAdapter.h"
#include "ContosoKeywordDetector.h"
#include <wrl.h>
using namespace Microsoft::WRL;
class KeywordDetectorContosoAdapter : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IKeywordDetectorOemAdapter>
{
public:
KeywordDetectorContosoAdapter()
{
}
STDMETHODIMP KeywordDetectorContosoAdapter::GetCapabilities(
BOOL* SupportsUserModels,
KEYWORDID** KeywordIds,
ULONG* NumKeywords,
LANGID** LangIds,
ULONG* NumLanguages,
IMFMediaType* *ppMediaType)
{
HRESULT hr;
ComPtr<IMFMediaType> spMFType;
const WAVEFORMATEX waveFormat = { WAVE_FORMAT_PCM, 1, 16000, 32000, 2, 16, 0 };
*SupportsUserModels = FALSE;
*KeywordIds = (KEYWORDID *)CoTaskMemAlloc(sizeof(KEYWORDID));
if (*KeywordIds == nullptr)
{
return E_OUTOFMEMORY;
}
**KeywordIds = KwVoiceAssistant;
*NumKeywords = 1;
*LangIds = (LANGID *)CoTaskMemAlloc(sizeof(LANGID));
if (*LangIds == nullptr)
{
CoTaskMemFree(*KeywordIds);
return E_OUTOFMEMORY;
}
**LangIds = 0x409;
*NumLanguages = 1;
hr = MFCreateMediaType(spMFType.GetAddressOf());
if (SUCCEEDED(hr))
{
hr = MFInitMediaTypeFromWaveFormatEx(spMFType.Get(), &waveFormat, sizeof(waveFormat));
if (SUCCEEDED(hr))
{
spMFType.CopyTo(ppMediaType);
hr = S_OK;
}
}
return hr;
}
STDMETHODIMP VerifyUserKeyword(
IStream* ModelData,
KEYWORDID KeywordId,
LANGID LangId,
LONG KeywordEndBytePos,
IMFMediaBuffer* UserRecording)
{
UNREFERENCED_PARAMETER(ModelData);
UNREFERENCED_PARAMETER(KeywordId);
UNREFERENCED_PARAMETER(LangId);
UNREFERENCED_PARAMETER(KeywordEndBytePos);
UNREFERENCED_PARAMETER(UserRecording);
return E_NOTIMPL;
}
STDMETHODIMP ComputeAndAddUserModelData(
IStream* ModelData,
KEYWORDSELECTOR KeywordSelector,
LONG *KeywordEndBytePos,
IMFMediaBuffer **UserRecordings,
ULONG NumUserRecordings)
{
UNREFERENCED_PARAMETER(ModelData);
UNREFERENCED_PARAMETER(KeywordSelector);
UNREFERENCED_PARAMETER(KeywordEndBytePos);
UNREFERENCED_PARAMETER(UserRecordings);
UNREFERENCED_PARAMETER(NumUserRecordings);
return E_NOTIMPL;
}
STDMETHODIMP BuildArmingPatternData(
IStream *ModelData,
KEYWORDSELECTOR *KeywordSelectors,
ULONG NumKeywordSelectors,
SOUNDDETECTOR_PATTERNHEADER **ppPatternData)
{
CONTOSO_KEYWORDCONFIGURATION *pPatternData = nullptr;
UNREFERENCED_PARAMETER(ModelData);
if (NumKeywordSelectors > 1)
{
return E_INVALIDARG;
}
if ((KeywordSelectors[0].KeywordId != KwVoiceAssistant) ||
(KeywordSelectors[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_IDENTIFIER;
pPatternData->ContosoDetectorConfigurationData = 0x12345678;
*ppPatternData = &pPatternData->Header;
pPatternData = nullptr;
return S_OK;
}
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)
{
const CONTOSO_KEYWORDDETECTIONRESULT *contosoResult;
UNREFERENCED_PARAMETER(ModelData);
if (Result->PatternType != CONTOSO_KEYWORDCONFIGURATION_IDENTIFIER || Result->Size < sizeof(CONTOSO_KEYWORDDETECTIONRESULT))
{
return E_INVALIDARG;
}
contosoResult = (CONTOSO_KEYWORDDETECTIONRESULT*)Result;
// Do something with the result data to determine return parameters
// PostProcessResult(contosoResult->ContosoDetectorResultData, contosoResult->KeywordStartTimestamp, contosoResult->KeywordStopTimestamp);
*KeywordId = KwVoiceAssistant;
*LangId = 0x0409;
*pIsUserMatch = FALSE;
*KeywordStartPerformanceCounterValue = 0;
*KeywordEndPerformanceCounterValue = 0;
return S_OK;
}
};
CoCreatableClass(KeywordDetectorContosoAdapter);
|