void MediaPlayerOCV::OCVCaptureThread::execute() { //m_ocvCamera.m_capture.open( m_ocvCamera.getDeviceId() ); if ( !m_player.m_capture.isOpened() ) { LOG_ERROR( "[MediaPlayerOCV] Player not opened, capture thread will not load" ); return; } // Capture thread loop while( !get_signaled() ) { // New frame flag bool newFrame = false; // If false, opencv controls the playhead. If false, it is controlled by our timer bool setPlayhead = false; // Set the playhead double currentActualFrame = 0.0f; if ( setPlayhead ) { unsigned long millisPlayback = m_timer.getMilliseconds(); double currentFrame = ((double)millisPlayback/1000.0) * m_fps; currentActualFrame = m_player.m_capture.get(CV_CAP_PROP_POS_FRAMES); // Have new frame? if ( currentFrame > currentActualFrame ) { m_player.m_capture.set(CV_CAP_PROP_POS_FRAMES, currentFrame); currentActualFrame = currentFrame; } } // And grab new frame (it will be updated in the next call to getImage() { cv::Mat m_cvCaptureImage; newFrame = m_player.m_capture.read( m_cvCaptureImage ); // Convert from BGR to RGB cv::cvtColor(m_cvCaptureImage, m_localMat, CV_BGR2RGB); // Get the current frame position if ( !setPlayhead ) currentActualFrame = m_player.m_capture.get(CV_CAP_PROP_POS_FRAMES); // Set the new frame to the player if ( newFrame ) { m_player.setNewFrame( currentActualFrame, m_localMat ); // relax the thread relax(20); } } } }
void PVCamera::PVCaptureThread::execute() { unsigned char *cameraBuffer = NULL; unsigned char *cameraWriteBuffer = NULL; // Execute until the thread gets signaled while( !get_signaled() ) { // Get new frame from the camera cameraBuffer = m_PVCamera.m_pvCamera->getFrame(); if ( cameraBuffer ) { // Get buffer to write the image cameraWriteBuffer = m_PVCamera.m_ringBuffer->getNextBufferToWrite(); if ( cameraWriteBuffer ) { // Copy the new frame in the buffer, and notify it memcpy( cameraWriteBuffer, cameraBuffer, m_PVCamera.m_ringBuffer->size() ); m_PVCamera.m_ringBuffer->writeFinished(); } } } }