Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roleo testing merge for pre-release #289

Merged
merged 15 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0d
0.4.0
44 changes: 35 additions & 9 deletions src/h264grabber/h264grabber/h264grabber.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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) +
Expand All @@ -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
Expand All @@ -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) +
Expand Down Expand Up @@ -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;
}
}
Expand Down
84 changes: 84 additions & 0 deletions src/mqtt-config/mqtt-config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/mqtt-config/mqtt-config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 5 additions & 0 deletions src/mqtt-config/mqtt-config/mqtt-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/rRTSPServer/Makefile.rRTSPServer
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 0 additions & 1 deletion src/rRTSPServer/init.rRTSPServer
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ fi
tar zxvf $ARCHIVE

patch -p0 < rRTSPServer.patch
patch -p0 < rRTSPServer2.patch

cd live || exit 1

Expand Down
4 changes: 2 additions & 2 deletions src/rRTSPServer/rRTSPServer.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 -DRTP_PAYLOAD_MAX_SIZE=1352 -DNEWLOCALE_NOT_USED
+C = c
+C_COMPILER = $(CC)
+C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS)
Expand All @@ -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 =
Expand Down
37 changes: 0 additions & 37 deletions src/rRTSPServer/rRTSPServer2.patch

This file was deleted.

20 changes: 19 additions & 1 deletion src/rRTSPServer/src/ADTSAudioFifoSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,45 @@ 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;
}
}
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':
Expand Down
4 changes: 2 additions & 2 deletions src/snapshot/.gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading