hi!
My code is based on 09_camera_jpeg_capture.And I use 3 cameras,and each has 30fps.I want to save every image,but i find acquireFrame() not working well,it allway lose some images? Is there any way to fix it?
After 180 seconds,I checked the result,and find some frame not received.
Camera0 e.g,first frameid(image_frame_id) is 1,and my receive index is 1 too.and last frameid(image_frame_id) is 938,but my receive index is 934. so is that means the program lost 938-934=4 images?
bool CaptureConsumerThread::threadExecute() {
IStream *iStream = interface_cast(m_stream);
IFrameConsumer *iFrameConsumer = interface_cast(m_consumer);
// Wait until the producer has connected to the stream.
CONSUMER_PRINT("Waiting until producer is connected...\n");
if (iStream->waitUntilConnected() != STATUS_OK)
ORIGINATE_ERROR("Stream failed to connect.");
CONSUMER_PRINT("Producer has connected; continuing.%d,\n",m_cameraIndex);
int current_camera_recv_index = 0;
while (true) {
// Acquire a frame.
UniqueObj <Frame> frame(iFrameConsumer->acquireFrame());
IFrame *iFrame = interface_cast<IFrame>(frame);
if (!iFrame)
break;
// Get the IImageNativeBuffer extension interface.
NV::IImageNativeBuffer *iNativeBuffer =
interface_cast<NV::IImageNativeBuffer>(iFrame->getImage());
if (!iNativeBuffer)
ORIGINATE_ERROR("IImageNativeBuffer not supported by Image.");
// If we don't already have a buffer, create one from this image.
// Otherwise, just blit to our buffer.
if (m_dmabuf == -1) {
printf("error 0\r\n");
m_dmabuf = iNativeBuffer->createNvBuffer(CAPTURE_SIZE,
NvBufferColorFormat_YUV420,
NvBufferLayout_BlockLinear);
if (m_dmabuf == -1)
CONSUMER_PRINT("\tFailed to create NvBuffer\n");
} else if (iNativeBuffer->copyToNvBuffer(m_dmabuf) != STATUS_OK) {
printf("error 1\r\n");
ORIGINATE_ERROR("Failed to copy frame to NvBuffer.");
}
unsigned long size = JPEG_BUFFER_SIZE;
unsigned char *buffer = m_OutputBuffer;
m_JpegEncoder->encodeFromFd(m_dmabuf, JCS_YCbCr, &buffer, size);
current_camera_recv_index ++;
printf("camera_index: %d, image_frame_id: %d,current_camera_index: %d,thread: %lu\r\n",
m_cameraIndex,(unsigned int)iFrame->getNumber(),current_camera_recv_index,all_camera_recv_image_count,pthread_self());
}
CONSUMER_PRINT("Done.\n");
requestShutdown();
return true;
}
-------------------------------------output results-----------------------------------
camera_index: 1, image_frame_id: 1,current_camera_index: 1,thread: 545758192016
camera_index: 0, image_frame_id: 1,current_camera_index: 1,thread: 545774104976
camera_index: 1, image_frame_id: 3,current_camera_index: 2,thread: 545758192016
camera_index: 0, image_frame_id: 3,current_camera_index: 2,thread: 545774104976
camera_index: 1, image_frame_id: 4,current_camera_index: 3,thread: 545758192016
camera_index: 0, image_frame_id: 4,current_camera_index: 3,thread: 545774104976
camera_index: 2, image_frame_id: 1,current_camera_index: 1,thread: 545742279056
camera_index: 2, image_frame_id: 3,current_camera_index: 2,thread: 545742279056
camera_index: 1, image_frame_id: 5,current_camera_index: 4,thread: 545758192016
camera_index: 0, image_frame_id: 5,current_camera_index: 4,thread: 545774104976
camera_index: 2, image_frame_id: 4,current_camera_index: 3,thread: 545742279056
…
…
…
camera_index: 0, image_frame_id: 938,current_camera_index: 934,thread: 545774104976
camera_index: 1, image_frame_id: 941,current_camera_index: 935,thread: 545758192016
camera_index: 2, image_frame_id: 940,current_camera_index: 939,thread: 545742279056