fix: port OmxEncoder safety fixes from upstream FrogPilot
- OMX_Init/OMX_Deinit managed per encoder instance lifecycle - Proper error handling in constructor, encoder_open, encoder_close - Null guards on done_out.pop() and handle in destructor - Codec config written directly to codecpar (no codec_ctx) - ffmpeg faststart remux on segment close - Crash handler in dashcamd for diagnostics - DashcamFrames param for live frame count in status window Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,8 @@
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <signal.h>
|
||||
#include <execinfo.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
@@ -115,12 +117,22 @@ static std::string srt_time(int seconds) {
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
setpriority(PRIO_PROCESS, 0, -10);
|
||||
static void crash_handler(int sig) {
|
||||
FILE *f = fopen("/tmp/dashcamd_crash.log", "w");
|
||||
if (f) {
|
||||
fprintf(f, "CRASH: signal %d\n", sig);
|
||||
void *bt[30];
|
||||
int n = backtrace(bt, 30);
|
||||
backtrace_symbols_fd(bt, n, fileno(f));
|
||||
fclose(f);
|
||||
}
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
// Reset OMX subsystem — clears any stale encoder state from previous unclean exit
|
||||
OMX_Deinit();
|
||||
OMX_Init();
|
||||
int main(int argc, char *argv[]) {
|
||||
signal(SIGSEGV, crash_handler);
|
||||
signal(SIGABRT, crash_handler);
|
||||
setpriority(PRIO_PROCESS, 0, -10);
|
||||
|
||||
// Ensure base output directory exists
|
||||
mkdir(VIDEOS_BASE.c_str(), 0755);
|
||||
@@ -183,6 +195,11 @@ int main(int argc, char *argv[]) {
|
||||
// Param check throttle (don't hit filesystem every frame)
|
||||
int param_check_counter = 0;
|
||||
|
||||
// Total encoded frames counter + param writer
|
||||
Params params_memory("/dev/shm/params");
|
||||
int total_frames = 0;
|
||||
double last_frame_count_write = 0;
|
||||
|
||||
// Helper: start a new trip with recording + optional idle timer
|
||||
auto start_new_trip = [&]() {
|
||||
// Close existing encoder if any
|
||||
@@ -198,7 +215,7 @@ int main(int argc, char *argv[]) {
|
||||
mkdir(trip_dir.c_str(), 0755);
|
||||
LOGW("dashcamd: new trip %s", trip_dir.c_str());
|
||||
|
||||
encoder = new OmxEncoder(trip_dir.c_str(), width, height, CAMERA_FPS, BITRATE, false, false);
|
||||
encoder = new OmxEncoder(trip_dir.c_str(), width, height, CAMERA_FPS, BITRATE);
|
||||
|
||||
std::string seg_name = make_timestamp();
|
||||
LOGW("dashcamd: opening segment %s", seg_name.c_str());
|
||||
@@ -358,6 +375,13 @@ int main(int argc, char *argv[]) {
|
||||
// Feed NV12 frame directly to OMX encoder
|
||||
encoder->encode_frame_nv12(buf->y, y_stride, buf->uv, uv_stride, width, height, ts);
|
||||
frame_count++;
|
||||
total_frames++;
|
||||
|
||||
// Write total frame count to params_memory every 5 seconds
|
||||
if (now - last_frame_count_write >= 5.0) {
|
||||
params_memory.put("DashcamFrames", std::to_string(total_frames));
|
||||
last_frame_count_write = now;
|
||||
}
|
||||
|
||||
// Write GPS subtitle at most once per second
|
||||
if (srt_file && (now - last_srt_write) >= 1.0) {
|
||||
|
||||
Reference in New Issue
Block a user