ImageWindow::ImageWindow(AVData *avData, bool filtered, bool showName, bool showDate, bool showTime, QColor textColor, QWidget *parent) : QLabel(parent) { m_avData = avData; m_filtered = filtered; m_showName = showName; m_showDate = showDate; m_showTime = showTime; m_textColor = textColor; m_selected = false; m_idle = true; m_lastFrame = SyntroClock(); m_displayDate = QDate::currentDate(); m_displayTime = QTime::currentTime(); setAlignment(Qt::AlignCenter); setMinimumWidth(120); setMinimumHeight(90); setMaximumWidth(640); setMaximumHeight(480); if (m_avData) { if (m_filtered) m_name = m_avData->filteredName(); else m_name = m_avData->name(); m_timer = startTimer(30); } }
void ViewSingleCamera::timerEvent(QTimerEvent *) { if (m_avSource && m_lastFrame < m_avSource->lastUpdate()) { newImage(m_avSource->image()); } else if (SyntroUtils::syntroTimerExpired(SyntroClock(), m_lastFrame, SYNTROVIEW_CAMERA_DEADTIME)) { ui.cameraView->setText("No Image"); } }
void ViewSingleCamera::newImage(QImage image) { m_lastFrame = SyntroClock(); if (image.width() == 0) return; else ui.cameraView->setPixmap(QPixmap::fromImage(image.scaled(size(), Qt::KeepAspectRatio))); update(); }
void ImageWindow::timerEvent(QTimerEvent *) { if (m_avData && m_lastFrame < m_avData->lastUpdate()) { if (m_filtered) newImage(m_avData->filteredImage(), m_avData->imageTimestamp()); else newImage(m_avData->image(), m_avData->imageTimestamp()); } else if (SyntroUtils::syntroTimerExpired(SyntroClock(), m_lastFrame, SPACESVIEW_CAMERA_DEADTIME)) { m_idle = true; update(); } }
void ImageWindow::newImage(QImage image, qint64 timestamp) { m_lastFrame = SyntroClock(); if (image.width() == 0) return; m_idle = false; m_image = image; QPixmap pixmap = QPixmap::fromImage(image.scaled(size(), Qt::KeepAspectRatio)); setPixmap(pixmap); QDateTime dt = QDateTime::fromMSecsSinceEpoch(timestamp); m_displayDate = dt.date(); m_displayTime = dt.time(); update(); }
bool DirectoryManager::DMFindService(SYNTRO_UID *sourceUID, SYNTRO_SERVICE_LOOKUP *serviceLookup) { QString componentName; QString serviceName; QString regionName; int componentIndex; int servicePort; int serviceIndex; DM_CONNECTEDCOMPONENT *connectedComponent; DM_COMPONENT *component; DM_SERVICE *service; QMutexLocker locker(&m_lock); if (!SyntroUtils::crackServicePath(serviceLookup->servicePath, regionName, componentName, serviceName)) { serviceLookup->response = SERVICE_LOOKUP_FAIL; TRACE1("Path %s is invalid", serviceLookup->servicePath); return false; } if (serviceLookup->response == SERVICE_LOOKUP_SUCCEED) { // this is a refresh - check all important fields for validity componentIndex = SyntroUtils::convertUC2ToInt(serviceLookup->componentIndex); servicePort = SyntroUtils::convertUC2ToInt(serviceLookup->remotePort); if ((componentIndex < 0) || (componentIndex >= SYNTRO_MAX_CONNECTEDCOMPONENTS)) { TRACE2("Lookup refresh with incorrect CompIndex %d for service %s", componentIndex, serviceLookup->servicePath); goto fullLookup; } connectedComponent = m_directory + componentIndex; component = connectedComponent->componentDE; while (component != NULL) { if ((componentName.length() > 0) && (strcmp(qPrintable(componentName), component->appName) != 0)) { component = component->next; continue; // require a specific component but not this one } // Need to check the service entry information if (serviceLookup->serviceType == SERVICETYPE_MULTICAST) { service = component->services; // need to match against multicastMap index in this case for (serviceIndex = 0; serviceIndex < component->serviceCount; serviceIndex++, service++) { if (service->serviceType != SERVICETYPE_MULTICAST) continue; if (service->multicastMap == NULL) continue; // should not happen but just in case if (service->multicastMap->index == servicePort) break; } if (serviceIndex == component->serviceCount) { component = component->next; continue; // can't be this component then } } else { if ((servicePort < 0) || (servicePort >= component->serviceCount)) { // not in correct range component = component->next; continue; // can't be this component as port outof range } service = component->services + servicePort; if (service->serviceType != SERVICETYPE_E2E) { component = component->next; continue; // can't be this component as wrong type } } if (component->sequenceID != SyntroUtils::convertUC4ToInt(serviceLookup->ID)) { component = component->next; continue; } if (strcmp(service->serviceName, qPrintable(serviceName)) != 0) { component = component->next; continue; } if (!SyntroUtils::compareUID(&(component->componentUID), &(serviceLookup->lookupUID))) { component = component->next; continue; } if ((service->serviceType == SERVICETYPE_MULTICAST) && (service->multicastMap != NULL)) service->multicastMap->lastLookupRefresh = SyntroClock(); TRACE3("Expedited lookup from component %s to source %s port %d", qPrintable(SyntroUtils::displayUID(sourceUID)), qPrintable(SyntroUtils::displayUID(&component->componentUID)), SyntroUtils::convertUC2ToInt(serviceLookup->localPort)); return true; // all good! } } // Jump to here if refresh lookup failed for some reason fullLookup: connectedComponent = m_directory; for (componentIndex = 0; componentIndex < SYNTRO_MAX_CONNECTEDCOMPONENTS; componentIndex++, connectedComponent++) { component = connectedComponent->componentDE; while (component != NULL) { if ((componentName.length() > 0) && (strcmp(qPrintable(componentName), component->appName) != 0)) { component = component->next; continue; // require a specific component but not this one } service = component->services; for (servicePort = 0; servicePort < component->serviceCount; servicePort++, service++) { if (serviceLookup->serviceType != service->serviceType) continue; if (strcmp(service->serviceName, qPrintable(serviceName)) != 0) continue; // found it - but it could be a registration request or removal if (serviceLookup->response == SERVICE_LOOKUP_REMOVE) { // this is a removal request m_server->m_multicastManager.MMDeleteRegistered(sourceUID, SyntroUtils::convertUC2ToUInt(serviceLookup->localPort)); TRACE3("Removed reg from component %s to source %s port %d", qPrintable(SyntroUtils::displayUID(sourceUID)), qPrintable(SyntroUtils::displayUID(&component->componentUID)), SyntroUtils::convertUC2ToInt(serviceLookup->localPort)); return true; } memcpy(&(serviceLookup->lookupUID), &(component->componentUID), sizeof(SYNTRO_UID)); SyntroUtils::convertIntToUC4(component->sequenceID, serviceLookup->ID); if (serviceLookup->serviceType == SERVICETYPE_MULTICAST) SyntroUtils::convertIntToUC2(service->multicastMap->index, serviceLookup->remotePort); else SyntroUtils::convertIntToUC2(service->port, serviceLookup->remotePort); SyntroUtils::convertIntToUC2(componentIndex, serviceLookup->componentIndex); if (serviceLookup->serviceType == SERVICETYPE_MULTICAST) { // must add this to the registered components list if (m_server->m_multicastManager.MMCheckRegistered(service->multicastMap, sourceUID, SyntroUtils::convertUC2ToInt(serviceLookup->localPort))) { // already there - just a refresh TRACE3("Refreshed reg from component %s to source %s port %d", qPrintable(SyntroUtils::displayUID(sourceUID)), qPrintable(SyntroUtils::displayUID(&component->componentUID)), SyntroUtils::convertUC2ToInt(serviceLookup->localPort)); serviceLookup->response = SERVICE_LOOKUP_SUCCEED; return true; } // Must add as this is a new one m_server->m_multicastManager.MMAddRegistered(service->multicastMap, sourceUID, SyntroUtils::convertUC2ToInt(serviceLookup->localPort)); logDebug(QString("Added reg request from component %1 to source %2 port %3") .arg(SyntroUtils::displayUID(sourceUID)) .arg(SyntroUtils::displayUID(&component->componentUID)) .arg(SyntroUtils::convertUC2ToInt(serviceLookup->localPort))); serviceLookup->response = SERVICE_LOOKUP_SUCCEED; return true; } else { TRACE3("Refreshed E2E lookup from component %s to source %s port %d", qPrintable(SyntroUtils::displayUID(sourceUID)), qPrintable(SyntroUtils::displayUID(&component->componentUID)), SyntroUtils::convertUC2ToInt(serviceLookup->localPort)); serviceLookup->response = SERVICE_LOOKUP_SUCCEED; return true; } } component = component->next; } } // not found serviceLookup->response = SERVICE_LOOKUP_FAIL; TRACE1("Lookup for %s failed", serviceLookup->servicePath); return false; }
void CamClient::sendPrerollMJPPCM(bool highRate) { PREROLL *videoPreroll = NULL; PREROLL *audioPreroll = NULL; int videoSize = 0; int audioSize = 0; if (highRate) { if (!m_videoPrerollQueue.empty()) { videoPreroll = m_videoPrerollQueue.dequeue(); videoSize = videoPreroll->data.size(); m_lastFrameTime = QDateTime::currentMSecsSinceEpoch(); } if (!m_audioPrerollQueue.empty()) { audioPreroll = m_audioPrerollQueue.dequeue(); audioSize = audioPreroll->data.size(); } if ((videoPreroll != NULL) || (audioPreroll != NULL)) { SYNTRO_EHEAD *multiCast = clientBuildMessage(m_avmuxPortHighRate, sizeof(SYNTRO_RECORD_AVMUX) + videoSize + audioSize); SYNTRO_RECORD_AVMUX *avHead = (SYNTRO_RECORD_AVMUX *)(multiCast + 1); SyntroUtils::avmuxHeaderInit(avHead, &m_avParams, SYNTRO_RECORDHEADER_PARAM_PREROLL, m_recordIndex++, 0, videoSize, audioSize); if (audioPreroll != NULL) SyntroUtils::convertInt64ToUC8(audioPreroll->timestamp, avHead->recordHeader.timestamp); if (videoPreroll != NULL) SyntroUtils::convertInt64ToUC8(videoPreroll->timestamp, avHead->recordHeader.timestamp); unsigned char *ptr = (unsigned char *)(avHead + 1); if (videoSize > 0) { memcpy(ptr, videoPreroll->data.data(), videoSize); ptr += videoSize; } if (audioSize > 0) memcpy(ptr, audioPreroll->data.data(), audioSize); int length = sizeof(SYNTRO_RECORD_AVMUX) + videoSize + audioSize; clientSendMessage(m_avmuxPortHighRate, multiCast, length, SYNTROLINK_MEDPRI); } } else { if (!m_videoLowRatePrerollQueue.empty()) { videoPreroll = m_videoLowRatePrerollQueue.dequeue(); if (m_lowRateHalfRes) halfRes(videoPreroll->data); videoSize = videoPreroll->data.size(); m_lastLowRateFrameTime = SyntroClock(); } if (!m_audioLowRatePrerollQueue.empty()) { audioPreroll = m_audioLowRatePrerollQueue.dequeue(); audioSize = audioPreroll->data.size(); } if ((videoPreroll != NULL) || (audioPreroll == NULL)) { SYNTRO_EHEAD *multiCast = clientBuildMessage(m_avmuxPortLowRate, sizeof(SYNTRO_RECORD_AVMUX) + videoSize + audioSize); SYNTRO_RECORD_AVMUX *avHead = (SYNTRO_RECORD_AVMUX *)(multiCast + 1); SyntroUtils::avmuxHeaderInit(avHead, &m_avParams, SYNTRO_RECORDHEADER_PARAM_PREROLL, m_recordIndex++, 0, videoSize, audioSize); if (audioPreroll != NULL) SyntroUtils::convertInt64ToUC8(audioPreroll->timestamp, avHead->recordHeader.timestamp); if (videoPreroll != NULL) SyntroUtils::convertInt64ToUC8(videoPreroll->timestamp, avHead->recordHeader.timestamp); unsigned char *ptr = (unsigned char *)(avHead + 1); if (videoSize > 0) { memcpy(ptr, videoPreroll->data.data(), videoSize); ptr += videoSize; } if (audioSize > 0) memcpy(ptr, audioPreroll->data.data(), audioSize); int length = sizeof(SYNTRO_RECORD_AVMUX) + videoSize + audioSize; clientSendMessage(m_avmuxPortLowRate, multiCast, length, SYNTROLINK_MEDPRI); } } if (videoPreroll != NULL) delete videoPreroll; if (audioPreroll != NULL) delete audioPreroll; }