Skip to content

Commit

Permalink
Stub interface for DirectSoundPrivate
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Apr 20, 2023
1 parent c1fedb5 commit f0a55a8
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ add_library(dsound SHARED
src/logging.h
src/primarybuffer.cpp
src/primarybuffer.h
src/propset.cpp
src/propset.h
src/vmanager.h
version.rc
${DEF_FILE}
Expand Down
8 changes: 8 additions & 0 deletions src/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "dsoundoal.h"
#include "guidprinter.h"
#include "logging.h"
#include "propset.h"


namespace {
Expand Down Expand Up @@ -33,11 +34,18 @@ HRESULT CreateDSCapture(REFIID riid, void **ppvObject)
return dsobj->QueryInterface(riid, ppvObject);
}

HRESULT CreateDSPrivatePropSet(REFIID riid, void **ppvObject)
{
auto dsobj = DSPrivatePropertySet::Create();
return dsobj->QueryInterface(riid, ppvObject);
}

Factory sFactories[]{
{CLSID_DirectSound8, CreateDS8},
{CLSID_DirectSound, CreateDS},
{CLSID_DirectSoundCapture8, CreateDSCapture8},
{CLSID_DirectSoundCapture, CreateDSCapture},
{CLSID_DirectSoundPrivate, CreateDSPrivatePropSet},
};

} // namespace
Expand Down
3 changes: 3 additions & 0 deletions src/guidprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <objbase.h>

#include "eax.h"
#include "propset.h"
#include "vmanager.h"


