    wait_for_state(OMX_StateLoaded);
  
    OMX_CHECK(OMX_FreeHandle(this->handle));
  
    while (queue_try_pop(&this->free_in)); 
    while (queue_try_pop(&this->done_out)); 
  
    if (this->codec_config) {
      free(this->codec_config);
    }
  
 
</s> remove     OMX_BUFFERHEADERTYPE *out_buf = (OMX_BUFFERHEADERTYPE *)queue_try_pop(&this->done_out);
    if (!out_buf) {
 </s> add     OMX_BUFFERHEADERTYPE *out_buf;
    if (!this->done_out.try_pop(out_buf)) { </s> remove         OMX_BUFFERHEADERTYPE *out_buf = (OMX_BUFFERHEADERTYPE *)queue_pop(&this->done_out);
 </s> add         OMX_BUFFERHEADERTYPE *out_buf = this->done_out.pop(); </s> remove   OMX_BUFFERHEADERTYPE* in_buf = (OMX_BUFFERHEADERTYPE *)queue_pop(&this->free_in);
 </s> add   OMX_BUFFERHEADERTYPE* in_buf = nullptr;
  while (!this->free_in.try_pop(in_buf, 20)) {
    if (do_exit) {
      pthread_mutex_unlock(&this->lock);
      return -1;
    }
  }
 </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;
  OMX_BUFFERHEADERTYPE *out_buf;
  while (this->free_in.try_pop(out_buf)); 
  while (this->done_out.try_pop(out_buf)); 
    wait_for_state(OMX_StateLoaded);
  
    OMX_CHECK(OMX_FreeHandle(this->handle));
  
  OMX_BUFFERHEADERTYPE *out_buf;
  while (this->free_in.try_pop(out_buf)); 
  while (this->done_out.try_pop(out_buf)); 
  OMX_BUFFERHEADERTYPE *out_buf;
  while (this->free_in.try_pop(out_buf)); 
  while (this->done_out.try_pop(out_buf)); 
  
    if (this->codec_config) {
      free(this->codec_config);
    }
  
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.cc