VideoInputSenderManager::VideoInputSenderManager(QObject *parent)
	: QObject(parent)
{
	QStringList devs = CameraThread::enumerateDevices();
	foreach(QString dev, devs)
	{
                //qDebug() << "VideoInputSenderManager::ctor: Creating thread for device: "<<dev;
		VideoSender *sender = new VideoSender();
                CameraThread *source = CameraThread::threadForCamera(dev);
                source->setFps(30);
		source->registerConsumer(sender);
		
                // The 'raw frames' mode uses V4L to get the frames instead of LibAV
		// Of course, V4L isn't supported on windows, so we don't enable raw frames on windows.
		// In the future, I suppose I could find code to use the appros Windows API to
		// connect to the capture card - but I just don't have a need for that level of performance
		// on windows right now, so I'll put it off until I need it or someone really wants it.
		// For now, the high-performance capture use is on Linux (for me), so that's where I'll focus. 
		#ifndef Q_OS_WIN
		source->enableRawFrames(true);
		#endif
		
                sender->setVideoSource(source);
                m_videoSenders[dev] = sender;
	}
Example #2
0
void* ConnectToClient(void* cam)
{
    CameraThread* camera = static_cast<CameraThread *>(cam);
    while(camera->Continue())
    {
        cout << "Waiting for new client\n";
        if(!camera->serverSocket->ConnectClient())
            cout << "Could not connect to client\n";
    }
    pthread_exit(NULL);
}
Example #3
0
void* DrawThreadFunction(void* cam)
{
    cout << "\nStarting Draw Function";
    CameraThread* camera = static_cast<CameraThread *>(cam);
    string buffer;

    // FPS Calculation
    struct timeval tim;
    double t, dt;
    int fps;
    gettimeofday(&tim, NULL);
    t = tim.tv_sec + (tim.tv_usec/1000000.0);

    while(camera->Continue())
    {
        buffer.clear();
        while(!camera->display);

        buffer.append("{");
            buffer.append("\"fabric\":");
                buffer.append("[");
                    buffer.append("{");
                        buffer.append("\"id\":101");
                        buffer.append(",");
                        buffer.append("\"x\":");
                            buffer.append(to_string((camera->fabricPosition.x - camera->frameCenter.x)*camera->pixelToRealx));
                        buffer.append(",");
                        buffer.append("\"y\":");
                            buffer.append(to_string((camera->frameSize.height - camera->fabricPosition.y - camera->frameCenter.y)*camera->pixelToRealy));
                        buffer.append(",");
                        buffer.append("\"theta\":");
                            buffer.append(to_string(camera->fabricAngle));
                    buffer.append("}");
                buffer.append("]");
            buffer.append(",");
            buffer.append("\"budger\":[]");
        buffer.append("}\n");

        for(auto client : camera->serverSocket->clients)
            camera->serverSocket->Write(client.first, buffer.c_str(), buffer.size());

        camera->display = false;

        gettimeofday(&tim, NULL);
        dt = tim.tv_sec + (tim.tv_usec/1000000.0) - t;
        gettimeofday(&tim, NULL);
        t = tim.tv_sec + (tim.tv_usec/1000000.0);

        fps = (int)(1/dt);
        cout << "\nComm FPS: " << fps;
    }

    pthread_exit(NULL);
}
Example #4
0
VideoInputSenderManager::VideoInputSenderManager(QObject *parent)
	: QObject(parent)
{
	QStringList devs = CameraThread::enumerateDevices();
	foreach(QString dev, devs)
	{
		VideoSender *sender = new VideoSender();
		CameraThread *source = CameraThread::threadForCamera(dev);
		source->setFps(30);
		source->registerConsumer(sender);
		#ifndef Q_OS_WINDOWS
		source->enableRawFrames(true);
		#endif
		sender->setVideoSource(source);
		
		m_videoSenders[dev] = sender;
	}
Example #5
0
int main(int argc, char const *argv[])
{
    if(argc != 3)
    {
        cout << "Usage: " << argv[0] << " <Camera Number> <Server Port>" << endl;
        exit(0);
    }

    unsigned int cameraNum = atoi(argv[1]);
    int portno = atoi(argv[2]);

    CServerSocket *server = new CServerSocket(portno);
    CameraThread* camera = new CameraThread();
    camera->serverSocket = server;

    if(!camera->Init(cameraNum))
        return 0;

    cout << "Camera Initialized\n";

    if(!camera->SetupVision())
        return 0;

    cout << "Camera Setup Done\n";

    pthread_t camThread;
    pthread_t drawThread;
    pthread_t commThread;

    void* camStatus = 0;
    void* drawStatus = 0;
    void* commStatus = 0;

    pthread_attr_t camAttr;
    pthread_attr_t drawAttr;
    pthread_attr_t commAttr;

    pthread_attr_init(&camAttr);
    pthread_attr_init(&drawAttr);
    pthread_attr_init(&commAttr);

    pthread_attr_setschedpolicy(&camAttr, SCHED_FIFO);
    pthread_attr_setschedpolicy(&drawAttr, SCHED_FIFO);
    pthread_attr_setschedpolicy(&commAttr, SCHED_FIFO);

    struct sched_param camSched;
    struct sched_param drawSched;
    struct sched_param commSched;

    camSched.sched_priority = 1;
    drawSched.sched_priority = 2;
    commSched.sched_priority = 3;
    pthread_attr_setschedparam(&camAttr, &camSched);
    pthread_attr_setschedparam(&drawAttr, &drawSched);
    pthread_attr_setschedparam(&commAttr, &commSched);

    pthread_create(&camThread, &camAttr, CameraThreadFunction, (void*) camera);
    pthread_create(&drawThread, &drawAttr, DrawThreadFunction, (void*) camera);
    pthread_create(&commThread, &commAttr, ConnectToClient, (void*) camera);

    pthread_join(camThread, &camStatus);
    pthread_join(drawThread, &drawStatus);
    pthread_join(commThread, &commStatus);

    delete camera;
    delete server;
    return 0;
}