Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use transmuxer debug/warn/error events to the debug log #1155

Merged
merged 6 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions 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.11.3",
"mux.js": "5.12.0",
"video.js": "^6 || ^7"
},
"peerDependencies": {
Expand All @@ -81,7 +81,7 @@
"lodash-compat": "^3.10.0",
"nomnoml": "^0.3.0",
"rollup": "^2.36.1",
"rollup-plugin-worker-factory": "0.5.5",
"rollup-plugin-worker-factory": "0.5.7",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to update rollup-plugin-worker-factory to call onmessage in dispatchEvent as we use onmessage in this scenario in tests.

"shelljs": "^0.8.4",
"sinon": "^8.1.1",
"url-toolkit": "^2.2.1",
Expand Down
59 changes: 49 additions & 10 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ const transmuxAndNotify = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerError,
onTransmuxerWarn,
onTransmuxerDebug
}) => {
const fmp4Tracks = segment.map && segment.map.tracks || {};
const isMuxed = Boolean(fmp4Tracks.audio && fmp4Tracks.video);
Expand Down Expand Up @@ -358,6 +361,15 @@ const transmuxAndNotify = ({
onEndedTimeline: () => {
endedTimelineFn();
},
onError: (message) => {
onTransmuxerError(message);
},
onWarn: (message) => {
onTransmuxerWarn(message);
},
onDebug: (message) => {
onTransmuxerDebug(message);
},
onDone: (result) => {
if (!doneFn) {
return;
Expand Down Expand Up @@ -415,7 +427,10 @@ const handleSegmentBytes = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might do a refactor after this pull request, 90% of these functions don't care about these handlers, why do we have to call each one out in the parameters every single time...

onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
}) => {
let bytesAsUint8Array = new Uint8Array(bytes);

Expand Down Expand Up @@ -547,7 +562,10 @@ const handleSegmentBytes = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerError,
onTransmuxerDebug,
onTransmuxerWarn
});
};

Expand Down Expand Up @@ -623,7 +641,10 @@ const decryptSegment = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
}) => {
decrypt({
id: segment.requestId,
Expand All @@ -645,7 +666,10 @@ const decryptSegment = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerError,
onTransmuxerWarn,
onTransmuxerDebug
});
});
};
Expand Down Expand Up @@ -691,7 +715,10 @@ const waitForCompletion = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
}) => {
let count = 0;
let didError = false;
Expand Down Expand Up @@ -737,7 +764,10 @@ const waitForCompletion = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerError,
onTransmuxerWarn,
onTransmuxerDebug
});
}
// Otherwise, everything is ready just continue
Expand All @@ -753,7 +783,10 @@ const waitForCompletion = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerError,
onTransmuxerWarn,
onTransmuxerDebug
});
};

Expand Down Expand Up @@ -942,7 +975,10 @@ export const mediaSegmentRequest = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
}) => {
const activeXhrs = [];
const finishProcessingFn = waitForCompletion({
Expand All @@ -957,7 +993,10 @@ export const mediaSegmentRequest = ({
isEndOfTimeline,
endedTimelineFn,
dataFn,
doneFn
doneFn,
onTransmuxerDebug,
onTransmuxerWarn,
onTransmuxerError
});

// optionally, request the decryption key
Expand Down
11 changes: 10 additions & 1 deletion src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,16 @@ export default class SegmentLoader extends videojs.EventTarget {
id3Fn: this.handleId3_.bind(this),

dataFn: this.handleData_.bind(this),
doneFn: this.segmentRequestFinished_.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}`);
}
});
}

Expand Down
12 changes: 12 additions & 0 deletions src/segment-transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export const processTransmux = (options) => {
onCaptions,
onDone,
onEndedTimeline,
onWarn,
onDebug,
onError,
isEndOfTimeline
} = options;
const transmuxedData = {
Expand Down Expand Up @@ -125,6 +128,15 @@ 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);
}

// wait for the transmuxed event since we may have audio and video
if (event.data.type !== 'transmuxed') {
Expand Down
12 changes: 12 additions & 0 deletions src/transmuxer-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ 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});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the mux.js commit is already in, but I think we may be better off using log with a level and message. error usually is a special case separate from standard log messages, and it would also allow us to only have one function all the way through the chain.


};

/**
Expand Down
67 changes: 67 additions & 0 deletions test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,73 @@ QUnit.module('SegmentLoader', function(hooks) {
});
});

QUnit.test('logs warnings, debugs, and errors from the transmuxer', function(assert) {
const playlist = playlistWithDuration(10);
const ogPost = loader.transmuxer_.postMessage;
const messages = [];

loader.logger_ = (message) => {
messages.push(message);
};

loader.transmuxer_.postMessage = (message) => {
const retval = ogPost.call(loader.transmuxer_, message);

if (message.action === 'push') {
const debug = newEvent('message');
const error = newEvent('message');
const warn = newEvent('message');

debug.data = {action: 'debug', message: 'debug foo'};
error.data = {action: 'error', message: 'error foo'};
warn.data = {action: 'warn', message: 'warning foo'};

loader.transmuxer_.dispatchEvent(debug);
loader.transmuxer_.dispatchEvent(error);
loader.transmuxer_.dispatchEvent(warn);
return;
}

return retval;
};

return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_, {isVideoOnly: true}).then(() => {
return new Promise((resolve, reject) => {
loader.one('appended', resolve);
loader.one('error', reject);

loader.playlist(playlist);
loader.load();

this.clock.tick(100);
// segment
standardXHRResponse(this.requests.shift(), videoOneSecondSegment());
});
}).then(() => {
let debugFound = false;
let warnFound = false;
let errorFound = 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;
}
});

assert.ok(debugFound, 'debug message was logged');
assert.ok(warnFound, 'warn message was logged');
assert.ok(errorFound, 'error message was logged');
});
});

QUnit.test('segmentKey will cache new encrypted keys with cacheEncryptionKeys true', function(assert) {
loader.cacheEncryptionKeys_ = true;

Expand Down