Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit f3be6cb

Browse files
committed
implement computeLength and write functions for mp4 subs box
1 parent 2304d33 commit f3be6cb

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

app/lib/mp4lib/mp4lib-boxes.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,7 +3082,26 @@ mp4lib.boxes.SubSampleInformationBox.prototype.constructor = mp4lib.boxes.SubSam
30823082

30833083
mp4lib.boxes.SubSampleInformationBox.prototype.computeLength = function() {
30843084
mp4lib.boxes.FullBox.prototype.computeLength.call(this);
3085-
// To Define if needed
3085+
3086+
this.size += mp4lib.fields.FIELD_UINT32.getLength(); //entry_count size
3087+
for (i = 0; i < this.entry_count; i++) {
3088+
this.size += mp4lib.fields.FIELD_UINT32.getLength(); //sample_delta size
3089+
this.size += mp4lib.fields.FIELD_UINT16.getLength(); //subsample_count size
3090+
3091+
if (this.entry[i].subsample_count > 0) {
3092+
for (j=0; j < this.entry[i].subsample_count; j++) {
3093+
if (this.version === 1) {
3094+
this.size += mp4lib.fields.FIELD_UINT32.getLength(); //subsample_size size
3095+
} else {
3096+
this.size += mp4lib.fields.FIELD_UINT16.getLength(); //subsample_size size
3097+
}
3098+
3099+
this.size += mp4lib.fields.FIELD_UINT8.getLength(); //subsample_priority size
3100+
this.size += mp4lib.fields.FIELD_UINT8.getLength(); //discardable size
3101+
this.size += mp4lib.fields.FIELD_UINT32.getLength(); //reserved size
3102+
}
3103+
}
3104+
}
30863105
};
30873106

30883107
mp4lib.boxes.SubSampleInformationBox.prototype.read = function(data, pos, end) {
@@ -3121,7 +3140,30 @@ mp4lib.boxes.SubSampleInformationBox.prototype.read = function(data, pos, end) {
31213140

31223141
mp4lib.boxes.SubSampleInformationBox.prototype.write = function(data, pos) {
31233142
mp4lib.boxes.FullBox.prototype.write.call(this, data, pos);
3124-
// To Define if needed
3143+
var i = 0,
3144+
j = 0;
3145+
3146+
this._writeData(data, mp4lib.fields.FIELD_UINT32, this.entry_count);
3147+
3148+
for (i = 0; i < this.entry_count; i++) {
3149+
this._writeData(data, mp4lib.fields.FIELD_UINT32, this.entry[i].sample_delta);
3150+
this._writeData(data, mp4lib.fields.FIELD_UINT16, this.entry[i].subsample_count);
3151+
if (this.entry[i].subsample_count > 0) {
3152+
3153+
for (j = 0; j < this.entry[i].subsample_count; j++) {
3154+
if (this.version === 1) {
3155+
this._writeData(data, mp4lib.fields.FIELD_UINT32, this.entry[i].subSampleEntries[j].subsample_size);
3156+
} else {
3157+
this._writeData(data, mp4lib.fields.FIELD_UINT16, this.entry[i].subSampleEntries[j].subsample_size);
3158+
}
3159+
this._writeData(data, mp4lib.fields.FIELD_UINT8, this.entry[i].subSampleEntries[j].subsample_priority);
3160+
this._writeData(data, mp4lib.fields.FIELD_UINT8, this.entry[i].subSampleEntries[j].discardable);
3161+
this._writeData(data, mp4lib.fields.FIELD_UINT32, this.entry[i].subSampleEntries[j].reserved);
3162+
}
3163+
}
3164+
}
3165+
3166+
return this.localPos;
31253167
};
31263168

31273169
mp4lib.registerTypeBoxes();

0 commit comments

Comments
 (0)