omx: allow gst_omx_port_acquire_buffer() to not wait for buffers
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 13 Aug 2018 13:10:37 +0000 (15:10 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 30 Aug 2018 08:59:30 +0000 (10:59 +0200)
Will be needed to implement GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT.

https://bugzilla.gnome.org/show_bug.cgi?id=796918

omx/gstomx.c
omx/gstomx.h
omx/gstomxaudiodec.c
omx/gstomxaudioenc.c
omx/gstomxaudiosink.c
omx/gstomxvideodec.c
omx/gstomxvideoenc.c

index 6096806..8f99f82 100644 (file)
@@ -1372,7 +1372,8 @@ gst_omx_port_update_port_definition (GstOMXPort * port,
 
 /* NOTE: Uses comp->lock and comp->messages_lock */
 GstOMXAcquireBufferReturn
-gst_omx_port_acquire_buffer (GstOMXPort * port, GstOMXBuffer ** buf)
+gst_omx_port_acquire_buffer (GstOMXPort * port, GstOMXBuffer ** buf,
+    GstOMXWait wait)
 {
   GstOMXAcquireBufferReturn ret = GST_OMX_ACQUIRE_BUFFER_ERROR;
   GstOMXComponent *comp;
@@ -1504,11 +1505,17 @@ retry:
   if (g_queue_is_empty (&port->pending_buffers)) {
     GST_DEBUG_OBJECT (comp->parent, "Queue of %s port %u is empty",
         comp->name, port->index);
-    gst_omx_component_wait_message (comp,
-        timeout == -2 ? GST_CLOCK_TIME_NONE : timeout);
 
-    /* And now check everything again and maybe get a buffer */
-    goto retry;
+    if (wait == GST_OMX_WAIT) {
+      gst_omx_component_wait_message (comp,
+          timeout == -2 ? GST_CLOCK_TIME_NONE : timeout);
+
+      /* And now check everything again and maybe get a buffer */
+      goto retry;
+    } else {
+      ret = GST_OMX_ACQUIRE_BUFFER_NO_AVAILABLE;
+      goto done;
+    }
   }
 
   GST_DEBUG_OBJECT (comp->parent, "%s port %u has pending buffers",
index cab62bd..c43e2d7 100644 (file)
@@ -225,7 +225,9 @@ typedef enum {
   /* The port is EOS */
   GST_OMX_ACQUIRE_BUFFER_EOS,
   /* A fatal error happened */
-  GST_OMX_ACQUIRE_BUFFER_ERROR
+  GST_OMX_ACQUIRE_BUFFER_ERROR,
+  /* No buffer is currently available (used when calling gst_omx_port_acquire_buffer() in not waiting mode) */
+  GST_OMX_ACQUIRE_BUFFER_NO_AVAILABLE,
 } GstOMXAcquireBufferReturn;
 
 struct _GstOMXCore {
@@ -269,6 +271,11 @@ typedef enum {
   GST_OMX_BUFFER_ALLOCATION_USE_BUFFER_DYNAMIC, /* Only supported by OMX 1.2.0 */
 } GstOMXBufferAllocation;
 
+typedef enum {
+  GST_OMX_WAIT,
+  GST_OMX_DONT_WAIT,
+} GstOMXWait;
+
 struct _GstOMXMessage {
   GstOMXMessageType type;
 
@@ -441,7 +448,7 @@ OMX_ERRORTYPE     gst_omx_close_tunnel (GstOMXPort * port1, GstOMXPort * port2);
 OMX_ERRORTYPE     gst_omx_port_get_port_definition (GstOMXPort * port, OMX_PARAM_PORTDEFINITIONTYPE * port_def);
 OMX_ERRORTYPE     gst_omx_port_update_port_definition (GstOMXPort *port, OMX_PARAM_PORTDEFINITIONTYPE *port_definition);
 
-GstOMXAcquireBufferReturn gst_omx_port_acquire_buffer (GstOMXPort *port, GstOMXBuffer **buf);
+GstOMXAcquireBufferReturn gst_omx_port_acquire_buffer (GstOMXPort *port, GstOMXBuffer **buf, GstOMXWait wait);
 OMX_ERRORTYPE     gst_omx_port_release_buffer (GstOMXPort *port, GstOMXBuffer *buf);
 
 OMX_ERRORTYPE     gst_omx_port_set_flushing (GstOMXPort *port, GstClockTime timeout, gboolean flush);
index 1fb0bd5..8275b72 100644 (file)
@@ -303,7 +303,7 @@ gst_omx_audio_dec_loop (GstOMXAudioDec * self)
   OMX_ERRORTYPE err;
   gint spf;
 
-  acq_return = gst_omx_port_acquire_buffer (port, &buf);
+  acq_return = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
   if (acq_return == GST_OMX_ACQUIRE_BUFFER_ERROR) {
     goto component_error;
   } else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
@@ -1085,7 +1085,7 @@ gst_omx_audio_dec_handle_frame (GstAudioDecoder * decoder, GstBuffer * inbuf)
      * _loop() can't call _finish_frame() and we might block forever
      * because no input buffers are released */
     GST_AUDIO_DECODER_STREAM_UNLOCK (self);
-    acq_ret = gst_omx_port_acquire_buffer (port, &buf);
+    acq_ret = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
 
     if (acq_ret == GST_OMX_ACQUIRE_BUFFER_ERROR) {
       GST_AUDIO_DECODER_STREAM_LOCK (self);
@@ -1353,7 +1353,7 @@ gst_omx_audio_dec_drain (GstOMXAudioDec * self)
   /* Send an EOS buffer to the component and let the base
    * class drop the EOS event. We will send it later when
    * the EOS buffer arrives on the output port. */
-  acq_ret = gst_omx_port_acquire_buffer (self->dec_in_port, &buf);
+  acq_ret = gst_omx_port_acquire_buffer (self->dec_in_port, &buf, GST_OMX_WAIT);
   if (acq_ret != GST_OMX_ACQUIRE_BUFFER_OK) {
     GST_AUDIO_DECODER_STREAM_LOCK (self);
     GST_ERROR_OBJECT (self, "Failed to acquire buffer for draining: %d",
index 036b911..c5c1d6f 100644 (file)
@@ -285,7 +285,7 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
 
   klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
 
-  acq_return = gst_omx_port_acquire_buffer (port, &buf);
+  acq_return = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
   if (acq_return == GST_OMX_ACQUIRE_BUFFER_ERROR) {
     goto component_error;
   } else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
@@ -960,7 +960,7 @@ gst_omx_audio_enc_handle_frame (GstAudioEncoder * encoder, GstBuffer * inbuf)
      * _loop() can't call _finish_frame() and we might block forever
      * because no input buffers are released */
     GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
-    acq_ret = gst_omx_port_acquire_buffer (port, &buf);
+    acq_ret = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
 
     if (acq_ret == GST_OMX_ACQUIRE_BUFFER_ERROR) {
       GST_AUDIO_ENCODER_STREAM_LOCK (self);
@@ -1145,7 +1145,7 @@ gst_omx_audio_enc_drain (GstOMXAudioEnc * self)
   /* Send an EOS buffer to the component and let the base
    * class drop the EOS event. We will send it later when
    * the EOS buffer arrives on the output port. */
-  acq_ret = gst_omx_port_acquire_buffer (self->enc_in_port, &buf);
+  acq_ret = gst_omx_port_acquire_buffer (self->enc_in_port, &buf, GST_OMX_WAIT);
   if (acq_ret != GST_OMX_ACQUIRE_BUFFER_OK) {
     GST_AUDIO_ENCODER_STREAM_LOCK (self);
     GST_ERROR_OBJECT (self, "Failed to acquire buffer for draining: %d",
index 0f1c23e..d4e684f 100644 (file)
@@ -760,7 +760,7 @@ gst_omx_audio_sink_acquire_buffer (GstOMXAudioSink * self)
   GstOMXBuffer *buf = NULL;
 
   while (!buf) {
-    acq_ret = gst_omx_port_acquire_buffer (port, &buf);
+    acq_ret = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
     if (acq_ret == GST_OMX_ACQUIRE_BUFFER_ERROR) {
       goto component_error;
     } else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
index cdf6300..1a943b3 100644 (file)
@@ -1608,7 +1608,7 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
   port = self->dec_out_port;
 #endif
 
-  acq_return = gst_omx_port_acquire_buffer (port, &buf);
+  acq_return = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
   if (acq_return == GST_OMX_ACQUIRE_BUFFER_ERROR) {
     goto component_error;
   } else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
@@ -2816,7 +2816,7 @@ gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
      * _loop() can't call _finish_frame() and we might block forever
      * because no input buffers are released */
     GST_VIDEO_DECODER_STREAM_UNLOCK (self);
-    acq_ret = gst_omx_port_acquire_buffer (port, &buf);
+    acq_ret = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
 
     if (acq_ret == GST_OMX_ACQUIRE_BUFFER_ERROR) {
       GST_VIDEO_DECODER_STREAM_LOCK (self);
@@ -3149,7 +3149,7 @@ gst_omx_video_dec_finish (GstVideoDecoder * decoder)
   /* Send an EOS buffer to the component and let the base
    * class drop the EOS event. We will send it later when
    * the EOS buffer arrives on the output port. */
-  acq_ret = gst_omx_port_acquire_buffer (self->dec_in_port, &buf);
+  acq_ret = gst_omx_port_acquire_buffer (self->dec_in_port, &buf, GST_OMX_WAIT);
   if (acq_ret != GST_OMX_ACQUIRE_BUFFER_OK) {
     GST_VIDEO_DECODER_STREAM_LOCK (self);
     GST_ERROR_OBJECT (self, "Failed to acquire buffer for draining: %d",
index a8a0212..6da94a7 100644 (file)
@@ -1425,7 +1425,7 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
 
   klass = GST_OMX_VIDEO_ENC_GET_CLASS (self);
 
-  acq_return = gst_omx_port_acquire_buffer (port, &buf);
+  acq_return = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
   if (acq_return == GST_OMX_ACQUIRE_BUFFER_ERROR) {
     goto component_error;
   } else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
@@ -2673,7 +2673,7 @@ gst_omx_video_enc_handle_frame (GstVideoEncoder * encoder,
      * _loop() can't call _finish_frame() and we might block forever
      * because no input buffers are released */
     GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
-    acq_ret = gst_omx_port_acquire_buffer (port, &buf);
+    acq_ret = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
 
     if (acq_ret == GST_OMX_ACQUIRE_BUFFER_ERROR) {
       GST_VIDEO_ENCODER_STREAM_LOCK (self);
@@ -2933,7 +2933,7 @@ gst_omx_video_enc_drain (GstOMXVideoEnc * self)
   /* Send an EOS buffer to the component and let the base
    * class drop the EOS event. We will send it later when
    * the EOS buffer arrives on the output port. */
-  acq_ret = gst_omx_port_acquire_buffer (self->enc_in_port, &buf);
+  acq_ret = gst_omx_port_acquire_buffer (self->enc_in_port, &buf, GST_OMX_WAIT);
   if (acq_ret != GST_OMX_ACQUIRE_BUFFER_OK) {
     GST_VIDEO_ENCODER_STREAM_LOCK (self);
     GST_ERROR_OBJECT (self, "Failed to acquire buffer for draining: %d",