in Shared/HoloLensForCV/SensorFrameStreamingServer.cpp [79:192]
void SensorFrameStreamingServer::Send(
SensorFrame^ sensorFrame)
{
if (nullptr == _socket)
{
#if DBG_ENABLE_VERBOSE_LOGGING
dbg::trace(
L"SensorFrameStreamingServer::Consume: image dropped -- no connection!");
#endif /* DBG_ENABLE_VERBOSE_LOGGING */
return;
}
if (_writeInProgress)
{
#if DBG_ENABLE_INFORMATIONAL_LOGGING
dbg::trace(
L"SensorFrameStreamingServer::Send: image dropped -- previous send operation is in progress!");
#endif /* DBG_ENABLE_INFORMATIONAL_LOGGING */
return;
}
Windows::Graphics::Imaging::SoftwareBitmap^ bitmap;
Windows::Graphics::Imaging::BitmapBuffer^ bitmapBuffer;
Windows::Foundation::IMemoryBufferReference^ bitmapBufferReference;
int32_t imageWidth = 0;
int32_t imageHeight = 0;
int32_t pixelStride = 1;
int32_t rowStride = 0;
Platform::Array<uint8_t>^ imageBufferAsPlatformArray;
int32_t imageBufferSize = 0;
{
#if DBG_ENABLE_INFORMATIONAL_LOGGING
dbg::TimerGuard timerGuard(
L"SensorFrameStreamingServer::Send: buffer preparation",
4.0 /* minimum_time_elapsed_in_milliseconds */);
#endif /* DBG_ENABLE_INFORMATIONAL_LOGGING */
bitmap =
sensorFrame->SoftwareBitmap;
imageWidth = bitmap->PixelWidth;
imageHeight = bitmap->PixelHeight;
bitmapBuffer =
bitmap->LockBuffer(
Windows::Graphics::Imaging::BitmapBufferAccessMode::Read);
bitmapBufferReference =
bitmapBuffer->CreateReference();
uint32_t bitmapBufferDataSize = 0;
uint8_t* bitmapBufferData =
Io::GetTypedPointerToMemoryBuffer<uint8_t>(
bitmapBufferReference,
bitmapBufferDataSize);
switch (bitmap->BitmapPixelFormat)
{
case Windows::Graphics::Imaging::BitmapPixelFormat::Bgra8:
pixelStride = 4;
break;
case Windows::Graphics::Imaging::BitmapPixelFormat::Gray16:
pixelStride = 2;
break;
case Windows::Graphics::Imaging::BitmapPixelFormat::Gray8:
pixelStride = 1;
break;
default:
#if DBG_ENABLE_INFORMATIONAL_LOGGING
dbg::trace(
L"SensorFrameStreamingServer::Send: unrecognized bitmap pixel format, assuming 1 byte per pixel");
#endif /* DBG_ENABLE_INFORMATIONAL_LOGGING */
break;
}
rowStride =
imageWidth * pixelStride;
imageBufferSize =
imageHeight * rowStride;
ASSERT(
imageBufferSize == (int32_t)bitmapBufferDataSize);
imageBufferAsPlatformArray =
ref new Platform::Array<uint8_t>(
bitmapBufferData,
imageBufferSize);
}
SensorFrameStreamHeader^ header =
ref new SensorFrameStreamHeader();
header->FrameType = sensorFrame->FrameType;
header->Timestamp = sensorFrame->Timestamp.UniversalTime;
header->ImageWidth = imageWidth;
header->ImageHeight = imageHeight;
header->PixelStride = pixelStride;
header->RowStride = rowStride;
SendImage(
header,
imageBufferAsPlatformArray);
}