From a4ccfcffe8247bf467bddfb0e6c5b3eb8851e21a Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Tue, 13 Oct 2020 16:01:07 +0200 Subject: [PATCH] Remove czmq part 1 (#2332) * remove czmq * remove streaming mode from loggerd * Add include for usleep --- selfdrive/logcatd/SConscript | 2 +- selfdrive/loggerd/SConscript | 2 +- selfdrive/loggerd/encoder.c | 11 -------- selfdrive/loggerd/encoder.h | 4 --- selfdrive/loggerd/loggerd.cc | 37 +++++++-------------------- selfdrive/modeld/modeld.cc | 1 + selfdrive/modeld/models/commonmodel.c | 3 ++- selfdrive/modeld/models/driving.h | 1 - selfdrive/modeld/visiontest.mk | 3 +-- selfdrive/proclogd/SConscript | 2 +- selfdrive/ui/SConscript | 2 +- selfdrive/ui/test/Makefile | 2 +- 12 files changed, 18 insertions(+), 52 deletions(-) diff --git a/selfdrive/logcatd/SConscript b/selfdrive/logcatd/SConscript index 7f87cbad..2646537a 100644 --- a/selfdrive/logcatd/SConscript +++ b/selfdrive/logcatd/SConscript @@ -1,6 +1,6 @@ Import('env', 'cereal', 'messaging', 'arch') if arch == "aarch64": - env.Program('logcatd', 'logcatd_android.cc', LIBS=[cereal, messaging, 'cutils', 'zmq', 'czmq', 'capnp', 'kj']) + env.Program('logcatd', 'logcatd_android.cc', LIBS=[cereal, messaging, 'cutils', 'zmq', 'capnp', 'kj']) else: env.Program('logcatd', 'logcatd_systemd.cc', LIBS=[cereal, messaging, 'zmq', 'capnp', 'kj', 'systemd', 'json11']) diff --git a/selfdrive/loggerd/SConscript b/selfdrive/loggerd/SConscript index 2e5dae55..5d59e929 100644 --- a/selfdrive/loggerd/SConscript +++ b/selfdrive/loggerd/SConscript @@ -1,7 +1,7 @@ Import('env', 'arch', 'cereal', 'messaging', 'common', 'visionipc') src = ['loggerd.cc', 'logger.cc'] -libs = ['zmq', 'czmq', 'capnp', 'kj', 'z', +libs = ['zmq', 'capnp', 'kj', 'z', 'avformat', 'avcodec', 'swscale', 'avutil', 'yuv', 'bz2', common, cereal, messaging, visionipc] diff --git a/selfdrive/loggerd/encoder.c b/selfdrive/loggerd/encoder.c index 721c6901..5dccbead 100644 --- a/selfdrive/loggerd/encoder.c +++ b/selfdrive/loggerd/encoder.c @@ -6,8 +6,6 @@ #include #include -#include - #include #include @@ -397,15 +395,6 @@ static void handle_out_buf(EncoderState *s, OMX_BUFFERHEADERTYPE *out_buf) { memcpy(s->codec_config, buf_data, out_buf->nFilledLen); } - if (s->stream_sock_raw) { - //uint64_t current_time = nanos_since_boot(); - //uint64_t diff = current_time - out_buf->nTimeStamp*1000LL; - //double msdiff = (double) diff / 1000000.0; - // printf("encoded latency to tsEof: %f\n", msdiff); - zmq_send(s->stream_sock_raw, &out_buf->nTimeStamp, sizeof(out_buf->nTimeStamp), ZMQ_SNDMORE); - zmq_send(s->stream_sock_raw, buf_data, out_buf->nFilledLen, 0); - } - if (s->of) { //printf("write %d flags 0x%x\n", out_buf->nFilledLen, out_buf->nFlags); fwrite(buf_data, out_buf->nFilledLen, 1, s->of); diff --git a/selfdrive/loggerd/encoder.h b/selfdrive/loggerd/encoder.h index 18054d20..abd9d18c 100644 --- a/selfdrive/loggerd/encoder.h +++ b/selfdrive/loggerd/encoder.h @@ -56,15 +56,11 @@ typedef struct EncoderState { Queue free_in; Queue done_out; - void *stream_sock_raw; - AVFormatContext *ofmt_ctx; AVCodecContext *codec_ctx; AVStream *out_stream; bool remuxing; - void *zmq_ctx; - bool downscale; uint8_t *y_ptr2, *u_ptr2, *v_ptr2; } EncoderState; diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index 5d81f548..bd151ad7 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -23,7 +23,6 @@ #include #include -#include #ifdef QCOM #include #endif @@ -200,7 +199,7 @@ struct LoggerdState { LoggerdState s; #ifndef DISABLE_ENCODER -void encoder_thread(RotateState *rotate_state, bool is_streaming, bool raw_clips, int cam_idx) { +void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { switch (cam_idx) { case LOG_CAMERA_ID_DCAMERA: { @@ -271,12 +270,6 @@ void encoder_thread(RotateState *rotate_state, bool is_streaming, bool raw_clips } encoder_inited = true; - if (is_streaming) { - encoder.zmq_ctx = zmq_ctx_new(); - encoder.stream_sock_raw = zmq_socket(encoder.zmq_ctx, ZMQ_PUB); - assert(encoder.stream_sock_raw); - zmq_bind(encoder.stream_sock_raw, "tcp://*:9002"); - } } // dont log a raw clip in the first minute @@ -664,16 +657,6 @@ int main(int argc, char** argv) { logger_init(&s.logger, "rlog", bytes.begin(), bytes.size(), true); } - bool is_streaming = false; - bool is_logging = true; - - if (argc > 1 && strcmp(argv[1], "--stream") == 0) { - is_streaming = true; - } else if (argc > 1 && strcmp(argv[1], "--only-stream") == 0) { - is_streaming = true; - is_logging = false; - } - s.rotate_seq_id = 0; s.should_close = 0; s.finish_close = 0; @@ -681,17 +664,17 @@ int main(int argc, char** argv) { pthread_mutex_init(&s.rotate_lock, NULL); #ifndef DISABLE_ENCODER // rear camera - std::thread encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_FCAMERA], is_streaming, false, LOG_CAMERA_ID_FCAMERA); + std::thread encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_FCAMERA], false, LOG_CAMERA_ID_FCAMERA); s.rotate_state[LOG_CAMERA_ID_FCAMERA].enabled = true; // front camera std::thread front_encoder_thread_handle; if (record_front) { - front_encoder_thread_handle = std::thread(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_DCAMERA], false, false, LOG_CAMERA_ID_DCAMERA); + front_encoder_thread_handle = std::thread(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_DCAMERA], false, LOG_CAMERA_ID_DCAMERA); s.rotate_state[LOG_CAMERA_ID_DCAMERA].enabled = true; } #ifdef QCOM2 // wide camera - std::thread wide_encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_ECAMERA], false, false, LOG_CAMERA_ID_ECAMERA); + std::thread wide_encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_ECAMERA], false, LOG_CAMERA_ID_ECAMERA); s.rotate_state[LOG_CAMERA_ID_ECAMERA].enabled = true; #endif #endif @@ -787,13 +770,11 @@ int main(int argc, char** argv) { pthread_mutex_lock(&s.rotate_lock); last_rotate_tms = millis_since_boot(); - // rotate the log - if (is_logging) { - err = logger_next(&s.logger, LOG_ROOT, s.segment_path, sizeof(s.segment_path), &s.rotate_segment); - assert(err == 0); - if (s.logger.part == 0) { LOGW("logging to %s", s.segment_path); } - LOGW("rotated to %s", s.segment_path); - } + err = logger_next(&s.logger, LOG_ROOT, s.segment_path, sizeof(s.segment_path), &s.rotate_segment); + assert(err == 0); + if (s.logger.part == 0) { LOGW("logging to %s", s.segment_path); } + LOGW("rotated to %s", s.segment_path); + // rotate the encoders for (int cid=0;cid<=MAX_CAM_IDX;cid++) { s.rotate_state[cid].rotate(); } pthread_mutex_unlock(&s.rotate_lock); diff --git a/selfdrive/modeld/modeld.cc b/selfdrive/modeld/modeld.cc index e2dcf69c..69d71ac2 100644 --- a/selfdrive/modeld/modeld.cc +++ b/selfdrive/modeld/modeld.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "common/visionbuf.h" diff --git a/selfdrive/modeld/models/commonmodel.c b/selfdrive/modeld/models/commonmodel.c index 0bdc61bb..c156ad39 100644 --- a/selfdrive/modeld/models/commonmodel.c +++ b/selfdrive/modeld/models/commonmodel.c @@ -1,6 +1,7 @@ +#include +#include #include "commonmodel.h" -#include #include "common/mat.h" #include "common/timing.h" diff --git a/selfdrive/modeld/models/driving.h b/selfdrive/modeld/models/driving.h index 52e7401a..170982db 100644 --- a/selfdrive/modeld/models/driving.h +++ b/selfdrive/modeld/models/driving.h @@ -14,7 +14,6 @@ #include "commonmodel.h" #include "runners/run.h" -#include #include #include "messaging.hpp" diff --git a/selfdrive/modeld/visiontest.mk b/selfdrive/modeld/visiontest.mk index f1aa7afd..8e8f199d 100644 --- a/selfdrive/modeld/visiontest.mk +++ b/selfdrive/modeld/visiontest.mk @@ -30,7 +30,6 @@ OPENCV_LIBS = -lopencv_video -lopencv_core -lopencv_imgproc ifeq ($(UNAME_S),Darwin) VT_LDFLAGS += $(PHONELIBS)/capnp-c/mac/lib/libcapnp_c.a \ - $(PHONELIBS)/zmq/mac/lib/libczmq.a \ $(PHONELIBS)/zmq/mac/lib/libzmq.a \ -framework OpenCL @@ -41,7 +40,7 @@ else VT_LDFLAGS += $(CEREAL_LIBS) \ -L/system/vendor/lib64 \ -L$(BASEDIR)/external/zmq/lib/ \ - -l:libczmq.a -l:libzmq.a \ + -l:libzmq.a \ -lOpenCL endif diff --git a/selfdrive/proclogd/SConscript b/selfdrive/proclogd/SConscript index e7677099..b80d1720 100644 --- a/selfdrive/proclogd/SConscript +++ b/selfdrive/proclogd/SConscript @@ -1,2 +1,2 @@ Import('env', 'cereal', 'messaging') -env.Program('proclogd.cc', LIBS=[cereal, messaging, 'pthread', 'zmq', 'czmq', 'capnp', 'kj']) +env.Program('proclogd.cc', LIBS=[cereal, messaging, 'pthread', 'zmq', 'capnp', 'kj']) diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index 2207123a..55f269cb 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -1,7 +1,7 @@ Import('env', 'qt_env', 'arch', 'common', 'messaging', 'gpucommon', 'visionipc', 'cereal') src = ['ui.cc', 'paint.cc', 'sidebar.cc', '#phonelibs/nanovg/nanovg.c'] -libs = [common, 'zmq', 'czmq', 'capnp', 'kj', 'm', cereal, messaging, gpucommon, visionipc] +libs = [common, 'zmq', 'capnp', 'kj', 'm', cereal, messaging, gpucommon, visionipc] if qt_env is None: diff --git a/selfdrive/ui/test/Makefile b/selfdrive/ui/test/Makefile index e0442db5..f321593e 100644 --- a/selfdrive/ui/test/Makefile +++ b/selfdrive/ui/test/Makefile @@ -14,7 +14,7 @@ CXXFLAGS = -std=c++11 -g -fPIC -O2 $(WARN_FLAGS) ZMQ_FLAGS = -I$(PHONELIBS)/zmq/aarch64/include ZMQ_LIBS = -L$(PHONELIBS)/zmq/aarch64/lib \ - -l:libczmq.a -l:libzmq.a \ + -l:libzmq.a \ -lgnustl_shared NANOVG_FLAGS = -I$(PHONELIBS)/nanovg