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


Java ParsableByteArray.readUnsignedInt24方法代码示例

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


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

示例1: parseSeekTable

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Parses a FLAC file seek table metadata structure and initializes internal fields.
 *
 * @param data A {@link ParsableByteArray} including whole seek table metadata block. Its
 *     position should be set to the beginning of the block.
 * @see <a href="https://xiph.org/flac/format.html#metadata_block_seektable">FLAC format
 *     METADATA_BLOCK_SEEKTABLE</a>
 */
public void parseSeekTable(ParsableByteArray data) {
  data.skipBytes(METADATA_LENGTH_OFFSET);
  int length = data.readUnsignedInt24();
  int numberOfSeekPoints = length / SEEK_POINT_SIZE;
  seekPointGranules = new long[numberOfSeekPoints];
  seekPointOffsets = new long[numberOfSeekPoints];
  for (int i = 0; i < numberOfSeekPoints; i++) {
    seekPointGranules[i] = data.readLong();
    seekPointOffsets[i] = data.readLong();
    data.skipBytes(2); // Skip "Number of samples in the target frame."
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:21,代码来源:FlacReader.java

示例2: sniff

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
  // Skip any ID3 headers.
  ParsableByteArray scratch = new ParsableByteArray(10);
  ParsableBitArray scratchBits = new ParsableBitArray(scratch.data);
  int startPosition = 0;
  while (true) {
    input.peekFully(scratch.data, 0, 10);
    scratch.setPosition(0);
    if (scratch.readUnsignedInt24() != ID3_TAG) {
      break;
    }
    scratch.skipBytes(3);
    int length = scratch.readSynchSafeInt();
    startPosition += 10 + length;
    input.advancePeekPosition(length);
  }
  input.resetPeekPosition();
  input.advancePeekPosition(startPosition);

  // Try to find four or more consecutive AAC audio frames, exceeding the MPEG TS packet size.
  int headerPosition = startPosition;
  int validFramesSize = 0;
  int validFramesCount = 0;
  while (true) {
    input.peekFully(scratch.data, 0, 2);
    scratch.setPosition(0);
    int syncBytes = scratch.readUnsignedShort();
    if ((syncBytes & 0xFFF6) != 0xFFF0) {
      validFramesCount = 0;
      validFramesSize = 0;
      input.resetPeekPosition();
      if (++headerPosition - startPosition >= MAX_SNIFF_BYTES) {
        return false;
      }
      input.advancePeekPosition(headerPosition);
    } else {
      if (++validFramesCount >= 4 && validFramesSize > 188) {
        return true;
      }

      // Skip the frame.
      input.peekFully(scratch.data, 0, 4);
      scratchBits.setPosition(14);
      int frameSize = scratchBits.readBits(13);
      // Either the stream is malformed OR we're not parsing an ADTS stream.
      if (frameSize <= 6) {
        return false;
      }
      input.advancePeekPosition(frameSize - 6);
      validFramesSize += frameSize;
    }
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:55,代码来源:AdtsExtractor.java

示例3: sniff

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
  // Skip any ID3 headers.
  ParsableByteArray scratch = new ParsableByteArray(10);
  int startPosition = 0;
  while (true) {
    input.peekFully(scratch.data, 0, 10);
    scratch.setPosition(0);
    if (scratch.readUnsignedInt24() != ID3_TAG) {
      break;
    }
    scratch.skipBytes(3);
    int length = scratch.readSynchSafeInt();
    startPosition += 10 + length;
    input.advancePeekPosition(length);
  }
  input.resetPeekPosition();
  input.advancePeekPosition(startPosition);

  int headerPosition = startPosition;
  int validFramesCount = 0;
  while (true) {
    input.peekFully(scratch.data, 0, 5);
    scratch.setPosition(0);
    int syncBytes = scratch.readUnsignedShort();
    if (syncBytes != AC3_SYNC_WORD) {
      validFramesCount = 0;
      input.resetPeekPosition();
      if (++headerPosition - startPosition >= MAX_SNIFF_BYTES) {
        return false;
      }
      input.advancePeekPosition(headerPosition);
    } else {
      if (++validFramesCount >= 4) {
        return true;
      }
      int frameSize = Ac3Util.parseAc3SyncframeSize(scratch.data);
      if (frameSize == C.LENGTH_UNSET) {
        return false;
      }
      input.advancePeekPosition(frameSize - 5);
    }
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:45,代码来源:Ac3Extractor.java

示例4: parsePayload

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
protected void parsePayload(ParsableByteArray data, long timeUs) throws ParserException {
  int packetType = data.readUnsignedByte();
  int compositionTimeMs = data.readUnsignedInt24();
  timeUs += compositionTimeMs * 1000L;
  // Parse avc sequence header in case this was not done before.
  if (packetType == AVC_PACKET_TYPE_SEQUENCE_HEADER && !hasOutputFormat) {
    ParsableByteArray videoSequence = new ParsableByteArray(new byte[data.bytesLeft()]);
    data.readBytes(videoSequence.data, 0, data.bytesLeft());
    AvcConfig avcConfig = AvcConfig.parse(videoSequence);
    nalUnitLengthFieldLength = avcConfig.nalUnitLengthFieldLength;
    // Construct and output the format.
    Format format = Format.createVideoSampleFormat(null, MimeTypes.VIDEO_H264, null,
        Format.NO_VALUE, Format.NO_VALUE, avcConfig.width, avcConfig.height, Format.NO_VALUE,
        avcConfig.initializationData, Format.NO_VALUE, avcConfig.pixelWidthAspectRatio, null);
    output.format(format);
    hasOutputFormat = true;
  } else if (packetType == AVC_PACKET_TYPE_AVC_NALU && hasOutputFormat) {
    // TODO: Deduplicate with Mp4Extractor.
    // Zero the top three bytes of the array that we'll use to decode nal unit lengths, in case
    // they're only 1 or 2 bytes long.
    byte[] nalLengthData = nalLength.data;
    nalLengthData[0] = 0;
    nalLengthData[1] = 0;
    nalLengthData[2] = 0;
    int nalUnitLengthFieldLengthDiff = 4 - nalUnitLengthFieldLength;
    // NAL units are length delimited, but the decoder requires start code delimited units.
    // Loop until we've written the sample to the track output, replacing length delimiters with
    // start codes as we encounter them.
    int bytesWritten = 0;
    int bytesToWrite;
    while (data.bytesLeft() > 0) {
      // Read the NAL length so that we know where we find the next one.
      data.readBytes(nalLength.data, nalUnitLengthFieldLengthDiff, nalUnitLengthFieldLength);
      nalLength.setPosition(0);
      bytesToWrite = nalLength.readUnsignedIntToInt();

      // Write a start code for the current NAL unit.
      nalStartCode.setPosition(0);
      output.sampleData(nalStartCode, 4);
      bytesWritten += 4;

      // Write the payload of the NAL unit.
      output.sampleData(data, bytesToWrite);
      bytesWritten += bytesToWrite;
    }
    output.sampleMetadata(timeUs, frameType == VIDEO_FRAME_KEYFRAME ? C.BUFFER_FLAG_KEY_FRAME : 0,
        bytesWritten, 0, null);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:51,代码来源:VideoTagPayloadReader.java

示例5: create

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Returns a {@link VbriSeeker} for seeking in the stream, if required information is present.
 * Returns {@code null} if not. On returning, {@code frame}'s position is not specified so the
 * caller should reset it.
 *
 * @param mpegAudioHeader The MPEG audio header associated with the frame.
 * @param frame The data in this audio frame, with its position set to immediately after the
 *     'VBRI' tag.
 * @param position The position (byte offset) of the start of this frame in the stream.
 * @param inputLength The length of the stream in bytes.
 * @return A {@link VbriSeeker} for seeking in the stream, or {@code null} if the required
 *     information is not present.
 */
public static VbriSeeker create(MpegAudioHeader mpegAudioHeader, ParsableByteArray frame,
    long position, long inputLength) {
  frame.skipBytes(10);
  int numFrames = frame.readInt();
  if (numFrames <= 0) {
    return null;
  }
  int sampleRate = mpegAudioHeader.sampleRate;
  long durationUs = Util.scaleLargeTimestamp(numFrames,
      C.MICROS_PER_SECOND * (sampleRate >= 32000 ? 1152 : 576), sampleRate);
  int entryCount = frame.readUnsignedShort();
  int scale = frame.readUnsignedShort();
  int entrySize = frame.readUnsignedShort();
  frame.skipBytes(2);

  // Skip the frame containing the VBRI header.
  position += mpegAudioHeader.frameSize;

  // Read table of contents entries.
  long[] timesUs = new long[entryCount + 1];
  long[] positions = new long[entryCount + 1];
  timesUs[0] = 0L;
  positions[0] = position;
  for (int index = 1; index < timesUs.length; index++) {
    int segmentSize;
    switch (entrySize) {
      case 1:
        segmentSize = frame.readUnsignedByte();
        break;
      case 2:
        segmentSize = frame.readUnsignedShort();
        break;
      case 3:
        segmentSize = frame.readUnsignedInt24();
        break;
      case 4:
        segmentSize = frame.readUnsignedIntToInt();
        break;
      default:
        return null;
    }
    position += segmentSize * scale;
    timesUs[index] = index * durationUs / entryCount;
    positions[index] =
        inputLength == C.LENGTH_UNSET ? position : Math.min(inputLength, position);
  }
  return new VbriSeeker(timesUs, positions, durationUs);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:62,代码来源:VbriSeeker.java

示例6: validateFrames

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static boolean validateFrames(ParsableByteArray id3Data, int majorVersion,
    int frameHeaderSize, boolean unsignedIntFrameSizeHack) {
  int startPosition = id3Data.getPosition();
  try {
    while (id3Data.bytesLeft() >= frameHeaderSize) {
      // Read the next frame header.
      int id;
      long frameSize;
      int flags;
      if (majorVersion >= 3) {
        id = id3Data.readInt();
        frameSize = id3Data.readUnsignedInt();
        flags = id3Data.readUnsignedShort();
      } else {
        id = id3Data.readUnsignedInt24();
        frameSize = id3Data.readUnsignedInt24();
        flags = 0;
      }
      // Validate the frame header and skip to the next one.
      if (id == 0 && frameSize == 0 && flags == 0) {
        // We've reached zero padding after the end of the final frame.
        return true;
      } else {
        if (majorVersion == 4 && !unsignedIntFrameSizeHack) {
          // Parse the data size as a synchsafe integer, as per the spec.
          if ((frameSize & 0x808080L) != 0) {
            return false;
          }
          frameSize = (frameSize & 0xFF) | (((frameSize >> 8) & 0xFF) << 7)
              | (((frameSize >> 16) & 0xFF) << 14) | (((frameSize >> 24) & 0xFF) << 21);
        }
        boolean hasGroupIdentifier = false;
        boolean hasDataLength = false;
        if (majorVersion == 4) {
          hasGroupIdentifier = (flags & FRAME_FLAG_V4_HAS_GROUP_IDENTIFIER) != 0;
          hasDataLength = (flags & FRAME_FLAG_V4_HAS_DATA_LENGTH) != 0;
        } else if (majorVersion == 3) {
          hasGroupIdentifier = (flags & FRAME_FLAG_V3_HAS_GROUP_IDENTIFIER) != 0;
          // A V3 frame has data length if and only if it's compressed.
          hasDataLength = (flags & FRAME_FLAG_V3_IS_COMPRESSED) != 0;
        }
        int minimumFrameSize = 0;
        if (hasGroupIdentifier) {
          minimumFrameSize++;
        }
        if (hasDataLength) {
          minimumFrameSize += 4;
        }
        if (frameSize < minimumFrameSize) {
          return false;
        }
        if (id3Data.bytesLeft() < frameSize) {
          return false;
        }
        id3Data.skipBytes((int) frameSize); // flags
      }
    }
    return true;
  } finally {
    id3Data.setPosition(startPosition);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:63,代码来源:Id3Decoder.java


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