diff --git a/src/main/java/tv/amwa/maj/io/mxf/MXFBuilder.java b/src/main/java/tv/amwa/maj/io/mxf/MXFBuilder.java index 630e965..41c4dd2 100644 --- a/src/main/java/tv/amwa/maj/io/mxf/MXFBuilder.java +++ b/src/main/java/tv/amwa/maj/io/mxf/MXFBuilder.java @@ -107,10 +107,11 @@ public final static synchronized void registerMXF() { Warehouse.lookForClass(PrimerPackImpl.class); Warehouse.lookForClass(RandomIndexPackImpl.class); Warehouse.lookForClass(IndexTableSegmentImpl.class); - Warehouse.registerTypes(TypeDefinitions.class, MXFConstants.RP210_NAMESPACE, MXFConstants.RP210_PREFIX); - + TypeDefinitionRecordImpl.registerInterfaceMapping(DeltaEntry.class, DeltaEntryImpl.class); TypeDefinitionRecordImpl.registerInterfaceMapping(IndexEntry.class, IndexEntryImpl.class); + + Warehouse.registerTypes(TypeDefinitions.class, MXFConstants.RP210_NAMESPACE, MXFConstants.RP210_PREFIX); mxfRegistration = true; } @@ -745,7 +746,7 @@ private final static long writeToLocalSet( throws NullPointerException { if (toWrite == null) - throw new NullPointerException("Cannot calculat the length as a local set value for a null metadata object."); + throw new NullPointerException("Cannot calculate the length as a local set value for a null metadata object."); ClassDefinition classOfMetadata = MediaEngine.getClassDefinition(toWrite); SortedMap properties = classOfMetadata.getProperties(toWrite); diff --git a/src/main/java/tv/amwa/maj/io/mxf/impl/IndexEntryImpl.java b/src/main/java/tv/amwa/maj/io/mxf/impl/IndexEntryImpl.java index 46cc7fe..b29e971 100644 --- a/src/main/java/tv/amwa/maj/io/mxf/impl/IndexEntryImpl.java +++ b/src/main/java/tv/amwa/maj/io/mxf/impl/IndexEntryImpl.java @@ -24,6 +24,7 @@ import org.w3c.dom.Node; import tv.amwa.maj.exception.EndOfDataException; +import tv.amwa.maj.exception.InsufficientSpaceException; import tv.amwa.maj.exception.PropertyNotPresentException; import tv.amwa.maj.integer.Int8; import tv.amwa.maj.integer.UInt32Array; @@ -401,5 +402,43 @@ public final static IndexEntry createFromBuffer( return new IndexEntryImpl(temporalOffset, keyFrameOffset, flags, streamOffset, unresolvedBytes); } + + public final static void writeToBuffer( + IndexEntry entry, + ByteBuffer buffer) + throws NullPointerException, + InsufficientSpaceException { + + if (entry == null) + throw new NullPointerException("Cannot write a null index entry to a buffer."); + if (buffer == null) + throw new NullPointerException("Cannot write an index entry to a null buffer."); + + if (buffer.remaining() < lengthAsBuffer(entry)) + throw new InsufficientSpaceException("Insufficient space in the given buffer to write an index entry value."); + + buffer.put(entry.getTemporalOffset()); + buffer.put(entry.getKeyFrameOffset()); + buffer.put(entry.getFlags()); + buffer.putLong(entry.getStreamOffset()); + for (int offset : entry.getSliceOffset()) { + buffer.putInt(offset); + } + for (Rational pos : entry.getPosTable()) { + buffer.putInt(pos.getNumerator()); + buffer.putInt(pos.getDenominator()); + } + + } + + public final static long lengthAsBuffer( + IndexEntry value) { + + long length = 11l; + length += 4*value.getSliceOffset().length; + length += 8*value.getPosTable().length; + + return length; + } } diff --git a/src/main/java/tv/amwa/maj/io/mxf/impl/IndexTableSegmentImpl.java b/src/main/java/tv/amwa/maj/io/mxf/impl/IndexTableSegmentImpl.java index cc135c0..11b971c 100644 --- a/src/main/java/tv/amwa/maj/io/mxf/impl/IndexTableSegmentImpl.java +++ b/src/main/java/tv/amwa/maj/io/mxf/impl/IndexTableSegmentImpl.java @@ -389,7 +389,11 @@ public void setDeltaEntries( optional = true, uniqueIdentifier = false, pid = 0x3f0a, - symbol = "IndexEntryArray") + symbol = "IndexEntryArray", + // Make this come last in the local set, since it depends on sliceCount and posTableCount values + // As per the MXF spec this ordering should not be needed, but if we don't do this + // Adobe PremierPro 2022 can't import the files - Adobe pls fix your product! + weight = 2147483647) public IndexEntry[] getIndexEntryArray() throws PropertyNotPresentException { diff --git a/src/main/java/tv/amwa/maj/io/mxf/impl/RandomIndexPackImpl.java b/src/main/java/tv/amwa/maj/io/mxf/impl/RandomIndexPackImpl.java index 7283b2d..a7fd576 100644 --- a/src/main/java/tv/amwa/maj/io/mxf/impl/RandomIndexPackImpl.java +++ b/src/main/java/tv/amwa/maj/io/mxf/impl/RandomIndexPackImpl.java @@ -271,13 +271,7 @@ public static RandomIndexPack createFromBytes( ByteBuffer ripBytes) throws BufferUnderflowException { - UL ripKey = MXFBuilder.readKey(ripBytes); - if (ripKey == null) - return null; - if (!ripKeyValue.equals(ripKey)) - return null; - - long ripLength = MXFBuilder.readBERLength(ripBytes); + long ripLength = ripBytes.array().length; int ripItemCount = (int) (ripLength - 4) / 12; // If remainder, the random index pack is corrupt in some way. if (((ripLength - 4) % 12) != 0) return null;