diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2018-04-26 12:30:47 +0200 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2018-06-08 09:53:01 +0200 |
commit | c8969b0dbec565f388c35f6d5eb43bc463d6348a (patch) | |
tree | 19928770061371c6e80b7e4e57bc7de629f9980a /omx/gstomxvideoenc.c | |
parent | 431eac07bffd7019fbbad0464b2a2df95d29ed66 (diff) | |
download | gst-omx-c8969b0dbec565f388c35f6d5eb43bc463d6348a.tar.gz |
omxvideoenc: implement decide_allocation
Increase the number of output buffers by the number of buffers requested
downstream.
Prevent buffers starvation if downstream is going to use dynamic buffer
mode on its input.
https://bugzilla.gnome.org/show_bug.cgi?id=795746
Diffstat (limited to 'omx/gstomxvideoenc.c')
-rw-r--r-- | omx/gstomxvideoenc.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c index faba38e..1a630c4 100644 --- a/omx/gstomxvideoenc.c +++ b/omx/gstomxvideoenc.c @@ -226,6 +226,8 @@ static gboolean gst_omx_video_enc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query); static GstCaps *gst_omx_video_enc_getcaps (GstVideoEncoder * encoder, GstCaps * filter); +static gboolean gst_omx_video_enc_decide_allocation (GstVideoEncoder * encoder, + GstQuery * query); static GstFlowReturn gst_omx_video_enc_drain (GstOMXVideoEnc * self); @@ -481,6 +483,8 @@ gst_omx_video_enc_class_init (GstOMXVideoEncClass * klass) video_encoder_class->propose_allocation = GST_DEBUG_FUNCPTR (gst_omx_video_enc_propose_allocation); video_encoder_class->getcaps = GST_DEBUG_FUNCPTR (gst_omx_video_enc_getcaps); + video_encoder_class->decide_allocation = + GST_DEBUG_FUNCPTR (gst_omx_video_enc_decide_allocation); klass->cdata.type = GST_OMX_COMPONENT_TYPE_FILTER; klass->cdata.default_sink_template_caps = "video/x-raw, " @@ -1372,11 +1376,18 @@ static gboolean gst_omx_video_enc_ensure_nb_out_buffers (GstOMXVideoEnc * self) { GstOMXVideoEncClass *klass = GST_OMX_VIDEO_ENC_GET_CLASS (self); + guint extra = 0; - if ((klass->cdata.hacks & GST_OMX_HACK_ENSURE_BUFFER_COUNT_ACTUAL)) { - if (!gst_omx_port_ensure_buffer_count_actual (self->enc_out_port)) - return FALSE; - } + if (!(klass->cdata.hacks & GST_OMX_HACK_ENSURE_BUFFER_COUNT_ACTUAL)) + return TRUE; + + /* If dowstream tell us how many buffers it needs allocate as many extra buffers so we won't starve + * if it keeps them downstream (like when using dynamic mode). */ + if (self->nb_downstream_buffers) + extra = self->nb_downstream_buffers; + + if (!gst_omx_port_ensure_buffer_count_actual (self->enc_out_port, extra)) + return FALSE; return TRUE; } @@ -1641,6 +1652,7 @@ gst_omx_video_enc_start (GstVideoEncoder * encoder) self->last_upstream_ts = 0; self->downstream_flow_ret = GST_FLOW_OK; + self->nb_downstream_buffers = 0; return TRUE; } @@ -1883,7 +1895,7 @@ gst_omx_video_enc_ensure_nb_in_buffers (GstOMXVideoEnc * self) GstOMXVideoEncClass *klass = GST_OMX_VIDEO_ENC_GET_CLASS (self); if ((klass->cdata.hacks & GST_OMX_HACK_ENSURE_BUFFER_COUNT_ACTUAL)) { - if (!gst_omx_port_ensure_buffer_count_actual (self->enc_in_port)) + if (!gst_omx_port_ensure_buffer_count_actual (self->enc_in_port, 0)) return FALSE; } @@ -3030,3 +3042,28 @@ gst_omx_video_enc_getcaps (GstVideoEncoder * encoder, GstCaps * filter) return ret; } + +static gboolean +gst_omx_video_enc_decide_allocation (GstVideoEncoder * encoder, + GstQuery * query) +{ + GstOMXVideoEnc *self = GST_OMX_VIDEO_ENC (encoder); + guint min = 1; + + if (!GST_VIDEO_ENCODER_CLASS + (gst_omx_video_enc_parent_class)->decide_allocation (encoder, query)) + return FALSE; + + if (gst_query_get_n_allocation_pools (query)) { + gst_query_parse_nth_allocation_pool (query, 0, NULL, NULL, &min, NULL); + GST_DEBUG_OBJECT (self, + "Downstream requested %d buffers, adjust number of output buffers accordingly", + min); + } else { + GST_DEBUG_OBJECT (self, "Downstream didn't set any allocation pool info"); + } + + self->nb_downstream_buffers = min; + + return TRUE; +} |