winCE6.0 摄像头buffer问题

这里仍存疑问的是buffer的配置和关联问题。申请DMA buffer的物理和逻辑地址是在s3c6410_camera.cpp的CameraInit()中,将它们写入寄存器在CONNECT_STATE run的时候。CS_ALLOCATE和CS_ENQUEUE时,将应用层传入的buffer加入CPinDevice的streamDescriptorList中。中断里,将unmashalled的stream descriptor从list中取出放入队列。从中断的FillBuffer()中取出的图像数据是如何与unmashalled stream descriptor关联的?在读取和显示过程中,是应用层取走一帧,再向驱动注册一个buffer呢,还是有其他办法?应用层可以通过CSPROPERTY_DROPPEDFRAMES_CURRENT 查询丢弃的帧数,从代码上看,removeBufferFromList()时一些指针为空时丢弃一帧,实际上这些丢弃是什么原因造成的?这与m_pStreamDescriptorList[]的存取有关,该数组结构复杂,未及深究。

另外关于buffer,MSDN里有如下说明。先贴着,改天细看。

http://msdn.microsoft.com/en-US/library/ee485464(v=WinEmbedded.60).aspx

Buffers allocated by the client
In the case where the buffers are allocated in system memory, the client passes the list of buffers to the driver while the pin is in stop mode. Placing the pin in stop mode allows the driver to prepare for the direct memory access (DMA) operation to transfer the buffer. The client must initialize the buffers before it gives them to the driver. Once the client is done with the buffer, it must free the memory for the buffer. A client can take one of two different approaches for allocating buffers, depending on the direct memory access (DMA) capabilities of the client.

If the driver's DMA preparation time is slow then the driver needs to know in advance about all of the buffers that it will receive from the client. A driver indicates its support for this buffer allocation model through the CSPROPERTY_BUFFER_CLIENT_LIMITED property.

If the driver's DMA preparation time is fast then the client can allocate, initialize, and release buffers as they are needed. A driver indicates its support for this buffer allocation model through the CSPROPERTY_BUFFER_CLIENT_UNLIMITED property.

The client determines which framing model the driver supports by querying for the CSPROPERTY_CONNECTION_ALLOCATORFRAMING property.

The client negotiates the number of buffers through by calling DeviceIoControl with IOCTL_CS_PROPERTY and specifying the property CSPROPERTY_BUFFER_COUNT.

The client sends the buffers to the driver by using IOCTL_CS_BUFFERS and specifying CS_ENQUEUE. The client releases the processed buffers by using IOCTL_CS_BUFFERS and specifying CS_DEALLOCATE.

Buffer rotation
--------------------------------------------------------------------------------

There are two buffer queues, one for idle buffers and the other for ready buffers. The client manages the queue of idle buffers and the driver manages the queue of ready buffers.

After the driver is initialized, all of the capture buffers are loaded in the client's idle queue. At this point, the driver aware of the buffers, but it has no control over them.To allow the driver to control a buffer, the client has to transfer that buffer from the idle queue to the ready queue.  The client calls IOCTL_CS_PROPERTY with a SET operation on the CS_ENQUEUE property (see BUFFER_COMMANDS).

This IOCTL call takes a pointer to a CS_STREAM_DESCRIPTOR structure and returns a status. Both members of the CS_STREAM_DESCRIPTOR structure must be populated. The CS_STREAM_DESCRIPTOR structure is allocated by the application and must remain valid until the driver returns the buffer to the application.

When the driver receives the IOCTL call, it uses the handle to validate the pointer and then retrieves the shadow copy of the descriptor. It then associates the shadow copy to the descriptor and adds the buffer to the ready queue.

Once the hardware has filled the buffer, the driver returns the buffer to the application using the message queue.   To do so, it sends back the pointer to the stream descriptor passed in through the Read function using the message queue.

你可能感兴趣的:(Stream,buffer,WinCE,Descriptor,Allocation,structure)