Java Code Examples for com.google.android.exoplayer2.util.Util#SDK_INT

The following examples show how to use com.google.android.exoplayer2.util.Util#SDK_INT . 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: Requirements.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isInternetConnectivityValidated(ConnectivityManager connectivityManager) {
  if (Util.SDK_INT < 23) {
    // TODO Check internet connectivity using http://clients3.google.com/generate_204 on API
    // levels prior to 23.
    return true;
  }
  Network activeNetwork = connectivityManager.getActiveNetwork();
  if (activeNetwork == null) {
    return false;
  }
  NetworkCapabilities networkCapabilities =
      connectivityManager.getNetworkCapabilities(activeNetwork);
  boolean validated =
      networkCapabilities == null
          || !networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
  return !validated;
}
 
Example 2
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a maximum input buffer size for a given format.
 *
 * @param codecInfo A {@link MediaCodecInfo} describing the decoder.
 * @param format The format.
 * @return A maximum input buffer size in bytes, or {@link Format#NO_VALUE} if a maximum could not
 *     be determined.
 */
private int getCodecMaxInputSize(MediaCodecInfo codecInfo, Format format) {
  if (Util.SDK_INT < 24 && "OMX.google.raw.decoder".equals(codecInfo.name)) {
    // OMX.google.raw.decoder didn't resize its output buffers correctly prior to N, so there's no
    // point requesting a non-default input size. Doing so may cause a native crash, where-as not
    // doing so will cause a more controlled failure when attempting to fill an input buffer. See:
    // https://github.com/google/ExoPlayer/issues/4057.
    boolean needsRawDecoderWorkaround = true;
    if (Util.SDK_INT == 23) {
      PackageManager packageManager = context.getPackageManager();
      if (packageManager != null
          && packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
        // The workaround is not required for AndroidTV devices running M.
        needsRawDecoderWorkaround = false;
      }
    }
    if (needsRawDecoderWorkaround) {
      return Format.NO_VALUE;
    }
  }
  return format.maxInputSize;
}
 
Example 3
Source File: MediaCodecAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
 * for decoding the given {@link Format} for playback.
 *
 * @param format The format of the media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxInputSize The maximum input size supported by the codec.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @return The framework media format.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, format.channelCount);
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, format.sampleRate);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set codec max values.
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxInputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET && !deviceDoesntSupportOperatingRate()) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (Util.SDK_INT <= 28 && MimeTypes.AUDIO_AC4.equals(format.sampleMimeType)) {
    // On some older builds, the AC-4 decoder expects to receive samples formatted as raw frames
    // not sync frames. Set a format key to override this.
    mediaFormat.setInteger("ac4-is-sync", 1);
  }
  return mediaFormat;
}
 
Example 4
Source File: MediaCodecUtil.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns all {@link MediaCodecInfo}s for the given mime type, in the order given by {@link
 * MediaCodecList}.
 *
 * @param mimeType The MIME type.
 * @param secure Whether the decoder is required to support secure decryption. Always pass false
 *     unless secure decryption really is required.
 * @param tunneling Whether the decoder is required to support tunneling. Always pass false unless
 *     tunneling really is required.
 * @return An unmodifiable list of all {@link MediaCodecInfo}s for the given mime type, in the
 *     order given by {@link MediaCodecList}.
 * @throws DecoderQueryException If there was an error querying the available decoders.
 */
public static synchronized List<MediaCodecInfo> getDecoderInfos(
    String mimeType, boolean secure, boolean tunneling) throws DecoderQueryException {
  CodecKey key = new CodecKey(mimeType, secure, tunneling);
  List<MediaCodecInfo> cachedDecoderInfos = decoderInfosCache.get(key);
  if (cachedDecoderInfos != null) {
    return cachedDecoderInfos;
  }
  MediaCodecListCompat mediaCodecList =
      Util.SDK_INT >= 21
          ? new MediaCodecListCompatV21(secure, tunneling)
          : new MediaCodecListCompatV16();
  ArrayList<MediaCodecInfo> decoderInfos = getDecoderInfosInternal(key, mediaCodecList);
  if (secure && decoderInfos.isEmpty() && 21 <= Util.SDK_INT && Util.SDK_INT <= 23) {
    // Some devices don't list secure decoders on API level 21 [Internal: b/18678462]. Try the
    // legacy path. We also try this path on API levels 22 and 23 as a defensive measure.
    mediaCodecList = new MediaCodecListCompatV16();
    decoderInfos = getDecoderInfosInternal(key, mediaCodecList);
    if (!decoderInfos.isEmpty()) {
      Log.w(TAG, "MediaCodecList API didn't list secure decoder for: " + mimeType
          + ". Assuming: " + decoderInfos.get(0).name);
    }
  }
  applyWorkarounds(mimeType, decoderInfos);
  List<MediaCodecInfo> unmodifiableDecoderInfos = Collections.unmodifiableList(decoderInfos);
  decoderInfosCache.put(key, unmodifiableDecoderInfos);
  return unmodifiableDecoderInfos;
}
 
Example 5
Source File: AudioTrack.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * @param audioCapabilities The audio capabilities for playback on this device. May be null if the
 *     default capabilities (no encoded audio passthrough support) should be assumed.
 * @param audioProcessors An array of {@link AudioProcessor}s that will process PCM audio before
 *     output. May be empty.
 * @param listener Listener for audio track events.
 */
public AudioTrack(AudioCapabilities audioCapabilities, AudioProcessor[] audioProcessors,
    Listener listener) {
  this.audioCapabilities = audioCapabilities;
  channelMappingAudioProcessor = new ChannelMappingAudioProcessor();
  availableAudioProcessors = new AudioProcessor[audioProcessors.length + 2];
  availableAudioProcessors[0] = new ResamplingAudioProcessor();
  availableAudioProcessors[1] = channelMappingAudioProcessor;
  System.arraycopy(audioProcessors, 0, availableAudioProcessors, 2, audioProcessors.length);
  this.listener = listener;
  releasingConditionVariable = new ConditionVariable(true);
  if (Util.SDK_INT >= 18) {
    try {
      getLatencyMethod =
          android.media.AudioTrack.class.getMethod("getLatency", (Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 23) {
    audioTrackUtil = new AudioTrackUtilV23();
  } else if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
  streamType = C.STREAM_TYPE_DEFAULT;
  audioSessionId = C.AUDIO_SESSION_ID_UNSET;
  drainingAudioProcessorIndex = C.INDEX_UNSET;
  this.audioProcessors = new AudioProcessor[0];
  outputBuffers = new ByteBuffer[0];
}
 
Example 6
Source File: PlaybackFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
/** Pauses the player. */
@TargetApi(Build.VERSION_CODES.N)
@Override
public void onPause() {
    super.onPause();

    if (mPlayerGlue != null && mPlayerGlue.isPlaying()) {
        mPlayerGlue.pause();
    }
    if (Util.SDK_INT <= 23) {
        releasePlayer();
    }
}
 
Example 7
Source File: DefaultAudioSink.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void setVolumeInternal() {
  if (!isInitialized()) {
    // Do nothing.
  } else if (Util.SDK_INT >= 21) {
    setVolumeInternalV21(audioTrack, volume);
  } else {
    setVolumeInternalV3(audioTrack, volume);
  }
}
 
Example 8
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static int adjustMaxInputChannelCount(String name, String mimeType, int maxChannelCount) {
  if (maxChannelCount > 1 || (Util.SDK_INT >= 26 && maxChannelCount > 0)) {
    // The maximum channel count looks like it's been set correctly.
    return maxChannelCount;
  }
  if (MimeTypes.AUDIO_MPEG.equals(mimeType)
      || MimeTypes.AUDIO_AMR_NB.equals(mimeType)
      || MimeTypes.AUDIO_AMR_WB.equals(mimeType)
      || MimeTypes.AUDIO_AAC.equals(mimeType)
      || MimeTypes.AUDIO_VORBIS.equals(mimeType)
      || MimeTypes.AUDIO_OPUS.equals(mimeType)
      || MimeTypes.AUDIO_RAW.equals(mimeType)
      || MimeTypes.AUDIO_FLAC.equals(mimeType)
      || MimeTypes.AUDIO_ALAW.equals(mimeType)
      || MimeTypes.AUDIO_MLAW.equals(mimeType)
      || MimeTypes.AUDIO_MSGSM.equals(mimeType)) {
    // Platform code should have set a default.
    return maxChannelCount;
  }
  // The maximum channel count looks incorrect. Adjust it to an assumed default.
  int assumedMaxChannelCount;
  if (MimeTypes.AUDIO_AC3.equals(mimeType)) {
    assumedMaxChannelCount = 6;
  } else if (MimeTypes.AUDIO_E_AC3.equals(mimeType)) {
    assumedMaxChannelCount = 16;
  } else {
    // Default to the platform limit, which is 30.
    assumedMaxChannelCount = 30;
  }
  Log.w(TAG, "AssumedMaxChannelAdjustment: " + name + ", [" + maxChannelCount + " to "
      + assumedMaxChannelCount + "]");
  return assumedMaxChannelCount;
}
 
Example 9
Source File: FrameworkMediaDrm.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static String adjustRequestMimeType(UUID uuid, String mimeType) {
  // Prior to API level 26 the ClearKey CDM only accepted "cenc" as the scheme for MP4.
  if (Util.SDK_INT < 26
      && C.CLEARKEY_UUID.equals(uuid)
      && (MimeTypes.VIDEO_MP4.equals(mimeType) || MimeTypes.AUDIO_MP4.equals(mimeType))) {
    return CENC_SCHEME_MIME_TYPE;
  }
  return mimeType;
}
 
Example 10
Source File: FrameworkMediaDrm.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static String adjustRequestMimeType(UUID uuid, String mimeType) {
  // Prior to API level 26 the ClearKey CDM only accepted "cenc" as the scheme for MP4.
  if (Util.SDK_INT < 26
      && C.CLEARKEY_UUID.equals(uuid)
      && (MimeTypes.VIDEO_MP4.equals(mimeType) || MimeTypes.AUDIO_MP4.equals(mimeType))) {
    return CENC_SCHEME_MIME_TYPE;
  }
  return mimeType;
}
 
Example 11
Source File: VideoActivity.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if ((Util.SDK_INT <= 23 || player == null)) {
        initializePlayer();
    }
}
 
Example 12
Source File: PlayerActivity.java    From exoplayer-intro with Apache License 2.0 5 votes vote down vote up
@Override
public void onStop() {
  super.onStop();
  if (Util.SDK_INT > 23) {
    releasePlayer();
  }
}
 
Example 13
Source File: DefaultDrmSessionManager.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param uuid The UUID of the drm scheme.
 * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
 * @param callback Performs key and provisioning requests.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null.
 * @param multiSession A boolean that specify whether multiple key session support is enabled.
 *     Default is false.
 * @param initialDrmRequestRetryCount The number of times to retry for initial provisioning and
 *     key request before reporting error.
 */
public DefaultDrmSessionManager(
    UUID uuid,
    ExoMediaDrm<T> mediaDrm,
    MediaDrmCallback callback,
    @Nullable HashMap<String, String> optionalKeyRequestParameters,
    boolean multiSession,
    int initialDrmRequestRetryCount) {
  Assertions.checkNotNull(uuid);
  Assertions.checkNotNull(mediaDrm);
  Assertions.checkArgument(!C.COMMON_PSSH_UUID.equals(uuid), "Use C.CLEARKEY_UUID instead");
  this.uuid = uuid;
  this.mediaDrm = mediaDrm;
  this.callback = callback;
  this.optionalKeyRequestParameters = optionalKeyRequestParameters;
  this.eventDispatcher = new EventDispatcher<>();
  this.multiSession = multiSession;
  this.initialDrmRequestRetryCount = initialDrmRequestRetryCount;
  mode = MODE_PLAYBACK;
  sessions = new ArrayList<>();
  provisioningSessions = new ArrayList<>();
  if (multiSession && C.WIDEVINE_UUID.equals(uuid) && Util.SDK_INT >= 19) {
    // TODO: Enabling session sharing probably doesn't do anything useful here. It would only be
    // useful if DefaultDrmSession instances were aware of one another's state, which is not
    // implemented. Or if custom renderers are being used that allow playback to proceed before
    // keys, which seems unlikely to be true in practice.
    mediaDrm.setPropertyString("sessionSharing", "enable");
  }
  mediaDrm.setOnEventListener(new MediaDrmEventListener());
}
 
Example 14
Source File: MediaCodecInfo.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isTunneling(CodecCapabilities capabilities) {
  return Util.SDK_INT >= 21 && isTunnelingV21(capabilities);
}
 
Example 15
Source File: AudioFocusManager.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Converts {@link AudioAttributes} to one of the audio focus request.
 *
 * <p>This follows the class Javadoc of {@link AudioFocusRequest}.
 *
 * @param audioAttributes The audio attributes associated with this focus request.
 * @return The type of audio focus gain that should be requested.
 */
@C.AudioFocusGain
private static int convertAudioAttributesToFocusGain(@Nullable AudioAttributes audioAttributes) {

  if (audioAttributes == null) {
    // Don't handle audio focus. It may be either video only contents or developers
    // want to have more finer grained control. (e.g. adding audio focus listener)
    return C.AUDIOFOCUS_NONE;
  }

  switch (audioAttributes.usage) {
      // USAGE_VOICE_COMMUNICATION_SIGNALLING is for DTMF that may happen multiple times
      // during the phone call when AUDIOFOCUS_GAIN_TRANSIENT is requested for that.
      // Don't request audio focus here.
    case C.USAGE_VOICE_COMMUNICATION_SIGNALLING:
      return C.AUDIOFOCUS_NONE;

      // Javadoc says 'AUDIOFOCUS_GAIN: Examples of uses of this focus gain are for music
      // playback, for a game or a video player'
    case C.USAGE_GAME:
    case C.USAGE_MEDIA:
      return C.AUDIOFOCUS_GAIN;

      // Special usages: USAGE_UNKNOWN shouldn't be used. Request audio focus to prevent
      // multiple media playback happen at the same time.
    case C.USAGE_UNKNOWN:
      Log.w(
          TAG,
          "Specify a proper usage in the audio attributes for audio focus"
              + " handling. Using AUDIOFOCUS_GAIN by default.");
      return C.AUDIOFOCUS_GAIN;

      // Javadoc says 'AUDIOFOCUS_GAIN_TRANSIENT: An example is for playing an alarm, or
      // during a VoIP call'
    case C.USAGE_ALARM:
    case C.USAGE_VOICE_COMMUNICATION:
      return C.AUDIOFOCUS_GAIN_TRANSIENT;

      // Javadoc says 'AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK: Examples are when playing
      // driving directions or notifications'
    case C.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
    case C.USAGE_ASSISTANCE_SONIFICATION:
    case C.USAGE_NOTIFICATION:
    case C.USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
    case C.USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
    case C.USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
    case C.USAGE_NOTIFICATION_EVENT:
    case C.USAGE_NOTIFICATION_RINGTONE:
      return C.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK;

      // Javadoc says 'AUDIOFOCUS_GAIN_EXCLUSIVE: This is typically used if you are doing
      // audio recording or speech recognition'.
      // Assistant is considered as both recording and notifying developer
    case C.USAGE_ASSISTANT:
      if (Util.SDK_INT >= 19) {
        return C.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE;
      } else {
        return C.AUDIOFOCUS_GAIN_TRANSIENT;
      }

      // Special usages:
    case C.USAGE_ASSISTANCE_ACCESSIBILITY:
      if (audioAttributes.contentType == C.CONTENT_TYPE_SPEECH) {
        // Voice shouldn't be interrupted by other playback.
        return C.AUDIOFOCUS_GAIN_TRANSIENT;
      }
      return C.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK;
    default:
      Log.w(TAG, "Unidentified audio usage: " + audioAttributes.usage);
      return C.AUDIOFOCUS_NONE;
  }
}
 
Example 16
Source File: CryptoInfo.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
public CryptoInfo() {
  frameworkCryptoInfo = new android.media.MediaCodec.CryptoInfo();
  patternHolder = Util.SDK_INT >= 24 ? new PatternHolderV24(frameworkCryptoInfo) : null;
}
 
Example 17
Source File: FrameworkMediaDrm.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static UUID adjustUuid(UUID uuid) {
  // ClearKey had to be accessed using the Common PSSH UUID prior to API level 27.
  return Util.SDK_INT < 27 && C.CLEARKEY_UUID.equals(uuid) ? C.COMMON_PSSH_UUID : uuid;
}
 
Example 18
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isSecure(CodecCapabilities capabilities) {
  return Util.SDK_INT >= 21 && isSecureV21(capabilities);
}
 
Example 19
Source File: MediaCodecUtil.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns whether the decoder is known to fail when adapting, despite advertising itself as an
 * adaptive decoder.
 *
 * @param name The decoder name.
 * @return True if the decoder is known to fail when adapting.
 */
private static boolean codecNeedsDisableAdaptationWorkaround(String name) {
  return Util.SDK_INT <= 22
      && ("ODROID-XU3".equals(Util.MODEL) || "Nexus 10".equals(Util.MODEL))
      && ("OMX.Exynos.AVC.Decoder".equals(name) || "OMX.Exynos.AVC.Decoder.secure".equals(name));
}
 
Example 20
Source File: MediaCodecRenderer.java    From K-Sonic with MIT License 2 votes vote down vote up
/**
 * Returns whether the decoder is known to handle the propagation of the
 * {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM} flag incorrectly on the host device.
 * <p>
 * If true is returned, the renderer will work around the issue by approximating end of stream
 * behavior without relying on the flag being propagated through to an output buffer by the
 * underlying decoder.
 *
 * @param name The name of the decoder.
 * @return True if the decoder is known to handle {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM}
 *     propagation incorrectly on the host device. False otherwise.
 */
private static boolean codecNeedsEosPropagationWorkaround(String name) {
  return Util.SDK_INT <= 17 && ("OMX.rk.video_decoder.avc".equals(name)
      || "OMX.allwinner.video.decoder.avc".equals(name));
}