Has anyone used Kotlin/native to get webcam or mic...
# kotlin-native
s
Has anyone used Kotlin/native to get webcam or microphone feeds on windows? It seems to work in C++, but the “equivalent” code in Kotlin/native doesn’t seem to work. Code in 🧵 .
Copy code
memScoped {
        var hr: HRESULT = S_OK

        val attribute : CPointerVarOf<CPointer<IMFAttributes>> = alloc()
        val devices: CPointerVarOf<CPointer<CPointerVarOf<CPointer<IMFActivate>>>> = alloc()
        val devicesCount: UINT32Var = alloc()

        hr = MFCreateAttributes(attribute.ptr, 1)

        if (hr == S_OK) {
            hr = attribute.value!!.pointed.lpVtbl!!.pointed.SetGUID!!.invoke(
                attribute.value,
                MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE.ptr,
                MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID.ptr,
            )
        }

        if (hr == S_OK) {
            hr = MFEnumDeviceSources(attribute.value, devices.ptr, devicesCount.ptr)
        } else {
            println("MFEnumDeviceSources was not called")
        }
        
        println("Audio Device Count: ${devicesCount.value}")
    }
Always returns 0 devices. The final
MFEnumDeviceSources
call is returning an error, I’m working on trying to get the error.
The code I’m trying to replicate looks something like this in C++:
Copy code
HRESULT hr = S_OK;
IMFAttributes *pAttributes = NULL;

// Initialize an attribute store to specify enumeration parameters.
hr = MFCreateAttributes(&pAttributes, 1);

// Ask for source type = audio capture devices
if (SUCCEEDED(hr))
{
    // Set the device attribute.
    hr = pAttributes->SetGUID(
    MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
    MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID
    );
}

// Enumerate devices.
if (SUCCEEDED(hr))
{
    // Enumerate the device list.
    hr = MFEnumDeviceSources(pAttributes, &(*param).ppDevices, &(*param).count);
}

// Safe release.
SafeRelease(&pAttributes);
108 Views