This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA2SX: How to config VUI information of h264 sps(Sequence parameter set) frame using TI Vision SDK 3.04

Part Number: TDA2SX

Tool/software:

  How to config VUI information of  h264 sps(Sequence parameter set) frame  using TI Vision SDK 3.04.

 

platform :   TDA2SX

 SDK version:   TI Vision SDK 3.04  

 H264 Encoder HDVICP2 version:  H264ENC_TI DEV.500.V.H264AVC.E.IVAHD.02.01.09.01

According to the  H264_Encoder_HDVICP2_UserGuide.pdf,  I  tried to modify the enclink_h264_set_static_params function code.     

There is still no vui information in H264 SPS frame.

The code for enclink_h264_set_static_params is as follows

static Int enclink_h264_set_static_params(IH264ENC_Params * staticParams,
                                          EncLink_AlgCreateParams *
                                          algCreateParams)
{
    /* Initialize default values for static params */
    *staticParams = H264ENC_TI_PARAMS;

    /* Both width & height needs to be align with 2 bytes */
    staticParams->videnc2Params.maxHeight =
                  VpsUtils_align(algCreateParams->maxHeight, 2);

    staticParams->videnc2Params.maxWidth =
                  VpsUtils_align(algCreateParams->maxWidth, 16);

    staticParams->videnc2Params.maxInterFrameInterval =
        algCreateParams->maxInterFrameInterval;

    staticParams->videnc2Params.inputContentType =
        algCreateParams->inputContentType;

    staticParams->videnc2Params.inputChromaFormat =
        algCreateParams->inputChromaFormat;

    if (algCreateParams->format == SYSTEM_IVIDEO_H264BP)
        staticParams->videnc2Params.profile = IH264_BASELINE_PROFILE;
    else if (algCreateParams->format == SYSTEM_IVIDEO_H264MP)
        staticParams->videnc2Params.profile = IH264_MAIN_PROFILE;
    else if (algCreateParams->format == SYSTEM_IVIDEO_H264HP)
        staticParams->videnc2Params.profile = IH264_HIGH_PROFILE;

    staticParams->videnc2Params.level = IH264_LEVEL_40;
    staticParams->videnc2Params.encodingPreset = algCreateParams->encodingPreset;

    if ((staticParams->videnc2Params.encodingPreset == XDM_USER_DEFINED) &&
        (algCreateParams->enableHighSpeed == TRUE))
    {
        staticParams->interCodingParams.interCodingPreset =
            IH264_INTERCODING_HIGH_SPEED;
        staticParams->intraCodingParams.intraCodingPreset =
            IH264_INTRACODING_HIGH_SPEED;
        staticParams->transformBlockSize = IH264_TRANSFORM_8x8;
    }
    /* In case of interlaced encode, below would be used. In case of progressive
        this will be ignored. */
    staticParams->enableAnalyticinfo = algCreateParams->enableAnalyticinfo;
    staticParams->enableWatermark = algCreateParams->enableWaterMarking;
    staticParams->videnc2Params.rateControlPreset = IVIDEO_USER_DEFINED;
    staticParams->rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
    staticParams->rateControlParams.scalingMatrixPreset
        = IH264_SCALINGMATRIX_NONE;
    staticParams->rateControlParams.rcAlgo = algCreateParams->rateControlPreset;
    staticParams->videnc2Params.maxBitRate = algCreateParams->maxBitRate;

    staticParams->videnc2Params.inputDataMode = IVIDEO_ENTIREFRAME;
    staticParams->videnc2Params.outputDataMode = IVIDEO_ENTIREFRAME;


    /* Number of temporal layeers set to 1. This is the default value  */
    /* in the codec*/
    if (0 == algCreateParams->numTemporalLayer)
    {
        staticParams->numTemporalLayer = IH264_TEMPORAL_LAYERS_1;
    }
    else
    {
        staticParams->numTemporalLayer = algCreateParams->numTemporalLayer;
    }

    /*Note: Enabling this flag adds svc enxtension header to the stream, not all decoders
          are generally able to play back such a stream. */
    /* Needs to be enabled to IH264_SVC_EXTENSION_FLAG_ENABLE for the
          svc extension headers to be present in the stream*/
    /*!!! Note: This flag needs to be enabled for the temporalId to be parsed
         out from the stream.*/
    staticParams->svcCodingParams.svcExtensionFlag =
		        algCreateParams->enableSVCExtensionFlag;

    /*Slice Coding Parameters*/
    staticParams->sliceCodingParams.sliceCodingPreset = IH264_SLICECODING_DEFAULT;
    staticParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_NONE;
    staticParams->sliceCodingParams.streamFormat = IH264_STREAM_FORMAT_DEFAULT;


    /* To set IDR frame periodically instead of I Frame */
    staticParams->IDRFrameInterval = 1;
    /* Override with App settings */
    staticParams->IDRFrameInterval = algCreateParams->IDRFrameInterval;

    /*To trigger workaround inside codec, where SAME_CODEC is overridden as same
      codec type*/
    staticParams->reservedParams[1] = 0x5A3EC0DE;

    /* Enabling debug logging inside the codec. Details in appendix E in H.264
     * encoder user guide.
     */
#ifdef ENCLINK_H264_PERFORMANCE_LOGGING
     staticParams->debugTraceLevel = 1;
     staticParams->lastNFramesToLog = ENCLINK_H264_PROFILER_NUM_FRAMES;
#endif

    /* We want SPS and PPS to be set for every intra frame. Hence configure the
     * the NALU control params to force encoder to insert SPS/PPS on every
     * I frame
     */
 #if 1  
    staticParams->nalUnitControlParams.naluControlPreset =
                                             IH264_NALU_CONTROL_USERDEFINED;
                                             
    ENCLINK_H264_SETNALU_MASK_SPS(staticParams->nalUnitControlParams.
                                               naluPresentMaskIntraPicture);
    ENCLINK_H264_SETNALU_MASK_PPS(staticParams->nalUnitControlParams.
                                                naluPresentMaskIntraPicture);
    ENCLINK_H264_SETNALU_MASK_SEI(staticParams->nalUnitControlParams.
                                                naluPresentMaskIntraPicture);

    ENCLINK_H264_SETNALU_MASK_SPS(staticParams->nalUnitControlParams.
                                                naluPresentMaskIDRPicture);
    ENCLINK_H264_SETNALU_MASK_PPS(staticParams->nalUnitControlParams.
                                                naluPresentMaskIDRPicture);
    ENCLINK_H264_SETNALU_MASK_SEI(staticParams->nalUnitControlParams.
                                                naluPresentMaskIDRPicture);

    ENCLINK_H264_SETNALU_MASK_SPS(staticParams->nalUnitControlParams.
                                                naluPresentMaskStartOfSequence);
    ENCLINK_H264_SETNALU_MASK_PPS(staticParams->nalUnitControlParams.
                                                naluPresentMaskStartOfSequence);
    ENCLINK_H264_SETNALU_MASK_SEI(staticParams->nalUnitControlParams.
                                                naluPresentMaskStartOfSequence);
#endif

    staticParams->entropyCodingMode = IH264_ENTROPYCODING_CABAC;

    if (algCreateParams->profile != IH264_HIGH_PROFILE)
    {
        memset (&staticParams->intraCodingParams, 0,
                               sizeof(IH264ENC_IntraCodingParams));
        staticParams->transformBlockSize = IH264_TRANSFORM_4x4;
        if (algCreateParams->profile == IH264_BASELINE_PROFILE)
        {
            staticParams->entropyCodingMode = IH264_ENTROPYCODING_CAVLC;
        }
    }

#if 1
    staticParams->vuiCodingParams.vuiCodingPreset = IH264_VUICODING_USERDEFINED;
    staticParams->vuiCodingParams.hrdParamsPresentFlag = 1;

    staticParams->vuiCodingParams.aspectRatioInfoPresentFlag  = 0;
    staticParams->vuiCodingParams.aspectRatioIdc              = 0;
    staticParams->vuiCodingParams.videoSignalTypePresentFlag  = 0;
    staticParams->vuiCodingParams.videoFormat                 = 0;
    staticParams->vuiCodingParams.videoFullRangeFlag          = 0;
    staticParams->vuiCodingParams.timingInfoPresentFlag       = 1;
    staticParams->vuiCodingParams.numUnitsInTicks             = 1;
#endif

    /* Uncomment below settings if SEI/meta data needs to be enabled */
    /* staticParams->videnc2Params.metadataType[0] = IH264_SEI_USER_DATA_UNREGISTERED; */

    return 0;
}