// File: /workspace/github_c_makefile_star2_O0/xiane[P]libvphevcodec/AML_HEVCEncoder.cpp
// Function: AML_HEVCInitialize(AMVHEVCEncHandle_s*, HEVCEncParams_s*, bool*, int)
AMVEnc_Status AML_HEVCInitialize(AMVHEVCEncHandle *Handle, AMVHEVCEncParams *encParam, bool* has_mix, int force_mode) {
    AMVEnc_Status ret;
    (void)has_mix;
    (void)force_mode;
    Handle->mEncParams = encParam;

    Handle->instance_id = 0;
    Handle->src_idx = 0;
    Handle->enc_counter = 0;
    Handle->enc_width = encParam->width;
    Handle->enc_height = encParam->height;
    Handle->bitrate = encParam->bitrate;
    Handle->frame_rate = encParam->frame_rate;
    Handle->mPrependSPSPPSToIDRFrames = true;
    Handle->mOutputBufferLen = 0;
    Handle->mUvSwap = 1;
    Handle->mGopIdx = 0;

    Handle->idrPeriod = encParam->idr_period;

    VLOG(DEBUG, "Handle->idrPeriod: %d\n", Handle->idrPeriod);

    reset_error = 0;

    if (vdi_init(Handle->instance_id) < 0)
        return AMVENC_FAIL;
    ret = Wave4VpuInit(Handle, Handle->instance_id);
    if (ret < AMVENC_SUCCESS)
        return ret;
    ret = Wave4VpuCreateInstance(Handle, 1);
    if (ret < AMVENC_SUCCESS)
        return ret;
    ret = Wave4VpuEncSeqInit(Handle, 1);
    if (ret < AMVENC_SUCCESS)
        return ret;
    //if(Handle->mGopIdx == 0)
    ret = Wave4VpuEncSeqSet(Handle);
    if (ret < AMVENC_SUCCESS)
        return ret;
    Handle->src_count = VpuReadReg(Handle->instance_id, W4_RET_ENC_MIN_SRC_BUF_NUM);
    VLOG(DEBUG, "src count:%d\n", Handle->src_count);
    Wave4VpuEncRegisterFrame(Handle, 1);

#if SUPPORT_SCALE
    if ((encParam->width != encParam->src_width) || (encParam->height != encParam->src_height) || true) {
        memset(&amlge2d,0x0,sizeof(aml_ge2d_t));
        aml_ge2d_info_t *pge2dinfo = &amlge2d.ge2dinfo;
        memset(pge2dinfo, 0, sizeof(aml_ge2d_info_t));
        memset(&(pge2dinfo->src_info[0]), 0, sizeof(buffer_info_t));
        memset(&(pge2dinfo->src_info[1]), 0, sizeof(buffer_info_t));
        memset(&(pge2dinfo->dst_info), 0, sizeof(buffer_info_t));

        set_ge2dinfo(pge2dinfo, encParam);

        int ret = aml_ge2d_init(&amlge2d);
        if (ret < 0) {
            VLOG(ERR, "encode open ge2d failed, ret=0x%x", ret);
            return AMVENC_FAIL;
        }

        INIT_GE2D = true;
    }
#endif
    VLOG(INFO, "AML_HEVCInitialize succeed\n");
    return AMVENC_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x2e0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl 0x38(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x3c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x2fd(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x300(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x308(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x304(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0x8333
movl $0x0, 0x2aeb7(%rip)     # 0x331f4
movq -0x10(%rbp), %rax
movl (%rax), %edi
callq 0x22c0
cmpl $0x0, %eax
jge 0x8359
movl $0x0, -0x4(%rbp)
jmp 0x8423
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %esi
callq 0x21f0
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jge 0x837c
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8423
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x21c0
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jge 0x839e
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8423
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2090
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jge 0x83bd
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8423
movq -0x10(%rbp), %rdi
callq 0x20e0
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jge 0x83d7
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8423
movq -0x10(%rbp), %rax
movl (%rax), %edi
movl $0x1d8, %esi            # imm = 0x1D8
callq 0x2210
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x83f2
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2310
leaq 0x27efd(%rip), %rdi     # 0x30304
movb $0x0, %al
callq 0x2050
leaq 0x27e51(%rip), %rdi     # 0x30266
movb $0x0, %al
callq 0x2050
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)