Ejemplo n.º 1
0
  /**
   * @param header parentHeader info
   * @param dataBuffer data of box (doesnt include parentHeader data)
   */
  public Mp4NameBox(Mp4BoxHeader header, ByteBuffer dataBuffer) {
    this.header = header;

    // Double check
    if (!header.getId().equals(IDENTIFIER)) {
      throw new RuntimeException(
          "Unable to process name box because identifier is:" + header.getId());
    }

    // Make slice so operations here don't effect position of main buffer
    this.dataBuffer = dataBuffer.slice();

    // issuer
    this.name =
        Utils.getString(
            this.dataBuffer,
            PRE_DATA_LENGTH,
            header.getDataLength() - PRE_DATA_LENGTH,
            header.getEncoding());
  }
Ejemplo n.º 2
0
  /**
   * @param header parentHeader info
   * @param dataBuffer data of box (doesnt include parentHeader data)
   */
  public Mp4DataBox(Mp4BoxHeader header, ByteBuffer dataBuffer) {
    this.header = header;
    // Double check
    if (!header.getId().equals(IDENTIFIER)) {
      throw new RuntimeException(
          "Unable to process data box because identifier is:" + header.getId());
    }

    // Make slice so operations here don't effect position of main buffer
    this.dataBuffer = dataBuffer.slice();

    // Type
    type =
        Utils.getIntBE(
            this.dataBuffer, Mp4DataBox.TYPE_POS, Mp4DataBox.TYPE_POS + Mp4DataBox.TYPE_LENGTH - 1);

    if (type == Mp4FieldType.TEXT.getFileClassId()) {
      content =
          Utils.getString(
              this.dataBuffer,
              PRE_DATA_LENGTH,
              header.getDataLength() - PRE_DATA_LENGTH,
              header.getEncoding());
    } else if (type == Mp4FieldType.NUMERIC.getFileClassId()) {
      numbers = new ArrayList<Short>();

      for (int i = 0; i < ((header.getDataLength() - PRE_DATA_LENGTH) / NUMBER_LENGTH); i++) {
        short number =
            Utils.getShortBE(
                this.dataBuffer,
                PRE_DATA_LENGTH + (i * NUMBER_LENGTH),
                PRE_DATA_LENGTH + (i * NUMBER_LENGTH) + (NUMBER_LENGTH - 1));
        numbers.add(number);
      }

      // Make String representation  (separate values with slash)
      StringBuffer sb = new StringBuffer();
      ListIterator<Short> iterator = numbers.listIterator();
      while (iterator.hasNext()) {
        sb.append(iterator.next());
        if (iterator.hasNext()) {
          sb.append("/");
        }
      }
      content = sb.toString();
    } else if (type == Mp4FieldType.BYTE.getFileClassId()) {
      // TODO byte data length seems to be 1 for pgap and cpil but 2 for tmpo ?
      // Create String representation for display
      content = Utils.getIntBE(this.dataBuffer, PRE_DATA_LENGTH, header.getDataLength() - 1) + "";

      // But store data for safer writng back to file
      bytedata = new byte[header.getDataLength() - PRE_DATA_LENGTH];
      int pos = dataBuffer.position();
      dataBuffer.position(pos + PRE_DATA_LENGTH);
      dataBuffer.get(bytedata);
      dataBuffer.position(pos);
    } else if (type == Mp4FieldType.COVERART_JPEG.getFileClassId()) {
      content =
          Utils.getString(
              this.dataBuffer,
              PRE_DATA_LENGTH,
              header.getDataLength() - PRE_DATA_LENGTH,
              header.getEncoding());
    }
  }