Commit 2e89f4ec authored by Nicolas Dufresne's avatar Nicolas Dufresne

Revert "v4l2bufferpool: Port to bufferpool flush_start/stop method"

This reverts commit 2e0fb42e.

Conflicts:
	sys/v4l2/gstv4l2allocator.c
	sys/v4l2/gstv4l2bufferpool.c
	sys/v4l2/gstv4l2videodec.c
parent ba10cb14
......@@ -1221,12 +1221,6 @@ gst_v4l2_allocator_qbuf (GstV4l2Allocator * allocator,
gboolean ret = TRUE;
gint i;
g_return_val_if_fail (g_atomic_int_get (&allocator->active), FALSE);
/* Buffer already queued */
if (IS_QUEUED (group->buffer))
return TRUE;
/* update sizes */
if (V4L2_TYPE_IS_MULTIPLANAR (allocator->type)) {
for (i = 0; i < group->n_mem; i++)
......
This diff is collapsed.
......@@ -50,8 +50,6 @@ struct _GstV4l2BufferPool
GstV4l2Object *obj; /* the v4l2 object */
gint video_fd; /* a dup(2) of the v4l2object's video_fd */
GstPoll *poll; /* a poll for video_fd */
gboolean can_poll_device;
GstV4l2Allocator *vallocator;
GstAllocator *allocator;
......@@ -86,6 +84,9 @@ GstBufferPool * gst_v4l2_buffer_pool_new (GstV4l2Object *obj, GstCaps *c
GstFlowReturn gst_v4l2_buffer_pool_process (GstV4l2BufferPool * bpool, GstBuffer ** buf);
gboolean gst_v4l2_buffer_pool_stop_streaming (GstV4l2BufferPool * pool);
gboolean gst_v4l2_buffer_pool_start_streaming (GstV4l2BufferPool * pool);
void gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool,
GstBufferPool * other_pool);
......
......@@ -431,6 +431,7 @@ gst_v4l2_object_new (GstElement * element,
v4l2object->update_fps_func = update_fps_func;
v4l2object->video_fd = -1;
v4l2object->poll = gst_poll_new (TRUE);
v4l2object->active = FALSE;
v4l2object->videodev = g_strdup (default_device);
......@@ -460,6 +461,9 @@ gst_v4l2_object_destroy (GstV4l2Object * v4l2object)
if (v4l2object->videodev)
g_free (v4l2object->videodev);
if (v4l2object->poll)
gst_poll_free (v4l2object->poll);
if (v4l2object->channel)
g_free (v4l2object->channel);
......@@ -3039,27 +3043,19 @@ gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps)
gboolean
gst_v4l2_object_unlock (GstV4l2Object * v4l2object)
{
gboolean ret = TRUE;
GST_LOG_OBJECT (v4l2object->element, "start flushing");
if (v4l2object->pool && gst_buffer_pool_is_active (v4l2object->pool))
gst_buffer_pool_set_flushing (v4l2object->pool, TRUE);
GST_LOG_OBJECT (v4l2object->element, "flush poll");
gst_poll_set_flushing (v4l2object->poll, TRUE);
return ret;
return TRUE;
}
gboolean
gst_v4l2_object_unlock_stop (GstV4l2Object * v4l2object)
{
gboolean ret = TRUE;
GST_LOG_OBJECT (v4l2object->element, "flush stop poll");
gst_poll_set_flushing (v4l2object->poll, FALSE);
GST_LOG_OBJECT (v4l2object->element, "stop flushing");
if (v4l2object->pool && gst_buffer_pool_is_active (v4l2object->pool))
gst_buffer_pool_set_flushing (v4l2object->pool, FALSE);
return ret;
return TRUE;
}
gboolean
......
......@@ -88,6 +88,8 @@ struct _GstV4l2Object {
/* the video-device's file descriptor */
gint video_fd;
GstV4l2IOMode mode;
GstPoll * poll;
gboolean can_poll_device;
gboolean active;
gboolean streaming;
......
......@@ -533,6 +533,19 @@ gst_v4l2_transform_sink_event (GstBaseTransform * trans, GstEvent * event)
gst_v4l2_object_unlock (self->v4l2output);
gst_v4l2_object_unlock (self->v4l2capture);
break;
case GST_EVENT_FLUSH_STOP:
GST_DEBUG_OBJECT (self, "flush stop");
if (self->v4l2output->pool) {
gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
(self->v4l2output->pool));
gst_v4l2_buffer_pool_start_streaming (GST_V4L2_BUFFER_POOL
(self->v4l2capture->pool));
gst_v4l2_object_unlock_stop (self->v4l2output);
}
if (self->v4l2capture->pool)
gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
(self->v4l2capture->pool));
default:
break;
}
......@@ -542,9 +555,12 @@ gst_v4l2_transform_sink_event (GstBaseTransform * trans, GstEvent * event)
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_STOP:
/* Buffer should be back now */
GST_DEBUG_OBJECT (self, "flush stop");
gst_v4l2_object_unlock_stop (self->v4l2capture);
gst_v4l2_object_unlock_stop (self->v4l2output);
if (self->v4l2capture->pool) {
gst_v4l2_buffer_pool_start_streaming (GST_V4L2_BUFFER_POOL
(self->v4l2capture->pool));
gst_v4l2_object_unlock_stop (self->v4l2capture);
}
GST_DEBUG_OBJECT (self, "flush stop done");
break;
default:
break;
......
......@@ -259,23 +259,23 @@ gst_v4l2_video_dec_flush (GstVideoDecoder * decoder)
{
GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
GST_DEBUG_OBJECT (self, "Flushed");
GST_DEBUG_OBJECT (self, "Flushing");
/* Ensure the processing thread has stopped for the reverse playback
* discount case */
if (g_atomic_int_get (&self->processing)) {
GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
gst_v4l2_object_unlock (self->v4l2output);
gst_v4l2_object_unlock (self->v4l2capture);
gst_pad_stop_task (decoder->srcpad);
GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
}
/* Wait for capture thread to stop */
GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
gst_v4l2_object_unlock (self->v4l2capture);
gst_pad_stop_task (decoder->srcpad);
GST_VIDEO_DECODER_STREAM_LOCK (decoder);
self->output_flow = GST_FLOW_OK;
gst_v4l2_object_unlock_stop (self->v4l2output);
gst_v4l2_object_unlock_stop (self->v4l2capture);
if (self->v4l2output->pool)
gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
(self->v4l2output->pool));
if (self->v4l2capture->pool)
gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
(self->v4l2capture->pool));
return TRUE;
}
......@@ -308,13 +308,15 @@ gst_v4l2_video_dec_finish (GstVideoDecoder * decoder)
v4l2output->pool), &buffer);
gst_buffer_unref (buffer);
}
/* and ensure the processing thread has stopped in case another error
* occured. */
gst_v4l2_object_unlock (self->v4l2capture);
gst_pad_stop_task (decoder->srcpad);
GST_VIDEO_DECODER_STREAM_LOCK (decoder);
/* Ensure the processing thread has stopped */
if (g_atomic_int_get (&self->processing)) {
gst_v4l2_object_unlock (self->v4l2capture);
gst_pad_stop_task (decoder->srcpad);
g_assert (g_atomic_int_get (&self->processing) == FALSE);
}
if (ret == GST_FLOW_FLUSHING)
ret = self->output_flow;
......@@ -487,9 +489,11 @@ gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
}
GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
gst_v4l2_object_unlock_stop (self->v4l2output);
ret =
gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
v4l2output->pool), &codec_data);
gst_v4l2_object_unlock (self->v4l2output);
GST_VIDEO_DECODER_STREAM_LOCK (decoder);
gst_buffer_unref (codec_data);
......@@ -528,6 +532,14 @@ gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
GST_DEBUG_OBJECT (self, "Starting decoding thread");
/* Enable processing input */
if (!gst_v4l2_buffer_pool_start_streaming (GST_V4L2_BUFFER_POOL
(self->v4l2capture->pool)))
goto start_streaming_failed;
gst_v4l2_object_unlock_stop (self->v4l2output);
gst_v4l2_object_unlock_stop (self->v4l2capture);
/* Start the processing task, when it quits, the task will disable input
* processing to unlock input if draining, or prevent potential block */
g_atomic_int_set (&self->processing, TRUE);
......@@ -566,6 +578,13 @@ not_negotiated:
ret = GST_FLOW_NOT_NEGOTIATED;
goto drop;
}
start_streaming_failed:
{
GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
(_("Failed to re-enabled decoder.")),
("Could not re-enqueue and start streaming on decide."));
return GST_FLOW_ERROR;
}
activate_failed:
{
GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
......@@ -705,31 +724,17 @@ static gboolean
gst_v4l2_video_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
{
GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
gboolean ret;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
GST_DEBUG_OBJECT (self, "flush start");
gst_v4l2_object_unlock (self->v4l2output);
gst_v4l2_object_unlock (self->v4l2capture);
break;
default:
break;
}
ret = GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
/* The processing thread should stop now, wait for it */
gst_pad_stop_task (decoder->srcpad);
GST_DEBUG_OBJECT (self, "flush start done");
break;
default:
break;
}
return ret;
return GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event);
}
static GstStateChangeReturn
......@@ -737,13 +742,11 @@ gst_v4l2_video_dec_change_state (GstElement * element,
GstStateChange transition)
{
GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (element);
GstVideoDecoder *decoder = GST_VIDEO_DECODER (element);
if (transition == GST_STATE_CHANGE_PAUSED_TO_READY) {
g_atomic_int_set (&self->active, FALSE);
gst_v4l2_object_unlock (self->v4l2output);
gst_v4l2_object_unlock (self->v4l2capture);
gst_pad_stop_task (decoder->srcpad);
}
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
......
......@@ -514,6 +514,7 @@ gst_v4l2_open (GstV4l2Object * v4l2object)
{
struct stat st;
int libv4l2_fd;
GstPollFD pollfd = GST_POLL_FD_INIT;
GST_DEBUG_OBJECT (v4l2object->element, "Trying to open device %s",
v4l2object->videodev);
......@@ -550,6 +551,8 @@ gst_v4l2_open (GstV4l2Object * v4l2object)
if (libv4l2_fd != -1)
v4l2object->video_fd = libv4l2_fd;
v4l2object->can_poll_device = TRUE;
/* get capabilities, error will be posted */
if (!gst_v4l2_get_capabilities (v4l2object))
goto error;
......@@ -586,6 +589,14 @@ gst_v4l2_open (GstV4l2Object * v4l2object)
"Opened device '%s' (%s) successfully",
v4l2object->vcap.card, v4l2object->videodev);
pollfd.fd = v4l2object->video_fd;
gst_poll_add_fd (v4l2object->poll, &pollfd);
if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
|| v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
gst_poll_fd_ctl_read (v4l2object->poll, &pollfd, TRUE);
else
gst_poll_fd_ctl_write (v4l2object->poll, &pollfd, TRUE);
if (v4l2object->extra_controls)
gst_v4l2_set_controls (v4l2object, v4l2object->extra_controls);
......@@ -661,6 +672,8 @@ error:
gboolean
gst_v4l2_dup (GstV4l2Object * v4l2object, GstV4l2Object * other)
{
GstPollFD pollfd = GST_POLL_FD_INIT;
GST_DEBUG_OBJECT (v4l2object->element, "Trying to dup device %s",
other->videodev);
......@@ -683,7 +696,16 @@ gst_v4l2_dup (GstV4l2Object * v4l2object, GstV4l2Object * other)
"Cloned device '%s' (%s) successfully",
v4l2object->vcap.card, v4l2object->videodev);
pollfd.fd = v4l2object->video_fd;
gst_poll_add_fd (v4l2object->poll, &pollfd);
if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
|| v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
gst_poll_fd_ctl_read (v4l2object->poll, &pollfd, TRUE);
else
gst_poll_fd_ctl_write (v4l2object->poll, &pollfd, TRUE);
v4l2object->never_interlaced = other->never_interlaced;
v4l2object->can_poll_device = TRUE;
return TRUE;
......@@ -706,6 +728,7 @@ not_open:
gboolean
gst_v4l2_close (GstV4l2Object * v4l2object)
{
GstPollFD pollfd = GST_POLL_FD_INIT;
GST_DEBUG_OBJECT (v4l2object->element, "Trying to close %s",
v4l2object->videodev);
......@@ -714,6 +737,8 @@ gst_v4l2_close (GstV4l2Object * v4l2object)
/* close device */
v4l2_close (v4l2object->video_fd);
pollfd.fd = v4l2object->video_fd;
gst_poll_remove_fd (v4l2object->poll, &pollfd);
v4l2object->video_fd = -1;
/* empty lists */
......
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