com.google.android.exoplayer2.util.MimeTypes Java Examples

The following examples show how to use com.google.android.exoplayer2.util.MimeTypes. 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: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void configureCodec(
    MediaCodecInfo codecInfo,
    MediaCodec codec,
    Format format,
    MediaCrypto crypto,
    float codecOperatingRate) {
  codecMaxInputSize = getCodecMaxInputSize(codecInfo, format, getStreamFormats());
  codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
  passthroughEnabled = codecInfo.passthrough;
  String codecMimeType = codecInfo.mimeType == null ? MimeTypes.AUDIO_RAW : codecInfo.mimeType;
  MediaFormat mediaFormat =
      getMediaFormat(format, codecMimeType, codecMaxInputSize, codecOperatingRate);
  codec.configure(mediaFormat, /* surface= */ null, crypto, /* flags= */ 0);
  if (passthroughEnabled) {
    // Store the input MIME type if we're using the passthrough codec.
    passthroughMediaFormat = mediaFormat;
    passthroughMediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
  } else {
    passthroughMediaFormat = null;
  }
}
 
Example #2
Source File: SoftVideoRenderer.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
@Override
public int supportsFormat(Format format) {
  if (!DecoderSoLibrary.isAvailable() ||
          !(MimeTypes.VIDEO_MP4.equalsIgnoreCase(format.sampleMimeType)
          || MimeTypes.VIDEO_H264.equalsIgnoreCase(format.sampleMimeType)
          || MimeTypes.VIDEO_H265.equalsIgnoreCase(format.sampleMimeType)
          || MimeTypes.VIDEO_MPEG.equalsIgnoreCase(format.sampleMimeType)
          || MimeTypes.VIDEO_MPEG2.equalsIgnoreCase(format.sampleMimeType))
          ) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  }

  // ffmpeg解码需要
  if (format.initializationData == null || format.initializationData.size() <= 0) {
    return FORMAT_EXCEEDS_CAPABILITIES;
  }

  return FORMAT_HANDLED | ADAPTIVE_SEAMLESS;
}
 
Example #3
Source File: SpliceInfoSectionReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void consume(ParsableByteArray sectionData) {
  if (!formatDeclared) {
    if (timestampAdjuster.getTimestampOffsetUs() == C.TIME_UNSET) {
      // There is not enough information to initialize the timestamp adjuster.
      return;
    }
    output.format(Format.createSampleFormat(null, MimeTypes.APPLICATION_SCTE35,
        timestampAdjuster.getTimestampOffsetUs()));
    formatDeclared = true;
  }
  int sampleSize = sectionData.bytesLeft();
  output.sampleData(sectionData, sampleSize);
  output.sampleMetadata(timestampAdjuster.getLastAdjustedTimestampUs(), C.BUFFER_FLAG_KEY_FRAME,
      sampleSize, 0, null);
}
 
Example #4
Source File: AudioDecoder.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
/**
 * Returns FFmpeg-compatible codec-specific initialization data ("extra data"), or {@code null} if
 * not required.
 */
private static @Nullable
byte[] getExtraData(String mimeType, List<byte[]> initializationData) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AAC:
    case MimeTypes.AUDIO_ALAC:
    case MimeTypes.AUDIO_OPUS:
      return initializationData.get(0);
    case MimeTypes.AUDIO_VORBIS:
      byte[] header0 = initializationData.get(0);
      byte[] header1 = initializationData.get(1);
      byte[] extraData = new byte[header0.length + header1.length + 6];
      extraData[0] = (byte) (header0.length >> 8);
      extraData[1] = (byte) (header0.length & 0xFF);
      System.arraycopy(header0, 0, extraData, 2, header0.length);
      extraData[header0.length + 2] = 0;
      extraData[header0.length + 3] = 0;
      extraData[header0.length + 4] =  (byte) (header1.length >> 8);
      extraData[header0.length + 5] = (byte) (header1.length & 0xFF);
      System.arraycopy(header1, 0, extraData, header0.length + 6, header1.length);
      return extraData;
    default:
      // Other codecs do not require extra data.
      return null;
  }
}
 
