Java Code Examples for com.google.android.exoplayer2.source.SampleQueue#setSampleOffsetUs()

The following examples show how to use com.google.android.exoplayer2.source.SampleQueue#setSampleOffsetUs() . 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: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private SampleQueue createSampleQueue(int id, int type) {
  int trackCount = sampleQueues.length;

  SampleQueue trackOutput =
      new FormatAdjustingSampleQueue(allocator, drmSessionManager, overridingDrmInitData);
  trackOutput.setSampleOffsetUs(sampleOffsetUs);
  trackOutput.sourceId(chunkUid);
  trackOutput.setUpstreamFormatChangeListener(this);
  sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1);
  sampleQueueTrackIds[trackCount] = id;
  sampleQueues = Util.nullSafeArrayAppend(sampleQueues, trackOutput);
  sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1);
  sampleQueueIsAudioVideoFlags[trackCount] =
      type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO;
  haveAudioVideoSampleQueues |= sampleQueueIsAudioVideoFlags[trackCount];
  sampleQueueMappingDoneByType.add(type);
  sampleQueueIndicesByType.append(type, trackCount);
  if (getTrackTypeScore(type) > getTrackTypeScore(primarySampleQueueType)) {
    primarySampleQueueIndex = trackCount;
    primarySampleQueueType = type;
  }
  sampleQueuesEnabledStates = Arrays.copyOf(sampleQueuesEnabledStates, trackCount + 1);
  return trackOutput;
}
 
Example 2
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private SampleQueue createSampleQueue(int id, int type) {
  int trackCount = sampleQueues.length;

  SampleQueue trackOutput = new PrivTimestampStrippingSampleQueue(allocator);
  trackOutput.setSampleOffsetUs(sampleOffsetUs);
  trackOutput.sourceId(chunkUid);
  trackOutput.setUpstreamFormatChangeListener(this);
  sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1);
  sampleQueueTrackIds[trackCount] = id;
  sampleQueues = Arrays.copyOf(sampleQueues, trackCount + 1);
  sampleQueues[trackCount] = trackOutput;
  sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1);
  sampleQueueIsAudioVideoFlags[trackCount] =
      type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO;
  haveAudioVideoSampleQueues |= sampleQueueIsAudioVideoFlags[trackCount];
  sampleQueueMappingDoneByType.add(type);
  sampleQueueIndicesByType.append(type, trackCount);
  if (getTrackTypeScore(type) > getTrackTypeScore(primarySampleQueueType)) {
    primarySampleQueueIndex = trackCount;
    primarySampleQueueType = type;
  }
  sampleQueuesEnabledStates = Arrays.copyOf(sampleQueuesEnabledStates, trackCount + 1);
  return trackOutput;
}
 
Example 3
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private SampleQueue createSampleQueue(int id, int type) {
  int trackCount = sampleQueues.length;

  SampleQueue trackOutput = new PrivTimestampStrippingSampleQueue(allocator);
  trackOutput.setSampleOffsetUs(sampleOffsetUs);
  trackOutput.sourceId(chunkUid);
  trackOutput.setUpstreamFormatChangeListener(this);
  sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1);
  sampleQueueTrackIds[trackCount] = id;
  sampleQueues = Arrays.copyOf(sampleQueues, trackCount + 1);
  sampleQueues[trackCount] = trackOutput;
  sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1);
  sampleQueueIsAudioVideoFlags[trackCount] =
      type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO;
  haveAudioVideoSampleQueues |= sampleQueueIsAudioVideoFlags[trackCount];
  sampleQueueMappingDoneByType.add(type);
  sampleQueueIndicesByType.append(type, trackCount);
  if (getTrackTypeScore(type) > getTrackTypeScore(primarySampleQueueType)) {
    primarySampleQueueIndex = trackCount;
    primarySampleQueueType = type;
  }
  sampleQueuesEnabledStates = Arrays.copyOf(sampleQueuesEnabledStates, trackCount + 1);
  return trackOutput;
}
 
Example 4
Source File: BaseMediaChunkOutput.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples
 * subsequently written to the sample queues.
 */
public void setSampleOffsetUs(long sampleOffsetUs) {
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue != null) {
      sampleQueue.setSampleOffsetUs(sampleOffsetUs);
    }
  }
}
 
Example 5
Source File: BaseMediaChunkOutput.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples
 * subsequently written to the sample queues.
 */
public void setSampleOffsetUs(long sampleOffsetUs) {
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue != null) {
      sampleQueue.setSampleOffsetUs(sampleOffsetUs);
    }
  }
}
 
Example 6
Source File: BaseMediaChunkOutput.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples
 * subsequently written to the sample queues.
 */
public void setSampleOffsetUs(long sampleOffsetUs) {
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue != null) {
      sampleQueue.setSampleOffsetUs(sampleOffsetUs);
    }
  }
}
 
Example 7
Source File: BaseMediaChunkOutput.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples
 * subsequently written to the sample queues.
 */
public void setSampleOffsetUs(long sampleOffsetUs) {
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue != null) {
      sampleQueue.setSampleOffsetUs(sampleOffsetUs);
    }
  }
}
 
Example 8
Source File: BaseMediaChunkOutput.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples
 * subsequently written to the sample queues.
 */
public void setSampleOffsetUs(long sampleOffsetUs) {
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue != null) {
      sampleQueue.setSampleOffsetUs(sampleOffsetUs);
    }
  }
}
 
Example 9
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
public void setSampleOffsetUs(long sampleOffsetUs) {
  this.sampleOffsetUs = sampleOffsetUs;
  for (SampleQueue sampleQueue : sampleQueues) {
    sampleQueue.setSampleOffsetUs(sampleOffsetUs);
  }
}
 
Example 10
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public TrackOutput track(int id, int type) {
  int trackCount = sampleQueues.length;

  // Audio and video tracks are handled manually to ignore ids.
  if (type == C.TRACK_TYPE_AUDIO) {
    if (audioSampleQueueIndex != C.INDEX_UNSET) {
      if (audioSampleQueueMappingDone) {
        return sampleQueueTrackIds[audioSampleQueueIndex] == id
            ? sampleQueues[audioSampleQueueIndex]
            : createDummyTrackOutput(id, type);
      }
      audioSampleQueueMappingDone = true;
      sampleQueueTrackIds[audioSampleQueueIndex] = id;
      return sampleQueues[audioSampleQueueIndex];
    } else if (tracksEnded) {
      return createDummyTrackOutput(id, type);
    }
  } else if (type == C.TRACK_TYPE_VIDEO) {
    if (videoSampleQueueIndex != C.INDEX_UNSET) {
      if (videoSampleQueueMappingDone) {
        return sampleQueueTrackIds[videoSampleQueueIndex] == id
            ? sampleQueues[videoSampleQueueIndex]
            : createDummyTrackOutput(id, type);
      }
      videoSampleQueueMappingDone = true;
      sampleQueueTrackIds[videoSampleQueueIndex] = id;
      return sampleQueues[videoSampleQueueIndex];
    } else if (tracksEnded) {
      return createDummyTrackOutput(id, type);
    }
  } else /* sparse track */ {
    for (int i = 0; i < trackCount; i++) {
      if (sampleQueueTrackIds[i] == id) {
        return sampleQueues[i];
      }
    }
    if (tracksEnded) {
      return createDummyTrackOutput(id, type);
    }
  }
  SampleQueue trackOutput = new SampleQueue(allocator);
  trackOutput.setSampleOffsetUs(sampleOffsetUs);
  trackOutput.sourceId(chunkUid);
  trackOutput.setUpstreamFormatChangeListener(this);
  sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1);
  sampleQueueTrackIds[trackCount] = id;
  sampleQueues = Arrays.copyOf(sampleQueues, trackCount + 1);
  sampleQueues[trackCount] = trackOutput;
  sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1);
  sampleQueueIsAudioVideoFlags[trackCount] = type == C.TRACK_TYPE_AUDIO
      || type == C.TRACK_TYPE_VIDEO;
  haveAudioVideoSampleQueues |= sampleQueueIsAudioVideoFlags[trackCount];
  if (type == C.TRACK_TYPE_AUDIO) {
    audioSampleQueueMappingDone = true;
    audioSampleQueueIndex = trackCount;
  } else if (type == C.TRACK_TYPE_VIDEO) {
    videoSampleQueueMappingDone = true;
    videoSampleQueueIndex = trackCount;
  }
  if (getTrackTypeScore(type) > getTrackTypeScore(primarySampleQueueType)) {
    primarySampleQueueIndex = trackCount;
    primarySampleQueueType = type;
  }
  sampleQueuesEnabledStates = Arrays.copyOf(sampleQueuesEnabledStates, trackCount + 1);
  return trackOutput;
}
 
