Remove czmq part 1
diff --git a/selfdrive/logcatd/SConscript b/selfdrive/logcatd/SConscript
index 7f87cbaddf423f..2646537adf773d 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 2e5dae5553c738..5d59e929e3acac 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 721c6901e87943..5dccbeadd51f0a 100644
--- a/selfdrive/loggerd/encoder.c
+++ b/selfdrive/loggerd/encoder.c
@@ -6,8 +6,6 @@
 #include <unistd.h>
 #include <assert.h>
 
-#include <czmq.h>
-
 #include <pthread.h>
 
 #include <OMX_Component.h>
@@ -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 18054d20d8254a..abd9d18c5308ae 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 5d81f5480816e4..bd151ad79dedf4 100644
--- a/selfdrive/loggerd/loggerd.cc
+++ b/selfdrive/loggerd/loggerd.cc
@@ -23,7 +23,6 @@
 #include <random>
 
 #include <ftw.h>
-#include <zmq.h>
 #ifdef QCOM
 #include <cutils/properties.h>
 #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 e2dcf69cb428b3..69d71ac2490714 100644
--- a/selfdrive/modeld/modeld.cc
+++ b/selfdrive/modeld/modeld.cc
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <unistd.h>
 #include <eigen3/Eigen/Dense>
 
 #include "common/visionbuf.h"
diff --git a/selfdrive/modeld/models/commonmodel.c b/selfdrive/modeld/models/commonmodel.c
index 0bdc61bbe32e47..c156ad39df7ea9 100644
--- a/selfdrive/modeld/models/commonmodel.c
+++ b/selfdrive/modeld/models/commonmodel.c
@@ -1,6 +1,7 @@
+#include <assert.h>
+#include <math.h>
 #include "commonmodel.h"
 
-#include <czmq.h>
 #include "common/mat.h"
 #include "common/timing.h"
 
diff --git a/selfdrive/modeld/models/driving.h b/selfdrive/modeld/models/driving.h
index 52e7401a3b18ec..170982db11b78a 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 <czmq.h>
 #include <memory>
 #include "messaging.hpp"
 
diff --git a/selfdrive/modeld/visiontest.mk b/selfdrive/modeld/visiontest.mk
index f1aa7afdbaa85b..8e8f199d0c4b24 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 e7677099e989c8..b80d17200d7221 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 2207123a9777a7..55f269cb550617 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 e0442db518f9d4..f321593ec3505b 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

Only camerad left, will be done in separate PR.