summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/inputstreamer.cc40
-rw-r--r--src/v4l.cc25
2 files changed, 35 insertions, 30 deletions
diff --git a/src/inputstreamer.cc b/src/inputstreamer.cc
index 04edc7b..deffa71 100644
--- a/src/inputstreamer.cc
+++ b/src/inputstreamer.cc
@@ -67,6 +67,11 @@ InputStreamer::InputStreamer(QHostAddress addr, quint16 port)
running = true;
start();
}
+int interrupted;
+
+void handle_int(int num) {
+ interrupted = 1;
+}
InputStreamer::~InputStreamer()
{
@@ -93,28 +98,33 @@ void InputStreamer::run()
char packet[64*1024];
while(running) {
- /*
- if(!socket.hasPendingDatagrams()) {
- qApp->processEvents();
- usleep(2000); // sleep 2ms
- continue;
- }
- qint64 packetsize =
- socket.readDatagram(packet, (quint64)sizeof(packet), 0, 0);
- if(packetsize < 1) {
- continue;
+ ssize_t packetsize;
+
+ {
+ int fd = sock;
+ fd_set fds;
+ struct timeval timeout;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 1000;
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ if(select(fd + 1, &fds, NULL, NULL, &timeout) > 0) {
+ packetsize = recv(sock, (char*)packet, sizeof(packet), 0);
+ } else {
+ // timeout
+ continue;
+ }
}
- */
- ssize_t packetsize = recv(sock, (char*)packet, sizeof(packet), 0);
if(packetsize == -1) {
perror("recv()");
- usleep(100); // sleep 2ms
+ usleep(1000);
continue;
}
if(packetsize == 0) {
- usleep(100); // sleep 2ms
+ usleep(1000);
continue;
}
@@ -149,6 +159,8 @@ void InputStreamer::run()
}
}
+ printf("done\n");
+
status = lrtp_destroy_profile(lrtp, CSRC_V);
if(status != LRTP_OK) printf("O:lrtp_destroy_profile (v) err: %d\n", status);
diff --git a/src/v4l.cc b/src/v4l.cc
index 55b0397..246026f 100644
--- a/src/v4l.cc
+++ b/src/v4l.cc
@@ -54,6 +54,7 @@ extern "C" {
static bool isYUYV = false;
static V4L *v4l = NULL;
+static volatile bool running = true;
#define CLEAR(x) memset(&(x), 0, sizeof(x))
@@ -174,20 +175,10 @@ static void process_image(const void *p, int size)
if(isYUYV) {
toJpeg(70, (unsigned char*)p, 640, 480, (char**)&img, (size_t*)&img_size);
}
+
if(v4l) v4l->processImage(img, img_size);
- /*
- if (out_buf)
- fwrite(p, size, 1, stdout);
-
- fflush(stderr);
- fprintf(stderr, "[%d]", size);
- fflush(stdout);
-
- FILE *fp = fopen("out.jpg", "w");
- fwrite(p, size, 1, fp);
- fclose(fp);
- exit(0);
- */
+
+ //TODO: if(img != p) free(img);
}
static int read_frame(void)
@@ -281,7 +272,7 @@ static int read_frame(void)
return 1;
}
-static bool running = true;
+
static void mainloop(void)
{
unsigned int count;
@@ -799,16 +790,18 @@ V4L::V4L(QString device)
v4l = this; // Set global V4L object pointer.
+ running = true;
start();
}
V4L::~V4L()
{
+ running = false;
+ wait();
+
free(dev_name);
v4l = NULL; // Unset global V4L object pointer.
-
- // TODO: Stop thread.... somehow.
}
void V4L::run()