Package VisionEgg :: Module qtlowlevel |
[frames] | no frames]

# Source Code for Module VisionEgg.qtlowlevel

      1  import os, sys
      2  import ctypes
      3
      4  if os.name=='nt':
      5      QTMLClient = ctypes.CDLL(r'C:\Program Files\QuickTime\QTSystem\QTMLClient.dll')
      6  elif sys.platform.startswith('darwin'):
      7      # There was once a functional Mac QuickTime implementation, but it
      8      # used a combination of the Python stdlib's quicktime module and
      9      # some C extensions based on the Carbon QuickTime interface. Given
     10      # the inevitable long-term ultimate demise of Carbon, it would be
     11      # foolish to spend much time on the Carbon implementation. On the
     12      # other hand, the newer implementation will require someone who
     13      # knows or learns the new QTKit bindings, which come included with PyObjC.
     14      raise NotImplementedError('QuickTime support is not implemented for Mac OS X.')
     15
     16  # OSErr SInt16 MacTypes.h
     17  # OSStatus SInt32 MacTypes.h
     18  # ItemCount UInt32 MacTypes.h
     19  # FourCharCode SInt32 MacTypes.h
     20  # OSType FourCharCode MacTypes.h
     21  # QTNewMoviePropertyElement struct Movies.h
     22  # QTPropertyClass OSType Movies.h
     23  # QTPropertyID OSType Movies.h
     24  # ByteCount UInt32 MacTypes.h
     25  # QTPropertyValuePtr void* Movies.h
     26  # Movie
     27
     28  OSErr = ctypes.c_short
     29  OSStatus = ctypes.c_int
     30  ItemCount = ctypes.c_uint
     31  FourCharCode = ctypes.c_int
     32  OSType = FourCharCode
     33  QTPropertyClass = OSType
     34  QTPropertyID = OSType
     35  ByteCount = ctypes.c_uint
     36  QTPropertyValuePtr = ctypes.c_void_p
     37  QTVisualContextRef = ctypes.c_void_p
     38 -class Rect(ctypes.Structure):
     39      _fields_ = [("top",   ctypes.c_short),
     40                  ("left",  ctypes.c_short),
     41                  ("bottom",ctypes.c_short),
     42                  ("right", ctypes.c_short)]
     43
     44  Movie = ctypes.c_void_p # not done
     45
     46 -class QTNewMoviePropertyElement(ctypes.Structure):
     47      _fields_ = [("propClass",QTPropertyClass),
     48                  ("propID",QTPropertyID),
     49                  ("propValueSize",ByteCount),
     50                  ("propValueAddress",QTPropertyValuePtr),
     51                  ("propStatus",OSStatus)]
     52
     53 -def FOUR_CHAR_CODE(code):
     54      assert isinstance(code,str)
     55      assert len(code)==4
     56      val = 0
     57      for i in range(4):
     58          c = code[i]
     59          ordc = ord(c)
     60          addval = ordc << (3-i)*8
     61          #print '%d: %s %x %x'%(i,c,ordc,addval)
     62          val += addval
     63      #print '%x\n'%val
     64      return val
     65
     66  if 1:
     67      kQTPropertyClass_DataLocation = FOUR_CHAR_CODE('dloc')
     68      kQTDataLocationPropertyID_DataReference = FOUR_CHAR_CODE('dref') # DataReferenceRecord (for semantics of NewMovieFromDataRef)
     69      kQTDataLocationPropertyID_CFStringNativePath = FOUR_CHAR_CODE('cfnp')
     70      kQTDataLocationPropertyID_CFStringPosixPath = FOUR_CHAR_CODE('cfpp')
     71      kQTDataLocationPropertyID_CFStringHFSPath = FOUR_CHAR_CODE('cfhp')
     72      kQTDataLocationPropertyID_CFStringWindowsPath = FOUR_CHAR_CODE('cfwp')
     73      kQTDataLocationPropertyID_CFURL = FOUR_CHAR_CODE('cfur')
     74      kQTDataLocationPropertyID_QTDataHandler = FOUR_CHAR_CODE('qtdh') # for semantics of NewMovieFromStorageOffset
     75      kQTDataLocationPropertyID_Scrap = FOUR_CHAR_CODE('scrp')
     76      kQTDataLocationPropertyID_LegacyMovieResourceHandle = FOUR_CHAR_CODE('rezh') # QTNewMovieUserProcInfo * (for semantics of NewMovieFromHandle)
     77      kQTDataLocationPropertyID_MovieUserProc = FOUR_CHAR_CODE('uspr') # for semantics of NewMovieFromUserProc
     78      kQTDataLocationPropertyID_ResourceFork = FOUR_CHAR_CODE('rfrk') # for semantics of NewMovieFromFile
     79      kQTDataLocationPropertyID_DataFork = FOUR_CHAR_CODE('dfrk') # for semantics of NewMovieFromDataFork64
     80      kQTPropertyClass_Context      = FOUR_CHAR_CODE('ctxt') # Media Contexts
     81      kQTContextPropertyID_AudioContext = FOUR_CHAR_CODE('audi')
     82      kQTContextPropertyID_VisualContext = FOUR_CHAR_CODE('visu')
     83      kQTPropertyClass_MovieResourceLocator = FOUR_CHAR_CODE('rloc')
     84      kQTMovieResourceLocatorPropertyID_LegacyResID = FOUR_CHAR_CODE('rezi') # (input/result property)
     85      kQTMovieResourceLocatorPropertyID_LegacyResName = FOUR_CHAR_CODE('rezn') # (result property)
     86      kQTMovieResourceLocatorPropertyID_FileOffset = FOUR_CHAR_CODE('foff') # NewMovieFromDataFork[64]
     87      kQTMovieResourceLocatorPropertyID_Callback = FOUR_CHAR_CODE('calb') # NewMovieFromUserProc(getProcrefcon)
     88                                          # Uses kQTMovieDefaultDataRefPropertyID for default dataref
     89      kQTPropertyClass_MovieInstantiation = FOUR_CHAR_CODE('mins')
     90      kQTMovieInstantiationPropertyID_DontResolveDataRefs = FOUR_CHAR_CODE('rdrn')
     91      kQTMovieInstantiationPropertyID_DontAskUnresolvedDataRefs = FOUR_CHAR_CODE('aurn')
     92      kQTMovieInstantiationPropertyID_DontAutoAlternates = FOUR_CHAR_CODE('aaln')
     93      kQTMovieInstantiationPropertyID_DontUpdateForeBackPointers = FOUR_CHAR_CODE('fbpn')
     94      kQTMovieInstantiationPropertyID_AsyncOK = FOUR_CHAR_CODE('asok')
     95      kQTMovieInstantiationPropertyID_IdleImportOK = FOUR_CHAR_CODE('imok')
     96      kQTMovieInstantiationPropertyID_DontAutoUpdateClock = FOUR_CHAR_CODE('aucl')
     97      kQTMovieInstantiationPropertyID_ResultDataLocationChanged = FOUR_CHAR_CODE('dlch') # (result property)
     98      kQTPropertyClass_NewMovieProperty = FOUR_CHAR_CODE('mprp')
     99      kQTNewMoviePropertyID_DefaultDataRef = FOUR_CHAR_CODE('ddrf') # DataReferenceRecord
    100      kQTNewMoviePropertyID_Active  = FOUR_CHAR_CODE('actv')
    101      kQTNewMoviePropertyID_DontInteractWithUser = FOUR_CHAR_CODE('intn')
    102
    103 -class qtlowlevelError(RuntimeError):
    104      pass
    105
    106  noErr = 0
    107  paramErr = -50
    108  movieToolboxUninitialized = -2020
    109 -def GetErrorString(value):
    110      if value == paramErr:
    111          return 'paramErr'
    112      elif value == movieToolboxUninitialized:
    113          return 'movieToolboxUninitialized'
    114      elif value != noErr:
    115          return 'error value: %d'%value
    116      else:
    117          return 'noErr'
    118
    119 -def CheckOSStatus(value):
    120      if value != noErr:
    121          raise qtlowlevelError(GetErrorString(value))
    122      return value
    123
    124  NewMovieFromFile = QTMLClient.NewMovieFromFile
    125
    126  NewMovieFromProperties = QTMLClient.NewMovieFromProperties
    127  #NewMovieFromProperties.restype = OSStatus
    128  NewMovieFromProperties.restype = CheckOSStatus
    129  NewMovieFromProperties.argtypes = [ItemCount,
    130                                     ctypes.POINTER(QTNewMoviePropertyElement),
    131                                     ItemCount,
    132                                     ctypes.POINTER(QTNewMoviePropertyElement),
    133                                     ctypes.POINTER(Movie)]
    134
    135  InitializeQTML = QTMLClient.InitializeQTML
    136  EnterMovies = QTMLClient.EnterMovies
    137
    138  QTGetCFConstant = QTMLClient.QTGetCFConstant
    139
    140  GetMovieBox = QTMLClient.GetMovieBox
    141  GetMovieBox.argtypes = [Movie,
    142                          ctypes.POINTER(Rect)]
    143  SetMovieBox = QTMLClient.SetMovieBox
    144  SetMovieBox.argtypes = [Movie,
    145                          ctypes.POINTER(Rect)]
    146
    147  StartMovie = QTMLClient.StartMovie
    148  StartMovie.argtypes = [Movie]
    149
    150  MoviesTask = QTMLClient.MoviesTask
    151  MoviesTask.argtypes = [Movie,ctypes.c_long]
    152
    153  IsMovieDone = QTMLClient.IsMovieDone
    154  IsMovieDone.argtypes = [Movie]
    155
    156  GoToBeginningOfMovie = QTMLClient.GoToBeginningOfMovie
    157  GoToBeginningOfMovie.argtypes = [Movie]
    158
    159  FSSpec = ctypes.c_void_p
    160  CFStringRef = ctypes.c_void_p
    161  CFStringEncoding = ctypes.c_uint
    162  CFAllocatorRef = ctypes.c_void_p
    163  CFIndex = ctypes.c_int
    164  if 1:
    165      CFStringCreateWithCharacters = QTMLClient.CFStringCreateWithCharacters
    166      CFStringCreateWithCharacters.restype = CFStringRef
    167      CFStringCreateWithCharacters.argtypes = [CFAllocatorRef,
    168                                               ctypes.c_wchar_p,
    169                                               CFIndex]
    170
    171      CFStringCreateWithCString = QTMLClient.CFStringCreateWithCString
    172      CFStringCreateWithCString.restype = CFStringRef
    173      CFStringCreateWithCString.argtypes = [CFAllocatorRef,
    174                                            ctypes.c_char_p,
    175                                            CFStringEncoding]
    176
    177      CFStringGetCString = QTMLClient.CFStringGetCString
    178      CFStringGetCStringPtr = QTMLClient.CFStringGetCStringPtr
    179      CFStringGetCStringPtr.restype = ctypes.c_char_p
    180
    181      NativePathNameToFSSpec = QTMLClient.NativePathNameToFSSpec
    182      NativePathNameToFSSpec.restype = OSErr
    183      NativePathNameToFSSpec.argtypes = [ctypes.c_char_p,
    184                                         ctypes.POINTER(FSSpec),
    185                                         ctypes.c_long]
    186
    187      OpenMovieFile = QTMLClient.OpenMovieFile
    188
    189  if 1:
    190      kCFAllocatorDefault = 0
    191      kCFStringEncodingMacRoman = 0 # CoreFoundation/CFString.h
    192