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


Java Format.createAudioSampleFormat方法代码示例

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


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

示例1: parseHeader

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * Parses the sample header.
 */
@SuppressWarnings("ReferenceEquality")
private void parseHeader() {
  headerScratchBits.setPosition(0);
  Ac3Util.Ac3SyncFrameInfo 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;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:21,代码来源:Ac3Reader.java

示例2: readHeaders

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
@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;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:23,代码来源:VorbisReader.java

示例3: readHeaders

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
@Override
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData)
    throws IOException, InterruptedException {
  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;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:25,代码来源:OpusReader.java

示例4: parseEAc3AnnexFFormat

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * Returns the E-AC-3 format given {@code data} containing the EC3SpecificBox according to
 * ETSI TS 102 366 Annex F. The reading position of {@code data} will be modified.
 *
 * @param data The EC3SpecificBox to parse.
 * @param trackId The track identifier to set on the format, or null.
 * @param language The language to set on the format.
 * @param drmInitData {@link DrmInitData} to be included in the format.
 * @return The E-AC-3 format parsed from data in the header.
 */
public static Format parseEAc3AnnexFFormat(ParsableByteArray data, String trackId,
    String language, DrmInitData drmInitData) {
  data.skipBytes(2); // data_rate, num_ind_sub

  // Read only the first substream.
  // TODO: Read later substreams?
  int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
  int sampleRate = SAMPLE_RATE_BY_FSCOD[fscod];
  int nextByte = data.readUnsignedByte();
  int channelCount = CHANNEL_COUNT_BY_ACMOD[(nextByte & 0x0E) >> 1];
  if ((nextByte & 0x01) != 0) { // lfeon
    channelCount++;
  }
  return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_E_AC3, null, Format.NO_VALUE,
      Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:27,代码来源:Ac3Util.java

示例5: parseDtsFormat

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114
 * subsections 5.3/5.4.
 *
 * @param frame The DTS frame to parse.
 * @param trackId The track identifier to set on the format, or null.
 * @param language The language to set on the format.
 * @param drmInitData {@link DrmInitData} to be included in the format.
 * @return The DTS format parsed from data in the header.
 */
public static Format parseDtsFormat(byte[] frame, String trackId, String language,
    DrmInitData drmInitData) {
  ParsableBitArray frameBits = new ParsableBitArray(frame);
  frameBits.skipBits(4 * 8 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE
  int amode = frameBits.readBits(6);
  int channelCount = CHANNELS_BY_AMODE[amode];
  int sfreq = frameBits.readBits(4);
  int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq];
  int rate = frameBits.readBits(5);
  int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE
      : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2;
  frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF
  channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF
  return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate,
      Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:27,代码来源:DtsUtil.java

示例6: readHeaderRemainder

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * Attempts to read the remaining two bytes of the frame header.
 * <p>
 * If a frame header is read in full then the state is changed to {@link #STATE_READING_FRAME},
 * the media format is output if this has not previously occurred, the four header bytes are
 * output as sample data, and the position of the source is advanced to the byte that immediately
 * follows the header.
 * <p>
 * If a frame header is read in full but cannot be parsed then the state is changed to
 * {@link #STATE_READING_HEADER}.
 * <p>
 * If a frame header is not read in full 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 read.
 *
 * @param source The source from which to read.
 */
private void readHeaderRemainder(ParsableByteArray source) {
  int bytesToRead = Math.min(source.bytesLeft(), HEADER_SIZE - frameBytesRead);
  source.readBytes(headerScratch.data, frameBytesRead, bytesToRead);
  frameBytesRead += bytesToRead;
  if (frameBytesRead < HEADER_SIZE) {
    // We haven't read the whole header yet.
    return;
  }

  headerScratch.setPosition(0);
  boolean parsedHeader = MpegAudioHeader.populateHeader(headerScratch.readInt(), header);
  if (!parsedHeader) {
    // We thought we'd located a frame header, but we hadn't.
    frameBytesRead = 0;
    state = STATE_READING_HEADER;
    return;
  }

  frameSize = header.frameSize;
  if (!hasOutputFormat) {
    frameDurationUs = (C.MICROS_PER_SECOND * header.samplesPerFrame) / header.sampleRate;
    Format format = Format.createAudioSampleFormat(formatId, header.mimeType, null,
        Format.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, header.channels, header.sampleRate,
        null, null, 0, language);
    output.format(format);
    hasOutputFormat = true;
  }

  headerScratch.setPosition(0);
  output.sampleData(headerScratch, HEADER_SIZE);
  state = STATE_READING_FRAME;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:49,代码来源:MpegAudioReader.java

示例7: read

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  if (wavHeader == null) {
    wavHeader = WavHeaderReader.peek(input);
    if (wavHeader == null) {
      // Should only happen if the media wasn't sniffed.
      throw new ParserException("Unsupported or unrecognized wav header.");
    }
    Format format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_RAW, null,
        wavHeader.getBitrate(), MAX_INPUT_SIZE, wavHeader.getNumChannels(),
        wavHeader.getSampleRateHz(), wavHeader.getEncoding(), null, null, 0, null);
    trackOutput.format(format);
    bytesPerFrame = wavHeader.getBytesPerFrame();
  }

  if (!wavHeader.hasDataBounds()) {
    WavHeaderReader.skipToData(input, wavHeader);
    extractorOutput.seekMap(this);
  }

  int bytesAppended = trackOutput.sampleData(input, MAX_INPUT_SIZE - pendingBytes, true);
  if (bytesAppended != RESULT_END_OF_INPUT) {
    pendingBytes += bytesAppended;
  }

  // Samples must consist of a whole number of frames.
  int pendingFrames = pendingBytes / bytesPerFrame;
  if (pendingFrames > 0) {
    long timeUs = wavHeader.getTimeUs(input.getPosition() - pendingBytes);
    int size = pendingFrames * bytesPerFrame;
    pendingBytes -= size;
    trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, size, pendingBytes, null);
  }

  return bytesAppended == RESULT_END_OF_INPUT ? RESULT_END_OF_INPUT : RESULT_CONTINUE;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:38,代码来源:WavExtractor.java

示例8: parseAc3AnnexFFormat

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * Returns the AC-3 format given {@code data} containing the AC3SpecificBox according to
 * ETSI TS 102 366 Annex F. The reading position of {@code data} will be modified.
 *
 * @param data The AC3SpecificBox to parse.
 * @param trackId The track identifier to set on the format, or null.
 * @param language The language to set on the format.
 * @param drmInitData {@link DrmInitData} to be included in the format.
 * @return The AC-3 format parsed from data in the header.
 */
public static Format parseAc3AnnexFFormat(ParsableByteArray data, String trackId,
    String language, DrmInitData drmInitData) {
  int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
  int sampleRate = SAMPLE_RATE_BY_FSCOD[fscod];
  int nextByte = data.readUnsignedByte();
  int channelCount = CHANNEL_COUNT_BY_ACMOD[(nextByte & 0x38) >> 3];
  if ((nextByte & 0x04) != 0) { // lfeon
    channelCount++;
  }
  return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_AC3, null, Format.NO_VALUE,
      Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:23,代码来源:Ac3Util.java

示例9: parseAdtsHeader

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * Parses the sample header.
 */
private void parseAdtsHeader() {
  adtsScratch.setPosition(0);

  if (!hasOutputFormat) {
    int audioObjectType = adtsScratch.readBits(2) + 1;
    if (audioObjectType != 2) {
      // The stream indicates AAC-Main (1), AAC-SSR (3) or AAC-LTP (4). When the stream indicates
      // AAC-Main it's more likely that the stream contains HE-AAC (5), which cannot be
      // represented correctly in the 2 bit audio_object_type field in the ADTS header. In
      // practice when the stream indicates AAC-SSR or AAC-LTP it more commonly contains AAC-LC or
      // HE-AAC. Since most Android devices don't support AAC-Main, AAC-SSR or AAC-LTP, and since
      // indicating AAC-LC works for HE-AAC streams, we pretend that we're dealing with AAC-LC and
      // hope for the best. In practice this often works.
      // See: https://github.com/google/ExoPlayer/issues/774
      // See: https://github.com/google/ExoPlayer/issues/1383
      Log.w(TAG, "Detected audio object type: " + audioObjectType + ", but assuming AAC LC.");
      audioObjectType = 2;
    }

    int sampleRateIndex = adtsScratch.readBits(4);
    adtsScratch.skipBits(1);
    int channelConfig = adtsScratch.readBits(3);

    byte[] audioSpecificConfig = CodecSpecificDataUtil.buildAacAudioSpecificConfig(
        audioObjectType, sampleRateIndex, channelConfig);
    Pair<Integer, Integer> audioParams = CodecSpecificDataUtil.parseAacAudioSpecificConfig(
        audioSpecificConfig);

    Format format = Format.createAudioSampleFormat(formatId, MimeTypes.AUDIO_AAC, null,
        Format.NO_VALUE, Format.NO_VALUE, audioParams.second, audioParams.first,
        Collections.singletonList(audioSpecificConfig), null, 0, language);
    // In this class a sample is an access unit, but the MediaFormat sample rate specifies the
    // number of PCM audio samples per second.
    sampleDurationUs = (C.MICROS_PER_SECOND * 1024) / format.sampleRate;
    output.format(format);
    hasOutputFormat = true;
  } else {
    adtsScratch.skipBits(10);
  }

  adtsScratch.skipBits(4);
  int sampleSize = adtsScratch.readBits(13) - 2 /* the sync word */ - HEADER_SIZE;
  if (hasCrc) {
    sampleSize -= CRC_SIZE;
  }

  setReadingSampleState(output, sampleDurationUs, 0, sampleSize);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:52,代码来源:AdtsReader.java

示例10: getOutputFormat

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:13,代码来源:SimpleDecoderAudioRenderer.java


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