Handle the case when the monitor doesn't exist more gracefully and not crash. Fixes #3316

This commit is contained in:
Isaac Connor 2021-07-08 10:06:33 -04:00
parent b0cf3a4732
commit 1766bbdfcd
1 changed files with 18 additions and 5 deletions

View File

@ -254,14 +254,27 @@ Image *StreamBase::prepareImage(Image *image) {
} // end Image *StreamBase::prepareImage(Image *image)
bool StreamBase::sendTextFrame(const char *frame_text) {
int width = 640;
int height = 480;
int colours = ZM_COLOUR_RGB32;
int subpixelorder = ZM_SUBPIX_ORDER_RGBA;
int labelsize = 2;
if (monitor) {
width = monitor->Width();
height = monitor->Height();
colours = monitor->Colours();
subpixelorder = monitor->SubpixelOrder();
labelsize = monitor->LabelSize();
}
Debug(2, "Sending %dx%d * %d text frame '%s'",
monitor->Width(), monitor->Height(), scale, frame_text);
width, height, scale, frame_text);
Image image(monitor->Width(), monitor->Height(), monitor->Colours(), monitor->SubpixelOrder());
Image image(width, height, colours, subpixelorder);
image.Clear();
image.Annotate(frame_text, image.centreCoord(frame_text, monitor->LabelSize()), monitor->LabelSize());
image.Annotate(frame_text, image.centreCoord(frame_text, labelsize), labelsize);
if ( scale != 100 ) {
if (scale != 100) {
image.Scale(scale);
}
if ( type == STREAM_MPEG ) {
@ -279,7 +292,7 @@ bool StreamBase::sendTextFrame(const char *frame_text) {
fputs("--" BOUNDARY "\r\nContent-Type: image/jpeg\r\n", stdout);
fprintf(stdout, "Content-Length: %d\r\n\r\n", n_bytes);
if ( fwrite(buffer, n_bytes, 1, stdout) != 1 ) {
if (fwrite(buffer, n_bytes, 1, stdout) != 1) {
Error("Unable to send stream text frame: %s", strerror(errno));
return false;
}