Skip to content

Commit

Permalink
switch from debug/warn/error to log
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jul 9, 2021
1 parent 1723a60 commit 5497d00
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 101 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
53 changes: 14 additions & 39 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -428,9 +418,7 @@ const handleSegmentBytes = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
onTransmuxerLog
}) => {
let bytesAsUint8Array = new Uint8Array(bytes);

Expand Down Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -563,9 +554,7 @@ const handleSegmentBytes = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerError,
onTransmuxerDebug,
onTransmuxerWarn
onTransmuxerLog
});
};

Expand Down Expand Up @@ -642,9 +631,7 @@ const decryptSegment = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
onTransmuxerLog
}) => {
decrypt({
id: segment.requestId,
Expand All @@ -667,9 +654,7 @@ const decryptSegment = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerError,
onTransmuxerWarn,
onTransmuxerDebug
onTransmuxerLog
});
});
};
Expand Down Expand Up @@ -716,9 +701,7 @@ const waitForCompletion = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
onTransmuxerLog
}) => {
let count = 0;
let didError = false;
Expand Down Expand Up @@ -765,9 +748,7 @@ const waitForCompletion = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerError,
onTransmuxerWarn,
onTransmuxerDebug
onTransmuxerLog
});
}
// Otherwise, everything is ready just continue
Expand All @@ -784,9 +765,7 @@ const waitForCompletion = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerError,
onTransmuxerWarn,
onTransmuxerDebug
onTransmuxerLog
});
};

Expand Down Expand Up @@ -976,9 +955,7 @@ export const mediaSegmentRequest = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
onTransmuxerLog
}) => {
const activeXhrs = [];
const finishProcessingFn = waitForCompletion({
Expand All @@ -994,9 +971,7 @@ export const mediaSegmentRequest = ({
endedTimelineFn,
dataFn,
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
onTransmuxerLog
});

// optionally, request the decryption key
Expand Down
10 changes: 2 additions & 8 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
});
}
Expand Down
14 changes: 3 additions & 11 deletions src/segment-transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ export const processTransmux = (options) => {
onCaptions,
onDone,
onEndedTimeline,
onWarn,
onDebug,
onError,
onTransmuxerLog,
isEndOfTimeline
} = options;
const transmuxedData = {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions src/transmuxer-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
});

};
Expand Down Expand Up @@ -210,6 +202,7 @@ class MessageHandlers {
this.self.postMessage({
action: 'mp4Captions',
captions: parsed && parsed.captions || [],
logs: parsed && parsed.logs || [],
data: segment.buffer
}, [segment.buffer]);
}
Expand Down
9 changes: 6 additions & 3 deletions test/media-segment-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {}
};

[
Expand Down Expand Up @@ -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: []
}
});
}
Expand Down Expand Up @@ -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: []
}
});
}
Expand Down
34 changes: 8 additions & 26 deletions test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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;
}

Expand All @@ -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');
});
});

Expand Down
1 change: 1 addition & 0 deletions test/transmuxer-worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5497d00

Please sign in to comment.