123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "UVCDeviceManager.h"
- #include "../DataManager/DataManager.h"
- #include "../DataManager/DataPackage.h"
- void UVCManager::init(int nWaitingTime)
- {
- // get device list
- uvc_device_t **deviceList;
- uvc_get_device_list(ctx, &deviceList);
- // get device number
- deviceNum = 0;
- while (deviceList[deviceNum] != NULL)
- {
- deviceNum++;
- }
- std::cout << "Device Number: " << deviceNum << std::endl;
- uvc_device_t **OrderedDeviceList = new uvc_device_t *[deviceNum];
- for (int i = 0; i < deviceNum; i++)
- {
- int minBus = 255;
- int minAddress = 255;
- int minBusIndex = -1;
- int minAddressIndex = -1;
- for (int j = 0; j < deviceNum; j++)
- {
- if (deviceList[j] == nullptr)
- {
- continue;
- }
- int bus = uvc_get_bus_number(deviceList[j]);
- if (bus < minBus)
- {
- minBus = bus;
- minBusIndex = j;
- minAddress = uvc_get_device_address(deviceList[j]);
- minAddressIndex = j;
- }
- else if (bus == minBus && uvc_get_device_address(deviceList[j]) < minAddress)
- {
- minAddress = uvc_get_device_address(deviceList[j]);
- minAddressIndex = j;
- }
- }
- OrderedDeviceList[i] = deviceList[minBusIndex];
- deviceList[minBusIndex] = nullptr;
- }
- // init the Uvc device by deviceNum
- for (int i = 0; i < deviceNum; i++)
- {
- UVCDevice *uvcDevice = new UVCDevice();
- uvcDevice->init(i, ctx, OrderedDeviceList[i]);
- uvcDevice->setCallBack(cbSaveToLocal);
- uvcDeviceList.push_back(uvcDevice);
- int bus = uvc_get_bus_number(OrderedDeviceList[i]);
- int address = uvc_get_device_address(OrderedDeviceList[i]);
- std::cout << "Device " << i << " Bus: " << bus << " Address: " << address << std::endl;
- // init the data manager
- DataManager::getInstance()
- .addDataPipe<DataPackage>("uvc" + std::to_string(i));
- }
- m_GpioExplorer = std::make_shared<GPIOExplorer>("gpiochip0", 16);
- m_GpioExplorer->setWaitingTime(nWaitingTime);
- }
- int UVCManager::deliverFrameInCallBack(uvc_device_handle_t *devh)
- {
- int i = 0;
- std::list<UVCDevice *>::iterator it = uvcDeviceList.begin();
- for (; it != uvcDeviceList.end(); it++, i++)
- {
- if ((*it)->getDevh() == devh)
- {
- return i;
- }
- }
- return -1;
- }
- void UVCManager::startAllStreaming()
- {
- for (auto uvcDevice : uvcDeviceList)
- {
- uvcDevice->startStreaming();
- }
- }
- void UVCManager::stopAllStreaming()
- {
- for (auto uvcDevice : uvcDeviceList)
- {
- uvcDevice->stopStreaming();
- }
- }
|