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

📄 jsvm_mvc_config.py

📁 JMVM MPEG MVC/3DAV 测试平台 国际通用标准
💻 PY
字号:

"""
This file provides functions to create a JSVM configuration file
for the JSVM reference software.  The main function to use
is MakeConfigFile
"""

import string

class ConfigFile:
    """
    An instance of the ConfigFile class represents the configuration
    file parameters for JSVM.  When you first create an instance of
    this class, most of the parameters will be set to reasonable
    defaults.  You can override values or add new values using
    the SetValue command.  Note, that you will have to assign
    values to certain parameters for which no default is given
    otherwise an exception will be reasied when you try to
    write out the config file with the WriteConfigFile method.

    See comments for the following methods for more info:
      __init__
      SetValue
      AddComment
      WriteConfigFile
    """

    def GetValue(self,parameterName):

        assert self.parameterValues.has_key(parameterName), (
            'Cannot get value for parameter %s because it has not been set.' %
            `parameter`)

        return self.parameterValues[parameterName].value

    def SetValue(self,parameterName,value,comment=''):
        """
        SetValue(self,parameterName,value,comment):

        Set the value of a given parameter.
        """
        if (not self.parameterValues.has_key(parameterName)):
            # Add new parameter
            self.parameterPositions[self.parameterCount] = parameterName
            self.parameterCount += 1
        # Update value and comment for new or old parameter
        self.parameterValues[parameterName]=ValueCommentPair(value,comment)

    def AddComment(self,comment):
        """
        AddComment(self,comment):

        Add the given comment.
        """
        name = '<comment>_' + `self.parameterCount`
        self.SetValue(name,'',comment)

    def __init__(self, initialSettings):
        """
        __init__(self, initialSettings):

        initialSettings:  A dictionary of initial values.  For example,
                          if initialSettings = {'SourceWidth':640,
                                                'SourceHeight':480}
                          then the SourceWidth and SourceHeight would be
                          set to 640 and 480.

        Create an instance of a config file with default parameters set.

        """
        self.parameterPositions = {} # maps integers to parameter names
        self.parameterValues = {}
        self.parameterCount = 0
        self.EMPTY=None # flag for uninitialized value that needs non-default

        self.SetDefaults()

        for key in initialSettings.keys():
            self.SetValue(key,initialSettings[key])

    def WriteConfigFile(self,configFileName,warnAboutDefaults=1):
        """
        WriteConfigFile(self,configFileName,warnAboutDefaults=1):

        Write the given configuration file parameters to the file given
        by configFileName.  An exception will be raised if any
        parameters that need a non-default value have not been
        given a value and warnAboutDefaults is non-zero.
        """
        fd = open(configFileName,'w')
        for position in range(self.parameterCount):
            paramName = self.parameterPositions[position]
            paramValue = self.parameterValues[paramName].value
            paramComment = self.parameterValues[paramName].comment            
            if (warnAboutDefaults and self.EMPTY == paramValue):
                raise '\n\nParameter %s must be given non-default value\n\n'%(
                    paramName)
            elif ('' == paramValue): # just a comment
                pass # just a comment, not a real parameter definition    
            else:
                if (type(paramValue) != str): # convert non-strings to strings
                    paramValue = `paramValue`
                fd.write(paramName + '  ' + paramValue)
            if (None == paramComment or '' == paramComment.strip()):
                fd.write('\n')
            else:
                fd.write(' #' + paramComment + '\n')
        fd.close()

    def SetDefaults(self):
        """
        SetDefaults(self):
        
        Set parameters to their default values.
        """
    
        self.AddComment('# JSVM Configuration File')
        self.AddComment('')
        self.AddComment('')
        self.AddComment('#====================== GENERAL ================================')
        self.SetValue('MVCMode',1,'         # must be one for MVC simulations')
        self.SetValue('InputFile',self.EMPTY)
        self.SetValue('OutputFile',self.EMPTY)
        self.SetValue('ReconFile',self.EMPTY)
        self.SetValue('SourceWidth',640,'         # input  frame width')
        self.SetValue('SourceHeight',480,'       # input  frame height')
        self.SetValue('FrameRate',25.0,'      # frame rate [Hz]')
        self.SetValue('FramesToBeEncoded',50,'         # number of frames')
        self.AddComment('')
        self.SetValue('SymbolMode',1,'         # 0=CAVLC, 1=CABAC')
        self.SetValue('FRExt',1,'         # 8x8 transform (0:off, 1:on)')
        self.SetValue('BasisQP',self.EMPTY,'        # Quantization parameters')
        self.SetValue('DPBSize',32,'        # decoded picture buffer in frames')
        self.SetValue('NumRefFrames',32,'# max num of stored reference frames')
        self.SetValue('Log2MaxFrameNum',11,'#  max val for frame_num (4..16)')
        self.SetValue('Log2MaxPocLsb',8,'# coding of pic order counts (4..15)')
        self.SetValue('SequenceFormatString',self.EMPTY)
        self.SetValue('DeltaLayer0Quant',0)
        self.SetValue('DeltaLayer1Quant',3)
        self.SetValue('DeltaLayer2Quant',4)
        self.SetValue('DeltaLayer3Quant',5)
        self.SetValue('DeltaLayer4Quant',6)
        self.SetValue('DeltaLayer5Quant',7)
        self.SetValue('MaxRefIdxActiveBL0',2,'# active entries in ref list 0 for B slices')
        self.SetValue('MaxRefIdxActiveBL1',2,'# active entries in ref list 1 for B slices')
        self.SetValue('MaxRefIdxActiveP',1,'# active entries in ref list for P slices')
        self.SetValue('SearchMode',4,'#Search mode(0:BlockSearch,4:FastSearch)')
        self.SetValue('SearchFuncFullPel',3,'         # Search function full pel (0:SAD, 1:SSE, 2:HADAMARD, 3:SAD-YUV) ')
        self.SetValue('SearchFuncSubPel',2,'         # Search function sub pel  (0:SAD, 1:SSE, 2:HADAMARD) ')
        self.SetValue('SearchRange',96,'        # Search range (Full Pel)')
        self.SetValue('BiPredIter',4,' # Max iterations for bi-pred search')
        self.SetValue('IterSearchRange',8,'         # Search range for iterations (0: normal)')
        self.SetValue('LoopFilterDisable',0,'         # Loop filter idc (0: on, 1: off, 2: on except for slice boundaries)')
        self.SetValue('LoopFilterAlphaC0Offset',0,'         # AlphaOffset(-6..+6): valid range')
        self.SetValue('LoopFilterBetaOffset',0,'         # BetaOffset (-6..+6): valid range')
        self.AddComment('#==========MULTIVIEW CODING PARAMETERS==========')
        self.AddComment('')
        self.SetValue('VFramePeriod',0,'# 0 = disabled')
        self.SetValue('ViewSubsetId',0,'# View subset id')
        self.SetValue('ICMode',1,'# Illumination Compensation (0: off, 1: on)')

class ValueCommentPair:
    """
    Class to hold a config file value and comment.
    """
    
    def __init__(self,value,comment):
        self.value = value
        self.comment = comment


def MakeFileName(fileName):
    """
    Makes sure that there is a single set of quotes around fileName.
    """

    if (fileName[0] == "'" or fileName[0] == "\""):
        return fileName
    else:
        return "\"" + fileName + "\""

⌨️ 快捷键说明

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