@@ -6,13 +6,17 @@ import { ETestErrorMsg, GetErrorMessage } from '../util/error_messages';
66import { OBSHandler } from '../util/obs_handler'
77import { deleteConfigFiles , sleep } from '../util/general' ;
88import { 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
1113const testName = 'osn-advanced-streaming' ;
1214
1315describe ( 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
0 commit comments