Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c09c123d authored by Robert Shih's avatar Robert Shih Committed by Android (Google) Code Review
Browse files

Merge "Return sources from the same program if possible"

parents ce33ac39 9ff1e728
Loading
Loading
Loading
Loading
+26 −14
Original line number Diff line number Diff line
@@ -524,16 +524,11 @@ int64_t ATSParser::Program::recoverPTS(uint64_t PTS_33bit) {
}

sp<MediaSource> ATSParser::Program::getSource(SourceType type) {
    size_t index = (type == AUDIO) ? 0 : 0;

    for (size_t i = 0; i < mStreams.size(); ++i) {
        sp<MediaSource> source = mStreams.editValueAt(i)->getSource(type);
        if (source != NULL) {
            if (index == 0) {
            return source;
        }
            --index;
        }
    }

    return NULL;
@@ -546,6 +541,8 @@ bool ATSParser::Program::hasSource(SourceType type) const {
            return true;
        } else if (type == VIDEO && stream->isVideo()) {
            return true;
        } else if (type == META && stream->isMeta()) {
            return true;
        }
    }

@@ -1499,23 +1496,38 @@ status_t ATSParser::parseTS(ABitReader *br, SyncEvent *event) {
}

sp<MediaSource> ATSParser::getSource(SourceType type) {
    int which = -1;  // any

    sp<MediaSource> firstSourceFound;
    for (size_t i = 0; i < mPrograms.size(); ++i) {
        const sp<Program> &program = mPrograms.editItemAt(i);

        if (which >= 0 && (int)program->number() != which) {
        sp<MediaSource> source = program->getSource(type);
        if (source == NULL) {
            continue;
        }
        if (firstSourceFound == NULL) {
            firstSourceFound = source;
        }
        // Prefer programs with both audio/video
        switch (type) {
            case VIDEO: {
                if (program->hasSource(AUDIO)) {
                    return source;
                }
                break;
            }

        sp<MediaSource> source = program->getSource(type);
            case AUDIO: {
                if (program->hasSource(VIDEO)) {
                    return source;
                }
                break;
            }

        if (source != NULL) {
            default:
                return source;
        }
    }

    return NULL;
    return firstSourceFound;
}

bool ATSParser::hasSource(SourceType type) const {