Skip to content

Commit

Permalink
add matthew van eerde samples
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed Aug 17, 2010
1 parent 98eb544 commit f4ee42e
Show file tree
Hide file tree
Showing 101 changed files with 6,700 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README
@@ -1,4 +1,4 @@
This repository has an actual working directshow audio input source filter.
This repository has an actual working directshow audio input source filter (source is in "acam", solution is "virtual audio output replay.sln".

Simplified examples like this were pretty hard to find online, and not even the MSDN SDK examples seemed to have any audio source examples.

Expand Down
Binary file removed Release/acam.dll
Binary file not shown.
Binary file added matthew_van_eerde/ac3.wav
Binary file not shown.
Binary file added matthew_van_eerde/acmenum/amd64/acmenum.exe
Binary file not shown.
71 changes: 71 additions & 0 deletions matthew_van_eerde/acmenum/source/acmenum.cpp
@@ -0,0 +1,71 @@
// acmenum.cpp

#include <windows.h>
#include <mmreg.h>
#include <mmiscapi.h>
#include <msacm.h>
#include <stdio.h>

#include "acmenum.h"
#include "details.h"
#include "list.h"
#include "log.h"

BOOL myAcmDriverEnumCallback(
HACMDRIVERID hadid,
DWORD_PTR dwInstance,
DWORD fdwSupport
);

MMRESULT EnumerateACMDrivers() {
AcmDriverList list;

MMRESULT mmr = acmDriverEnum(
myAcmDriverEnumCallback,
reinterpret_cast<DWORD_PTR>(&list), // app-specific pointer
ACM_DRIVERENUMF_DISABLED // include disabled drivers
);

if (MMSYSERR_NOERROR != mmr) {
ERR(L"acmDriverEnum failed: mmr = 0x%08x", mmr);
return mmr;
}

LOG(L"ACM Drivers found: %u", list.nCount);
for (UINT32 i = 0; i < list.nCount; i++) {
ACMDRIVERDETAILS details = {0};
details.cbStruct = sizeof(details);

mmr = acmDriverDetails(list.pDrivers[i].id, &details, 0);
if (MMSYSERR_NOERROR != mmr) {
ERR(L"acmDriverDetails failed: mmr = 0x%08x", mmr);
return mmr;
}

if (list.pDrivers[i].fdwSupport != details.fdwSupport) {
ERR(
L"Different fdwSupport values from "
L"acmDriverEnum Callback (0x%08x) and acmDriverDetails (0x%08x)",
list.pDrivers[i].fdwSupport,
details.fdwSupport
);
}

LogDetails(details);

LOG(L""); // blank line
}

return MMSYSERR_NOERROR;
}

BOOL myAcmDriverEnumCallback(
HACMDRIVERID hadid,
DWORD_PTR dwInstance,
DWORD fdwSupport
) {
AcmDriverList *pList = reinterpret_cast<AcmDriverList *>(dwInstance);
MMRESULT mmr = pList->Add(AcmDriverInfo(hadid, fdwSupport));

return (MMSYSERR_NOERROR == mmr);
}
3 changes: 3 additions & 0 deletions matthew_van_eerde/acmenum/source/acmenum.h
@@ -0,0 +1,3 @@
// acmenum.h

MMRESULT EnumerateACMDrivers();
88 changes: 88 additions & 0 deletions matthew_van_eerde/acmenum/source/details.cpp
@@ -0,0 +1,88 @@
// details.cpp

#include <windows.h>
#include <mmreg.h>
#include <mmiscapi.h>
#include <msacm.h>
#include <stdio.h>

#include "details.h"
#include "log.h"

#define CHARS_FROM_FOURCC(x) \
(CHAR)((x) & 0xff), \
(CHAR)(((x) >> 8) & 0xff), \
(CHAR)(((x) >> 16) & 0xff), \
(CHAR)(((x) >> 24) & 0xff) \

#define COMPONENTS_FROM_VERSION_DWORD(x) \
((x) >> 24), \
(((x) >> 16) & 0xff), \
(((x) >> 8) & 0xffff)

#define DISPLAY_FLAG(flag, x) \
(((x) & (flag)) == (flag) ? L" " L ## #flag L"\n" : L"")

#define DISPLAY_INVALID_FLAGS(mask, x) \
(((x) & ~(mask)) == 0 ? L"" : L" Invalid flags!\n")


void LogDetails(ACMDRIVERDETAILS details) {

LOG(
L"-- ACM Driver Details: %s --\n"
L" cbStruct: %u\n"
L" fccType: 0x%08x (%hc%hc%hc%hc)\n"
L" fccComp: 0x%08x (%hc%hc%hc%hc)\n"
L" wMid: %u\n"
L" wPid: %u\n"
L" vdwACM: 0x%08x (%u.%u.%u)\n"
L" vdwDriver: 0x%08x (%u.%u.%u)\n"
L" fdwSupport: 0x%08x\n"
L"%s%s%s%s%s%s%s%s"
L" cFormatTags: %d\n"
L" cFilterTags: %d\n"
L" hicon: 0x%p\n"
L" szShortName: \"%s\"\n"
L" szLongName: \"%s\"\n"
L" szCopyright: \"%s\"\n"
L" szLicensing: \"%s\"\n"
L" szFeatures: \"%s\"",

details.szShortName,
details.cbStruct,
details.fccType, CHARS_FROM_FOURCC(details.fccType ? details.fccType : 0x20202020), // print spaces rather than \0s
details.fccComp, CHARS_FROM_FOURCC(details.fccComp ? details.fccComp : 0x20202020), // to allow piping
details.wMid,
details.wPid,
details.vdwACM, COMPONENTS_FROM_VERSION_DWORD(details.vdwACM),
details.vdwDriver, COMPONENTS_FROM_VERSION_DWORD(details.vdwDriver),
details.fdwSupport,
DISPLAY_FLAG( ACMDRIVERDETAILS_SUPPORTF_ASYNC, details.fdwSupport ),
DISPLAY_FLAG( ACMDRIVERDETAILS_SUPPORTF_CODEC, details.fdwSupport ),
DISPLAY_FLAG( ACMDRIVERDETAILS_SUPPORTF_CONVERTER, details.fdwSupport ),
DISPLAY_FLAG( ACMDRIVERDETAILS_SUPPORTF_DISABLED, details.fdwSupport ),
DISPLAY_FLAG( ACMDRIVERDETAILS_SUPPORTF_FILTER, details.fdwSupport ),
DISPLAY_FLAG( ACMDRIVERDETAILS_SUPPORTF_HARDWARE, details.fdwSupport ),
DISPLAY_FLAG( ACMDRIVERDETAILS_SUPPORTF_LOCAL, details.fdwSupport ),
DISPLAY_INVALID_FLAGS(
ACMDRIVERDETAILS_SUPPORTF_ASYNC |
ACMDRIVERDETAILS_SUPPORTF_CODEC |
ACMDRIVERDETAILS_SUPPORTF_CONVERTER |
ACMDRIVERDETAILS_SUPPORTF_DISABLED |
ACMDRIVERDETAILS_SUPPORTF_FILTER |
ACMDRIVERDETAILS_SUPPORTF_HARDWARE |
ACMDRIVERDETAILS_SUPPORTF_LOCAL,
details.fdwSupport
),
details.cFormatTags,
details.cFilterTags,
details.hicon, // this is a shared icon - do not call DestroyIcon(..) on this HICON
details.szShortName,
details.szLongName,
details.szCopyright,
details.szLicensing,
details.szFeatures
);

}
3 changes: 3 additions & 0 deletions matthew_van_eerde/acmenum/source/details.h
@@ -0,0 +1,3 @@
// details.h

void LogDetails(ACMDRIVERDETAILS details);
60 changes: 60 additions & 0 deletions matthew_van_eerde/acmenum/source/list.cpp
@@ -0,0 +1,60 @@
// list.cpp

#include <windows.h>
#include <mmreg.h>
#include <mmiscapi.h>
#include <msacm.h>
#include <stdio.h>

#include "list.h"
#include "log.h"

// AcmDriverInfo
AcmDriverInfo::AcmDriverInfo()
: id(NULL), fdwSupport(0)
{}

AcmDriverInfo::AcmDriverInfo(HACMDRIVERID i, DWORD d)
: id(i), fdwSupport(d)
{}

// AcmDriverList
AcmDriverList::AcmDriverList()
: nCount(0), pDrivers(NULL)
{}


AcmDriverList::~AcmDriverList() {
if (NULL != pDrivers) {
delete [] pDrivers;
}
}

MMRESULT AcmDriverList::Add(AcmDriverInfo newDriver) {
// allocate the new list
AcmDriverInfo *pNewDrivers = new AcmDriverInfo[nCount + 1];

if (NULL == pNewDrivers) {
ERR(L"Could not allocate %u-element AcmDriverInfo array", nCount + 1);
return MMSYSERR_NOMEM;
}

// copy all the old drivers over
for (UINT32 i = 0; i < nCount; i++) {
pNewDrivers[i] = pDrivers[i];
}

// don't forget the new driver
pNewDrivers[nCount] = newDriver;

// free the old list
if (NULL != pDrivers) {
delete [] pDrivers;
}

// swap in the new list
pDrivers = pNewDrivers;
nCount++;

return MMSYSERR_NOERROR;
}
19 changes: 19 additions & 0 deletions matthew_van_eerde/acmenum/source/list.h
@@ -0,0 +1,19 @@
// list.h

struct AcmDriverInfo {
HACMDRIVERID id;
DWORD fdwSupport;

AcmDriverInfo();
AcmDriverInfo(HACMDRIVERID i, DWORD d);
};

struct AcmDriverList {
UINT32 nCount;
AcmDriverInfo *pDrivers;

AcmDriverList();
~AcmDriverList();

MMRESULT Add(AcmDriverInfo newDriver);
};
4 changes: 4 additions & 0 deletions matthew_van_eerde/acmenum/source/log.h
@@ -0,0 +1,4 @@
// log.h

#define LOG(sz, ...) wprintf(sz L"\n", __VA_ARGS__);
#define ERR(sz, ...) wprintf(L"ERROR: " sz L"\n", __VA_ARGS__);
17 changes: 17 additions & 0 deletions matthew_van_eerde/acmenum/source/main.cpp
@@ -0,0 +1,17 @@
// main.cpp

#include <windows.h>
#include <mmreg.h>
#include <mmiscapi.h>
#include <msacm.h>
#include <stdio.h>

#include "log.h"
#include "acmenum.h"

int _cdecl wmain() {

MMRESULT mmr = EnumerateACMDrivers();

return mmr;
}
23 changes: 23 additions & 0 deletions matthew_van_eerde/acmenum/source/sources
@@ -0,0 +1,23 @@
# sources
TARGETTYPE = PROGRAM
TARGETNAME = acmenum
UMTYPE = console
UMENTRY = wmain
USE_MSVCRT = 1

C_DEFINES = $(C_DEFINES) -DUNICODE -D_UNICODE

MSC_WARNING_LEVEL = /W4 /WX

_NT_TARGET_VERSION = $(_NT_TARGET_VERSION_WINXP)

SOURCES = \
acmenum.cpp \
details.cpp \
list.cpp \
main.cpp \

TARGETLIBS = \
$(SDK_LIB_PATH)\ole32.lib \
$(SDK_LIB_PATH)\msacm32.lib \

Binary file added matthew_van_eerde/acmenum/x86/acmenum.exe
Binary file not shown.
Binary file added matthew_van_eerde/amd64/play-exclusive.exe
Binary file not shown.
Binary file added matthew_van_eerde/apoenum/amd64/apoenum.exe
Binary file not shown.
46 changes: 46 additions & 0 deletions matthew_van_eerde/apoenum/source/apoenum.cpp
@@ -0,0 +1,46 @@
// apoenum.cpp

#include <windows.h>
#include <audioenginebaseapo.h>
#include <stdio.h>

#include "apoenum.h"
#include "details.h"
#include "log.h"

HRESULT myEnumerateAPOsCallback(
PAPO_REG_PROPERTIES pProperties,
PVOID pvRefData
);

HRESULT EnumerateAudioProcessingObjects() {
UINT32 nCount = 0;

HRESULT hr = EnumerateAPOs(myEnumerateAPOsCallback, &nCount);
if (FAILED(hr)) {
ERR(L"EnumerateAPOs failed: hr = 0x%08x", hr);
return hr;
}

LOG(L"APOs found: %u", nCount);

return S_OK;
}

// note that APO_REG_PROPERTIES is a variable-sized structure so beware of slicing
// also note that it's only valid for the life of the callback;
// if you want to store the info for use later, make a deep copy
HRESULT myEnumerateAPOsCallback(
PAPO_REG_PROPERTIES pProperties,
PVOID pvRefData
) {
UINT32 *pnCount = reinterpret_cast<UINT32 *>(pvRefData);
if (NULL == pnCount) {
ERR(L"myEnumerateAPOsCallback got a NULL pvRefData");
return E_POINTER;
}

(*pnCount)++;

return LogDetails(pProperties); // LogDetails logs its own failures
}
3 changes: 3 additions & 0 deletions matthew_van_eerde/apoenum/source/apoenum.h
@@ -0,0 +1,3 @@
// apoenum.h

HRESULT EnumerateAudioProcessingObjects();
16 changes: 16 additions & 0 deletions matthew_van_eerde/apoenum/source/cleanup.cpp
@@ -0,0 +1,16 @@
// cleanup.cpp
#include <windows.h>
#include <objbase.h>
#include <stdio.h>

#include "log.h"
#include "cleanup.h"

// CoTaskMemFreeOnExit
CoTaskMemFreeOnExit::CoTaskMemFreeOnExit(PVOID p)
: m_p(p)
{}

CoTaskMemFreeOnExit::~CoTaskMemFreeOnExit() {
CoTaskMemFree(m_p);
}
10 changes: 10 additions & 0 deletions matthew_van_eerde/apoenum/source/cleanup.h
@@ -0,0 +1,10 @@
// cleanup.h

class CoTaskMemFreeOnExit {
public:
CoTaskMemFreeOnExit(PVOID p);
~CoTaskMemFreeOnExit();

private:
PVOID m_p;
};

0 comments on commit f4ee42e

Please sign in to comment.