Eliot Miranda uploaded a new version of EToys to project The Trunk:
http://source.squeak.org/trunk/EToys-eem.403.mcz==================== Summary ====================
Name: EToys-eem.403
Author: eem
Time: 7 October 2020, 4:11:55.903414 pm
UUID: 4ebcb883-1cbd-42fa-a1a4-bf2299298c33
Ancestors: EToys-eem.402
Add interrupt-driven frame capture to the CameraInterface (as yet unused in the WebCamMorph).
=============== Diff against EToys-eem.402 ===============
Item was added:
+ ----- Method: CameraInterface class>>camera:setSemaphore: (in category 'camera ops') -----
+ camera: cameraNum setSemaphore: semaphoreIndex
+ "Set an external semaphore index through which to signal that a frame is available.
+ Fail if cameraNum does not reference an open camera, or if the platform does not
+ support interrupt-driven frame receipt."
+ <primitive: 'primSetCameraSemaphore' module: 'CameraPlugin' error: ec>
+ ^self primitiveFailed!
Item was added:
+ ----- Method: CameraInterface class>>interruptDrivenVideoTest: (in category 'test') -----
+ interruptDrivenVideoTest: camNum
+ "A quick test of video input. Displays video on the screen until the mouse is pressed.
+ Answer nil if the interrupt-driven interface is unavailable."
+ "self interruptDrivenVideoTest: 1"
+ "[self interruptDrivenVideoTest: 2"
+ "[self interruptDrivenVideoTest: 2] fork.
+ self interruptDrivenVideoTest: 1"
+
+ | semaphore height |
+ height := 16.
+ 1 to: camNum - 1 do:
+ [:camIndex| "N.B. the of an unopened camera is 0@0"
+ height := height + (CameraInterface frameExtent: camIndex) y + 16].
+ (CameraInterface cameraIsOpen: camNum) ifFalse:
+ [(CameraInterface openCamera: camNum width: 320 height: 240) ifNil:
+ [self inform: 'no camera'.
+ ^nil]].
+ semaphore := Semaphore new.
+ [CameraInterface camera: camNum setSemaphore: (Smalltalk registerExternalObject: semaphore)]
+ on: Error
+ do: [:err|
+ Smalltalk unregisterExternalObject: semaphore.
+ self inform: 'interrupt-driven camera interface unavailable: ', err messageText.
+ ^nil].
+ [| f n startTime frameCount msecs fps |
+ (self frameExtent: camNum) x = 0 ifTrue: [self inform: 'no camera'. ^nil].
+ f := Form extent: (CameraInterface frameExtent: camNum) depth: 32.
+ frameCount := 0.
+ startTime := nil.
+ [semaphore wait.
+ Sensor anyButtonPressed] whileFalse:
+ [n := CameraInterface getFrameForCamera: camNum into: f bits.
+ n > 0 ifTrue:
+ [startTime ifNil: [startTime := Time millisecondClockValue].
+ frameCount := frameCount + 1.
+ f displayAt: 16 @ height]].
+ msecs := Time millisecondClockValue - startTime.
+ fps := (frameCount * 1000) // msecs.
+ ^frameCount printString, ' frames at ', fps printString, ' frames/sec']
+ ensure:
+ [CameraInterface closeCamera: camNum.
+ Smalltalk unregisterExternalObject: semaphore.
+ Sensor waitNoButton]!