Expand Down Expand Up @@ -73,6 +74,7 @@ class GuidPrinter {
CHECKID(EAXPROPERTYID_EAX40_FXSlot3)
CHECKID(EAXPROPERTYID_EAX40_Source)
CHECKID(DSPROPSETID_VoiceManager)
CHECKID(DSPROPSETID_DirectSoundDevice)
if(mIdStr) return;

std::snprintf(mMsg, std::size(mMsg), "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
Expand Down Expand Up @@ -119,6 +121,7 @@ class GuidPrinter {
CHECKID(CLSID_DirectSoundCapture)
CHECKID(CLSID_DirectSoundCapture8)
CHECKID(CLSID_DirectSoundFullDuplex)
CHECKID(CLSID_DirectSoundPrivate)
if(mIdStr) return;

std::snprintf(mMsg, std::size(mMsg), "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
Expand Down
116 changes: 116 additions & 0 deletions src/propset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "propset.h"

#include <vfwmsgs.h>

#include "guidprinter.h"
#include "logging.h"


namespace {

using voidp = void*;

} // namespace


#define CLASS_PREFIX "DSPrivatePropertySet::"
DSPrivatePropertySet::DSPrivatePropertySet() = default;
DSPrivatePropertySet::~DSPrivatePropertySet() = default;

ComPtr<DSPrivatePropertySet> DSPrivatePropertySet::Create()
{
return ComPtr<DSPrivatePropertySet>{new DSPrivatePropertySet{}};
}


#define PREFIX CLASS_PREFIX "QueryInterface "
HRESULT STDMETHODCALLTYPE DSPrivatePropertySet::QueryInterface(REFIID riid, void **ppvObject) noexcept
{
DEBUG(PREFIX "(%p)->(%s, %p)\n", voidp{this}, IidPrinter{riid}.c_str(), voidp{ppvObject});

*ppvObject = nullptr;
if(riid == IID_IUnknown)
{
AddRef();
*ppvObject = as<IUnknown*>();
return S_OK;
}
if(riid == IID_IKsPropertySet)
{
AddRef();
*ppvObject = as<IKsPropertySet*>();
return S_OK;
}

FIXME(PREFIX "Unhandled GUID: %s\n", IidPrinter{riid}.c_str());
return E_NOINTERFACE;
}
#undef PREFIX

ULONG STDMETHODCALLTYPE DSPrivatePropertySet::AddRef() noexcept
{
const auto ret = mRef.fetch_add(1u, std::memory_order_relaxed) + 1;
DEBUG(CLASS_PREFIX "AddRef (%p) ref %lu\n", voidp{this}, ret);
return ret;
}

ULONG STDMETHODCALLTYPE DSPrivatePropertySet::Release() noexcept
{
const auto ret = mRef.fetch_sub(1u, std::memory_order_relaxed) - 1;
DEBUG(CLASS_PREFIX "Release (%p) ref %lu\n", voidp{this}, ret);
if(ret == 0) UNLIKELY delete this;
return ret;
}


#define PREFIX CLASS_PREFIX "Get "
HRESULT STDMETHODCALLTYPE DSPrivatePropertySet::Get(REFGUID guidPropSet, ULONG dwPropID,
void *pInstanceData, ULONG cbInstanceData, void *pPropData, ULONG cbPropData,
ULONG *pcbReturned) noexcept
{
DEBUG(PREFIX "(%p)->(%s, 0x%lx, %p, %lu, %p, %lu, %p)\n", voidp{this},
PropidPrinter{guidPropSet}.c_str(), dwPropID, pInstanceData, cbInstanceData, pPropData,
cbPropData, voidp{pcbReturned});

if(!pcbReturned)
return E_POINTER;
*pcbReturned = 0;

if(cbPropData > 0 && !pPropData)
{
WARN(PREFIX "pPropData is null with cbPropData > 0\n");
return E_POINTER;
}

FIXME(PREFIX "Unhandled propset: %s (propid: %lu)\n", PropidPrinter{guidPropSet}.c_str(),
dwPropID);
return E_PROP_ID_UNSUPPORTED;
}
#undef PREFIX

#define PREFIX CLASS_PREFIX "Set "
HRESULT STDMETHODCALLTYPE DSPrivatePropertySet::Set(REFGUID guidPropSet, ULONG dwPropID,
void *pInstanceData, ULONG cbInstanceData, void *pPropData, ULONG cbPropData) noexcept
{
DEBUG(PREFIX "(%p)->(%s, 0x%lx, %p, %lu, %p, %lu)\n", voidp{this},
PropidPrinter{guidPropSet}.c_str(), dwPropID, pInstanceData, cbInstanceData, pPropData,
cbPropData);
return E_PROP_ID_UNSUPPORTED;
}
#undef PREFIX

#define PREFIX CLASS_PREFIX "QuerySupport "
HRESULT STDMETHODCALLTYPE DSPrivatePropertySet::QuerySupport(REFGUID guidPropSet, ULONG dwPropID,
ULONG *pTypeSupport) noexcept
{
FIXME(PREFIX "(%p)->(%s, 0x%lx, %p)\n", voidp{this}, PropidPrinter{guidPropSet}.c_str(),
dwPropID, voidp{pTypeSupport});

if(!pTypeSupport)
return E_POINTER;
*pTypeSupport = 0;

return E_PROP_ID_UNSUPPORTED;
}
#undef PREFIX
#undef CLASS_PREFIX
44 changes: 44 additions & 0 deletions src/propset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef PROPSET_H
#define PROPSET_H

#include <atomic>

#include <dsound.h>

#include "comptr.h"


inline constexpr GUID CLSID_DirectSoundPrivate{
0x11ab3ec0,
0x25ec,0x11d1,
{0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca}
};

inline constexpr GUID DSPROPSETID_DirectSoundDevice{
0x84624f82,
0x25ec,0x11d1,
{0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca}
};


class DSPrivatePropertySet final : IKsPropertySet {
std::atomic<ULONG> mRef{1u};

public:
DSPrivatePropertySet();
~DSPrivatePropertySet();

HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) noexcept override;
ULONG STDMETHODCALLTYPE AddRef() noexcept override;
ULONG STDMETHODCALLTYPE Release() noexcept override;
HRESULT STDMETHODCALLTYPE Get(REFGUID guidPropSet, ULONG dwPropID, void *pInstanceData, ULONG cbInstanceData, void *pPropData, ULONG cbPropData, ULONG *pcbReturned) noexcept override;
HRESULT STDMETHODCALLTYPE Set(REFGUID guidPropSet, ULONG dwPropID, void *pInstanceData, ULONG cbInstanceData, void *pPropData, ULONG cbPropData) noexcept override;
HRESULT STDMETHODCALLTYPE QuerySupport(REFGUID guidPropSet, ULONG dwPropID, ULONG *pTypeSupport) noexcept override;

template<typename T>
T as() noexcept { return static_cast<T>(this); }

static ComPtr<DSPrivatePropertySet> Create();
};

#endif // PROPSET_H

0 comments on commit f0a55a8

Please sign in to comment.