Example #5
Source File: FlacExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void outputFormat(
    FlacStreamMetadata streamMetadata, @Nullable Metadata metadata, TrackOutput output) {
  Format mediaFormat =
      Format.createAudioSampleFormat(
          /* id= */ null,
          MimeTypes.AUDIO_RAW,
          /* codecs= */ null,
          streamMetadata.bitRate(),
          streamMetadata.maxDecodedFrameSize(),
          streamMetadata.channels,
          streamMetadata.sampleRate,
          getPcmEncoding(streamMetadata.bitsPerSample),
          /* encoderDelay= */ 0,
          /* encoderPadding= */ 0,
          /* initializationData= */ null,
          /* drmInitData= */ null,
          /* selectionFlags= */ 0,
          /* language= */ null,
          metadata);
  output.format(mediaFormat);
}
 
Example #6
Source File: MetadataDecoderFactory.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MetadataDecoder createDecoder(Format format) {
  switch (format.sampleMimeType) {
    case MimeTypes.APPLICATION_ID3:
      return new Id3Decoder();
    case MimeTypes.APPLICATION_EMSG:
      return new EventMessageDecoder();
    case MimeTypes.APPLICATION_SCTE35:
      return new SpliceInfoDecoder();
    case MimeTypes.APPLICATION_ICY:
      return new IcyDecoder();
    default:
      throw new IllegalArgumentException(
          "Attempted to create decoder for unsupported format");
  }
}
 
Example #7
Source File: MediaCodecAudioRenderer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link C.Encoding} constant to use for passthrough of the given format, or {@link
 * C#ENCODING_INVALID} if passthrough is not possible.
 */
@C.Encoding
protected int getPassthroughEncoding(int channelCount, String mimeType) {
  if (MimeTypes.AUDIO_E_AC3_JOC.equals(mimeType)) {
    if (audioSink.supportsOutput(channelCount, C.ENCODING_E_AC3_JOC)) {
      return MimeTypes.getEncoding(MimeTypes.AUDIO_E_AC3_JOC);
    }
    // E-AC3 receivers can decode JOC streams, but in 2-D rather than 3-D, so try to fall back.
    mimeType = MimeTypes.AUDIO_E_AC3;
  }

  @C.Encoding int encoding = MimeTypes.getEncoding(mimeType);
  if (audioSink.supportsOutput(channelCount, encoding)) {
    return encoding;
  } else {
    return C.ENCODING_INVALID;
  }
}
 
Example #8
Source File: HlsSampleStreamWrapper.java    From K-Sonic with MIT License 6 votes vote down vote up
private static String getCodecsOfType(String codecs, int trackType) {
  if (TextUtils.isEmpty(codecs)) {
    return null;
  }
  String[] codecArray = codecs.split("(\\s*,\\s*)|(\\s*$)");
  StringBuilder builder = new StringBuilder();
  for (String codec : codecArray) {
    if (trackType == MimeTypes.getTrackTypeOfCodec(codec)) {
      if (builder.length() > 0) {
        builder.append(",");
      }
      builder.append(codec);
    }
  }
  return builder.length() > 0 ? builder.toString() : null;
}
 
Example #9
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/** Returns DrmInitData from leaf atoms. */
private static DrmInitData getDrmInitDataFromAtoms(List<Atom.LeafAtom> leafChildren) {
  ArrayList<SchemeData> schemeDatas = null;
  int leafChildrenSize = leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom child = leafChildren.get(i);
    if (child.type == Atom.TYPE_pssh) {
      if (schemeDatas == null) {
        schemeDatas = new ArrayList<>();
      }
      byte[] psshData = child.data.data;
      UUID uuid = PsshAtomUtil.parseUuid(psshData);
      if (uuid == null) {
        Log.w(TAG, "Skipped pssh atom (failed to extract uuid)");
      } else {
        schemeDatas.add(new SchemeData(uuid, MimeTypes.VIDEO_MP4, psshData));
      }
    }
  }
  return schemeDatas == null ? null : new DrmInitData(schemeDatas);
}
 
