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

Store config in Profile #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jaykijay
Copy link

Do not merge, keeps crashing OBS on destructor (SaveSetting())
:(

Do not merge, keeps crashing OBS on destructor (SaveSetting())
:(
@jaykijay
Copy link
Author

Fault address: 7FFC38BB2F57 (c:\program files\obs-studio\bin\64bit\w32-pthreads.dll)
libobs version: 26.1.0 (64-bit)

Thread 1F9C (Crashed)
Stack EIP Arg0 Arg1 Arg2 Arg3 Address
00000056B92FE7C0 00007FFC38BB2F57 0000000000000005 00007FFC2AE79580 000002093E57B1E0 00007FFC2AE79580 w32-pthreads.dll!pthread_mutex_unlock+0x27
00000056B92FE820 00007FFC2C7956DF 0000000000000000 0000000000000000 0000000000000000 000000000000005E obs.dll!config_set_bool+0x6f
00000056B92FE860 00007FFC2AE728E1 000002093FE842E0 0000020943D16110 000000000000005E 000000000000005E obs-virtualoutput.dll!VirtualProperties::SaveSetting+0xe1
00000056B92FE8D0 00007FFC2AE72409 000002093E57E4F0 0000000000000000 0000000000000000 000002093FF11F60 obs-virtualoutput.dll!VirtualProperties::~VirtualProperties+0x39
00000056B92FE910 00007FFC2AE72754 0000000024FCDF58 0000020900000000 0000000024FCDF58 0000020943C99D01 obs-virtualoutput.dll!VirtualProperties::`vector deleting destructor'+0x14

@MrRraper710
Copy link

The TypeScript script provided serves as a hypothetical implementation to manage configuration settings for an OBS plugin, specifically tailored for obs-virtual-cam. Although actual OBS plugin development does not typically use TypeScript, this script serves as a conceptual demonstration on how to handle profile-specific settings within a plugin framework. Here's what each part of the script does:

Overview

The script aims to save, load, and apply settings for the obs-virtual-cam based on the active OBS profile. This ensures that users can have different configurations for the virtual camera depending on which OBS profile they are currently using.

Details of the Script

  1. Import Modules:

    • fs: Node.js file system module used for reading and writing files.
    • obs: A placeholder module representing the OBS Studio client, which would typically provide methods to interact with OBS, like getting the current profile name or setting configurations for plugins.
  2. Class VirtualCamConfig:

    • This class encapsulates the functionality for managing the virtual camera's configuration settings.
  3. Constructor:

    • It initializes the instance by determining the file path for storing the configuration settings. This path includes the current OBS profile name to ensure settings are profile-specific.
  4. saveSettings Method:

    • Takes configuration settings as a parameter and writes them to a JSON file. The file path is determined by the current OBS profile, ensuring that these settings are unique to each profile.
  5. loadSettings Method:

    • Reads the settings from the JSON file if it exists. If the file doesn't exist, it returns an empty object. This method is used to retrieve settings specific to the current profile when the plugin loads or when the profile is switched.
  6. applySettings Method:

    • Retrieves the settings using loadSettings and applies them to obs-virtual-cam using a hypothetical OBS method setVirtualCamSettings. This method should be called when the plugin starts or when the profile changes to ensure the camera uses the correct settings.
  7. onProfileChange Method:

    • Sets up an event listener for profile changes using obs.on('profileChange', ...). When a profile change is detected, it re-applies the settings for the new profile, ensuring the virtual camera settings are consistent with the new profile.

Practical Usage

  • virtualCamConfig instance creation and initial setup: An instance of VirtualCamConfig is created, and it immediately applies the settings for the current profile.
  • Profile change handling: The script listens for changes in the OBS profile and updates the camera settings accordingly to match the new profile's configuration.

Summary

The script is designed to enhance user experience by making obs-virtual-cam settings adaptable to different user profiles in OBS Studio. This allows users to maintain different streaming or recording setups and have the virtual camera settings automatically adjust based on the active profile. This functionality is crucial for users who use OBS in varied contexts, such as different streaming platforms or recording scenarios, and need quick switches between setups.

@MrRraper710
Copy link

import * as fs from 'fs';
import * as obs from 'obs-studio-client';

class VirtualCamConfig {
private settingsFile: string;

constructor() {
    const profileName = obs.getProfileName();
    this.settingsFile = `./configs/${profileName}-virtual-cam.json`;
}

saveSettings(settings: any): void {
    fs.writeFileSync(this.settingsFile, JSON.stringify(settings));
}

loadSettings(): any {
    if (fs.existsSync(this.settingsFile)) {
        const settingsData = fs.readFileSync(this.settingsFile, 'utf-8');
        return JSON.parse(settingsData);
    }
    return {};
}

applySettings(): void {
    const settings = this.loadSettings();
    obs.setVirtualCamSettings(settings);
}

onProfileChange(): void {
    obs.on('profileChange', () => {
        this.applySettings();
    });
}

}

// Usage
const virtualCamConfig = new VirtualCamConfig();
virtualCamConfig.applySettings();
virtualCamConfig.onProfileChange();

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

Successfully merging this pull request may close these issues.

2 participants