Example #1
0
  public static final void writeAsBytes(PrimerPack primerPack, ByteBuffer buffer)
      throws NullPointerException, InsufficientSpaceException {

    if (primerPack == null)
      throw new NullPointerException("Cannot write a null primer pack to a buffer.");
    if (buffer == null)
      throw new NullPointerException("Cannot write a primer pack into a null buffer.");

    if (buffer.remaining() < lengthAsBytes(primerPack))
      throw new InsufficientSpaceException(
          "Insufficient space remaining to write primer pack into given buffer.");

    UL key =
        (UL)
            Forge.makeAUID(
                0x0d010201,
                (short) 0x0105,
                (short) 0x0100,
                new byte[] {0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01});
    MXFBuilder.writeKey(key, buffer);
    MXFBuilder.writeBERLength(18 * primerPack.countLocalTagEntries() + 8, 4, buffer);

    buffer.putInt(primerPack.countLocalTagEntries());
    buffer.putInt(18);

    for (LocalTagEntry entry : primerPack.getLocalTagEntryBatch()) {
      buffer.putShort(entry.getLocalTag());
      MXFBuilder.writeKey((UL) entry.getUID(), buffer);
    }
  }
Example #2
0
  public static final PrimerPack createFromBytes(ByteBuffer buffer) throws EndOfDataException {

    UL key = MXFBuilder.readKey(buffer);
    long length = MXFBuilder.readBERLength(buffer);
    int preserveLimit = buffer.limit();
    PrimerPack primerPack = null;

    try {
      buffer.limit((int) (buffer.position() + length));
      primerPack = (PrimerPack) MXFBuilder.readFixedLengthPack((AUIDImpl) key, buffer);
    } finally {
      buffer.limit(preserveLimit);
    }

    return primerPack;
  }
Example #3
0
  public static final long addPropertiesForObject(PrimerPack primerPack, MetadataObject mdObject)
      throws NullPointerException {

    if (primerPack == null)
      throw new NullPointerException("Cannot add local tag entries to a null primer pack.");
    if (mdObject == null)
      throw new NullPointerException(
          "Cannot add local tag entries to a primer pack using a null metadata object.");

    ClassDefinition objectsClass = MediaEngine.getClassDefinition(mdObject);
    long setLength =
        MXFBuilder.lengthOfLocalSet(mdObject)
            + 20l; // Bytes in value plus initial class ID and 4-byte length

    for (PropertyDefinition propertyDefinition : objectsClass.getAllPropertyDefinitions()) {

      PropertyValue propertyValue = null;
      try {
        if (propertyDefinition.getIsOptional()) propertyDefinition.getPropertyValue(mdObject);
      } catch (IllegalArgumentException iae) {
        continue;
      } catch (PropertyNotPresentException pnpe) {
        continue;
      }

      primerPack.addLocalTagEntry(propertyDefinition);

      TypeDefinition propertyType = propertyDefinition.getTypeDefinition();

      switch (propertyType.getTypeCategory()) {
        case StrongObjRef:
          if (propertyValue == null) propertyValue = propertyDefinition.getPropertyValue(mdObject);
          MetadataObject stronglyReferencedObject = (MetadataObject) propertyValue.getValue();
          setLength += addPropertiesForObject(primerPack, stronglyReferencedObject);
          break;
        case Set:
          if (propertyValue == null) propertyValue = propertyDefinition.getPropertyValue(mdObject);
          TypeDefinition setElementType = ((TypeDefinitionSet) propertyType).getElementType();

          if (setElementType instanceof TypeDefinitionStrongObjectReference) {
            Set<?> setValues = (Set<?>) propertyValue.getValue();
            for (Object value : setValues)
              setLength += addPropertiesForObject(primerPack, (MetadataObject) value);
          }
          break;
        case VariableArray:
          if (propertyValue == null) propertyValue = propertyDefinition.getPropertyValue(mdObject);
          TypeDefinition arrayElementType = ((TypeDefinitionVariableArray) propertyType).getType();

          if (arrayElementType instanceof TypeDefinitionStrongObjectReference) {
            List<?> arrayValues = (List<?>) propertyValue.getValue();
            for (Object value : arrayValues)
              setLength += addPropertiesForObject(primerPack, (MetadataObject) value);
          }
          break;
        default:
          break;
      }
    }

    // Add local tags defined in the index packs
    PrimerPack indexPrimerPack = new IndexPrimerPackImpl();
    for (LocalTagEntry tagEntry : indexPrimerPack.getLocalTagEntryBatch()) {
      primerPack.addLocalTagEntry(tagEntry);
    }

    return setLength;
  }