aboutsummaryrefslogtreecommitdiff
path: root/src/listener.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-10-17 23:04:12 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-10-17 23:04:12 +0300
commit7e64d0c78e8a21f2ede7eab1303758391001c0dc (patch)
treea01e44b12d66de3e4fbc5cf5ab20f439fc8d6fc8 /src/listener.c
parentb1b7c92aa96af5502f276819b628b05d54f4655c (diff)
many changes in progess
Diffstat (limited to 'src/listener.c')
-rw-r--r--src/listener.c56
1 files changed, 22 insertions, 34 deletions
diff --git a/src/listener.c b/src/listener.c
index 7e9a839..135405c 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -2,51 +2,39 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
+#include <pthread.h>
#include "socket.h"
#include "display.h"
#include "audio.h"
#include "typedef.h"
-static int fd;
+char *cam_data;
-void on_recv(char *buf, int numbytes)
+void *display_thread(void *arg)
{
- // read and play audio
- pid_t p = fork();
- if(p < 0) {
- fputs("fork: failed", stderr);
- exit(1);
- } else if(p > 0) {
- write(fd, &(buf[REC_CAP]), numbytes-REC_CAP);
- } else {
- audio_play(buf);
- exit(0);
- }
+ (void)arg;
- // audio_play(buf);
- // write(fd, &(buf[REC_CAP]), numbytes-REC_CAP);
+ int c = 1;
+ char *name = "./display";
+ display(&c, &name);
+ pthread_exit(0);
+}
+void on_recv(char *buf, int numbytes)
+{
+ cam_data = &(buf[REC_CAP]);
+ usleep(100000);
+ // audio_play(buf);
}
-int main(int argc, char **argv)
+int main(void)
{
- int pipefd[2];
- if(pipe2(pipefd, O_NONBLOCK) == -1) {
- fputs("pipe: failed", stderr);
- return 1;
- }
-
- pid_t p = fork();
- if(p < 0) {
- fputs("fork: failed", stderr);
- return 1;
- } else if(p > 0) {
- close(pipefd[0]);
- fd = pipefd[1];
- return listener("4950", &on_recv);
- } else {
- close(pipefd[1]);
- display(&argc, argv, pipefd[0]);
- }
+ // char empty[1024] = {0};
+ // cam_data = empty;
+
+ pthread_t tid;
+ pthread_create(&tid, NULL, display_thread, NULL);
+
+ return listener("4950", &on_recv);
}