From d7e18745491037bd81d700fc5feac218e847c515 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Mon, 8 Mar 2021 13:36:37 +0800 Subject: [PATCH] raw_logger: remove unneeded recursive_mutex (#20274) * remove lock * remove forword declared err * cleanup include old-commit-hash: 51d46e289a7cc7afa2f893060acb568ccb2b116a --- selfdrive/loggerd/raw_logger.cc | 20 ++++---------------- selfdrive/loggerd/raw_logger.h | 4 ---- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/selfdrive/loggerd/raw_logger.cc b/selfdrive/loggerd/raw_logger.cc index 71703c1ffb..2e8fd20a77 100644 --- a/selfdrive/loggerd/raw_logger.cc +++ b/selfdrive/loggerd/raw_logger.cc @@ -25,8 +25,6 @@ RawLogger::RawLogger(const char* filename, int width, int height, int fps, : filename(filename), fps(fps) { - int err = 0; - av_register_all(); codec = avcodec_find_encoder(AV_CODEC_ID_FFVHUFF); // codec = avcodec_find_encoder(AV_CODEC_ID_FFV1); @@ -45,7 +43,7 @@ RawLogger::RawLogger(const char* filename, int width, int height, int fps, codec_ctx->time_base = (AVRational){ 1, fps }; - err = avcodec_open2(codec_ctx, codec, NULL); + int err = avcodec_open2(codec_ctx, codec, NULL); assert(err >= 0); frame = av_frame_alloc(); @@ -65,10 +63,6 @@ RawLogger::~RawLogger() { } void RawLogger::encoder_open(const char* path) { - int err = 0; - - std::lock_guard guard(lock); - vid_path = util::string_format("%s/%s.mkv", path, filename); // create camera lock file @@ -91,7 +85,7 @@ void RawLogger::encoder_open(const char* path) { stream->time_base = (AVRational){ 1, fps }; // codec_ctx->time_base = stream->time_base; - err = avcodec_parameters_from_context(stream->codecpar, codec_ctx); + int err = avcodec_parameters_from_context(stream->codecpar, codec_ctx); assert(err >= 0); err = avio_open(&format_ctx->pb, vid_path.c_str(), AVIO_FLAG_WRITE); @@ -105,13 +99,9 @@ void RawLogger::encoder_open(const char* path) { } void RawLogger::encoder_close() { - int err = 0; - - std::lock_guard guard(lock); - if (!is_open) return; - err = av_write_trailer(format_ctx); + int err = av_write_trailer(format_ctx); assert(err == 0); avcodec_close(stream->codec); @@ -128,8 +118,6 @@ void RawLogger::encoder_close() { int RawLogger::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) { - int err = 0; - AVPacket pkt; av_init_packet(&pkt); pkt.data = NULL; @@ -143,7 +131,7 @@ int RawLogger::encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const ui int ret = counter; int got_output = 0; - err = avcodec_encode_video2(codec_ctx, &pkt, frame, &got_output); + int err = avcodec_encode_video2(codec_ctx, &pkt, frame, &got_output); if (err) { LOGE("encoding error\n"); ret = -1; diff --git a/selfdrive/loggerd/raw_logger.h b/selfdrive/loggerd/raw_logger.h index 28bfdf906e..5df6eabedb 100644 --- a/selfdrive/loggerd/raw_logger.h +++ b/selfdrive/loggerd/raw_logger.h @@ -5,8 +5,6 @@ #include #include -#include -#include extern "C" { #include @@ -34,8 +32,6 @@ private: std::string vid_path, lock_path; - std::recursive_mutex lock; - AVCodec *codec = NULL; AVCodecContext *codec_ctx = NULL;