  
    auto words = new kj::Array<capnp::word>(capnp::messageToFlatArray(msg));
    auto bytes = words->asBytes();
    e->pm->send(e->service_name, bytes.begin(), bytes.size());
    if (e->write) {
      e->to_write.push(words);
    } else {
      delete words;
    }
  }
  
  // TODO: writing should be moved to loggerd
  void VideoEncoder::write_handler(VideoEncoder *e, const char *path) {
    VideoWriter writer(path, e->filename, e->codec != cereal::EncodeIndex::Type::FULL_H_E_V_C, e->out_width, e->out_height, e->fps, e->codec);
  
    bool first = true;
    kj::Array<capnp::word>* out_buf;
    while ((out_buf = e->to_write.pop())) {
      capnp::FlatArrayMessageReader cmsg(*out_buf);
      cereal::Event::Reader event = cmsg.getRoot<cereal::Event>();
  
      auto edata = (e->type == DriverCam) ? event.getDriverEncodeData() :
        ((e->type == WideRoadCam) ? event.getWideRoadEncodeData() :
        (e->in_width == e->out_width ? event.getRoadEncodeData() : event.getQRoadEncodeData()));
      auto idx = edata.getIdx();
      auto flags = idx.getFlags();
  
      if (first) {
        assert(flags & V4L2_BUF_FLAG_KEYFRAME);
        auto header = edata.getHeader();
        writer.write((uint8_t *)header.begin(), header.size(), idx.getTimestampEof()/1000, true, false);
        first = false;
      }
  
      // dangerous cast from const, but should be fine
      auto data = edata.getData();
      if (data.size() > 0) {
        writer.write((uint8_t *)data.begin(), data.size(), idx.getTimestampEof()/1000, false, flags & V4L2_BUF_FLAG_KEYFRAME);
      }
  
      // free the data
      delete out_buf;
    }
  
    // VideoWriter is freed on out of scope
  }
 
</s> remove     writer_close();
 </s> add  </s> remove   writer_open(path);
 </s> add  </s> remove   writer_close();
 </s> add  </s> remove   void writer_open(const char* path) {
    if (this->write) write_handler_thread = std::thread(VideoEncoder::write_handler, this, path);
  }

  void writer_close() {
    if (this->write) {
      to_write.push(NULL);
      write_handler_thread.join();
    }
    assert(to_write.empty());
  }
 </s> add  </s> remove                                         qcam_info.frame_width, qcam_info.frame_height, false));
 </s> add                                         qcam_info.frame_width, qcam_info.frame_height));
  delete words;
  
    auto words = new kj::Array<capnp::word>(capnp::messageToFlatArray(msg));
    auto bytes = words->asBytes();
    e->pm->send(e->service_name, bytes.begin(), bytes.size());
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  delete words;
  }
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep
 Encoderd: encoders don't write, they only encode (#28499)

* Encoders dont write, they encode

* Delete words

* unused

---------

Co-authored-by: Harald Schaefer <torq_boi@Haralds-MacBook-Air.local>
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> 
system/loggerd/encoder/encoder.cc