当前位置: 首页>>代码示例>>Java>>正文


Java ParsableByteArray.setLimit方法代码示例

本文整理汇总了Java中com.google.android.exoplayer2.util.ParsableByteArray.setLimit方法的典型用法代码示例。如果您正苦于以下问题:Java ParsableByteArray.setLimit方法的具体用法?Java ParsableByteArray.setLimit怎么用?Java ParsableByteArray.setLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.exoplayer2.util.ParsableByteArray的用法示例。


在下文中一共展示了ParsableByteArray.setLimit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: appendNumberOfSamples

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
static void appendNumberOfSamples(ParsableByteArray buffer,
    long packetSampleCount) {

  buffer.setLimit(buffer.limit() + 4);
  // The vorbis decoder expects the number of samples in the packet
  // to be appended to the audio data as an int32
  buffer.data[buffer.limit() - 4] = (byte) ((packetSampleCount) & 0xFF);
  buffer.data[buffer.limit() - 3] = (byte) ((packetSampleCount >>> 8) & 0xFF);
  buffer.data[buffer.limit() - 2] = (byte) ((packetSampleCount >>> 16) & 0xFF);
  buffer.data[buffer.limit() - 1] = (byte) ((packetSampleCount >>> 24) & 0xFF);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:12,代码来源:VorbisReader.java

示例2: decode

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Decodes ID3 tags.
 *
 * @param data The bytes to decode ID3 tags from.
 * @param size Amount of bytes in {@code data} to read.
 * @return A {@link Metadata} object containing the decoded ID3 tags.
 */
public Metadata decode(byte[] data, int size) {
  List<Id3Frame> id3Frames = new ArrayList<>();
  ParsableByteArray id3Data = new ParsableByteArray(data, size);

  Id3Header id3Header = decodeHeader(id3Data);
  if (id3Header == null) {
    return null;
  }

  int startPosition = id3Data.getPosition();
  int frameHeaderSize = id3Header.majorVersion == 2 ? 6 : 10;
  int framesSize = id3Header.framesSize;
  if (id3Header.isUnsynchronized) {
    framesSize = removeUnsynchronization(id3Data, id3Header.framesSize);
  }
  id3Data.setLimit(startPosition + framesSize);

  boolean unsignedIntFrameSizeHack = false;
  if (!validateFrames(id3Data, id3Header.majorVersion, frameHeaderSize, false)) {
    if (id3Header.majorVersion == 4 && validateFrames(id3Data, 4, frameHeaderSize, true)) {
      unsignedIntFrameSizeHack = true;
    } else {
      Log.w(TAG, "Failed to validate ID3 tag with majorVersion=" + id3Header.majorVersion);
      return null;
    }
  }

  while (id3Data.bytesLeft() >= frameHeaderSize) {
    Id3Frame frame = decodeFrame(id3Header.majorVersion, id3Data, unsignedIntFrameSizeHack,
        frameHeaderSize, framePredicate);
    if (frame != null) {
      id3Frames.add(frame);
    }
  }

  return new Metadata(id3Frames);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:45,代码来源:Id3Decoder.java

示例3: consume

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
public final void consume(ParsableByteArray data, boolean payloadUnitStartIndicator) {
  if (payloadUnitStartIndicator) {
    switch (state) {
      case STATE_FINDING_HEADER:
      case STATE_READING_HEADER:
        // Expected.
        break;
      case STATE_READING_HEADER_EXTENSION:
        Log.w(TAG, "Unexpected start indicator reading extended header");
        break;
      case STATE_READING_BODY:
        // If payloadSize == -1 then the length of the previous packet was unspecified, and so
        // we only know that it's finished now that we've seen the start of the next one. This
        // is expected. If payloadSize != -1, then the length of the previous packet was known,
        // but we didn't receive that amount of data. This is not expected.
        if (payloadSize != -1) {
          Log.w(TAG, "Unexpected start indicator: expected " + payloadSize + " more bytes");
        }
        // Either way, notify the reader that it has now finished.
        reader.packetFinished();
        break;
    }
    setState(STATE_READING_HEADER);
  }

  while (data.bytesLeft() > 0) {
    switch (state) {
      case STATE_FINDING_HEADER:
        data.skipBytes(data.bytesLeft());
        break;
      case STATE_READING_HEADER:
        if (continueRead(data, pesScratch.data, HEADER_SIZE)) {
          setState(parseHeader() ? STATE_READING_HEADER_EXTENSION : STATE_FINDING_HEADER);
        }
        break;
      case STATE_READING_HEADER_EXTENSION:
        int readLength = Math.min(MAX_HEADER_EXTENSION_SIZE, extendedHeaderLength);
        // Read as much of the extended header as we're interested in, and skip the rest.
        if (continueRead(data, pesScratch.data, readLength)
            && continueRead(data, null, extendedHeaderLength)) {
          parseHeaderExtension();
          reader.packetStarted(timeUs, dataAlignmentIndicator);
          setState(STATE_READING_BODY);
        }
        break;
      case STATE_READING_BODY:
        readLength = data.bytesLeft();
        int padding = payloadSize == -1 ? 0 : readLength - payloadSize;
        if (padding > 0) {
          readLength -= padding;
          data.setLimit(data.getPosition() + readLength);
        }
        reader.consume(data);
        if (payloadSize != -1) {
          payloadSize -= readLength;
          if (payloadSize == 0) {
            reader.packetFinished();
            setState(STATE_READING_HEADER);
          }
        }
        break;
    }
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:66,代码来源:PesReader.java

示例4: sniffInternal

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static boolean sniffInternal(ExtractorInput input, boolean fragmented)
    throws IOException, InterruptedException {
  long inputLength = input.getLength();
  int bytesToSearch = (int) (inputLength == C.LENGTH_UNSET || inputLength > SEARCH_LENGTH
      ? SEARCH_LENGTH : inputLength);

  ParsableByteArray buffer = new ParsableByteArray(64);
  int bytesSearched = 0;
  boolean foundGoodFileType = false;
  boolean isFragmented = false;
  while (bytesSearched < bytesToSearch) {
    // Read an atom header.
    int headerSize = Atom.HEADER_SIZE;
    buffer.reset(headerSize);
    input.peekFully(buffer.data, 0, headerSize);
    long atomSize = buffer.readUnsignedInt();
    int atomType = buffer.readInt();
    if (atomSize == Atom.LONG_SIZE_PREFIX) {
      headerSize = Atom.LONG_HEADER_SIZE;
      input.peekFully(buffer.data, Atom.HEADER_SIZE, Atom.LONG_HEADER_SIZE - Atom.HEADER_SIZE);
      buffer.setLimit(Atom.LONG_HEADER_SIZE);
      atomSize = buffer.readUnsignedLongToLong();
    }

    if (atomSize < headerSize) {
      // The file is invalid because the atom size is too small for its header.
      return false;
    }
    bytesSearched += headerSize;

    if (atomType == Atom.TYPE_moov) {
      // Check for an mvex atom inside the moov atom to identify whether the file is fragmented.
      continue;
    }

    if (atomType == Atom.TYPE_moof || atomType == Atom.TYPE_mvex) {
      // The movie is fragmented. Stop searching as we must have read any ftyp atom already.
      isFragmented = true;
      break;
    }

    if (bytesSearched + atomSize - headerSize >= bytesToSearch) {
      // Stop searching as peeking this atom would exceed the search limit.
      break;
    }

    int atomDataSize = (int) (atomSize - headerSize);
    bytesSearched += atomDataSize;
    if (atomType == Atom.TYPE_ftyp) {
      // Parse the atom and check the file type/brand is compatible with the extractors.
      if (atomDataSize < 8) {
        return false;
      }
      buffer.reset(atomDataSize);
      input.peekFully(buffer.data, 0, atomDataSize);
      int brandsCount = atomDataSize / 4;
      for (int i = 0; i < brandsCount; i++) {
        if (i == 1) {
          // This index refers to the minorVersion, not a brand, so skip it.
          buffer.skipBytes(4);
        } else if (isCompatibleBrand(buffer.readInt())) {
          foundGoodFileType = true;
          break;
        }
      }
      if (!foundGoodFileType) {
        // The types were not compatible and there is only one ftyp atom, so reject the file.
        return false;
      }
    } else if (atomDataSize != 0) {
      // Skip the atom.
      input.advancePeekPosition(atomDataSize);
    }
  }
  return foundGoodFileType && fragmented == isFragmented;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:77,代码来源:Sniffer.java


注:本文中的com.google.android.exoplayer2.util.ParsableByteArray.setLimit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。