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

InputVolumeMeters report no values #61

Closed
normen opened this issue Nov 22, 2023 · 5 comments
Closed

InputVolumeMeters report no values #61

normen opened this issue Nov 22, 2023 · 5 comments

Comments

@normen
Copy link

normen commented Nov 22, 2023

Hi,

for the InputVolumeMeters messages I do manage to enable them but the resulting event doesn't seem to contain any info about the actual meters, only the name and type of the channel?

Bildschirmfoto 2023-11-22 um 11 14 54

Am I missing something?

Thanks for any hints and especially for the library!

@andreykaipov
Copy link
Owner

andreykaipov commented Dec 16, 2023

Oh this is a bug in the generation code :(

The right type for inputs on this event is Array<Object>:

https://github.com/obsproject/obs-websocket/blob/cb6f0b8986292aad640928aee8416ab7a14935c3/docs/generated/protocol.json#L5150

This should translate to []map[string]interface{}, but it's currently a []*typedef.Input:

Inputs []*typedefs.Input `json:"inputs,omitempty"`

This is a result of some wonky logic here:

func handleCommonObjects(origin, fieldName, structName string) (string, *keyInfo) {
type nestedInfo struct {
Refer string
Comment string
OnlyFor []string // additional requirement to allow us to use different types for the same key prefix
}
// key prefix to manually declared struct in typedefs package
lookup := map[string]nestedInfo{
"keyModifiers.": {"KeyModifiers", "Key modifiers to apply", nil},
"streamServiceSettings": {"StreamServiceSettings", " ", nil},
"inputAudioTracks": {"InputAudioTracks", "", nil},
"sceneItemTransform": {"SceneItemTransform", "Scene item transform info", nil},
"monitors": {"[]Monitor", "List of detected monitors", nil},
"scenes": {"[]Scene", "", nil},
"sceneItems": {"[]SceneItem", "", nil},
"inputs": {"[]Input", "", nil},
"filters": {"[]Filter", "", nil},
"transitions": {"[]Transition", "", nil},
"propertyItems": {"[]PropertyItem", "", nil},
// "settings.": {"StreamSettings", " ", []string{"GetStreamSettings", "SetStreamSettings"}},
// "stream.settings.": {"StreamSettings", " ", []string{}},
}
valid := func(i nestedInfo) bool {
if len(i.OnlyFor) == 0 {
return true
}
for _, v := range i.OnlyFor {
if strings.HasPrefix(structName, v) {
return true
}
}
return false
}
for k, info := range lookup {
if !valid(info) {
continue
}
if strings.HasPrefix(fieldName, k) {
k = strings.TrimSuffix(k, ".")
s := Null()
if strings.HasPrefix(info.Refer, "[]") {
s = Index()
info.Refer = strings.TrimPrefix(info.Refer, "[]")
}
s = s.Op("*").Qual(typedefQualifier(origin), info.Refer)
return k, &keyInfo{Type: s, Comment: info.Comment, OmitEmpty: true}
}
}
return "", nil
}
where I take a guess at what structs match what fields based on their name.

It's a remnant of the v4 protocol where it documented common typedefs that it then referred to in requests, but in v5 a lot of the request types are documented as just Object or Array<Object>.

At the risk of just using map[string]interface{} everywhere to avoid situations like this and at least expose the hidden values (mapstructure's remain decoding might come in handy here), it might just be time to migrate this library from generated code spaghetti into more maintainable code... 😅

@normen
Copy link
Author

normen commented Dec 19, 2023

Already tested and incorporated your changes, seems to work nicely including meters and setting zero values. Thank you very much!

@andreykaipov
Copy link
Owner

Oh snap are you talking about #81? That's crazy thank you for testing it out already! I was hesitant to ping you here until I was ready to cut a release but this gives me more confidence in it!

@normen
Copy link
Author

normen commented Dec 19, 2023

Yep, didn't use the new builder pattern but it works great in my bridge app: https://github.com/normen/obs-mcu

I basically just had to add a few &'s really to adapt my code, meters work great without much overhead.

@andreykaipov
Copy link
Owner

Thanks once again for testing this out 🙏 I released these changes in v1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants