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


Java ParsableByteArray.limit方法代码示例

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


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

示例1: findHeader

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Attempts to locate the start of the next frame header.
 * <p>
 * If a frame header is located then the state is changed to {@link #STATE_READING_HEADER}, the
 * first two bytes of the header are written into {@link #headerScratch}, and the position of the
 * source is advanced to the byte that immediately follows these two bytes.
 * <p>
 * If a frame header is not located then the position of the source is advanced to the limit, and
 * the method should be called again with the next source to continue the search.
 *
 * @param source The source from which to read.
 */
private void findHeader(ParsableByteArray source) {
  byte[] data = source.data;
  int startOffset = source.getPosition();
  int endOffset = source.limit();
  for (int i = startOffset; i < endOffset; i++) {
    boolean byteIsFF = (data[i] & 0xFF) == 0xFF;
    boolean found = lastByteWasFF && (data[i] & 0xE0) == 0xE0;
    lastByteWasFF = byteIsFF;
    if (found) {
      source.setPosition(i + 1);
      // Reset lastByteWasFF for next time.
      lastByteWasFF = false;
      headerScratch.data[1] = data[i];
      frameBytesRead = 2;
      state = STATE_READING_HEADER;
      return;
    }
  }
  source.setPosition(endOffset);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:33,代码来源:MpegAudioReader.java

示例2: readSetupHeaders

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
VorbisSetup readSetupHeaders(ParsableByteArray scratch) throws IOException {

    if (vorbisIdHeader == null) {
      vorbisIdHeader = VorbisUtil.readVorbisIdentificationHeader(scratch);
      return null;
    }

    if (commentHeader == null) {
      commentHeader = VorbisUtil.readVorbisCommentHeader(scratch);
      return null;
    }

    // the third packet contains the setup header
    byte[] setupHeaderData = new byte[scratch.limit()];
    // raw data of vorbis setup header has to be passed to decoder as CSD buffer #2
    System.arraycopy(scratch.data, 0, setupHeaderData, 0, scratch.limit());
    // partially decode setup header to get the modes
    Mode[] modes = VorbisUtil.readVorbisModes(scratch, vorbisIdHeader.channels);
    // we need the ilog of modes all the time when extracting, so we compute it once
    int iLogModes = VorbisUtil.iLog(modes.length - 1);

    return new VorbisSetup(vorbisIdHeader, commentHeader, setupHeaderData, modes, iLogModes);
  }
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:24,代码来源:VorbisReader.java

示例3: maybeSkipComment

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static boolean maybeSkipComment(ParsableByteArray input) {
  int position = input.getPosition();
  int limit = input.limit();
  byte[] data = input.data;
  if (position + 2 <= limit && data[position++] == '/' && data[position++] == '*') {
    while (position + 1 < limit) {
      char skippedChar = (char) data[position++];
      if (skippedChar == '*') {
        if (((char) data[position]) == '/') {
          position++;
          limit = position;
        }
      }
    }
    input.skipBytes(limit - input.getPosition());
    return true;
  }
  return false;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:20,代码来源:CssParser.java

示例4: parseIdentifier

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static String parseIdentifier(ParsableByteArray input, StringBuilder stringBuilder) {
  stringBuilder.setLength(0);
  int position = input.getPosition();
  int limit = input.limit();
  boolean identifierEndFound = false;
  while (position  < limit && !identifierEndFound) {
    char c = (char) input.data[position];
    if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '#'
        || c == '-' || c == '.' || c == '_') {
      position++;
      stringBuilder.append(c);
    } else {
      identifierEndFound = true;
    }
  }
  input.skipBytes(position - input.getPosition());
  return stringBuilder.toString();
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:19,代码来源:CssParser.java

示例5: 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

示例6: parsePsshAtom

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Parses the UUID and scheme specific data from a PSSH atom. Version 0 and 1 PSSH atoms are
 * supported.
 *
 * @param atom The atom to parse.
 * @return A pair consisting of the parsed UUID and scheme specific data. Null if the input is
 *     not a valid PSSH atom, or if the PSSH atom has an unsupported version.
 */
private static Pair<UUID, byte[]> parsePsshAtom(byte[] atom) {
  ParsableByteArray atomData = new ParsableByteArray(atom);
  if (atomData.limit() < Atom.FULL_HEADER_SIZE + 16 /* UUID */ + 4 /* DataSize */) {
    // Data too short.
    return null;
  }
  atomData.setPosition(0);
  int atomSize = atomData.readInt();
  if (atomSize != atomData.bytesLeft() + 4) {
    // Not an atom, or incorrect atom size.
    return null;
  }
  int atomType = atomData.readInt();
  if (atomType != Atom.TYPE_pssh) {
    // Not an atom, or incorrect atom type.
    return null;
  }
  int atomVersion = Atom.parseFullAtomVersion(atomData.readInt());
  if (atomVersion > 1) {
    Log.w(TAG, "Unsupported pssh version: " + atomVersion);
    return null;
  }
  UUID uuid = new UUID(atomData.readLong(), atomData.readLong());
  if (atomVersion == 1) {
    int keyIdCount = atomData.readUnsignedIntToInt();
    atomData.skipBytes(16 * keyIdCount);
  }
  int dataSize = atomData.readUnsignedIntToInt();
  if (dataSize != atomData.bytesLeft()) {
    // Incorrect dataSize.
    return null;
  }
  byte[] data = new byte[dataSize];
  atomData.readBytes(data, 0, dataSize);
  return Pair.create(uuid, data);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:45,代码来源:PsshAtomUtil.java

示例7: readCueTarget

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Reads the contents of ::cue() and returns it as a string.
 */
private static String readCueTarget(ParsableByteArray input) {
  int position = input.getPosition();
  int limit = input.limit();
  boolean cueTargetEndFound = false;
  while (position < limit && !cueTargetEndFound) {
    char c = (char) input.data[position++];
    cueTargetEndFound = c == ')';
  }
  return input.readString(--position - input.getPosition()).trim();
  // --offset to return ')' to the input.
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:15,代码来源:CssParser.java

示例8: consume

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  int offset = data.getPosition();
  int limit = data.limit();
  byte[] dataArray = data.data;

  // Append the data to the buffer.
  totalBytesWritten += data.bytesLeft();
  output.sampleData(data, data.bytesLeft());

  int searchOffset = offset;
  while (true) {
    int startCodeOffset = NalUnitUtil.findNalUnit(dataArray, searchOffset, limit, prefixFlags);

    if (startCodeOffset == limit) {
      // We've scanned to the end of the data without finding another start code.
      if (!hasOutputFormat) {
        csdBuffer.onData(dataArray, offset, limit);
      }
      return;
    }

    // We've found a start code with the following value.
    int startCodeValue = data.data[startCodeOffset + 3] & 0xFF;

    if (!hasOutputFormat) {
      // This is the number of bytes from the current offset to the start of the next start
      // code. It may be negative if the start code started in the previously consumed data.
      int lengthToStartCode = startCodeOffset - offset;
      if (lengthToStartCode > 0) {
        csdBuffer.onData(dataArray, offset, startCodeOffset);
      }
      // This is the number of bytes belonging to the next start code that have already been
      // passed to csdDataTargetBuffer.
      int bytesAlreadyPassed = lengthToStartCode < 0 ? -lengthToStartCode : 0;
      if (csdBuffer.onStartCode(startCodeValue, bytesAlreadyPassed)) {
        // The csd data is complete, so we can decode and output the media format.
        Pair<Format, Long> result = parseCsdBuffer(csdBuffer, formatId);
        output.format(result.first);
        frameDurationUs = result.second;
        hasOutputFormat = true;
      }
    }

    if (hasOutputFormat && (startCodeValue == START_GROUP || startCodeValue == START_PICTURE)) {
      int bytesWrittenPastStartCode = limit - startCodeOffset;
      if (foundFirstFrameInGroup) {
        @C.BufferFlags int flags = isKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
        int size = (int) (totalBytesWritten - framePosition) - bytesWrittenPastStartCode;
        output.sampleMetadata(frameTimeUs, flags, size, bytesWrittenPastStartCode, null);
        isKeyframe = false;
      }
      if (startCodeValue == START_GROUP) {
        foundFirstFrameInGroup = false;
        isKeyframe = true;
      } else /* startCodeValue == START_PICTURE */ {
        frameTimeUs = pesPtsUsAvailable ? pesTimeUs : (frameTimeUs + frameDurationUs);
        framePosition = totalBytesWritten - bytesWrittenPastStartCode;
        pesPtsUsAvailable = false;
        foundFirstFrameInGroup = true;
      }
    }

    offset = startCodeOffset;
    searchOffset = offset + 3;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:68,代码来源:H262Reader.java

示例9: consume

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  int offset = data.getPosition();
  int limit = data.limit();
  byte[] dataArray = data.data;

  // Append the data to the buffer.
  totalBytesWritten += data.bytesLeft();
  output.sampleData(data, data.bytesLeft());

  // Scan the appended data, processing NAL units as they are encountered
  while (true) {
    int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags);

    if (nalUnitOffset == limit) {
      // We've scanned to the end of the data without finding the start of another NAL unit.
      nalUnitData(dataArray, offset, limit);
      return;
    }

    // We've seen the start of a NAL unit of the following type.
    int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset);

    // This is the number of bytes from the current offset to the start of the next NAL unit.
    // It may be negative if the NAL unit started in the previously consumed data.
    int lengthToNalUnit = nalUnitOffset - offset;
    if (lengthToNalUnit > 0) {
      nalUnitData(dataArray, offset, nalUnitOffset);
    }
    int bytesWrittenPastPosition = limit - nalUnitOffset;
    long absolutePosition = totalBytesWritten - bytesWrittenPastPosition;
    // Indicate the end of the previous NAL unit. If the length to the start of the next unit
    // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes
    // when notifying that the unit has ended.
    endNalUnit(absolutePosition, bytesWrittenPastPosition,
        lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs);
    // Indicate the start of the next NAL unit.
    startNalUnit(absolutePosition, nalUnitType, pesTimeUs);
    // Continue scanning the data.
    offset = nalUnitOffset + 3;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:43,代码来源:H264Reader.java

示例10: consume

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
  while (data.bytesLeft() > 0) {
    int offset = data.getPosition();
    int limit = data.limit();
    byte[] dataArray = data.data;

    // Append the data to the buffer.
    totalBytesWritten += data.bytesLeft();
    output.sampleData(data, data.bytesLeft());

    // Scan the appended data, processing NAL units as they are encountered
    while (offset < limit) {
      int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags);

      if (nalUnitOffset == limit) {
        // We've scanned to the end of the data without finding the start of another NAL unit.
        nalUnitData(dataArray, offset, limit);
        return;
      }

      // We've seen the start of a NAL unit of the following type.
      int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset);

      // This is the number of bytes from the current offset to the start of the next NAL unit.
      // It may be negative if the NAL unit started in the previously consumed data.
      int lengthToNalUnit = nalUnitOffset - offset;
      if (lengthToNalUnit > 0) {
        nalUnitData(dataArray, offset, nalUnitOffset);
      }

      int bytesWrittenPastPosition = limit - nalUnitOffset;
      long absolutePosition = totalBytesWritten - bytesWrittenPastPosition;
      // Indicate the end of the previous NAL unit. If the length to the start of the next unit
      // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes
      // when notifying that the unit has ended.
      endNalUnit(absolutePosition, bytesWrittenPastPosition,
          lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs);
      // Indicate the start of the next NAL unit.
      startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs);
      // Continue scanning the data.
      offset = nalUnitOffset + 3;
    }
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:46,代码来源:H265Reader.java

示例11: setupSeeker

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Returns a {@link Seeker} to seek using metadata read from {@code input}, which should provide
 * data from the start of the first frame in the stream. On returning, the input's position will
 * be set to the start of the first frame of audio.
 *
 * @param input The {@link ExtractorInput} from which to read.
 * @throws IOException Thrown if there was an error reading from the stream. Not expected if the
 *     next two frames were already peeked during synchronization.
 * @throws InterruptedException Thrown if reading from the stream was interrupted. Not expected if
 *     the next two frames were already peeked during synchronization.
 * @return a {@link Seeker}.
 */
private Seeker setupSeeker(ExtractorInput input) throws IOException, InterruptedException {
  // Read the first frame which may contain a Xing or VBRI header with seeking metadata.
  ParsableByteArray frame = new ParsableByteArray(synchronizedHeader.frameSize);
  input.peekFully(frame.data, 0, synchronizedHeader.frameSize);

  long position = input.getPosition();
  long length = input.getLength();
  int headerData = 0;
  Seeker seeker = null;

  // Check if there is a Xing header.
  int xingBase = (synchronizedHeader.version & 1) != 0
      ? (synchronizedHeader.channels != 1 ? 36 : 21) // MPEG 1
      : (synchronizedHeader.channels != 1 ? 21 : 13); // MPEG 2 or 2.5
  if (frame.limit() >= xingBase + 4) {
    frame.setPosition(xingBase);
    headerData = frame.readInt();
  }
  if (headerData == XING_HEADER || headerData == INFO_HEADER) {
    seeker = XingSeeker.create(synchronizedHeader, frame, position, length);
    if (seeker != null && !gaplessInfoHolder.hasGaplessInfo()) {
      // If there is a Xing header, read gapless playback metadata at a fixed offset.
      input.resetPeekPosition();
      input.advancePeekPosition(xingBase + 141);
      input.peekFully(scratch.data, 0, 3);
      scratch.setPosition(0);
      gaplessInfoHolder.setFromXingHeaderValue(scratch.readUnsignedInt24());
    }
    input.skipFully(synchronizedHeader.frameSize);
  } else if (frame.limit() >= 40) {
    // Check if there is a VBRI header.
    frame.setPosition(36); // MPEG audio header (4 bytes) + 32 bytes.
    headerData = frame.readInt();
    if (headerData == VBRI_HEADER) {
      seeker = VbriSeeker.create(synchronizedHeader, frame, position, length);
      input.skipFully(synchronizedHeader.frameSize);
    }
  }

  if (seeker == null || (!seeker.isSeekable()
      && (flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) != 0)) {
    // Repopulate the synchronized header in case we had to skip an invalid seeking header, which
    // would give an invalid CBR bitrate.
    input.resetPeekPosition();
    input.peekFully(scratch.data, 0, 4);
    scratch.setPosition(0);
    MpegAudioHeader.populateHeader(scratch.readInt(), synchronizedHeader);
    seeker = new ConstantBitrateSeeker(input.getPosition(), synchronizedHeader.bitrate, length);
  }

  return seeker;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:65,代码来源:Mp3Extractor.java


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