Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8264737: JavaFX media stream stops playing after reconnecting via Remote Desktop #479

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,124 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

#ifdef GSTREAMER_LITE

#include <stdio.h>
#include "gstdirectsoundnotify.h"

void* InitNotificator(GSTDSNotfierCallback pCallback, void *pData) {
GSTDirectSoundNotify *pNotify = new GSTDirectSoundNotify();
if (pNotify != NULL) {
if (pNotify->Init(pCallback, pData)) {
return (void*)pNotify;
} else {
pNotify->Release();
}
}

return NULL;
}

void ReleaseNotificator(void *pObject) {
GSTDirectSoundNotify *pNotify = (GSTDirectSoundNotify*)pObject;
if (pNotify) {
pNotify->Dispose();
pNotify->Release();
}
}

bool GSTDirectSoundNotify::Init(GSTDSNotfierCallback pCallback, void *pData) {
m_pCallback = pCallback;
m_pData = pData;

HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&m_pEnumerator));
if (SUCCEEDED(hr)) {
hr = m_pEnumerator->RegisterEndpointNotificationCallback(this);
if (SUCCEEDED(hr)) {
return true;
}
}

return false;
}

void GSTDirectSoundNotify::Dispose() {
if (m_pEnumerator) {
m_pEnumerator->UnregisterEndpointNotificationCallback(this);
m_pEnumerator->Release();
}
}

GSTDirectSoundNotify::GSTDirectSoundNotify() {
m_cRef = 1;
m_pEnumerator = NULL;
m_pCallback = NULL;
m_pData = NULL;
}

HRESULT GSTDirectSoundNotify::OnDefaultDeviceChanged(EDataFlow flow,
ERole role,
LPCWSTR pwstrDefaultDeviceId) {
if (flow == eRender && pwstrDefaultDeviceId != NULL) {
if (m_pCallback && m_pData) {
m_pCallback(m_pData);
}
}

// return value of this callback is ignored
return S_OK;
}

// IUnknown methods
HRESULT GSTDirectSoundNotify::QueryInterface(REFIID iid, void** ppUnk) {
if ((iid == __uuidof(IUnknown)) ||
(iid == __uuidof(IMMNotificationClient))) {
*ppUnk = static_cast<IMMNotificationClient*>(this);
} else {
*ppUnk = NULL;
return E_NOINTERFACE;
}

AddRef();

return S_OK;
}

ULONG GSTDirectSoundNotify::AddRef() {
return InterlockedIncrement(&m_cRef);
}

ULONG GSTDirectSoundNotify::Release() {
long lRef = InterlockedDecrement(&m_cRef);
if (lRef == 0) {
delete this;
}
return lRef;
}

#endif // GSTREAMER_LITE
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

#ifdef GSTREAMER_LITE

#ifndef GSTDIRECTSOUNDNOTIFY_H
#define GSTDIRECTSOUNDNOTIFY_H

#include <mmdeviceapi.h>

typedef void (*GSTDSNotfierCallback)(void*);

#ifdef __cplusplus
extern "C" {
#endif
void* InitNotificator(GSTDSNotfierCallback pCallback, void *pData);
void ReleaseNotificator(void *pObject);
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
class GSTDirectSoundNotify : IMMNotificationClient
{
public:
GSTDirectSoundNotify();

bool Init(GSTDSNotfierCallback pCallback, void *pData);
void Dispose();

// IUnknown
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP_(ULONG) Release();

private:
// IMMNotificationClient
IFACEMETHODIMP OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) { return S_OK; }
IFACEMETHODIMP OnDeviceAdded(LPCWSTR pwstrDeviceId) { return S_OK; }
IFACEMETHODIMP OnDeviceRemoved(LPCWSTR pwstrDeviceId) { return S_OK; }
IFACEMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId);
IFACEMETHODIMP OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) { return S_OK; }

long m_cRef;
IMMDeviceEnumerator* m_pEnumerator;
GSTDSNotfierCallback m_pCallback;
void *m_pData;

// IUnknown
IFACEMETHODIMP QueryInterface(const IID& iid, void** ppUnk);
};
#endif // __cplusplus

#endif // GSTDIRECTSOUNDNOTIFY_H
#endif // GSTREAMER_LITE