-
Notifications
You must be signed in to change notification settings - Fork 793
Conversation
110875b
to
8da13c6
Compare
src/media-segment-request.js
Outdated
|
||
if (progressEvent.lengthComputable) { | ||
stats.bytesReceived = progressEvent.loaded; | ||
stats.bandwidth = (stats.bytesReceived / roundTripTime) * 8 * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should use stats.roundTripTime
or use Math.max
when initializing roundTripTime
to avoid division by 0 (I assume the use of Math.max
above was to not report a round trip of 0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/media-segment-request.js
Outdated
if (error) { | ||
// If there are errors, we have to abort any outstanding requests | ||
abortAll(activeXhrs); | ||
errors.unshift(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't unshifting cause the original error that caused all the aborts to be at the end of the array? You abort all the other requests, unshift the error, and then when the aborted requests get handled, they would have an error here and unshift themselves in front of the original?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be right. It looks like I was seeing sinon's mock xhr results (which are synchronous) and was confusing it with actual behavior.
src/media-segment-request.js
Outdated
const xhr = activeXhrs[xhrKey]; | ||
|
||
// only abort xhrs that haven't had a response | ||
if (!xhr.responseTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it hurt to call abort
on a request that has already been aborted? If so should probably add a check for that here as well. If one of the requests causes an error, the rest of the requests are aborted which in turn would cause an error on the aborted request, which would loop through all the requests again, even the aborted one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't seen any issues. Aborting an already aborted xhr seems to be a no-op and doesn't trigger any sort of readystatechange.
src/media-segment-request.js
Outdated
|
||
segment.map.bytes = new Uint8Array(request.response); | ||
|
||
if (!Array.isArray(segment.bandwidth)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bandwidth array isn't used anywhere. What is it for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed...
src/media-segment-request.js
Outdated
* Handle all error conditions in one place and return an object | ||
* with all the information | ||
* | ||
* @param {Anything} error - if non-null signals an error occured with the XHR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think {Object|null}
or {Error|null}
would be acceptable here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/media-segment-request.js
Outdated
} | ||
}; | ||
}; | ||
|
||
const handleProgress = (segment, callback) => (event) => { | ||
/** | ||
* Simple progress event callback handler that gathers some states before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gathers some states stats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
bee0e37
to
ed2de70
Compare
// the request was aborted and the SegmentLoader has already started | ||
// another request. this can happen when the timeout for an aborted | ||
// request triggers due to a limitation in the XHR library | ||
// do not count this as any sort of request or we risk double-counting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing. Can you explain the limitation? (Not requesting you add more detail to the actual code comment)
EDIT: Ran the tests locally and see that is because of |
I think it would be good to have a test that makes sure |
@@ -249,7 +249,6 @@ QUnit.test('calculates bandwidth after downloading a segment', function(assert) | |||
// verify stats | |||
assert.equal(loader.mediaBytesTransferred, 10, '10 bytes'); | |||
assert.equal(loader.mediaTransferDuration, 100, '100 ms (clock above)'); | |||
assert.equal(loader.mediaRequests, 1, '1 request'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we have this same test dozens of times and it's very redundant. I actually tried to remove more of them but lost hope.
a14dbfd
to
e356bb9
Compare
@@ -669,6 +644,7 @@ export default class SegmentLoader extends videojs.EventTarget { | |||
let segment = playlist.segments[mediaIndex]; | |||
|
|||
return { | |||
requestId: 'segment-loader-' + Math.random(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to do Math.random().toString(36)
like you do with decryptionId
in mediaSegmentRequest
.
src/media-segment-request.js
Outdated
* @param {Function} doneFn - a callback that is executed after decryption has completed | ||
*/ | ||
const decryptSegment = (decrypter, segment, doneFn) => { | ||
const decryptionId = 'segment-request-' + Math.random().toString(36); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use segment.requestId
here instead of generating another random string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…gmentRequest function
…king for aborted, timeout, and errored requets
…al meaning of the event
…g convention in the hls spec
ce94669
to
a79b6a7
Compare
…vent asynchronously to updating the updating property on a SourceBuffer
68c3073
to
470cf4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM PART 2
Description
Segment XHR-related state is strewn across large parts of
SegmentLoader
. The actual problem of fetching a segment and one or two other requests that the segment might depend on is fairly self-contained. This PR aims to refactor the xhr code almost completely out ofSegmentLoader
so that it can focus on deciding what to get, not how to get them.Specific Changes proposed
SegmentLoader
intomediaSegmentRequest
- now the only thing it has to do is handle a nicely packaged response that has either failed or is ready for transmuxingmediaSegmentRequest
including the callback management that was inMasterPlaylistController
mediaRequests*
statsmediaRequests
now properly tracks the count of ALL media requests even failed or aborted requestsmediaRequestsErrored
has the number of requests that resulted in a failure (40x, 50x, etc.)mediaRequestsTimedout
has the number of requests that timed-outmediaRequestsAborted
has the number of requests explicitly aborted by theSegmentLoader
mediaSegmentRequest
unit-testsRequirements Checklist