From b0d7c7c99330d582d4a8f13919520885304ee86f Mon Sep 17 00:00:00 2001 From: swamikevala Date: Tue, 9 Nov 2021 20:32:48 +0530 Subject: [PATCH 1/4] Moved DeltaEntry and IndexEntry registryInterfaceMapping calls to before call to Wareouse.registerTypes (as they were not getting run) --- src/main/java/tv/amwa/maj/io/mxf/MXFBuilder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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..e41052a 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; } From 4a824f922629b3ccc3350e3be58b7650081e9a1e Mon Sep 17 00:00:00 2001 From: swamikevala Date: Fri, 12 Nov 2021 16:37:57 +0530 Subject: [PATCH 2/4] Added writeToBuffer() and lengthAsBuffer() methods to IndexEntryImpl so that optional Index Entry properties (sliceOffset, posTable) are picked up --- .../java/tv/amwa/maj/io/mxf/MXFBuilder.java | 2 +- .../amwa/maj/io/mxf/impl/IndexEntryImpl.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) 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 e41052a..41c4dd2 100644 --- a/src/main/java/tv/amwa/maj/io/mxf/MXFBuilder.java +++ b/src/main/java/tv/amwa/maj/io/mxf/MXFBuilder.java @@ -746,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; + } } From 6f37f937a79ad14b1d2d68998fc732a568f76b40 Mon Sep 17 00:00:00 2001 From: swamikevala Date: Thu, 18 Nov 2021 16:13:51 +0530 Subject: [PATCH 3/4] RandomIndexPack.createFromBytes() method: removed lines that read the key and length, since these are already read in MXFStream.readRandomIndexPack() causing this method to read them twice. --- .../java/tv/amwa/maj/io/mxf/impl/RandomIndexPackImpl.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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; From 17b331afd5daf07104c80819be6755530c73cfe2 Mon Sep 17 00:00:00 2001 From: swamikevala Date: Mon, 25 Jul 2022 14:41:16 +0530 Subject: [PATCH 4/4] re-ordered IndexTableSegment properties to work around Adobe Premiere import bug --- .../java/tv/amwa/maj/io/mxf/impl/IndexTableSegmentImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 {