Commit 70826e26 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

SAPI: fix leaks, cosmetics and simplify

parent a7eb0f0a
...@@ -70,7 +70,7 @@ struct filter_sys_t ...@@ -70,7 +70,7 @@ struct filter_sys_t
/* MTA functions */ /* MTA functions */
static int TryEnterMTA(vlc_object_t *obj) static int TryEnterMTA(vlc_object_t *obj)
{ {
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (unlikely(FAILED(hr))) if (unlikely(FAILED(hr)))
{ {
msg_Err (obj, "cannot initialize COM (error 0x%lx)", hr); msg_Err (obj, "cannot initialize COM (error 0x%lx)", hr);
...@@ -82,7 +82,7 @@ static int TryEnterMTA(vlc_object_t *obj) ...@@ -82,7 +82,7 @@ static int TryEnterMTA(vlc_object_t *obj)
static void EnterMTA(void) static void EnterMTA(void)
{ {
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (unlikely(FAILED(hr))) if (unlikely(FAILED(hr)))
abort(); abort();
} }
...@@ -105,16 +105,16 @@ static int Create (vlc_object_t *p_this) ...@@ -105,16 +105,16 @@ static int Create (vlc_object_t *p_this)
if (!p_sys) if (!p_sys)
goto error; goto error;
p_sys->cpVoice = nullptr; p_sys->cpVoice = NULL;
p_sys->lastString = nullptr; p_sys->lastString = NULL;
hr = CoCreateInstance(CLSID_SpVoice, nullptr, CLSCTX_INPROC_SERVER, IID_ISpVoice, (void**) &p_sys->cpVoice); hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_INPROC_SERVER, IID_ISpVoice, (void**) &p_sys->cpVoice);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
ISpObjectToken* cpVoiceToken = nullptr; ISpObjectToken* cpVoiceToken = NULL;
IEnumSpObjectTokens* cpEnum = nullptr; IEnumSpObjectTokens* cpEnum = NULL;
ULONG ulCount = 0; ULONG ulCount = 0;
hr = SpEnumTokens(SPCAT_VOICES, nullptr, nullptr, &cpEnum); hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
// Get the number of voices. // Get the number of voices.
...@@ -135,7 +135,7 @@ static int Create (vlc_object_t *p_this) ...@@ -135,7 +135,7 @@ static int Create (vlc_object_t *p_this)
msg_Err(p_this, "Failed to set voice %d", voiceIndex); msg_Err(p_this, "Failed to set voice %d", voiceIndex);
} }
cpVoiceToken->Release(); cpVoiceToken->Release();
cpVoiceToken = nullptr; cpVoiceToken = NULL;
} }
} }
else else
...@@ -143,10 +143,9 @@ static int Create (vlc_object_t *p_this) ...@@ -143,10 +143,9 @@ static int Create (vlc_object_t *p_this)
} }
} }
cpEnum->Release(); cpEnum->Release();
cpEnum = nullptr;
/* Set Output */ /* Set Output */
hr = p_sys->cpVoice->SetOutput(nullptr, TRUE); hr = p_sys->cpVoice->SetOutput(NULL, TRUE);
} }
} }
else else
...@@ -172,63 +171,53 @@ static void Destroy(vlc_object_t *p_this) ...@@ -172,63 +171,53 @@ static void Destroy(vlc_object_t *p_this)
filter_t *p_filter = (filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
if (p_sys->cpVoice) { if (p_sys->cpVoice)
p_sys->cpVoice->Release(); p_sys->cpVoice->Release();
p_sys->cpVoice = nullptr;
}
if (p_sys->lastString) {
free(p_sys->lastString);
p_sys->lastString = nullptr;
}
free(p_sys->lastString);
free(p_sys); free(p_sys);
} }
static int RenderText(filter_t *p_filter, static int RenderText(filter_t *p_filter,
subpicture_region_t *p_region_out, subpicture_region_t *,
subpicture_region_t *p_region_in, subpicture_region_t *p_region_in,
const vlc_fourcc_t *p_chroma_list) const vlc_fourcc_t *)
{ {
VLC_UNUSED(p_region_out);
VLC_UNUSED(p_chroma_list);
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
text_segment_t *p_segment = p_region_in->p_text; text_segment_t *p_segment = p_region_in->p_text;
if (!p_segment) if (!p_segment)
return VLC_EGENERIC; return VLC_EGENERIC;
for (const text_segment_t *s = p_segment; s != nullptr; s = s->p_next ) { for (const text_segment_t *s = p_segment; s != NULL; s = s->p_next ) {
if (!s->psz_text ) if (!s->psz_text)
continue; continue;
if (strlen(s->psz_text) == 0) if (strlen(s->psz_text) == 0)
continue; continue;
try { if (p_sys->lastString && !strcmp(p_sys->lastString, s->psz_text))
if (p_sys->lastString && !strcmp(p_sys->lastString, s->psz_text)) continue;
continue;
if (!strcmp(s->psz_text, "\n"))
continue;
p_sys->lastString = strdup(s->psz_text); if (!strcmp(s->psz_text, "\n"))
if (p_sys->lastString) { continue;
msg_Dbg(p_filter, "Speaking '%s'", s->psz_text);
EnterMTA(); /* */
wchar_t* wideText = ToWide(s->psz_text); free(p_sys->lastString);
HRESULT hr = p_sys->cpVoice->Speak(wideText, SPF_ASYNC, nullptr); p_sys->lastString = strdup(s->psz_text);
free(wideText);
if (!SUCCEEDED(hr)) { /* */
msg_Err(p_filter, "Speak() error"); if (p_sys->lastString) {
} msg_Dbg(p_filter, "Speaking '%s'", s->psz_text);
LeaveMTA();
EnterMTA();
wchar_t* wideText = ToWide(s->psz_text);
HRESULT hr = p_sys->cpVoice->Speak(wideText, SPF_ASYNC, NULL);
free(wideText);
if (!SUCCEEDED(hr)) {
msg_Err(p_filter, "Speak() error");
} }
} LeaveMTA();
catch (...) {
msg_Err(p_filter, "Caught an exception!");
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment