@@ -31,6 +31,12 @@ std::string intelligenceSourceLabel(const Config& config, const std::string& pee
3131 return config.source .empty () ? peerId : config.source ;
3232}
3333
34+
35+ std::string intelligenceStreamId (const std::string& peerId)
36+ {
37+ return " stream/" + peerId;
38+ }
39+
3440} // namespace
3541
3642
@@ -425,6 +431,12 @@ json::Value MediaSession::intelligenceStatus() const
425431 vision[" sampledFrames" ] = stats.forwarded ;
426432 vision[" sampledDropped" ] = stats.dropped ;
427433 }
434+ if (_visionNormalizer) {
435+ const auto stats = _visionNormalizer->stats ();
436+ vision[" normalizedFrames" ] = stats.emitted ;
437+ vision[" normalizerDropped" ] = stats.dropped ;
438+ vision[" normalizerConverted" ] = stats.converted ;
439+ }
428440 if (_visionQueue) {
429441 vision[" queueDepth" ] = static_cast <std::uint64_t >(_visionQueue->size ());
430442 vision[" queueDropped" ] = static_cast <std::uint64_t >(_visionQueue->dropped ());
@@ -577,6 +589,8 @@ void MediaSession::startStreaming()
577589
578590 if (_visionSampler)
579591 _visionSampler->reset ();
592+ if (_visionNormalizer)
593+ _visionNormalizer->reset ();
580594 if (_visionDetector)
581595 _visionDetector->reset ();
582596 if (_visionArtifacts)
@@ -605,6 +619,7 @@ void MediaSession::setupIntelligence()
605619 return ;
606620
607621 const auto sourceLabel = intelligenceSourceLabel (_config, _peerId);
622+ const auto streamId = intelligenceStreamId (_peerId);
608623
609624 if (_config.vision .enabled ) {
610625 _visionArtifacts = std::make_unique<VisionArtifacts>(
@@ -623,9 +638,18 @@ void MediaSession::setupIntelligence()
623638 .everyNthFrame = _config.vision .everyNthFrame ,
624639 .minIntervalUsec = _config.vision .minIntervalUsec ,
625640 });
641+ _visionNormalizer = std::make_shared<vision::FrameNormalizer>(
642+ vision::FrameNormalizerConfig{
643+ .sourceId = sourceLabel,
644+ .streamId = streamId,
645+ .width = _config.vision .normalize .width ,
646+ .height = _config.vision .normalize .height ,
647+ .pixelFmt = _config.vision .normalize .pixelFmt ,
648+ });
626649 _visionQueue = std::make_shared<vision::DetectionQueue>(_config.vision .queueDepth );
627650 _visionDetector = std::make_unique<vision::MotionDetector>(vision::MotionDetectorConfig{
628651 .source = sourceLabel,
652+ .streamId = streamId,
629653 .detectorName = " motion" ,
630654 .gridWidth = _config.vision .motionGridWidth ,
631655 .gridHeight = _config.vision .motionGridHeight ,
@@ -644,12 +668,16 @@ void MediaSession::setupIntelligence()
644668 _visionSampler->process (packet);
645669 };
646670 _visionSampler->emitter += [this ](IPacket& packet) {
647- auto * frame = dynamic_cast <av::PlanarVideoPacket*>(&packet);
671+ if (_visionNormalizer)
672+ _visionNormalizer->process (packet);
673+ };
674+ _visionNormalizer->emitter += [this ](IPacket& packet) {
675+ auto * frame = dynamic_cast <vision::VisionFramePacket*>(&packet);
648676 if (frame && _visionQueue)
649677 _visionQueue->process (*frame);
650678 };
651679 _visionQueue->emitter += [this ](IPacket& packet) {
652- auto * frame = dynamic_cast <av::PlanarVideoPacket *>(&packet);
680+ auto * frame = dynamic_cast <vision::VisionFramePacket *>(&packet);
653681 if (frame && _visionDetector)
654682 _visionDetector->process (*frame);
655683 };
0 commit comments