diff --git a/src/views/Edit/Sources/Network.js b/src/views/Edit/Sources/Network.js index dd56f21..5161ccb 100644 --- a/src/views/Edit/Sources/Network.js +++ b/src/views/Edit/Sources/Network.js @@ -74,10 +74,10 @@ const initSettings = (initialSettings, config) => { }; settings.general = { - analyzeduration: 5000000, - analyzeduration_rtmp: 3000000, - analyzeduration_http: 20000000, - probesize: 5000000, + analyzeduration: 5_000_000, // microseconds, 5s, + analyzeduration_rtmp: 3_000_000, // 3s + analyzeduration_http: 20_000_000, // 20s + probesize: 5_000_000, // bytes max_probe_packets: 2500, fflags: ['genpts'], thread_queue_size: 512, @@ -220,9 +220,8 @@ const createInputs = (settings, config, skills) => { input.options.push('-fflags', '+' + settings.general.fflags.join('+')); } input.options.push('-thread_queue_size', settings.general.thread_queue_size); - if (settings.general.probesize !== 5000000) { - input.options.push('-probesize', settings.general.probesize); - } + input.options.push('-probesize', settings.general.probesize); + if (settings.general.max_probe_packets !== 2500) { input.options.push('-max_probe_packets', settings.general.max_probe_packets); } @@ -245,13 +244,9 @@ const createInputs = (settings, config, skills) => { // analyzeduration: 20s for http and 3s for rtmp streams if (settings.mode === 'push') { if (settings.push.type === 'hls') { - if (settings.general.analyzeduration_http !== 5000000) { - input.options.push('-analyzeduration', settings.general.analyzeduration_http); - } + input.options.push('-analyzeduration', settings.general.analyzeduration_http); } else if (settings.push.type === 'rtmp') { - if (settings.general.analyzeduration_rtmp !== 5000000) { - input.options.push('-analyzeduration', settings.general.analyzeduration_rtmp); - } + input.options.push('-analyzeduration', settings.general.analyzeduration_rtmp); if (skills.ffmpeg.version_major >= 6) { const codecs = []; @@ -270,59 +265,14 @@ const createInputs = (settings, config, skills) => { } } } else if (settings.push.type === 'srt') { - if (settings.general.analyzeduration !== 5000000) { - input.options.push('-analyzeduration', settings.general.analyzeduration); - } + input.options.push('-analyzeduration', settings.general.analyzeduration); } } else { - if (protocol === 'http') { - if (settings.general.analyzeduration_http !== 5000000) { - input.options.push('-analyzeduration', settings.general.analyzeduration_http); - } - } else if (protocol === 'rtmp') { - if (settings.general.analyzeduration_rtmp !== 5000000) { - input.options.push('-analyzeduration', settings.general.analyzeduration_rtmp); - } - - if (skills.ffmpeg.version_major >= 6) { - const codecs = []; - if (skills.codecs.video.hevc?.length > 0) { - codecs.push('hvc1'); - } - if (skills.codecs.video.av1?.length > 0) { - codecs.push('av01'); - } - if (skills.codecs.video.vp9?.length > 0) { - codecs.push('vp09'); - } - - if (codecs.length !== 0) { - input.options.push('-rtmp_enhanced_codecs', codecs.join(',')); - } - } - } else { - if (settings.general.analyzeduration !== 5000000) { - input.options.push('-analyzeduration', settings.general.analyzeduration); - } - } - } - - if (settings.mode === 'pull') { input.address = addUsernamePassword(input.address, settings.username, settings.password); - if (protocol === 'rtsp') { - if (skills.ffmpeg.version_major === 4) { - input.options.push('-stimeout', settings.rtsp.stimeout); - } else { - input.options.push('-timeout', settings.rtsp.stimeout); - } + if (protocol === 'http') { + input.options.push('-analyzeduration', settings.general.analyzeduration_http); - if (settings.rtsp.udp === true) { - input.options.push('-rtsp_transport', 'udp'); - } else { - input.options.push('-rtsp_transport', 'tcp'); - } - } else if (protocol === 'http') { if (settings.http.readNative === true) { input.options.push('-re'); } @@ -342,19 +292,44 @@ const createInputs = (settings, config, skills) => { if (settings.http.http_proxy.length !== 0) { input.options.push('-http_proxy', settings.http.http_proxy); } - } - } - /* - if (skills.protocols.input.includes('playout')) { - if (protocol === 'http' || protocol === 'rtmp' || protocol === 'rtsp') { - if (!input.address.startsWith('playout:')) { - input.address = 'playout:' + input.address; - } + } else if (protocol === 'rtmp') { + input.options.push('-analyzeduration', settings.general.analyzeduration_rtmp); - input.options.push('-playout_audio', '1'); + if (skills.ffmpeg.version_major >= 6) { + const codecs = []; + if (skills.codecs.video.hevc?.length > 0) { + codecs.push('hvc1'); + } + if (skills.codecs.video.av1?.length > 0) { + codecs.push('av01'); + } + if (skills.codecs.video.vp9?.length > 0) { + codecs.push('vp09'); + } + + if (codecs.length !== 0) { + input.options.push('-rtmp_enhanced_codecs', codecs.join(',')); + } + } + } else { + input.options.push('-analyzeduration', settings.general.analyzeduration); + + if (protocol === 'rtsp') { + if (skills.ffmpeg.version_major === 4) { + input.options.push('-stimeout', settings.rtsp.stimeout); + } else { + input.options.push('-timeout', settings.rtsp.stimeout); + } + + if (settings.rtsp.udp === true) { + input.options.push('-rtsp_transport', 'udp'); + } else { + input.options.push('-rtsp_transport', 'tcp'); + } + } } } -*/ + return [input]; }; @@ -522,7 +497,18 @@ const isValidURL = (address) => { function AdvancedSettings(props) { const settings = props.settings; - const protocolClass = getProtocolClass(settings.address); + let protocolClass = getProtocolClass(settings.address); + if (settings.mode === 'push') { + switch (settings.push.type) { + case 'rtmp': + protocolClass = 'rtmp'; + break; + case 'srt': + protocolClass = 'srt'; + break; + default: + } + } return ( diff --git a/src/views/Edit/Sources/Network.test.js b/src/views/Edit/Sources/Network.test.js index a76f6db..ade2756 100644 --- a/src/views/Edit/Sources/Network.test.js +++ b/src/views/Edit/Sources/Network.test.js @@ -7,6 +7,8 @@ import * as Network from './Network'; const $skills_ffmpeg6 = { ffmpeg: { version: '6.1.1', + version_major: 6, + version_minor: 1, }, formats: { demuxers: ['rtsp'], @@ -27,6 +29,8 @@ const $skills_ffmpeg6 = { const $skills_ffmpeg5 = { ffmpeg: { version: '5.1.2', + version_major: 5, + version_minor: 1, }, formats: { demuxers: ['rtsp'], @@ -39,6 +43,8 @@ const $skills_ffmpeg5 = { const $skills_ffmpeg4 = { ffmpeg: { version: '4.4.1', + version_major: 4, + version_minor: 4, }, formats: { demuxers: ['rtsp'], @@ -71,7 +77,7 @@ test('source:network pull', async () => { }; const Source = Network.component; - let { getByLabelText, queryByText, rerender } = render(); + let { getByLabelText, queryByText, rerender } = render(); expect(queryByText(`This protocol is unknown or not supported by the available FFmpeg binary.`)).toBe(null); @@ -81,19 +87,19 @@ test('source:network pull', async () => { expect($settings.mode).toBe('pull'); expect($settings.address).toBe('rtsp://127.0.0.1/live/stream'); - rerender(); + rerender(); expect(queryByText(`This protocol is unknown or not supported by the available FFmpeg binary.`)).toBeInTheDocument(); - rerender(); + rerender(); expect(queryByText(`This protocol is unknown or not supported by the available FFmpeg binary.`)).toBe(null); - rerender(); + rerender(); expect(queryByText(`This protocol is unknown or not supported by the available FFmpeg binary.`)).toBe(null); - rerender(); + rerender(); expect(queryByText(`This protocol is unknown or not supported by the available FFmpeg binary.`)).toBe(null); }); @@ -140,7 +146,20 @@ pullmatrix.tests = [ skills: $skills_ffmpeg4, input: { address: 'rtsp://admin:foobar@127.0.0.1/live/stream', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-stimeout', 5000000, '-rtsp_transport', 'tcp'], + options: [ + '-fflags', + '+genpts', + '-thread_queue_size', + 512, + '-probesize', + 5000000, + '-analyzeduration', + 5000000, + '-stimeout', + 5000000, + '-rtsp_transport', + 'tcp', + ], }, }, { @@ -149,7 +168,7 @@ pullmatrix.tests = [ skills: $skills_ffmpeg4, input: { address: 'rtmp://admin:foobar@127.0.0.1/live/stream', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-analyzeduration', 3000000], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 3000000], }, }, { @@ -163,6 +182,8 @@ pullmatrix.tests = [ '+genpts', '-thread_queue_size', 512, + '-probesize', + 5000000, '-analyzeduration', 20000000, '-re', @@ -181,7 +202,7 @@ pullmatrix.tests = [ skills: $skills_ffmpeg4, input: { address: 'srt://127.0.0.1?mode=caller&streamid=foobar', - options: ['-fflags', '+genpts', '-thread_queue_size', 512], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 5000000], }, }, { @@ -190,7 +211,20 @@ pullmatrix.tests = [ skills: $skills_ffmpeg5, input: { address: 'rtsp://admin:foobar@127.0.0.1/live/stream', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-timeout', 5000000, '-rtsp_transport', 'tcp'], + options: [ + '-fflags', + '+genpts', + '-thread_queue_size', + 512, + '-probesize', + 5000000, + '-analyzeduration', + 5000000, + '-timeout', + 5000000, + '-rtsp_transport', + 'tcp', + ], }, }, { @@ -199,7 +233,7 @@ pullmatrix.tests = [ skills: $skills_ffmpeg5, input: { address: 'rtmp://admin:foobar@127.0.0.1/live/stream', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-analyzeduration', 3000000], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 3000000], }, }, { @@ -213,6 +247,8 @@ pullmatrix.tests = [ '+genpts', '-thread_queue_size', 512, + '-probesize', + 5000000, '-analyzeduration', 20000000, '-re', @@ -231,7 +267,7 @@ pullmatrix.tests = [ skills: $skills_ffmpeg5, input: { address: 'srt://127.0.0.1?mode=caller&streamid=foobar', - options: ['-fflags', '+genpts', '-thread_queue_size', 512], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 5000000], }, }, { @@ -240,7 +276,20 @@ pullmatrix.tests = [ skills: $skills_ffmpeg6, input: { address: 'rtsp://admin:foobar@127.0.0.1/live/stream', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-timeout', 5000000, '-rtsp_transport', 'tcp'], + options: [ + '-fflags', + '+genpts', + '-thread_queue_size', + 512, + '-probesize', + 5000000, + '-analyzeduration', + 5000000, + '-timeout', + 5000000, + '-rtsp_transport', + 'tcp', + ], }, }, { @@ -249,7 +298,18 @@ pullmatrix.tests = [ skills: $skills_ffmpeg6, input: { address: 'rtmp://admin:foobar@127.0.0.1/live/stream', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-analyzeduration', 3000000, '-rtmp_enhanced_codecs', 'hvc1,av01,vp09'], + options: [ + '-fflags', + '+genpts', + '-thread_queue_size', + 512, + '-probesize', + 5000000, + '-analyzeduration', + 3000000, + '-rtmp_enhanced_codecs', + 'hvc1,av01,vp09', + ], }, }, { @@ -263,6 +323,8 @@ pullmatrix.tests = [ '+genpts', '-thread_queue_size', 512, + '-probesize', + 5000000, '-analyzeduration', 20000000, '-re', @@ -281,7 +343,7 @@ pullmatrix.tests = [ skills: $skills_ffmpeg6, input: { address: 'srt://127.0.0.1?mode=caller&streamid=foobar', - options: ['-fflags', '+genpts', '-thread_queue_size', 512], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 5000000], }, }, ]; @@ -294,7 +356,7 @@ test.each(pullmatrix.tests)('source:network pull $name input with ffmpeg $skills const Source = Network.component; - let { getByText, getByRole } = render(); + let { getByText, getByRole } = render(); expect(getByText('Probe')).toBeInTheDocument(); @@ -318,21 +380,21 @@ test('source:network push', async () => { }; const Source = Network.component; - let { queryByText, rerender } = render(); + let { queryByText, rerender } = render(); expect($settings.mode).toBe('push'); expect(queryByText(`The available FFmpeg binary doesn't support any of the required protocols.`)).toBeInTheDocument(); - rerender(); + rerender(); expect(queryByText(`The available FFmpeg binary doesn't support any of the required protocols.`)).toBe(null); - rerender(); + rerender(); expect(queryByText(`The available FFmpeg binary doesn't support any of the required protocols.`)).toBe(null); - rerender(); + rerender(); expect(queryByText(`The available FFmpeg binary doesn't support any of the required protocols.`)).toBe(null); }); @@ -350,14 +412,14 @@ test('source:network push RTMP', async () => { }; const Source = Network.component; - let { getByText, queryByText, rerender } = render(); + let { getByText, queryByText, rerender } = render(); expect($settings.mode).toBe('push'); expect($settings.push.type).toBe('rtmp'); expect(queryByText(`Enable RTMP server ...`)).toBeInTheDocument(); - rerender(); + rerender(); expect(getByText('Probe')).toBeInTheDocument(); }); @@ -375,14 +437,14 @@ test('source:network push SRT', async () => { }; const Source = Network.component; - let { getByText, queryByText, rerender } = render(); + let { getByText, queryByText, rerender } = render(); expect($settings.mode).toBe('push'); expect($settings.push.type).toBe('srt'); expect(queryByText(`Enable SRT server ...`)).toBeInTheDocument(); - rerender(); + rerender(); expect(getByText('Probe')).toBeInTheDocument(); }); @@ -406,7 +468,7 @@ pushmatrix.tests = [ config: $config, input: { address: '{rtmp,name=external.stream}', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-analyzeduration', 3000000], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 3000000], }, }, { @@ -416,7 +478,7 @@ pushmatrix.tests = [ config: $config, input: { address: '{srt,name=external.stream,mode=request}', - options: ['-fflags', '+genpts', '-thread_queue_size', 512], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 5000000], }, }, { @@ -426,7 +488,7 @@ pushmatrix.tests = [ config: $config, input: { address: '{rtmp,name=external.stream}', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-analyzeduration', 3000000], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 3000000], }, }, { @@ -436,7 +498,7 @@ pushmatrix.tests = [ config: $config, input: { address: '{srt,name=external.stream,mode=request}', - options: ['-fflags', '+genpts', '-thread_queue_size', 512], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 5000000], }, }, { @@ -446,7 +508,18 @@ pushmatrix.tests = [ config: $config, input: { address: '{rtmp,name=external.stream}', - options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-analyzeduration', 3000000, '-rtmp_enhanced_codecs', 'hvc1,av01,vp09'], + options: [ + '-fflags', + '+genpts', + '-thread_queue_size', + 512, + '-probesize', + 5000000, + '-analyzeduration', + 3000000, + '-rtmp_enhanced_codecs', + 'hvc1,av01,vp09', + ], }, }, { @@ -456,7 +529,7 @@ pushmatrix.tests = [ config: $config, input: { address: '{srt,name=external.stream,mode=request}', - options: ['-fflags', '+genpts', '-thread_queue_size', 512], + options: ['-fflags', '+genpts', '-thread_queue_size', 512, '-probesize', 5000000, '-analyzeduration', 5000000], }, }, ]; @@ -468,7 +541,9 @@ test.each(pushmatrix.tests)('source:network push $name input with ffmpeg $skills }; const Source = Network.component; - let { getByText, getByRole } = render(); + let { getByText, getByRole } = render( + , + ); expect(getByText('Probe')).toBeInTheDocument(); diff --git a/src/views/Edit/Wizard/index.test.js b/src/views/Edit/Wizard/index.test.js index 79e013b..6ad0a2d 100644 --- a/src/views/Edit/Wizard/index.test.js +++ b/src/views/Edit/Wizard/index.test.js @@ -18,6 +18,8 @@ const restreamer = { return { ffmpeg: { version: '5.1.2', + version_major: 5, + version_minor: 1, }, formats: { demuxers: ['rtsp'], @@ -26,7 +28,7 @@ const restreamer = { input: ['http', 'https', 'rtmp', 'rtmps', 'srt'], }, sources: { - network: {}, + network: [], }, encoders: { audio: ['copy', 'none', 'aac'], @@ -335,7 +337,7 @@ test('wizard: rtmp source video h264-aac', async () => { let button = screen.getByRole('button', { name: 'RTMP server' }); fireEvent.click(button); - expect(screen.queryByText(/Send stream to this address:/)).toBeInTheDocument(); + expect(screen.queryByText(/Address:/)).toBeInTheDocument(); button = screen.getByRole('button', { name: 'Next' }); expect(button).toBeEnabled(); @@ -397,6 +399,8 @@ test('wizard: srt source video h264-aac', async () => { let button = screen.getByRole('button', { name: 'SRT server' }); fireEvent.click(button); + expect(screen.queryByText(/Address:/)).toBeInTheDocument(); + button = screen.getByRole('button', { name: 'Next' }); expect(button).toBeEnabled();