8 #include "PlusConfigure.h" 9 #include "vtkPlusNvidiaDVPVideoSourceWin32.h" 13 #include <vtkObjectFactory.h> 31 , EnableGPUCPUCopy(false)
32 , VideoSize( { 0, 0, 1 })
35 this->StartThreadForInternalUpdates =
true;
36 this->AcquisitionRate = 30;
57 LOG_TRACE(
"vtkPlusPhilips3DProbeVideoSource::InternalConnect");
62 LOG_ERROR(
"Unable to retrieve NvGPU.");
86 LOG_TRACE(
"vtkPlusNvidiaDVPVideoSource::InternalDisconnect");
115 LOG_ERROR(
"Unable to capture frame from SDI capture.");
126 LOG_TRACE(
"vtkPlusNvidiaDVPVideoSource::ReadConfiguration");
137 LOG_ERROR(
"Unable to obtain system GPU topology.");
143 if (numCaptureDevices <= 0)
145 LOG_ERROR(
"Unable to obtain system Capture topology.");
164 if (deviceConfig->GetAttribute(
"Framelock") != NULL)
167 if (STRCASECMP(deviceConfig->GetAttribute(
"Framelock"),
"TRUE") == 0)
174 if (deviceConfig->GetAttribute(
"Blocking") != NULL)
177 if (STRCASECMP(deviceConfig->GetAttribute(
"Blocking"),
"TRUE") == 0)
184 if (deviceConfig->GetAttribute(
"FSAA") != NULL)
190 if (deviceConfig->GetAttribute(
"Field") != NULL)
193 if (STRCASECMP(deviceConfig->GetAttribute(
"Field"),
"TRUE") == 0)
200 if (deviceConfig->GetAttribute(
"ConversionScaleFactor") != NULL)
203 if (deviceConfig->GetVectorAttribute(
"ConversionScaleFactor", 3, tmpValue) == 3)
212 if (deviceConfig->GetAttribute(
"ConversionOffsetVector") != NULL)
215 if (deviceConfig->GetVectorAttribute(
"ConversionOffsetVector", 3, tmpValue) == 3)
224 if (deviceConfig->GetAttribute(
"ConversionMatrix") != NULL)
227 if (deviceConfig->GetVectorAttribute(
"ConversionMatrix", 9, tmpValue) == 9)
244 if (deviceConfig->GetAttribute(
"GammaCorrection") != NULL)
247 if (deviceConfig->GetVectorAttribute(
"GammaCorrection", 3, tmpValue) == 3)
257 LOG_ERROR(
"Illegal gamma values specified.");
264 if (deviceConfig->GetScalarAttribute(
"FlipQueueLength", flipQueueLength) != NULL)
269 LOG_ERROR(
"Illegal number of flip queue buffers specified.");
276 if (deviceConfig->GetScalarAttribute(
"GPU", gpu) != NULL)
281 LOG_ERROR(
"Illegal GPU specified.");
287 std::string videoFormat;
288 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(VideoFormat, videoFormat, deviceConfig);
289 if (videoFormat ==
"487i5994_259")
294 else if (videoFormat ==
"576i5000_259")
299 else if (videoFormat ==
"720p2398_296")
304 else if (videoFormat ==
"720p2400_296")
309 else if (videoFormat ==
"720p2500_296")
314 else if (videoFormat ==
"720p2997_296")
319 else if (videoFormat ==
"720p3000_296")
324 else if (videoFormat ==
"720p5000_296")
329 else if (videoFormat ==
"720p5994_296")
334 else if (videoFormat ==
"720p6000_296")
339 else if (videoFormat ==
"1035i5994_260")
344 else if (videoFormat ==
"1035i6000_260")
349 else if (videoFormat ==
"1080i4796_274")
354 else if (videoFormat ==
"1080i4800_274")
359 else if (videoFormat ==
"1080i5000_295")
364 else if (videoFormat ==
"1080i5000_274")
369 else if (videoFormat ==
"1080i5994_274")
374 else if (videoFormat ==
"1080i6000_274")
379 else if (videoFormat ==
"1080psf23976_274")
384 else if (videoFormat ==
"1080psf2398_274")
389 else if (videoFormat ==
"1080psf2400_274")
394 else if (videoFormat ==
"1080psf2500_274")
399 else if (videoFormat ==
"1080psf2997_274")
404 else if (videoFormat ==
"1080psf3000_274")
409 else if (videoFormat ==
"1080p23976_274")
414 else if (videoFormat ==
"1080p2400_274")
419 else if (videoFormat ==
"1080p2500_274")
424 else if (videoFormat ==
"1080p2997_274")
429 else if (videoFormat ==
"1080p3000_274")
434 else if (videoFormat ==
"2048i4796_372")
439 else if (videoFormat ==
"2048i4800_372")
444 else if (videoFormat ==
"2048i5000_372")
449 else if (videoFormat ==
"2048i5994_372")
454 else if (videoFormat ==
"2048i6000_372")
459 else if (videoFormat ==
"2048p2398_372")
464 else if (videoFormat ==
"2048p2400_372")
469 else if (videoFormat ==
"2048p2500_372")
474 else if (videoFormat ==
"2048p2997_372")
479 else if (videoFormat ==
"2048p3000_372")
486 LOG_WARNING(
"Invalid video format in configuration file.");
491 std::string dataFormat;
492 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(DataFormat, dataFormat, deviceConfig);
493 if (dataFormat ==
"r8g8b8_to_ycrcb444")
497 else if (dataFormat ==
"r8g8b8a8_to_ycrcba4444")
501 else if (dataFormat ==
"r8g8b8_to_ycrcb422")
505 else if (dataFormat ==
"r8g8b8a8_to_ycrcb4224")
509 else if (dataFormat ==
"r8g8b8_to_rgb444")
513 else if (dataFormat ==
"r8g8b8a8_to_rgb4444")
517 else if (dataFormat ==
"y10cr10cb10_to_ycrcb444")
521 else if (dataFormat ==
"y10cr8cb8_to_ycrcb444")
525 else if (dataFormat ==
"y10cr8cb8a10_to_ycrcb4444")
529 else if (dataFormat ==
"dual_r8g8b8_to_dual_ycrcb422")
533 else if (dataFormat ==
"dual_y8cr8cb8_to_dual_ycrcb422")
537 else if (dataFormat ==
"r10g10b10_to_ycrcb422")
541 else if (dataFormat ==
"r10g10b10_to_ycrcb444")
545 else if (dataFormat ==
"y12cr12cb12_to_ycrcb444")
549 else if (dataFormat ==
"y12cr12cb12_to_ycrcb422")
553 else if (dataFormat ==
"y10cr10cb10_to_ycrcb422")
557 else if (dataFormat ==
"y8cr8cb8_to_ycrcb422")
561 else if (dataFormat ==
"y10cr8cb8a10_to_ycrcba4224")
565 else if (dataFormat ==
"r10g10b10_to_rgb444")
569 else if (dataFormat ==
"r12g12b12_to_rgb444")
579 if (deviceConfig->GetAttribute(
"SyncSource") != NULL)
581 std::string syncSource(deviceConfig->GetAttribute(
"SyncSource"));
582 if (syncSource ==
"bi")
588 else if (syncSource ==
"tri")
594 else if (syncSource ==
"auto")
600 else if (syncSource ==
"sdi")
612 if (deviceConfig->GetAttribute(
"Alpha") != NULL)
615 if (STRCASECMP(deviceConfig->GetAttribute(
"Alpha"),
"TRUE") == 0)
622 if (deviceConfig->GetAttribute(
"cr") != NULL)
626 if (deviceConfig->GetVectorAttribute(
"cr", 4, tmpValue) == 4)
635 if (deviceConfig->GetAttribute(
"cb") != NULL)
639 if (deviceConfig->GetVectorAttribute(
"cb", 4, tmpValue) == 4)
648 if (deviceConfig->GetAttribute(
"y") != NULL)
652 if (deviceConfig->GetVectorAttribute(
"y", 4, tmpValue) == 4)
663 if (deviceConfig->GetScalarAttribute(
"HorizontalDelay", horizontalDelay) != NULL)
668 if (deviceConfig->GetScalarAttribute(
"VerticalDelay", verticalDelay) != NULL)
675 if (deviceConfig->GetScalarAttribute(
"CaptureGPU", captureGPU) != NULL)
682 if (deviceConfig->GetScalarAttribute(
"CaptureDevice", captureDevice) != NULL)
688 std::string sampling;
689 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(Sampling, sampling, deviceConfig);
690 if (sampling ==
"422")
694 else if (sampling ==
"444")
698 else if (sampling ==
"4224")
702 else if (sampling ==
"4444")
708 int bitsPerComponent;
709 if (deviceConfig->GetScalarAttribute(
"BitsPerComponent", bitsPerComponent) != NULL)
716 case NVVIOCOMPONENTSAMPLING_422:
731 case NVVIOCOMPONENTSAMPLING_4224:
746 case NVVIOCOMPONENTSAMPLING_444:
762 case NVVIOCOMPONENTSAMPLING_4444:
781 LOG_ERROR(
"Selected Capture Device is out of range.");
786 LOG_ERROR(
"Selected Capture GPU is out of range.");
796 LOG_TRACE(
"vtkPlusNvidiaDVPVideoSource::WriteConfiguration");
809 LOG_ERROR(
"Incorrect configuration. GPU/CPU copy and OutputChannel configuration are incompatible.");
816 LOG_ERROR(
"Unable to find video source. Device needs a video buffer to put new frames into when copying frames from the GPU.");
836 LOG_ERROR(
"Error setting up video capture.");
849 LOG_ERROR(
"Error starting video capture.");
882 GLuint gpuVideoSlot = 1;
888 int videoBufferPitch = 0;
896 assert(glGetError() == GL_NO_ERROR);
898 glBufferData(GL_VIDEO_BUFFER_NV, videoBufferPitch * VideoHeight, NULL, GL_STREAM_COPY);
899 assert(glGetError() == GL_NO_ERROR);
913 LOG_WARNING(
"Unable to create GPU affinity DC.");
916 PIXELFORMATDESCRIPTOR pfd =
918 sizeof(PIXELFORMATDESCRIPTOR),
937 GLuint pf = ChoosePixelFormat(
HandleDC, &pfd);
952 LOG_ERROR(
"Could not load the required OpenGL extensions.");
956 glClearColor(0.0, 0.0, 0.0, 0.0);
959 glDisable(GL_DEPTH_TEST);
961 glDisable(GL_TEXTURE_1D);
962 glDisable(GL_TEXTURE_2D);
971 static GLuint64EXT captureTime;
973 static GLuint prevSequenceNum = 0;
975 static int numFails = 0;
976 static int numTries = 0;
982 if (sequenceNum - prevSequenceNum > 1)
984 LOG_WARNING(
"glVideoCaptureNV: Dropped " << sequenceNum - prevSequenceNum <<
" frames.");
986 prevSequenceNum = sequenceNum;
993 case GL_PARTIAL_SUCCESS_NV:
994 LOG_WARNING(
"glVideoCaptureNV: GL_PARTIAL_SUCCESS_NV.");
998 LOG_ERROR(
"glVideoCaptureNV: GL_FAILURE_NV - Video capture failed.");
1002 LOG_ERROR(
"glVideoCaptureNV: Unknown return value.");
1020 return GL_FAILURE_NV;
1028 return GL_FAILURE_NV;
1051 wglMakeCurrent(NULL, NULL);
vtkPlusDataSource * OutputDataSource
Data source for CPU output (if enabled)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
bool EnableGPUCPUCopy
Enable copying of frame data from GPU to CPU for broadcasting.
virtual CNvGpu * GetGpu(int index)
NVVIODATAFORMAT dataFormat
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
NVVIOSYNCSOURCE syncSource
GLenum Capture(GLuint *sequenceNum, GLuint64EXT *captureTime)
HRESULT UnbindVideoFrameBuffer(unsigned int stream)
HRESULT StartSDIPipeline()
virtual PlusStatus AddItem(vtkImageData *frame, US_IMAGE_ORIENTATION usImageOrientation, US_IMAGE_TYPE imageType, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
HRESULT SetupSDIDevices()
GLuint VideoBufferObject[MAX_VIDEO_STREAMS]
static CNvSDIinTopology & Instance()
virtual PlusStatus InternalDisconnect()
HRESULT BindDevice(GLuint videoSlot, HDC hDC)
CNvSDIin NvSDIin
Capture interface class.
HRESULT SetupDevice(int deviceNumber=0)
HRESULT StopSDIPipeline()
PlusStatus GetFirstVideoSource(vtkPlusDataSource *&anImage)
PFNGLGETBUFFERSUBDATAPROC glGetBufferSubData
bool loadBufferObjectExtension()
virtual PlusStatus Disconnect()
NVVIOCOMPONENTSAMPLING sampling
virtual PlusStatus NotifyConfigured()
Perform any completion tasks once configured.
nvOptions NvOptions
Options to configure capture.
virtual void SetCorrectlyConfigured(bool)
bool loadTimerQueryExtension()
PFNWGLCREATEAFFINITYDCNVPROC wglCreateAffinityDCNV
vtkStandardNewMacro(vtkPlusNvidiaDVPVideoSource)
HRESULT BindVideoFrameBuffer(GLuint videoBuffer, GLint videoBufferFormat, unsigned int stream)
NVVIOCOMPSYNCTYPE syncType
HRESULT Init(nvOptions *options=NULL)
unsigned char * CPUFrame
CPU memory storage of image.
PFNGLBUFFERDATAARBPROC glBufferData
uint64_t FrameNumber
The current frame number.
HGPUNV getAffinityHandle()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
virtual PlusStatus InternalUpdate()
NVVIOSIGNALFORMAT videoFormat
PFNGLDELETEBUFFERSARBPROC glDeleteBuffers
HRESULT CleanupSDIDevices()
virtual ~vtkPlusNvidiaDVPVideoSource()
virtual US_IMAGE_ORIENTATION GetInputImageOrientation()
virtual bool IsTracker() const
Respond to the query if this is a tracker or not.
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)
Read configuration from XML data.
ChannelContainer OutputChannels
unsigned int GetNumStreams()
virtual PlusStatus InternalConnect()
bool loadCaptureVideoExtension()
int GetBufferObjectPitch(unsigned int streamIndex)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
HRESULT SetupSDIinDevices()
HDC HandleDC
Windows device context.
FrameSizeType GetInputFrameSize() const
PFNGLBINDBUFFERARBPROC glBindBuffer
PFNGLGENBUFFERSARBPROC glGenBuffers
static CNvGpuTopology & Instance()
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *config)
Write configuration to XML data.
Class for providing VTK video input interface from an NVidia digital video platform interface.
vtkPlusNvidiaDVPVideoSource()
HGLRC HandleGLRC
Windows GL context.