com.google.android.exoplayer2.Format.createAudioSampleFormat()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(15.7k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中com.google.android.exoplayer2.Format.createAudioSampleFormat()方法的一些代码示例,展示了Format.createAudioSampleFormat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Format.createAudioSampleFormat()方法的具体详情如下:
包路径:com.google.android.exoplayer2.Format
类名称:Format
方法名:createAudioSampleFormat

Format.createAudioSampleFormat介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

/**
 * Returns the format of audio buffers output by the decoder. Will not be called until the first
 * output buffer has been dequeued, so the decoder may use input data to determine the format.
 * <p>
 * The default implementation returns a 16-bit PCM format with the same channel count and sample
 * rate as the input.
 */
protected Format getOutputFormat() {
 return Format.createAudioSampleFormat(null, MimeTypes.AUDIO_RAW, null, Format.NO_VALUE,
   Format.NO_VALUE, inputFormat.channelCount, inputFormat.sampleRate, C.ENCODING_PCM_16BIT,
   null, null, 0, null);
}

代码示例来源:origin: google/ExoPlayer

private static Format buildAudioFormat(String id, String language, int selectionFlags) {
 return Format.createAudioSampleFormat(
   id,
   MimeTypes.AUDIO_AAC,
   /* codecs= */ null,
   /* bitrate= */ Format.NO_VALUE,
   /* maxInputSize= */ Format.NO_VALUE,
   /* channelCount= */ 2,
   /* sampleRate= */ 44100,
   /* initializationData= */ null,
   /* drmInitData= */ null,
   selectionFlags,
   language);
}

代码示例来源:origin: google/ExoPlayer

private void maybeOutputFormat() {
 if (!hasOutputFormat) {
  hasOutputFormat = true;
  String mimeType = isWideBand ? MimeTypes.AUDIO_AMR_WB : MimeTypes.AUDIO_AMR_NB;
  int sampleRate = isWideBand ? SAMPLE_RATE_WB : SAMPLE_RATE_NB;
  trackOutput.format(
    Format.createAudioSampleFormat(
      /* id= */ null,
      mimeType,
      /* codecs= */ null,
      /* bitrate= */ Format.NO_VALUE,
      MAX_FRAME_SIZE_BYTES,
      /* channelCount= */ 1,
      sampleRate,
      /* pcmEncoding= */ Format.NO_VALUE,
      /* initializationData= */ null,
      /* drmInitData= */ null,
      /* selectionFlags= */ 0,
      /* language= */ null));
 }
}

代码示例来源:origin: google/ExoPlayer

@Override
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData)
  throws IOException, InterruptedException {
 if (vorbisSetup != null) {
  return false;
 }
 vorbisSetup = readSetupHeaders(packet);
 if (vorbisSetup == null) {
  return true;
 }
 ArrayList<byte[]> codecInitialisationData = new ArrayList<>();
 codecInitialisationData.add(vorbisSetup.idHeader.data);
 codecInitialisationData.add(vorbisSetup.setupHeaderData);
 setupData.format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_VORBIS, null,
   this.vorbisSetup.idHeader.bitrateNominal, Format.NO_VALUE,
   this.vorbisSetup.idHeader.channels, (int) this.vorbisSetup.idHeader.sampleRate,
   codecInitialisationData, null, 0, null);
 return true;
}

代码示例来源:origin: google/ExoPlayer

@Override
protected Format getOutputFormat() {
 return Format.createAudioSampleFormat(null, MimeTypes.AUDIO_RAW, null, Format.NO_VALUE,
   Format.NO_VALUE, decoder.getChannelCount(), decoder.getSampleRate(), C.ENCODING_PCM_16BIT,
   null, null, 0, null);
}

代码示例来源:origin: google/ExoPlayer

@Override
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData) {
 if (!headerRead) {
  byte[] metadata = Arrays.copyOf(packet.data, packet.limit());
  int channelCount = metadata[9] & 0xFF;
  int preskip = ((metadata[11] & 0xFF) << 8) | (metadata[10] & 0xFF);
  List<byte[]> initializationData = new ArrayList<>(3);
  initializationData.add(metadata);
  putNativeOrderLong(initializationData, preskip);
  putNativeOrderLong(initializationData, DEFAULT_SEEK_PRE_ROLL_SAMPLES);
  setupData.format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_OPUS, null,
    Format.NO_VALUE, Format.NO_VALUE, channelCount, SAMPLE_RATE, initializationData, null, 0,
    null);
  headerRead = true;
 } else {
  boolean headerPacket = packet.readInt() == OPUS_CODE;
  packet.setPosition(0);
  return headerPacket;
 }
 return true;
}

代码示例来源:origin: google/ExoPlayer

/**
 * Parses the sample header.
 */
@SuppressWarnings("ReferenceEquality")
private void parseHeader() {
 headerScratchBits.setPosition(0);
 SyncFrameInfo frameInfo = Ac3Util.parseAc3SyncframeInfo(headerScratchBits);
 if (format == null || frameInfo.channelCount != format.channelCount
   || frameInfo.sampleRate != format.sampleRate
   || frameInfo.mimeType != format.sampleMimeType) {
  format = Format.createAudioSampleFormat(trackFormatId, frameInfo.mimeType, null,
    Format.NO_VALUE, Format.NO_VALUE, frameInfo.channelCount, frameInfo.sampleRate, null,
    null, 0, language);
  output.format(format);
 }
 sampleSize = frameInfo.frameSize;
 // In this class a sample is an access unit (syncframe in AC-3), but the MediaFormat sample rate
 // specifies the number of PCM audio samples per second.
 sampleDurationUs = C.MICROS_PER_SECOND * frameInfo.sampleCount / format.sampleRate;
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio tracks with higher bit-rate when other factors
 * are the same, and tracks are within renderer's capabilities.
 */
@Test
public void testSelectTracksWithinCapabilitiesSelectHigherBitrate()
  throws Exception {
 Format lowerBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format higherBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
   singleTrackGroup(lowerBitrateFormat, higherBitrateFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(higherBitrateFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio tracks with lower num channel when other factors
 * are the same, and tracks exceed renderer's capabilities.
 */
@Test
public void testSelectTracksExceedingCapabilitiesSelectLowerNumChannel()
  throws Exception {
 Format lowerChannelFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format higherChannelFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 6, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
   singleTrackGroup(higherChannelFormat, lowerChannelFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerChannelFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio tracks with lower bit-rate when other factors
 * are the same, and tracks exceed renderer's capabilities.
 */
@Test
public void testSelectTracksExceedingCapabilitiesSelectLowerBitrate()
  throws Exception {
 Format lowerBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format higherBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
   singleTrackGroup(lowerBitrateFormat, higherBitrateFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerBitrateFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will prefer audio tracks with higher sample rate over tracks with
 * higher bitrate when other factors are the same, and tracks are within renderer's
 * capabilities.
 */
@Test
public void testSelectTracksPreferHigherSampleRateBeforeBitrate()
  throws Exception {
 Format higherSampleRateLowerBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format lowerSampleRateHigherBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
     Format.NO_VALUE, 2, 22050, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
   singleTrackGroup(higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat));
 assertThat(result.selections.get(0).getSelectedFormat())
   .isEqualTo(higherSampleRateLowerBitrateFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio tracks with higher num channel when other factors
 * are the same, and tracks are within renderer's capabilities.
 */
@Test
public void testSelectTracksWithinCapabilitiesSelectHigherNumChannel()
  throws Exception {
 Format lowerChannelFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format higherChannelFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 6, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
   singleTrackGroup(higherChannelFormat, lowerChannelFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(higherChannelFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio tracks with higher sample rate when other factors
 * are the same, and tracks are within renderer's capabilities.
 */
@Test
public void testSelectTracksWithinCapabilitiesSelectHigherSampleRate()
  throws Exception {
 Format higherSampleRateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format lowerSampleRateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 22050, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
   singleTrackGroup(higherSampleRateFormat, lowerSampleRateFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(higherSampleRateFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio tracks with lower sample rate when other factors
 * are the same, and tracks exceed renderer's capabilities.
 */
@Test
public void testSelectTracksExceedingCapabilitiesSelectLowerSampleRate()
  throws Exception {
 Format lowerSampleRateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 22050, null, null, 0, null);
 Format higherSampleRateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
   singleTrackGroup(higherSampleRateFormat, lowerSampleRateFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerSampleRateFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will prefer audio tracks with lower channel count over tracks with
 * lower sample rate when other factors are the same, and tracks are within renderer's
 * capabilities.
 */
@Test
public void testSelectTracksExceedingCapabilitiesPreferLowerNumChannelBeforeSampleRate()
  throws Exception {
 Format lowerChannelHigherSampleRateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format higherChannelLowerSampleRateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 6, 22050, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
   singleTrackGroup(higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat));
 assertThat(result.selections.get(0).getSelectedFormat())
   .isEqualTo(lowerChannelHigherSampleRateFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select a track that exceeds the renderer's capabilities when
 * there are no other choice, given the default {@link Parameters}.
 */
@Test
public void testSelectTracksWithNoTrackWithinCapabilitiesSelectExceededCapabilityTrack()
  throws Exception {
 Format audioFormat =
   Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
   singleTrackGroup(audioFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(audioFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio tracks with lower bitrate when {@link Parameters}
 * indicate lowest bitrate preference, even when tracks are within capabilities.
 */
@Test
public void testSelectTracksWithinCapabilitiesAndForceLowestBitrateSelectLowerBitrate()
  throws Exception {
 trackSelector.setParameters(new ParametersBuilder().setForceLowestBitrate(true).build());
 Format lowerBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 Format higherBitrateFormat =
   Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
   singleTrackGroup(lowerBitrateFormat, higherBitrateFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerBitrateFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will prefer selecting audio track with language that match preferred
 * language given by {@link Parameters} over track with {@link C#SELECTION_FLAG_DEFAULT}.
 */
@Test
public void testSelectTracksSelectPreferredAudioLanguageOverSelectionFlag()
  throws Exception {
 trackSelector.setParameters(new ParametersBuilder().setPreferredAudioLanguage("eng").build());
 Format frAudioFormat =
   Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, C.SELECTION_FLAG_DEFAULT, "fra");
 Format enAudioFormat =
   Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, "eng");
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
   wrapFormats(frAudioFormat, enAudioFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(enAudioFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will select audio track with language that match preferred language
 * given by {@link Parameters}.
 */
@Test
public void testSelectTracksSelectPreferredAudioLanguage()
  throws Exception {
 trackSelector.setParameters(new ParametersBuilder().setPreferredAudioLanguage("eng").build());
 Format frAudioFormat =
   Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, "fra");
 Format enAudioFormat =
   Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, "eng");
 TrackSelectorResult result =
   trackSelector.selectTracks(
     new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
     wrapFormats(frAudioFormat, enAudioFormat));
 assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(enAudioFormat);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Tests that track selector will return a null track selection for a renderer when
 * all tracks exceed that renderer's capabilities when {@link Parameters} does not allow
 * exceeding-capabilities tracks.
 */
@Test
public void testSelectTracksWithNoTrackWithinCapabilitiesAndSetByParamsReturnNoSelection()
  throws Exception {
 trackSelector.setParameters(
   new ParametersBuilder().setExceedRendererCapabilitiesIfNecessary(false).build());
 Format audioFormat =
   Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
     Format.NO_VALUE, 2, 44100, null, null, 0, null);
 TrackSelectorResult result = trackSelector.selectTracks(
   new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
   singleTrackGroup(audioFormat));
 assertThat(result.selections.get(0)).isNull();
}

相关文章