Example 11
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setSampleOffsetUs(long sampleOffsetUs) {
  this.sampleOffsetUs = sampleOffsetUs;
  for (SampleQueue sampleQueue : sampleQueues) {
    sampleQueue.setSampleOffsetUs(sampleOffsetUs);
  }
}
 
Example 12
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public TrackOutput track(int id, int type) {
  int trackCount = sampleQueues.length;

  // Audio and video tracks are handled manually to ignore ids.
  if (type == C.TRACK_TYPE_AUDIO) {
    if (audioSampleQueueIndex != C.INDEX_UNSET) {
      if (audioSampleQueueMappingDone) {
        return sampleQueueTrackIds[audioSampleQueueIndex] == id
            ? sampleQueues[audioSampleQueueIndex]
            : createDummyTrackOutput(id, type);
      }
      audioSampleQueueMappingDone = true;
      sampleQueueTrackIds[audioSampleQueueIndex] = id;
      return sampleQueues[audioSampleQueueIndex];
    } else if (tracksEnded) {
      return createDummyTrackOutput(id, type);
    }
  } else if (type == C.TRACK_TYPE_VIDEO) {
    if (videoSampleQueueIndex != C.INDEX_UNSET) {
      if (videoSampleQueueMappingDone) {
        return sampleQueueTrackIds[videoSampleQueueIndex] == id
            ? sampleQueues[videoSampleQueueIndex]
            : createDummyTrackOutput(id, type);
      }
      videoSampleQueueMappingDone = true;
      sampleQueueTrackIds[videoSampleQueueIndex] = id;
      return sampleQueues[videoSampleQueueIndex];
    } else if (tracksEnded) {
      return createDummyTrackOutput(id, type);
    }
  } else /* sparse track */ {
    for (int i = 0; i < trackCount; i++) {
      if (sampleQueueTrackIds[i] == id) {
        return sampleQueues[i];
      }
    }
    if (tracksEnded) {
      return createDummyTrackOutput(id, type);
    }
  }
  SampleQueue trackOutput = new SampleQueue(allocator);
  trackOutput.setSampleOffsetUs(sampleOffsetUs);
  trackOutput.sourceId(chunkUid);
  trackOutput.setUpstreamFormatChangeListener(this);
  sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1);
  sampleQueueTrackIds[trackCount] = id;
  sampleQueues = Arrays.copyOf(sampleQueues, trackCount + 1);
  sampleQueues[trackCount] = trackOutput;
  sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1);
  sampleQueueIsAudioVideoFlags[trackCount] = type == C.TRACK_TYPE_AUDIO
      || type == C.TRACK_TYPE_VIDEO;
  haveAudioVideoSampleQueues |= sampleQueueIsAudioVideoFlags[trackCount];
  if (type == C.TRACK_TYPE_AUDIO) {
    audioSampleQueueMappingDone = true;
    audioSampleQueueIndex = trackCount;
  } else if (type == C.TRACK_TYPE_VIDEO) {
    videoSampleQueueMappingDone = true;
    videoSampleQueueIndex = trackCount;
  }
  if (getTrackTypeScore(type) > getTrackTypeScore(primarySampleQueueType)) {
    primarySampleQueueIndex = trackCount;
    primarySampleQueueType = type;
  }
  sampleQueuesEnabledStates = Arrays.copyOf(sampleQueuesEnabledStates, trackCount + 1);
  return trackOutput;
}
 
Example 13
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setSampleOffsetUs(long sampleOffsetUs) {
  this.sampleOffsetUs = sampleOffsetUs;
  for (SampleQueue sampleQueue : sampleQueues) {
    sampleQueue.setSampleOffsetUs(sampleOffsetUs);
  }
}
 
Example 14
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void setSampleOffsetUs(long sampleOffsetUs) {
  this.sampleOffsetUs = sampleOffsetUs;
  for (SampleQueue sampleQueue : sampleQueues) {
    sampleQueue.setSampleOffsetUs(sampleOffsetUs);
  }
}
 
Example 15
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void setSampleOffsetUs(long sampleOffsetUs) {
  this.sampleOffsetUs = sampleOffsetUs;
  for (SampleQueue sampleQueue : sampleQueues) {
    sampleQueue.setSampleOffsetUs(sampleOffsetUs);
  }
}