Fixed checkstyle problems
Unable to compile! * Cleaned up ``getMostCompactAudioIndex`` and ``getHighestQualityAudioIndex`` into a new method ``getAudioIndexByHighestRank`` * Removed unreadable code and use Java Streams API * Tests work as expected
This commit is contained in:
parent
8ed87e7fbb
commit
a489f40b76
|
@ -288,28 +288,12 @@ public final class ListHelper {
|
||||||
* @param audioStreams List of audio streams
|
* @param audioStreams List of audio streams
|
||||||
* @return Index of audio stream that produces the most compact results or -1 if not found
|
* @return Index of audio stream that produces the most compact results or -1 if not found
|
||||||
*/
|
*/
|
||||||
static int getHighestQualityAudioIndex(@Nullable MediaFormat format,
|
static int getHighestQualityAudioIndex(@Nullable final MediaFormat format,
|
||||||
final List<AudioStream> audioStreams) {
|
@Nullable final List<AudioStream> audioStreams) {
|
||||||
int result = -1;
|
return getAudioIndexByHighestRank(format, audioStreams,
|
||||||
if (audioStreams != null) {
|
// Compares descending (last = highest rank)
|
||||||
while (result == -1) {
|
(s1, s2) -> compareAudioStreamBitrate(s1, s2, AUDIO_FORMAT_QUALITY_RANKING)
|
||||||
AudioStream prevStream = null;
|
);
|
||||||
for (int idx = 0; idx < audioStreams.size(); idx++) {
|
|
||||||
final AudioStream stream = audioStreams.get(idx);
|
|
||||||
if ((format == null || stream.getFormat() == format)
|
|
||||||
&& (prevStream == null || compareAudioStreamBitrate(prevStream, stream,
|
|
||||||
AUDIO_FORMAT_QUALITY_RANKING) < 0)) {
|
|
||||||
prevStream = stream;
|
|
||||||
result = idx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result == -1 && format == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
format = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -320,28 +304,47 @@ public final class ListHelper {
|
||||||
* @param audioStreams List of audio streams
|
* @param audioStreams List of audio streams
|
||||||
* @return Index of audio stream that produces the most compact results or -1 if not found
|
* @return Index of audio stream that produces the most compact results or -1 if not found
|
||||||
*/
|
*/
|
||||||
static int getMostCompactAudioIndex(@Nullable MediaFormat format,
|
static int getMostCompactAudioIndex(@Nullable final MediaFormat format,
|
||||||
final List<AudioStream> audioStreams) {
|
@Nullable final List<AudioStream> audioStreams) {
|
||||||
int result = -1;
|
|
||||||
if (audioStreams != null) {
|
return getAudioIndexByHighestRank(format, audioStreams,
|
||||||
while (result == -1) {
|
// The "-" is important -> Compares ascending (first = highest rank)
|
||||||
AudioStream prevStream = null;
|
(s1, s2) -> -compareAudioStreamBitrate(s1, s2, AUDIO_FORMAT_EFFICIENCY_RANKING)
|
||||||
for (int idx = 0; idx < audioStreams.size(); idx++) {
|
);
|
||||||
final AudioStream stream = audioStreams.get(idx);
|
|
||||||
if ((format == null || stream.getFormat() == format)
|
|
||||||
&& (prevStream == null || compareAudioStreamBitrate(prevStream, stream,
|
|
||||||
AUDIO_FORMAT_EFFICIENCY_RANKING) > 0)) {
|
|
||||||
prevStream = stream;
|
|
||||||
result = idx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the audio-stream from the list with the highest rank, depending on the comparator.
|
||||||
|
* Format will be ignored if it yields no results.
|
||||||
|
*
|
||||||
|
* @param targetedFormat The target format type or null if it doesn't matter
|
||||||
|
* @param audioStreams List of audio streams
|
||||||
|
* @param comparator The comparator used for determining the max/best/highest ranked value
|
||||||
|
* @return Index of audio stream that produces the most compact results or -1 if not found
|
||||||
|
*/
|
||||||
|
private static int getAudioIndexByHighestRank(@Nullable final MediaFormat targetedFormat,
|
||||||
|
@Nullable final List<AudioStream> audioStreams,
|
||||||
|
final Comparator<AudioStream> comparator) {
|
||||||
|
if (audioStreams == null || audioStreams.isEmpty()) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (result == -1 && format == null) {
|
|
||||||
break;
|
final AudioStream highestRankedAudioStream = audioStreams.stream()
|
||||||
|
.filter(audioStream -> targetedFormat == null
|
||||||
|
|| audioStream.getFormat() == targetedFormat)
|
||||||
|
.max(comparator)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (highestRankedAudioStream == null) {
|
||||||
|
// Fallback: Ignore targetedFormat if not null
|
||||||
|
if (targetedFormat != null) {
|
||||||
|
return getAudioIndexByHighestRank(null, audioStreams, comparator);
|
||||||
}
|
}
|
||||||
format = null;
|
// targetedFormat is already null -> return -1
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return result;
|
return audioStreams.indexOf(highestRankedAudioStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue