bool v4l2::qbuf_mmap(int index, __u32 buftype) { v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = buftype; buf.memory = V4L2_MEMORY_MMAP; buf.index = index; return qbuf(buf); }
bool v4l2::qbuf_user_out(void *ptr, int length) { v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; buf.memory = V4L2_MEMORY_USERPTR; buf.m.userptr = (unsigned long)ptr; buf.length = length; return qbuf(buf); }
bool v4l2::qbuf_mmap_out(int index, int bytesused) { v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; buf.memory = V4L2_MEMORY_MMAP; buf.index = index; buf.bytesused = bytesused; return qbuf(buf); }
bool v4l2::qbuf_user(int index, __u32 buftype, void *ptr, int length) { v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = buftype; buf.memory = V4L2_MEMORY_USERPTR; buf.m.userptr = (unsigned long)ptr; buf.length = length; buf.index = index; return qbuf(buf); }
bool v4l2::qbuf_mmap(int index, __u32 buftype) { v4l2_plane planes[VIDEO_MAX_PLANES]; v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = buftype; buf.memory = V4L2_MEMORY_MMAP; buf.index = index; buf.length = 2; buf.m.planes = planes; return qbuf(buf); }
int V4L2VideoNode::putFrame(unsigned int index) { LOG2("@%s", __FUNCTION__); int ret(0); if (index > mBufferPool.size()) { ALOGE("%s Invalid index %d pool size %d", __FUNCTION__, index, mBufferPool.size()); return -1; } struct v4l2_buffer_info vbuf = mBufferPool.editItemAt(index); ret = qbuf(&vbuf); return ret; }
int V4L2VideoNode::putFrame(unsigned int index) { LOG2("@%s", __FUNCTION__); int ret(0); if (index > mBufferPool.size()) { LOGE("%s Invalid index %d pool size %d", __FUNCTION__, index, mBufferPool.size()); return -1; } struct v4l2_buffer_info vbuf = mBufferPool.editItemAt(index); LOG2("userptr = %p, reserved2=0x%x", (void*)vbuf.vbuffer.m.userptr, vbuf.vbuffer.reserved2); ret = qbuf(&vbuf); return ret; }
int V4L2VideoNode::activateBufferPool() { LOG1("@%s: device = %s", __FUNCTION__, mName.string()); int ret = 0; if (mState != DEVICE_POPULATED) return -1; for (size_t i = 0; i < mBufferPool.size(); i++) { ret = qbuf(&mBufferPool.editItemAt(i)); if (ret < 0) { ALOGE("Failed to queue buffer %d", i); break; } } return ret; }
bool v4l2::qbuf_user(int index, __u32 buftype, void *ptr[], size_t length[]) { v4l2_plane planes[VIDEO_MAX_PLANES]; v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = buftype; buf.memory = V4L2_MEMORY_USERPTR; if (V4L2_TYPE_IS_MULTIPLANAR(buftype)) { buf.length = 2; buf.m.planes = planes; planes[0].length = length[0]; planes[0].m.userptr = (unsigned long)ptr[0]; planes[1].length = length[1]; planes[1].m.userptr = (unsigned long)ptr[1]; } else { buf.m.userptr = (unsigned long)ptr[0]; buf.length = length[0]; } buf.index = index; return qbuf(buf); }
// Reads a server message from the socket. The protocol consists of // two parts. First the message length is read as unsigned // integer, after that the actual message as 8 bit character string. void GpsClient::readServerMsg() { static const char* method = "GpsClient::readServerMsg():"; uint msgLen = 0; uint done = clientData.readMsg( &msgLen, sizeof(msgLen) ); if( done < sizeof(msgLen) ) { qWarning() << method << "MSG length" << done << "too short"; setShutdownFlag(true); return; // Error occurred } if( msgLen > 512 ) { // such messages length are not defined. we will ignore that. qWarning() << method << "message" << msgLen << "too large, ignoring it!"; setShutdownFlag(true); return; // Error occurred } char *buf = new char[msgLen+1]; memset( buf, 0, msgLen+1 ); done = clientData.readMsg( buf, msgLen ); if( done <= 0 ) { qWarning() << method << "MSG data" << done << "too short"; delete [] buf; setShutdownFlag(true); return; // Error occurred } #ifdef DEBUG qDebug() << method << "Received Message:" << buf; #endif // Split the received message into its two parts. Space is used as separator // between the command word and the optional content of the message. QString qbuf( buf ); delete[] buf; buf = 0; int spaceIdx = qbuf.indexOf( QChar(' ') ); QStringList args; if( spaceIdx == -1 || qbuf.size() == spaceIdx ) { args.append(qbuf); args.append(""); } else { args.append(qbuf.left(spaceIdx)); args.append(qbuf.mid(spaceIdx+1)); } // look, what the server is requesting if( MSG_MAGIC == args[0] ) { // check protocol versions, reply with pos or neg if( MSG_PROTOCOL != args[1] ) { qCritical() << method << "Client-Server protocol mismatch!" << "Client:" << MSG_PROTOCOL << "Server:" << args[1]; writeServerMsg( MSG_NEG ); setShutdownFlag(true); return; } writeServerMsg( MSG_POS ); } else if( MSG_OPEN == args[0] ) { QStringList devArgs = args[1].split(QChar(' ')); if( devArgs.size() == 2 ) { // Initialization of GPS device is requested. The message // consists of two parts separated by spaces. // 1) device name // 2) io speed bool res = openGps( devArgs[0].toLatin1().data(), devArgs[1].toUInt() ); if( res ) { writeServerMsg( MSG_POS ); } else { writeServerMsg( MSG_NEG ); } } } else if( MSG_CLOSE == args[0] ) { // Close GPS device is requested closeGps(); writeServerMsg( MSG_POS ); } else if( MSG_FGPS_ON == args[0] ) { // Switches on GPS data forwarding to the server. forwardGpsData = true; writeServerMsg( MSG_POS ); } else if( MSG_FGPS_OFF == args[0] ) { // Switches off GPS data forwarding to the server. forwardGpsData = false; writeServerMsg( MSG_POS ); } else if( MSG_SM == args[0] && args.count() == 2 ) { // Sent message to the GPS device int res = writeGpsData( args[1].toLatin1().data() ); if( res == -1 ) { writeServerMsg( MSG_NEG ); } else { writeServerMsg( MSG_POS ); } } else if( MSG_GPS_KEYS == args[0] && args.count() == 2 ) { // Well known GPS message keys are received. QStringList keys = args[1].split( ",", QString::SkipEmptyParts ); // Clear old content. gpsMessageFilter.clear(); for( int i = 0; i < keys.size(); i++ ) { gpsMessageFilter.insert( keys.at(i) ); } // qDebug() << "GPS-Keys:" << gpsMessageFilter; writeServerMsg( MSG_POS ); } else if( MSG_SHD == args[0] ) { // Shutdown is requested by the server. This message will not be // acknowledged! setShutdownFlag(true); } #ifdef FLARM else if( MSG_FLARM_FLIGHT_LIST_REQ == args[0] ) { // Flarm flight list is requested writeServerMsg( MSG_POS ); getFlarmFlightList(); } else if( MSG_FLARM_FLIGHT_DOWNLOAD == args[0] && args.count() == 2 ) { // Flarm flight download is requested writeServerMsg( MSG_POS ); getFlarmIgcFiles(args[1]); } else if( MSG_FLARM_RESET == args[0] ) { // Flarm reset is requested writeServerMsg( MSG_POS ); flarmReset(); } #endif else { qWarning() << method << "Unknown message received:" << qbuf; writeServerMsg( MSG_NEG ); } return; }
void Videostreaming::capFrame() { __u32 buftype = m_buftype; v4l2_plane planes[VIDEO_MAX_PLANES]; v4l2_buffer buf; unsigned char *tempSrcBuffer = NULL, *tempDestBuffer = NULL, *copyDestBuffer = NULL; unsigned char *tempCu130DestBuffer = NULL, *tempCu130SrcBuffer = NULL; unsigned char *tempCu40DestBuffer = NULL, *irBuffer = NULL; unsigned char *tempLogtechSrcBuffer = NULL, *tempLogtechDestBuffer = NULL; unsigned char *displaybuf = NULL; unsigned short int *tempCu40SrcBuffer = NULL; //Modified by Nithyesh //Previously it was int err = 0, x, y; int err = 0; __u32 x, y; bool again, v4l2convert = false; memset(planes, 0, sizeof(planes)); buf.length = VIDEO_MAX_PLANES; buf.m.planes = planes; if (!dqbuf_mmap(buf, buftype, again)) { closeDevice(); unsigned char *m_data=NULL; QImage tempImage(m_data,320,240,QImage::Format_RGB888); qImage = QPixmap::fromImage(tempImage); update(); emit deviceUnplugged("Disconnected","Device Not Found"); emit logCriticalHandle("Device disconnected"); return; } if (again) { return; } if (buf.flags & V4L2_BUF_FLAG_ERROR) { qbuf(buf); return; } #if 0 switch(m_capSrcFormat.fmt.pix.pixelformat) { case V4L2_PIX_FMT_YUYV: { if((width*height*2) == buf.bytesused){ validFrame = true; } } break; case V4L2_PIX_FMT_SGRBG8:{ // if bayer - 8 bit camera // { if ((width*height) == buf.bytesused) validFrame = true; // } // if bayer - 8 bit + pad camera // { if ((width*height*2) == buf.bytesused) validFrame = true; // } } break; case V4L2_PIX_FMT_MJPEG:{ validFrame = true; break; } default: // To do: for other color spaces break; } if (validFrame != true){ qbuf(buf); qDebug()<<"validFrame != true"; // return; } #endif if (camDeviceName == "e-con's CX3 RDK with M\nT9P031" || camDeviceName == "See3CAM_12CUNIR" || camDeviceName == "See3CAM_CU51") { tempSrcBuffer = (unsigned char *)malloc(width * height * 2); tempDestBuffer = (unsigned char *)malloc(width * height << 1); copyDestBuffer = tempDestBuffer; memcpy(tempSrcBuffer, m_buffers[buf.index].start[0], buf.bytesused); for(__u32 l=0; l<(width*height*2); l=l+2) /* Y16 to YUYV conversion */ { *tempDestBuffer++ = (((tempSrcBuffer[l] & 0xF0) >> 4) | (tempSrcBuffer[l+1] & 0x0F) << 4); *tempDestBuffer++ = 0x80; } m_capSrcFormat.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; err = v4lconvert_convert(m_convertData, &m_capSrcFormat, &m_capDestFormat, (unsigned char *)copyDestBuffer, buf.bytesused, m_capImage->bits(), m_capDestFormat.fmt.pix.sizeimage); v4l2convert = true; }else if (camDeviceName == "See3CAM_CU40") {