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

Commit 309ee9d2 authored by Ray Essick's avatar Ray Essick
Browse files

Faster sniffing for MIDIExtractor

For sniffing, use the 'magic number' header bits in the front of the file.

Bug: 181040054
Test: atest CtsMediaPlayerTestCases
Test: atest CtsMediaAudioTestCases
Change-Id: I05f778a9aca5e7c6c9389e08fd88a95a10268915
parent f521e485
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -327,12 +327,29 @@ media_status_t MidiExtractor::getMetaData(AMediaFormat *meta)

bool SniffMidi(CDataSource *source, float *confidence)
{
    MidiEngine p(source, NULL, NULL);
    if (p.initCheck() == OK) {
        *confidence = 0.8;
        ALOGV("SniffMidi: yes");
    // look for standard prefix / magic number info in the files.
    // "MThd" for midi
    // "XMF_"
    // this will be very fast.
    //
    char hdr_magic[4];
    if (source->readAt(source->handle, 0, hdr_magic, sizeof(hdr_magic)) == sizeof(hdr_magic)) {
        if (memcmp(hdr_magic,"MThd", sizeof(hdr_magic)) == 0) {
            *confidence = 0.85;
            ALOGV("SniffMidi: yes, MThd");
            return true;
        }
        if (memcmp(hdr_magic,"XMF_", sizeof(hdr_magic)) == 0) {
            *confidence = 0.85;
            ALOGV("SniffMidi: yes, XMF_");
            return true;
        }
    }

    // alternatives:
    // instantiate MidiEngine, (expensively) parsing the entire file to decide.


    ALOGV("SniffMidi: no");
    return false;