Commit 553308b9 authored by Timothy Stack's avatar Timothy Stack

Only record mezzanine frames when a client is connected or debug > 1.

parent 25dbae3a
...@@ -104,6 +104,8 @@ static mezz_mmap_t *recorded_frames[RECORD_FRAME_COUNT]; ...@@ -104,6 +104,8 @@ static mezz_mmap_t *recorded_frames[RECORD_FRAME_COUNT];
static char *recordpath = "/var/log/mezzframe"; static char *recordpath = "/var/log/mezzframe";
static int maxfd;
static XDR xdr; static XDR xdr;
static char packet_buffer[2048]; static char packet_buffer[2048];
static char *cursor; static char *cursor;
...@@ -213,9 +215,11 @@ static void record_frame(mezz_mmap_t *mm) ...@@ -213,9 +215,11 @@ static void record_frame(mezz_mmap_t *mm)
assert(mm != NULL); assert(mm != NULL);
frame_number = (mezz_frame_count - 1) % RECORD_FRAME_COUNT; if (mm->calibrate != 0) {
memcpy(recorded_frames[frame_number], mm, sizeof(mezz_mmap_t)); frame_number = (mezz_frame_count - 1) % RECORD_FRAME_COUNT;
recorded_frames[frame_number]->calibrate = -1; memcpy(recorded_frames[frame_number], mm, sizeof(mezz_mmap_t));
recorded_frames[frame_number]->calibrate = -1;
}
} }
static void sighup(int sig) static void sighup(int sig)
...@@ -482,8 +486,8 @@ int main(int argc, char *argv[]) ...@@ -482,8 +486,8 @@ int main(int argc, char *argv[])
exit(2); exit(2);
} }
mezzmap = mezz_mmap(); mezzmap = mezz_mmap();
// We want mezzanine to copy the image data over. if (debug > 1)
mezzmap->calibrate += 1; mezzmap->calibrate += 1;
} }
#else #else
{ {
...@@ -557,6 +561,9 @@ int main(int argc, char *argv[]) ...@@ -557,6 +561,9 @@ int main(int argc, char *argv[])
FD_SET(serv_sock, &readfds); FD_SET(serv_sock, &readfds);
if (serv_sock > maxfd)
maxfd = serv_sock;
for (lpc = 0; lpc < RECORD_FRAME_COUNT; lpc++) { for (lpc = 0; lpc < RECORD_FRAME_COUNT; lpc++) {
if ((recorded_frames[lpc] = malloc(sizeof(mezz_mmap_t))) == NULL) { if ((recorded_frames[lpc] = malloc(sizeof(mezz_mmap_t))) == NULL) {
fatal("cannot allocate space for recorded frames\n"); fatal("cannot allocate space for recorded frames\n");
...@@ -575,7 +582,7 @@ int main(int argc, char *argv[]) ...@@ -575,7 +582,7 @@ int main(int argc, char *argv[])
* become read-ready. Technically, we could miss a signal and a * become read-ready. Technically, we could miss a signal and a
* frame, but I'm too lazy to fix it at the moment. * frame, but I'm too lazy to fix it at the moment.
*/ */
rc = select(FD_SETSIZE, &rreadyfds, NULL, NULL, NULL); rc = select(maxfd + 1, &rreadyfds, NULL, NULL, NULL);
if (rc > 0) { if (rc > 0) {
int lpc; int lpc;
...@@ -606,6 +613,8 @@ int main(int argc, char *argv[]) ...@@ -606,6 +613,8 @@ int main(int argc, char *argv[])
fd); fd);
} }
// We want mezzanine to copy the image data over.
mezzmap->calibrate += 1;
if (setsockopt(fd, if (setsockopt(fd,
IPPROTO_TCP, IPPROTO_TCP,
TCP_NODELAY, TCP_NODELAY,
...@@ -616,6 +625,9 @@ int main(int argc, char *argv[]) ...@@ -616,6 +625,9 @@ int main(int argc, char *argv[])
FD_SET(fd, &readfds); FD_SET(fd, &readfds);
FD_SET(fd, &clientfds); FD_SET(fd, &clientfds);
if (fd > maxfd)
maxfd = fd;
fd = -1; fd = -1;
} }
...@@ -657,6 +669,7 @@ int main(int argc, char *argv[]) ...@@ -657,6 +669,7 @@ int main(int argc, char *argv[])
} }
if (!good) { if (!good) {
mezzmap->calibrate -= 1;
close(lpc); close(lpc);
FD_CLR(lpc, &readfds); FD_CLR(lpc, &readfds);
FD_CLR(lpc, &clientfds); FD_CLR(lpc, &clientfds);
...@@ -691,7 +704,7 @@ int main(int argc, char *argv[]) ...@@ -691,7 +704,7 @@ int main(int argc, char *argv[])
else { else {
int lpc; int lpc;
for (lpc = 0; lpc < FD_SETSIZE; lpc++) { for (lpc = 0; lpc <= maxfd; lpc++) {
if (FD_ISSET(lpc, &clientfds)) { if (FD_ISSET(lpc, &clientfds)) {
write(lpc, packet_buffer, rc); write(lpc, packet_buffer, rc);
} }
...@@ -744,7 +757,8 @@ int main(int argc, char *argv[]) ...@@ -744,7 +757,8 @@ int main(int argc, char *argv[])
} }
#if defined(HAVE_MEZZANINE) #if defined(HAVE_MEZZANINE)
mezzmap->calibrate -= 1; if (debug > 1)
mezzmap->calibrate -= 1;
mezz_term(0); mezz_term(0);
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment