⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp4_enc_misc.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    //f VOL.low_delay;
    //f VOL.vbv_parameters;
    //f VOL.first_half_bit_rate;
    //f VOL.latter_half_bit_rate;
    //f VOL.first_half_vbv_buffer_size;
    //f VOL.latter_half_vbv_buffer_size;
    //f VOL.first_half_vbv_occupancy;
    //f VOL.latter_half_vbv_occupancy;
    VOL.video_object_layer_shape = MP4_SHAPE_TYPE_RECTANGULAR;
    //f VOL.video_object_layer_shape_extension
    VOL.vop_time_increment_resolution = par->TimeResolution;
    VOL.fixed_vop_rate = (par->TimeResolution > par->TimeIncrement) ? 1 : 0;
    VOL.fixed_vop_time_increment = par->TimeIncrement;
    VOL.vop_time_increment_resolution_bits = 1;
    i = VOL.vop_time_increment_resolution - 1;
    while (i >> VOL.vop_time_increment_resolution_bits)
        VOL.vop_time_increment_resolution_bits ++;
    VOL.video_object_layer_width = par->Width;
    VOL.video_object_layer_height = par->Height;
    VOL.interlaced = par->interlaced;
    VOL.obmc_disable = par->obmc_disable;
    VOL.sprite_enable = par->sprite_enable;
    VOL.sprite_width = par->sprite_width;
    VOL.sprite_height = par->sprite_height;
    VOL.sprite_left_coordinate = par->sprite_left_coordinate;
    VOL.sprite_top_coordinate = par->sprite_left_coordinate;
    VOL.no_of_sprite_warping_points = par->no_of_sprite_warping_points;
    VOL.sprite_warping_accuracy = par->sprite_warping_accuracy;
    VOL.sprite_brightness_change = VOL.sprite_enable == MP4_SPRITE_GMC ? 0 : par->sprite_brightness_change;
    VOL.low_latency_sprite_enable = 0;
    VOL.sadct_disable = 1;
    VOL.not_8_bit = 0;
    VOL.quant_precision = 5;
    VOL.bits_per_pixel = 8;
    //f VOL.no_gray_quant_update;
    //f VOL.composition_method;
    //f VOL.linear_composition;
    VOL.quant_type = par->quant_type;
    VOL.load_intra_quant_mat = par->load_intra_quant_mat;
    VOL.load_intra_quant_mat_len = par->load_intra_quant_mat_len;
    VOL.load_nonintra_quant_mat = par->load_nonintra_quant_mat;
    VOL.load_nonintra_quant_mat_len = par->load_nonintra_quant_mat_len;
    //f VOL.quant_mat_grayscale;
    VOL.quarter_sample = (mMEflags & ME_QP) ? 1 : 0;
    VOL.complexity_estimation_disable = 1;
    //f VOL.ComplexityEstimation;
    VOL.resync_marker_disable = par->resync ? 0 : 1;
    mInsertResync = par->resync;
    mVideoPacketLength = par->VideoPacketLenght;
    VOL.data_partitioned = par->data_partitioned;
    VOL.reversible_vlc = (VOL.data_partitioned) ? par->reversible_vlc : 0;
    VOL.newpred_enable = 0;
    //f VOL.requested_upstream_message_type;
    //f VOL.newpred_segment_type;
    VOL.reduced_resolution_vop_enable = 0;
    VOL.scalability = 0;
    //f VOL.ScalabilityParameters;
    VOP.vop_time_increment = 0;
    VOP.intra_dc_vlc_thr = 0; //par->intra_dc_vlc_thr;
    if (VOL.data_partitioned)
        VOL.interlaced = 0;
    if (VOL.interlaced) {
        VOP.top_field_first = par->top_field_first;
        VOP.alternate_vertical_scan_flag = par->alternate_vertical_scan_flag;
        if (par->interlacedME == 0)
            mMEflags |= ME_FIELD;
        else if (par->interlacedME == 1)
            mMEflags |= ME_FRAME;
        else  if (par->interlacedME == 2)
            mMEflags |= ME_FRAME | ME_FIELD;
        //f  if ((mMEflags & ME_CHROMA) && (mMEflags & ME_FIELD)) {
        //    mMEflags &= ~ME_CHROMA;
        //    ErrorMessage("chroma ME is not implemented for field ME");
        //}
    } else {
        mMEflags |= ME_FRAME;
    }
    VOP.vop_rounding_type = 0;
    if (VOL.short_video_header) {
        mBVOPdist = 0;
        VO.colour_primaries = 1;
        VO.transfer_characteristics = 1;
        VO.matrix_coefficients = 6;
        VOL.quant_precision  = 5;
        VOL.video_object_layer_shape = MP4_SHAPE_TYPE_RECTANGULAR;
        VOL.obmc_disable = 1;
        VOL.quant_type = 0;
        VOL.resync_marker_disable = 1;
        VOL.data_partitioned = 0;
        VOL.reversible_vlc = 0;
        VOL.interlaced = 0;
        VOL.complexity_estimation_disable = 1;
        VOL.scalability = 0;
        VOL.not_8_bit = 0;
        VOL.bits_per_pixel = 8;
        VOP.vop_rounding_type = 0;
        VOP.vop_fcode_forward = 1;
        VOP.vop_coded = 1;
        VOP.split_screen_indicator = 0;
        VOP.document_camera_indicator = 0;
        VOP.full_picture_freeze_release = 0;
        if (par->Width == 128 && par->Height == 96) {
            VOP.source_format = 1;
            VOP.num_gobs_in_vop = 6;
            VOP.num_macroblocks_in_gob = 8;
        } else if (par->Width == 176 && par->Height == 144) {
            VOP.source_format = 2;
            VOP.num_gobs_in_vop = 9;
            VOP.num_macroblocks_in_gob = 11;
        } else if (par->Width == 352 && par->Height == 288) {
            VOP.source_format = 3;
            VOP.num_gobs_in_vop = 18;
            VOP.num_macroblocks_in_gob = 22;
        } else if (par->Width == 704 && par->Height == 576) {
            VOP.source_format = 4;
            VOP.num_gobs_in_vop = 18;
            VOP.num_macroblocks_in_gob = 88;
        } else if (par->Width == 1408 && par->Height == 1152) {
            VOP.source_format = 5;
            VOP.num_gobs_in_vop = 18;
            VOP.num_macroblocks_in_gob = 352;
        } else {
            ErrorMessage(VM_STRING("Size of picture is incompatible with short_video_header"));
            return MP4_STS_ERR_PARAM;
        }
        VOP.temporal_reference_increment = VOL.fixed_vop_time_increment / 1001;
        VOL.quarter_sample = 0;
        if (mMEflags & ME_QP) {
            mMEflags &= ~ME_QP;
            mMEflags |= ME_HP;
        }
        mMEflags &= ~ME_4MV;
        Ipp32s sw = IPP_MIN(15, par->Width);
        Ipp32s sh = IPP_MIN(15, par->Height);
        mBVOPsearchHorForw = mBVOPsearchVerForw = mBVOPsearchHorBack = mBVOPsearchVerBack = 0;
        mPVOPsearchHor = par->PVOPsearchWidth;
        mPVOPsearchVer = par->PVOPsearchHeight;
        mp4_ClipR(mPVOPsearchHor, sw);
        mp4_ClipR(mPVOPsearchVer, sh);
        if (mPVOPsearchHor < 0)
            mPVOPsearchHor = sw;
        if (mPVOPsearchVer < 0)
            mPVOPsearchVer = sh;
        if (mPVOPsearchHor == 0 || mPVOPsearchVer == 0)
            mMEflags |= ME_ZERO_MV;
        mPVOPfcodeForw = 1;
        mRoundingControl = 0;
        mInsertGOV = 0;
        mRepeatHeaders = 0;
    } else {
        Ipp32s sw = IPP_MIN(VOL.quarter_sample ? 511 : 1023, par->Width);
        Ipp32s sh = IPP_MIN(VOL.quarter_sample ? 511 : 1023, par->Height);
        mPVOPsearchHor = par->PVOPsearchWidth;
        mPVOPsearchVer = par->PVOPsearchHeight;
        mBVOPsearchHorForw = par->BVOPsearchWidthForw;
        mBVOPsearchVerForw = par->BVOPsearchHeightForw;
        mBVOPsearchHorBack = par->BVOPsearchWidthBack;
        mBVOPsearchVerBack = par->BVOPsearchHeightBack;
        mp4_ClipR(mPVOPsearchHor, sw);
        mp4_ClipR(mPVOPsearchVer, sh);
        mp4_ClipR(mBVOPsearchHorForw, sw);
        mp4_ClipR(mBVOPsearchVerForw, sh);
        mp4_ClipR(mBVOPsearchHorBack, sw);
        mp4_ClipR(mBVOPsearchVerBack, sh);
        if (mPVOPsearchHor < 0 || mPVOPsearchVer < 0 || (mBVOPdist && (mBVOPsearchHorForw < 0 || mBVOPsearchVerForw < 0 || mBVOPsearchHorBack < 0 || mBVOPsearchVerBack < 0))) {
            mMEflags |= ME_AUTO_RANGE;
            mPVOPsearchHor = mPVOPsearchVer = mBVOPsearchHorForw = mBVOPsearchVerForw = mBVOPsearchHorBack = mBVOPsearchVerBack = 31;
            mPVOPfcodeForw = mBVOPfcodeForw = mBVOPfcodeBack = 2;
        } else if (mPVOPsearchHor == 0 || mPVOPsearchVer == 0 || (mBVOPdist && (mBVOPsearchHorForw == 0 || mBVOPsearchVerForw == 0 || mBVOPsearchHorBack == 0 || mBVOPsearchVerBack == 0))) {
            mMEflags |= ME_ZERO_MV;
            mPVOPfcodeForw = mBVOPfcodeForw = mBVOPfcodeBack = 1;
        } else {
            // calc vop_fcode_forward for PVOPs
            i = IPP_MAX(mPVOPsearchHor, mPVOPsearchVer);
            j = i << 1;
            mPVOPfcodeForw = 1;
            while (j > ((16 << mPVOPfcodeForw) - 1))
                mPVOPfcodeForw ++;
            // calc vop_fcode_forward for BVOPs
            i = IPP_MAX(mBVOPsearchHorForw, mBVOPsearchVerForw);
            j = i << 1;
            mBVOPfcodeForw = 1;
            while (j > ((16 << mBVOPfcodeForw) - 1))
                mBVOPfcodeForw ++;
            // calc vop_fcode_backward for BVOPs
            i = IPP_MAX(mBVOPsearchHorBack, mBVOPsearchHorBack);
            j = i << 1;
            mBVOPfcodeBack = 1;
            while (j > ((16 << mBVOPfcodeBack) - 1))
                mBVOPfcodeBack ++;
        }
        if (VOL.quarter_sample) {
            if ((IPP_MAX(mPVOPsearchHor, mPVOPsearchVer) << 2) > (16 << mPVOPfcodeForw) - 1)
                mPVOPfcodeForw ++;
            if ((IPP_MAX(mBVOPsearchHorForw, mBVOPsearchVerForw) << 2) > (16 << mBVOPfcodeForw) - 1)
                mBVOPfcodeForw ++;
            if ((IPP_MAX(mBVOPsearchHorBack, mBVOPsearchVerBack) << 2) > (16 << mBVOPfcodeBack) - 1)
                mBVOPfcodeBack ++;
            VO.visual_object_verid = 2;
            VOL.video_object_layer_verid = 2;
        }
        if (VOL.sprite_enable == MP4_SPRITE_GMC) {
            VO.visual_object_verid = 2;
            VOL.video_object_layer_verid = 2;
        }
        mTframe = 0; // for Direct field MC
    }
    if (VOL.sprite_enable == MP4_SPRITE_STATIC) {
        mPlanes = 1;
        mSourceWidth = par->sprite_width;
        mSourceHeight = par->sprite_height;
    } else {
        mPlanes = (mIVOPdist == 1) ? 1 : (mBVOPdist == 0) ? 2 : 2 + mBVOPdist + 1;
        mSourceWidth = par->Width;
        mSourceHeight = par->Height;
    }
    VOP.warping_mv_code_du[0] = VOP.warping_mv_code_du[1] = VOP.warping_mv_code_du[2] = VOP.warping_mv_code_du[3] = 0;
    VOP.warping_mv_code_dv[0] = VOP.warping_mv_code_dv[1] = VOP.warping_mv_code_dv[2] = VOP.warping_mv_code_dv[3] = 0;
    mSourceFormat = YUV_CHROMA_420;
    mExpandSize = 16;
    mExpandSizeA = (mExpandSize + 15) & (~15);
    mNumMacroBlockPerRow = (mSourceWidth + 15) >> 4;
    mNumMacroBlockPerCol = (mSourceHeight + 15) >> 4;
    mNumMacroBlockPerVOP = mNumMacroBlockPerRow * mNumMacroBlockPerCol;
    mStepLuma = mExpandSizeA * 2 + mNumMacroBlockPerRow * 16;
    mLumaPlaneSize = mStepLuma * (mExpandSizeA * 2 + mNumMacroBlockPerCol * 16);
    mStepChroma = (mExpandSizeA >> 1) * 2 + mNumMacroBlockPerRow * 8;
    mChromaPlaneSize = mStepChroma * ((mExpandSizeA >> 1) * 2 + mNumMacroBlockPerCol * 8);
    mSceneChangeThreshold = (mNumMacroBlockPerVOP * par->SceneChangeThreshold + 50) / 100;
    mIsInit = true;
    // buffers allocation
    mFrame = new mp4_Frame [mPlanes];
    if (mFrame) {
        for (i = 0; i < mPlanes; i ++) {
            //mFrame[i].ap = ippsMalloc_8u(mLumaPlaneSize + mChromaPlaneSize + mChromaPlaneSize);
            //if (!mFrame[i].ap)
            //    stsAlloc = ippStsMemAllocErr;
            //mFrame[i].pY = mFrame[i].ap + mExpandSizeA + mExpandSizeA * mStepLuma;
            //mFrame[i].pU = mFrame[i].ap + mLumaPlaneSize + (mExpandSizeA >> 1) + (mExpandSizeA >> 1) * mStepChroma;
            //mFrame[i].pV = mFrame[i].ap + mLumaPlaneSize + mChromaPlaneSize + (mExpandSizeA >> 1) + (mExpandSizeA >> 1) * mStepChroma;
        }
    } else
        stsAlloc = ippStsMemAllocErr;
    if (VOL.sprite_enable == MP4_SPRITE_GMC) {
        ippiWarpGetSize_MPEG4(&specSize);
        mWarpSpec = (IppiWarpSpec_MPEG4*)ippsMalloc_8u(specSize);
        if (!mWarpSpec)
            stsAlloc = ippStsMemAllocErr;
        mGMCPredY = mGMCPredU = mGMCPredV = NULL;
        //mGMCPredY = ippsMalloc_8u(3*16*16*mNumMacroBlockPerRow >> 1);
        //mGMCPredU = mGMCPredY + 16*16*mNumMacroBlockPerRow;
        //mGMCPredV = mGMCPredU + 8*8*mNumMacroBlockPerRow;
#ifdef USE_CV_GME
        // pyramids
        mPyrLevel = 3;
        while (mSourceWidth < (1 << mPyrLevel) && mSourceHeight < (1 << mPyrLevel))
            mPyrLevel --;
        Ipp16s pKernel[5] = {1, 4, 6, 4, 1};
        IppiSize vopSize;
        const Ipp32f  rate = 2.0f;
        vopSize.width = mSourceWidth;
        vopSize.height = mSourceHeight;
        mPyramid[0] = NULL;
        stsPyr = ippiPyramidInitAlloc(&mPyramid[0], mPyrLevel, vopSize, rate);
        if (stsPyr == ippStsNoErr) {
            mPyramid[0]->pState = NULL;
            stsPyr = ippiPyramidLayerDownInitAlloc_8u_C1R((IppiPyramidDownState_8u_C1R**)(&(mPyramid[0]->pState)), vopSize, rate, pKernel, 5, IPPI_INTER_LINEAR);
            if (stsPyr == ippStsNoErr && mPyramid[0]->level == mPyrLevel) {
                mPyramid[1] = NULL;
                stsPyr = ippiPyramidInitAlloc(&mPyramid[1], mPyrLevel, vopSize, rate);
                if (stsPyr == ippStsNoErr) {
                    mPyramid[1]->pState = NULL;
                    stsPyr = ippiPyramidLayerDownInitAlloc_8u_C1R((IppiPyramidDownState_8u_C1R**)(&(mPyramid[1]->pState)), vopSize, rate, pKernel, 5, IPPI_INTER_LINEAR);
                    if (mPyramid[1]->level != mPyrLevel)
                        stsPyr = ippStsMemAllocErr;
                    else {
                        for (i = 1; i <= mPyrLevel; i ++) {
                            mPyramid[0]->pImage[i] = ippiMalloc_8u_C1(mPyramid[0]->pRoi[i].width, mPyramid[0]->pRoi[i].height, &mPyramid[0]->pStep[i]);
                            if (!mPyramid[0]->pImage[i])
                                stsPyr = ippStsMemAllocErr;
                            mPyramid[1]->pImage[i] = ippiMalloc_8u_C1(mPyramid[1]->pRoi[i].width, mPyramid[1]->pRoi[i].height, &mPyramid[1]->pStep[i]);
                            if (!mPyramid[1]->pImage[i])
                                stsPyr = ippStsMemAllocErr;
                        }
                    }
                }
            }
        }
        if (stsPyr != ippStsNoErr)
            stsAlloc = ippStsMemAllocErr;
        mPyrC = mPyramid[0];
        mPyrR = mPyramid[1];
        mOptFlowNumPoint = mSourceWidth * mSourceHeight / (32 * 32);
        if (mOptFlowNumPoint <= 0)
            mOptFlowNumPoint = 10;
        else if (mOptFlowNumPoint > 10000)
            mOptFlowNumPoint = 10000;
        Ipp64f ratio_xy = (Ipp64f)mPyramid[0]->pRoi[0].width / mPyramid[0]->pRoi[0].height;
        mOptFlowNumPointY = (Ipp32s)floor(sqrt(mOptFlowNumPoint / ratio_xy) + 0.5);
        mOptFlowNumPointX = (Ipp32s)floor(mOptFlowNumPointY * ratio_xy + 0.5);
        mOptFlowNumPoint = mOptFlowNumPointX * mOptFlowNumPointY;
        mOptFlowWinSize = 11;
        if (ippiOpticalFlowPyrLKInitAlloc_8u_C1R(&mOptFlowState, mPyramid[0]->pRoi[0], mOptFlowWinSize, ippAlgHintAccurate) != ippStsNoErr)
            stsAlloc = ippStsMemAllocErr;
        mOptFlowPoints = (IppiPoint_32f*)ippMalloc(mOptFlowNumPoint * 2 * sizeof(mOptFlowPoints[0]));
        mOptFlowPtC = mOptFlowPoints;
        mOptFlowPtR = mOptFlowPoints + mOptFlowNumPoint;
        mOptFlowPtSts = (Ipp8s*)ippMalloc(mOptFlowNumPoint * sizeof(mOptFlowPtSts[0]));
        mOptFlowPatchDiff = (Ipp32f*)ippMalloc(mOptFlowNumPoint * sizeof(mOptFlowPatchDiff[0]));
        mOptFlowMask = (Ipp8s*)ippMalloc(mOptFlowNumPoint * 2 * sizeof(mOptFlowMask[0]));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -