private MetaBox getMetaBox() { if (metaBox == null) { UserDataBox ud = getUserDataBox(); metaBox = (MetaBox) getBox(ud, MetaBox.TYPE); if (metaBox == null) { metaBox = new MetaBox(); ud.addBox(metaBox); } } return metaBox; }
private AppleItemListBox getItemListBox() { AppleItemListBox itemList = (AppleItemListBox) getBox(isoFile, AppleItemListBox.TYPE); if (itemList == null) { MetaBox mb = getMetaBox(); itemList = new AppleItemListBox(); mb.addBox(itemList); } return itemList; }
@Override public long getSize() { long s = getContainerSize(); long t = quickTimeFormat ? 0 : 4; // bytes to container start return s + t + ((largeBox || (s + t) >= (1L << 32)) ? 16 : 8); } }
@Override public void getBox(WritableByteChannel writableByteChannel) throws IOException { writableByteChannel.write(getHeader()); if (!quickTimeFormat) { ByteBuffer bb = ByteBuffer.allocate(4); writeVersionAndFlags(bb); writableByteChannel.write((ByteBuffer) bb.rewind()); } writeContainer(writableByteChannel); }
@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { // Read first 20 bytes to determine whether the file is formatted according to QuickTime File Format. RewindableReadableByteChannel rewindableDataSource = new RewindableReadableByteChannel(dataSource, 20); ByteBuffer bb = ByteBuffer.allocate(20); int bytesRead = rewindableDataSource.read(bb); if (bytesRead == 20) { // If the second and the fifth 32-bit integers encode 'hdlr' and 'mdta' respectively then the MetaBox is // formatted according to QuickTime File Format. // See https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html bb.position(4); String second4cc = IsoTypeReader.read4cc(bb); bb.position(16); String fifth4cc = IsoTypeReader.read4cc(bb); if ("hdlr".equals(second4cc) && "mdta".equals(fifth4cc)) { quickTimeFormat = true; } } rewindableDataSource.rewind(); if (!quickTimeFormat) { bb = ByteBuffer.allocate(4); rewindableDataSource.read(bb); parseVersionAndFlags((ByteBuffer) bb.rewind()); } int bytesUsed = quickTimeFormat ? 0 : 4; initContainer(rewindableDataSource, contentSize - bytesUsed, boxParser); }
UserDataBox userDataBox; long sizeBefore; if ((userDataBox = Path.getPath(tempIsoFile, "/moov/udta")) == null) { sizeBefore = 0; userDataBox = new UserDataBox(); tempIsoFile.getMovieBox().addBox(userDataBox); } else { sizeBefore = userDataBox.getSize(); } MetaBox metaBox; if ((metaBox = Path.getPath(userDataBox, "meta")) == null) { metaBox = new MetaBox(); userDataBox.addBox(metaBox); } XmlBox xmlBox = new XmlBox(); xmlBox.setXml(text); metaBox.addBox(xmlBox);
@Override public void getBox(WritableByteChannel writableByteChannel) throws IOException { writableByteChannel.write(getHeader()); if (!quickTimeFormat) { ByteBuffer bb = ByteBuffer.allocate(4); writeVersionAndFlags(bb); writableByteChannel.write((ByteBuffer) bb.rewind()); } writeContainer(writableByteChannel); }
@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { // Read first 20 bytes to determine whether the file is formatted according to QuickTime File Format. RewindableReadableByteChannel rewindableDataSource = new RewindableReadableByteChannel(dataSource, 20); ByteBuffer bb = ByteBuffer.allocate(20); int bytesRead = rewindableDataSource.read(bb); if (bytesRead == 20) { // If the second and the fifth 32-bit integers encode 'hdlr' and 'mdta' respectively then the MetaBox is // formatted according to QuickTime File Format. // See https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html bb.position(4); String second4cc = IsoTypeReader.read4cc(bb); bb.position(16); String fifth4cc = IsoTypeReader.read4cc(bb); if ("hdlr".equals(second4cc) && "mdta".equals(fifth4cc)) { quickTimeFormat = true; } } rewindableDataSource.rewind(); if (!quickTimeFormat) { bb = ByteBuffer.allocate(4); rewindableDataSource.read(bb); parseVersionAndFlags((ByteBuffer) bb.rewind()); } int bytesUsed = quickTimeFormat ? 0 : 4; initContainer(rewindableDataSource, contentSize - bytesUsed, boxParser); }
@Override public long getSize() { long s = getContainerSize(); long t = quickTimeFormat ? 0 : 4; // bytes to container start return s + t + ((largeBox || (s + t) >= (1L << 32)) ? 16 : 8); } }