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

Commit 1c7bf573 authored by Fyodor Kyslov's avatar Fyodor Kyslov Committed by Android (Google) Code Review
Browse files

Merge changes from topic "AV1Enc"

* changes:
  AV1 Encoder. Fixing idents
  Add AV1 Encoder to the registry and XMLs
  Implement AV1 Encoder via Codec2 interface
parents 734fd6a9 a056c626
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -23,3 +23,23 @@ cc_library {
    srcs: ["C2SoftAomDec.cpp"],
    static_libs: ["libaom"],
}

cc_library {
    name: "libcodec2_soft_av1enc",
    defaults: [
        "libcodec2_soft-defaults",
        "libcodec2_soft_sanitize_all-defaults",
    ],

    static_libs: ["libaom"],

    srcs: ["C2SoftAomEnc.cpp"],

    export_include_dirs: ["."],

    apex_available: [
        "//apex_available:platform",
        "com.android.media.swcodec",
    ],

}
+866 −0

File added.

Preview size limit exceeded, changes collapsed.

+156 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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_ENC_H_
#define ANDROID_C2_SOFT_AV1_ENC_H_

#include <inttypes.h>

#include <C2PlatformSupport.h>
#include <Codec2BufferUtils.h>
#include <SimpleC2Component.h>
#include <SimpleC2Interface.h>
#include <util/C2InterfaceHelper.h>

#include "aom/aom_encoder.h"
#include "aom/aomcx.h"
#include "common/av1_config.h"

namespace android {
struct C2SoftAomEnc : public SimpleC2Component {
    class IntfImpl;

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

    // From SimpleC2Component
    c2_status_t onInit() override final;
    c2_status_t onStop() override final;
    void onReset() override final;
    void onRelease() override final;
    c2_status_t onFlush_sm() override final;

    void process(const std::unique_ptr<C2Work>& work,
                 const std::shared_ptr<C2BlockPool>& pool) override final;
    c2_status_t drain(uint32_t drainMode, const std::shared_ptr<C2BlockPool>& pool) override final;

  protected:
    virtual ~C2SoftAomEnc();

  private:
    std::shared_ptr<IntfImpl> mIntf;

    // Initializes aom encoder with available settings.
    status_t initEncoder();

    // aom specific opaque data structure that
    // stores encoder state
    aom_codec_ctx_t* mCodecContext;

    // aom specific data structure that
    // stores encoder configuration
    aom_codec_enc_cfg_t* mCodecConfiguration;

    // aom specific read-only data structure
    // that specifies algorithm interface
    aom_codec_iface_t* mCodecInterface;

    // align stride to the power of 2
    int32_t mStrideAlign;

    aom_rc_mode mBitrateControlMode;

    // Minimum (best quality) quantizer
    uint32_t mMinQuantizer;

    // Maximum (worst quality) quantizer
    uint32_t mMaxQuantizer;

    // Last input buffer timestamp
    uint64_t mLastTimestamp;

    // Number of input frames
    int64_t mNumInputFrames;

    // Conversion buffer is needed to input to
    // yuv420 planar format.
    MemoryBlock mConversionBuffer;

    // Signalled End Of Stream
    bool mSignalledOutputEos;

    // Signalled Error
    bool mSignalledError;

    bool mHeadersReceived;

    std::shared_ptr<C2StreamPictureSizeInfo::input> mSize;
    std::shared_ptr<C2StreamIntraRefreshTuning::output> mIntraRefresh;
    std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamBitrateModeTuning::output> mBitrateMode;
    std::shared_ptr<C2StreamRequestSyncFrameTuning::output> mRequestSync;

    aom_codec_err_t setupCodecParameters();
};

class C2SoftAomEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
  public:
    explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper>& helper);

    static C2R BitrateSetter(bool mayBlock, C2P<C2StreamBitrateInfo::output>& me);

    static C2R SizeSetter(bool mayBlock, const C2P<C2StreamPictureSizeInfo::input>& oldMe,
                          C2P<C2StreamPictureSizeInfo::input>& me);

    static C2R ProfileLevelSetter(bool mayBlock, C2P<C2StreamProfileLevelInfo::output>& me);

    // unsafe getters
    std::shared_ptr<C2StreamPictureSizeInfo::input> getSize_l() const { return mSize; }
    std::shared_ptr<C2StreamIntraRefreshTuning::output> getIntraRefresh_l() const {
        return mIntraRefresh;
    }
    std::shared_ptr<C2StreamFrameRateInfo::output> getFrameRate_l() const { return mFrameRate; }
    std::shared_ptr<C2StreamBitrateInfo::output> getBitrate_l() const { return mBitrate; }
    std::shared_ptr<C2StreamBitrateModeTuning::output> getBitrateMode_l() const {
        return mBitrateMode;
    }
    std::shared_ptr<C2StreamRequestSyncFrameTuning::output> getRequestSync_l() const {
        return mRequestSync;
    }
    std::shared_ptr<C2StreamColorAspectsInfo::output> getCodedColorAspects_l() const {
        return mCodedColorAspects;
    }
    uint32_t getSyncFramePeriod() const;
    static C2R ColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::input>& me);
    static C2R CodedColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::output>& me,
                                       const C2P<C2StreamColorAspectsInfo::input>& coded);

  private:
    std::shared_ptr<C2StreamUsageTuning::input> mUsage;
    std::shared_ptr<C2StreamPictureSizeInfo::input> mSize;
    std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate;
    std::shared_ptr<C2StreamIntraRefreshTuning::output> mIntraRefresh;
    std::shared_ptr<C2StreamRequestSyncFrameTuning::output> mRequestSync;
    std::shared_ptr<C2StreamSyncFrameIntervalTuning::output> mSyncFramePeriod;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamBitrateModeTuning::output> mBitrateMode;
    std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel;
    std::shared_ptr<C2StreamColorAspectsInfo::input> mColorAspects;
    std::shared_ptr<C2StreamColorAspectsInfo::output> mCodedColorAspects;
};

}  // namespace android
#endif  // ANDROID_C2_SOFT_AV1_ENC_H_
+1 −0
Original line number Diff line number Diff line
@@ -1081,6 +1081,7 @@ C2PlatformComponentStore::C2PlatformComponentStore()
    emplace("libcodec2_soft_amrwbenc.so");
    //emplace("libcodec2_soft_av1dec_aom.so"); // deprecated for the gav1 implementation
    emplace("libcodec2_soft_av1dec_gav1.so");
    emplace("libcodec2_soft_av1enc.so");
    emplace("libcodec2_soft_avcdec.so");
    emplace("libcodec2_soft_avcenc.so");
    emplace("libcodec2_soft_flacdec.so");
+8 −0
Original line number Diff line number Diff line
@@ -118,5 +118,13 @@
            <Limit name="bitrate" range="1-40000000" />
            <Feature name="bitrate-modes" value="VBR,CBR" />
        </MediaCodec>
        <MediaCodec name="c2.android.av1.encoder" type="video/av01">
            <Limit name="size" min="2x2" max="2048x2048" />
            <Limit name="alignment" value="2x2" />
            <Limit name="block-size" value="16x16" />
            <Limit name="block-count" range="1-3600" />
            <Limit name="bitrate" range="1-40000000" />
            <Feature name="bitrate-modes" value="VBR,CBR" />
        </MediaCodec>
    </Encoders>
</Included>
Loading