Advertisement
KenV99

line profiler

Jul 30th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. Line # Hits Time Per Hit % Time Line Contents
  2. ==============================================================
  3. 1171 @profile
  4. 1172 def run_ni(self):
  5. 1173 1 7 7.0 0.0 capture = xbmc.RenderCapture()
  6. 1174 1 2 2.0 0.0 tw = capture.getHeight()
  7. 1175 1 2 2.0 0.0 th = capture.getWidth()
  8. 1176 1 2 2.0 0.0 tar = capture.getAspectRatio()
  9. 1177 1 1 1.0 0.0 width = self.infos[0]
  10. 1178 1 1 1.0 0.0 height = self.infos[1]
  11. 1179 1 1 1.0 0.0 ratio = self.infos[2]
  12. 1180 1 1 1.0 0.0 missed_capture_count = 0
  13. 1181 1 1 1.0 0.0 counter = 0
  14. 1182 1 1 1.0 0.0 length = width * height * 4
  15. 1183 1 1 1.0 0.0 sfps = self.infos[4]
  16. 1184 1 1 1.0 0.0 if sfps == 0:
  17. 1185 sfps = float(xbmc.getInfoLabel('System.FPS'))
  18. 1186 1 9 9.0 0.0 info('Initial video framerate reported as %s' % str(sfps))
  19. 1187 1 3 3.0 0.0 tpf = int(1000.0/sfps)
  20. 1188 1 2 2.0 0.0 sleeptime = int(0.1 * tpf)
  21. 1189 1 1 1.0 0.0 try:
  22. 1190 1 19 19.0 0.0 self.inDataMap = mmap.mmap(0, length + 11, 'AmbiBox_XBMC_SharedMemory', mmap.ACCESS_WRITE)
  23. 1191 1 1 1.0 0.0 if simul:
  24. 1192 1 3 3.0 0.0 self.inDataMap[0] = chr(248)
  25. 1193 except Exception, e:
  26. 1194 info('Error creating connection to Ambibox Windows')
  27. 1195 if hasattr(e, 'message'):
  28. 1196 info(str(e.message))
  29. 1197 return
  30. 1198 else:
  31. 1199 1 1 1.0 0.0 if self.inDataMap is None:
  32. 1200 info('Error creating connection to Ambibox Windows, no further information available')
  33. 1201 return
  34. 1202 1 33007 33007.0 0.4 capture.capture(width, height, xbmc.CAPTURE_FLAG_CONTINUOUS)
  35. 1203 1 3 3.0 0.0 if self.runtype == self.TYPE_STANDARD:
  36. 1204 self.playing_file = self.player.getPlayingFile()
  37. 1205 1272 5823 4.6 0.1 while self.exit_event(counter) is False:
  38. 1206 1271 3520392 2769.8 45.3 capture.waitForCaptureStateChangeEvent(tpf)
  39. 1207 1271 5661 4.5 0.1 cgcs = capture.getCaptureState()
  40. 1208 1271 2353 1.9 0.0 if cgcs == xbmc.CAPTURE_STATE_DONE:
  41. 1209 1271 3134 2.5 0.0 image = capture.getImage()
  42. 1210 1271 3690 2.9 0.0 self.inDataMap.seek(0)
  43. 1211 1271 2814 2.2 0.0 seeked = self.inDataMap.read_byte()
  44. 1212 1271 2406 1.9 0.0 if ord(seeked) == 248:
  45. 1213 1271 1929 1.5 0.0 if counter == 0:
  46. 1214 1 1 1.0 0.0 length = len(image)
  47. 1215 1 10 10.0 0.0 info('XBMCDirect Capture successful')XBMCDirect capture terminated
  48.  
  49. 1216 1 4 4.0 0.0 notification(__language__(32034))
  50. 1217 # width
  51. 1218 1 2 2.0 0.0 self.inDataMap[1] = chr(width & 0xff)
  52. 1219 1 1 1.0 0.0 self.inDataMap[2] = chr((width >> 8) & 0xff)
  53. 1220 # height
  54. 1221 1 2 2.0 0.0 self.inDataMap[3] = (chr(height & 0xff))
  55. 1222 1 1 1.0 0.0 self.inDataMap[4] = (chr((height >> 8) & 0xff))
  56. 1223 # aspect ratio
  57. 1224 1 2 2.0 0.0 self.inDataMap[5] = (chr(int(ratio * 100)))
  58. 1225 # image format
  59. 1226 1 7 7.0 0.0 fmt = capture.getImageFormat()
  60. 1227 1 2 2.0 0.0 if fmt == 'RGBA':
  61. 1228 1 1 1.0 0.0 self.inDataMap[6] = (chr(0))
  62. 1229 elif fmt == 'BGRA':
  63. 1230 self.inDataMap[6] = (chr(1))
  64. 1231 else:
  65. 1232 self.inDataMap[6] = (chr(2))
  66. 1233 # datasize
  67. 1234 1 1 1.0 0.0 self.inDataMap[7] = (chr(length & 0xff))
  68. 1235 1 1 1.0 0.0 self.inDataMap[8] = (chr((length >> 8) & 0xff))
  69. 1236 1 2 2.0 0.0 self.inDataMap[9] = (chr((length >> 16) & 0xff))
  70. 1237 1 1 1.0 0.0 self.inDataMap[10] = (chr((length >> 24) & 0xff))
  71. 1238 1271 2899 2.3 0.0 a = str(image)
  72. 1239 1271 926552 729.0 11.9 self.inDataMap[11:(11+length)] = str(a)
  73. 1240 # write first byte to indicate we finished writing the data
  74. 1241 1271 4109 3.2 0.1 self.inDataMap[0] = (chr(240))
  75. 1242 1271 1999 1.6 0.0 counter += 1
  76. 1243 1271 3248890 2556.2 41.8 xbmc.sleep(sleeptime)
  77. 1244 1271 6305 5.0 0.1 if simul: self.inDataMap[0] = chr(248)
  78. 1245 elif cgcs == xbmc.CAPTURE_STATE_WORKING:
  79. 1246 missed_capture_count += 1
  80. 1247 continue
  81. 1248 elif cgcs == xbmc.CAPTURE_STATE_FAILED:
  82. 1249 info('XBMCDirect Capture stopped after %s frames' % counter)
  83. 1250 if (self.runtype == XBMCD.TYPE_THREADED and self.killswitch is False) or self.runtype == XBMCD.TYPE_STANDARD:
  84. 1251 notification(__language__(32035)) # @[XBMCDirect Fail]
  85. 1252 break
  86. 1253 del capture
  87. 1254 info('XBMCDirect capture terminated')
  88. 1255 if missed_capture_count != 0:
  89. 1256 info('XBMCDirect reports missing %s captures due to RenderCapture timeouts' % missed_capture_count)
  90. 1257 self.inDataMap.close()
  91. 1258 self.inDataMap = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement