Java Code Examples for com.google.android.exoplayer2.C#POSITION_UNSET

The following examples show how to use com.google.android.exoplayer2.C#POSITION_UNSET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cea708Decoder.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void append(char text) {
  if (text == '\n') {
    rolledUpCaptions.add(buildSpannableString());
    captionStringBuilder.clear();

    if (italicsStartPosition != C.POSITION_UNSET) {
      italicsStartPosition = 0;
    }
    if (underlineStartPosition != C.POSITION_UNSET) {
      underlineStartPosition = 0;
    }
    if (foregroundColorStartPosition != C.POSITION_UNSET) {
      foregroundColorStartPosition = 0;
    }
    if (backgroundColorStartPosition != C.POSITION_UNSET) {
      backgroundColorStartPosition = 0;
    }

    while ((rowLock && (rolledUpCaptions.size() >= rowCount))
        || (rolledUpCaptions.size() >= MAXIMUM_ROW_COUNT)) {
      rolledUpCaptions.remove(0);
    }
  } else {
    captionStringBuilder.append(text);
  }
}
 
Example 2
Source File: AudioTimestampPoller.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void updateState(@State int state) {
  this.state = state;
  switch (state) {
    case STATE_INITIALIZING:
      // Force polling a timestamp immediately, and poll quickly.
      lastTimestampSampleTimeUs = 0;
      initialTimestampPositionFrames = C.POSITION_UNSET;
      initializeSystemTimeUs = System.nanoTime() / 1000;
      sampleIntervalUs = FAST_POLL_INTERVAL_US;
      break;
    case STATE_TIMESTAMP:
      sampleIntervalUs = FAST_POLL_INTERVAL_US;
      break;
    case STATE_TIMESTAMP_ADVANCING:
    case STATE_NO_TIMESTAMP:
      sampleIntervalUs = SLOW_POLL_INTERVAL_US;
      break;
    case STATE_ERROR:
      sampleIntervalUs = ERROR_POLL_INTERVAL_US;
      break;
    default:
      throw new IllegalStateException();
  }
}
 
Example 3
Source File: Cea708Decoder.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public void append(char text) {
  if (text == '\n') {
    rolledUpCaptions.add(buildSpannableString());
    captionStringBuilder.clear();

    if (italicsStartPosition != C.POSITION_UNSET) {
      italicsStartPosition = 0;
    }
    if (underlineStartPosition != C.POSITION_UNSET) {
      underlineStartPosition = 0;
    }
    if (foregroundColorStartPosition != C.POSITION_UNSET) {
      foregroundColorStartPosition = 0;
    }
    if (backgroundColorStartPosition != C.POSITION_UNSET) {
      backgroundColorStartPosition = 0;
    }

    while ((rowLock && (rolledUpCaptions.size() >= rowCount))
        || (rolledUpCaptions.size() >= MAXIMUM_ROW_COUNT)) {
      rolledUpCaptions.remove(0);
    }
  } else {
    captionStringBuilder.append(text);
  }
}
 
Example 4
Source File: Cea708Decoder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void clear() {
  rolledUpCaptions.clear();
  captionStringBuilder.clear();
  italicsStartPosition = C.POSITION_UNSET;
  underlineStartPosition = C.POSITION_UNSET;
  foregroundColorStartPosition = C.POSITION_UNSET;
  backgroundColorStartPosition = C.POSITION_UNSET;
  row = 0;
}
 
Example 5
Source File: SampleMetadataQueue.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Discards all samples in the queue. The read position is also advanced.
 *
 * @return The corresponding offset up to which data should be discarded, or
 *     {@link C#POSITION_UNSET} if no discarding of data is necessary.
 */
public synchronized long discardToEnd() {
  if (length == 0) {
    return C.POSITION_UNSET;
  }
  return discardSamples(length);
}
 
Example 6
Source File: AdtsExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param firstStreamSampleTimestampUs The timestamp to be used for the first sample of the stream
 *     output from this extractor.
 * @param flags Flags that control the extractor's behavior.
 */
public AdtsExtractor(long firstStreamSampleTimestampUs, @Flags int flags) {
  this.firstStreamSampleTimestampUs = firstStreamSampleTimestampUs;
  this.firstSampleTimestampUs = firstStreamSampleTimestampUs;
  this.flags = flags;
  reader = new AdtsReader(true);
  packetBuffer = new ParsableByteArray(MAX_PACKET_SIZE);
  averageFrameSize = C.LENGTH_UNSET;
  firstFramePosition = C.POSITION_UNSET;
  scratch = new ParsableByteArray(10);
  scratchBits = new ParsableBitArray(scratch.data);
}
 
Example 7
Source File: SampleQueue.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Advances {@link #firstAllocationNode} to the specified absolute position.
 * {@link #readAllocationNode} is also advanced if necessary to avoid it falling behind
 * {@link #firstAllocationNode}. Nodes that have been advanced past are cleared, and their
 * underlying allocations are returned to the allocator.
 *
 * @param absolutePosition The position to which {@link #firstAllocationNode} should be advanced.
 *     May be {@link C#POSITION_UNSET}, in which case calling this method is a no-op.
 */
private void discardDownstreamTo(long absolutePosition) {
  if (absolutePosition == C.POSITION_UNSET) {
    return;
  }
  while (absolutePosition >= firstAllocationNode.endPosition) {
    allocator.release(firstAllocationNode.allocation);
    firstAllocationNode = firstAllocationNode.clear();
  }
  // If we discarded the node referenced by readAllocationNode then we need to advance it to the
  // first remaining node.
  if (readAllocationNode.startPosition < firstAllocationNode.startPosition) {
    readAllocationNode = firstAllocationNode;
  }
}
 
Example 8
Source File: Cea708Decoder.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public void clear() {
  rolledUpCaptions.clear();
  captionStringBuilder.clear();
  italicsStartPosition = C.POSITION_UNSET;
  underlineStartPosition = C.POSITION_UNSET;
  foregroundColorStartPosition = C.POSITION_UNSET;
  backgroundColorStartPosition = C.POSITION_UNSET;
  row = 0;
}
 
Example 9
Source File: MatroskaExtractor.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example 10
Source File: Id3Decoder.java    From K-Sonic with MIT License 5 votes vote down vote up
private static ChapterFrame decodeChapterFrame(ParsableByteArray id3Data, int frameSize,
    int majorVersion, boolean unsignedIntFrameSizeHack, int frameHeaderSize,
    FramePredicate framePredicate) throws UnsupportedEncodingException {
  int framePosition = id3Data.getPosition();
  int chapterIdEndIndex = indexOfZeroByte(id3Data.data, framePosition);
  String chapterId = new String(id3Data.data, framePosition, chapterIdEndIndex - framePosition,
      "ISO-8859-1");
  id3Data.setPosition(chapterIdEndIndex + 1);

  int startTime = id3Data.readInt();
  int endTime = id3Data.readInt();
  long startOffset = id3Data.readUnsignedInt();
  if (startOffset == 0xFFFFFFFFL) {
    startOffset = C.POSITION_UNSET;
  }
  long endOffset = id3Data.readUnsignedInt();
  if (endOffset == 0xFFFFFFFFL) {
    endOffset = C.POSITION_UNSET;
  }

  ArrayList<Id3Frame> subFrames = new ArrayList<>();
  int limit = framePosition + frameSize;
  while (id3Data.getPosition() < limit) {
    Id3Frame frame = decodeFrame(majorVersion, id3Data, unsignedIntFrameSizeHack,
        frameHeaderSize, framePredicate);
    if (frame != null) {
      subFrames.add(frame);
    }
  }

  Id3Frame[] subFrameArray = new Id3Frame[subFrames.size()];
  subFrames.toArray(subFrameArray);
  return new ChapterFrame(chapterId, startTime, endTime, startOffset, endOffset, subFrameArray);
}
 
Example 11
Source File: AtomParsers.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the position of the esds box within a parent, or {@link C#POSITION_UNSET} if no esds
 * box is found
 */
private static int findEsdsPosition(ParsableByteArray parent, int position, int size) {
  int childAtomPosition = parent.getPosition();
  while (childAtomPosition - position < size) {
    parent.setPosition(childAtomPosition);
    int childAtomSize = parent.readInt();
    Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive");
    int childType = parent.readInt();
    if (childType == Atom.TYPE_esds) {
      return childAtomPosition;
    }
    childAtomPosition += childAtomSize;
  }
  return C.POSITION_UNSET;
}
 
Example 12
Source File: AtomParsers.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Returns the position of the esds box within a parent, or {@link C#POSITION_UNSET} if no esds
 * box is found
 */
private static int findEsdsPosition(ParsableByteArray parent, int position, int size) {
  int childAtomPosition = parent.getPosition();
  while (childAtomPosition - position < size) {
    parent.setPosition(childAtomPosition);
    int childAtomSize = parent.readInt();
    Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive");
    int childType = parent.readInt();
    if (childType == Atom.TYPE_esds) {
      return childAtomPosition;
    }
    childAtomPosition += childAtomSize;
  }
  return C.POSITION_UNSET;
}
 
Example 13
Source File: WavHeader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/** Returns whether the data start position and size have been set. */
public boolean hasDataBounds() {
  return dataStartPosition != C.POSITION_UNSET;
}
 
Example 14
Source File: TsBinarySearchSeeker.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private TimestampSearchResult searchForPcrValueInBuffer(
    ParsableByteArray packetBuffer, long targetPcrTimeUs, long bufferStartOffset) {
  int limit = packetBuffer.limit();

  long startOfLastPacketPosition = C.POSITION_UNSET;
  long endOfLastPacketPosition = C.POSITION_UNSET;
  long lastPcrTimeUsInRange = C.TIME_UNSET;

  while (packetBuffer.bytesLeft() >= TsExtractor.TS_PACKET_SIZE) {
    int startOfPacket =
        TsUtil.findSyncBytePosition(packetBuffer.data, packetBuffer.getPosition(), limit);
    int endOfPacket = startOfPacket + TsExtractor.TS_PACKET_SIZE;
    if (endOfPacket > limit) {
      break;
    }
    long pcrValue = TsUtil.readPcrFromPacket(packetBuffer, startOfPacket, pcrPid);
    if (pcrValue != C.TIME_UNSET) {
      long pcrTimeUs = pcrTimestampAdjuster.adjustTsTimestamp(pcrValue);
      if (pcrTimeUs > targetPcrTimeUs) {
        if (lastPcrTimeUsInRange == C.TIME_UNSET) {
          // First PCR timestamp is already over target.
          return TimestampSearchResult.overestimatedResult(pcrTimeUs, bufferStartOffset);
        } else {
          // Last PCR timestamp < target timestamp < this timestamp.
          return TimestampSearchResult.targetFoundResult(
              bufferStartOffset + startOfLastPacketPosition);
        }
      } else if (pcrTimeUs + SEEK_TOLERANCE_US > targetPcrTimeUs) {
        long startOfPacketInStream = bufferStartOffset + startOfPacket;
        return TimestampSearchResult.targetFoundResult(startOfPacketInStream);
      }

      lastPcrTimeUsInRange = pcrTimeUs;
      startOfLastPacketPosition = startOfPacket;
    }
    packetBuffer.setPosition(endOfPacket);
    endOfLastPacketPosition = endOfPacket;
  }

  if (lastPcrTimeUsInRange != C.TIME_UNSET) {
    long endOfLastPacketPositionInStream = bufferStartOffset + endOfLastPacketPosition;
    return TimestampSearchResult.underestimatedResult(
        lastPcrTimeUsInRange, endOfLastPacketPositionInStream);
  } else {
    return TimestampSearchResult.NO_TIMESTAMP_IN_RANGE_RESULT;
  }
}
 
Example 15
Source File: SectionReader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void consume(ParsableByteArray data, @Flags int flags) {
  boolean payloadUnitStartIndicator = (flags & FLAG_PAYLOAD_UNIT_START_INDICATOR) != 0;
  int payloadStartPosition = C.POSITION_UNSET;
  if (payloadUnitStartIndicator) {
    int payloadStartOffset = data.readUnsignedByte();
    payloadStartPosition = data.getPosition() + payloadStartOffset;
  }

  if (waitingForPayloadStart) {
    if (!payloadUnitStartIndicator) {
      return;
    }
    waitingForPayloadStart = false;
    data.setPosition(payloadStartPosition);
    bytesRead = 0;
  }

  while (data.bytesLeft() > 0) {
    if (bytesRead < SECTION_HEADER_LENGTH) {
      // Note: see ISO/IEC 13818-1, section 2.4.4.3 for detailed information on the format of
      // the header.
      if (bytesRead == 0) {
        int tableId = data.readUnsignedByte();
        data.setPosition(data.getPosition() - 1);
        if (tableId == 0xFF /* forbidden value */) {
          // No more sections in this ts packet.
          waitingForPayloadStart = true;
          return;
        }
      }
      int headerBytesToRead = Math.min(data.bytesLeft(), SECTION_HEADER_LENGTH - bytesRead);
      data.readBytes(sectionData.data, bytesRead, headerBytesToRead);
      bytesRead += headerBytesToRead;
      if (bytesRead == SECTION_HEADER_LENGTH) {
        sectionData.reset(SECTION_HEADER_LENGTH);
        sectionData.skipBytes(1); // Skip table id (8).
        int secondHeaderByte = sectionData.readUnsignedByte();
        int thirdHeaderByte = sectionData.readUnsignedByte();
        sectionSyntaxIndicator = (secondHeaderByte & 0x80) != 0;
        totalSectionLength =
            (((secondHeaderByte & 0x0F) << 8) | thirdHeaderByte) + SECTION_HEADER_LENGTH;
        if (sectionData.capacity() < totalSectionLength) {
          // Ensure there is enough space to keep the whole section.
          byte[] bytes = sectionData.data;
          sectionData.reset(
              Math.min(MAX_SECTION_LENGTH, Math.max(totalSectionLength, bytes.length * 2)));
          System.arraycopy(bytes, 0, sectionData.data, 0, SECTION_HEADER_LENGTH);
        }
      }
    } else {
      // Reading the body.
      int bodyBytesToRead = Math.min(data.bytesLeft(), totalSectionLength - bytesRead);
      data.readBytes(sectionData.data, bytesRead, bodyBytesToRead);
      bytesRead += bodyBytesToRead;
      if (bytesRead == totalSectionLength) {
        if (sectionSyntaxIndicator) {
          // This section has common syntax as defined in ISO/IEC 13818-1, section 2.4.4.11.
          if (Util.crc(sectionData.data, 0, totalSectionLength, 0xFFFFFFFF) != 0) {
            // The CRC is invalid so discard the section.
            waitingForPayloadStart = true;
            return;
          }
          sectionData.reset(totalSectionLength - 4); // Exclude the CRC_32 field.
        } else {
          // This is a private section with private defined syntax.
          sectionData.reset(totalSectionLength);
        }
        reader.consume(sectionData);
        bytesRead = 0;
      }
    }
  }
}
 
Example 16
Source File: SectionReader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void consume(ParsableByteArray data, boolean payloadUnitStartIndicator) {
  int payloadStartPosition = C.POSITION_UNSET;
  if (payloadUnitStartIndicator) {
    int payloadStartOffset = data.readUnsignedByte();
    payloadStartPosition = data.getPosition() + payloadStartOffset;
  }

  if (waitingForPayloadStart) {
    if (!payloadUnitStartIndicator) {
      return;
    }
    waitingForPayloadStart = false;
    data.setPosition(payloadStartPosition);
    bytesRead = 0;
  }

  while (data.bytesLeft() > 0) {
    if (bytesRead < SECTION_HEADER_LENGTH) {
      // Note: see ISO/IEC 13818-1, section 2.4.4.3 for detailed information on the format of
      // the header.
      if (bytesRead == 0) {
        int tableId = data.readUnsignedByte();
        data.setPosition(data.getPosition() - 1);
        if (tableId == 0xFF /* forbidden value */) {
          // No more sections in this ts packet.
          waitingForPayloadStart = true;
          return;
        }
      }
      int headerBytesToRead = Math.min(data.bytesLeft(), SECTION_HEADER_LENGTH - bytesRead);
      data.readBytes(sectionData.data, bytesRead, headerBytesToRead);
      bytesRead += headerBytesToRead;
      if (bytesRead == SECTION_HEADER_LENGTH) {
        sectionData.reset(SECTION_HEADER_LENGTH);
        sectionData.skipBytes(1); // Skip table id (8).
        int secondHeaderByte = sectionData.readUnsignedByte();
        int thirdHeaderByte = sectionData.readUnsignedByte();
        sectionSyntaxIndicator = (secondHeaderByte & 0x80) != 0;
        totalSectionLength =
            (((secondHeaderByte & 0x0F) << 8) | thirdHeaderByte) + SECTION_HEADER_LENGTH;
        if (sectionData.capacity() < totalSectionLength) {
          // Ensure there is enough space to keep the whole section.
          byte[] bytes = sectionData.data;
          sectionData.reset(
              Math.min(MAX_SECTION_LENGTH, Math.max(totalSectionLength, bytes.length * 2)));
          System.arraycopy(bytes, 0, sectionData.data, 0, SECTION_HEADER_LENGTH);
        }
      }
    } else {
      // Reading the body.
      int bodyBytesToRead = Math.min(data.bytesLeft(), totalSectionLength - bytesRead);
      data.readBytes(sectionData.data, bytesRead, bodyBytesToRead);
      bytesRead += bodyBytesToRead;
      if (bytesRead == totalSectionLength) {
        if (sectionSyntaxIndicator) {
          // This section has common syntax as defined in ISO/IEC 13818-1, section 2.4.4.11.
          if (Util.crc(sectionData.data, 0, totalSectionLength, 0xFFFFFFFF) != 0) {
            // The CRC is invalid so discard the section.
            waitingForPayloadStart = true;
            return;
          }
          sectionData.reset(totalSectionLength - 4); // Exclude the CRC_32 field.
        } else {
          // This is a private section with private defined syntax.
          sectionData.reset(totalSectionLength);
        }
        reader.consume(sectionData);
        bytesRead = 0;
      }
    }
  }
}
 
Example 17
Source File: MatroskaExtractor.java    From K-Sonic with MIT License 4 votes vote down vote up
void endMasterElement(int id) throws ParserException {
  switch (id) {
    case ID_SEGMENT_INFO:
      if (timecodeScale == C.TIME_UNSET) {
        // timecodeScale was omitted. Use the default value.
        timecodeScale = 1000000;
      }
      if (durationTimecode != C.TIME_UNSET) {
        durationUs = scaleTimecodeToUs(durationTimecode);
      }
      break;
    case ID_SEEK:
      if (seekEntryId == UNSET_ENTRY_ID || seekEntryPosition == C.POSITION_UNSET) {
        throw new ParserException("Mandatory element SeekID or SeekPosition not found");
      }
      if (seekEntryId == ID_CUES) {
        cuesContentPosition = seekEntryPosition;
      }
      break;
    case ID_CUES:
      if (!sentSeekMap) {
        extractorOutput.seekMap(buildSeekMap());
        sentSeekMap = true;
      } else {
        // We have already built the cues. Ignore.
      }
      break;
    case ID_BLOCK_GROUP:
      if (blockState != BLOCK_STATE_DATA) {
        // We've skipped this block (due to incompatible track number).
        return;
      }
      // If the ReferenceBlock element was not found for this sample, then it is a keyframe.
      if (!sampleSeenReferenceBlock) {
        blockFlags |= C.BUFFER_FLAG_KEY_FRAME;
      }
      commitSampleToOutput(tracks.get(blockTrackNumber), blockTimeUs);
      blockState = BLOCK_STATE_START;
      break;
    case ID_CONTENT_ENCODING:
      if (currentTrack.hasContentEncryption) {
        if (currentTrack.encryptionKeyId == null) {
          throw new ParserException("Encrypted Track found but ContentEncKeyID was not found");
        }
        currentTrack.drmInitData = new DrmInitData(
            new SchemeData(C.UUID_NIL, MimeTypes.VIDEO_WEBM, currentTrack.encryptionKeyId));
      }
      break;
    case ID_CONTENT_ENCODINGS:
      if (currentTrack.hasContentEncryption && currentTrack.sampleStrippedBytes != null) {
        throw new ParserException("Combining encryption and compression is not supported");
      }
      break;
    case ID_TRACK_ENTRY:
      if (isCodecSupported(currentTrack.codecId)) {
        currentTrack.initializeOutput(extractorOutput, currentTrack.number);
        tracks.put(currentTrack.number, currentTrack);
      }
      currentTrack = null;
      break;
    case ID_TRACKS:
      if (tracks.size() == 0) {
        throw new ParserException("No valid tracks were found");
      }
      extractorOutput.endTracks();
      break;
    default:
      break;
  }
}
 
Example 18
Source File: TsBinarySearchSeeker.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private TimestampSearchResult searchForPcrValueInBuffer(
    ParsableByteArray packetBuffer, long targetPcrTimeUs, long bufferStartOffset) {
  int limit = packetBuffer.limit();

  long startOfLastPacketPosition = C.POSITION_UNSET;
  long endOfLastPacketPosition = C.POSITION_UNSET;
  long lastPcrTimeUsInRange = C.TIME_UNSET;

  while (packetBuffer.bytesLeft() >= TsExtractor.TS_PACKET_SIZE) {
    int startOfPacket =
        TsUtil.findSyncBytePosition(packetBuffer.data, packetBuffer.getPosition(), limit);
    int endOfPacket = startOfPacket + TsExtractor.TS_PACKET_SIZE;
    if (endOfPacket > limit) {
      break;
    }
    long pcrValue = TsUtil.readPcrFromPacket(packetBuffer, startOfPacket, pcrPid);
    if (pcrValue != C.TIME_UNSET) {
      long pcrTimeUs = pcrTimestampAdjuster.adjustTsTimestamp(pcrValue);
      if (pcrTimeUs > targetPcrTimeUs) {
        if (lastPcrTimeUsInRange == C.TIME_UNSET) {
          // First PCR timestamp is already over target.
          return TimestampSearchResult.overestimatedResult(pcrTimeUs, bufferStartOffset);
        } else {
          // Last PCR timestamp < target timestamp < this timestamp.
          return TimestampSearchResult.targetFoundResult(
              bufferStartOffset + startOfLastPacketPosition);
        }
      } else if (pcrTimeUs + SEEK_TOLERANCE_US > targetPcrTimeUs) {
        long startOfPacketInStream = bufferStartOffset + startOfPacket;
        return TimestampSearchResult.targetFoundResult(startOfPacketInStream);
      }

      lastPcrTimeUsInRange = pcrTimeUs;
      startOfLastPacketPosition = startOfPacket;
    }
    packetBuffer.setPosition(endOfPacket);
    endOfLastPacketPosition = endOfPacket;
  }

  if (lastPcrTimeUsInRange != C.TIME_UNSET) {
    long endOfLastPacketPositionInStream = bufferStartOffset + endOfLastPacketPosition;
    return TimestampSearchResult.underestimatedResult(
        lastPcrTimeUsInRange, endOfLastPacketPositionInStream);
  } else {
    return TimestampSearchResult.NO_TIMESTAMP_IN_RANGE_RESULT;
  }
}
 
Example 19
Source File: AudioTimestampPoller.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * If {@link #maybePollTimestamp(long)} or {@link #hasTimestamp()} returned {@code true}, returns
 * the latest timestamp's position in frames.
 */
public long getTimestampPositionFrames() {
  return audioTimestamp != null ? audioTimestamp.getTimestampPositionFrames() : C.POSITION_UNSET;
}
 
Example 20
Source File: AudioTimestampPoller.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * If {@link #maybePollTimestamp(long)} or {@link #hasTimestamp()} returned {@code true}, returns
 * the latest timestamp's position in frames.
 */
public long getTimestampPositionFrames() {
  return audioTimestamp != null ? audioTimestamp.getTimestampPositionFrames() : C.POSITION_UNSET;
}