How to get (void*) data into a Python array

Trevor Bentley <[email protected]>
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <[email protected]>
Hello,

I am working on a small Python script to grab a single frame from the
iSight camera using PyObjC.  I want to import the frame into a python
numpy array for manipulation, and I want to write it exclusively in
Python.  I have fairly limited experience in Python and Objective-C, and
no prior experience with PyObjC.

I have made some progress, and currently it is able to find the camera,
open it, and capture a frame.  The frame data is (theoretically)
available in my QTCaptureDecompressedVideoOutput delegate's callback
function:

- (void)captureOutput:(QTCaptureOutput *)captureOutput
didOutputVideoFrame:(CVImageBufferRef)videoFrame
withSampleBuffer:(QTSampleBuffer *)sampleBuffer
fromConnection:(QTCaptureConnection *)connection

So I added "pdb.set_trace()" at the beginning of the callback, and am
trying to figure out how to get the raw bytes available in Python.

The closest I have come is examining sampleBuffer:
--------------------------------------------------
(Pdb) sampleBuffer
<QTSampleBuffer: 0x1044b42d0>
(Pdb) sampleBuffer.numberOfSamples()
1
(Pdb) sampleBuffer.lengthForAllSamples()
2624000
(Pdb) sampleBuffer.bytesForAllSamples()
4674363392L
--------------------------------------------------

However, this is where I'm confused.  bytesForAllSamples() returns a
(void*), which is literally, of course, a long integer.  I have no idea
how to get at those bytes, since I'm assuming I can't just dereference
an ObjC pointer somehow in Python.  I was hoping an NSData object
initialized with the address would work, but it does not:

--------------------------------------------------
(Pdb)
NSData.dataWithBytes_length_(sampleBuffer.bytesForAllSamples(),2624000)
*** TypeError: converting to a C array
--------------------------------------------------

Any guidance in getting past this point would be much appreciated!  And
thanks to everyone responsible for PyObjC, it is an excellent resource.

-Trevor

------------------------------------------------------------------------------
The modern datacenter depends on network connectivity to access resources
and provide services. The best practices for maximizing a physical server's
connectivity to a physical network are well understood - see how these
rules translate into the virtual world? 
http://p.sf.net/sfu/oracle-sfdevnlfb
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.