    std::vector<OMX_BUFFERHEADERTYPE *> out_buf_headers;
  
    uint64_t last_t;
  
    Queue free_in;
    Queue done_out;
  
    AVFormatContext *ofmt_ctx;
    AVCodecContext *codec_ctx;
    AVStream *out_stream;
    bool remuxing;
 
</s> remove   {
    std::unique_lock<std::mutex> lk(frame_queue_mutex);
    bool got_frame = frame_queue_cv.wait_for(lk, std::chrono::milliseconds(1), [this]{ return !frame_queue.empty(); });
    if (!got_frame) return false;

    cur_buf_idx = frame_queue.front();
    frame_queue.pop();
  }
 </s> add   if (!safe_queue.try_pop(cur_buf_idx, 1)) return false; </s> remove   while (queue_try_pop(&this->free_in)); 
  while (queue_try_pop(&this->done_out)); 
 </s> add   OMX_BUFFERHEADERTYPE *out_buf;
  while (this->free_in.try_pop(out_buf)); 
  while (this->done_out.try_pop(out_buf));  </s> remove void CameraBuf::queue(size_t buf_idx){
  {
    std::lock_guard<std::mutex> lk(frame_queue_mutex);
    frame_queue.push(buf_idx);
  }
  frame_queue_cv.notify_one();
 </s> add void CameraBuf::queue(size_t buf_idx) {
  safe_queue.push(buf_idx); </s> remove #include <queue>
#include <mutex>
#include <condition_variable>
 </s> add 
  SafeQueue<OMX_BUFFERHEADERTYPE *> free_in;
  SafeQueue<OMX_BUFFERHEADERTYPE *> done_out;
    std::vector<OMX_BUFFERHEADERTYPE *> out_buf_headers;
  
    uint64_t last_t;
  
  SafeQueue<OMX_BUFFERHEADERTYPE *> free_in;
  SafeQueue<OMX_BUFFERHEADERTYPE *> done_out;
  SafeQueue<OMX_BUFFERHEADERTYPE *> free_in;
  SafeQueue<OMX_BUFFERHEADERTYPE *> done_out;
  
    AVFormatContext *ofmt_ctx;
    AVCodecContext *codec_ctx;
    AVStream *out_stream;
    bool remuxing;
keep keep keep keep replace replace keep keep keep keep keep
 remove cqueue, use class SafeQueue (#19774)

* class SafeQueue

* cleanup includes

* space

* add timeout

use try_poll

* add function empty() & size()

* class SafeQueue

* add timeout

use try_poll

* add function empty() & size()

* rebase master

* rebase master

* for loop

* fix bug 
selfdrive/loggerd/omx_encoder.h