Skip to content

Commit f72db5d

Browse files
committed
Keeping the reference to all globals, resetting the MP4 struct on a new
moof, adding a restart feature
1 parent e4f7213 commit f72db5d

9 files changed

Lines changed: 45 additions & 13 deletions

File tree

res/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@
260260
}
261261
}
262262

263+
function restartApp() {
264+
var req = new XMLHttpRequest();
265+
req.onreadystatechange = function() {
266+
if (this.readyState != 4 || this.status != 200) return;
267+
var dec = JSON.parse(req.responseText);
268+
for (var key in dec) {
269+
if (!dec.hasOwnProperty(key)) continue;
270+
if (key == 'code' && dec[key] !== 0)
271+
return alert('Failed to restart streamer!');
272+
}
273+
}
274+
req.open('GET', '/api/cmd?restart');
275+
req.send();
276+
}
277+
263278
function saveConfig() {
264279
var req = new XMLHttpRequest();
265280
req.onreadystatechange = function() {
@@ -413,6 +428,7 @@ <h2 class="unl">Live</h2>
413428
<b><label for="media-modal" class="lbl-modal ph2 gray">Divinus</label></b>
414429
<div class="col">
415430
<a href="javascript:saveConfig()" class="ph2">Save</a>
431+
<a href="javascript:restartApp()" class="ph2">Restart</a>
416432
<label for="media-modal" class="btn primary close">Close</label>
417433
</div>
418434
</div>
@@ -655,6 +671,7 @@ <h2 class="unl">Media</h2>
655671
<div class="col">
656672
<a href="javascript:saveOsds()" class="ph2">Apply all</a>
657673
<a href="javascript:saveConfig()" class="ph2">Save</a>
674+
<a href="javascript:restartApp()" class="ph2">Restart</a>
658675
<label for="osd-modal" class="btn primary close">Close</label>
659676
</div>
660677
</div>
@@ -711,6 +728,8 @@ <h2 class="unl">OSD</h2>
711728
<div class="c bg-black menu pv2 row" tabindex="0">
712729
<b><label for="system-modal" class="lbl-modal ph2 gray">Divinus</label></b>
713730
<div class="col">
731+
<a href="javascript:saveConfig()" class="ph2">Save</a>
732+
<a href="javascript:restartApp()" class="ph2">Restart</a>
714733
<label for="system-modal" class="btn primary close">Close</label>
715734
</div>
716735
</div>

src/fmt/moof.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ enum BufError write_moof(
5757
const uint32_t samples_aud_len) {
5858
enum BufError err;
5959
uint32_t start_atom = ptr->offset;
60+
61+
pos_sequence_number = 0;
62+
pos_base_data_offset = 0;
63+
pos_audio_media_decode_time = 0;
64+
pos_video_media_decode_time = 0;
65+
6066
err = put_u32_be(ptr, 0);
6167
chk_err;
6268
err = put_str4(ptr, "moof");

src/hal/globals.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#include "types.h"
44

5-
extern char audioOn, keepRunning;
5+
extern char graceful, keepRunning;
6+
extern char audioOn, recordOn;
67

78
extern void *aud_thread;
89
extern void *isp_thread;

src/http_post.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
#include <time.h>
1111
#include <unistd.h>
1212

13+
#include "hal/globals.h"
1314
#include "hal/macros.h"
1415
#include "jpeg.h"
1516

16-
extern char keepRunning;
17-
1817
void start_http_post_send();
19-
void stop_http_post_send();
18+
void stop_http_post_send();

src/main.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void handle_exit(int signo) {
3535
int main(int argc, char *argv[]) {
3636
{
3737
char signal_error[] = {SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV};
38-
char signal_exit[] = {SIGINT, SIGQUIT, SIGTERM};
38+
char signal_exit[] = {SIGHUP, SIGINT, SIGQUIT, SIGTERM};
3939
char signal_null[] = {EPIPE, SIGPIPE};
4040

4141
for (char *s = signal_error; s < (&signal_error)[1]; s++)
@@ -133,6 +133,11 @@ int main(int argc, char *argv[]) {
133133
if (!graceful)
134134
restore_app_config();
135135

136+
if (graceful) {
137+
fprintf(stderr, "Restarting...\n");
138+
execvp(argv[0], argv);
139+
}
140+
136141
fprintf(stderr, "Main thread is shutting down...\n");
137142
return EXIT_SUCCESS;
138-
}
143+
}

src/region.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <time.h>
1010

1111
#include "app_config.h"
12+
#include "hal/globals.h"
1213
#include "hal/support.h"
1314
#include "lib/spng.h"
1415
#include "text.h"
@@ -24,8 +25,6 @@
2425
#define DEF_TIMEFMT "%Y/%m/%d %H:%M:%S"
2526
#define MAX_OSD 10
2627

27-
extern char keepRunning;
28-
2928
typedef struct {
3029
unsigned int size;
3130
unsigned short reserved1;
@@ -75,4 +74,4 @@ extern osd osds[MAX_OSD];
7574
extern char timefmt[64];
7675

7776
int start_region_handler();
78-
void stop_region_handler();
77+
void stop_region_handler();

src/rtmp.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "app_config.h"
1515
#include "fmt/flv.h"
1616
#include "fmt/nal.h"
17+
#include "hal/globals.h"
1718
#include "hal/macros.h"
1819
#include "hal/tools.h"
1920
#include "hal/types.h"
@@ -37,9 +38,7 @@
3738
#define RTMP_CS_AUDIO 4
3839
#define RTMP_CS_VIDEO 6
3940

40-
extern char keepRunning;
41-
4241
int rtmp_init(const char *url);
4342
void rtmp_close(void);
4443
int rtmp_ingest_video(hal_vidpack *packet, int is_h265);
45-
int rtmp_ingest_audio(void *data, int len);
44+
int rtmp_ingest_audio(void *data, int len);

src/server.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,10 @@ void respond_request(http_request_t *req) {
878878
else
879879
HAL_WARNING("server", "Failed to save configuration!\n");
880880
break;
881+
} else if (EQUALS(key, "restart")) {
882+
kill(getpid(), SIGHUP);
883+
result = 0;
884+
break;
881885
}
882886
}
883887
}

src/server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "app_config.h"
2121
#include "fmt/mp4.h"
2222
#include "fmt/nal.h"
23+
#include "hal/globals.h"
2324
#include "hal/types.h"
2425
#include "jpeg.h"
2526
#include "media.h"
@@ -29,7 +30,6 @@
2930
#include "region.h"
3031
#include "watchdog.h"
3132

32-
extern char graceful, keepRunning, recordOn;
3333
extern time_t recordStartTime;
3434

3535
int start_server();

0 commit comments

Comments
 (0)