  OMX_ERRORTYPE OmxEncoder::empty_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
                                                     OMX_BUFFERHEADERTYPE *buffer) {
    // printf("empty_buffer_done\n");
    OmxEncoder *e = (OmxEncoder*)app_data;
    queue_push(&e->free_in, (void*)buffer);
    return OMX_ErrorNone;
  }
  
  OMX_ERRORTYPE OmxEncoder::fill_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
                                                    OMX_BUFFERHEADERTYPE *buffer) {
 
</s> remove   queue_push(&e->done_out, (void*)buffer);
 </s> add   e->done_out.push(buffer); </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   {
    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     queue_push(&this->free_in, (void*)buf);
 </s> add     this->free_in.push(buf);
  e->free_in.push(buffer);
  OMX_ERRORTYPE OmxEncoder::empty_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
                                                     OMX_BUFFERHEADERTYPE *buffer) {
    // printf("empty_buffer_done\n");
    OmxEncoder *e = (OmxEncoder*)app_data;
  e->free_in.push(buffer);
    return OMX_ErrorNone;
  }
  
  OMX_ERRORTYPE OmxEncoder::fill_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
                                                    OMX_BUFFERHEADERTYPE *buffer) {
keep keep keep keep 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