diff --git a/package-lock.json b/package-lock.json index dfe4cfd50..d5f1677d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6563,9 +6563,9 @@ "dev": true }, "mux.js": { - "version": "5.12.0", - "resolved": "https://registry.npmjs.org/mux.js/-/mux.js-5.12.0.tgz", - "integrity": "sha512-xDvaPG3lkMvUgPqppJPQ4GYc9bx/vriU1rHoT+Y35QG2/t/vWDZ8395zJtu+FDuE0WC/KmsUnCN9S7smURIp5Q==", + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/mux.js/-/mux.js-5.12.1.tgz", + "integrity": "sha512-bUZmpGr9fdyAsCc8UO761x8VKIxRuSIJ4yFX7F5bDer6bz5nCFcb3hbgFNc0bA3/v/Tp96Rftftexnx6BZAbVg==", "requires": { "@babel/runtime": "^7.11.2" } diff --git a/package.json b/package.json index 85ee17d4a..d1ede88f1 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "global": "^4.4.0", "m3u8-parser": "4.7.0", "mpd-parser": "0.17.0", - "mux.js": "5.12.0", + "mux.js": "5.12.1", "video.js": "^6 || ^7" }, "peerDependencies": { diff --git a/src/media-segment-request.js b/src/media-segment-request.js index 23322a775..d6c91051e 100644 --- a/src/media-segment-request.js +++ b/src/media-segment-request.js @@ -290,9 +290,7 @@ const transmuxAndNotify = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerError, - onTransmuxerWarn, - onTransmuxerDebug + onTransmuxerLog }) => { const fmp4Tracks = segment.map && segment.map.tracks || {}; const isMuxed = Boolean(fmp4Tracks.audio && fmp4Tracks.video); @@ -361,15 +359,7 @@ const transmuxAndNotify = ({ onEndedTimeline: () => { endedTimelineFn(); }, - onError: (message) => { - onTransmuxerError(message); - }, - onWarn: (message) => { - onTransmuxerWarn(message); - }, - onDebug: (message) => { - onTransmuxerDebug(message); - }, + onTransmuxerLog, onDone: (result) => { if (!doneFn) { return; @@ -428,9 +418,7 @@ const handleSegmentBytes = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerDebug, - onTransmuxerWarn, - onTransmuxerError + onTransmuxerLog }) => { let bytesAsUint8Array = new Uint8Array(bytes); @@ -525,6 +513,9 @@ const handleSegmentBytes = ({ // transfer bytes back to us bytes = message.data.buffer; segment.bytes = bytesAsUint8Array = message.data; + message.logs.forEach(function(log) { + onTransmuxerLog(videojs.mergeOptions(log, {stream: 'mp4CaptionParser'})); + }); finishLoading(message.captions); } }); @@ -563,9 +554,7 @@ const handleSegmentBytes = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerError, - onTransmuxerDebug, - onTransmuxerWarn + onTransmuxerLog }); }; @@ -642,9 +631,7 @@ const decryptSegment = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerDebug, - onTransmuxerWarn, - onTransmuxerError + onTransmuxerLog }) => { decrypt({ id: segment.requestId, @@ -667,9 +654,7 @@ const decryptSegment = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerError, - onTransmuxerWarn, - onTransmuxerDebug + onTransmuxerLog }); }); }; @@ -716,9 +701,7 @@ const waitForCompletion = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerDebug, - onTransmuxerWarn, - onTransmuxerError + onTransmuxerLog }) => { let count = 0; let didError = false; @@ -765,9 +748,7 @@ const waitForCompletion = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerError, - onTransmuxerWarn, - onTransmuxerDebug + onTransmuxerLog }); } // Otherwise, everything is ready just continue @@ -784,9 +765,7 @@ const waitForCompletion = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerError, - onTransmuxerWarn, - onTransmuxerDebug + onTransmuxerLog }); }; @@ -976,9 +955,7 @@ export const mediaSegmentRequest = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerDebug, - onTransmuxerWarn, - onTransmuxerError + onTransmuxerLog }) => { const activeXhrs = []; const finishProcessingFn = waitForCompletion({ @@ -994,9 +971,7 @@ export const mediaSegmentRequest = ({ endedTimelineFn, dataFn, doneFn, - onTransmuxerDebug, - onTransmuxerWarn, - onTransmuxerError + onTransmuxerLog }); // optionally, request the decryption key diff --git a/src/segment-loader.js b/src/segment-loader.js index 53df2c8b8..4b3598f15 100644 --- a/src/segment-loader.js +++ b/src/segment-loader.js @@ -2428,14 +2428,8 @@ export default class SegmentLoader extends videojs.EventTarget { dataFn: this.handleData_.bind(this), doneFn: this.segmentRequestFinished_.bind(this), - onTransmuxerWarn: (message) => { - this.logger_(`${segmentInfoString(segmentInfo)} transmuxer warn: ${message}`); - }, - onTransmuxerDebug: (message) => { - this.logger_(`${segmentInfoString(segmentInfo)} transmuxer debug: ${message}`); - }, - onTransmuxerError: (message) => { - this.logger_(`${segmentInfoString(segmentInfo)} transmuxer error: ${message}`); + onTransmuxerLog: ({message, level, stream}) => { + this.logger_(`${segmentInfoString(segmentInfo)} logged from transmuxer stream ${stream} as a ${level}: ${message}`); } }); } diff --git a/src/segment-transmuxer.js b/src/segment-transmuxer.js index 65b33f52e..6d1bb789e 100644 --- a/src/segment-transmuxer.js +++ b/src/segment-transmuxer.js @@ -81,9 +81,7 @@ export const processTransmux = (options) => { onCaptions, onDone, onEndedTimeline, - onWarn, - onDebug, - onError, + onTransmuxerLog, isEndOfTimeline } = options; const transmuxedData = { @@ -128,14 +126,8 @@ export const processTransmux = (options) => { waitForEndedTimelineEvent = false; onEndedTimeline(); } - if (event.data.action === 'warn') { - onWarn(event.data.message); - } - if (event.data.action === 'debug') { - onDebug(event.data.message); - } - if (event.data.action === 'error') { - onError(event.data.message); + if (event.data.action === 'log') { + onTransmuxerLog(event.data.log); } // wait for the transmuxed event since we may have audio and video diff --git a/src/transmuxer-worker.js b/src/transmuxer-worker.js index e116a4dfe..d8f9e7e3f 100644 --- a/src/transmuxer-worker.js +++ b/src/transmuxer-worker.js @@ -155,16 +155,8 @@ const wireTransmuxerEvents = function(self, transmuxer) { }); }); - transmuxer.on('debug', function({message}) { - self.postMessage({action: 'debug', message}); - }); - - transmuxer.on('error', function({message}) { - self.postMessage({action: 'error', message}); - }); - - transmuxer.on('warn', function({message}) { - self.postMessage({action: 'warn', message}); + transmuxer.on('log', function(log) { + self.postMessage({action: 'log', log}); }); }; @@ -210,6 +202,7 @@ class MessageHandlers { this.self.postMessage({ action: 'mp4Captions', captions: parsed && parsed.captions || [], + logs: parsed && parsed.logs || [], data: segment.buffer }, [segment.buffer]); } diff --git a/test/media-segment-request.test.js b/test/media-segment-request.test.js index 7a1c5164d..92f6344a7 100644 --- a/test/media-segment-request.test.js +++ b/test/media-segment-request.test.js @@ -89,7 +89,8 @@ QUnit.module('Media Segment Request - make it to transmuxer', { xhr: this.xhr, xhrOptions: this.xhrOptions, decryptionWorker: this.mockDecrypter, - segment: {} + segment: {}, + onTransmuxerLog: () => {} }; [ @@ -1335,7 +1336,8 @@ QUnit.test('non-TS segment will get parsed for captions', function(assert) { data: { action: 'mp4Captions', data: event.data, - captions + captions, + logs: [] } }); } @@ -1475,7 +1477,8 @@ QUnit.test('non-TS segment will get parsed for captions on next segment request data: { action: 'mp4Captions', data: event.data, - captions + captions, + logs: [] } }); } diff --git a/test/segment-loader.test.js b/test/segment-loader.test.js index 781119424..4f196f18c 100644 --- a/test/segment-loader.test.js +++ b/test/segment-loader.test.js @@ -902,7 +902,7 @@ QUnit.module('SegmentLoader', function(hooks) { }); }); - QUnit.test('logs warnings, debugs, and errors from the transmuxer', function(assert) { + QUnit.test('uses the log event from the transmuxer', function(assert) { const playlist = playlistWithDuration(10); const ogPost = loader.transmuxer_.postMessage; const messages = []; @@ -915,17 +915,11 @@ QUnit.module('SegmentLoader', function(hooks) { const retval = ogPost.call(loader.transmuxer_, message); if (message.action === 'push') { - const debug = newEvent('message'); - const error = newEvent('message'); - const warn = newEvent('message'); + const log = newEvent('message'); - debug.data = {action: 'debug', message: 'debug foo'}; - error.data = {action: 'error', message: 'error foo'}; - warn.data = {action: 'warn', message: 'warning foo'}; + log.data = {action: 'log', log: {message: 'debug foo', stream: 'something', level: 'warn'}}; - loader.transmuxer_.dispatchEvent(debug); - loader.transmuxer_.dispatchEvent(error); - loader.transmuxer_.dispatchEvent(warn); + loader.transmuxer_.dispatchEvent(log); return; } @@ -945,27 +939,15 @@ QUnit.module('SegmentLoader', function(hooks) { standardXHRResponse(this.requests.shift(), videoOneSecondSegment()); }); }).then(() => { - let debugFound = false; - let warnFound = false; - let errorFound = false; + let messageFound = false; messages.forEach(function(message) { - if ((/debug foo/).test(message)) { - debugFound = true; - } - - if ((/warning foo/).test(message)) { - warnFound = true; - } - - if ((/error foo/).test(message)) { - errorFound = true; + if ((/debug foo/).test(message) && (/warn/).test(message) && (/something/).test(message)) { + messageFound = true; } }); - assert.ok(debugFound, 'debug message was logged'); - assert.ok(warnFound, 'warn message was logged'); - assert.ok(errorFound, 'error message was logged'); + assert.ok(messageFound, 'message was logged'); }); }); diff --git a/test/transmuxer-worker.test.js b/test/transmuxer-worker.test.js index abad1c584..5730e11eb 100644 --- a/test/transmuxer-worker.test.js +++ b/test/transmuxer-worker.test.js @@ -328,6 +328,7 @@ QUnit.test('can parse mp4 captions', function(assert) { assert.equal(message.action, 'mp4Captions', 'returned mp4Captions event'); assert.deepEqual(message.captions.length, 2, 'two captions'); + assert.deepEqual(message.logs.length, 0, 'no logs returned'); assert.deepEqual( new Uint8Array(message.data), data,