diff --git a/selfdrive/camerad/cameras/camera_common.h b/selfdrive/camerad/cameras/camera_common.h index dd46eb5502..7b510058e3 100644 --- a/selfdrive/camerad/cameras/camera_common.h +++ b/selfdrive/camerad/cameras/camera_common.h @@ -62,6 +62,7 @@ typedef struct LogCameraInfo { bool has_qcamera; bool trigger_rotate; bool enable; + bool record; } LogCameraInfo; typedef struct FrameMetadata { diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index 1d3a005ffa..38f9596300 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -64,6 +64,7 @@ const LogCameraInfo cameras_logged[] = { .has_qcamera = true, .trigger_rotate = true, .enable = true, + .record = true, }, { .type = DriverCam, @@ -76,7 +77,8 @@ const LogCameraInfo cameras_logged[] = { .downscale = false, .has_qcamera = false, .trigger_rotate = Hardware::TICI(), - .enable = !Hardware::PC() && Params().getBool("RecordFront"), + .enable = !Hardware::PC(), + .record = Params().getBool("RecordFront"), }, { .type = WideRoadCam, @@ -90,6 +92,7 @@ const LogCameraInfo cameras_logged[] = { .has_qcamera = false, .trigger_rotate = true, .enable = Hardware::TICI(), + .record = Hardware::TICI(), }, }; const LogCameraInfo qcam_info = { @@ -146,7 +149,8 @@ void encoder_thread(const LogCameraInfo &cam_info) { // main encoder encoders.push_back(new Encoder(cam_info.filename, buf_info.width, buf_info.height, - cam_info.fps, cam_info.bitrate, cam_info.is_h265, cam_info.downscale)); + cam_info.fps, cam_info.bitrate, cam_info.is_h265, + cam_info.downscale, cam_info.record)); // qcamera encoder if (cam_info.has_qcamera) { encoders.push_back(new Encoder(qcam_info.filename, qcam_info.frame_width, qcam_info.frame_height, diff --git a/selfdrive/loggerd/omx_encoder.cc b/selfdrive/loggerd/omx_encoder.cc index df5e3d2489..3ccbbff57b 100644 --- a/selfdrive/loggerd/omx_encoder.cc +++ b/selfdrive/loggerd/omx_encoder.cc @@ -156,8 +156,9 @@ static const char* omx_color_fomat_name(uint32_t format) { // ***** encoder functions ***** -OmxEncoder::OmxEncoder(const char* filename, int width, int height, int fps, int bitrate, bool h265, bool downscale) { +OmxEncoder::OmxEncoder(const char* filename, int width, int height, int fps, int bitrate, bool h265, bool downscale, bool write) { this->filename = filename; + this->write = write; this->width = width; this->height = height; this->fps = fps; @@ -503,13 +504,15 @@ void OmxEncoder::encoder_open(const char* path) { this->wrote_codec_config = false; } else { - this->of = fopen(this->vid_path, "wb"); - assert(this->of); + if (this->write) { + this->of = fopen(this->vid_path, "wb"); + assert(this->of); #ifndef QCOM2 - if (this->codec_config_len > 0) { - fwrite(this->codec_config, this->codec_config_len, 1, this->of); - } + if (this->codec_config_len > 0) { + fwrite(this->codec_config, this->codec_config_len, 1, this->of); + } #endif + } } // create camera lock file @@ -553,8 +556,10 @@ void OmxEncoder::encoder_close() { avio_closep(&this->ofmt_ctx->pb); avformat_free_context(this->ofmt_ctx); } else { - fclose(this->of); - this->of = nullptr; + if (this->of) { + fclose(this->of); + this->of = nullptr; + } } unlink(this->lock_path); } diff --git a/selfdrive/loggerd/omx_encoder.h b/selfdrive/loggerd/omx_encoder.h index d7273872a5..74ea17f640 100644 --- a/selfdrive/loggerd/omx_encoder.h +++ b/selfdrive/loggerd/omx_encoder.h @@ -15,7 +15,7 @@ extern "C" { // OmxEncoder, lossey codec using hardware hevc class OmxEncoder : public VideoEncoder { public: - OmxEncoder(const char* filename, int width, int height, int fps, int bitrate, bool h265, bool downscale); + OmxEncoder(const char* filename, int width, int height, int fps, int bitrate, bool h265, bool downscale, bool write = true); ~OmxEncoder(); int encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr, int in_width, int in_height, uint64_t ts); @@ -39,10 +39,11 @@ private: char lock_path[1024]; bool is_open = false; bool dirty = false; + bool write = false; int counter = 0; const char* filename; - FILE *of; + FILE *of = nullptr; size_t codec_config_len; uint8_t *codec_config = NULL; diff --git a/selfdrive/loggerd/raw_logger.cc b/selfdrive/loggerd/raw_logger.cc index fc400dfe2f..39757b8ffe 100644 --- a/selfdrive/loggerd/raw_logger.cc +++ b/selfdrive/loggerd/raw_logger.cc @@ -21,9 +21,10 @@ extern "C" { #include "selfdrive/common/util.h" RawLogger::RawLogger(const char* filename, int width, int height, int fps, - int bitrate, bool h265, bool downscale) - : filename(filename), - fps(fps) { + int bitrate, bool h265, bool downscale, bool write) + : filename(filename), fps(fps) { + + // TODO: respect write arg av_register_all(); codec = avcodec_find_encoder(AV_CODEC_ID_FFVHUFF); diff --git a/selfdrive/loggerd/raw_logger.h b/selfdrive/loggerd/raw_logger.h index 7955ef5e1b..9cef7ddcab 100644 --- a/selfdrive/loggerd/raw_logger.h +++ b/selfdrive/loggerd/raw_logger.h @@ -16,7 +16,7 @@ extern "C" { class RawLogger : public VideoEncoder { public: RawLogger(const char* filename, int width, int height, int fps, - int bitrate, bool h265, bool downscale); + int bitrate, bool h265, bool downscale, bool write = true); ~RawLogger(); int encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr, int in_width, int in_height, uint64_t ts); @@ -25,6 +25,7 @@ class RawLogger : public VideoEncoder { private: const char* filename; + //bool write; int fps; int counter = 0; bool is_open = false; diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index 0a590cb2d1..cbe8776053 100755 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -51,7 +51,7 @@ if EON: if TICI: PROCS.update({ - "./loggerd": 60.0, + "./loggerd": 70.0, "selfdrive.controls.controlsd": 28.0, "./camerad": 31.0, "./_ui": 21.0,