Example #10
Source File: UserDataReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void createTracks(
    ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    Format channelFormat = closedCaptionFormats.get(i);
    String channelMimeType = channelFormat.sampleMimeType;
    Assertions.checkArgument(
        MimeTypes.APPLICATION_CEA608.equals(channelMimeType)
            || MimeTypes.APPLICATION_CEA708.equals(channelMimeType),
        "Invalid closed caption mime type provided: " + channelMimeType);
    output.format(
        Format.createTextSampleFormat(
            idGenerator.getFormatId(),
            channelMimeType,
            /* codecs= */ null,
            /* bitrate= */ Format.NO_VALUE,
            channelFormat.selectionFlags,
            channelFormat.language,
            channelFormat.accessibilityChannel,
            /* drmInitData= */ null,
            Format.OFFSET_SAMPLE_RELATIVE,
            channelFormat.initializationData));
    outputs[i] = output;
  }
}
 
Example #11
Source File: FfmpegAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private boolean shouldUseFloatOutput(Format inputFormat) {
  Assertions.checkNotNull(inputFormat.sampleMimeType);
  if (!enableFloatOutput || !supportsOutputEncoding(C.ENCODING_PCM_FLOAT)) {
    return false;
  }
  switch (inputFormat.sampleMimeType) {
    case MimeTypes.AUDIO_RAW:
      // For raw audio, output in 32-bit float encoding if the bit depth is > 16-bit.
      return inputFormat.pcmEncoding == C.ENCODING_PCM_24BIT
          || inputFormat.pcmEncoding == C.ENCODING_PCM_32BIT
          || inputFormat.pcmEncoding == C.ENCODING_PCM_FLOAT;
    case MimeTypes.AUDIO_AC3:
      // AC-3 is always 16-bit, so there is no point outputting in 32-bit float encoding.
      return false;
    default:
      // For all other formats, assume that it's worth using 32-bit float encoding.
      return true;
  }
}
 
Example #12
Source File: Cea608Decoder.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public Cea608Decoder(String mimeType, int accessibilityChannel) {
  ccData = new ParsableByteArray();
  cueBuilders = new ArrayList<>();
  currentCueBuilder = new CueBuilder(CC_MODE_UNKNOWN, DEFAULT_CAPTIONS_ROW_COUNT);
  packetLength = MimeTypes.APPLICATION_MP4CEA608.equals(mimeType) ? 2 : 3;
  switch (accessibilityChannel) {
    case 3:
    case 4:
      selectedField = 2;
      break;
    case 1:
    case 2:
    case Format.NO_VALUE:
    default:
      selectedField = 1;
  }

  setCaptionMode(CC_MODE_UNKNOWN);
  resetCueBuilders();
}
 
Example #13
Source File: DvbSubtitleReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    DvbSubtitleInfo subtitleInfo = subtitleInfos.get(i);
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    output.format(
        Format.createImageSampleFormat(
            idGenerator.getFormatId(),
            MimeTypes.APPLICATION_DVBSUBS,
            null,
            Format.NO_VALUE,
            0,
            Collections.singletonList(subtitleInfo.initializationData),
            subtitleInfo.language,
            null));
    outputs[i] = output;
  }
}
 
Example #14
Source File: AmrExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
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));
  }
}
 
Example #15
Source File: MediaCodecInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private MediaCodecInfo(
    String name,
    @Nullable String mimeType,
    @Nullable String codecMimeType,
    @Nullable CodecCapabilities capabilities,
    boolean passthrough,
    boolean hardwareAccelerated,
    boolean softwareOnly,
    boolean vendor,
    boolean forceDisableAdaptive,
    boolean forceSecure) {
  this.name = Assertions.checkNotNull(name);
  this.mimeType = mimeType;
  this.codecMimeType = codecMimeType;
  this.capabilities = capabilities;
  this.passthrough = passthrough;
  this.hardwareAccelerated = hardwareAccelerated;
  this.softwareOnly = softwareOnly;
  this.vendor = vendor;
  adaptive = !forceDisableAdaptive && capabilities != null && isAdaptive(capabilities);
  tunneling = capabilities != null && isTunneling(capabilities);
  secure = forceSecure || (capabilities != null && isSecure(capabilities));
  isVideo = MimeTypes.isVideo(mimeType);
}
 
