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

Commit f51cb695 authored by Marco Nelissen's avatar Marco Nelissen Committed by Android (Google) Code Review
Browse files

Merge changes I8f585cfb,I77fcb609

* changes:
  Make some methods static
  Consolidate two MakeAACCodecSpecificData functions
parents a94cb66c cd5efc0e
Loading
Loading
Loading
Loading
+42 −6
Original line number Diff line number Diff line
@@ -49,20 +49,56 @@ sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {
sp<MetaData> MakeAACCodecSpecificData(
        unsigned profile, unsigned sampling_freq_index,
        unsigned channel_configuration) {
    int32_t sampleRate;
    int32_t channelCount;
    sp<ABuffer> csd = MakeAACCodecSpecificData(profile, sampling_freq_index,
            channel_configuration, &sampleRate, &channelCount);
    if (csd == nullptr) {
    if(sampling_freq_index > 11u) {
        return nullptr;
    }
    int32_t sampleRate;
    int32_t channelCount;
    static const int32_t kSamplingFreq[] = {
        96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
        16000, 12000, 11025, 8000
    };
    sampleRate = kSamplingFreq[sampling_freq_index];
    channelCount = channel_configuration;

    static const uint8_t kStaticESDS[] = {
        0x03, 22,
        0x00, 0x00,     // ES_ID
        0x00,           // streamDependenceFlag, URL_Flag, OCRstreamFlag

        0x04, 17,
        0x40,                       // Audio ISO/IEC 14496-3
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,

        0x05, 2,
        // AudioSpecificInfo follows

        // oooo offf fccc c000
        // o - audioObjectType
        // f - samplingFreqIndex
        // c - channelConfig
    };

    size_t csdSize = sizeof(kStaticESDS) + 2;
    uint8_t *csd = new uint8_t[csdSize];
    memcpy(csd, kStaticESDS, sizeof(kStaticESDS));

    csd[sizeof(kStaticESDS)] =
        ((profile + 1) << 3) | (sampling_freq_index >> 1);

    csd[sizeof(kStaticESDS) + 1] =
        ((sampling_freq_index << 7) & 0x80) | (channel_configuration << 3);

    sp<MetaData> meta = new MetaData;
    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC);

    meta->setInt32(kKeySampleRate, sampleRate);
    meta->setInt32(kKeyChannelCount, channelCount);

    meta->setData(kKeyESDS, 0, csd->data(), csd->size());
    meta->setData(kKeyESDS, 0, csd, csdSize);
    delete [] csd;
    return meta;
}

+0 −43
Original line number Diff line number Diff line
@@ -537,49 +537,6 @@ uint32_t FindAVCLayerId(const uint8_t *data, size_t size) {
    return layerId;
}

sp<ABuffer> MakeAACCodecSpecificData(
        unsigned profile, unsigned sampling_freq_index,
        unsigned channel_configuration, int32_t *sampleRate,
        int32_t *channelCount) {
    CHECK_LE(sampling_freq_index, 11u);
    static const int32_t kSamplingFreq[] = {
        96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
        16000, 12000, 11025, 8000
    };
    *sampleRate = kSamplingFreq[sampling_freq_index];
    *channelCount = channel_configuration;

    static const uint8_t kStaticESDS[] = {
        0x03, 22,
        0x00, 0x00,     // ES_ID
        0x00,           // streamDependenceFlag, URL_Flag, OCRstreamFlag

        0x04, 17,
        0x40,                       // Audio ISO/IEC 14496-3
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,

        0x05, 2,
        // AudioSpecificInfo follows

        // oooo offf fccc c000
        // o - audioObjectType
        // f - samplingFreqIndex
        // c - channelConfig
    };
    sp<ABuffer> csd = new ABuffer(sizeof(kStaticESDS) + 2);
    memcpy(csd->data(), kStaticESDS, sizeof(kStaticESDS));

    csd->data()[sizeof(kStaticESDS)] =
        ((profile + 1) << 3) | (sampling_freq_index >> 1);

    csd->data()[sizeof(kStaticESDS) + 1] =
        ((sampling_freq_index << 7) & 0x80) | (channel_configuration << 3);

    return csd;
}

bool ExtractDimensionsFromVOLHeader(
        const uint8_t *data, size_t size, int32_t *width, int32_t *height) {
    ABitReader br(&data[4], size - 4);
+0 −5
Original line number Diff line number Diff line
@@ -90,11 +90,6 @@ uint32_t FindAVCLayerId(const uint8_t *data, size_t size);

const char *AVCProfileToString(uint8_t profile);

sp<ABuffer> MakeAACCodecSpecificData(
        unsigned profile, unsigned sampling_freq_index,
        unsigned channel_configuration, int32_t *sampleRate,
        int32_t *channelCount);

// Given an MPEG4 video VOL-header chunk (starting with 0x00 0x00 0x01 0x2?)
// parse it and fill in dimensions, returns true iff successful.
bool ExtractDimensionsFromVOLHeader(
+2 −2
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ static sp<ABuffer> MakeAVCCodecSpecificData(
    return csd;
}

sp<ABuffer> MakeAACCodecSpecificData(const char *params) {
static sp<ABuffer> MakeAACCodecSpecificData(const char *params) {
    AString val;
    CHECK(GetAttribute(params, "config", &val));

@@ -257,7 +257,7 @@ sp<ABuffer> MakeAACCodecSpecificData(const char *params) {
}

// From mpeg4-generic configuration data.
sp<ABuffer> MakeAACCodecSpecificData2(const char *params) {
static sp<ABuffer> MakeAACCodecSpecificData2(const char *params) {
    AString val;
    unsigned long objectType;
    if (GetAttribute(params, "objectType", &val)) {