Exemplo n.º 1
0
 public void parse(IsoBufferWrapper in, long size, BoxParser boxParser, Box lastMovieFragmentBox)
     throws IOException {
   super.parse(in, size, boxParser, lastMovieFragmentBox);
   classificationEntity = IsoFile.bytesToFourCC(in.read(4));
   classificationTableIndex = in.readUInt16();
   language = in.readIso639();
   classificationInfo = in.readString();
 }
 @Override
 public void parse(IsoBufferWrapper in, long size, BoxParser boxParser, Box lastMovieFragmentBox)
     throws IOException {
   super.parse(in, size, boxParser, lastMovieFragmentBox);
   dataReferenceType = in.readString(4);
   dataReferenceSize = in.readUInt32();
   dataReference = in.readString((int) dataReferenceSize);
 }
 private long getVariable(long length, IsoBufferWrapper in) throws IOException {
   long ret;
   if (((length + 1) * 8) == 8) {
     ret = in.readUInt8();
   } else if (((length + 1) * 8) == 16) {
     ret = in.readUInt16();
   } else if (((length + 1) * 8) == 24) {
     ret = in.readUInt24();
   } else if (((length + 1) * 8) == 32) {
     ret = in.readUInt32();
   } else if (((length + 1) * 8) == 64) {
     ret = in.readUInt64();
   } else {
     throw new IOException("lengthSize not power of two");
   }
   return ret;
 }
  @Override
  public void parse(int tag, IsoBufferWrapper in, int maxLength) throws IOException {
    super.parse(tag, in, maxLength);

    if (getSize() > 0) {
      bytes = in.read(getSize());
    }
  }
  @Override
  public void parse(IsoBufferWrapper in, long size, BoxParser boxParser, Box lastMovieFragmentBox)
      throws IOException {
    super.parse(in, size, boxParser, lastMovieFragmentBox);

    trackId = in.readUInt32();
    long temp = in.readUInt32();
    reserved = (int) (temp >> 6);
    lengthSizeOfTrafNum = (int) (temp & 0x3F) >> 4;
    lengthSizeOfTrunNum = (int) (temp & 0xC) >> 2;
    lengthSizeOfSampleNum = (int) (temp & 0x3);
    long numberOfEntries = in.readUInt32();

    entries = new ArrayList<Entry>();

    for (int i = 0; i < numberOfEntries; i++) {
      Entry entry = new Entry();
      if (getVersion() == 1) {
        entry.time = in.readUInt64();
        entry.moofOffset = in.readUInt64();
      } else {
        entry.time = in.readUInt32();
        entry.moofOffset = in.readUInt32();
      }
      entry.trafNumber = getVariable(lengthSizeOfTrafNum, in);
      entry.trunNumber = getVariable(lengthSizeOfTrunNum, in);
      entry.sampleNumber = getVariable(lengthSizeOfSampleNum, in);

      entries.add(entry);
    }
  }
  public RawH264Track(IsoBufferWrapperImpl rawH264) throws IOException {
    InnerAccessUnit current = new InnerAccessUnit();
    InnerAccessUnit previous = new InnerAccessUnit();

    NALUnitReader nalUnitReader = new AnnexBNALUnitReader(rawH264);
    AccessUnitSourceImpl accessUnitSource = new AccessUnitSourceImpl(nalUnitReader);
    streamParams = accessUnitSource;
    SliceHeaderReader sliceHeaderReader = new SliceHeaderReader(accessUnitSource);
    AccessUnit au;
    long frameNumInGop = 0;
    while ((au = accessUnitSource.nextAccessUnit()) != null) {
      // System.err.println("Start AU");
      List<IsoBufferWrapper> nals = new LinkedList<IsoBufferWrapper>();
      IsoBufferWrapper nalUnitBuffer;
      while ((nalUnitBuffer = au.nextNALUnit()) != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new IsoOutputStream(baos).writeUInt32(nalUnitBuffer.size());
        nals.add(new IsoBufferWrapperImpl(baos.toByteArray()));
        nals.add(nalUnitBuffer);
        NALUnit nalUnit = NALUnit.read(nalUnitBuffer);
        if (nalUnit.type == NALUnitType.IDR_SLICE
            || nalUnit.type == NALUnitType.NON_IDR_SLICE
            || nalUnit.type == NALUnitType.AUX_SLICE
            || nalUnit.type == NALUnitType.SLICE_PART_A
            || nalUnit.type == NALUnitType.SLICE_PART_B
            || nalUnit.type == NALUnitType.SLICE_PART_C) {
          current.sliceHeaders.add(sliceHeaderReader.read(nalUnit, new CAVLCReader(nalUnitBuffer)));
        }

        if (++a % 1000 == 0) {
          System.err.println(a);
        }
      }
      samples.add(new MultiplexIsoBufferWrapperImpl(nals));
      decodedPoc(current, previous);
      if (current.poc == 0) {
        frameNumInGop = 0;
      }
      System.err.println("cts: " + (current.poc - frameNumInGop * 2));
      previous = current;
      frameNumInGop++;
      current = new InnerAccessUnit();
    }
  }
  public IsoBufferWrapper nextNALUnit() throws IOException {
    if (src.remaining() < 5) {
      return null;
    }

    long nalLength;
    if (src.remaining() >= nalLengthSize) {
      // nalLength = src.read(nalLengthSize);
      nalLength = src.readUInt32();
      if (nalLength == 0) return null;

      IsoBufferWrapper segment = src.getSegment(src.position(), nalLength);
      src.position(src.position() + nalLength);
      return segment;
    } else {
      throw new RuntimeException(
          "remaining bytes less than nalLengthSize found in sample. should not be here.");
    }
  }
 @Override
 public void parse(IsoBufferWrapper in, long size, BoxParser boxParser, Box lastMovieFragmentBox)
     throws IOException {
   super.parse(in, size, boxParser, lastMovieFragmentBox);
   maxSamplePerFrame = in.readUInt32();
   unknown1 = in.readUInt8();
   sampleSize = in.readUInt8();
   historyMult = in.readUInt8();
   initialHistory = in.readUInt8();
   kModifier = in.readUInt8();
   channels = in.readUInt8();
   unknown2 = in.readUInt16();
   maxCodedFrameSize = in.readUInt32();
   bitRate = in.readUInt32();
   sampleRate = in.readUInt32();
 }