Example #16
Source File: MediaCodecAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link C.Encoding} constant to use for passthrough of the given format, or {@link
 * C#ENCODING_INVALID} if passthrough is not possible.
 */
@C.Encoding
protected int getPassthroughEncoding(int channelCount, String mimeType) {
  if (MimeTypes.AUDIO_E_AC3_JOC.equals(mimeType)) {
    if (audioSink.supportsOutput(channelCount, C.ENCODING_E_AC3_JOC)) {
      return MimeTypes.getEncoding(MimeTypes.AUDIO_E_AC3_JOC);
    }
    // E-AC3 receivers can decode JOC streams, but in 2-D rather than 3-D, so try to fall back.
    mimeType = MimeTypes.AUDIO_E_AC3;
  }

  @C.Encoding int encoding = MimeTypes.getEncoding(mimeType);
  if (audioSink.supportsOutput(channelCount, encoding)) {
    return encoding;
  } else {
    return C.ENCODING_INVALID;
  }
}
 
Example #17
Source File: HlsMasterPlaylist.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a variant for a given media playlist url.
 *
 * @param url The media playlist url.
 * @return The variant instance.
 */
public static Variant createMediaPlaylistVariantUrl(Uri url) {
  Format format =
      Format.createContainerFormat(
          "0",
          /* label= */ null,
          MimeTypes.APPLICATION_M3U8,
          /* sampleMimeType= */ null,
          /* codecs= */ null,
          /* bitrate= */ Format.NO_VALUE,
          /* selectionFlags= */ 0,
          /* roleFlags= */ 0,
          /* language= */ null);
  return new Variant(
      url,
      format,
      /* videoGroupId= */ null,
      /* audioGroupId= */ null,
      /* subtitleGroupId= */ null,
      /* captionGroupId= */ null);
}
 
Example #18
Source File: DashManifestParser.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Derives a sample mimeType from a container mimeType and codecs attribute.
 *
 * @param containerMimeType The mimeType of the container.
 * @param codecs The codecs attribute.
 * @return The derived sample mimeType, or null if it could not be derived.
 */
private static String getSampleMimeType(String containerMimeType, String codecs) {
  if (MimeTypes.isAudio(containerMimeType)) {
    return MimeTypes.getAudioMediaMimeType(codecs);
  } else if (MimeTypes.isVideo(containerMimeType)) {
    return MimeTypes.getVideoMediaMimeType(codecs);
  } else if (mimeTypeIsRawText(containerMimeType)) {
    return containerMimeType;
  } else if (MimeTypes.APPLICATION_MP4.equals(containerMimeType)) {
    if ("stpp".equals(codecs)) {
      return MimeTypes.APPLICATION_TTML;
    } else if ("wvtt".equals(codecs)) {
      return MimeTypes.APPLICATION_MP4VTT;
    }
  } else if (MimeTypes.APPLICATION_RAWCC.equals(containerMimeType)) {
    if (codecs != null) {
      if (codecs.contains("cea708")) {
        return MimeTypes.APPLICATION_CEA708;
      } else if (codecs.contains("eia608") || codecs.contains("cea608")) {
        return MimeTypes.APPLICATION_CEA608;
      }
    }
    return null;
  }
  return null;
}
 
Example #19
Source File: Ac3Util.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.
 * @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,
      /* codecs= */ null,
      Format.NO_VALUE,
      Format.NO_VALUE,
      channelCount,
      sampleRate,
      /* initializationData= */ null,
      drmInitData,
      /* selectionFlags= */ 0,
      language);
}
 
