Skip to content

Commit

Permalink
offset bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
U01749 committed May 5, 2017
1 parent bf0c1d3 commit 4246094
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/EBMLReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var EBMLReader = (function (_super) {
if (this.segmentOffset != 0) {
console.warn("Multiple segments detected!");
}
this.segmentOffset = elm.tagEnd + 1;
this.segmentOffset = elm.dataStart;
this.emit("segment_offset", this.segmentOffset);
}
else if (elm.type === "b" && elm.name === "SimpleBlock") {
Expand Down
2 changes: 1 addition & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function putRefinedMetaData(segmentOffset, metadata, clusterPtrs, duration, cueI
throw new Error("metadata does not have size");
} // metadata が 不定サイズ
var metadataSize = lastmetadata.dataEnd; // 書き換える前の metadata のサイズ
var encorder = new EBMLEncoder_1.default();
// 一旦 seekhead を作って自身のサイズを調べる
var refinedMetadata = refineMetadata(-segmentOffset);
var refinedMetadataSize = encodedSizeOfEbml(refinedMetadata);
Expand All @@ -117,6 +116,7 @@ function putRefinedMetaData(segmentOffset, metadata, clusterPtrs, duration, cueI
throw new Error("unable to refine metadata, stable size could not be found in " + i + " iterations!");
// Given a list of EBMLElementBuffers, returns their encoded size in bytes
function encodedSizeOfEbml(refinedMetaData) {
var encorder = new EBMLEncoder_1.default();
return refinedMetaData.reduce(function (lst, elm) { return lst.concat(encorder.encode([elm])); }, []).reduce(function (o, buf) { return o + buf.byteLength; }, 0);
}
function refineMetadata(sizeDiff) {
Expand Down
2 changes: 1 addition & 1 deletion src/EBMLReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class EBMLReader extends EventEmitter {
if(this.segmentOffset != 0) {
console.warn("Multiple segments detected!");
}
this.segmentOffset = elm.tagEnd + 1;
this.segmentOffset = elm.dataStart;
this.emit("segment_offset", this.segmentOffset);
}else if(elm.type === "b" && elm.name === "SimpleBlock"){
const {timecode, trackNumber, frames} = tools.ebmlBlock(elm.data);
Expand Down
2 changes: 1 addition & 1 deletion src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export function putRefinedMetaData(
if(lastmetadata == null){ throw new Error("metadata not found"); }
if(lastmetadata.dataEnd < 0){ throw new Error("metadata does not have size"); } // metadata が 不定サイズ
const metadataSize = lastmetadata.dataEnd; // 書き換える前の metadata のサイズ
const encorder = new Encoder();
// 一旦 seekhead を作って自身のサイズを調べる
let refinedMetadata = refineMetadata(-segmentOffset);
let refinedMetadataSize = encodedSizeOfEbml(refinedMetadata);
Expand All @@ -117,6 +116,7 @@ export function putRefinedMetaData(

// Given a list of EBMLElementBuffers, returns their encoded size in bytes
function encodedSizeOfEbml(refinedMetaData: EBML.EBMLElementBuffer[]): number {
const encorder = new Encoder();
return refinedMetaData.reduce<ArrayBuffer[]>((lst, elm)=> lst.concat(encorder.encode([elm])), []).reduce((o, buf)=> o + buf.byteLength, 0);
}

Expand Down

0 comments on commit 4246094

Please sign in to comment.