From c82ff436b86f67756e74d7159e515621cc73a6bc Mon Sep 17 00:00:00 2001 From: alienatedsec <73167064+alienatedsec@users.noreply.github.com> Date: Sun, 20 Aug 2023 16:45:34 +0100 Subject: [PATCH 01/81] [New] Wi-Fi Recovery Changes to be committed: modified: src/static/static/home/yi-hack-v5/script/configure_wifi.sh modified: src/static/static/home/yi-hack-v5/script/system.sh --- .../static/home/yi-hack-v5/script/configure_wifi.sh | 8 ++++++++ src/static/static/home/yi-hack-v5/script/system.sh | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/static/static/home/yi-hack-v5/script/configure_wifi.sh b/src/static/static/home/yi-hack-v5/script/configure_wifi.sh index 29bb7e5..b81dd47 100755 --- a/src/static/static/home/yi-hack-v5/script/configure_wifi.sh +++ b/src/static/static/home/yi-hack-v5/script/configure_wifi.sh @@ -1,10 +1,18 @@ #!/bin/sh +# 0.4.1a + function print_help { echo "configure_wifi.sh" echo "will be used on next boot" } +if [ -f "/tmp/sd/recover/mtdblock2_recover.bin" ]; then + dd if=/tmp/sd/recover/mtdblock2_recover.bin of=/dev/mtdblock2 2>/dev/null + mv /tmp/sd/recover/mtdblock2_recover.bin /tmp/sd/recover/mtdblock2_recover_done.bin + reboot +fi + CFG_FILE=/tmp/configure_wifi.cfg if [ ! -f "$CFG_FILE" ]; then echo "configure_wifi.cfg not found" diff --git a/src/static/static/home/yi-hack-v5/script/system.sh b/src/static/static/home/yi-hack-v5/script/system.sh index 84ad7ab..42a49ff 100755 --- a/src/static/static/home/yi-hack-v5/script/system.sh +++ b/src/static/static/home/yi-hack-v5/script/system.sh @@ -1,6 +1,6 @@ #!/bin/sh -# 0.4.0c +# 0.4.1a CONF_FILE="etc/system.conf" @@ -79,6 +79,11 @@ if [ -f /tmp/sd/recover/configure_wifi.cfg ]; then sh $YI_HACK_PREFIX/script/configure_wifi.sh fi +if [ -f "/tmp/sd/recover/mtdblock2_recover.bin" ]; then + sync + sh $YI_HACK_PREFIX/script/configure_wifi.sh +fi + $YI_HACK_PREFIX/script/check_conf.sh hostname -F $YI_HACK_PREFIX/etc/hostname From 4d70c2bfca77cf917e31af179c75854930fbc794 Mon Sep 17 00:00:00 2001 From: alienatedsec <73167064+alienatedsec@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:17:17 +0100 Subject: [PATCH 02/81] [New] Setting Merge Changes to be committed: modified: src/static/static/home/yi-hack-v5/etc/camera.conf modified: src/static/static/home/yi-hack-v5/etc/system.conf --- src/static/static/home/yi-hack-v5/etc/camera.conf | 12 +++++++++--- src/static/static/home/yi-hack-v5/etc/system.conf | 13 ++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/etc/camera.conf b/src/static/static/home/yi-hack-v5/etc/camera.conf index 8919915..cffe2f8 100644 --- a/src/static/static/home/yi-hack-v5/etc/camera.conf +++ b/src/static/static/home/yi-hack-v5/etc/camera.conf @@ -1,9 +1,15 @@ SWITCH_ON=yes SAVE_VIDEO_ON_MOTION=yes -SENSITIVITY=low -AI_HUMAN_DETECTION=no -SOUND_DETECTION=no +SENSITIVITY=high +AI_HUMAN_DETECTION=yes +SOUND_DETECTION=yes SOUND_SENSITIVITY=80 LED=yes ROTATE=no IR=yes +MOTION_DETECTION=yes +AI_VEHICLE_DETECTION=no +AI_ANIMAL_DETECTION=no +FACE_DETECTION=no +MOTION_TRACKING=no +CRUISE=no diff --git a/src/static/static/home/yi-hack-v5/etc/system.conf b/src/static/static/home/yi-hack-v5/etc/system.conf index aa88ff6..40aeece 100644 --- a/src/static/static/home/yi-hack-v5/etc/system.conf +++ b/src/static/static/home/yi-hack-v5/etc/system.conf @@ -31,7 +31,18 @@ FTP_DIR= FTP_DIR_TREE=no FTP_USERNAME= FTP_PASSWORD= -FTP_FILE_DELETE_AFTER_UPLOAD=yes +FTP_FILE_DELETE_AFTER_UPLOAD=no CHECK_UPDATES=no SSH_PASSWORD= CRONTAB= +RTSP_ALT=no +SPEAKER_AUDIO=yes +SNAPSHOT=yes +SNAPSHOT_VIDEO=no +SNAPSHOT_LOW=no +TIMELAPSE=no +TIMELAPSE_FTP=no +TIMELAPSE_DT=60 +TIMELAPSE_VDT= +TIME_OSD=no +DEBUG_LOG=no From 25db09f312d3f05f5ed64c81ec9f4ad5a5167f64 Mon Sep 17 00:00:00 2001 From: alienatedsec <73167064+alienatedsec@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:34:00 +0100 Subject: [PATCH 03/81] [New] Backup before Wi-Fi recover Changes to be committed: modified: src/static/static/home/yi-hack-v5/script/configure_wifi.sh --- .../static/home/yi-hack-v5/script/configure_wifi.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/script/configure_wifi.sh b/src/static/static/home/yi-hack-v5/script/configure_wifi.sh index b81dd47..b6d3f68 100755 --- a/src/static/static/home/yi-hack-v5/script/configure_wifi.sh +++ b/src/static/static/home/yi-hack-v5/script/configure_wifi.sh @@ -8,9 +8,11 @@ function print_help { } if [ -f "/tmp/sd/recover/mtdblock2_recover.bin" ]; then - dd if=/tmp/sd/recover/mtdblock2_recover.bin of=/dev/mtdblock2 2>/dev/null - mv /tmp/sd/recover/mtdblock2_recover.bin /tmp/sd/recover/mtdblock2_recover_done.bin - reboot + DATE=$(date '+%Y%m%d%H%M%S') + dd if=/dev/mtdblock2 of=/tmp/sd/recover/mtdblock2_prerecover_$DATE.bin 2>/dev/null + dd if=/tmp/sd/recover/mtdblock2_recover.bin of=/dev/mtdblock2 2>/dev/null + mv /tmp/sd/recover/mtdblock2_recover.bin /tmp/sd/recover/mtdblock2_recover_done.bin + reboot fi CFG_FILE=/tmp/configure_wifi.cfg From 9a8871666fe542898cce1cc3c0dd5d5e5dd36e6f Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 11:40:43 +0200 Subject: [PATCH 04/81] Restore feature to edit config files --- src/mqtt-config/mqtt-config/config.c | 84 +++++++++++++++++++++++ src/mqtt-config/mqtt-config/config.h | 1 + src/mqtt-config/mqtt-config/mqtt-config.c | 5 ++ 3 files changed, 90 insertions(+) diff --git a/src/mqtt-config/mqtt-config/config.c b/src/mqtt-config/mqtt-config/config.c index 1e02ee1..66eeb06 100644 --- a/src/mqtt-config/mqtt-config/config.c +++ b/src/mqtt-config/mqtt-config/config.c @@ -2,6 +2,24 @@ void (*fconf_handler)(const char* key, const char* value); +void ucase(char *string) { + // Convert to upper case + char *s = string; + while (*s) { + *s = toupper((unsigned char) *s); + s++; + } +} + +void lcase(char *string) { + // Convert to lower case + char *s = string; + while (*s) { + *s = tolower((unsigned char) *s); + s++; + } +} + void config_set_handler(void (*f)(const char* key, const char* value)) { if (f != NULL) @@ -30,6 +48,72 @@ void config_parse(FILE *fp) } } +void config_replace(char *filename, char *key, char *value) +{ + char buf[MAX_LINE_LENGTH]; + char oldkey[128]; + char oldvalue[128]; + char *line; + int parsed; + FILE *fps, *fpt; + char tmpFile[L_tmpnam + 1]; // Add +1 for the null character. + + lcase(filename); + ucase(key); + + fps = fopen(filename, "r"); + if (fps == NULL) { + printf("Can't open file \"%s\": %s\n", filename, strerror(errno)); + return; + } + + tmpnam(tmpFile); + fpt = fopen(tmpFile, "w"); + if (fpt == NULL) { + printf("Can't open file \"%s\": %s\n", filename, strerror(errno)); + return; + } + + while (!feof(fps)) { + line = fgets(buf, MAX_LINE_LENGTH, fps); + if (line == NULL) break; + if (buf[0] != '#') { + parsed = sscanf(buf, "%[^=] = %s", oldkey, oldvalue); + if((parsed == 2) && (strcasecmp(key, oldkey) == 0)) { + sprintf(buf, "%s=%s\n", key, value); + } + } + fputs(buf, fpt); + } + + fclose(fpt); + fclose(fps); + + // Rename file (rename function is a cross-device link) + fps = fopen(filename, "w"); + if (fps == NULL) { + printf("Can't open file \"%s\": %s\n", filename, strerror(errno)); + return; + } + + fpt = fopen(tmpFile, "r"); + if (fpt == NULL) { + printf("Can't open file \"%s\": %s\n", filename, strerror(errno)); + return; + } + + while (!feof(fpt)) { + line = fgets(buf, MAX_LINE_LENGTH, fpt); + if (line == NULL) break; + fputs(buf, fps); + } + + fclose(fpt); + fclose(fps); + + remove(tmpFile); +} + FILE *open_conf_file(const char* filename) { FILE *fp; diff --git a/src/mqtt-config/mqtt-config/config.h b/src/mqtt-config/mqtt-config/config.h index cc0a9e5..cb070a4 100644 --- a/src/mqtt-config/mqtt-config/config.h +++ b/src/mqtt-config/mqtt-config/config.h @@ -11,5 +11,6 @@ void config_set_handler(void (*f)(const char* key, const char* value)); void config_parse(FILE *fp); +void config_replace(char *filename, char *key, char *value); FILE *open_conf_file(const char* filename); void close_conf_file(FILE *fp); diff --git a/src/mqtt-config/mqtt-config/mqtt-config.c b/src/mqtt-config/mqtt-config/mqtt-config.c index 04e511c..50ebec3 100644 --- a/src/mqtt-config/mqtt-config/mqtt-config.c +++ b/src/mqtt-config/mqtt-config/mqtt-config.c @@ -60,6 +60,7 @@ void disconnect_callback(struct mosquitto *mosq, void *obj, int result) void message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) { char topic_prefix[MAX_LINE_LENGTH], topic[MAX_LINE_LENGTH], file[MAX_KEY_LENGTH], param[MAX_KEY_LENGTH]; + char conf_file[256]; char *slash; bool match = 0; int len; @@ -148,6 +149,10 @@ void message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_ sprintf(cmd_line, "ipc_cmd %s %s", ipc_cmd_param, (char *) message->payload); if (debug) printf("Running system command \"%s\"\n", cmd_line); system(cmd_line); + } else { + sprintf(conf_file, "%s/%s.conf", CONF_FILE_PATH, file); + if (debug) fprintf(stderr, "Updating file \"%s\", parameter \"%s\" with value \"%s\"\n", file, param, (char *) message->payload); + config_replace(conf_file, param, message->payload); } } } else { From 5c0e1f6d39f53edc84593ff1727380437532e75b Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 11:45:19 +0200 Subject: [PATCH 05/81] Add flag to decrease binary size --- src/rRTSPServer/Makefile.rRTSPServer | 2 +- src/rRTSPServer/rRTSPServer.patch | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rRTSPServer/Makefile.rRTSPServer b/src/rRTSPServer/Makefile.rRTSPServer index d45bcf4..9cecfac 100755 --- a/src/rRTSPServer/Makefile.rRTSPServer +++ b/src/rRTSPServer/Makefile.rRTSPServer @@ -8,7 +8,7 @@ CPLUSPLUS_COMPILER = $(CXX) CPLUSPLUS_FLAGS = $(COMPILE_OPTS) -Wall -DBSD=1 $(CPPFLAGS) $(CXXFLAGS) OBJ = o LINK = $(CXX) -o -LINK_OPTS = -L. $(LDFLAGS) +LINK_OPTS = -Wl,--gc-sections -L. $(LDFLAGS) CONSOLE_LINK_OPTS = $(LINK_OPTS) LIBRARY_LINK = $(AR) cr LIBRARY_LINK_OPTS = diff --git a/src/rRTSPServer/rRTSPServer.patch b/src/rRTSPServer/rRTSPServer.patch index 71ba3bb..3c4f799 100755 --- a/src/rRTSPServer/rRTSPServer.patch +++ b/src/rRTSPServer/rRTSPServer.patch @@ -2,7 +2,7 @@ diff -Naur live.ori/config.linux-cross live/config.linux-cross --- live.ori/config.linux-cross 1970-01-01 01:00:00.000000000 +0100 +++ live/config.linux-cross 2021-02-18 10:39:28.103846011 +0100 @@ -0,0 +1,17 @@ -+COMPILE_OPTS = $(INCLUDES) -I. -O1 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DNEWLOCALE_NOT_USED ++COMPILE_OPTS = $(INCLUDES) -I. -O1 -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DNEWLOCALE_NOT_USED +C = c +C_COMPILER = $(CC) +C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS) @@ -11,7 +11,7 @@ diff -Naur live.ori/config.linux-cross live/config.linux-cross +CPLUSPLUS_FLAGS = $(COMPILE_OPTS) -Wall -DBSD=1 $(CPPFLAGS) $(CXXFLAGS) +OBJ = o +LINK = $(CXX) -o -+LINK_OPTS = -L. $(LDFLAGS) ++LINK_OPTS = -Wl,--gc-sections -L. $(LDFLAGS) +CONSOLE_LINK_OPTS = $(LINK_OPTS) +LIBRARY_LINK = $(AR) cr +LIBRARY_LINK_OPTS = From 381b840bf043e8c02331fb0d95ff4e19e679093e Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 11:46:10 +0200 Subject: [PATCH 06/81] Remove old patch --- src/rRTSPServer/init.rRTSPServer | 1 - src/rRTSPServer/rRTSPServer2.patch | 37 ------------------------------ 2 files changed, 38 deletions(-) delete mode 100755 src/rRTSPServer/rRTSPServer2.patch diff --git a/src/rRTSPServer/init.rRTSPServer b/src/rRTSPServer/init.rRTSPServer index 1567571..4751ee1 100755 --- a/src/rRTSPServer/init.rRTSPServer +++ b/src/rRTSPServer/init.rRTSPServer @@ -30,7 +30,6 @@ fi tar zxvf $ARCHIVE patch -p0 < rRTSPServer.patch -patch -p0 < rRTSPServer2.patch cd live || exit 1 diff --git a/src/rRTSPServer/rRTSPServer2.patch b/src/rRTSPServer/rRTSPServer2.patch deleted file mode 100755 index beb531d..0000000 --- a/src/rRTSPServer/rRTSPServer2.patch +++ /dev/null @@ -1,37 +0,0 @@ -diff -Naur include.ori/ADTSAudioFifoServerMediaSubsession.hh include/ADTSAudioFifoServerMediaSubsession.hh ---- include.ori/ADTSAudioFifoServerMediaSubsession.hh 2023-04-15 23:22:04.964120526 +0200 -+++ include/ADTSAudioFifoServerMediaSubsession.hh 2023-04-20 19:18:14.115207781 +0200 -@@ -54,6 +54,8 @@ - private: - char* fAuxSDPLine; - char fDoneFlag; // used when setting up "fAuxSDPLine" -+ unsigned fSamplingFrequency; -+ unsigned fNumChannels; - char fConfigStr[5]; - RTPSink* fDummyRTPSink; // ditto - StreamReplicator *fReplicator; -diff -Naur src.ori/ADTSAudioFifoServerMediaSubsession.cpp src/ADTSAudioFifoServerMediaSubsession.cpp ---- src.ori/ADTSAudioFifoServerMediaSubsession.cpp 2023-04-15 23:22:04.964120526 +0200 -+++ src/ADTSAudioFifoServerMediaSubsession.cpp 2023-04-20 21:46:20.842280500 +0200 -@@ -128,6 +128,8 @@ - Medium::close(resultSource); - return NULL; - } else { -+ fSamplingFrequency = originalSource->samplingFrequency(); -+ fNumChannels = originalSource->numChannels(); - sprintf(fConfigStr, originalSource->configStr()); - if (debug & 4) fprintf(stderr, "createStreamReplica completed successfully\n"); - -@@ -139,10 +141,9 @@ - ::createNewRTPSink(Groupsock* rtpGroupsock, - unsigned char rtpPayloadTypeIfDynamic, - FramedSource* inputSource) { -- ADTSAudioFifoSource* adtsSource = (ADTSAudioFifoSource*)inputSource; - return MPEG4GenericRTPSink::createNew(envir(), rtpGroupsock, - rtpPayloadTypeIfDynamic, -- adtsSource->samplingFrequency(), -+ fSamplingFrequency, - "audio", "AAC-hbr", fConfigStr, -- adtsSource->numChannels()); -+ fNumChannels); - } From f5e97ce30d01cf6b41081c7f2a4ca3741f19bab9 Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 11:46:57 +0200 Subject: [PATCH 07/81] Decrease RTP packet length --- src/rRTSPServer/rRTSPServer.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rRTSPServer/rRTSPServer.patch b/src/rRTSPServer/rRTSPServer.patch index 3c4f799..0ec3ef1 100755 --- a/src/rRTSPServer/rRTSPServer.patch +++ b/src/rRTSPServer/rRTSPServer.patch @@ -2,7 +2,7 @@ diff -Naur live.ori/config.linux-cross live/config.linux-cross --- live.ori/config.linux-cross 1970-01-01 01:00:00.000000000 +0100 +++ live/config.linux-cross 2021-02-18 10:39:28.103846011 +0100 @@ -0,0 +1,17 @@ -+COMPILE_OPTS = $(INCLUDES) -I. -O1 -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DNEWLOCALE_NOT_USED ++COMPILE_OPTS = $(INCLUDES) -I. -O1 -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DRTP_PAYLOAD_MAX_SIZE=1352 -DNEWLOCALE_NOT_USED +C = c +C_COMPILER = $(CC) +C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS) From 9897afc09df6e08870401341e53262bc5a3be558 Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 11:47:46 +0200 Subject: [PATCH 08/81] Improve sync/async read --- src/rRTSPServer/src/ADTSAudioFifoSource.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/rRTSPServer/src/ADTSAudioFifoSource.cpp b/src/rRTSPServer/src/ADTSAudioFifoSource.cpp index 528d730..d706cd5 100755 --- a/src/rRTSPServer/src/ADTSAudioFifoSource.cpp +++ b/src/rRTSPServer/src/ADTSAudioFifoSource.cpp @@ -56,19 +56,33 @@ ADTSAudioFifoSource::createNew(UsageEnvironment& env, char const* fileName) { }; // Clean fifo content +#ifdef READ_FROM_FILES_SYNCHRONOUSLY + if (debug & 4) fprintf(stderr, "Read synchronously\n"); while (fread(null, 1, sizeof(null), fid) > 0) {} +#else + if (debug & 4) fprintf(stderr, "Read asynchronously\n"); + while (read(fileno(fid), null, sizeof(null)) > 0) {} +#endif // Restore old blocking if (fcntl(fileno(fid), F_SETFL, flags) != 0) { fclose(fid); break; - }; + } unsigned char fixedHeader[7]; while (1) { +#ifdef READ_FROM_FILES_SYNCHRONOUSLY fread(fixedHeader, 1, 1, fid); +#else + read(fileno(fid), fixedHeader, 1); +#endif if (fixedHeader[0] == 0xFF) { +#ifdef READ_FROM_FILES_SYNCHRONOUSLY fread(&fixedHeader[1], 1, 1, fid); +#else + read(fileno(fid), &fixedHeader[1], 1); +#endif // Check the 'syncword': if ((fixedHeader[1]&0xF0) == 0xF0) { break; @@ -76,7 +90,11 @@ ADTSAudioFifoSource::createNew(UsageEnvironment& env, char const* fileName) { } usleep(10000); } +#ifdef READ_FROM_FILES_SYNCHRONOUSLY fread(&fixedHeader[2], 1, 5, fid); +#else + read(fileno(fid), &fixedHeader[2], 5); +#endif u_int16_t frame_length = ((fixedHeader[3]&0x03)<<11) | (fixedHeader[4]<<3) | ((fixedHeader[5]&0xE0)>>5); // Get and check the 'profile': From d29169e3cceb7765e9ffb182a3663b3ec51bfc0b Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 12:44:22 +0200 Subject: [PATCH 09/81] Update gitignore --- src/snapshot/.gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/snapshot/.gitignore b/src/snapshot/.gitignore index 9cd7c97..9ca2b40 100644 --- a/src/snapshot/.gitignore +++ b/src/snapshot/.gitignore @@ -1,8 +1,8 @@ # Ignore the install dir _install/ snapshot/SDK -snapshot/jpeg-9c -snapshot/ffmpeg-4.0.4 +snapshot/jpeg-9e +snapshot/ffmpeg-6.0 snapshot/add_water.o snapshot/convert2jpg.o snapshot/imggrabber From 70a78bd9ba275af44f93c4d11928b92af4a6d87c Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 12:45:30 +0200 Subject: [PATCH 10/81] New features: disable, force low and already running --- src/snapshot/snapshot/imggrabber.c | 65 +++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/snapshot/snapshot/imggrabber.c b/src/snapshot/snapshot/imggrabber.c index 67f3b95..9f8f380 100644 --- a/src/snapshot/snapshot/imggrabber.c +++ b/src/snapshot/snapshot/imggrabber.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 roleo. + * Copyright (c) 2023 roleo. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -314,6 +315,49 @@ int add_watermark(char *buffer, int width, int height) return 0; } +pid_t proc_find(const char* process_name, pid_t process_pid) +{ + DIR* dir; + struct dirent* ent; + char* endptr; + char buf[512]; + + if (!(dir = opendir("/proc"))) { + perror("can't open /proc"); + return -1; + } + + while((ent = readdir(dir)) != NULL) { + /* if endptr is not a null character, the directory is not + * entirely numeric, so ignore it */ + long lpid = strtol(ent->d_name, &endptr, 10); + if (*endptr != '\0') { + continue; + } + + /* try to open the cmdline file */ + snprintf(buf, sizeof(buf), "/proc/%ld/cmdline", lpid); + FILE* fp = fopen(buf, "r"); + + if (fp) { + if (fgets(buf, sizeof(buf), fp) != NULL) { + /* check the first token in the file, the program name */ + char* first = strtok(buf, " "); + if ((strcmp(first, process_name) == 0) && ((pid_t) lpid != process_pid)) { + fclose(fp); + closedir(dir); + return (pid_t) lpid; + } + } + fclose(fp); + } + + } + + closedir(dir); + return -1; +} + void print_usage(char *prog_name) { fprintf(stderr, "Usage: %s [options]\n", prog_name); @@ -614,6 +658,25 @@ int main(int argc, char **argv) { if (debug) fprintf(stderr, "Starting program\n"); + // Check if snapshot is disabled + if (access("/tmp/snapshot.disabled", F_OK ) == 0 ) { + fprintf(stderr, "Snapshot is disabled\n"); + return 0; + } + + // Check if snapshot is low res + if (access("/tmp/snapshot.low", F_OK ) == 0 ) { + fprintf(stderr, "Snapshot is low res\n"); + resolution = RESOLUTION_LOW; + } + + // Check if the process is already running + pid_t my_pid = getpid(); + if (proc_find(basename(argv[0]), my_pid) != -1) { + fprintf(stderr, "Process is already running\n"); + return 0; + } + if (resolution == RESOLUTION_LOW) { table_offset = table_low_offset; stream_offset = stream_low_offset; From d19971d4933f1addc75192ad786e3a120ba02729 Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 12:49:09 +0200 Subject: [PATCH 11/81] Remove unused settings from config files --- src/static/static/home/yi-hack-v5/etc/mqttv4.conf | 8 ++------ .../static/home/yi-hack-v5/script/check_conf.sh | 15 --------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/etc/mqttv4.conf b/src/static/static/home/yi-hack-v5/etc/mqttv4.conf index e601173..4dcbf24 100644 --- a/src/static/static/home/yi-hack-v5/etc/mqttv4.conf +++ b/src/static/static/home/yi-hack-v5/etc/mqttv4.conf @@ -24,9 +24,8 @@ MQTT_PREFIX=yicam TOPIC_BIRTH_WILL=status TOPIC_MOTION=motion_detection TOPIC_MOTION_IMAGE=motion_detection_image +MOTION_IMAGE_DELAY=0.5 TOPIC_MOTION_FILES=motion_files -TOPIC_AI_HUMAN_DETECTION=ai_human_detection -TOPIC_BABY_CRYING=baby_crying TOPIC_SOUND_DETECTION=sound_detection # ----------------------------------------------------------------------------- @@ -37,9 +36,8 @@ BIRTH_MSG=online WILL_MSG=offline MOTION_START_MSG=motion_start MOTION_STOP_MSG=motion_stop -AI_HUMAN_DETECTION_MSG=human BABY_CRYING_MSG=crying -SOUND_DETECTION_MSG=sound +SOUND_DETECTION_MSG=sound_detected # ----------------------------------------------------------------------------- # Other settings @@ -51,6 +49,4 @@ MQTT_RETAIN_BIRTH_WILL=1 MQTT_RETAIN_MOTION=0 MQTT_RETAIN_MOTION_IMAGE=0 MQTT_RETAIN_MOTION_FILES=0 -MQTT_RETAIN_AI_HUMAN_DETECTION=0 -MQTT_RETAIN_BABY_CRYING=0 MQTT_RETAIN_SOUND_DETECTION=0 diff --git a/src/static/static/home/yi-hack-v5/script/check_conf.sh b/src/static/static/home/yi-hack-v5/script/check_conf.sh index 834e56a..cd71161 100755 --- a/src/static/static/home/yi-hack-v5/script/check_conf.sh +++ b/src/static/static/home/yi-hack-v5/script/check_conf.sh @@ -14,23 +14,13 @@ DISABLE_CLOUD=no REC_WITHOUT_CLOUD=no MQTT=no RTSP=no -RTSP_ALT=no RTSP_STREAM=high RTSP_AUDIO=no -SPEAKER_AUDIO=yes -SNAPSHOT=yes -SNAPSHOT_VIDEO=no -SNAPSHOT_LOW=no -TIMELAPSE=no -TIMELAPSE_FTP=no -TIMELAPSE_DT=60 -TIMELAPSE_VDT= ONVIF=no ONVIF_WSDD=yes ONVIF_PROFILE=high ONVIF_NETIF=wlan0 ONVIF_WM_SNAPSHOT=yes -TIME_OSD=no NTPD=yes NTP_SERVER=pool.ntp.org PROXYCHAINSNG=no @@ -82,15 +72,11 @@ TOPIC_MOTION=motion_detection TOPIC_MOTION_IMAGE=motion_detection_image MOTION_IMAGE_DELAY=0.5 TOPIC_MOTION_FILES=motion_files -TOPIC_AI_HUMAN_DETECTION=ai_human_detection TOPIC_SOUND_DETECTION=sound_detection BIRTH_MSG=online WILL_MSG=offline MOTION_START_MSG=motion_start MOTION_STOP_MSG=motion_stop -AI_HUMAN_DETECTION_MSG=human -AI_VEHICLE_DETECTION_MSG=vehicle -AI_ANIMAL_DETECTION_MSG=animal BABY_CRYING_MSG=crying SOUND_DETECTION_MSG=sound_detected MQTT_KEEPALIVE=120 @@ -99,7 +85,6 @@ MQTT_RETAIN_BIRTH_WILL=1 MQTT_RETAIN_MOTION=0 MQTT_RETAIN_MOTION_IMAGE=0 MQTT_RETAIN_MOTION_FILES=0 -MQTT_RETAIN_AI_HUMAN_DETECTION=0 MQTT_RETAIN_SOUND_DETECTION=0" if [ ! -f $SYSTEM_CONF_FILE ]; then From c7034e24c88b105183cdb1b802ec9d4445b6d963 Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 12:49:57 +0200 Subject: [PATCH 12/81] Add options to disable snapshot and force low res --- .../static/home/yi-hack-v5/etc/system.conf | 2 ++ .../home/yi-hack-v5/script/check_conf.sh | 2 ++ .../static/home/yi-hack-v5/script/system.sh | 8 ++++++ .../httpd/htdocs/pages/configurations.html | 28 +++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/static/static/home/yi-hack-v5/etc/system.conf b/src/static/static/home/yi-hack-v5/etc/system.conf index aa88ff6..562bf1f 100644 --- a/src/static/static/home/yi-hack-v5/etc/system.conf +++ b/src/static/static/home/yi-hack-v5/etc/system.conf @@ -14,6 +14,8 @@ ONVIF_WSDD=no ONVIF_PROFILE=high ONVIF_NETIF=wlan0 ONVIF_WM_SNAPSHOT=no +SNAPSHOT=yes +SNAPSHOT_LOW=no NTPD=no NTP_SERVER=pool.ntp.org PROXYCHAINSNG=no diff --git a/src/static/static/home/yi-hack-v5/script/check_conf.sh b/src/static/static/home/yi-hack-v5/script/check_conf.sh index cd71161..0c9a350 100755 --- a/src/static/static/home/yi-hack-v5/script/check_conf.sh +++ b/src/static/static/home/yi-hack-v5/script/check_conf.sh @@ -21,6 +21,8 @@ ONVIF_WSDD=yes ONVIF_PROFILE=high ONVIF_NETIF=wlan0 ONVIF_WM_SNAPSHOT=yes +SNAPSHOT=yes +SNAPSHOT_LOW=no NTPD=yes NTP_SERVER=pool.ntp.org PROXYCHAINSNG=no diff --git a/src/static/static/home/yi-hack-v5/script/system.sh b/src/static/static/home/yi-hack-v5/script/system.sh index 84ad7ab..d934ab2 100755 --- a/src/static/static/home/yi-hack-v5/script/system.sh +++ b/src/static/static/home/yi-hack-v5/script/system.sh @@ -249,6 +249,14 @@ if [[ $(get_config ONVIF_WM_SNAPSHOT) == "yes" ]] ; then WATERMARK="&watermark=yes" fi +if [[ $(get_config SNAPSHOT) == "no" ]] ; then + touch /tmp/snapshot.disabled +fi + +if [[ $(get_config SNAPSHOT_LOW) == "yes" ]] ; then + touch /tmp/snapshot.low +fi + RRTSP_MODEL=$MODEL_SUFFIX RRTSP_RES=$(get_config RTSP_STREAM) RRTSP_AUDIO=$(get_config RTSP_AUDIO) diff --git a/src/www/httpd/htdocs/pages/configurations.html b/src/www/httpd/htdocs/pages/configurations.html index 1249f0a..989e240 100644 --- a/src/www/httpd/htdocs/pages/configurations.html +++ b/src/www/httpd/htdocs/pages/configurations.html @@ -172,6 +172,34 @@

