@Override public Sample get(final int index) { final Sample orignalSample = parentSamples.get(index); if (orignalSample.getSampleEntry().getType().equals("avc1") && Arrays.binarySearch(Avc1ToAvc3TrackImpl.this.getSyncSamples(), index + 1) >= 0) { final AvcConfigurationBox avcC = orignalSample.getSampleEntry().getBoxes(AvcConfigurationBox.class).get(0); final int len = avcC.getLengthSizeMinusOne() + 1; final ByteBuffer buf = ByteBuffer.allocate(len); final SampleEntry se = avc1toavc3.get(orignalSample.getSampleEntry());
final ByteBuffer decSampleBuffer = ByteBuffer.allocate(encSampleBuffer.limit()); final CencSampleAuxiliaryDataFormat sencEntry = sencInfo.get(index); Cipher cipher = getCipher(keys.get(index), sencEntry.iv, encSample.getSampleEntry()); byte[] fullyEncryptedSample = new byte[encSampleBuffer.limit()]; encSampleBuffer.get(fullyEncryptedSample); String schemeType = getSchemeType(encSample.getSampleEntry()); if ("cbc1".equals(schemeType)) { int encryptedLength = fullyEncryptedSample.length / 16 * 16;
protected void createStsc(Track track, Map<Track, int[]> chunks, SampleTableBox stbl) { int[] tracksChunkSizes = chunks.get(track); SampleToChunkBox stsc = new SampleToChunkBox(); stsc.setEntries(new LinkedList<SampleToChunkBox.Entry>()); long lastChunkSize = Integer.MIN_VALUE; // to be sure the first chunks hasn't got the same size long lastSampleDescriptionIndex = Integer.MIN_VALUE; List<Sample> samples = track.getSamples(); int currentSampleIndex = 0; List<SampleEntry> sampleEntries = track.getSampleEntries(); for (int i = 0; i < tracksChunkSizes.length; i++) { Sample sample = samples.get(currentSampleIndex); int currentSampleDescriptionIndex = sampleEntries.indexOf(sample.getSampleEntry()) + 1; // one base if (lastChunkSize != tracksChunkSizes[i] || lastSampleDescriptionIndex != currentSampleDescriptionIndex) { stsc.getEntries().add(new SampleToChunkBox.Entry(i + 1, tracksChunkSizes[i], currentSampleDescriptionIndex)); lastChunkSize = tracksChunkSizes[i]; lastSampleDescriptionIndex = currentSampleDescriptionIndex; } currentSampleIndex += tracksChunkSizes[i]; } stbl.addBox(stsc); }
public ReplaceSampleTrack(Track origTrack, long sampleNumber, ByteBuffer content) { super("replace(" + origTrack.getName() + ")"); this.origTrack = origTrack; this.sampleNumber = sampleNumber; this.sampleContent = new SampleImpl(content, this.origTrack.getSamples().get(l2i(sampleNumber)).getSampleEntry()); this.samples = new ReplaceASingleEntryList(); }
private void init(Map<UUID, SecretKey> keys) { CencDecryptingSampleEntryTransformer tx = new CencDecryptingSampleEntryTransformer(); List<Sample> encSamples = original.getSamples(); RangeStartMap<Integer, SecretKey> indexToKey = new RangeStartMap<>(); RangeStartMap<Integer, SampleEntry> indexToSampleEntry = new RangeStartMap<>(); SampleEntry previousSampleEntry = null; for (int i = 0; i < encSamples.size(); i++) { Sample encSample = encSamples.get(i); SampleEntry current = encSample.getSampleEntry(); sampleEntries.add(tx.transform(encSample.getSampleEntry())); if (previousSampleEntry != current) { indexToSampleEntry.put(i, current); TrackEncryptionBox tenc = Path.getPath((Container) encSample.getSampleEntry(), "sinf[0]/schi[0]/tenc[0]"); if (tenc != null) { indexToKey.put(i, keys.get(tenc.getDefault_KID())); } else { indexToKey.put(i, null); } } previousSampleEntry = current; } samples = new CencDecryptingSampleList(indexToKey, indexToSampleEntry, encSamples, original.getSampleEncryptionEntries()); }
for (int i = 0; i < sourceSamples.size(); i++) { Sample origSample = sourceSamples.get(i); int nalLengthSize = nalLengthSizes.get(origSample.getSampleEntry()); CencSampleAuxiliaryDataFormat e = new CencSampleAuxiliaryDataFormat(); this.cencSampleAuxiliaryData.add(e); UUID keyId = indexToKeyId.get(i); if (keyId != null) { SampleEntry correct = tx.transform(origSample.getSampleEntry(), encryptionAlgo, indexToKeyId.get(i)); sampleEntries.add(correct); if (previousSampleEntry != correct) { } else { SampleEntry correct = origSample.getSampleEntry(); sampleEntries.add(correct); if (previousSampleEntry != correct) {
protected void createTfhd(long startSample, long endSample, Track track, int sequenceNumber, TrackFragmentBox parent) { TrackFragmentHeaderBox tfhd = new TrackFragmentHeaderBox(); SampleFlags sf = new SampleFlags(); tfhd.setDefaultSampleFlags(sf); tfhd.setBaseDataOffset(-1); tfhd.setSampleDescriptionIndex(track.getSampleEntries().indexOf(track.getSamples().get(l2i(startSample)).getSampleEntry()) + 1); tfhd.setTrackId(track.getTrackMetaData().getTrackId()); tfhd.setDefaultBaseIsMoof(true); parent.addBox(tfhd); }
SampleEntry _se = samples.get(i).getSampleEntry(); if (se != _se) { tenc = Path.getPath((Container) _se, "sinf[0]/schi[0]/tenc[0]"); for (int j = 0; j < chunkSizes[i]; j++) { long auxInfoSize = saiz.getSize(currentSampleNo + j); SampleEntry _se = samples.get(currentSampleNo + j).getSampleEntry(); if (se != _se) { tenc = Path.getPath((Container) _se, "sinf[0]/schi[0]/tenc[0]");
@Override public Sample get(final int index) { final Sample orignalSample = parentSamples.get(index); if (orignalSample.getSampleEntry().getType().equals("avc1") && Arrays.binarySearch(Avc1ToAvc3TrackImpl.this.getSyncSamples(), index + 1) >= 0) { final AvcConfigurationBox avcC = orignalSample.getSampleEntry().getBoxes(AvcConfigurationBox.class).get(0); final int len = avcC.getLengthSizeMinusOne() + 1; final ByteBuffer buf = ByteBuffer.allocate(len); final SampleEntry se = avc1toavc3.get(orignalSample.getSampleEntry());
final ByteBuffer decSampleBuffer = ByteBuffer.allocate(encSampleBuffer.limit()); final CencSampleAuxiliaryDataFormat sencEntry = sencInfo.get(index); Cipher cipher = getCipher(keys.get(index), sencEntry.iv, encSample.getSampleEntry()); byte[] fullyEncryptedSample = new byte[encSampleBuffer.limit()]; encSampleBuffer.get(fullyEncryptedSample); String schemeType = getSchemeType(encSample.getSampleEntry()); if ("cbc1".equals(schemeType)) { int encryptedLength = fullyEncryptedSample.length / 16 * 16;
public ReplaceSampleTrack(Track origTrack, long sampleNumber, ByteBuffer content) { super("replace(" + origTrack.getName() + ")"); this.origTrack = origTrack; this.sampleNumber = sampleNumber; this.sampleContent = new SampleImpl(content, this.origTrack.getSamples().get(l2i(sampleNumber)).getSampleEntry()); this.samples = new ReplaceASingleEntryList(); }
protected void createStsc(Track track, Map<Track, int[]> chunks, SampleTableBox stbl) { int[] tracksChunkSizes = chunks.get(track); SampleToChunkBox stsc = new SampleToChunkBox(); stsc.setEntries(new LinkedList<SampleToChunkBox.Entry>()); long lastChunkSize = Integer.MIN_VALUE; // to be sure the first chunks hasn't got the same size long lastSampleDescriptionIndex = Integer.MIN_VALUE; List<Sample> samples = track.getSamples(); int currentSampleIndex = 0; List<SampleEntry> sampleEntries = track.getSampleEntries(); for (int i = 0; i < tracksChunkSizes.length; i++) { Sample sample = samples.get(currentSampleIndex); int currentSampleDescriptionIndex = sampleEntries.indexOf(sample.getSampleEntry()) + 1; // one base if (lastChunkSize != tracksChunkSizes[i] || lastSampleDescriptionIndex != currentSampleDescriptionIndex) { stsc.getEntries().add(new SampleToChunkBox.Entry(i + 1, tracksChunkSizes[i], currentSampleDescriptionIndex)); lastChunkSize = tracksChunkSizes[i]; lastSampleDescriptionIndex = currentSampleDescriptionIndex; } currentSampleIndex += tracksChunkSizes[i]; } stbl.addBox(stsc); }
private void init(Map<UUID, SecretKey> keys) { CencDecryptingSampleEntryTransformer tx = new CencDecryptingSampleEntryTransformer(); List<Sample> encSamples = original.getSamples(); RangeStartMap<Integer, SecretKey> indexToKey = new RangeStartMap<>(); RangeStartMap<Integer, SampleEntry> indexToSampleEntry = new RangeStartMap<>(); SampleEntry previousSampleEntry = null; for (int i = 0; i < encSamples.size(); i++) { Sample encSample = encSamples.get(i); SampleEntry current = encSample.getSampleEntry(); sampleEntries.add(tx.transform(encSample.getSampleEntry())); if (previousSampleEntry != current) { indexToSampleEntry.put(i, current); TrackEncryptionBox tenc = Path.getPath((Container) encSample.getSampleEntry(), "sinf[0]/schi[0]/tenc[0]"); if (tenc != null) { indexToKey.put(i, keys.get(tenc.getDefault_KID())); } else { indexToKey.put(i, null); } } previousSampleEntry = current; } samples = new CencDecryptingSampleList(indexToKey, indexToSampleEntry, encSamples, original.getSampleEncryptionEntries()); }
for (int i = 0; i < sourceSamples.size(); i++) { Sample origSample = sourceSamples.get(i); int nalLengthSize = nalLengthSizes.get(origSample.getSampleEntry()); CencSampleAuxiliaryDataFormat e = new CencSampleAuxiliaryDataFormat(); this.cencSampleAuxiliaryData.add(e); UUID keyId = indexToKeyId.get(i); if (keyId != null) { SampleEntry correct = tx.transform(origSample.getSampleEntry(), encryptionAlgo, indexToKeyId.get(i)); sampleEntries.add(correct); if (previousSampleEntry != correct) { } else { SampleEntry correct = origSample.getSampleEntry(); sampleEntries.add(correct); if (previousSampleEntry != correct) {
protected void createSenc(long startSample, long endSample, CencEncryptedTrack track, TrackFragmentBox parent) { TrackEncryptionBox tenc = Path.getPath((Container) track.getSamples().get(l2i(startSample-1)).getSampleEntry(), "sinf[0]/schi[0]/tenc[0]"); if (tenc != null) { SampleEncryptionBox senc = new SampleEncryptionBox(); senc.setSubSampleEncryption(track.hasSubSampleEncryption()); senc.setEntries(track.getSampleEncryptionEntries().subList(l2i(startSample - 1), l2i(endSample - 1))); parent.addBox(senc); } }
protected void createTfhd(long startSample, long endSample, Track track, int sequenceNumber, TrackFragmentBox parent) { TrackFragmentHeaderBox tfhd = new TrackFragmentHeaderBox(); SampleFlags sf = new SampleFlags(); tfhd.setDefaultSampleFlags(sf); tfhd.setBaseDataOffset(-1); tfhd.setSampleDescriptionIndex(track.getSampleEntries().indexOf(track.getSamples().get(l2i(startSample)).getSampleEntry()) + 1); tfhd.setTrackId(track.getTrackMetaData().getTrackId()); tfhd.setDefaultBaseIsMoof(true); parent.addBox(tfhd); }
SampleEntry current = track.getSamples().get(l2i(startSample-1)).getSampleEntry(); int sdi = 1; for (SampleEntry entry : track.getSampleEntries()) {
protected void createSaiz(long startSample, long endSample, CencEncryptedTrack track, TrackFragmentBox parent) { TrackEncryptionBox tenc = Path.getPath((Container) track.getSamples().get(l2i(startSample-1)).getSampleEntry(), "sinf[0]/schi[0]/tenc[0]"); if (tenc != null) { SampleAuxiliaryInformationSizesBox saiz = new SampleAuxiliaryInformationSizesBox(); saiz.setAuxInfoType("cenc"); saiz.setFlags(1); if (track.hasSubSampleEncryption()) { short[] sizes = new short[l2i(endSample - startSample)]; List<CencSampleAuxiliaryDataFormat> auxs = track.getSampleEncryptionEntries().subList(l2i(startSample - 1), l2i(endSample - 1)); for (int i = 0; i < sizes.length; i++) { sizes[i] = (short) auxs.get(i).getSize(); } saiz.setSampleInfoSizes(sizes); } else { saiz.setDefaultSampleInfoSize(tenc.getDefaultIvSize()); saiz.setSampleCount(l2i(endSample - startSample)); } parent.addBox(saiz); } }
SampleEntry _se = samples.get(i).getSampleEntry(); if (se != _se) { tenc = Path.getPath((Container) _se, "sinf[0]/schi[0]/tenc[0]"); for (int j = 0; j < chunkSizes[i]; j++) { long auxInfoSize = saiz.getSize(currentSampleNo + j); SampleEntry _se = samples.get(currentSampleNo + j).getSampleEntry(); if (se != _se) { tenc = Path.getPath((Container) _se, "sinf[0]/schi[0]/tenc[0]");