videotestsrc: use baseclass allocator negotiation logic

Let the baseclass implement the negotiation of the allocators.
Influence the allocator buffersize.
Use the fill vmethod to fill the buffer with data.
This commit is contained in:
Wim Taymans 2011-06-13 12:09:34 +02:00
parent a8971beee0
commit f542a3e582
2 changed files with 39 additions and 84 deletions

View file

@ -102,10 +102,11 @@ static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
static void gst_video_test_src_get_times (GstBaseSrc * basesrc, static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
GstBuffer * buffer, GstClockTime * start, GstClockTime * end); GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
static GstFlowReturn gst_video_test_src_create (GstPushSrc * psrc, static gboolean gst_video_test_src_setup_allocation (GstBaseSrc * bsrc,
GstBuffer ** buffer); GstQuery * query);
static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
GstBuffer * buffer);
static gboolean gst_video_test_src_start (GstBaseSrc * basesrc); static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
static gboolean gst_video_test_src_stop (GstBaseSrc * basesrc);
#define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ()) #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
static GType static GType
@ -303,9 +304,9 @@ gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
gstbasesrc_class->query = gst_video_test_src_query; gstbasesrc_class->query = gst_video_test_src_query;
gstbasesrc_class->get_times = gst_video_test_src_get_times; gstbasesrc_class->get_times = gst_video_test_src_get_times;
gstbasesrc_class->start = gst_video_test_src_start; gstbasesrc_class->start = gst_video_test_src_start;
gstbasesrc_class->stop = gst_video_test_src_stop; gstbasesrc_class->setup_allocation = gst_video_test_src_setup_allocation;
gstpushsrc_class->create = gst_video_test_src_create; gstpushsrc_class->fill = gst_video_test_src_fill;
} }
static void static void
@ -651,6 +652,27 @@ no_framerate:
} }
} }
static gboolean
gst_video_test_src_setup_allocation (GstBaseSrc * bsrc, GstQuery * query)
{
GstVideoTestSrc *videotestsrc;
GstBufferPool *pool;
guint size, min, max, prefix, alignment;
videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
&alignment, &pool);
/* adjust size */
size = MAX (size, videotestsrc->size);
gst_query_set_allocation_params (query, size, min, max, prefix,
alignment, pool);
return TRUE;
}
static gboolean static gboolean
gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps) gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
{ {
@ -659,9 +681,6 @@ gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
struct fourcc_list_struct *fourcc; struct fourcc_list_struct *fourcc;
GstVideoTestSrc *videotestsrc; GstVideoTestSrc *videotestsrc;
GstVideoTestSrcColorSpec color_spec; GstVideoTestSrcColorSpec color_spec;
GstQuery *query;
GstBufferPool *pool;
guint size, min, max, prefix, alignment;
videotestsrc = GST_VIDEO_TEST_SRC (bsrc); videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
@ -678,45 +697,13 @@ gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
videotestsrc->rate_denominator = rate_denominator; videotestsrc->rate_denominator = rate_denominator;
videotestsrc->bpp = videotestsrc->fourcc->bitspp; videotestsrc->bpp = videotestsrc->fourcc->bitspp;
videotestsrc->color_spec = color_spec; videotestsrc->color_spec = color_spec;
videotestsrc->size =
gst_video_test_src_get_size (videotestsrc, width, height);
GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps", GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
videotestsrc->width, videotestsrc->height, videotestsrc->width, videotestsrc->height,
videotestsrc->rate_numerator, videotestsrc->rate_denominator); videotestsrc->rate_numerator, videotestsrc->rate_denominator);
/* find a pool for the negotiated caps now */
query = gst_query_new_allocation (caps, TRUE);
if (gst_pad_peer_query (bsrc->srcpad, query)) {
/* we got configuration from our peer, parse them */
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
&alignment, &pool);
} else {
size = gst_video_test_src_get_size (videotestsrc, width, height);
min = max = 0;
prefix = 0;
alignment = 0;
pool = NULL;
}
if (pool == NULL) {
GstStructure *config;
/* we did not get a pool, make one ourselves then */
pool = gst_buffer_pool_new ();
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_set (config, caps, size, min, max, prefix,
alignment);
gst_buffer_pool_set_config (pool, config);
}
if (videotestsrc->pool)
gst_object_unref (videotestsrc->pool);
videotestsrc->pool = pool;
/* and activate */
gst_buffer_pool_set_active (pool, TRUE);
return res; return res;
/* ERRORS */ /* ERRORS */
@ -861,18 +848,16 @@ gst_video_test_src_is_seekable (GstBaseSrc * psrc)
} }
static GstFlowReturn static GstFlowReturn
gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer) gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
{ {
GstVideoTestSrc *src; GstVideoTestSrc *src;
gsize size; gsize size;
GstBuffer *outbuf = NULL;
GstFlowReturn res;
GstClockTime next_time; GstClockTime next_time;
guint8 *data; guint8 *data;
src = GST_VIDEO_TEST_SRC (psrc); src = GST_VIDEO_TEST_SRC (psrc);
if (G_UNLIKELY (src->pool == NULL)) if (G_UNLIKELY (src->fourcc == NULL))
goto not_negotiated; goto not_negotiated;
/* 0 framerate and we are at the second frame, eos */ /* 0 framerate and we are at the second frame, eos */
@ -882,41 +867,35 @@ gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
GST_LOG_OBJECT (src, GST_LOG_OBJECT (src,
"creating buffer from pool for frame %d", (gint) src->n_frames); "creating buffer from pool for frame %d", (gint) src->n_frames);
res = gst_buffer_pool_acquire_buffer (src->pool, &outbuf, NULL); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE);
if (res != GST_FLOW_OK)
goto no_buffer;
data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE);
memset (data, 0, size); memset (data, 0, size);
src->tmpline_u8 = g_malloc (src->width + 8); src->tmpline_u8 = g_malloc (src->width + 8);
src->tmpline = g_malloc ((src->width + 8) * 4); src->tmpline = g_malloc ((src->width + 8) * 4);
src->tmpline2 = g_malloc ((src->width + 8) * 4); src->tmpline2 = g_malloc ((src->width + 8) * 4);
src->make_image (src, (void *) data, src->width, src->height); src->make_image (src, (void *) data, src->width, src->height);
gst_buffer_unmap (outbuf, data, size); gst_buffer_unmap (buffer, data, size);
g_free (src->tmpline); g_free (src->tmpline);
g_free (src->tmpline2); g_free (src->tmpline2);
g_free (src->tmpline_u8); g_free (src->tmpline_u8);
GST_BUFFER_TIMESTAMP (outbuf) = src->timestamp_offset + src->running_time; GST_BUFFER_TIMESTAMP (buffer) = src->timestamp_offset + src->running_time;
GST_BUFFER_OFFSET (outbuf) = src->n_frames; GST_BUFFER_OFFSET (buffer) = src->n_frames;
src->n_frames++; src->n_frames++;
GST_BUFFER_OFFSET_END (outbuf) = src->n_frames; GST_BUFFER_OFFSET_END (buffer) = src->n_frames;
if (src->rate_numerator) { if (src->rate_numerator) {
next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND, next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
src->rate_denominator, src->rate_numerator); src->rate_denominator, src->rate_numerator);
GST_BUFFER_DURATION (outbuf) = next_time - src->running_time; GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
} else { } else {
next_time = src->timestamp_offset; next_time = src->timestamp_offset;
/* NONE means forever */ /* NONE means forever */
GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE; GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
} }
src->running_time = next_time; src->running_time = next_time;
*buffer = outbuf;
return GST_FLOW_OK; return GST_FLOW_OK;
not_negotiated: not_negotiated:
@ -930,12 +909,6 @@ eos:
GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames); GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
return GST_FLOW_UNEXPECTED; return GST_FLOW_UNEXPECTED;
} }
no_buffer:
{
GST_DEBUG_OBJECT (src, "could not allocate buffer, reason %s",
gst_flow_get_name (res));
return res;
}
} }
static gboolean static gboolean
@ -949,22 +922,6 @@ gst_video_test_src_start (GstBaseSrc * basesrc)
return TRUE; return TRUE;
} }
static gboolean
gst_video_test_src_stop (GstBaseSrc * basesrc)
{
GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
/* deactivate */
if (src->pool) {
gst_buffer_pool_set_active (src->pool, FALSE);
gst_object_unref (src->pool);
}
src->pool = NULL;
return TRUE;
}
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {

View file

@ -142,9 +142,7 @@ struct _GstVideoTestSrc {
gint bpp; gint bpp;
gint rate_numerator; gint rate_numerator;
gint rate_denominator; gint rate_denominator;
guint size;
/* the bufferpool */
GstBufferPool *pool;
/* private */ /* private */
gint64 timestamp_offset; /* base offset */ gint64 timestamp_offset; /* base offset */