General

+ + Snapshot + + + + Enable snapshot feature. +
+ If you want to use this feature, enable swap file to avoid memory problems. +
+ + + + Force low resolution snapshot + + + + Take low resolution snapshots only (useful for avoiding memory problems). + + + From fcb3bc313482d30c3293fb8a5830f678ba4ba565 Mon Sep 17 00:00:00 2001 From: roleo Date: Fri, 25 Aug 2023 12:50:39 +0200 Subject: [PATCH 13/81] Remove unused mqtt options --- src/www/httpd/htdocs/pages/mqtt.html | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/www/httpd/htdocs/pages/mqtt.html b/src/www/httpd/htdocs/pages/mqtt.html index 3dc3326..5aace03 100644 --- a/src/www/httpd/htdocs/pages/mqtt.html +++ b/src/www/httpd/htdocs/pages/mqtt.html @@ -130,16 +130,20 @@

Topics

+ + A raw jpeg image is sent to this topic when a motion is detected. + + - + Sound Detection @@ -157,7 +161,7 @@

Topics

- + @@ -242,7 +246,7 @@

Advanced

- + Retain for Sound Detection messages From 2dc4cfa895413867f7bdc3b71e594c322d47401c Mon Sep 17 00:00:00 2001 From: roleo Date: Sat, 26 Aug 2023 14:53:32 +0200 Subject: [PATCH 14/81] Fix and improve h264grabber --- src/h264grabber/h264grabber/h264grabber.c | 44 ++++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/h264grabber/h264grabber/h264grabber.c b/src/h264grabber/h264grabber/h264grabber.c index c8815bc..55c4ec8 100644 --- a/src/h264grabber/h264grabber/h264grabber.c +++ b/src/h264grabber/h264grabber/h264grabber.c @@ -214,7 +214,7 @@ int main(int argc, char **argv) { FILE *fFid = NULL; FILE *fOut = NULL; - int current_frame, frame_counter, frame_counter_tmp, next_frame_counter; + int current_frame, frame_counter, frame_counter_tmp, next_frame_counter, frame_start, next_frame_start; int table_offset, stream_offset; unsigned int frame_ts = 0; unsigned int frame_ts_tmp, next_frame_ts, frame_ts_diff; @@ -573,17 +573,24 @@ int main(int argc, char **argv) { for (i = 0; i < table_record_num; i++) { // Get pointer to the record record_ptr = addr + table_offset + (i * table_record_size); + // Get the frame start and check if '01' + frame_start = (int) *(record_ptr); + if (frame_start != 1) continue; // Get the frame counter frame_counter_tmp = (((int) *(record_ptr + frame_counter_offset + 1)) << 8) + ((int) *(record_ptr + frame_counter_offset)); // Check if it is the largest frame_counter if (frame_counter_tmp > frame_counter) { frame_counter = frame_counter_tmp; - } else { current_frame = i; + } else { break; } } + if (current_frame == -1) { + usleep(MILLIS_10); + continue; + } if (debug) fprintf(stderr, "%lld - found latest frame: id %d, frame_counter %d\n", current_timestamp(), current_frame, frame_counter); // Wait 10 milliseconds @@ -601,6 +608,12 @@ int main(int argc, char **argv) { } else { next_record_ptr = record_ptr + table_record_size; } + // Get the frame start and check if '01' + next_frame_start = (int) *(next_record_ptr); + if (next_frame_start != 1) { + usleep(MILLIS_10); + continue; + } // Get the frame counter of the next record next_frame_counter = ((int) *(next_record_ptr + frame_counter_offset + 1)) * 256 + ((int) *(next_record_ptr + frame_counter_offset)); if (debug) fprintf(stderr, "%lld - current frame counter is %d, next frame counter is %d\n", current_timestamp(), frame_counter, next_frame_counter); @@ -635,7 +648,7 @@ int main(int argc, char **argv) { } else { frame_counter_invalid++; if (frame_counter_invalid < 10) { - if (debug) fprintf(stderr, "%lld - frame counter invalid %d\n", current_timestamp(), frame_counter_invalid); + if (debug) fprintf(stderr, "%lld - frame counter invalid %d, wait for the next frame\n", current_timestamp(), frame_counter_invalid); } else { if (debug) fprintf(stderr, "%lld - frame counter invalid %d, sync lost\n", current_timestamp(), frame_counter_invalid); break; @@ -650,10 +663,13 @@ int main(int argc, char **argv) { for(;;) { // Find the record with the largest timestamp current_frame = -1; - frame_counter = -1; + frame_ts = 0; for (i = 0; i < table_record_num; i++) { // Get pointer to the record record_ptr = addr + table_offset + (i * table_record_size); + // Get the frame start and check if '01' + frame_start = (int) *(record_ptr); + if (frame_start != 1) continue; // Get the frame timestamp frame_ts_tmp = (((int) *(record_ptr + frame_ts_offset + 3)) << 24) + (((int) *(record_ptr + frame_ts_offset + 2)) << 16) + @@ -662,11 +678,15 @@ int main(int argc, char **argv) { // Check if it is the largest timestamp if (frame_ts_tmp > frame_ts) { frame_ts = frame_ts_tmp; - } else { current_frame = i; + } else { break; } } + if (current_frame == -1) { + usleep(MILLIS_10); + continue; + } if (debug) fprintf(stderr, "%lld - found latest frame: id %d, frame_ts %u\n", current_timestamp(), current_frame, frame_ts); // Wait 10 milliseconds @@ -684,18 +704,24 @@ int main(int argc, char **argv) { } else { next_record_ptr = record_ptr + table_record_size; } + // Get the frame start and check if '01' + next_frame_start = (int) *(next_record_ptr); + if (next_frame_start != 1) { + usleep(MILLIS_10); + continue; + } // Get the frame timestamp of the next record next_frame_ts = (((int) *(next_record_ptr + frame_ts_offset + 3)) << 24) + (((int) *(next_record_ptr + frame_ts_offset + 2)) << 16) + (((int) *(next_record_ptr + frame_ts_offset + 1)) << 8) + ((int) *(next_record_ptr + frame_ts_offset)); - if (debug) fprintf(stderr, "%lld - current frame timestamp is %u, next frame timestamp is %u\n", current_timestamp(), frame_ts, next_frame_ts); + if (debug) fprintf(stderr, "%lld - current frame timestamp is %u, next frame timestamp is %u, duration is %u\n", current_timestamp(), frame_ts, next_frame_ts, next_frame_ts - frame_ts); // Check if the frame timestamp is valid if (next_frame_ts >= frame_ts) frame_ts_diff = next_frame_ts - frame_ts; else frame_ts_diff = next_frame_ts + (0xffffffff - frame_ts + 1); - if ((frame_ts_diff >= 0) && (frame_ts_diff <= 10 * 64)) { // 1 packet with 1024 samples every 64 ms + if ((frame_ts_diff >= 0) && (frame_ts_diff <= 2 * 128)) { // 1 packet with 1024 samples every 128 ms // Get the offset of the stream frame_offset = (((int) *(record_ptr + frame_offset_offset + 3)) << 24) + (((int) *(record_ptr + frame_offset_offset + 2)) << 16) + @@ -724,9 +750,9 @@ int main(int argc, char **argv) { } else { frame_counter_invalid++; if (frame_counter_invalid < 10) { - if (debug) fprintf(stderr, "%lld - frame counter invalid %d\n", current_timestamp(), frame_counter_invalid); + if (debug) fprintf(stderr, "%lld - frame timestamp invalid %d, wait for the next frame\n", current_timestamp(), frame_counter_invalid); } else { - if (debug) fprintf(stderr, "%lld - frame counter invalid %d, sync lost\n", current_timestamp(), frame_counter_invalid); + if (debug) fprintf(stderr, "%lld - frame timestamp invalid %d, sync lost\n", current_timestamp(), frame_counter_invalid); break; } } From 6ce47e243809f55bf4df60f9f5b5eadec930b2ad Mon Sep 17 00:00:00 2001 From: roleo Date: Sat, 26 Aug 2023 14:54:43 +0200 Subject: [PATCH 15/81] Fix system.conf parameters --- src/static/static/home/yi-hack-v5/etc/camera.conf | 2 +- src/static/static/home/yi-hack-v5/script/check_conf.sh | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/etc/camera.conf b/src/static/static/home/yi-hack-v5/etc/camera.conf index 8919915..f05ae90 100644 --- a/src/static/static/home/yi-hack-v5/etc/camera.conf +++ b/src/static/static/home/yi-hack-v5/etc/camera.conf @@ -1,9 +1,9 @@ SWITCH_ON=yes SAVE_VIDEO_ON_MOTION=yes SENSITIVITY=low -AI_HUMAN_DETECTION=no SOUND_DETECTION=no SOUND_SENSITIVITY=80 +BABY_CRYING_DETECT=no LED=yes ROTATE=no IR=yes diff --git a/src/static/static/home/yi-hack-v5/script/check_conf.sh b/src/static/static/home/yi-hack-v5/script/check_conf.sh index 0c9a350..4adf9ea 100755 --- a/src/static/static/home/yi-hack-v5/script/check_conf.sh +++ b/src/static/static/home/yi-hack-v5/script/check_conf.sh @@ -48,19 +48,13 @@ DEBUG_LOG=no" PARMS2=" SWITCH_ON=yes SAVE_VIDEO_ON_MOTION=yes -MOTION_DETECTION=yes SENSITIVITY=low -AI_HUMAN_DETECTION=no -AI_VEHICLE_DETECTION=no -AI_ANIMAL_DETECTION=no -FACE_DETECTION=no -MOTION_TRACKING=no SOUND_DETECTION=no SOUND_SENSITIVITY=80 +BABY_CRYING_DETECT=no LED=yes ROTATE=no -IR=yes -CRUISE=no" +IR=yes" PARMS3=" MQTT_IP=0.0.0.0 From a309b2aac774f2cb39f34969d7721f9c6df2a02a Mon Sep 17 00:00:00 2001 From: roleo Date: Sat, 26 Aug 2023 15:23:04 +0200 Subject: [PATCH 16/81] Remove ai_human_detection and restore baby_crying --- src/www/httpd/cgi-bin/camera_settings.sh | 12 ++++++------ .../httpd/htdocs/js/modules/camera_settings.js | 2 +- src/www/httpd/htdocs/pages/camera_settings.html | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/www/httpd/cgi-bin/camera_settings.sh b/src/www/httpd/cgi-bin/camera_settings.sh index be506fe..ad2888c 100755 --- a/src/www/httpd/cgi-bin/camera_settings.sh +++ b/src/www/httpd/cgi-bin/camera_settings.sh @@ -31,12 +31,6 @@ do fi elif [ "$CONF" == "sensitivity" ] ; then ipc_cmd -s $VAL - elif [ "$CONF" == "ai_human_detection" ] ; then - if [ "$VAL" == "no" ] ; then - ipc_cmd -a off - else - ipc_cmd -a on - fi elif [ "$CONF" == "sound_detection" ] ; then if [ "$VAL" == "no" ] ; then ipc_cmd -b off @@ -47,6 +41,12 @@ do if [ "$VAL" == "50" ] || [ "$VAL" == "60" ] || [ "$VAL" == "70" ] || [ "$VAL" == "80" ] || [ "$VAL" == "90" ] ; then ipc_cmd -n $VAL fi + elif [ "$CONF" == "baby_crying_detect" ] ; then + if [ "$VAL" == "no" ] ; then + ipc_cmd -B off + else + ipc_cmd -B on + fi elif [ "$CONF" == "led" ] ; then if [ "$VAL" == "no" ] ; then ipc_cmd -l off diff --git a/src/www/httpd/htdocs/js/modules/camera_settings.js b/src/www/httpd/htdocs/js/modules/camera_settings.js index b7e815e..57cdfd0 100644 --- a/src/www/httpd/htdocs/js/modules/camera_settings.js +++ b/src/www/httpd/htdocs/js/modules/camera_settings.js @@ -57,9 +57,9 @@ APP.camera_settings = (function ($) { url: 'cgi-bin/camera_settings.sh?' + 'save_video_on_motion=' + configs["SAVE_VIDEO_ON_MOTION"] + '&sensitivity=' + configs["SENSITIVITY"] + - '&ai_human_detection=' + configs["AI_HUMAN_DETECTION"] + '&sound_detection=' + configs["SOUND_DETECTION"] + '&sound_sensitivity=' + configs["SOUND_SENSITIVITY"] + + '&baby_crying_detect=' + configs["BABY_CRYING_DETECT"] + '&led=' + configs["LED"] + '&ir=' + configs["IR"] + '&rotate=' + configs["ROTATE"] + diff --git a/src/www/httpd/htdocs/pages/camera_settings.html b/src/www/httpd/htdocs/pages/camera_settings.html index 55bc522..8d94fb8 100644 --- a/src/www/httpd/htdocs/pages/camera_settings.html +++ b/src/www/httpd/htdocs/pages/camera_settings.html @@ -76,7 +76,7 @@

General

Enable/disable AI Human Detection. - + --> Sound Detection @@ -103,7 +103,20 @@

General

- --> + + + Baby crying detect + + + + Enable/disable baby crying detect. + + + Status led From 878720fe0f34a2a84197cadf913b484d91c3a3fa Mon Sep 17 00:00:00 2001 From: alienatedsec <73167064+alienatedsec@users.noreply.github.com> Date: Sat, 26 Aug 2023 15:08:01 +0100 Subject: [PATCH 17/81] [Pre-Release] 0.4.1a Changes to be committed: modified: VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1d0ba9e..39bbca7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.0 +0.4.1a From ee0da9d0eb8afdb560953dca9d7f9ac2631d8f92 Mon Sep 17 00:00:00 2001 From: roleo Date: Tue, 5 Sep 2023 17:21:38 +0200 Subject: [PATCH 18/81] Change size of fifo queues --- src/h264grabber/h264grabber/h264grabber.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/h264grabber/h264grabber/h264grabber.c b/src/h264grabber/h264grabber/h264grabber.c index 55c4ec8..57c4443 100644 --- a/src/h264grabber/h264grabber/h264grabber.c +++ b/src/h264grabber/h264grabber/h264grabber.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 roleo. + * Copyright (c) 2023 roleo. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -140,6 +140,10 @@ #define FIFO_NAME_HIGH "/tmp/h264_high_fifo" #define FIFO_NAME_AAC "/tmp/aac_audio_fifo" +#define F_LINUX_SPECIFIC_BASE 1024 +#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7) +#define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8) + // Unused vars unsigned char IDR[] = {0x65, 0xB8}; unsigned char NAL_START[] = {0x00, 0x00, 0x00, 0x01}; @@ -530,6 +534,10 @@ int main(int argc, char **argv) { fprintf(stderr, "Error opening fifo %s\n", FIFO_NAME_LOW); return -1; } + if (fcntl(fileno(fOut), F_SETPIPE_SZ, 65536) != 65536) { + fprintf(stderr, "Cannot set size of fifo\n"); + return -1; + }; } else if (resolution == RESOLUTION_HIGH) { unlink(FIFO_NAME_HIGH); if (mkfifo(FIFO_NAME_HIGH, mode) < 0) { @@ -546,6 +554,10 @@ int main(int argc, char **argv) { fprintf(stderr, "Error opening fifo %s\n", FIFO_NAME_HIGH); return -1; } + if (fcntl(fileno(fOut), F_SETPIPE_SZ, 262144) != 262144) { + fprintf(stderr, "Cannot set size of fifo\n"); + return -1; + }; } else if (resolution == RESOLUTION_AUDIO) { unlink(FIFO_NAME_AAC); if (mkfifo(FIFO_NAME_AAC, mode) < 0) { @@ -562,6 +574,10 @@ int main(int argc, char **argv) { fprintf(stderr, "Error opening fifo %s\n", FIFO_NAME_AAC); return -1; } + if (fcntl(fileno(fOut), F_SETPIPE_SZ, 8192) != 8192) { + fprintf(stderr, "Cannot set size of fifo\n"); + return -1; + }; } } From 66030f5abbbd86f186907809cb51c0a3a0af898f Mon Sep 17 00:00:00 2001 From: roleo Date: Tue, 5 Sep 2023 17:22:10 +0200 Subject: [PATCH 19/81] Restore audio stream ch0_2.h264 --- src/rRTSPServer/src/rRTSPServer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rRTSPServer/src/rRTSPServer.cpp b/src/rRTSPServer/src/rRTSPServer.cpp index fa16d88..9713e03 100755 --- a/src/rRTSPServer/src/rRTSPServer.cpp +++ b/src/rRTSPServer/src/rRTSPServer.cpp @@ -362,7 +362,7 @@ int main(int argc, char** argv) announceStream(rtspServer, sms_low, streamName, inputFileName, audio); } -/* + // An ADTS audio elementary stream: if (audio != 0) { @@ -379,7 +379,7 @@ int main(int argc, char** argv) announceStream(rtspServer, sms_audio, streamName, inputAudioFileName, audio); } -*/ + // Also, attempt to create a HTTP server for RTSP-over-HTTP tunneling. // Try first with the default HTTP port (80), and then with the alternative HTTP // port numbers (8000 and 8080). From cf13502b466fd084cfa7d442ca128056ab7540e8 Mon Sep 17 00:00:00 2001 From: roleo Date: Tue, 5 Sep 2023 17:23:13 +0200 Subject: [PATCH 20/81] Add native api to take low res snapshot --- src/snapshot/snapshot/Makefile | 7 +- src/snapshot/snapshot/cap_pic.c | 126 +++++++++++++++++++++++++ src/snapshot/snapshot/cap_pic.h | 146 +++++++++++++++++++++++++++++ src/snapshot/snapshot/imggrabber.c | 34 ++++++- 4 files changed, 310 insertions(+), 3 deletions(-) create mode 100644 src/snapshot/snapshot/cap_pic.c create mode 100644 src/snapshot/snapshot/cap_pic.h diff --git a/src/snapshot/snapshot/Makefile b/src/snapshot/snapshot/Makefile index 2a54974..42d26dc 100644 --- a/src/snapshot/snapshot/Makefile +++ b/src/snapshot/snapshot/Makefile @@ -1,8 +1,8 @@ -OBJECTS = imggrabber.o convert2jpg.o add_water.o water_mark.o +OBJECTS = imggrabber.o convert2jpg.o add_water.o water_mark.o cap_pic.o FFMPEG = ffmpeg-6.0 FFMPEG_DIR = ./$(FFMPEG) INC_FF = -I$(FFMPEG_DIR) -LIB_FF = $(FFMPEG_DIR)/libavcodec/libavcodec.a $(FFMPEG_DIR)/libavutil/libavutil.a -lpthread -lm +LIB_FF = $(FFMPEG_DIR)/libavcodec/libavcodec.a $(FFMPEG_DIR)/libavutil/libavutil.a -lpthread -lm -lrt JPEGLIB = jpeg-9e JPEGLIB_DIR = ./$(JPEGLIB) JPEGSRC = jpegsrc.v9e @@ -28,6 +28,9 @@ add_water.o: add_water.c $(HEADERS) water_mark.o: water_mark.c $(HEADERS) $(CC) -c $< $(INC_J) -fPIC -O2 -o $@ +cap_pic.o: cap_pic.c $(HEADERS) + $(CC) -c $< $(INC_J) -fPIC -O2 -o $@ + imggrabber: $(OBJECTS) $(CC) $(OBJECTS) $(LIB_J) $(LIB_FF) -fPIC -O2 -o $@ $(STRIP) $@ diff --git a/src/snapshot/snapshot/cap_pic.c b/src/snapshot/snapshot/cap_pic.c new file mode 100644 index 0000000..7b19baf --- /dev/null +++ b/src/snapshot/snapshot/cap_pic.c @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include + +#include "cap_pic.h" + +mqd_t ipc_mq; + +void dump_string(char *source_file, const char *func, int line, char *text, ...) +{ + time_t now; + struct tm *s_now; + struct timeval tv; + + if (text == '\0') { + return; + } + + time(&now); + s_now = localtime(&now); + if (s_now != 0) { + gettimeofday((struct timeval *) &tv, NULL); + printf("\n%s(%s-%d)[%02d:%02d:%02d.%03d]:", source_file, func, line, s_now->tm_hour, + s_now->tm_min, s_now->tm_sec, tv.tv_usec >> 10); + va_list args; + va_start (args, text); + vfprintf(stdout, text, args); + va_end (args); + putchar(10); + } + return; +} + +int mqueue_send(mqd_t mqfd,char *send_buf, size_t send_len) +{ + int iRet; + + if (send_len > 512 || mqfd == -1) { + return -1; + } + iRet = mq_send(mqfd, send_buf, send_len, 1); + + return iRet; +} + +int cloud_send_msg(mqd_t mqfd, MSG_TYPE msg_type, char *payload, int payload_len) +{ + cloud_send_msg_ex(mqfd, msg_type, 1, payload, payload_len); +} + +int cloud_send_msg_ex(mqd_t mqfd, MSG_TYPE msg_type, short sub, char *payload, int payload_len) +{ + mqueue_msg_header_t MsgHead; + char send_buf[1024] = {0}; + int send_len = 0; + int fsMsgRet = 0; + + memset(&MsgHead, 0, sizeof(MsgHead)); + MsgHead.srcMid = MID_CLOUD; + MsgHead.mainOp = msg_type; + MsgHead.subOp = sub; + MsgHead.msgLength = payload_len; + + switch(msg_type) + { + case RCD_START_SHORT_VIDEO: + case RCD_START_SHORT_VIDEO_10S: + case RCD_START_VOICECMD_VIDEO: + MsgHead.dstMid = MID_RCD; + break; + case RMM_START_CAPTURE: + case RMM_SPEAK_BAN_DEVICE: + case RMM_START_PANORAMA_CAPTURE: + case RMM_ABORT_PANORAMA_CAPTURE: + MsgHead.dstMid = MID_RMM; + break; + case CLOUD_DEBUG_ALARM: + MsgHead.dstMid = MID_CLOUD; + break; + default: + MsgHead.dstMid = MID_DISPATCH; + break; + } + + memcpy(send_buf, &MsgHead, sizeof(MsgHead)); + if(NULL!=payload && payload_len>0) + { + memcpy(send_buf + sizeof(MsgHead), payload, payload_len); + } + send_len = sizeof(MsgHead) + payload_len; + + fsMsgRet = mqueue_send(mqfd, send_buf, send_len); + + return fsMsgRet; +} + +int cloud_cap_pic(char *pic_name) +{ + if(cloud_send_msg(ipc_mq, RMM_START_CAPTURE, pic_name, strlen(pic_name)) < 0) + { + dump_string(_F_, _FU_, _L_, "cloud_cap_pic send_msg fail!\n"); + return -1; + } + else + { + dump_string(_F_, _FU_, _L_, "cloud_cap_pic send_msg ok!\n"); + return 0; + } +} + +int main_cloud_cap_pic(char *nameBuff) +{ + ipc_mq = mq_open("/ipc_dispatch", O_RDWR); + if (ipc_mq == -1) { + dump_string(_F_, _FU_, _L_, "open queue fail!\n"); + return -1; + } + + cloud_cap_pic(nameBuff); + + mq_close(ipc_mq); + + return 0; +} diff --git a/src/snapshot/snapshot/cap_pic.h b/src/snapshot/snapshot/cap_pic.h new file mode 100644 index 0000000..addfa56 --- /dev/null +++ b/src/snapshot/snapshot/cap_pic.h @@ -0,0 +1,146 @@ +#ifndef CMD_SRV_H +#define CMD_SRV_H + +#include +#include + +#define _F_ __FILE__ +#define _FU_ __FUNCTION__ +#define _L_ __LINE__ + +#define IPC_QUEUE_NAME "/ipc_dispatch" + +#define MID_P2P 1 +#define MID_RMM 2 +#define MID_CLOUD 4 +#define MID_DISPATCH 4 +#define MID_RCD 0x10 + +typedef enum { + DISPATCH_SET_TIME = 0x71, + DISPATCH_SET_BIND_FAIL = 0x73, + DISPATCH_SET_POWER_ON = 0x74, + DISPATCH_SET_POWER_OFF = 0x75, + DISPATCH_SET_LIGHT_ON = 0x76, + DISPATCH_SET_LIGHT_OFF = 0x77, + DISPATCH_SET_MOTION_RCD = 0x78, + DISPATCH_SET_ALWAYS_RCD = 0x79, + DISPATCH_SET_MIRROR_ON = 0x7a, + DISPATCH_SET_MIRROR_OFF = 0x7b, + DISPATCH_MOTION_DETECT_START = 0x7c, + DISPATCH_MOTION_DETECT_STOP = 0x7d, + DISPATCH_SET_TNP_INIT_STATUS = 0x7f, + DISPATCH_SET_TNP_WORK_MODE = 0x80, + DISPATCH_SET_SD_FORMAT = 0x85, + DISPATCH_SET_DEBUG_MODE = 0x86, + DISPATCH_SET_VIDEO_BACKUP_STATE = 0x87, + DISPATCH_SET_BAN_DEVICE = 0x88, + DISPATCH_SYNC_INFO_FROM_SERVER = 0x89, + DISPATCH_FINISH_SYNC_INFO_FROM_SERVER = 0x8a, + DISPATCH_SET_CLOUD_STORAGE_ON = 0x8b, + DISPATCH_SET_CLOUD_STORAGE_OFF = 0x8c, + DISPATCH_SET_REGION = 0x8d, + DISPATCH_SET_TZ_OFFSET = 0x8e, + DISPATCH_SET_PWD_USED_CNT = 0x8f, + DISPATCH_SET_PWD_SYNC_SERVER = 0x90, + DISPATCH_SET_OTA_STATE = 0x91, + DISPATCH_SET_PANORAMA_CAPTURE_STATE = 0x92, + DISPATCH_SET_PANORAMA_CAPTURE_COUNT = 0x93, + DISPATCH_SET_CLOUD_STORAGE_MODE_MOTION_DETECT = 0x94, + DISPATCH_SET_CLOUD_STORAGE_MODE_ALL_DAY = 0x95, + DISPATCH_SAVE_API_SERVER = 0x96, + DISPATCH_CLEAR_API_SERVER = 0x97, + DISPATCH_SET_BIND_TIMEOUT = 0x98, + DISPATCH_SPEAK_WRONG_DEVICE = 0x99, + DISPATCH_SET_LAPSE_VIDEO = 0x9a, + DISPATCH_SET_LAPSE_VIDEO_MODIFY = 0x9b, + DISPATCH_P2P_CONNECTTED = 0xe1, + DISPATCH_P2P_DISCONNECTTED = 0xe2, + DISPATCH_P2P_VIEWING = 0xe3, + DISPATCH_P2P_STOP_VIEWING = 0xe4, + DISPATCH_P2P_CLR_VIEWING = 0xe5, + DISPATCH_MOTION_TRACKING_DETECT_START = 0xe6, + DISPATCH_BABYCRY_OCCUR = 0xea, + DISPATCH_BABYCRY_CLEAR = 0xeb, + DISPATCH_SET_SCHEDULE_POWER = 0xec, + DISPATCH_HUMAN_DETECT_START = 0xed, + DISPATCH_ABNORMAL_SOUND_OCCUR = 0xee, + DISPATCH_ABNORMAL_SOUND_CLEAR = 0xef, + DISPATCH_CLOUD_PIC_INDEX_OCCUR = 0xf0, + DISPATCH_CLOUD_PIC_INDEX_CLEAR = 0xf1, + DISPATCH_CLOUD_PIC_SET_INTERVAL = 0xf2, + DISPATCH_SET_CLOUD_IMAGE_ON = 0xf3, + DISPATCH_SET_CLOUD_IMAGE_OFF = 0xf4, + DISPATCH_START_RECORDE = 0Xf5, + DISPATCH_STOP_RECORDE = 0Xf6, + DISPATCH_FACE_DETECT_START = 0xf7, + RMM_SPEAK_SUCCESS = 0x1000, + RMM_SPEAK_RESET = 0x1001, + RMM_SPEAK_WAIT = 0x1002, + RMM_SPEAK_PWD_WRONG = 0x1003, + RMM_SPEAK_CONNECTTING = 0x1004, + RMM_SPEAK_SCAN_OK = 0x1005, + RMM_SPEAK_WIFI_CONNECTTED = 0x1006, + RMM_START_CAPTURE = 0x1007, + RMM_START_WELCOME = 0x1008, + RMM_SPEAK_BINDFAIL = 0x1009, + RMM_SPEAK_DOWNLOADING = 0x100a, + RMM_SPEAK_UPDATING = 0x100b, + RMM_SPEAK_DOWNLOAD_FAIL = 0x100c, + RMM_SPEAK_BAN_DEVICE = 0x100d, + RMM_APP_MODE_EARPHONE = 0x1021, + RMM_APP_MODE_SPKER = 0x1022, + RMM_SET_MOTION_DETECT = 0x1023, + RMM_SET_DAY_NIGHT_MODE = 0x1024, + RMM_SET_MOTION_SENSITIVITY = 0x1027, + RMM_SET_LDC = 0x1028, + RMM_SET_BABY_CRY = 0x1029, + RMM_SET_MIC_VOLUME = 0x102a, + RMM_START_PANORAMA_CAPTURE = 0x102b, + RMM_ABORT_PANORAMA_CAPTURE = 0x102c, + RMM_SPEAK_WRONG_DEVICE = 0x1031, + RMM_SET_ENCODE_MODE = 0x1032, + RMM_SET_HIGH_RESOLUTION = 0x1033, + RNN_VC_START_RECORD = 0x1034, + RMM_VC_STOP_RECORD = 0x1035, + RMM_SET_LAPSE_FRAMERATE = 0x1036, + RMM_SET_LAPSE_FORCE_IDR = 0x1037, + RMM_APP_AUDIO_MODE_SIMPLEX = 0x1038, + RMM_APP_AUDIO_MODE_DUPLEX = 0x1039, + RMM_SET_ABNORMAL_SOUND = 0x103a, + RMM_SET_ABNORMAL_SOUND_SENSITIVITY = 0x103b, + RMM_SET_HUMAN_MOTION = 0x103c, + RMM_SET_FACE_MOTION = 0x103d, + RCD_START_SHORT_VIDEO = 0x2000, + RCD_START_SHORT_VIDEO_10S = 0x2001, + RCD_START_VOICECMD_VIDEO = 0x2002, + RCD_START_SHORT_FACE_VIDEO = 0x2003, + RCD_START_SHORT_HUMAN_VIDEO = 0x2004, + DISPATCH_SET_VIEWPOINT_TRACE = 0x3002, + DISPATCH_SET_VOICE_CTRL = 0x3003, + DISPATCH_P2P_PTZ_PRESET_ADD = 0x4000, + DISPATCH_P2P_PTZ_PRESET_DEL = 0x4001, + DISPATCH_P2P_PTZ_SET_CRUISE_STAY_TIME = 0x4003, + DISPATCH_P2P_PTZ_CRUISE_START = 0x4004, + DISPATCH_P2P_PTZ_CRUISE_STOP = 0x4005, + DISPATCH_P2P_PTZ_SET_CURISE_PERIOD = 0x400a, + DISPATCH_P2P_PTZ_SET_MOTION_TRACK = 0x400b, + BABYCRY_START_MSG = 0x6002, + ABNORMAL_SOUND_START_MSG = 0x6004, + CLOUD_DEBUG_ALARM = 0x6006 +} MSG_TYPE; + +typedef struct +{ + int dstMid; + int srcMid; + short mainOp; + short subOp; + int msgLength; +} mqueue_msg_header_t; + +void dump_string(char *source_file, const char *func, int line, char *text, ...); +int cloud_send_msg(mqd_t mqfd, MSG_TYPE msg_type, char *payload, int payload_len); +int cloud_send_msg_ex(mqd_t mqfd, MSG_TYPE msg_type, short sub, char *payload, int payload_len); + +#endif diff --git a/src/snapshot/snapshot/imggrabber.c b/src/snapshot/snapshot/imggrabber.c index 9f8f380..ad9b844 100644 --- a/src/snapshot/snapshot/imggrabber.c +++ b/src/snapshot/snapshot/imggrabber.c @@ -166,6 +166,8 @@ #define BUFFER_FILE "/tmp/view" +#define USE_NATIVE_API 1 + typedef struct { int sps_addr; int sps_len; @@ -666,8 +668,9 @@ int main(int argc, char **argv) { // Check if snapshot is low res if (access("/tmp/snapshot.low", F_OK ) == 0 ) { - fprintf(stderr, "Snapshot is low res\n"); + fprintf(stderr, "Snapshot is low res and watermark is disabled\n"); resolution = RESOLUTION_LOW; + watermark = 0; } // Check if the process is already running @@ -677,6 +680,35 @@ int main(int argc, char **argv) { return 0; } +// This method doesn't have performace issue +// But: +// - is not available for high resolution +// - it's not possible to add watermarks +#ifdef USE_NATIVE_API + if ((resolution == RESOLUTION_LOW) && (watermark == 0)) { + int old_stdout = dup(1); + int nj; + char sj[1024]; + FILE *aj; + + fprintf(stderr, "Using native api\n"); + + freopen ("/dev/null", "w", stdout); + main_cloud_cap_pic("/tmp/sd/snapshot.tmp"); + usleep(500000); + fclose(stdout); + stdout = fdopen(old_stdout, "w"); + + aj = fopen("/tmp/sd/snapshot.tmp", "r"); + while ((nj = fread(sj, 1, sizeof(sj), aj))) { + fwrite(sj, 1, nj, stdout); + } + fclose(aj); + remove("/tmp/sd/snapshot.tmp"); + return 0; + } +#endif + if (resolution == RESOLUTION_LOW) { table_offset = table_low_offset; stream_offset = stream_low_offset; From 15e07ff6e9e2d5d39af4fb8da58cb7c325cf32cb Mon Sep 17 00:00:00 2001 From: roleo Date: Tue, 5 Sep 2023 17:24:36 +0200 Subject: [PATCH 21/81] Remove option: watermark for onvif snapshot --- src/static/static/home/yi-hack-v5/etc/system.conf | 1 - .../static/home/yi-hack-v5/script/check_conf.sh | 1 - src/static/static/home/yi-hack-v5/script/system.sh | 12 ++++-------- src/www/httpd/htdocs/pages/configurations.html | 13 ------------- 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/etc/system.conf b/src/static/static/home/yi-hack-v5/etc/system.conf index 562bf1f..3e8ef99 100644 --- a/src/static/static/home/yi-hack-v5/etc/system.conf +++ b/src/static/static/home/yi-hack-v5/etc/system.conf @@ -13,7 +13,6 @@ ONVIF=no ONVIF_WSDD=no ONVIF_PROFILE=high ONVIF_NETIF=wlan0 -ONVIF_WM_SNAPSHOT=no SNAPSHOT=yes SNAPSHOT_LOW=no NTPD=no diff --git a/src/static/static/home/yi-hack-v5/script/check_conf.sh b/src/static/static/home/yi-hack-v5/script/check_conf.sh index 4adf9ea..4120d12 100755 --- a/src/static/static/home/yi-hack-v5/script/check_conf.sh +++ b/src/static/static/home/yi-hack-v5/script/check_conf.sh @@ -20,7 +20,6 @@ ONVIF=no ONVIF_WSDD=yes ONVIF_PROFILE=high ONVIF_NETIF=wlan0 -ONVIF_WM_SNAPSHOT=yes SNAPSHOT=yes SNAPSHOT_LOW=no NTPD=yes diff --git a/src/static/static/home/yi-hack-v5/script/system.sh b/src/static/static/home/yi-hack-v5/script/system.sh index d934ab2..02861d0 100755 --- a/src/static/static/home/yi-hack-v5/script/system.sh +++ b/src/static/static/home/yi-hack-v5/script/system.sh @@ -245,10 +245,6 @@ if [[ $ONVIF_PORT != "80" ]] ; then D_ONVIF_PORT=:$ONVIF_PORT fi -if [[ $(get_config ONVIF_WM_SNAPSHOT) == "yes" ]] ; then - WATERMARK="&watermark=yes" -fi - if [[ $(get_config SNAPSHOT) == "no" ]] ; then touch /tmp/snapshot.disabled fi @@ -281,20 +277,20 @@ if [[ $(get_config RTSP) == "yes" ]] ; then fi if [[ $(get_config RTSP_STREAM) == "low" ]]; then h264grabber -r low -m $MODEL_SUFFIX -f & - ONVIF_PROFILE_1="--name Profile_1 --width 640 --height 360 --url rtsp://%s$D_RTSP_PORT/ch0_1.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=low$WATERMARK --type H264" + ONVIF_PROFILE_1="--name Profile_1 --width 640 --height 360 --url rtsp://%s$D_RTSP_PORT/ch0_1.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=low&watermark=yes --type H264" fi if [[ $(get_config RTSP_STREAM) == "high" ]]; then h264grabber -r high -m $MODEL_SUFFIX -f & - ONVIF_PROFILE_0="--name Profile_0 --width $HIGHWIDTH --height $HIGHHEIGHT --url rtsp://%s$D_RTSP_PORT/ch0_0.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=high$WATERMARK --type H264" + ONVIF_PROFILE_0="--name Profile_0 --width $HIGHWIDTH --height $HIGHHEIGHT --url rtsp://%s$D_RTSP_PORT/ch0_0.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=high&watermark=yes --type H264" fi if [[ $(get_config RTSP_STREAM) == "both" ]]; then h264grabber -r low -m $MODEL_SUFFIX -f & h264grabber -r high -m $MODEL_SUFFIX -f & if [[ $(get_config ONVIF_PROFILE) == "low" ]] || [[ $(get_config ONVIF_PROFILE) == "both" ]] ; then - ONVIF_PROFILE_1="--name Profile_1 --width 640 --height 360 --url rtsp://%s$D_RTSP_PORT/ch0_1.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=low$WATERMARK --type H264" + ONVIF_PROFILE_1="--name Profile_1 --width 640 --height 360 --url rtsp://%s$D_RTSP_PORT/ch0_1.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=low&watermark=yes --type H264" fi if [[ $(get_config ONVIF_PROFILE) == "high" ]] || [[ $(get_config ONVIF_PROFILE) == "both" ]] ; then - ONVIF_PROFILE_0="--name Profile_0 --width $HIGHWIDTH --height $HIGHHEIGHT --url rtsp://%s$D_RTSP_PORT/ch0_0.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=high$WATERMARK --type H264" + ONVIF_PROFILE_0="--name Profile_0 --width $HIGHWIDTH --height $HIGHHEIGHT --url rtsp://%s$D_RTSP_PORT/ch0_0.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=high&watermark=yes --type H264" fi rRTSPServer -r $RRTSP_RES -a $RRTSP_AUDIO -p $RRTSP_PORT -u $RRTSP_USER -w $RRTSP_PWD & fi diff --git a/src/www/httpd/htdocs/pages/configurations.html b/src/www/httpd/htdocs/pages/configurations.html index 989e240..5a53b93 100644 --- a/src/www/httpd/htdocs/pages/configurations.html +++ b/src/www/httpd/htdocs/pages/configurations.html @@ -159,19 +159,6 @@

General

- - ONVIF watermark - - - - Add watermark to snapshot. - - - Snapshot From c821423f61da34d030435b4081c5290e9221b5f4 Mon Sep 17 00:00:00 2001 From: roleo Date: Tue, 5 Sep 2023 17:25:02 +0200 Subject: [PATCH 22/81] Change label for "Force low res snapshot" --- src/www/httpd/htdocs/pages/configurations.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www/httpd/htdocs/pages/configurations.html b/src/www/httpd/htdocs/pages/configurations.html index 5a53b93..2819fac 100644 --- a/src/www/httpd/htdocs/pages/configurations.html +++ b/src/www/httpd/htdocs/pages/configurations.html @@ -183,7 +183,7 @@

General

- Take low resolution snapshots only (useful for avoiding memory problems). + Take low resolution snapshots only and no watermark (useful for avoiding memory problems). From 63213ca4b62245b752d05ecb25d957f983c986f0 Mon Sep 17 00:00:00 2001 From: alienatedsec <73167064+alienatedsec@users.noreply.github.com> Date: Sat, 16 Sep 2023 23:01:20 +0100 Subject: [PATCH 23/81] [Change] launch.sh optimised to kill gently Changes to be committed: modified: src/static/static/home/yi-hack-v5/script/launch.sh --- .../static/home/yi-hack-v5/script/launch.sh | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/script/launch.sh b/src/static/static/home/yi-hack-v5/script/launch.sh index c267b0f..193d00c 100755 --- a/src/static/static/home/yi-hack-v5/script/launch.sh +++ b/src/static/static/home/yi-hack-v5/script/launch.sh @@ -1,3 +1,6 @@ +#!/bin/sh +# +# 0.4.1b # # This file is part of yi-hack-v5 (https://github.com/alienatedsec/yi-hack-v5). # Copyright (c) 2021-2023 alienatedsec - v5 specific @@ -14,19 +17,23 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Launch - version 0.3.8 -# -#!/bin/sh + kill_all() { - # Kills all running instances of app1 and app2 - killall wd_rtsp.sh - killall rRTSPServer - killall h264grabber + # Kills all running instances + killall -s SIGTERM wd_rtsp.sh + killall -s SIGTERM rRTSPServer + killall -s SIGTERM h264grabber + + sleep 10 + + killall -s SIGKILL wd_rtsp.sh + killall -s SIGKILL rRTSPServer + killall -s SIGKILL h264grabber } launch_apps() { - # Launches app1 and app2 with different commands + # Launches apps with different commands if [ "$execute_audio" = true ]; then h264grabber -r audio -m "$model" -f & fi @@ -62,7 +69,7 @@ launch_apps() { } -# Read model name from file +# Read model and versions from files model=$(cat /home/app/.camver) version_cam=$(cat /home/yi-hack-v5/version) version_sd=$(cat /tmp/sd/yi-hack-v5/version) From 26009c1e3c4e2fbe635ea7f601a1b7776c7e85c9 Mon Sep 17 00:00:00 2001 From: alienatedsec <73167064+alienatedsec@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:36:53 +0100 Subject: [PATCH 24/81] [Change] Tuning launch.sh Changes to be committed: modified: src/static/static/home/yi-hack-v5/script/launch.sh --- .../static/home/yi-hack-v5/script/launch.sh | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/script/launch.sh b/src/static/static/home/yi-hack-v5/script/launch.sh index 193d00c..b0def59 100755 --- a/src/static/static/home/yi-hack-v5/script/launch.sh +++ b/src/static/static/home/yi-hack-v5/script/launch.sh @@ -21,48 +21,62 @@ kill_all() { # Kills all running instances + echo Round 1 - Killing using SIGTERM killall -s SIGTERM wd_rtsp.sh killall -s SIGTERM rRTSPServer killall -s SIGTERM h264grabber - - sleep 10 - + echo Round 1 - Finished + sleep 2 + echo Round 2 - Killing using SIGKILL killall -s SIGKILL wd_rtsp.sh killall -s SIGKILL rRTSPServer killall -s SIGKILL h264grabber + echo Round 2 - Finished } launch_apps() { # Launches apps with different commands if [ "$execute_audio" = true ]; then + echo Launching - h264grabber -r audio -m "$model" -f & h264grabber -r audio -m "$model" -f & fi if [ "$settings" = "high" ]; then debug_flag="" if [ "$debug_mode" = true ]; then - debug_flag="-d 7" + debug_flag="-d "$debug_level"" fi + echo Launching - h264grabber -r high -m "$model" -f & h264grabber -r high -m "$model" -f & + sleep 1 + echo Launching - rRTSPServer -r high -a "$enable_audio" -p 554 -u -w $debug_flag & rRTSPServer -r high -a "$enable_audio" -p 554 -u -w $debug_flag & fi if [ "$settings" = "low" ]; then debug_flag="" if [ "$debug_mode" = true ]; then - debug_flag="-d 7" + debug_flag="-d "$debug_level"" fi + echo Launching - h264grabber -r low -m "$model" -f & h264grabber -r low -m "$model" -f & + sleep 1 + echo Launching - rRTSPServer -r low -a "$enable_audio" -p 554 -u -w $debug_flag & rRTSPServer -r low -a "$enable_audio" -p 554 -u -w $debug_flag & fi if [ "$settings" = "both" ]; then debug_flag="" if [ "$debug_mode" = true ]; then - debug_flag="-d 7" + debug_flag="-d "$debug_level"" fi + echo Launching - h264grabber -r low -m "$model" -f & h264grabber -r low -m "$model" -f & + sleep 1 + echo Launching - h264grabber -r high -m "$model" -f & h264grabber -r high -m "$model" -f & + sleep 1 + echo Launching - rRTSPServer -r both -a "$enable_audio" -p 554 -u -w $debug_flag & rRTSPServer -r both -a "$enable_audio" -p 554 -u -w $debug_flag & fi @@ -97,6 +111,11 @@ elif [ "$operation" = "l" ] || [ "$operation" = "L" ]; then if [ "$debug_choice" = "y" ] || [ "$debug_choice" = "Y" ]; then debug_mode=true + read -p "Provide debug level (0-15): " debug_level + while ! [ "$debug_level" -ge 0 -a "$debug_level" -le 15 ] 2>/dev/null; do + echo "Invalid input. Please enter a debug level between 0 and 15." + read -p "Provide debug level (0-15): " debug_level + done else debug_mode=false fi From db856f3dbde9e091cd52cf74411d363c39203347 Mon Sep 17 00:00:00 2001 From: alienatedsec <73167064+alienatedsec@users.noreply.github.com> Date: Sat, 23 Sep 2023 15:19:37 +0100 Subject: [PATCH 25/81] [New] Compile specific module - thanks @thelittlefireman Changes to be committed: modified: scripts/compile.sh --- scripts/compile.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/compile.sh b/scripts/compile.sh index 6c7972d..5e6fb2c 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -39,6 +39,7 @@ compile_module() printf "MOD_COMPILE: %s\n" "$MOD_COMPILE" printf "MOD_INSTALL: %s\n" "$MOD_INSTALL" + echo "Compile $MOD_NAME" cd "$MOD_DIR" if [ ! -f $MOD_INIT ]; then @@ -89,10 +90,22 @@ mkdir -p "$(get_script_dir)/../build/home" mkdir -p "$(get_script_dir)/../build/rootfs" SRC_DIR=$(get_script_dir)/../src +SELECTED_MODULE=$1 +if [ -n ${SELECTED_MODULE} ]; then + echo "SELECTED_MODULE: $SELECTED_MODULE" +fi for SUB_DIR in $SRC_DIR/* ; do if [ -d ${SUB_DIR} ]; then # Will not run if no directories are available - compile_module $(normalize_path "$SUB_DIR") || exit 1 + if [ -n ${SELECTED_MODULE} ]; then + if [[ $SUB_DIR == *"$SELECTED_MODULE"* ]]; then + compile_module $(normalize_path "$SUB_DIR") || exit 1 + else + echo "Skip $SUB_DIR" + fi + else + compile_module $(normalize_path "$SUB_DIR") || exit 1 + fi fi done From 54b1e653d8aa6136537568b3d8a4b8d7b66bb7cb Mon Sep 17 00:00:00 2001 From: roleo Date: Thu, 28 Sep 2023 18:32:12 +0200 Subject: [PATCH 26/81] Improve RTSP server --- src/rRTSPServer/Makefile.rRTSPServer | 4 +- .../ADTSAudioFifoServerMediaSubsession.hh | 0 .../include/ADTSAudioFifoSource.hh | 0 .../include/ByteStreamFifoSource.hh | 0 .../H264VideoFifoServerMediaSubsession.hh | 0 src/rRTSPServer/include/presentationTime.hh | 0 .../ADTSAudioFifoServerMediaSubsession.cpp | 1 + src/rRTSPServer/src/ADTSAudioFifoSource.cpp | 122 +++++++++--------- src/rRTSPServer/src/ByteStreamFifoSource.cpp | 4 + .../H264VideoFifoServerMediaSubsession.cpp | 2 +- src/rRTSPServer/src/rRTSPServer.cpp | 4 +- 11 files changed, 73 insertions(+), 64 deletions(-) mode change 100755 => 100644 src/rRTSPServer/Makefile.rRTSPServer mode change 100755 => 100644 src/rRTSPServer/include/ADTSAudioFifoServerMediaSubsession.hh mode change 100755 => 100644 src/rRTSPServer/include/ADTSAudioFifoSource.hh mode change 100755 => 100644 src/rRTSPServer/include/ByteStreamFifoSource.hh mode change 100755 => 100644 src/rRTSPServer/include/H264VideoFifoServerMediaSubsession.hh mode change 100755 => 100644 src/rRTSPServer/include/presentationTime.hh diff --git a/src/rRTSPServer/Makefile.rRTSPServer b/src/rRTSPServer/Makefile.rRTSPServer old mode 100755 new mode 100644 index 9cecfac..7fab00a --- a/src/rRTSPServer/Makefile.rRTSPServer +++ b/src/rRTSPServer/Makefile.rRTSPServer @@ -1,5 +1,5 @@ ##### Change the following for your environment: -COMPILE_OPTS = $(INCLUDES) -I. -I./include -O2 -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DRTP_PAYLOAD_MAX_SIZE=1352 -DNEWLOCALE_NOT_USED +COMPILE_OPTS = $(INCLUDES) -I. -I./include -O1 -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DRTP_PAYLOAD_MAX_SIZE=1352 -DNEWLOCALE_NOT_USED C = c C_COMPILER = $(CC) C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS) @@ -73,7 +73,7 @@ livemedia: rRTSPServer_OBJS = src/rRTSPServer.$(OBJ) \ src/ADTSAudioFifoServerMediaSubsession.$(OBJ) src/ADTSAudioFifoSource.$(OBJ) \ - src/DummySink.$(OBJ) src/ByteStreamFifoSource.$(OBJ) src/H264VideoFifoServerMediaSubsession.$(OBJ) \ + src/ByteStreamFifoSource.$(OBJ) src/H264VideoFifoServerMediaSubsession.$(OBJ) \ rRTSPServer$(EXE): $(rRTSPServer_OBJS) $(LOCAL_LIBS) $(LINK)$@ $(CONSOLE_LINK_OPTS) $(rRTSPServer_OBJS) $(LIBS) -lpthread diff --git a/src/rRTSPServer/include/ADTSAudioFifoServerMediaSubsession.hh b/src/rRTSPServer/include/ADTSAudioFifoServerMediaSubsession.hh old mode 100755 new mode 100644 diff --git a/src/rRTSPServer/include/ADTSAudioFifoSource.hh b/src/rRTSPServer/include/ADTSAudioFifoSource.hh old mode 100755 new mode 100644 diff --git a/src/rRTSPServer/include/ByteStreamFifoSource.hh b/src/rRTSPServer/include/ByteStreamFifoSource.hh old mode 100755 new mode 100644 diff --git a/src/rRTSPServer/include/H264VideoFifoServerMediaSubsession.hh b/src/rRTSPServer/include/H264VideoFifoServerMediaSubsession.hh old mode 100755 new mode 100644 diff --git a/src/rRTSPServer/include/presentationTime.hh b/src/rRTSPServer/include/presentationTime.hh old mode 100755 new mode 100644 diff --git a/src/rRTSPServer/src/ADTSAudioFifoServerMediaSubsession.cpp b/src/rRTSPServer/src/ADTSAudioFifoServerMediaSubsession.cpp index 19475ac..44e29c2 100755 --- a/src/rRTSPServer/src/ADTSAudioFifoServerMediaSubsession.cpp +++ b/src/rRTSPServer/src/ADTSAudioFifoServerMediaSubsession.cpp @@ -20,6 +20,7 @@ along with this library; if not, write to the Free Software Foundation, Inc., // Implementation #include "ADTSAudioFifoServerMediaSubsession.hh" +#include "ADTSAudioStreamDiscreteFramer.hh" #include "ADTSAudioFifoSource.hh" #include "MPEG4GenericRTPSink.hh" #include "FramedFilter.hh" diff --git a/src/rRTSPServer/src/ADTSAudioFifoSource.cpp b/src/rRTSPServer/src/ADTSAudioFifoSource.cpp index d706cd5..52e8262 100755 --- a/src/rRTSPServer/src/ADTSAudioFifoSource.cpp +++ b/src/rRTSPServer/src/ADTSAudioFifoSource.cpp @@ -212,90 +212,94 @@ void ADTSAudioFifoSource::doReadFromFile() { #else if (read(fileno(fFid), headers, sizeof headers) < (signed) sizeof headers) { #endif - // The input source has ended: - handleClosure(); - return; - } + fFrameSize = 0; + fNumTruncatedBytes = 0; +// // The input source has ended: +// handleClosure(); +// return; + } else { - // Extract important fields from the headers: - Boolean protection_absent = headers[1]&0x01; - u_int16_t frame_length - = ((headers[3]&0x03)<<11) | (headers[4]<<3) | ((headers[5]&0xE0)>>5); - u_int16_t syncword = (headers[0]<<4) | (headers[1]>>4); - if (debug & 4) fprintf(stderr, "Read frame: syncword 0x%x, protection_absent %d, frame_length %d\n", syncword, protection_absent, frame_length); - if (syncword != 0xFFF) { - fprintf(stderr, "WARNING: Bad syncword! Try to recover sync.\n"); - // Resync - while (1) { + // Extract important fields from the headers: + Boolean protection_absent = headers[1]&0x01; + u_int16_t frame_length + = ((headers[3]&0x03)<<11) | (headers[4]<<3) | ((headers[5]&0xE0)>>5); + u_int16_t syncword = (headers[0]<<4) | (headers[1]>>4); + if (debug & 4) fprintf(stderr, "Read frame: syncword 0x%x, protection_absent %d, frame_length %d\n", syncword, protection_absent, frame_length); + if (syncword != 0xFFF) { + fprintf(stderr, "WARNING: Bad syncword! Try to recover sync.\n"); + // Resync + while (1) { #ifdef READ_FROM_FILES_SYNCHRONOUSLY - fread(headers, 1, 1, fFid); + fread(headers, 1, 1, fFid); #else - read(fileno(fFid), headers, 1); + read(fileno(fFid), headers, 1); #endif - if (headers[0] == 0xFF) { + if (headers[0] == 0xFF) { #ifdef READ_FROM_FILES_SYNCHRONOUSLY - fread(&headers[1], 1, 1, fFid); + fread(&headers[1], 1, 1, fFid); #else - read(fileno(fFid), &headers[1], 1); + read(fileno(fFid), &headers[1], 1); #endif - // Check the 'syncword': - if ((headers[1]&0xF0) == 0xF0) { + // Check the 'syncword': + if ((headers[1]&0xF0) == 0xF0) { #ifdef READ_FROM_FILES_SYNCHRONOUSLY - fread(&headers[2], 1, sizeof(headers) - 2, fFid); + fread(&headers[2], 1, sizeof(headers) - 2, fFid); #else - read(fileno(fFid), &headers[2], sizeof(headers) - 2); + read(fileno(fFid), &headers[2], sizeof(headers) - 2); #endif - break; + break; + } } + usleep(1000); } - usleep(10000); } - } - unsigned numBytesToRead - = frame_length > sizeof headers ? frame_length - sizeof headers : 0; + unsigned numBytesToRead + = frame_length > sizeof headers ? frame_length - sizeof headers : 0; - // If there's a 'crc_check' field, skip it: - if (!protection_absent) { - unsigned char null[2]; + // If there's a 'crc_check' field, skip it: + if (!protection_absent) { + unsigned char null[2]; #ifdef READ_FROM_FILES_SYNCHRONOUSLY - fread(null, 1, 2, fFid); + fread(null, 1, 2, fFid); #else - read(fileno(fFid), null, 2); + read(fileno(fFid), null, 2); #endif - numBytesToRead = numBytesToRead > 2 ? numBytesToRead - 2 : 0; - } + numBytesToRead = numBytesToRead > 2 ? numBytesToRead - 2 : 0; + } - // Next, read the raw frame data into the buffer provided: - if (numBytesToRead > fMaxSize) { - fNumTruncatedBytes = numBytesToRead - fMaxSize; - numBytesToRead = fMaxSize; - } + // Next, read the raw frame data into the buffer provided: + if (numBytesToRead > fMaxSize) { + fNumTruncatedBytes = numBytesToRead - fMaxSize; + numBytesToRead = fMaxSize; + } #ifdef READ_FROM_FILES_SYNCHRONOUSLY - int numBytesRead = fread(fTo, 1, numBytesToRead, fFid); + int numBytesRead = fread(fTo, 1, numBytesToRead, fFid); #else - int numBytesRead = read(fileno(fFid), fTo, numBytesToRead); + int numBytesRead = read(fileno(fFid), fTo, numBytesToRead); #endif - if (numBytesRead < 0) numBytesRead = 0; - fFrameSize = numBytesRead; - fNumTruncatedBytes += numBytesToRead - numBytesRead; - - // Set the 'presentation time': - if (fPresentationTime.tv_sec == 0 && fPresentationTime.tv_usec == 0) { - // This is the first frame, so use the current time: - gettimeofday(&fPresentationTime, NULL); - } else { + if (numBytesRead < 0) numBytesRead = 0; + fFrameSize = numBytesRead; + fNumTruncatedBytes += numBytesToRead - numBytesRead; + + // Set the 'presentation time': + if (fPresentationTime.tv_sec == 0 && fPresentationTime.tv_usec == 0) { + // This is the first frame, so use the current time: + gettimeofday(&fPresentationTime, NULL); + } else { #ifndef PRES_TIME_CLOCK - // Increment by the play time of the previous frame: - unsigned uSeconds = fPresentationTime.tv_usec + fuSecsPerFrame; - fPresentationTime.tv_sec += uSeconds/1000000; - fPresentationTime.tv_usec = uSeconds%1000000; + // Increment by the play time of the previous frame: + unsigned uSeconds = fPresentationTime.tv_usec + fuSecsPerFrame; + fPresentationTime.tv_sec += uSeconds/1000000; + fPresentationTime.tv_usec = uSeconds%1000000; #else - // Use system clock to set presentation time - gettimeofday(&fPresentationTime, NULL); + // Use system clock to set presentation time + gettimeofday(&fPresentationTime, NULL); #endif - } + } + if (debug & 4) fprintf(stderr, "AAC frame - fPresentationTime, sec = %ld, usec = %ld\n", fPresentationTime.tv_sec, fPresentationTime.tv_usec); - fDurationInMicroseconds = fuSecsPerFrame; + fDurationInMicroseconds = fuSecsPerFrame; + } // Switch to another task, and inform the reader that he has data: #ifdef READ_FROM_FILES_SYNCHRONOUSLY diff --git a/src/rRTSPServer/src/ByteStreamFifoSource.cpp b/src/rRTSPServer/src/ByteStreamFifoSource.cpp index c30ed73..ee4e58d 100755 --- a/src/rRTSPServer/src/ByteStreamFifoSource.cpp +++ b/src/rRTSPServer/src/ByteStreamFifoSource.cpp @@ -27,6 +27,8 @@ along with this library; if not, write to the Free Software Foundation, Inc., ////////// ByteStreamFifoSource ////////// +extern int debug; + ByteStreamFifoSource* ByteStreamFifoSource::createNew(UsageEnvironment& env, char const* fileName, unsigned preferredFrameSize, @@ -170,7 +172,9 @@ void ByteStreamFifoSource::doReadFromFile() { // We don't know a specific play time duration for this data, // so just record the current time as being the 'presentation time': gettimeofday(&fPresentationTime, NULL); + fDurationInMicroseconds = fPlayTimePerFrame; } + if (debug & 4) fprintf(stderr, "h264 frame - fPresentationTime, sec = %ld, usec = %ld\n", fPresentationTime.tv_sec, fPresentationTime.tv_usec); // Inform the reader that he has data: #ifdef READ_FROM_FILES_SYNCHRONOUSLY diff --git a/src/rRTSPServer/src/H264VideoFifoServerMediaSubsession.cpp b/src/rRTSPServer/src/H264VideoFifoServerMediaSubsession.cpp index a25e05e..0ac2044 100755 --- a/src/rRTSPServer/src/H264VideoFifoServerMediaSubsession.cpp +++ b/src/rRTSPServer/src/H264VideoFifoServerMediaSubsession.cpp @@ -106,7 +106,7 @@ FramedSource* H264VideoFifoServerMediaSubsession::createNewStreamSource(unsigned estBitrate = 500; // kbps, estimate // Create the video source: - ByteStreamFifoSource* fileSource = ByteStreamFifoSource::createNew(envir(), fFileName); + ByteStreamFifoSource* fileSource = ByteStreamFifoSource::createNew(envir(), fFileName, 0, 50000); if (fileSource == NULL) return NULL; fFileSize = fileSource->fileSize(); diff --git a/src/rRTSPServer/src/rRTSPServer.cpp b/src/rRTSPServer/src/rRTSPServer.cpp index 9713e03..4c1f83c 100755 --- a/src/rRTSPServer/src/rRTSPServer.cpp +++ b/src/rRTSPServer/src/rRTSPServer.cpp @@ -64,10 +64,10 @@ StreamReplicator* startReplicatorStream(const char* inputAudioFileName) { FramedSource* source = replicator->createStreamReplica(); // Then create a 'dummy sink' object to receive the replica stream: - MediaSink* sink = DummySink::createNew(*env, "dummy"); +// MediaSink* sink = DummySink::createNew(*env, "dummy"); // Now, start playing, feeding the sink object from the source: - sink->startPlaying(*source, NULL, NULL); +// sink->startPlaying(*source, NULL, NULL); return replicator; } From e6ebbce764ecd559ec5d612619caba1f9197b154 Mon Sep 17 00:00:00 2001 From: roleo Date: Thu, 28 Sep 2023 18:32:54 +0200 Subject: [PATCH 27/81] Minor fixes --- src/static/static/home/yi-hack-v5/script/cloudAPI_fake | 4 ++-- src/static/static/home/yi-hack-v5/script/system.sh | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/script/cloudAPI_fake b/src/static/static/home/yi-hack-v5/script/cloudAPI_fake index 748167d..5bfc867 100755 --- a/src/static/static/home/yi-hack-v5/script/cloudAPI_fake +++ b/src/static/static/home/yi-hack-v5/script/cloudAPI_fake @@ -95,8 +95,8 @@ elif [ "$c" = "142" ]; then TZP=$(TZ="$TIMEZONE" date +%z) TZP_SET=$(echo ${TZP:1:2} ${TZP:3:2} | awk '{ print ($1*3600+$2*60) }') TZP_GMT=$(echo GMT${TZP:0:1}${TZP:1:2}:${TZP:3:2}) - echo '{"code":"20000","data":{"timezone":"'$TZP_GMT'","language":"en-US","tz_offset":'$TZP_SET'000,"css_flag":0,"css_mode":0,"appParam":"","doorbellCoolingDuration":"0"}}' - #echo '{"code":"20000","data":{"timezone":"'$TZP_GMT'","language":"en-US","tz_offset":'$TZP_SET'000,"css_flag":0,"css_mode":0,"appParam":"","doorbellCoolingDuration":"0","allowFeature":{"Vehicle":0,"Animal":0,"Person":1}}}' + #echo '{"code":"20000","data":{"timezone":"'$TZP_GMT'","language":"en-US","tz_offset":'$TZP_SET'000,"css_flag":0,"css_mode":0,"appParam":"","doorbellCoolingDuration":"0"}}' + echo '{"code":"20000","data":{"timezone":"'$TZP_GMT'","language":"en-US","tz_offset":'$TZP_SET'000,"css_flag":0,"css_mode":0,"appParam":"","doorbellCoolingDuration":"0","allowFeature":{"Vehicle":0,"Animal":0,"Person":1}}}' #{"code":"20000","data":{"timezone":"GMT+01:00","language":"en-US","tz_offset":3600000,"css_flag":0,"css_mode":0,"appParam":{"schedule_power":{"schedule_power_on":{"enable":0,"repeater":"","time":"2212220800"},"schedule_power_off":{"enable":0,"repeater":"","time":"2212222200"}}},"doorbellCoolingDuration":"0","model":"38","allowFeature":{"Vehicle":0,"Animal":0,"Person":1}}} elif [ "$c" = "304" ]; then #CMD_do_update_event_v4 diff --git a/src/static/static/home/yi-hack-v5/script/system.sh b/src/static/static/home/yi-hack-v5/script/system.sh index 1691a8a..b5d3771 100755 --- a/src/static/static/home/yi-hack-v5/script/system.sh +++ b/src/static/static/home/yi-hack-v5/script/system.sh @@ -230,8 +230,6 @@ mkdir -p $YI_HACK_PREFIX/etc/dropbear dropbear -R -B fi -ipc_multiplexer & - mqttv4 & if [[ $(get_config MQTT) == "yes" ]] ; then mqtt-config & From 9c4fff63880b10779c4a4802f22503fb29cd61d6 Mon Sep 17 00:00:00 2001 From: roleo Date: Thu, 28 Sep 2023 18:33:45 +0200 Subject: [PATCH 28/81] Remove unused options when empty password --- .../static/home/yi-hack-v5/script/system.sh | 10 ++++++--- .../static/home/yi-hack-v5/script/wd_rtsp.sh | 22 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/static/static/home/yi-hack-v5/script/system.sh b/src/static/static/home/yi-hack-v5/script/system.sh index b5d3771..c2455b1 100755 --- a/src/static/static/home/yi-hack-v5/script/system.sh +++ b/src/static/static/home/yi-hack-v5/script/system.sh @@ -260,8 +260,12 @@ RRTSP_MODEL=$MODEL_SUFFIX RRTSP_RES=$(get_config RTSP_STREAM) RRTSP_AUDIO=$(get_config RTSP_AUDIO) RRTSP_PORT=$(get_config RTSP_PORT) -RRTSP_USER=$USERNAME -RRTSP_PWD=$PASSWORD +if [ ! -z $USERNAME ]; then + RRTSP_USER="-u $USERNAME" +fi +if [ ! -z $PASSWORD ]; then + RRTSP_PWD="-w $PASSWORD" +fi # some non-working functions to be added later @@ -295,7 +299,7 @@ if [[ $(get_config RTSP) == "yes" ]] ; then if [[ $(get_config ONVIF_PROFILE) == "high" ]] || [[ $(get_config ONVIF_PROFILE) == "both" ]] ; then ONVIF_PROFILE_0="--name Profile_0 --width $HIGHWIDTH --height $HIGHHEIGHT --url rtsp://%s$D_RTSP_PORT/ch0_0.h264 --snapurl http://%s$D_HTTPD_PORT/cgi-bin/snapshot.sh?res=high&watermark=yes --type H264" fi - rRTSPServer -r $RRTSP_RES -a $RRTSP_AUDIO -p $RRTSP_PORT -u $RRTSP_USER -w $RRTSP_PWD & + rRTSPServer -r $RRTSP_RES -a $RRTSP_AUDIO -p $RRTSP_PORT $RRTSP_USER $RRTSP_PWD & fi #Seems to be killing the resource - fixed via #153 $YI_HACK_PREFIX/script/wd_rtsp.sh & diff --git a/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh b/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh index 838cf5b..ed028f5 100755 --- a/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh +++ b/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh @@ -27,17 +27,26 @@ COUNTER=0 COUNTER_LIMIT=10 INTERVAL=10 +if [[ "$(get_config USERNAME)" != "" ]] ; then + USERNAME=$(get_config USERNAME) + PASSWORD=$(get_config PASSWORD) +fi + RRTSP_RES=$(get_config RTSP_STREAM) RRTSP_AUDIO=$(get_config RTSP_AUDIO) RRTSP_MODEL=$MODEL_SUFFIX RRTSP_PORT=$(get_config RTSP_PORT) -RRTSP_USER=$(get_config USERNAME) -RRTSP_PWD=$(get_config PASSWORD) +if [ ! -z $USERNAME ]; then + RRTSP_USER="-u $USERNAME" +fi +if [ ! -z $PASSWORD ]; then + RRTSP_PWD="-w $PASSWORD" +fi restart_rtsp() { killall -q rRTSPServer - rRTSPServer -r $RRTSP_RES -a $RRTSP_AUDIO -p $RRTSP_PORT -u $RRTSP_USER -w $RRTSP_PWD & + rRTSPServer -r $RRTSP_RES -a $RRTSP_AUDIO -p $RRTSP_PORT $RRTSP_USER $RRTSP_PWD & } restart_grabber() @@ -57,7 +66,7 @@ restart_grabber() if [[ $(get_config RTSP_AUDIO) == "yes" ]]; then h264grabber -r AUDIO -m $MODEL_SUFFIX -f & fi - rRTSPServer -r $RRTSP_RES -a $RRTSP_AUDIO -p $RRTSP_PORT -u $RRTSP_USER -w $RRTSP_PWD & + rRTSPServer -r $RRTSP_RES -a $RRTSP_AUDIO -p $RRTSP_PORT $RRTSP_USER $RRTSP_PWD & } restart_cloud() @@ -139,11 +148,6 @@ if [[ $(get_config RTSP) == "no" ]] ; then exit fi -if [[ "$(get_config USERNAME)" != "" ]] ; then - USERNAME=$(get_config USERNAME) - PASSWORD=$(get_config PASSWORD) -fi - # Re-enabled when its starting echo "$(date +'%Y-%m-%d %H:%M:%S') - Starting RTSP watchdog..." >> $LOG_FILE From 434db6d2ac1c70da9d7895087fcbf48f7fe562a5 Mon Sep 17 00:00:00 2001 From: roleo Date: Thu, 28 Sep 2023 18:34:01 +0200 Subject: [PATCH 29/81] Add mqttv4 to watchdog --- .../static/home/yi-hack-v5/script/wd_rtsp.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh b/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh index ed028f5..df33a4e 100755 --- a/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh +++ b/src/static/static/home/yi-hack-v5/script/wd_rtsp.sh @@ -79,6 +79,11 @@ restart_cloud() fi } +restart_mqttv4() +{ + mqttv4 & +} + check_rtsp() { SOCKET=`/bin/netstat -an 2>&1 | grep ":$RTSP_PORT " | grep LISTEN | grep -c ^` @@ -144,6 +149,18 @@ check_grabber() fi } +check_mqttv4() +{ + PS=`ps | grep mqttv4 | grep -v grep | grep -c ^` + + if [ $PS -eq 0 ]; then + echo "$(date +'%Y-%m-%d %H:%M:%S') - No running processes, restarting mqttv4 ..." >> $LOG_FILE + killall -q mqttv4 + sleep 1 + restart_mqttv4 + fi +} + if [[ $(get_config RTSP) == "no" ]] ; then exit fi @@ -157,6 +174,7 @@ do check_rtsp check_rmm check_cloud + check_mqttv4 if [ $COUNTER -eq 0 ]; then sleep $INTERVAL fi From 3cedddd5ab5d40d8ea432a1ae7869b4ed6a3f541 Mon Sep 17 00:00:00 2001 From: roleo Date: Thu, 28 Sep 2023 18:34:25 +0200 Subject: [PATCH 30/81] Add "if supported" in camera settings page --- src/www/httpd/htdocs/pages/camera_settings.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/www/httpd/htdocs/pages/camera_settings.html b/src/www/httpd/htdocs/pages/camera_settings.html index 8d94fb8..367f725 100644 --- a/src/www/httpd/htdocs/pages/camera_settings.html +++ b/src/www/httpd/htdocs/pages/camera_settings.html @@ -78,7 +78,7 @@

General

--> - Sound Detection + Sound Detection (if supported by your cam)