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

Commit bfd41f33 authored by Andreas Huber's avatar Andreas Huber
Browse files

Refactor h.264 profile/level support into avc_utils.

Change-Id: Idb33636dc723aa79ea0122dc3582109ada4b1358
related-to-bug: 2368598
parent 2d71233d
Loading
Loading
Loading
Loading
+1 −33
Original line number Original line Diff line number Diff line
@@ -54,6 +54,7 @@
#include <OMX_Component.h>
#include <OMX_Component.h>


#include "include/ThreadedSource.h"
#include "include/ThreadedSource.h"
#include "include/avc_utils.h"


namespace android {
namespace android {


@@ -264,39 +265,6 @@ static const char *GetCodec(const CodecInfo *info, size_t numInfos,
    return NULL;
    return NULL;
}
}


enum {
    kAVCProfileBaseline      = 0x42,
    kAVCProfileMain          = 0x4d,
    kAVCProfileExtended      = 0x58,
    kAVCProfileHigh          = 0x64,
    kAVCProfileHigh10        = 0x6e,
    kAVCProfileHigh422       = 0x7a,
    kAVCProfileHigh444       = 0xf4,
    kAVCProfileCAVLC444Intra = 0x2c
};

static const char *AVCProfileToString(uint8_t profile) {
    switch (profile) {
        case kAVCProfileBaseline:
            return "Baseline";
        case kAVCProfileMain:
            return "Main";
        case kAVCProfileExtended:
            return "Extended";
        case kAVCProfileHigh:
            return "High";
        case kAVCProfileHigh10:
            return "High 10";
        case kAVCProfileHigh422:
            return "High 422";
        case kAVCProfileHigh444:
            return "High 444";
        case kAVCProfileCAVLC444Intra:
            return "CAVLC 444 Intra";
        default:   return "Unknown";
    }
}

template<class T>
template<class T>
static void InitOMXParams(T *params) {
static void InitOMXParams(T *params) {
    params->nSize = sizeof(T);
    params->nSize = sizeof(T);
+28 −1
Original line number Original line Diff line number Diff line
@@ -218,6 +218,28 @@ static sp<ABuffer> FindNAL(
    return NULL;
    return NULL;
}
}


const char *AVCProfileToString(uint8_t profile) {
    switch (profile) {
        case kAVCProfileBaseline:
            return "Baseline";
        case kAVCProfileMain:
            return "Main";
        case kAVCProfileExtended:
            return "Extended";
        case kAVCProfileHigh:
            return "High";
        case kAVCProfileHigh10:
            return "High 10";
        case kAVCProfileHigh422:
            return "High 422";
        case kAVCProfileHigh444:
            return "High 444";
        case kAVCProfileCAVLC444Intra:
            return "CAVLC 444 Intra";
        default:   return "Unknown";
    }
}

sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {
sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {
    const uint8_t *data = accessUnit->data();
    const uint8_t *data = accessUnit->data();
    size_t size = accessUnit->size();
    size_t size = accessUnit->size();
@@ -244,6 +266,10 @@ sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {


    *out++ = 0x01;  // configurationVersion
    *out++ = 0x01;  // configurationVersion
    memcpy(out, seqParamSet->data() + 1, 3);  // profile/level...
    memcpy(out, seqParamSet->data() + 1, 3);  // profile/level...

    uint8_t profile = out[0];
    uint8_t level = out[2];

    out += 3;
    out += 3;
    *out++ = (0x3f << 2) | 1;  // lengthSize == 2 bytes
    *out++ = (0x3f << 2) | 1;  // lengthSize == 2 bytes
    *out++ = 0xe0 | 1;
    *out++ = 0xe0 | 1;
@@ -271,7 +297,8 @@ sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {
    meta->setInt32(kKeyWidth, width);
    meta->setInt32(kKeyWidth, width);
    meta->setInt32(kKeyHeight, height);
    meta->setInt32(kKeyHeight, height);


    LOGI("found AVC codec config (%d x %d)", width, height);
    LOGI("found AVC codec config (%d x %d, %s-profile level %d.%d)",
         width, height, AVCProfileToString(profile), level / 10, level % 10);


    return meta;
    return meta;
}
}
+13 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,17 @@ namespace android {


struct ABitReader;
struct ABitReader;


enum {
    kAVCProfileBaseline      = 0x42,
    kAVCProfileMain          = 0x4d,
    kAVCProfileExtended      = 0x58,
    kAVCProfileHigh          = 0x64,
    kAVCProfileHigh10        = 0x6e,
    kAVCProfileHigh422       = 0x7a,
    kAVCProfileHigh444       = 0xf4,
    kAVCProfileCAVLC444Intra = 0x2c
};

void FindAVCDimensions(
void FindAVCDimensions(
        const sp<ABuffer> &seqParamSet, int32_t *width, int32_t *height);
        const sp<ABuffer> &seqParamSet, int32_t *width, int32_t *height);


@@ -39,6 +50,8 @@ sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit);


bool IsIDR(const sp<ABuffer> &accessUnit);
bool IsIDR(const sp<ABuffer> &accessUnit);


const char *AVCProfileToString(uint8_t profile);

}  // namespace android
}  // namespace android


#endif  // AVC_UTILS_H_
#endif  // AVC_UTILS_H_