Skip to content

Audio decoder issue fix for android. #4398

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rahulnainwal107
Copy link

@rahulnainwal107 rahulnainwal107 commented Jan 29, 2025

Summary

I was facing an issue related to the audio decoder when the lang attribute was missing in manifest file for AdaptationSet tag and having multiple AdaptationSet, where 0th position audio is not supported by the device but 1st position audio is supported.

Changes

1- Default groupIndex updated.

int groupIndex = C.INDEX_UNSET; // default if no match

2- Added a helper function for checking supported audio codes.

public boolean isCodecSupported(String format) {
        List<String> codecList = new ArrayList<>();
        int codecCount = MediaCodecList.getCodecCount();
        for (int i = 0; i < codecCount; i++) {
            android.media.MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
            for (String type : codecInfo.getSupportedTypes()) {
                codecList.add(type);
            }
        }
        if (codecList.size() > 0) {
            return codecList.contains(format);
        }
        return false;
    }

3- If audio is supported only then updating groupIndex.

private int getGroupIndexForDefaultLocale(TrackGroupArray groups) {
        if (groups.length == 0){
            return C.INDEX_UNSET;
        }

        int groupIndex = C.INDEX_UNSET; // default if no match
        String locale2 = Locale.getDefault().getLanguage(); // 2 letter code
        String locale3 = Locale.getDefault().getISO3Language(); // 3 letter code
        for (int i = 0; i < groups.length; ++i) {
            Format format = groups.get(i).getFormat(0);
            String language = format.language;
            Boolean isSupported = isCodecSupported(format.sampleMimeType);
            if (isSupported) {
                if (language != null && (language.equals(locale2) || language.equals(locale3))) {
                    groupIndex = i;
                    break;
                } else {
                    groupIndex = i;
                }
            }
        }
        return groupIndex;
    }

@freeboub
Copy link
Collaborator

First thank you for the PR!
I don't think this will be OK, the function getGroupIndexForDefaultLocale is used for both audio and text tracks. Checking codec for text track doesn't make sense ...
But I am not sure on how to handle it (maybe just add track type to getGroupIndexForDefaultLocale and check it only for audio)

@rahulnainwal107
Copy link
Author

@freeboub Thanks for reviewing it.
I will update it to check the codec only for audio.

@freeboub
Copy link
Collaborator

@freeboub Thanks for reviewing it. I will update it to check the codec only for audio.

No problem, I think you should also rename the function to isCodecAudioSupported then !

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

Successfully merging this pull request may close these issues.

3 participants