use of androidx.annotation.RequiresApi in project ExoPlayer by google.
the class MediaCodecInfo method alignVideoSizeV21.
@RequiresApi(21)
private static Point alignVideoSizeV21(VideoCapabilities capabilities, int width, int height) {
int widthAlignment = capabilities.getWidthAlignment();
int heightAlignment = capabilities.getHeightAlignment();
return new Point(Util.ceilDivide(width, widthAlignment) * widthAlignment, Util.ceilDivide(height, heightAlignment) * heightAlignment);
}
use of androidx.annotation.RequiresApi in project ExoPlayer by google.
the class MediaCodecInfo method areSizeAndRateSupportedV21.
@RequiresApi(21)
private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width, int height, double frameRate) {
// Don't ever fail due to alignment. See: https://github.com/google/ExoPlayer/issues/6551.
Point alignedSize = alignVideoSizeV21(capabilities, width, height);
width = alignedSize.x;
height = alignedSize.y;
// versions of Android, so we only check the size in this case [Internal ref: b/153940404].
if (frameRate == Format.NO_VALUE || frameRate < 1) {
return capabilities.isSizeSupported(width, height);
} else {
// The signaled frame rate may be slightly higher than the actual frame rate, so we take the
// floor to avoid situations where a range check in areSizeAndRateSupported fails due to
// slightly exceeding the limits for a standard format (e.g., 1080p at 30 fps).
double floorFrameRate = Math.floor(frameRate);
return capabilities.areSizeAndRateSupported(width, height, floorFrameRate);
}
}
use of androidx.annotation.RequiresApi in project ExoPlayer by google.
the class DefaultAudioSink method writeNonBlockingWithAvSyncV21.
@RequiresApi(21)
private int writeNonBlockingWithAvSyncV21(AudioTrack audioTrack, ByteBuffer buffer, int size, long presentationTimeUs) {
if (Util.SDK_INT >= 26) {
// The underlying platform AudioTrack writes AV sync headers directly.
return audioTrack.write(buffer, size, AudioTrack.WRITE_NON_BLOCKING, presentationTimeUs * 1000);
}
if (avSyncHeader == null) {
avSyncHeader = ByteBuffer.allocate(16);
avSyncHeader.order(ByteOrder.BIG_ENDIAN);
avSyncHeader.putInt(0x55550001);
}
if (bytesUntilNextAvSync == 0) {
avSyncHeader.putInt(4, size);
avSyncHeader.putLong(8, presentationTimeUs * 1000);
avSyncHeader.position(0);
bytesUntilNextAvSync = size;
}
int avSyncHeaderBytesRemaining = avSyncHeader.remaining();
if (avSyncHeaderBytesRemaining > 0) {
int result = audioTrack.write(avSyncHeader, avSyncHeaderBytesRemaining, AudioTrack.WRITE_NON_BLOCKING);
if (result < 0) {
bytesUntilNextAvSync = 0;
return result;
}
if (result < avSyncHeaderBytesRemaining) {
return 0;
}
}
int result = writeNonBlockingV21(audioTrack, buffer, size);
if (result < 0) {
bytesUntilNextAvSync = 0;
return result;
}
bytesUntilNextAvSync -= result;
return result;
}
use of androidx.annotation.RequiresApi in project ExoPlayer by google.
the class DefaultAudioSink method setAudioTrackPlaybackParametersV23.
@RequiresApi(23)
private void setAudioTrackPlaybackParametersV23(PlaybackParameters audioTrackPlaybackParameters) {
if (isAudioTrackInitialized()) {
PlaybackParams playbackParams = new PlaybackParams().allowDefaults().setSpeed(audioTrackPlaybackParameters.speed).setPitch(audioTrackPlaybackParameters.pitch).setAudioFallbackMode(PlaybackParams.AUDIO_FALLBACK_MODE_FAIL);
try {
audioTrack.setPlaybackParams(playbackParams);
} catch (IllegalArgumentException e) {
Log.w(TAG, "Failed to set playback params", e);
}
// Update the speed using the actual effective speed from the audio track.
audioTrackPlaybackParameters = new PlaybackParameters(audioTrack.getPlaybackParams().getSpeed(), audioTrack.getPlaybackParams().getPitch());
audioTrackPositionTracker.setAudioTrackPlaybackSpeed(audioTrackPlaybackParameters.speed);
}
this.audioTrackPlaybackParameters = audioTrackPlaybackParameters;
}
use of androidx.annotation.RequiresApi in project Gadgetbridge by Freeyourgadget.
the class DiscoveryActivity method stopBLEDiscovery.
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private void stopBLEDiscovery() {
if (adapter == null) {
return;
}
BluetoothLeScanner bluetoothLeScanner = adapter.getBluetoothLeScanner();
if (bluetoothLeScanner == null) {
LOG.warn("Could not get BluetoothLeScanner()!");
return;
}
if (newBLEScanCallback == null) {
LOG.warn("newLeScanCallback == null!");
return;
}
try {
bluetoothLeScanner.stopScan(newBLEScanCallback);
} catch (NullPointerException e) {
LOG.warn("Internal NullPointerException when stopping the scan!");
return;
}
LOG.debug("Stopped BLE discovery");
setIsScanning(Scanning.SCANNING_OFF);
}
Aggregations