Skip to content

Commit 9c77727

Browse files
committed
Support senc, encryption sampling
1 parent bf3c1fb commit 9c77727

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

Diff for: src/isofile-write.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,28 @@ ISOFile.prototype.createFragment = function(track_id, sampleNumber, stream_) {
1717
}
1818
return null;
1919
}
20-
20+
2121
var stream = stream_ || new DataStream();
2222
stream.endianness = DataStream.BIG_ENDIAN;
2323

2424
var moof = ISOFile.createSingleSampleMoof(sample);
25+
26+
// Extract sample encryption.
27+
var senc = this.getBox('senc');
28+
29+
// Add sample encryption if it exists.
30+
if (senc) {
31+
moof.trafs[0].senc = senc;
32+
moof.trafs[0].boxes.push(senc);
33+
}
34+
2535
moof.write(stream);
2636

2737
/* adjusting the data_offset now that the moof size is known*/
2838
moof.trafs[0].truns[0].data_offset = moof.size+8; //8 is mdat header
2939
Log.debug("MP4Box", "Adjusting data_offset with new value "+moof.trafs[0].truns[0].data_offset);
3040
stream.adjustUint32(moof.trafs[0].truns[0].data_offset_position, moof.trafs[0].truns[0].data_offset);
31-
41+
3242
var mdat = new BoxParser.mdatBox();
3343
mdat.data = sample.data;
3444
mdat.write(stream);
@@ -47,7 +57,7 @@ ISOFile.writeInitializationSegment = function(ftyp, moov, total_duration, sample
4757
var stream = new DataStream();
4858
stream.endianness = DataStream.BIG_ENDIAN;
4959
ftyp.write(stream);
50-
60+
5161
/* we can now create the new mvex box */
5262
var mvex = moov.add("mvex");
5363
if (total_duration) {
@@ -70,7 +80,7 @@ ISOFile.prototype.save = function(name) {
7080
var stream = new DataStream();
7181
stream.endianness = DataStream.BIG_ENDIAN;
7282
this.write(stream);
73-
stream.save(name);
83+
stream.save(name);
7484
}
7585

7686
ISOFile.prototype.getBuffer = function() {
@@ -91,11 +101,11 @@ ISOFile.prototype.initializeSegmentation = function() {
91101
Log.warn("MP4Box", "No segmentation callback set!");
92102
}
93103
if (!this.isFragmentationInitialized) {
94-
this.isFragmentationInitialized = true;
104+
this.isFragmentationInitialized = true;
95105
this.nextMoofNumber = 0;
96106
this.resetTables();
97-
}
98-
initSegs = [];
107+
}
108+
initSegs = [];
99109
for (i = 0; i < this.fragmentedTracks.length; i++) {
100110
var moov = new BoxParser.moovBox();
101111
moov.mvhd = this.moov.mvhd;

Diff for: src/parsing/senc.js

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
// Cannot be fully parsed because Per_Sample_IV_Size needs to be known
2-
BoxParser.createFullBoxCtor("senc" /*, function(stream) {
1+
BoxParser.createFullBoxCtor("senc", function(stream) {
32
this.parseFullHeader(stream);
43
var sample_count = stream.readUint32();
5-
this.samples = [];
6-
for (var i = 0; i < sample_count; i++) {
7-
var sample = {};
8-
// tenc.default_Per_Sample_IV_Size or seig.Per_Sample_IV_Size
9-
sample.InitializationVector = this.readUint8Array(Per_Sample_IV_Size*8);
10-
if (this.flags & 0x2) {
11-
sample.subsamples = [];
12-
subsample_count = stream.readUint16();
13-
for (var j = 0; j < subsample_count; j++) {
14-
var subsample = {};
15-
subsample.BytesOfClearData = stream.readUint16();
16-
subsample.BytesOfProtectedData = stream.readUint32();
17-
sample.subsamples.push(subsample);
18-
}
19-
}
20-
// TODO
21-
this.samples.push(sample);
22-
}
23-
}*/);
4+
this.data = stream.readUint8Array(this.size - this.hdr_size - 4);
5+
// Cannot be fully parsed because Per_Sample_IV_Size needs to be known
6+
//this.samples = [];
7+
//for (var i = 0; i < sample_count; i++) {
8+
// var sample = {};
9+
// // tenc.default_Per_Sample_IV_Size or seig.Per_Sample_IV_Size
10+
// sample.InitializationVector = this.readUint8Array(Per_Sample_IV_Size*8);
11+
// if (this.flags & 0x2) {
12+
// sample.subsamples = [];
13+
// subsample_count = stream.readUint16();
14+
// for (var j = 0; j < subsample_count; j++) {
15+
// var subsample = {};
16+
// subsample.BytesOfClearData = stream.readUint16();
17+
// subsample.BytesOfProtectedData = stream.readUint32();
18+
// sample.subsamples.push(subsample);
19+
// }
20+
// }
21+
// // TODO
22+
// this.samples.push(sample);
23+
//}
24+
});

0 commit comments

Comments
 (0)