Move usage of Uint8Array into a function.
This memoizes widthBytes, heightBytes, and videocodedidBytes for later uses after the first invocation of hls.FlvTag.
Showing
1 changed file
with
28 additions
and
23 deletions
1 | (function(window) { | 1 | (function(window) { |
2 | 2 | ||
3 | var | 3 | var hls = window.videojs.hls; |
4 | hls = window.videojs.hls, | ||
5 | |||
6 | // commonly used metadata properties | ||
7 | widthBytes = new Uint8Array('width'.length), | ||
8 | heightBytes = new Uint8Array('height'.length), | ||
9 | videocodecidBytes = new Uint8Array('videocodecid'.length), | ||
10 | i; | ||
11 | |||
12 | // calculating the bytes of common metadata names ahead of time makes the | ||
13 | // corresponding writes faster because we don't have to loop over the | ||
14 | // characters | ||
15 | // re-test with test/perf.html if you're planning on changing this | ||
16 | for (i in 'width') { | ||
17 | widthBytes[i] = 'width'.charCodeAt(i); | ||
18 | } | ||
19 | for (i in 'height') { | ||
20 | heightBytes[i] = 'height'.charCodeAt(i); | ||
21 | } | ||
22 | for (i in 'videocodecid') { | ||
23 | videocodecidBytes[i] = 'videocodecid'.charCodeAt(i); | ||
24 | } | ||
25 | 4 | ||
26 | // (type:uint, extraData:Boolean = false) extends ByteArray | 5 | // (type:uint, extraData:Boolean = false) extends ByteArray |
27 | hls.FlvTag = function(type, extraData) { | 6 | hls.FlvTag = function(type, extraData) { |
... | @@ -46,7 +25,33 @@ hls.FlvTag = function(type, extraData) { | ... | @@ -46,7 +25,33 @@ hls.FlvTag = function(type, extraData) { |
46 | bytes.set(flv.bytes.subarray(0, flv.position), 0); | 25 | bytes.set(flv.bytes.subarray(0, flv.position), 0); |
47 | flv.bytes = bytes; | 26 | flv.bytes = bytes; |
48 | flv.view = new DataView(flv.bytes.buffer); | 27 | flv.view = new DataView(flv.bytes.buffer); |
49 | }; | 28 | }, |
29 | |||
30 | // commonly used metadata properties | ||
31 | widthBytes = hls.FlvTag.widthBytes || new Uint8Array('width'.length), | ||
32 | heightBytes = hls.FlvTag.heightBytes || new Uint8Array('height'.length), | ||
33 | videocodecidBytes = hls.FlvTag.videocodecidBytes || new Uint8Array('videocodecid'.length), | ||
34 | i; | ||
35 | |||
36 | if (!hls.FlvTag.widthBytes) { | ||
37 | // calculating the bytes of common metadata names ahead of time makes the | ||
38 | // corresponding writes faster because we don't have to loop over the | ||
39 | // characters | ||
40 | // re-test with test/perf.html if you're planning on changing this | ||
41 | for (i in 'width') { | ||
42 | widthBytes[i] = 'width'.charCodeAt(i); | ||
43 | } | ||
44 | for (i in 'height') { | ||
45 | heightBytes[i] = 'height'.charCodeAt(i); | ||
46 | } | ||
47 | for (i in 'videocodecid') { | ||
48 | videocodecidBytes[i] = 'videocodecid'.charCodeAt(i); | ||
49 | } | ||
50 | |||
51 | hls.FlvTag.widthBytes = widthBytes; | ||
52 | hls.FlvTag.heightBytes = heightBytes; | ||
53 | hls.FlvTag.videocodecidBytes = videocodecidBytes; | ||
54 | } | ||
50 | 55 | ||
51 | this.keyFrame = false; // :Boolean | 56 | this.keyFrame = false; // :Boolean |
52 | 57 | ... | ... |
-
Please register or sign in to post a comment