forked from Momo707577045/mux.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: dedupe code into modules for smaller vhs bundle (videojs#345)
- Loading branch information
1 parent
073e203
commit 040c506
Showing
10 changed files
with
312 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var toUnsigned = require('../utils/bin').toUnsigned; | ||
var parseType = require('./parse-type.js'); | ||
|
||
var findBox = function(data, path) { | ||
var results = [], | ||
i, size, type, end, subresults; | ||
|
||
if (!path.length) { | ||
// short-circuit the search for empty paths | ||
return null; | ||
} | ||
|
||
for (i = 0; i < data.byteLength;) { | ||
size = toUnsigned(data[i] << 24 | | ||
data[i + 1] << 16 | | ||
data[i + 2] << 8 | | ||
data[i + 3]); | ||
|
||
type = parseType(data.subarray(i + 4, i + 8)); | ||
|
||
end = size > 1 ? i + size : data.byteLength; | ||
|
||
if (type === path[0]) { | ||
if (path.length === 1) { | ||
// this is the end of the path and we've found the box we were | ||
// looking for | ||
results.push(data.subarray(i + 8, end)); | ||
} else { | ||
// recursively search for the next box along the path | ||
subresults = findBox(data.subarray(i + 8, end), path.slice(1)); | ||
if (subresults.length) { | ||
results = results.concat(subresults); | ||
} | ||
} | ||
} | ||
i = end; | ||
} | ||
|
||
// we've finished searching all of data | ||
return results; | ||
}; | ||
|
||
module.exports = findBox; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var parseType = function(buffer) { | ||
var result = ''; | ||
result += String.fromCharCode(buffer[0]); | ||
result += String.fromCharCode(buffer[1]); | ||
result += String.fromCharCode(buffer[2]); | ||
result += String.fromCharCode(buffer[3]); | ||
return result; | ||
}; | ||
|
||
|
||
module.exports = parseType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.