Skip to content

Commit 3e13fce

Browse files
authored
Add test for input/output audio devices (#1686)
* advanced_replayBuffer: always destroy encoders at end of test any call the invokes the background osn::startWorker() will now always be released at the end of the test to ensure each test run does not produce an orphaned worker thread if there is an error * add test to validate audio devices are returned * release the streamVideoEncoder as well
1 parent 0a945f7 commit 3e13fce

3 files changed

Lines changed: 66 additions & 20 deletions

File tree

tests/osn-tests/src/test_osn_advanced_replayBuffer.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const testName = 'osn-advanced-replay-buffer';
1313
describe(testName, () => {
1414
let obs: OBSHandler;
1515
let hasTestFailed: boolean = false;
16+
let replayBuffer : osn.IAdvancedReplayBuffer | undefined | null;
17+
let recording : osn.IAdvancedRecording | undefined | null;
18+
let stream : osn.IAdvancedStreaming | undefined | null;
19+
1620
// Initialize OBS process
1721
before(async() => {
1822
logInfo(testName, 'Starting ' + testName + ' tests');
@@ -38,17 +42,37 @@ describe(testName, () => {
3842
}
3943

4044
obs = null;
45+
replayBuffer = null;
46+
recording = null;
47+
stream = null;
4148
deleteConfigFiles();
4249
logInfo(testName, 'Finished ' + testName + ' tests');
4350
logEmptyLine();
4451
});
4552

4653
afterEach(async function() {
54+
// Destroying created outputs and encoders in case the test failed before they were destroyed in the test itself
55+
const videoEncoder = recording?.videoEncoder;
56+
if (replayBuffer) {
57+
osn.AdvancedReplayBufferFactory.destroy(replayBuffer);
58+
replayBuffer = null;
59+
}
60+
if (recording) {
61+
osn.AdvancedRecordingFactory.destroy(recording);
62+
recording = null;
63+
}
64+
const streamVideoEncoder = stream?.videoEncoder;
65+
if (stream) {
66+
osn.AdvancedStreamingFactory.destroy(stream);
67+
stream = null;
68+
}
69+
videoEncoder?.release();
70+
streamVideoEncoder?.release();
4771
hasTestFailed = (await obs.finalizeRetryableTest(this)) || hasTestFailed;
4872
});
4973

5074
it('Create advanced replay buffer', async () => {
51-
const replayBuffer = osn.AdvancedReplayBufferFactory.create();
75+
replayBuffer = osn.AdvancedReplayBufferFactory.create();
5276
expect(replayBuffer).to.not.equal(
5377
undefined, "Error while creating the simple replayBuffer output");
5478

@@ -104,15 +128,13 @@ describe(testName, () => {
104128
true, "Invalid usesStream value");
105129
expect(replayBuffer.mixer).to.equal(
106130
7, "Invalid mixer default value");
107-
108-
osn.AdvancedReplayBufferFactory.destroy(replayBuffer);
109131
});
110132

111133
it('Start advanced replay buffer - Use Recording', async function() {
112134
if (obs.isDarwin()) {
113135
this.skip();
114136
}
115-
const replayBuffer = osn.AdvancedReplayBufferFactory.create();
137+
replayBuffer = osn.AdvancedReplayBufferFactory.create();
116138
replayBuffer.path = path.join(path.normalize(__dirname), '..', 'osnData');
117139
replayBuffer.format = osn.ERecordingFormat.MP4;
118140
replayBuffer.overwrite = false;
@@ -123,7 +145,7 @@ describe(testName, () => {
123145
replayBuffer.prefix = 'Prefix';
124146
replayBuffer.suffix = 'Suffix';
125147

126-
const recording = osn.AdvancedRecordingFactory.create();
148+
recording = osn.AdvancedRecordingFactory.create();
127149
recording.path = path.join(path.normalize(__dirname), '..', 'osnData');
128150
recording.format = osn.ERecordingFormat.MP4;
129151
recording.useStreamEncoders = false;
@@ -236,18 +258,13 @@ describe(testName, () => {
236258
EOBSOutputType.Recording, GetErrorMessage(ETestErrorMsg.RecordingOutput));
237259
expect(signalInfo.signal).to.equal(
238260
EOBSOutputSignal.Wrote, GetErrorMessage(ETestErrorMsg.RecordingOutput));
239-
240-
const streamEncoder = recording.videoEncoder;
241-
osn.AdvancedReplayBufferFactory.destroy(replayBuffer);
242-
osn.AdvancedRecordingFactory.destroy(recording);
243-
streamEncoder.release();
244261
});
245262

246263
it('Start advanced replay buffer - Use Stream through Recording', async function() {
247264
if (obs.isDarwin()) {
248265
this.skip();
249266
}
250-
const replayBuffer = osn.AdvancedReplayBufferFactory.create();
267+
replayBuffer = osn.AdvancedReplayBufferFactory.create();
251268
replayBuffer.path = path.join(path.normalize(__dirname), '..', 'osnData');
252269
replayBuffer.format = osn.ERecordingFormat.MP4;
253270
replayBuffer.overwrite = false;
@@ -258,7 +275,7 @@ describe(testName, () => {
258275
replayBuffer.prefix = 'Prefix';
259276
replayBuffer.suffix = 'Suffix';
260277

261-
const recording = osn.AdvancedRecordingFactory.create();
278+
recording = osn.AdvancedRecordingFactory.create();
262279
recording.path = path.join(path.normalize(__dirname), '..', 'osnData');
263280
recording.format = osn.ERecordingFormat.MP4;
264281
recording.useStreamEncoders = true;
@@ -268,7 +285,7 @@ describe(testName, () => {
268285
recording.useStreamEncoders = true;
269286
recording.signalHandler = (signal) => {obs.signals.push(signal)};
270287

271-
const stream = osn.AdvancedStreamingFactory.create();
288+
stream = osn.AdvancedStreamingFactory.create();
272289
stream.video = obs.defaultVideoContext;
273290
stream.videoEncoder =
274291
osn.VideoEncoderFactory.create('obs_x264', 'video-encoder-adv-stream-1');
@@ -432,11 +449,5 @@ describe(testName, () => {
432449
EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
433450
expect(signalInfo.signal).to.equal(
434451
EOBSOutputSignal.Deactivate, GetErrorMessage(ETestErrorMsg.StreamOutput));
435-
436-
const videoEncoder = stream.videoEncoder;
437-
osn.AdvancedReplayBufferFactory.destroy(replayBuffer);
438-
osn.AdvancedRecordingFactory.destroy(recording);
439-
osn.AdvancedStreamingFactory.destroy(stream);
440-
videoEncoder.release();
441452
});
442453
});

tests/osn-tests/src/test_osn_audio.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,36 @@ describe(testName, () => {
5757
expect(currentAudio.sampleRate).to.equal(48000, GetErrorMessage(ETestErrorMsg.AudioSampleRate));
5858
expect(currentAudio.speakers).to.equal(osn.ESpeakerLayout.SevenOne, GetErrorMessage(ETestErrorMsg.AudioSpeakers));
5959
});
60+
61+
it('Get output audio devices', function() {
62+
const devices = osn.NodeObs.OBS_settings_getOutputAudioDevices();
63+
expect(devices).to.not.equal(undefined, GetErrorMessage(ETestErrorMsg.AudioDevices));
64+
expect(Array.isArray(devices)).to.equal(true, GetErrorMessage(ETestErrorMsg.AudioDevicesIsArray));
65+
let foundDefaultDevice = false;
66+
for (const device of devices) {
67+
expect(device).to.have.property('id');
68+
expect(device).to.have.property('description');
69+
if (device.id === 'default') {
70+
foundDefaultDevice = true;
71+
}
72+
}
73+
if (!obs.isDarwin()) { // On virtual mac the default output device is not included in the list of output devices
74+
expect(foundDefaultDevice).to.equal(true, GetErrorMessage(ETestErrorMsg.DefaultDeviceNotFound));
75+
}
76+
});
77+
78+
it('Get input audio devices', function() {
79+
const devices = osn.NodeObs.OBS_settings_getInputAudioDevices();
80+
expect(devices).to.not.equal(undefined, GetErrorMessage(ETestErrorMsg.AudioDevices));
81+
expect(Array.isArray(devices)).to.equal(true, GetErrorMessage(ETestErrorMsg.AudioDevicesIsArray));
82+
let foundDefaultDevice = false;
83+
for (const device of devices) {
84+
expect(device).to.have.property('id');
85+
expect(device).to.have.property('description');
86+
if (device.id === 'default') {
87+
foundDefaultDevice = true;
88+
}
89+
}
90+
expect(foundDefaultDevice).to.equal(true, GetErrorMessage(ETestErrorMsg.DefaultDeviceNotFound));
91+
});
6092
});

tests/osn-tests/util/error_messages.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ export const enum ETestErrorMsg {
199199
AudioDefaultSampleRate = 'The default value of audio sample rate is wrong',
200200
AudioDefaultSpeakers = 'The default value of audio speakers is wrong',
201201
AudioSampleRate = 'Failed to set the new sample rate value',
202-
AudioSpeakers = 'Failed to set the new speakers value'
202+
AudioSpeakers = 'Failed to set the new speakers value',
203+
AudioDevices = 'Failed to get audio devices',
204+
AudioDevicesIsArray = 'Returned audio devices value is not an array',
205+
DefaultDeviceNotFound = 'Did not find the default audio device in the list of audio devices',
203206
}
204207

205208
export function GetErrorMessage(message: string, value1?: string, value2?: string, value3?: string): string {

0 commit comments

Comments
 (0)