PvUInt32 Source::GetPayloadSize() { PvGenStateStack lState( mDevice->GetGenParameters() ); if ( mMultiSource ) { // Push change on stack, will be reset when lState goes out of scope lState.SetEnumValue( "SourceSelector", mSourceIndex ); } // Get parameters required PvGenInteger *lPayloadSize = mDevice->GetGenParameters()->GetInteger("PayloadSize" ); PvGenInteger *lWidth = mDevice->GetGenParameters()->GetInteger( "Width" ); PvGenInteger *lHeight = mDevice->GetGenParameters()->GetInteger( "Height" ); PvGenEnum *lPixelFormat = mDevice->GetGenParameters()->GetEnum( "PixelFormat" ); // Try getting the payload size from the PayloadSize mandatory parameter PvInt64 lPayloadSizeValue = 0; if ( lPayloadSize != NULL ) { lPayloadSize->GetValue( lPayloadSizeValue ); // Round up to make it mod 32 (works around an issue with some devices) if ((lPayloadSizeValue % 32) != 0) { lPayloadSizeValue = ((lPayloadSizeValue / 32) + 1) * 32; } } // Compute poor man's payload size - for devices not maintaining PayloadSize properly PvInt64 lPoorMansPayloadSize = 0; if ( (lWidth != NULL ) && ( lHeight != NULL ) && ( lPixelFormat != NULL ) ) { PvInt64 lWidthValue, lHeightValue; lWidth->GetValue( lWidthValue ); lHeight->GetValue( lHeightValue ); PvInt64 lPixelFormatValue; lPixelFormat->GetValue( lPixelFormatValue ); PvInt64 lPixelSizeInBits = PvImage::GetPixelSize( (PvPixelType)lPixelFormatValue ); lPoorMansPayloadSize = ( lWidthValue * lHeightValue * lPixelSizeInBits) / 8; } // Take max, let pipeline know what the payload size is PvInt64 lBestPayloadSize = ( lPayloadSizeValue >= lPoorMansPayloadSize ) ? lPayloadSizeValue : lPoorMansPayloadSize; if ( ( lBestPayloadSize > 0 ) && ( lBestPayloadSize < ULONG_MAX ) ) { return static_cast<PvUInt32>( lBestPayloadSize ); } // Could not compute/retrieve payload size... return 0; }
void PvDualSourceSample::Connect( PvDeviceInfo *aDeviceInfo ) { // Just in case we came here still connected... Disconnect(); // Connect to device using device info PvResult lResult = mDevice.Connect( aDeviceInfo ); if ( !lResult.IsOK() ) { PvMessageBox( this, lResult ); return; } Source *lSources[ 2 ] = { mSource1, mSource2 }; // Open channels PvGenEnum *lSourceSelector = mDevice.GetGenParameters()->GetEnum( "SourceSelector" ); PvGenInteger *lSourceStreamChannel = mDevice.GetGenParameters()->GetInteger( "SourceStreamChannel" ); if ( lSourceSelector != NULL ) { for ( PvUInt16 i = 0; i < 2; i++ ) { QString lValue; lValue.sprintf( "Source%d", i + 1 ); lSourceSelector->SetValue( lValue.toAscii().data() ); PvInt64 lChannel = 0; lSourceStreamChannel->GetValue( lChannel ); lResult = lSources[i]->Open( &mDevice, aDeviceInfo->GetIPAddress(), static_cast<PvUInt16>( lChannel ) ); if ( !lResult.IsOK() ) { PvMessageBox( this, lResult ); return; } } } else { // No source selector, if transmitter assume 1 on channel 0 lResult = mSource1->Open( &mDevice, aDeviceInfo->GetIPAddress(), 0 ); if ( !lResult.IsOK() ) { PvMessageBox( this, lResult ); return; } } // Sync the UI with our new status EnableInterface(); }
bool StartSlave() { // Let the user select the device to receive from PvString lDeviceIP; if ( !SelectDevice( lDeviceIP ) ) { return false; } // Create the PvStream object PvStream lStream; // Create the PvPipeline object PvPipeline lPipeline( &lStream ); // Create a PvPipeline event sink (used to trap buffer too small events) PipelineEventSink lPipelineEventSink; lPipeline.RegisterEventSink( &lPipelineEventSink ); // Open stream printf( "Opening stream\n" ); lStream.Open( lDeviceIP, "239.192.1.1", 1042 ); // IMPORTANT: the pipeline needs to be "armed", or started before // we instruct the device to send us images printf( "Starting pipeline\n" ); lPipeline.SetBufferCount( 16 ); lPipeline.Start(); // Get stream parameters/stats PvGenParameterArray *lStreamParams = lStream.GetParameters(); PvGenInteger *lCount = dynamic_cast<PvGenInteger *>( lStreamParams->Get( "ImagesCount" ) ); PvGenFloat *lFrameRate = dynamic_cast<PvGenFloat *>( lStreamParams->Get( "AcquisitionRateAverage" ) ); PvGenFloat *lBandwidth = dynamic_cast<PvGenFloat *>( lStreamParams->Get( "BandwidthAverage" ) ); PvGenBoolean *lIgnoreMissingPackets = dynamic_cast<PvGenBoolean *>( lStreamParams->Get( "IgnoreMissingPackets" ) ); // Disabling resend packets lIgnoreMissingPackets->SetValue( true ); char lDoodle[] = "|\\-|-/"; int lDoodleIndex = 0; PvInt64 lImageCountVal = 0; double lFrameRateVal = 0.0; double lBandwidthVal = 0.0; // Acquire images until the user instructs us to stop printf( "\n<press a key to stop receiving>\n" ); while ( !PvKbHit() ) { // Retrieve next buffer PvBuffer *lBuffer = NULL; PvResult lOperationResult; PvResult lResult = lPipeline.RetrieveNextBuffer( &lBuffer, 1000, &lOperationResult ); if ( lResult.IsOK() ) { if (lOperationResult.IsOK()) { // // We now have a valid buffer. This is where you would typically process the buffer. // ----------------------------------------------------------------------------------------- // ... lCount->GetValue( lImageCountVal ); lFrameRate->GetValue( lFrameRateVal ); lBandwidth->GetValue( lBandwidthVal ); // If the buffer contains an image, display width and height PvUInt32 lWidth = 0, lHeight = 0; if ( lBuffer->GetPayloadType() == PvPayloadTypeImage ) { // Get image specific buffer interface PvImage *lImage = lBuffer->GetImage(); // Read width, height lWidth = lBuffer->GetImage()->GetWidth(); lHeight = lBuffer->GetImage()->GetHeight(); } printf( "%c BlockID: %016llX W: %i H: %i %.01f FPS %.01f Mb/s\r", lDoodle[ lDoodleIndex ], lBuffer->GetBlockID(), lWidth, lHeight, lFrameRateVal, lBandwidthVal / 1000000.0 ); } // We have an image - do some processing (...) and VERY IMPORTANT, // release the buffer back to the pipeline lPipeline.ReleaseBuffer( lBuffer ); } else { // Timeout printf( "%c Timeout\r", lDoodle[ lDoodleIndex ] ); } ++lDoodleIndex %= 6; } PvGetChar(); // Flush key buffer for next stop printf( "\n\n" ); // We stop the pipeline - letting the object lapse out of // scope would have had the destructor do the same, but we do it anyway printf( "Stop pipeline\n" ); lPipeline.Stop(); // Now close the stream. Also optionnal but nice to have printf( "Closing stream\n" ); lStream.Close(); // Unregister pipeline event sink. Optional but nice to have. lPipeline.UnregisterEventSink( &lPipelineEventSink ); return true; }