Use more descriptive variable names
Avoid using one-letter variable names, especially in relatively complex functions.
Showing
1 changed file
with
42 additions
and
42 deletions
... | @@ -40,7 +40,7 @@ window.videojs.hls.AacStream = function() { | ... | @@ -40,7 +40,7 @@ window.videojs.hls.AacStream = function() { |
40 | // (pts:uint, pes_size:int, dataAligned:Boolean):void | 40 | // (pts:uint, pes_size:int, dataAligned:Boolean):void |
41 | this.setNextTimeStamp = function(pts, pes_size, dataAligned) { | 41 | this.setNextTimeStamp = function(pts, pes_size, dataAligned) { |
42 | if (0 > pts_delta) { | 42 | if (0 > pts_delta) { |
43 | // We assume the very firts pts is less than 0x80000000 | 43 | // We assume the very first pts is less than 0x80000000 |
44 | pts_delta = pts; | 44 | pts_delta = pts; |
45 | } | 45 | } |
46 | 46 | ||
... | @@ -54,100 +54,100 @@ window.videojs.hls.AacStream = function() { | ... | @@ -54,100 +54,100 @@ window.videojs.hls.AacStream = function() { |
54 | }; | 54 | }; |
55 | 55 | ||
56 | // (data:ByteArray, o:int = 0, l:int = 0):void | 56 | // (data:ByteArray, o:int = 0, l:int = 0):void |
57 | this.writeBytes = function(data, o, l) { | 57 | this.writeBytes = function(data, offset, length) { |
58 | var | 58 | var |
59 | e, // :int | 59 | end, // :int |
60 | newExtraData, // :uint | 60 | newExtraData, // :uint |
61 | bytesToCopy; // :int | 61 | bytesToCopy; // :int |
62 | 62 | ||
63 | // default arguments | 63 | // default arguments |
64 | o = o || 0; | 64 | offset = offset || 0; |
65 | l = l || 0; | 65 | length = length || 0; |
66 | 66 | ||
67 | // Do not allow more than 'pes_length' bytes to be written | 67 | // Do not allow more than 'pes_length' bytes to be written |
68 | l = (pes_length < l ? pes_length : l); | 68 | length = (pes_length < length ? pes_length : length); |
69 | pes_length -= l; | 69 | pes_length -= length; |
70 | e = o + l; | 70 | end = offset + length; |
71 | while (o < e) { | 71 | while (offset < end) { |
72 | switch (state) { | 72 | switch (state) { |
73 | default: | 73 | default: |
74 | state = 0; | 74 | state = 0; |
75 | break; | 75 | break; |
76 | case 0: | 76 | case 0: |
77 | if (o >= e) { | 77 | if (offset >= end) { |
78 | return; | 78 | return; |
79 | } | 79 | } |
80 | if (0xFF !== data[o]) { | 80 | if (0xFF !== data[offset]) { |
81 | console.assert(false, 'Error no ATDS header found'); | 81 | console.assert(false, 'Error no ATDS header found'); |
82 | o += 1; | 82 | offset += 1; |
83 | state = 0; | 83 | state = 0; |
84 | return; | 84 | return; |
85 | } | 85 | } |
86 | 86 | ||
87 | o += 1; | 87 | offset += 1; |
88 | state = 1; | 88 | state = 1; |
89 | break; | 89 | break; |
90 | case 1: | 90 | case 1: |
91 | if (o >= e) { | 91 | if (offset >= end) { |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | if (0xF0 !== (data[o] & 0xF0)) { | 94 | if (0xF0 !== (data[offset] & 0xF0)) { |
95 | console.assert(false, 'Error no ATDS header found'); | 95 | console.assert(false, 'Error no ATDS header found'); |
96 | o +=1; | 96 | offset +=1; |
97 | state = 0; | 97 | state = 0; |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | 100 | ||
101 | adtsProtectionAbsent = !!(data[o] & 0x01); | 101 | adtsProtectionAbsent = !!(data[offset] & 0x01); |
102 | 102 | ||
103 | o += 1; | 103 | offset += 1; |
104 | state = 2; | 104 | state = 2; |
105 | break; | 105 | break; |
106 | case 2: | 106 | case 2: |
107 | if (o >= e) { | 107 | if (offset >= end) { |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | adtsObjectType = ((data[o] & 0xC0) >>> 6) + 1; | 110 | adtsObjectType = ((data[offset] & 0xC0) >>> 6) + 1; |
111 | adtsSampleingIndex = ((data[o] & 0x3C) >>> 2); | 111 | adtsSampleingIndex = ((data[offset] & 0x3C) >>> 2); |
112 | adtsChanelConfig = ((data[o] & 0x01) << 2); | 112 | adtsChanelConfig = ((data[offset] & 0x01) << 2); |
113 | 113 | ||
114 | o += 1; | 114 | offset += 1; |
115 | state = 3; | 115 | state = 3; |
116 | break; | 116 | break; |
117 | case 3: | 117 | case 3: |
118 | if (o >= e) { | 118 | if (offset >= end) { |
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | adtsChanelConfig |= ((data[o] & 0xC0) >>> 6); | 121 | adtsChanelConfig |= ((data[offset] & 0xC0) >>> 6); |
122 | adtsFrameSize = ((data[o] & 0x03) << 11); | 122 | adtsFrameSize = ((data[offset] & 0x03) << 11); |
123 | 123 | ||
124 | o += 1; | 124 | offset += 1; |
125 | state = 4; | 125 | state = 4; |
126 | break; | 126 | break; |
127 | case 4: | 127 | case 4: |
128 | if (o >= e) { | 128 | if (offset >= end) { |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | adtsFrameSize |= (data[o] << 3); | 131 | adtsFrameSize |= (data[offset] << 3); |
132 | 132 | ||
133 | o += 1; | 133 | offset += 1; |
134 | state = 5; | 134 | state = 5; |
135 | break; | 135 | break; |
136 | case 5: | 136 | case 5: |
137 | if(o >= e) { | 137 | if(offset >= end) { |
138 | return; | 138 | return; |
139 | } | 139 | } |
140 | adtsFrameSize |= ((data[o] & 0xE0) >>> 5); | 140 | adtsFrameSize |= ((data[offset] & 0xE0) >>> 5); |
141 | adtsFrameSize -= (adtsProtectionAbsent ? 7 : 9); | 141 | adtsFrameSize -= (adtsProtectionAbsent ? 7 : 9); |
142 | 142 | ||
143 | o += 1; | 143 | offset += 1; |
144 | state = 6; | 144 | state = 6; |
145 | break; | 145 | break; |
146 | case 6: | 146 | case 6: |
147 | if (o >= e) { | 147 | if (offset >= end) { |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | adtsSampleCount = ((data[o] & 0x03) + 1) * 1024; | 150 | adtsSampleCount = ((data[offset] & 0x03) + 1) * 1024; |
151 | adtsDuration = (adtsSampleCount * 1000) / adtsSampleingRates[adtsSampleingIndex]; | 151 | adtsDuration = (adtsSampleCount * 1000) / adtsSampleingRates[adtsSampleingIndex]; |
152 | 152 | ||
153 | newExtraData = (adtsObjectType << 11) | | 153 | newExtraData = (adtsObjectType << 11) | |
... | @@ -182,15 +182,15 @@ window.videojs.hls.AacStream = function() { | ... | @@ -182,15 +182,15 @@ window.videojs.hls.AacStream = function() { |
182 | } | 182 | } |
183 | 183 | ||
184 | // Skip the checksum if there is one | 184 | // Skip the checksum if there is one |
185 | o += 1; | 185 | offset += 1; |
186 | state = 7; | 186 | state = 7; |
187 | break; | 187 | break; |
188 | case 7: | 188 | case 7: |
189 | if (!adtsProtectionAbsent) { | 189 | if (!adtsProtectionAbsent) { |
190 | if (2 > (e - o)) { | 190 | if (2 > (end - offset)) { |
191 | return; | 191 | return; |
192 | } else { | 192 | } else { |
193 | o += 2; | 193 | offset += 2; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
... | @@ -201,12 +201,12 @@ window.videojs.hls.AacStream = function() { | ... | @@ -201,12 +201,12 @@ window.videojs.hls.AacStream = function() { |
201 | break; | 201 | break; |
202 | case 8: | 202 | case 8: |
203 | while (adtsFrameSize) { | 203 | while (adtsFrameSize) { |
204 | if (o >= e) { | 204 | if (offset >= end) { |
205 | return; | 205 | return; |
206 | } | 206 | } |
207 | bytesToCopy = (e - o) < adtsFrameSize ? (e - o) : adtsFrameSize; | 207 | bytesToCopy = (end - offset) < adtsFrameSize ? (end - offset) : adtsFrameSize; |
208 | aacFrame.writeBytes(data, o, bytesToCopy); | 208 | aacFrame.writeBytes(data, offset, bytesToCopy); |
209 | o += bytesToCopy; | 209 | offset += bytesToCopy; |
210 | adtsFrameSize -= bytesToCopy; | 210 | adtsFrameSize -= bytesToCopy; |
211 | } | 211 | } |
212 | 212 | ... | ... |
-
Please register or sign in to post a comment