diff options
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; +} |