Commit 418eae3e authored by Wim Taymans's avatar Wim Taymans
Browse files

goom: add latency compensation code.

Implement a latency query and report how much latency we will add to the
stream.
Alse make some defaults for the default width/height/framerate

Fixes #631303
parent 1e310bc1
......@@ -50,6 +50,11 @@
GST_DEBUG_CATEGORY (goom_debug);
#define GST_CAT_DEFAULT goom_debug
#define DEFAULT_WIDTH 320
#define DEFAULT_HEIGHT 240
#define DEFAULT_FPS_N 25
#define DEFAULT_FPS_D 1
/* signals and args */
enum
{
......@@ -93,6 +98,8 @@ static GstFlowReturn gst_goom_chain (GstPad * pad, GstBuffer * buffer);
static gboolean gst_goom_src_event (GstPad * pad, GstEvent * event);
static gboolean gst_goom_sink_event (GstPad * pad, GstEvent * event);
static gboolean gst_goom_src_query (GstPad * pad, GstQuery * query);
static gboolean gst_goom_sink_setcaps (GstPad * pad, GstCaps * caps);
static gboolean gst_goom_src_setcaps (GstPad * pad, GstCaps * caps);
......@@ -170,14 +177,16 @@ gst_goom_init (GstGoom * goom)
GST_DEBUG_FUNCPTR (gst_goom_src_setcaps));
gst_pad_set_event_function (goom->srcpad,
GST_DEBUG_FUNCPTR (gst_goom_src_event));
gst_pad_set_query_function (goom->srcpad,
GST_DEBUG_FUNCPTR (gst_goom_src_query));
gst_element_add_pad (GST_ELEMENT (goom), goom->srcpad);
goom->adapter = gst_adapter_new ();
goom->width = 320;
goom->height = 200;
goom->fps_n = 25; /* desired frame rate */
goom->fps_d = 1; /* desired frame rate */
goom->width = DEFAULT_WIDTH;
goom->height = DEFAULT_HEIGHT;
goom->fps_n = DEFAULT_FPS_N; /* desired frame rate */
goom->fps_d = DEFAULT_FPS_D; /* desired frame rate */
goom->channels = 0;
goom->rate = 0;
goom->duration = 0;
......@@ -287,9 +296,10 @@ gst_goom_src_negotiate (GstGoom * goom)
}
structure = gst_caps_get_structure (target, 0);
gst_structure_fixate_field_nearest_int (structure, "width", 320);
gst_structure_fixate_field_nearest_int (structure, "height", 240);
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
gst_structure_fixate_field_nearest_int (structure, "width", DEFAULT_WIDTH);
gst_structure_fixate_field_nearest_int (structure, "height", DEFAULT_HEIGHT);
gst_structure_fixate_field_nearest_fraction (structure, "framerate",
DEFAULT_FPS_N, DEFAULT_FPS_D);
gst_pad_set_caps (goom->srcpad, target);
gst_caps_unref (target);
......@@ -388,6 +398,63 @@ gst_goom_sink_event (GstPad * pad, GstEvent * event)
return res;
}
static gboolean
gst_goom_src_query (GstPad * pad, GstQuery * query)
{
gboolean res;
GstGoom *goom;
goom = GST_GOOM (gst_pad_get_parent (pad));
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_LATENCY:
{
/* We need to send the query upstream and add the returned latency to our
* own */
GstClockTime min_latency, max_latency;
gboolean us_live;
GstClockTime our_latency;
guint max_samples;
if ((res = gst_pad_peer_query (goom->sinkpad, query))) {
gst_query_parse_latency (query, &us_live, &min_latency, &max_latency);
GST_DEBUG_OBJECT (goom, "Peer latency: min %"
GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
/* the max samples we must buffer buffer */
max_samples = MAX (GOOM_SAMPLES, goom->spf);
our_latency =
gst_util_uint64_scale_int (max_samples, GST_SECOND, goom->rate);
GST_DEBUG_OBJECT (goom, "Our latency: %" GST_TIME_FORMAT,
GST_TIME_ARGS (our_latency));
/* we add some latency but only if we need to buffer more than what
* upstream gives us */
min_latency = MAX (our_latency, min_latency);
if (max_latency != -1)
max_latency = MAX (our_latency, max_latency);
GST_DEBUG_OBJECT (goom, "Calculated total latency : min %"
GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
gst_query_set_latency (query, TRUE, min_latency, max_latency);
}
break;
}
default:
res = gst_pad_peer_query (goom->sinkpad, query);
break;
}
gst_object_unref (goom);
return res;
}
static GstFlowReturn
get_buffer (GstGoom * goom, GstBuffer ** outbuf)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment