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

Commit 26ac00d3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Plumbing to recognize AV1 content"

parents 52e19d49 707c1468
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -655,7 +655,8 @@ static void dumpCodecProfiles(bool queryDecoders) {
        MEDIA_MIMETYPE_AUDIO_G711_ALAW, MEDIA_MIMETYPE_AUDIO_VORBIS,
        MEDIA_MIMETYPE_VIDEO_VP8, MEDIA_MIMETYPE_VIDEO_VP9,
        MEDIA_MIMETYPE_VIDEO_DOLBY_VISION, MEDIA_MIMETYPE_VIDEO_HEVC,
        MEDIA_MIMETYPE_AUDIO_EAC3, MEDIA_MIMETYPE_AUDIO_AC4
        MEDIA_MIMETYPE_AUDIO_EAC3, MEDIA_MIMETYPE_AUDIO_AC4,
        MEDIA_MIMETYPE_VIDEO_AV1
    };

    const char *codecType = queryDecoders? "decoder" : "encoder";
+14 −0
Original line number Diff line number Diff line
cc_library_shared {
    name: "libcodec2_soft_av1dec",
    defaults: [
        "libcodec2_soft-defaults",
        "libcodec2_soft_sanitize_all-defaults",
    ],

    srcs: ["C2SoftAomDec.cpp"],
    static_libs: ["libaom"],

    include_dirs: [
        "external/libaom/",
    ],
}
+750 −0

File added.

Preview size limit exceeded, changes collapsed.

+137 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_C2_SOFT_AV1_DEC_H_
#define ANDROID_C2_SOFT_AV1_DEC_H_

#include <SimpleC2Component.h>
#include "aom/aom_decoder.h"
#include "aom/aomdx.h"

#define GETTIME(a, b) gettimeofday(a, b);
#define TIME_DIFF(start, end, diff)     \
    diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
            ((end).tv_usec - (start).tv_usec);

namespace android {

struct C2SoftAomDec : public SimpleC2Component {
    class IntfImpl;

    C2SoftAomDec(const char* name, c2_node_id_t id,
                 const std::shared_ptr<IntfImpl>& intfImpl);
    virtual ~C2SoftAomDec();

    // From SimpleC2Component
    c2_status_t onInit() override;
    c2_status_t onStop() override;
    void onReset() override;
    void onRelease() override;
    c2_status_t onFlush_sm() override;
    void process(const std::unique_ptr<C2Work>& work,
                 const std::shared_ptr<C2BlockPool>& pool) override;
    c2_status_t drain(uint32_t drainMode,
                      const std::shared_ptr<C2BlockPool>& pool) override;

   private:
    std::shared_ptr<IntfImpl> mIntf;
    aom_codec_ctx_t* mCodecCtx;

    uint32_t mWidth;
    uint32_t mHeight;
    bool mSignalledOutputEos;
    bool mSignalledError;

    #ifdef FILE_DUMP_ENABLE
    char mInFile[200];
    char mOutFile[200];
    #endif /* FILE_DUMP_ENABLE */

    struct timeval mTimeStart;   // Time at the start of decode()
    struct timeval mTimeEnd;     // Time at the end of decode()

    status_t initDecoder();
    status_t destroyDecoder();
    void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
                    const std::shared_ptr<C2GraphicBlock>& block);
    bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
                      const std::unique_ptr<C2Work>& work);

    c2_status_t drainInternal(uint32_t drainMode,
                              const std::shared_ptr<C2BlockPool>& pool,
                              const std::unique_ptr<C2Work>& work);

    C2_DO_NOT_COPY(C2SoftAomDec);
};

#ifdef FILE_DUMP_ENABLE

#define INPUT_DUMP_PATH "/data/local/tmp/temp/av1"
#define INPUT_DUMP_EXT "webm"
#define OUTPUT_DUMP_PATH "/data/local/tmp/temp/av1"
#define OUTPUT_DUMP_EXT "av1"
#define GENERATE_FILE_NAMES()                                                 \
    {                                                                         \
        GETTIME(&mTimeStart, NULL);                                           \
        strcpy(mInFile, "");                                                  \
        ALOGD("GENERATE_FILE_NAMES");                                         \
        sprintf(mInFile, "%s_%ld.%ld.%s", INPUT_DUMP_PATH, mTimeStart.tv_sec, \
                mTimeStart.tv_usec, INPUT_DUMP_EXT);                          \
        strcpy(mOutFile, "");                                                 \
        sprintf(mOutFile, "%s_%ld.%ld.%s", OUTPUT_DUMP_PATH,                  \
                mTimeStart.tv_sec, mTimeStart.tv_usec, OUTPUT_DUMP_EXT);      \
    }

#define CREATE_DUMP_FILE(m_filename)                     \
    {                                                    \
        FILE* fp = fopen(m_filename, "wb");              \
        if (fp != NULL) {                                \
            ALOGD("Opened file %s", m_filename);         \
            fclose(fp);                                  \
        } else {                                         \
            ALOGD("Could not open file %s", m_filename); \
        }                                                \
    }
