Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio track selection depends on initial tracks order #1868

Open
1 task
TheBeastLT opened this issue Nov 8, 2024 · 1 comment
Open
1 task

Audio track selection depends on initial tracks order #1868

TheBeastLT opened this issue Nov 8, 2024 · 1 comment
Assignees

Comments

@TheBeastLT
Copy link

TheBeastLT commented Nov 8, 2024

Version

Media3 main branch

More version details

No response

Devices that reproduce the issue

Any mobile device

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

When audio tracks are selected on some conditions the selected track will be different depending on how these tracks are ordered in the original video container, due to this block:

Ordering<Integer> qualityOrdering =
isWithinConstraints && isWithinRendererCapabilities
? FORMAT_VALUE_ORDERING
: FORMAT_VALUE_ORDERING.reverse();

Let's say we have 2 audio tracks one with 2ch and other with 6ch, on mobile devices due to spatializer logic these would be parsed to AudioTrackInfo { channelCount: 2, isWithinConstraints: true }, AudioTrackInfo { channelCount: 6, isWithinConstraints: false } (all other parameters would be the same). With such an order the 2nd track would be picked up, but if audio tracks in the container would be switched then it would pick the 1st audio track with 2ch.

Not sure if such a behaviour was intended, but in general sorting comparators should produce the same end results regardless of the initial order.

Expected result

Selected audio track is the same regardless of the initial order.

Actual result

Selected audio track depends on the initial track order.

Media

Bug Report

  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.
@tianyif
Copy link
Contributor

tianyif commented Nov 12, 2024

Hi @TheBeastLT,

Do you have the real sample media to reproduce? I quickly tried a unit test, and this can pass no matter the order I defined with TrackGroupArray trackGroups = wrapFormats(beyondConstraintFormat, withinConstraintFormat) (I also tried the swapped order).

public void selectTracksPreferTrackWithinConstraint() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format beyondConstraintFormat =
        formatBuilder.setId("beyondConstraintFormat").setChannelCount(6).build();
    Format withinConstraintFormat = formatBuilder.setId("withConstraintFormat").setChannelCount(2).build();
    TrackGroupArray trackGroups = wrapFormats(beyondConstraintFormat, withinConstraintFormat);

    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(withinConstraintFormat.id, FORMAT_HANDLED);
    mappedCapabilities.put(beyondConstraintFormat.id, FORMAT_HANDLED);
    RendererCapabilities mappedAudioRendererCapabilities =
        new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);

    trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(2).build());
    TrackSelectorResult result =
        trackSelector.selectTracks(
            new RendererCapabilities[] {mappedAudioRendererCapabilities},
            trackGroups,
            periodId,
            TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, withinConstraintFormat);
}

In fact, given that these two tracks are true and false in the field isWithinConstraints, the comparison chain will already have a decision on the comparison at this line:

.compareFalseFirst(this.isWithinConstraints, other.isWithinConstraints)

unless there are any preferences set via the track selection Parameter or media or the system, which can lead to a decision even earlier than isWithinConstraints.

Please feel free to send us the sample media to reproduce the real case of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants