Author Topic: Device ID  (Read 1590 times)

esasse

  • Posts: 32
Device ID
« on: 17 Oct '14 - 22:41 »
I've been using the device index to identify each device in my application, but as you probably know, this is not a good idea since indexes can change.

I read about a "Device instance ID" here: http://www.un4seen.com/forum/?topic=10643.msg77069#msg77069

But could not find anything in documentation. Is it available?
Is there any better option than using the name of the device?

Thanks!
Erick

Ian @ un4seen

  • Administrator
  • Posts: 21326
Re: Device ID
« Reply #1 on: 20 Oct '14 - 13:58 »
It's currently undocumented, but that information is available from BASS_GetDeviceInfo and BASS_RecordGetDeviceInfo. It's placed at the end of the BASS_DEVICEINFO "driver" string, and can be accessed like this...

Code: [Select]
BASS_DEVICEINFO di;
BASS_GetDeviceInfo(device, &di);
const char *interface=di.driver+strlen(di.driver)+1;

Note this only applies on Windows.

esasse

  • Posts: 32
Re: Device ID
« Reply #2 on: 20 Oct '14 - 14:53 »
Thanks Ian. And this is still the best way to uniquely identify a device, right?

Ian @ un4seen

  • Administrator
  • Posts: 21326
Re: Device ID
« Reply #3 on: 20 Oct '14 - 15:18 »
Yes, I believe so.

Bert

  • Posts: 176
Re: Device ID
« Reply #4 on: 21 Oct '14 - 08:42 »
Hi,
i do not understand: which information is stored there?

Thank you!

Ian @ un4seen

  • Administrator
  • Posts: 21326
Re: Device ID
« Reply #5 on: 21 Oct '14 - 16:30 »
It's the "Device Instance Id" or "Device Instance Path" string (depending on Windows version) that can be found in the device's properties in the Device Manager control panel.

esasse

  • Posts: 32
Re: Device ID
« Reply #6 on: 21 Oct '14 - 19:40 »
Code: [Select]
const char *interface=di.driver+strlen(di.driver)+1;

Can anyone help me translate this to Delphi?  :)

Thanks!

esasse

  • Posts: 32
Re: Device ID
« Reply #7 on: 22 Oct '14 - 20:54 »
I was lazy, sorry.
In Delphi the code is pretty much the same.

Code: [Select]
var
  ...
  intf: PAnsiChar;
begin
  BASS_GetDeviceInfo(device, di);
  intf := di.driver + Length(di.driver) + 1;
end;

esasse

  • Posts: 32
Re: Device ID
« Reply #8 on: 23 Oct '14 - 18:55 »
Ian, just to make sure I'm using the right data, this is what I get for a device:

Code: [Select]
hdaudio#func_01&ven_15ad&dev_1975&subsys_15ad1975&rev_1001#5&1c7818&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\elineoutwave
I should use this whole string as device ID?

Ed1966

  • Posts: 98
Re: Device ID
« Reply #9 on: 23 Oct '14 - 20:59 »
Ian, just to make sure I'm using the right data, this is what I get for a device:

Code: [Select]
hdaudio#func_01&ven_15ad&dev_1975&subsys_15ad1975&rev_1001#5&1c7818&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\elineoutwave
I should use this whole string as device ID?


No need to use PChar in Delphi. Just use String or WideString.
aHandle is Mainform.Handle.
Look:

Code: [Select]
function FullInitBass(aHandle: HWND): Integer;
var
  Count: Integer;
  fDeviceInfo: BASS_DEVICEINFO;
begin
  Count := 1;
  while BASS_GetDeviceInfo(Count, fDeviceInfo) do begin
    {
      fDeviceInfo.Flags
      flags The device's current status... a combination of these flags.
      [1] BASS_DEVICE_ENABLED: The device is enabled. It will not be possible to initialize the device if this flag is not present.
      [2] BASS_DEVICE_DEFAULT: The device is the system default.
      [4] BASS_DEVICE_INIT: The device is initialized, ie. BASS_Init or BASS_RecordInit has been called.
    }
    fDeviceStrings.Add(WideString(fDeviceInfo.Name)); << Here!!!
    BASS_Init(Count, BASS_CONFIG_FREQUENTIE, BASS_DEVICE_SPEAKERS or BASS_DEVICE_LATENCY, aHandle, nil);
    Inc(Count);
  end;
  Result := (Count - 1);
end;

Ian @ un4seen

  • Administrator
  • Posts: 21326
Re: Device ID
« Reply #10 on: 24 Oct '14 - 14:41 »
Ian, just to make sure I'm using the right data, this is what I get for a device:

Code: [Select]
hdaudio#func_01&ven_15ad&dev_1975&subsys_15ad1975&rev_1001#5&1c7818&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\elineoutwave
I should use this whole string as device ID?

Yes, you should retain the whole string (or a hash value of it). You can then look for the string in the device list to use the same device in future.