Example #20
Source File: HlsMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static Format deriveVideoFormat(Format variantFormat) {
  String codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_VIDEO);
  String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
  return Format.createVideoContainerFormat(
      variantFormat.id,
      variantFormat.label,
      variantFormat.containerMimeType,
      sampleMimeType,
      codecs,
      variantFormat.metadata,
      variantFormat.bitrate,
      variantFormat.width,
      variantFormat.height,
      variantFormat.frameRate,
      /* initializationData= */ null,
      variantFormat.selectionFlags,
      variantFormat.roleFlags);
}
 
Example #21
Source File: SsManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static String fourCCToMimeType(String fourCC) {
  if (fourCC.equalsIgnoreCase("H264") || fourCC.equalsIgnoreCase("X264")
      || fourCC.equalsIgnoreCase("AVC1") || fourCC.equalsIgnoreCase("DAVC")) {
    return MimeTypes.VIDEO_H264;
  } else if (fourCC.equalsIgnoreCase("AAC") || fourCC.equalsIgnoreCase("AACL")
      || fourCC.equalsIgnoreCase("AACH") || fourCC.equalsIgnoreCase("AACP")) {
    return MimeTypes.AUDIO_AAC;
  } else if (fourCC.equalsIgnoreCase("TTML") || fourCC.equalsIgnoreCase("DFXP")) {
    return MimeTypes.APPLICATION_TTML;
  } else if (fourCC.equalsIgnoreCase("ac-3") || fourCC.equalsIgnoreCase("dac3")) {
    return MimeTypes.AUDIO_AC3;
  } else if (fourCC.equalsIgnoreCase("ec-3") || fourCC.equalsIgnoreCase("dec3")) {
    return MimeTypes.AUDIO_E_AC3;
  } else if (fourCC.equalsIgnoreCase("dtsc")) {
    return MimeTypes.AUDIO_DTS;
  } else if (fourCC.equalsIgnoreCase("dtsh") || fourCC.equalsIgnoreCase("dtsl")) {
    return MimeTypes.AUDIO_DTS_HD;
  } else if (fourCC.equalsIgnoreCase("dtse")) {
    return MimeTypes.AUDIO_DTS_EXPRESS;
  } else if (fourCC.equalsIgnoreCase("opus")) {
    return MimeTypes.AUDIO_OPUS;
  }
  return null;
}
 
Example #22
Source File: DtsUtil.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 * @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, @Nullable String language, @Nullable DrmInitData drmInitData) {
  ParsableBitArray frameBits = getNormalizedFrameHeader(frame);
  frameBits.skipBits(32 + 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);
}
 
Example #23
Source File: MediaCodecAudioRenderer.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format)
    throws DecoderQueryException {
  String mimeType = format.sampleMimeType;
  if (!MimeTypes.isAudio(mimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  }
  int tunnelingSupport = Util.SDK_INT >= 21 ? TUNNELING_SUPPORTED : TUNNELING_NOT_SUPPORTED;
  if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderInfo() != null) {
    return ADAPTIVE_NOT_SEAMLESS | tunnelingSupport | FORMAT_HANDLED;
  }
  MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType, false);
  if (decoderInfo == null) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  }
  // Note: We assume support for unknown sampleRate and channelCount.
  boolean decoderCapable = Util.SDK_INT < 21
      || ((format.sampleRate == Format.NO_VALUE
      || decoderInfo.isAudioSampleRateSupportedV21(format.sampleRate))
      && (format.channelCount == Format.NO_VALUE
      ||  decoderInfo.isAudioChannelCountSupportedV21(format.channelCount)));
  int formatSupport = decoderCapable ? FORMAT_HANDLED : FORMAT_EXCEEDS_CAPABILITIES;
  return ADAPTIVE_NOT_SEAMLESS | tunnelingSupport | formatSupport;
}
 
Example #24
Source File: MediaCodecUtil.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns information about a decoder suitable for audio passthrough.
 *
 * @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder exists.
 * @throws DecoderQueryException If there was an error querying the available decoders.
 */
