|
270 | 270 | this.source = new Uint8Array(length);
|
271 | 271 | for (var i = 0; i < length; i++) {
|
272 | 272 | var hex = this.data.substr(i * 2, 2);
|
273 |
| - this.source[i] = parseInt(hex, 2); |
| 273 | + this.source[i] = parseInt(hex, 16); |
274 | 274 | }
|
275 | 275 | };
|
276 | 276 | WebmUint.prototype.getValue = function() {
|
|
284 | 284 | WebmBase.call(this, name, type || 'Float');
|
285 | 285 | }
|
286 | 286 | doInherit(WebmFloat, WebmBase);
|
| 287 | + WebmFloat.prototype.getFloatArrayType = function() { |
| 288 | + return this.source && this.source.length === 4 ? Float32Array : Float64Array; |
| 289 | + }; |
| 290 | + WebmFloat.prototype.updateBySource = function() { |
| 291 | + var byteArray = this.source.reverse(); |
| 292 | + var floatArrayType = this.getFloatArrayType(); |
| 293 | + var floatArray = new floatArrayType(byteArray.buffer); |
| 294 | + this.data = floatArray[0]; |
| 295 | + }; |
287 | 296 | WebmFloat.prototype.updateByData = function() {
|
288 |
| - var floatArray = new Float64Array([ this.data ]); |
| 297 | + var floatArrayType = this.getFloatArrayType(); |
| 298 | + var floatArray = new floatArrayType([ this.data ]); |
289 | 299 | var byteArray = new Uint8Array(floatArray.buffer);
|
290 | 300 | this.source = byteArray.reverse();
|
291 | 301 | };
|
| 302 | + WebmFloat.prototype.getValue = function() { |
| 303 | + return this.data; |
| 304 | + }; |
| 305 | + WebmFloat.prototype.setValue = function(value) { |
| 306 | + this.setData(value); |
| 307 | + }; |
292 | 308 |
|
293 | 309 | function WebmContainer(name, type) {
|
294 | 310 | WebmBase.call(this, name, type || 'Container');
|
|
411 | 427 |
|
412 | 428 | var durationSection = infoSection.getSectionById(0x489);
|
413 | 429 | if (durationSection) {
|
414 |
| - console.log('[fix-webm-duration] Duration section is present'); |
415 |
| - return false; |
| 430 | + if (durationSection.getValue() <= 0) { |
| 431 | + console.log('[fix-webm-duration] Duration section is present, but the value is empty'); |
| 432 | + durationSection.setValue(duration); |
| 433 | + } else { |
| 434 | + console.log('[fix-webm-duration] Duration section is present'); |
| 435 | + return false; |
| 436 | + } |
| 437 | + } else { |
| 438 | + console.log('[fix-webm-duration] Duration section is missing'); |
| 439 | + // append Duration section |
| 440 | + durationSection = new WebmFloat('Duration', 'Float'); |
| 441 | + durationSection.setValue(duration); |
| 442 | + infoSection.data.push({ |
| 443 | + id: 0x489, |
| 444 | + data: durationSection |
| 445 | + }); |
416 | 446 | }
|
417 | 447 |
|
418 |
| - console.log('[fix-webm-duration] Info section is missing'); |
419 | 448 | // set default time scale to 1 millisecond (1000000 nanoseconds)
|
420 | 449 | timeScaleSection.setValue(1000000);
|
421 |
| - // append Duration section |
422 |
| - durationSection = new WebmFloat('Duration', 'Float'); |
423 |
| - durationSection.setData(duration); |
424 |
| - infoSection.data.push({ |
425 |
| - id: 0x489, |
426 |
| - data: durationSection |
427 |
| - }); |
428 | 450 | infoSection.updateByData();
|
429 | 451 | segmentSection.updateByData();
|
430 | 452 | this.updateByData();
|
|
0 commit comments