void MainWindow::createUI() { tabs = new QTabWidget(this); sis3150usbUI = new Sis3150usbUI(this->sis3150); connect(sis3150usbUI,SIGNAL(deviceOpened()),this,SLOT(connectDevicesTo3150())); sis3350UI = new Sis3350UI(this->sis); tabs->addTab(sis3150usbUI,tr("sis3150")); tabs->addTab(sis3350UI, tr("sis3350")); this->setCentralWidget(tabs); }
/** * @brief Opens the video device and starts streaming. * @note Callers must own the biglock. * @return True if success, false otherwise. */ bool CameraSource::openDevice() { qDebug() << "Opening device " << deviceName; if (device) { device->open(); return true; } // We need to create a new CameraDevice AVCodec* codec; device = CameraDevice::open(deviceName, mode); if (!device) { qWarning() << "Failed to open device!"; return false; } // We need to open the device as many time as we already have subscribers, // otherwise the device could get closed while we still have subscribers for (int i = 0; i < subscriptions; ++i) device->open(); // Find the first video stream for (unsigned i = 0; i < device->context->nb_streams; ++i) { if (device->context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { videoStreamIndex = i; break; } } if (videoStreamIndex == -1) { qWarning() << "Video stream not found"; return false; } // Get a pointer to the codec context for the video stream cctxOrig = device->context->streams[videoStreamIndex]->codec; codec = avcodec_find_decoder(cctxOrig->codec_id); if (!codec) { qWarning() << "Codec not found"; return false; } // Copy context, since we apparently aren't allowed to use the original cctx = avcodec_alloc_context3(codec); if (avcodec_copy_context(cctx, cctxOrig) != 0) { qWarning() << "Can't copy context"; return false; } cctx->refcounted_frames = 1; // Open codec if (avcodec_open2(cctx, codec, nullptr) < 0) { qWarning() << "Can't open codec"; avcodec_free_context(&cctx); return false; } if (streamFuture.isRunning()) qDebug() << "The stream thread is already running! Keeping the current one open."; else streamFuture = QtConcurrent::run(std::bind(&CameraSource::stream, this)); // Synchronize with our stream thread while (!streamFuture.isRunning()) QThread::yieldCurrentThread(); emit deviceOpened(); return true; }