@Nullable
public static MediaCodecInfo getPassthroughDecoderInfo() throws DecoderQueryException {
  MediaCodecInfo decoderInfo =
      getDecoderInfo(MimeTypes.AUDIO_RAW, /* secure= */ false, /* tunneling= */ false);
  return decoderInfo == null ? null : MediaCodecInfo.newPassthroughInstance(decoderInfo.name);
}
 
Example #25
Source File: MediaCodecUtil.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns information about a decoder suitable for audio passthrough.
 *
 * @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder exists.
 * @throws DecoderQueryException If there was an error querying the available decoders.
 */
@Nullable
public static MediaCodecInfo getPassthroughDecoderInfo() throws DecoderQueryException {
  MediaCodecInfo decoderInfo =
      getDecoderInfo(MimeTypes.AUDIO_RAW, /* secure= */ false, /* tunneling= */ false);
  return decoderInfo == null ? null : MediaCodecInfo.newPassthroughInstance(decoderInfo.name);
}
 
Example #26
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testWidevineH265Adaptive() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H265)) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_h265_adaptive";
  testDashPlayback(getActivity(), streamName, WIDEVINE_H265_MANIFEST_PREFIX,
      WIDEVINE_AAC_AUDIO_REPRESENTATION_ID, true, MimeTypes.VIDEO_H265,
      ALLOW_ADDITIONAL_VIDEO_FORMATS, WIDEVINE_H265_CDD_ADAPTIVE);
}
 
Example #27
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testH265AdaptiveWithSeeking() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H265)) {
    // Pass.
    return;
  }
  String streamName = "test_h265_adaptive_with_seeking";
  testDashPlayback(getActivity(), streamName, SEEKING_SCHEDULE, false, H265_MANIFEST,
      AAC_AUDIO_REPRESENTATION_ID, false, MimeTypes.VIDEO_H265, ALLOW_ADDITIONAL_VIDEO_FORMATS,
      H265_CDD_ADAPTIVE);
}
 
Example #28
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testWidevineH264AdaptiveWithSeeking() throws DecoderQueryException {
  if (Util.SDK_INT < 18 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H264)) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_h264_adaptive_with_seeking";
  testDashPlayback(getActivity(), streamName, SEEKING_SCHEDULE, false,
      WIDEVINE_H264_MANIFEST_PREFIX, WIDEVINE_AAC_AUDIO_REPRESENTATION_ID, true,
      MimeTypes.VIDEO_H264, ALLOW_ADDITIONAL_VIDEO_FORMATS, WIDEVINE_H264_CDD_ADAPTIVE);
}
 
Example #29
Source File: SubtitleDecoderFactory.java    From K-Sonic with MIT License 5 votes vote down vote up
private Class<?> getDecoderClass(String mimeType) {
  if (mimeType == null) {
    return null;
  }
  try {
    switch (mimeType) {
      case MimeTypes.TEXT_VTT:
        return Class.forName("com.google.android.exoplayer2.text.webvtt.WebvttDecoder");
      case MimeTypes.APPLICATION_TTML:
        return Class.forName("com.google.android.exoplayer2.text.ttml.TtmlDecoder");
      case MimeTypes.APPLICATION_MP4VTT:
        return Class.forName("com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder");
      case MimeTypes.APPLICATION_SUBRIP:
        return Class.forName("com.google.android.exoplayer2.text.subrip.SubripDecoder");
      case MimeTypes.APPLICATION_TX3G:
        return Class.forName("com.google.android.exoplayer2.text.tx3g.Tx3gDecoder");
      case MimeTypes.APPLICATION_CEA608:
      case MimeTypes.APPLICATION_MP4CEA608:
        return Class.forName("com.google.android.exoplayer2.text.cea.Cea608Decoder");
      case MimeTypes.APPLICATION_CEA708:
        return Class.forName("com.google.android.exoplayer2.text.cea.Cea708Decoder");
      default:
        return null;
    }
  } catch (ClassNotFoundException e) {
    return null;
  }
}
 
Example #30
Source File: LibopusAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  if (!MimeTypes.AUDIO_OPUS.equalsIgnoreCase(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!supportsOutputEncoding(C.ENCODING_PCM_16BIT)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}