@Override
 protected long getContentSize() {
   long entries = 8 + ((4 + 2) * entryCount);
   int subsampleEntries = 0;
   for (SampleEntry sampleEntry : this.entries) {
     subsampleEntries +=
         sampleEntry.getSubsampleCount() * (((getVersion() == 1) ? 4 : 2) + 1 + 1 + 4);
   }
   return entries + subsampleEntries;
 }
  public void parse(ByteBuffer input) {
    super.parse(input);

    version = input.getShort();
    revision = input.getShort();
    vendor = input.getInt();

    channelCount = input.getShort();
    sampleSize = input.getShort();

    compressionId = input.getShort();
    pktSize = input.getShort();

    long sr = input.getInt() & 0xffffffffL;
    sampleRate = (float) sr / 65536f;

    if (version == 1) {
      samplesPerPkt = input.getInt();
      bytesPerPkt = input.getInt();
      bytesPerFrame = input.getInt();
      bytesPerSample = input.getInt();
    } else if (version == 2) {
      input.getInt(); /* sizeof struct only */
      sampleRate = (float) Double.longBitsToDouble(input.getLong());
      channelCount = (short) input.getInt();
      input.getInt(); /* always 0x7F000000 */
      sampleSize = (short) input.getInt();
      lpcmFlags = (int) input.getInt();
      bytesPerFrame = (int) input.getInt();
      samplesPerPkt = (int) input.getInt();
    }
    parseExtensions(input);
  }
 @Override
 protected void getContent(ByteBuffer byteBuffer) {
   writeVersionAndFlags(byteBuffer);
   IsoTypeWriter.writeUInt32(byteBuffer, entries.size());
   for (SampleEntry sampleEntry : entries) {
     IsoTypeWriter.writeUInt32(byteBuffer, sampleEntry.getSampleDelta());
     IsoTypeWriter.writeUInt16(byteBuffer, sampleEntry.getSubsampleCount());
     List<SampleEntry.SubsampleEntry> subsampleEntries = sampleEntry.getSubsampleEntries();
     for (SampleEntry.SubsampleEntry subsampleEntry : subsampleEntries) {
       if (getVersion() == 1) {
         IsoTypeWriter.writeUInt32(byteBuffer, subsampleEntry.getSubsampleSize());
       } else {
         IsoTypeWriter.writeUInt16(byteBuffer, l2i(subsampleEntry.getSubsampleSize()));
       }
       IsoTypeWriter.writeUInt8(byteBuffer, subsampleEntry.getSubsamplePriority());
       IsoTypeWriter.writeUInt8(byteBuffer, subsampleEntry.getDiscardable());
       IsoTypeWriter.writeUInt32(byteBuffer, subsampleEntry.getReserved());
     }
   }
 }
  @Override
  public void _parseDetails(ByteBuffer content) {
    parseVersionAndFlags(content);

    entryCount = IsoTypeReader.readUInt32(content);

    for (int i = 0; i < entryCount; i++) {
      SampleEntry sampleEntry = new SampleEntry();
      sampleEntry.setSampleDelta(IsoTypeReader.readUInt32(content));
      int subsampleCount = IsoTypeReader.readUInt16(content);
      for (int j = 0; j < subsampleCount; j++) {
        SampleEntry.SubsampleEntry subsampleEntry = new SampleEntry.SubsampleEntry();
        subsampleEntry.setSubsampleSize(
            getVersion() == 1
                ? IsoTypeReader.readUInt32(content)
                : IsoTypeReader.readUInt16(content));
        subsampleEntry.setSubsamplePriority(IsoTypeReader.readUInt8(content));
        subsampleEntry.setDiscardable(IsoTypeReader.readUInt8(content));
        subsampleEntry.setReserved(IsoTypeReader.readUInt32(content));
        sampleEntry.addSubsampleEntry(subsampleEntry);
      }
      entries.add(sampleEntry);
    }
  }
  protected void doWrite(ByteBuffer out) {
    super.doWrite(out);

    out.putShort(version);
    out.putShort(revision);
    out.putInt(vendor);

    if (version < 2) {
      out.putShort(channelCount);
      if (version == 0) out.putShort(sampleSize);
      else out.putShort((short) 16);

      out.putShort((short) compressionId);
      out.putShort((short) pktSize);

      out.putInt((int) Math.round(sampleRate * 65536d));

      if (version == 1) {
        out.putInt(samplesPerPkt);
        out.putInt(bytesPerPkt);
        out.putInt(bytesPerFrame);
        out.putInt(bytesPerSample);
      }
    } else if (version == 2) {
      out.putShort((short) 3);
      out.putShort((short) 16);
      out.putShort((short) -2);
      out.putShort((short) 0);
      out.putInt(65536);
      out.putInt(72);
      out.putLong(Double.doubleToLongBits(sampleRate));
      out.putInt(channelCount);
      out.putInt(0x7F000000);
      out.putInt(sampleSize);
      out.putInt(lpcmFlags);
      out.putInt(bytesPerFrame);
      out.putInt(samplesPerPkt);
    }
    writeExtensions(out);
  }