Changes to not just die if not connected to monitor. Instead wait around spitting out an error image.

This commit is contained in:
Isaac Connor 2020-09-02 16:36:05 -04:00
parent 43e1ac2ad4
commit ea3fcb16a6
2 changed files with 25 additions and 5 deletions

View File

@ -37,9 +37,17 @@ StreamBase::~StreamBase() {
}
#endif
closeComms();
if ( monitor ) {
delete monitor;
monitor = NULL;
}
}
bool StreamBase::loadMonitor(int monitor_id) {
bool StreamBase::loadMonitor(int p_monitor_id) {
monitor_id = p_monitor_id;
if ( monitor )
delete monitor;
if ( !(monitor = Monitor::Load(monitor_id, false, Monitor::QUERY)) ) {
Error("Unable to load monitor id %d for streaming", monitor_id);
return false;
@ -59,7 +67,15 @@ bool StreamBase::loadMonitor(int monitor_id) {
bool StreamBase::checkInitialised() {
if ( !monitor ) {
Fatal("Cannot stream, not initialised");
Error("Cannot stream, not initialised");
return false;
}
if ( monitor->GetFunction() == Monitor::NONE ) {
Error("Monitor %d has function NONE. Will not be able to connect to it.", monitor_id);
return false;
}
if ( !monitor->ShmValid() ) {
Error("Monitor shm is not connected");
return false;
}
return true;
@ -248,7 +264,7 @@ bool StreamBase::sendTextFrame(const char *frame_text) {
fprintf(stdout, "Content-type: %s\r\n\r\n", vid_stream->MimeType());
vid_stream->OpenStream();
}
/* double pts = */ vid_stream->EncodeFrame( image.Buffer(), image.Size() );
/* double pts = */ vid_stream->EncodeFrame(image.Buffer(), image.Size());
} else
#endif // HAVE_LIBAVCODEC
{
@ -257,13 +273,15 @@ bool StreamBase::sendTextFrame(const char *frame_text) {
image.EncodeJpeg(buffer, &n_bytes);
fputs("--ZoneMinderFrame\r\nContent-Type: image/jpeg\r\n", stdout);
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 ) {
Error("Unable to send stream text frame: %s", strerror(errno));
return false;
} else {
Debug(1, "Sent %d bytes", n_bytes);
}
fputs("\r\n\r\n",stdout);
fputs("\r\n\r\n", stdout);
fflush(stdout);
}
last_frame_sent = TV_2_FLOAT(now);

View File

@ -61,6 +61,7 @@ protected:
typedef enum { CMD_NONE=0, CMD_PAUSE, CMD_PLAY, CMD_STOP, CMD_FASTFWD, CMD_SLOWFWD, CMD_SLOWREV, CMD_FASTREV, CMD_ZOOMIN, CMD_ZOOMOUT, CMD_PAN, CMD_SCALE, CMD_PREV, CMD_NEXT, CMD_SEEK, CMD_VARPLAY, CMD_GET_IMAGE, CMD_QUIT, CMD_QUERY=99 } MsgCommand;
protected:
int monitor_id;
Monitor *monitor;
StreamType type;
@ -114,6 +115,7 @@ protected:
public:
StreamBase():
monitor_id(0),
monitor(0),
type(DEFAULT_TYPE),
format(""),