📄 mpeg2_params.cpp
字号:
/*////////////////////////////////////////////////////////////////////////////////// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright(c) 2002-2005 Intel Corporation. All Rights Reserved.//*/#include "mpeg2_params.h"#include <ipps.h>/* identifies valid profile/level combinations */static Ipp8u Profile_Level_Defined[5][4] ={ /* HL H-14 ML LL */ {1, 1, 1, 0}, /* HP */ {0, 1, 0, 0}, /* Spat */ {0, 0, 1, 1}, /* SNR */ {1, 1, 1, 1}, /* MP */ {0, 0, 1, 0} /* SP */};static struct LevelLimits{ int hor_f_code; int vert_f_code; int hor_size; int vert_size; int sample_rate; int bit_rate; /* Mbit/s */ int vbv_buffer_size; /* 16384 bit steps */} MaxValTbl[4] ={ {9, 5, 1920, 1152, 62668800, 80, 597}, /* HL */ {9, 5, 1440, 1152, 47001600, 60, 448}, /* H-14 */ {8, 5, 720, 576, 10368000, 15, 112}, /* ML */ {7, 4, 352, 288, 3041280, 4, 29} /* LL */};#define SP 5#define MP 4#define SNR 3#define SPAT 2#define HP 1#define LL 10#define ML 8#define H14 6#define HL 4#define MPEG2_StsWarn ippStsNoOperation#define error(Message) \{ \ vm_string_sprintf(err_warn_message, __VM_STRING(Message)); \ return ippStsErr; \}#define warning(Message) \{ \ if (vm_string_strlen(err_warn_message) + vm_string_strlen(__VM_STRING(Message) + vm_string_strlen(__VM_STRING("\n"))) < 256) { \ vm_string_sprintf(err_warn_message, __VM_STRING("%s \n"),Message); \ } \ ret = MPEG2_StsWarn; \}/* ISO/IEC 13818-2, 6.3.11 *//* this pretty table was designed to avoid coincidences with any GPL code */static VM_ALIGN16_DECL(Ipp16s) DefaultIntraQuantMatrix[64] ={ 8, 16, 19, 22, 26, 27, 29, 34, 16, 16, 22, 24, 27, 29, 34, 37, 19, 22, 26, 27, 29, 34, 34, 38, 22, 22, 26, 27, 29, 34, 37, 40, 22, 26, 27, 29, 32, 35, 40, 48, 26, 27, 29, 32, 35, 40, 48, 58, 26, 27, 29, 34, 38, 46, 56, 69, 27, 29, 35, 38, 46, 56, 69, 83};ippMPEG2EncoderParams::ippMPEG2EncoderParams(){ *err_warn_message = 0; *IntraQMatrixFName = 0; *NonIntraQMatrixFName = 0; *TemplateLogFile = 0; *IntraQMatrix = 0; *NonIntraQMatrix = 0; pMotionData = NULL; prog_seq = 1; // progressive sequence progressive_frame = 1; // progressive frame LogMask = 0; CustomIntraQMatrix = 0; CustomNonIntraQMatrix = 0; IPDistance = 1; // distance between key-frames gopSize = 4; // size of GOP frame_rate_code = 5; // 30 frames/sec aspectRatio = 2; ProfileID = 4; LevelID = 8; chroma_format = CHROMA420; repeat_first_field = 0; top_field_first = 0; // display top field first intra_dc_precision = 0; // 8 bit FieldPicture = 0; // field or frame picture (if progframe=> frame) VBV_BufferSize = 112; low_delay = 0; nonLinearQScale[0] = 0; nonLinearQScale[1] = 0; nonLinearQScale[2] = 0; frame_pred_frame_dct[0] = 1; frame_pred_frame_dct[1] = 1; frame_pred_frame_dct[2] = 1; intraVLCFormat[0] = 0; intraVLCFormat[1] = 0; intraVLCFormat[2] = 0; altscan_tab[0] = 0; altscan_tab[1] = 0; altscan_tab[2] = 0; mpeg1 = 0; // 1 - mpeg1, 0 - mpeg2 *idStr = 0; // user data to put to each sequence numThreads = 1; // not tested, use 1 performance = 0; encode_time = 0; motion_estimation_perf = 0; me_alg_num = 3;}ippMPEG2EncoderParams::~ippMPEG2EncoderParams(){ if (pMotionData) { ippsFree(pMotionData); } pMotionData = NULL;}void ippMPEG2EncoderParams::operator=(ippMPEG2EncoderParams &par){ if (pMotionData) { ippsFree(pMotionData); } memcpy(this, &par, sizeof(ippMPEG2EncoderParams)); if(IPDistance <= 0) pMotionData = 0; else { pMotionData = (MotionData*)ippsMalloc_8u(IPDistance*sizeof(MotionData)); if(pMotionData && par.pMotionData) memcpy(pMotionData, par.pMotionData, IPDistance*sizeof(MotionData)); }}IppStatus ippMPEG2EncoderParams::ReadQMatrices(){ int i, temp; FILE *InputFile; if( IntraQMatrixFName[0] == '-' ) { // use default intra matrix CustomIntraQMatrix = 0; for(i=0; i<64; i++) IntraQMatrix[i] = DefaultIntraQuantMatrix[i]; } else { // load custom intra matrix CustomIntraQMatrix = 1; if( !(InputFile = vm_file_open(IntraQMatrixFName,VM_STRING("rt"))) ) { vm_string_sprintf(err_warn_message, __VM_STRING("Couldn't open quant matrix file %s"), IntraQMatrixFName); return ippStsErr; } for(i=0; i<64; i++) { vm_file_scanf( InputFile, VM_STRING("%d"), &temp ); if( temp < 1 || temp > 255 ) error("invalid value in quant matrix"); IntraQMatrix[i] = temp; } fclose( InputFile ); } if (NonIntraQMatrixFName[0] == '-') { // use default non-intra matrix CustomNonIntraQMatrix = 0; for(i=0; i<64; i++) NonIntraQMatrix[i] = 16; } else { // load custom non-intra matrix CustomNonIntraQMatrix = 1; if( !(InputFile = vm_file_open(NonIntraQMatrixFName,VM_STRING("rt"))) ) { vm_string_sprintf(err_warn_message, __VM_STRING("Couldn't open quant matrix file %s"), NonIntraQMatrixFName); return ippStsErr; } for(i=0; i<64; i++) { vm_file_scanf( InputFile, VM_STRING("%d"), &temp ); if( temp < 1 || temp > 255 ) error("invalid value in quant matrix"); NonIntraQMatrix[i] = temp; } fclose( InputFile ); } return ippStsOk;}IppStatus ippMPEG2EncoderParams::Profile_and_Level_Checks(){ int i; struct LevelLimits *MaxVal; if( ProfileID < 0 || ProfileID > 15 ) error("profile must be between 0 and 15"); if( LevelID < 0 || LevelID > 15 ) error("level must be between 0 and 15"); if( ProfileID >= 8 ) { vm_string_strcat(err_warn_message, __VM_STRING("Warning: profile uses a reserved value, conformance checks skipped\n")); return MPEG2_StsWarn; } if( ProfileID < HP || ProfileID > SP ) error("undefined Profile"); if( ProfileID == SNR || ProfileID == SPAT ) error("This encoder currently generates no scalable bitstreams"); if( LevelID < HL || LevelID > LL || LevelID & 1 ) error("undefined Level"); MaxVal = &MaxValTbl[(LevelID - 4) >> 1]; // check profile - level combination if( !Profile_Level_Defined[ProfileID-1][(LevelID-4) >> 1] ) error("undefined profile - level combination"); // check profile constraints if( ProfileID == SP && IPDistance != 1 ) error("Simple Profile does not allow B pictures"); if( ProfileID != HP && chroma_format != CHROMA420 ) error("chroma format must be 4:2:0 in specified Profile");#ifndef MPEG2_DEBUG_CODE if( ProfileID == HP && chroma_format == CHROMA444 ) error("chroma format must be 4:2:0 or 4:2:2 in High Profile");#endif if( ProfileID >= MP ) // SP, MP: constrained repeat_first_field { if( frame_rate_code <=2 && repeat_first_field ) error("repeat_first_field must be zero"); if( frame_rate_code <=6 && prog_seq && repeat_first_field ) error("repeat_first_field must be zero"); } if( ProfileID !=HP && intra_dc_precision == 3 ) error("11 bit DC precision only allowed in High Profile"); // check level constraints // Table 8-8 if( frame_rate_code > 5 && LevelID >= ML ) error("Picture rate greater than permitted in specified Level"); if( pMotionData[0].forw_hor_f_code > MaxVal->hor_f_code ) error("forward horizontal f_code greater than permitted in specified Level"); if( pMotionData[0].forw_vert_f_code > MaxVal->vert_f_code ) error("forward vertical f_code greater than permitted in specified Level"); for(i = 1; i < IPDistance; i++) { if( pMotionData[i].forw_hor_f_code > MaxVal->hor_f_code ) error("forward horizontal f_code greater than permitted in specified Level"); if( pMotionData[i].forw_vert_f_code > MaxVal->vert_f_code ) error("forward vertical f_code greater than permitted in specified Level"); if( pMotionData[i].back_hor_f_code > MaxVal->hor_f_code ) error("backward horizontal f_code greater than permitted in specified Level"); if( pMotionData[i].back_vert_f_code > MaxVal->vert_f_code ) error("backward vertical f_code greater than permitted in specified Level"); } // Table 8-13 if( VBV_BufferSize > MaxVal->vbv_buffer_size ) error("vbv_buffer_size exceeds High Level limit"); return ippStsOk;}IppStatus ippMPEG2EncoderParams::RelationChecks(){ int i; IppStatus ret = ippStsOk; if( mpeg1 ) { warning("Warning: MPEG1 is not implemented. Setting to MPEG2"); mpeg1 = 0; } if(aspectRatio < 1 || aspectRatio > 4) { warning("Warning: setting aspect ratio to 1"); aspectRatio = 1; } if(frame_rate_code < 1 || frame_rate_code > 8) { warning("Warning: setting frame rate to 30 fps"); frame_rate_code = 5; } if( prog_seq && !progressive_frame ) { warning("Warning: setting progressive_frame = 1"); progressive_frame = 1; } if( !progressive_frame && repeat_first_field )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -