include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / msttsengine / tts.c
blobf895b35e21664be7578d4e7ca6124675661145e6
1 /*
2 * MSTTSEngine SAPI engine implementation.
4 * Copyright 2023 Shaun Ren for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "objbase.h"
29 #include "sapiddk.h"
30 #include "sperror.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msttsengine);
36 struct ttsengine
38 ISpTTSEngine ISpTTSEngine_iface;
39 ISpObjectWithToken ISpObjectWithToken_iface;
40 LONG ref;
42 ISpObjectToken *token;
45 static inline struct ttsengine *impl_from_ISpTTSEngine(ISpTTSEngine *iface)
47 return CONTAINING_RECORD(iface, struct ttsengine, ISpTTSEngine_iface);
50 static inline struct ttsengine *impl_from_ISpObjectWithToken(ISpObjectWithToken *iface)
52 return CONTAINING_RECORD(iface, struct ttsengine, ISpObjectWithToken_iface);
55 static HRESULT WINAPI ttsengine_QueryInterface(ISpTTSEngine *iface, REFIID iid, void **obj)
57 struct ttsengine *This = impl_from_ISpTTSEngine(iface);
59 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(iid), obj);
61 if (IsEqualIID(iid, &IID_IUnknown) ||
62 IsEqualIID(iid, &IID_ISpTTSEngine))
64 *obj = &This->ISpTTSEngine_iface;
66 else if (IsEqualIID(iid, &IID_ISpObjectWithToken))
67 *obj = &This->ISpObjectWithToken_iface;
68 else
70 *obj = NULL;
71 return E_NOINTERFACE;
74 IUnknown_AddRef((IUnknown *)*obj);
75 return S_OK;
78 static ULONG WINAPI ttsengine_AddRef(ISpTTSEngine *iface)
80 struct ttsengine *This = impl_from_ISpTTSEngine(iface);
81 ULONG ref = InterlockedIncrement(&This->ref);
83 TRACE("(%p) ref=%lu\n", This, ref);
85 return ref;
88 static ULONG WINAPI ttsengine_Release(ISpTTSEngine *iface)
90 struct ttsengine *This = impl_from_ISpTTSEngine(iface);
91 ULONG ref = InterlockedDecrement(&This->ref);
93 TRACE("(%p) ref=%lu\n", This, ref);
95 if (!ref)
97 if (This->token) ISpObjectToken_Release(This->token);
98 free(This);
101 return ref;
104 static HRESULT WINAPI ttsengine_Speak(ISpTTSEngine *iface, DWORD flags, REFGUID fmtid,
105 const WAVEFORMATEX *wfx, const SPVTEXTFRAG *frag_list,
106 ISpTTSEngineSite *site)
108 FIXME("(%p, %#lx, %s, %p, %p, %p): stub.\n", iface, flags, debugstr_guid(fmtid), wfx, frag_list, site);
110 return E_NOTIMPL;
113 static HRESULT WINAPI ttsengine_GetOutputFormat(ISpTTSEngine *iface, const GUID *fmtid,
114 const WAVEFORMATEX *wfx, GUID *out_fmtid,
115 WAVEFORMATEX **out_wfx)
117 FIXME("(%p, %s, %p, %p, %p): stub.\n", iface, debugstr_guid(fmtid), wfx, out_fmtid, out_wfx);
119 return E_NOTIMPL;
122 static ISpTTSEngineVtbl ttsengine_vtbl =
124 ttsengine_QueryInterface,
125 ttsengine_AddRef,
126 ttsengine_Release,
127 ttsengine_Speak,
128 ttsengine_GetOutputFormat,
131 static HRESULT WINAPI objwithtoken_QueryInterface(ISpObjectWithToken *iface, REFIID iid, void **obj)
133 struct ttsengine *This = impl_from_ISpObjectWithToken(iface);
135 TRACE("(%p, %s, %p).\n", iface, debugstr_guid(iid), obj);
137 return ISpTTSEngine_QueryInterface(&This->ISpTTSEngine_iface, iid, obj);
140 static ULONG WINAPI objwithtoken_AddRef(ISpObjectWithToken *iface)
142 struct ttsengine *This = impl_from_ISpObjectWithToken(iface);
144 TRACE("(%p).\n", iface);
146 return ISpTTSEngine_AddRef(&This->ISpTTSEngine_iface);
149 static ULONG WINAPI objwithtoken_Release(ISpObjectWithToken *iface)
151 struct ttsengine *This = impl_from_ISpObjectWithToken(iface);
153 TRACE("(%p).\n", iface);
155 return ISpTTSEngine_Release(&This->ISpTTSEngine_iface);
158 static HRESULT WINAPI objwithtoken_SetObjectToken(ISpObjectWithToken *iface, ISpObjectToken *token)
160 struct ttsengine *This = impl_from_ISpObjectWithToken(iface);
162 FIXME("(%p, %p): semi-stub.\n", iface, token);
164 if (!token)
165 return E_INVALIDARG;
166 if (This->token)
167 return SPERR_ALREADY_INITIALIZED;
169 ISpObjectToken_AddRef(token);
170 This->token = token;
171 return S_OK;
174 static HRESULT WINAPI objwithtoken_GetObjectToken(ISpObjectWithToken *iface, ISpObjectToken **token)
176 struct ttsengine *This = impl_from_ISpObjectWithToken(iface);
178 TRACE("(%p, %p).\n", iface, token);
180 if (!token)
181 return E_POINTER;
183 *token = This->token;
184 if (*token)
186 ISpObjectToken_AddRef(*token);
187 return S_OK;
189 else
190 return S_FALSE;
193 static const ISpObjectWithTokenVtbl objwithtoken_vtbl =
195 objwithtoken_QueryInterface,
196 objwithtoken_AddRef,
197 objwithtoken_Release,
198 objwithtoken_SetObjectToken,
199 objwithtoken_GetObjectToken
202 HRESULT ttsengine_create(REFIID iid, void **obj)
204 struct ttsengine *This;
205 HRESULT hr;
207 if (!(This = malloc(sizeof(*This))))
208 return E_OUTOFMEMORY;
210 This->ISpTTSEngine_iface.lpVtbl = &ttsengine_vtbl;
211 This->ISpObjectWithToken_iface.lpVtbl = &objwithtoken_vtbl;
212 This->ref = 1;
214 This->token = NULL;
216 hr = ISpTTSEngine_QueryInterface(&This->ISpTTSEngine_iface, iid, obj);
217 ISpTTSEngine_Release(&This->ISpTTSEngine_iface);
218 return hr;