@Override protected void getContent(ByteBuffer byteBuffer) { writeVersionAndFlags(byteBuffer); if (getVersion() == 1) { IsoTypeWriter.writeUInt64(byteBuffer, creationTime); IsoTypeWriter.writeUInt64(byteBuffer, modificationTime); IsoTypeWriter.writeUInt32(byteBuffer, timescale); IsoTypeWriter.writeUInt64(byteBuffer, duration); } else { IsoTypeWriter.writeUInt32(byteBuffer, creationTime); IsoTypeWriter.writeUInt32(byteBuffer, modificationTime); IsoTypeWriter.writeUInt32(byteBuffer, timescale); IsoTypeWriter.writeUInt32(byteBuffer, duration); } IsoTypeWriter.writeFixedPoint1616(byteBuffer, rate); IsoTypeWriter.writeFixedPoint88(byteBuffer, volume); IsoTypeWriter.writeUInt16(byteBuffer, 0); IsoTypeWriter.writeUInt32(byteBuffer, 0); IsoTypeWriter.writeUInt32(byteBuffer, 0); for (int i = 0; i < 9; i++) { IsoTypeWriter.writeUInt32(byteBuffer, matrix[i]); } byteBuffer.putInt(previewTime); byteBuffer.putInt(previewDuration); byteBuffer.putInt(posterTime); byteBuffer.putInt(selectionTime); byteBuffer.putInt(selectionDuration); byteBuffer.putInt(currentTime); IsoTypeWriter.writeUInt32(byteBuffer, nextTrackId); }
@Override public void getBox(WritableByteChannel writableByteChannel) throws IOException { writableByteChannel.write(getHeader()); ByteBuffer byteBuffer = ByteBuffer.allocate(52 + (fontName != null ? fontName.length() : 0)); byteBuffer.position(6); IsoTypeWriter.writeUInt16(byteBuffer, dataReferenceIndex); byteBuffer.putInt(displayFlags); byteBuffer.putInt(textJustification); IsoTypeWriter.writeUInt16(byteBuffer, backgroundR); IsoTypeWriter.writeUInt16(byteBuffer, backgroundG); IsoTypeWriter.writeUInt16(byteBuffer, backgroundB); IsoTypeWriter.writeUInt64(byteBuffer, defaultTextBox); IsoTypeWriter.writeUInt64(byteBuffer, reserved1); byteBuffer.putShort(fontNumber); byteBuffer.putShort(fontFace); byteBuffer.put(reserved2); byteBuffer.putShort(reserved3); IsoTypeWriter.writeUInt16(byteBuffer, foregroundR); IsoTypeWriter.writeUInt16(byteBuffer, foregroundG); IsoTypeWriter.writeUInt16(byteBuffer, foregroundB); if (fontName != null) { IsoTypeWriter.writeUInt8(byteBuffer, fontName.length()); byteBuffer.put(fontName.getBytes()); } writableByteChannel.write((ByteBuffer) byteBuffer.rewind()); // writeContainer(writableByteChannel); there are no child boxes!? }
@Override protected void getContent(ByteBuffer byteBuffer) { writeVersionAndFlags(byteBuffer); IsoTypeWriter.writeUInt8(byteBuffer, entries.size()); for (Entry entry : entries) { if (getVersion() == 0x01) { IsoTypeWriter.writeUInt64(byteBuffer, entry.fragmentAbsoluteTime); IsoTypeWriter.writeUInt64(byteBuffer, entry.fragmentAbsoluteDuration); } else { IsoTypeWriter.writeUInt32(byteBuffer, entry.fragmentAbsoluteTime); IsoTypeWriter.writeUInt32(byteBuffer, entry.fragmentAbsoluteDuration); } } }
protected ByteBuffer getHeader() { ByteBuffer header; if (largeBox || getSize() >= (1L << 32)) { header = ByteBuffer.wrap( new byte[] { 0, 0, 0, 1, type.getBytes()[0], type.getBytes()[1], type.getBytes()[2], type.getBytes()[3], 0, 0, 0, 0, 0, 0, 0, 0 }); header.position(8); IsoTypeWriter.writeUInt64(header, getSize()); } else { header = ByteBuffer.wrap( new byte[] { 0, 0, 0, 0, type.getBytes()[0], type.getBytes()[1], type.getBytes()[2], type.getBytes()[3] }); IsoTypeWriter.writeUInt32(header, getSize()); } header.rewind(); return header; }
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); if (writableByteChannel instanceof GatheringByteChannel) { List<ByteBuffer> nuSamples = unifyAdjacentBuffers(samples); int STEPSIZE = 1024; for (int i = 0; i < Math.ceil((double) nuSamples.size() / STEPSIZE); i++) { List<ByteBuffer> sublist = nuSamples.subList( i * STEPSIZE, // start (i + 1) * STEPSIZE < nuSamples.size() ? (i + 1) * STEPSIZE : nuSamples.size()); // end ByteBuffer sampleArray[] = sublist.toArray(new ByteBuffer[sublist.size()]); do { ((GatheringByteChannel) writableByteChannel).write(sampleArray); } while (sampleArray[sampleArray.length - 1].remaining() > 0); } // System.err.println(bytesWritten); } else { for (ByteBuffer sample : samples) { sample.rewind(); writableByteChannel.write(sample); } } }
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); for (List<Sample> samples : chunkList) { for (Sample sample : samples) { sample.writeTo(writableByteChannel); } } }