Skip to content

Commit 9bf5f0f

Browse files
Enhanced broadcasting tests
1 parent fa74915 commit 9bf5f0f

File tree

3 files changed

+197
-2
lines changed

3 files changed

+197
-2
lines changed
1.06 MB
Binary file not shown.

tests/osn-tests/src/test_osn_advanced_streaming.ts

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import { ETestErrorMsg, GetErrorMessage } from '../util/error_messages';
66
import { OBSHandler } from '../util/obs_handler'
77
import { deleteConfigFiles, sleep } from '../util/general';
88
import { EOBSInputTypes, EOBSOutputSignal, EOBSOutputType } from '../util/obs_enums';
9-
import { EFPSType } from '../osn';
9+
import * as inputSettings from '../util/input_settings';
10+
11+
import path = require('path');
1012

1113
const testName = 'osn-advanced-streaming';
1214

1315
describe(testName, () => {
1416
let obs: OBSHandler;
1517
let hasTestFailed: boolean = false;
18+
const mediaPath = path.join(path.normalize(__dirname), '..', 'media');
19+
1620
// Initialize OBS process
1721
before(async() => {
1822
logInfo(testName, 'Starting ' + testName + ' tests');
@@ -183,6 +187,100 @@ describe(testName, () => {
183187
osn.AdvancedStreamingFactory.destroy(stream);
184188
});
185189

190+
it('Enhanced broadcasting streaming', async function() {
191+
if (obs.isDarwin()) {
192+
this.skip();
193+
}
194+
195+
const stream = osn.AdvancedStreamingFactory.create();
196+
expect(stream).to.not.be.null;
197+
stream.service = osn.ServiceFactory.legacySettings;
198+
199+
// Note: no video encoder set, because it is automatically created by the enhanced broadcasting
200+
stream.delay = osn.DelayFactory.create();
201+
stream.reconnect = osn.ReconnectFactory.create();
202+
stream.network = osn.NetworkFactory.create();
203+
stream.video = obs.defaultVideoContext;
204+
stream.enhancedBroadcasting = true;
205+
const track1 = osn.AudioTrackFactory.create(160, 'track1');
206+
osn.AudioTrackFactory.setAtIndex(track1, 1);
207+
stream.signalHandler = (signal) => {obs.signals.push(signal)};
208+
209+
stream.start();
210+
211+
let signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Starting);
212+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
213+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Starting, GetErrorMessage(ETestErrorMsg.StreamOutput));
214+
215+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Activate);
216+
217+
if (signalInfo.signal == EOBSOutputSignal.Stop) {
218+
throw Error(GetErrorMessage(ETestErrorMsg.StreamOutputDidNotStart, signalInfo.code.toString()));
219+
}
220+
221+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
222+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Activate, GetErrorMessage(ETestErrorMsg.StreamOutput));
223+
224+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Start);
225+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
226+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Start, GetErrorMessage(ETestErrorMsg.StreamOutput));
227+
228+
// Scene setup
229+
const scene = osn.SceneFactory.create('my_scene');
230+
expect(scene).to.not.be.null;
231+
osn.Global.setOutputSource(0, scene);
232+
233+
let settings = inputSettings.ffmpegSource;
234+
settings['volume'] = 100;
235+
settings['local_file'] = path.join(mediaPath, "bigbuckbunny.mp4");
236+
settings['looping'] = true;
237+
const videoSource = osn.InputFactory.create(EOBSInputTypes.FFMPEGSource, 'video_source', settings);
238+
expect(videoSource).to.not.be.null;
239+
240+
const sceneItem = scene.add(videoSource);
241+
expect(sceneItem).to.not.be.null;
242+
243+
sceneItem.video = obs.defaultVideoContext;
244+
sceneItem.visible = true;
245+
sceneItem.position = { x: 0, y: 0 };
246+
247+
await sleep(5 * 1000);
248+
249+
expect(stream.droppedFrames).to.not.equal(undefined, "Undefined droppedFrames");
250+
expect(stream.totalFrames).to.not.equal(undefined, "Undefined totalFrames");
251+
expect(stream.kbitsPerSec).to.not.equal(undefined, "Undefined kbitsPerSec");
252+
expect(stream.dataOutput).to.not.equal(undefined, "Undefined dataOutput");
253+
254+
stream.stop();
255+
256+
// Scene cleanup
257+
sceneItem.remove();
258+
videoSource.release();
259+
scene.release();
260+
261+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Stopping);
262+
263+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
264+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Stopping, GetErrorMessage(ETestErrorMsg.StreamOutput));
265+
266+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Stop);
267+
268+
if (signalInfo.code != 0) {
269+
throw Error(GetErrorMessage(
270+
ETestErrorMsg.StreamOutputStoppedWithError,
271+
signalInfo.code.toString(), signalInfo.error));
272+
}
273+
274+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
275+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Stop, GetErrorMessage(ETestErrorMsg.StreamOutput));
276+
277+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Deactivate);
278+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
279+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Deactivate, GetErrorMessage(ETestErrorMsg.StreamOutput));
280+
281+
osn.AdvancedStreamingFactory.destroy(stream);
282+
});
283+
186284
it('Stream with invalid stream key', async function() {
187285
if (obs.isDarwin()) {
188286
this.skip();
@@ -218,7 +316,7 @@ describe(testName, () => {
218316
EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
219317
expect(signalInfo.signal).to.equal(
220318
EOBSOutputSignal.Stop, GetErrorMessage(ETestErrorMsg.StreamOutput));
221-
expect(signalInfo.code).to.equal(-3, GetErrorMessage(ETestErrorMsg.StreamOutput));
319+
expect(signalInfo.code).to.equal(-3, GetErrorMessage(ETestErrorMsg.StreamOutput));
222320

223321
stream.service.update({ key: obs.userStreamKey });
224322

tests/osn-tests/src/test_osn_simple_streaming.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import { ETestErrorMsg, GetErrorMessage } from '../util/error_messages';
66
import { OBSHandler } from '../util/obs_handler'
77
import { deleteConfigFiles, sleep } from '../util/general';
88
import { EOBSInputTypes, EOBSOutputSignal, EOBSOutputType } from '../util/obs_enums';
9+
import * as inputSettings from '../util/input_settings';
10+
11+
import path = require('path');
912

1013
const testName = 'osn-simple-streaming';
1114

1215
describe(testName, () => {
1316
let obs: OBSHandler;
1417
let hasTestFailed: boolean = false;
18+
const mediaPath = path.join(path.normalize(__dirname), '..', 'media');
1519

1620
// Initialize OBS process
1721
before(async() => {
@@ -167,6 +171,99 @@ describe(testName, () => {
167171
osn.SimpleStreamingFactory.destroy(stream);
168172
});
169173

174+
it('Enhanced broadcasting streaming', async function() {
175+
if (obs.isDarwin()) {
176+
this.skip();
177+
}
178+
179+
const stream = osn.SimpleStreamingFactory.create();
180+
expect(stream).to.not.be.null;
181+
// Note: no video encoder set, because it is automatically created by the enhanced broadcasting
182+
stream.service = osn.ServiceFactory.legacySettings;
183+
stream.delay = osn.DelayFactory.create();
184+
stream.reconnect = osn.ReconnectFactory.create();
185+
stream.network = osn.NetworkFactory.create();
186+
stream.video = obs.defaultVideoContext;
187+
stream.audioEncoder = osn.AudioEncoderFactory.create();
188+
stream.enhancedBroadcasting = true;
189+
stream.signalHandler = (signal) => {obs.signals.push(signal)};
190+
191+
stream.start();
192+
193+
let signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Starting);
194+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
195+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Starting, GetErrorMessage(ETestErrorMsg.StreamOutput));
196+
197+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Activate);
198+
199+
if (signalInfo.signal == EOBSOutputSignal.Stop) {
200+
throw Error(GetErrorMessage(
201+
ETestErrorMsg.StreamOutputDidNotStart, signalInfo.code.toString(), signalInfo.error));
202+
}
203+
204+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
205+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Activate, GetErrorMessage(ETestErrorMsg.StreamOutput));
206+
207+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Start);
208+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
209+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Start, GetErrorMessage(ETestErrorMsg.StreamOutput));
210+
211+
// Scene setup
212+
const scene = osn.SceneFactory.create('my_scene');
213+
expect(scene).to.not.be.null;
214+
osn.Global.setOutputSource(0, scene);
215+
216+
let settings = inputSettings.ffmpegSource;
217+
settings['volume'] = 100;
218+
settings['local_file'] = path.join(mediaPath, "bigbuckbunny.mp4");;
219+
settings['looping'] = true;
220+
const videoSource = osn.InputFactory.create(EOBSInputTypes.FFMPEGSource, 'video_source', settings);
221+
expect(videoSource).to.not.be.null;
222+
223+
const sceneItem = scene.add(videoSource);
224+
expect(sceneItem).to.not.be.null;
225+
226+
sceneItem.video = obs.defaultVideoContext;
227+
sceneItem.visible = true;
228+
sceneItem.position = { x: 0, y: 0 };
229+
230+
await sleep(5 * 1000);
231+
232+
expect(stream.droppedFrames).to.not.equal(undefined, "Undefined droppedFrames");
233+
expect(stream.totalFrames).to.not.equal(undefined, "Undefined totalFrames");
234+
expect(stream.kbitsPerSec).to.not.equal(undefined, "Undefined kbitsPerSec");
235+
expect(stream.dataOutput).to.not.equal(undefined, "Undefined dataOutput");
236+
237+
stream.stop();
238+
239+
// Scene cleanup
240+
sceneItem.remove();
241+
videoSource.release();
242+
scene.release();
243+
244+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Stopping);
245+
246+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
247+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Stopping, GetErrorMessage(ETestErrorMsg.StreamOutput));
248+
249+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Stop);
250+
251+
if (signalInfo.code != 0) {
252+
throw Error(GetErrorMessage(
253+
ETestErrorMsg.StreamOutputStoppedWithError,
254+
signalInfo.code.toString(), signalInfo.error));
255+
}
256+
257+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
258+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Stop, GetErrorMessage(ETestErrorMsg.StreamOutput));
259+
260+
signalInfo = await obs.getNextSignalInfo(EOBSOutputType.Streaming, EOBSOutputSignal.Deactivate);
261+
expect(signalInfo.type).to.equal(EOBSOutputType.Streaming, GetErrorMessage(ETestErrorMsg.StreamOutput));
262+
expect(signalInfo.signal).to.equal(EOBSOutputSignal.Deactivate, GetErrorMessage(ETestErrorMsg.StreamOutput));
263+
264+
osn.SimpleStreamingFactory.destroy(stream);
265+
});
266+
170267
it('Stream with invalid stream key', async function() {
171268
if (obs.isDarwin()) {
172269
this.skip();

0 commit comments

Comments
 (0)