#define DUMP_TO_FILE(m_filename, m_buf, m_size)              \
    {                                                        \
        FILE* fp = fopen(m_filename, "ab");                  \
        if (fp != NULL && m_buf != NULL) {                   \
            int i;                                           \
            ALOGD("Dump to file!");                          \
            i = fwrite(m_buf, 1, m_size, fp);                \
            if (i != (int)m_size) {                          \
                ALOGD("Error in fwrite, returned %d", i);    \
                perror("Error in write to file");            \
            }                                                \
            fclose(fp);                                      \
        } else {                                             \
            ALOGD("Could not write to file %s", m_filename); \
            if (fp != NULL) fclose(fp);                      \
        }                                                    \
    }
#else /* FILE_DUMP_ENABLE */
#define INPUT_DUMP_PATH
#define INPUT_DUMP_EXT
#define OUTPUT_DUMP_PATH
#define OUTPUT_DUMP_EXT
#define GENERATE_FILE_NAMES()
#define CREATE_DUMP_FILE(m_filename)
#define DUMP_TO_FILE(m_filename, m_buf, m_size)
#endif /* FILE_DUMP_ENABLE */

}  // namespace android

#endif  // ANDROID_C2_SOFT_AV1_DEC_H_
+31 −0
Original line number Diff line number Diff line
@@ -392,6 +392,7 @@ enum : uint32_t {
    _C2_PL_HEVC_BASE = 0x6000,
    _C2_PL_VP9_BASE  = 0x7000,
    _C2_PL_DV_BASE   = 0x8000,
    _C2_PL_AV1_BASE  = 0x9000,

    C2_PROFILE_LEVEL_VENDOR_START = 0x70000000,
};
@@ -539,6 +540,11 @@ enum C2Config::profile_t : uint32_t {
    PROFILE_DV_HE_07 = _C2_PL_DV_BASE + 7,      ///< Dolby Vision dvhe.07 profile
    PROFILE_DV_HE_08 = _C2_PL_DV_BASE + 8,      ///< Dolby Vision dvhe.08 profile
    PROFILE_DV_AV_09 = _C2_PL_DV_BASE + 9,      ///< Dolby Vision dvav.09 profile

    // AV1 profiles
    PROFILE_AV1_0 = _C2_PL_AV1_BASE,            ///< AV1 Profile 0 (4:2:0, 8 to 10 bit)
    PROFILE_AV1_1,                              ///< AV1 Profile 1 (8 to 10 bit)
    PROFILE_AV1_2,                              ///< AV1 Profile 2 (8 to 12 bit)
};

enum C2Config::level_t : uint32_t {
@@ -652,6 +658,31 @@ enum C2Config::level_t : uint32_t {
    LEVEL_DV_HIGH_UHD_30,                       ///< Dolby Vision high tier uhd30
    LEVEL_DV_HIGH_UHD_48,                       ///< Dolby Vision high tier uhd48
    LEVEL_DV_HIGH_UHD_60,                       ///< Dolby Vision high tier uhd60

    LEVEL_AV1_2    = _C2_PL_AV1_BASE ,          ///< AV1 Level 2
    LEVEL_AV1_2_1,                              ///< AV1 Level 2.1
    LEVEL_AV1_2_2,                              ///< AV1 Level 2.2
    LEVEL_AV1_2_3,                              ///< AV1 Level 2.3
    LEVEL_AV1_3,                                ///< AV1 Level 3
    LEVEL_AV1_3_1,                              ///< AV1 Level 3.1
    LEVEL_AV1_3_2,                              ///< AV1 Level 3.2
    LEVEL_AV1_3_3,                              ///< AV1 Level 3.3
    LEVEL_AV1_4,                                ///< AV1 Level 4
    LEVEL_AV1_4_1,                              ///< AV1 Level 4.1
    LEVEL_AV1_4_2,                              ///< AV1 Level 4.2
    LEVEL_AV1_4_3,                              ///< AV1 Level 4.3
    LEVEL_AV1_5,                                ///< AV1 Level 5
    LEVEL_AV1_5_1,                              ///< AV1 Level 5.1
    LEVEL_AV1_5_2,                              ///< AV1 Level 5.2
    LEVEL_AV1_5_3,                              ///< AV1 Level 5.3
    LEVEL_AV1_6,                                ///< AV1 Level 6
    LEVEL_AV1_6_1,                              ///< AV1 Level 6.1
    LEVEL_AV1_6_2,                              ///< AV1 Level 6.2
    LEVEL_AV1_6_3,                              ///< AV1 Level 6.3
    LEVEL_AV1_7,                                ///< AV1 Level 7
    LEVEL_AV1_7_1,                              ///< AV1 Level 7.1
    LEVEL_AV1_7_2,                              ///< AV1 Level 7.2
    LEVEL_AV1_7_3,                              ///< AV1 Level 7.3
};

struct C2ProfileLevelStruct {
Loading