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

Commit a1644109 authored by Andreas Huber's avatar Andreas Huber Committed by Android Git Automerger
Browse files

am 96dc4559: am b8814dce: Merge "Allow sniffers to return a packet of opaque...

am 96dc4559: am b8814dce: Merge "Allow sniffers to return a packet of opaque data that the corresponding extractor can take advantage of to not duplicate work already done sniffing. The mp3 extractor takes advantage of this now." into gingerbread

Merge commit '96dc4559'

* commit '96dc4559':
  Allow sniffers to return a packet of opaque data that the corresponding extractor can take advantage of to not duplicate work already done sniffing. The mp3 extractor takes advantage of this now.
parents cb3be1b4 96dc4559
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

namespace android {

struct AMessage;
class String8;

class DataSource : public RefBase {
@@ -59,10 +60,14 @@ public:

    ////////////////////////////////////////////////////////////////////////////

    bool sniff(String8 *mimeType, float *confidence);
    bool sniff(String8 *mimeType, float *confidence, sp<AMessage> *meta);

    // The sniffer can optionally fill in "meta" with an AMessage containing
    // a dictionary of values that helps the corresponding extractor initialize
    // its state without duplicating effort already exerted by the sniffer.
    typedef bool (*SnifferFunc)(
            const sp<DataSource> &source, String8 *mimeType, float *confidence);
            const sp<DataSource> &source, String8 *mimeType,
            float *confidence, sp<AMessage> *meta);

    static void RegisterSniffer(SnifferFunc func);
    static void RegisterDefaultSniffers();
+3 −2
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ AMRExtractor::AMRExtractor(const sp<DataSource> &source)
      mInitCheck(NO_INIT) {
    String8 mimeType;
    float confidence;
    if (!SniffAMR(mDataSource, &mimeType, &confidence)) {
    if (!SniffAMR(mDataSource, &mimeType, &confidence, NULL)) {
        return;
    }

@@ -276,7 +276,8 @@ status_t AMRSource::read(
////////////////////////////////////////////////////////////////////////////////

bool SniffAMR(
        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
        const sp<DataSource> &source, String8 *mimeType, float *confidence,
        sp<AMessage> *) {
    char header[9];

    if (source->readAt(0, header, sizeof(header)) != sizeof(header)) {
+11 −6
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include "matroska/MatroskaExtractor.h"

#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/FileSource.h>
#include <media/stagefright/MediaErrors.h>
@@ -56,19 +57,23 @@ status_t DataSource::getSize(off_t *size) {
Mutex DataSource::gSnifferMutex;
List<DataSource::SnifferFunc> DataSource::gSniffers;

bool DataSource::sniff(String8 *mimeType, float *confidence) {
bool DataSource::sniff(
        String8 *mimeType, float *confidence, sp<AMessage> *meta) {
    *mimeType = "";
    *confidence = 0.0f;
    meta->clear();

    Mutex::Autolock autoLock(gSnifferMutex);
    for (List<SnifferFunc>::iterator it = gSniffers.begin();
         it != gSniffers.end(); ++it) {
        String8 newMimeType;
        float newConfidence;
        if ((*it)(this, &newMimeType, &newConfidence)) {
        sp<AMessage> newMeta;
        if ((*it)(this, &newMimeType, &newConfidence, &newMeta)) {
            if (newConfidence > *confidence) {
                *mimeType = newMimeType;
                *confidence = newConfidence;
                *meta = newMeta;
            }
        }
    }
@@ -92,13 +97,13 @@ void DataSource::RegisterSniffer(SnifferFunc func) {

// static
void DataSource::RegisterDefaultSniffers() {
    RegisterSniffer(SniffMP3);
    RegisterSniffer(SniffMPEG4);
    RegisterSniffer(SniffAMR);
    RegisterSniffer(SniffWAV);
    RegisterSniffer(SniffOgg);
    RegisterSniffer(SniffMatroska);
    RegisterSniffer(SniffOgg);
    RegisterSniffer(SniffWAV);
    RegisterSniffer(SniffAMR);
    RegisterSniffer(SniffMPEG2TS);
    RegisterSniffer(SniffMP3);
}

// static
+27 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

#include "include/ID3.h"

#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaBufferGroup.h>
@@ -456,15 +457,31 @@ private:
    MP3Source &operator=(const MP3Source &);
};

MP3Extractor::MP3Extractor(const sp<DataSource> &source)
MP3Extractor::MP3Extractor(
        const sp<DataSource> &source, const sp<AMessage> &meta)
    : mDataSource(source),
      mFirstFramePos(-1),
      mFixedHeader(0),
      mByteNumber(0) {
    off_t pos = 0;
    uint32_t header;
    bool success = Resync(mDataSource, 0, &pos, &header);
    bool success;

    int64_t meta_offset;
    uint32_t meta_header;
    if (meta != NULL
            && meta->findInt64("offset", &meta_offset)
            && meta->findInt32("header", (int32_t *)&meta_header)) {
        // The sniffer has already done all the hard work for us, simply
        // accept its judgement.
        pos = (off_t)meta_offset;
        header = meta_header;

        success = true;
    } else {
        success = Resync(mDataSource, 0, &pos, &header);
        CHECK(success);
    }

    if (success) {
        mFirstFramePos = pos;
@@ -759,15 +776,20 @@ sp<MetaData> MP3Extractor::getMetaData() {
}

bool SniffMP3(
        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
        const sp<DataSource> &source, String8 *mimeType,
        float *confidence, sp<AMessage> *meta) {
    off_t pos = 0;
    uint32_t header;
    if (!Resync(source, 0, &pos, &header)) {
        return false;
    }

    *meta = new AMessage;
    (*meta)->setInt64("offset", pos);
    (*meta)->setInt32("header", header);

    *mimeType = MEDIA_MIMETYPE_AUDIO_MPEG;
    *confidence = 0.3f;
    *confidence = 0.2f;

    return true;
}
+4 −3
Original line number Diff line number Diff line
@@ -1738,7 +1738,7 @@ static bool LegacySniffMPEG4(
        || !memcmp(header, "ftypM4A ", 8) || !memcmp(header, "ftypf4v ", 8)
        || !memcmp(header, "ftypkddi", 8) || !memcmp(header, "ftypM4VP", 8)) {
        *mimeType = MEDIA_MIMETYPE_CONTAINER_MPEG4;
        *confidence = 0.1;
        *confidence = 0.4;

        return true;
    }
@@ -1805,13 +1805,14 @@ static bool BetterSniffMPEG4(
    }

    *mimeType = MEDIA_MIMETYPE_CONTAINER_MPEG4;
    *confidence = 0.3f;
    *confidence = 0.4f;

    return true;
}

bool SniffMPEG4(
        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
        const sp<DataSource> &source, String8 *mimeType, float *confidence,
        sp<AMessage> *) {
    if (BetterSniffMPEG4(source, mimeType, confidence)) {
        return true;
    }
Loading