decklink: Disable inputs/outputs in PAUSED->READY to allow going to PAUSED again from there

https://bugzilla.gnome.org/show_bug.cgi?id=755426
This commit is contained in:
Sebastian Dröge 2015-09-22 19:35:00 +02:00
parent 3417a15076
commit e0fd5317df
3 changed files with 72 additions and 21 deletions

View file

@ -109,6 +109,8 @@ static GstFlowReturn gst_decklink_audio_src_create (GstPushSrc * psrc,
static gboolean gst_decklink_audio_src_open (GstDecklinkAudioSrc * self);
static gboolean gst_decklink_audio_src_close (GstDecklinkAudioSrc * self);
static gboolean gst_decklink_audio_src_stop (GstDecklinkAudioSrc * self);
#define parent_class gst_decklink_audio_src_parent_class
G_DEFINE_TYPE (GstDecklinkAudioSrc, gst_decklink_audio_src, GST_TYPE_PUSH_SRC);
@ -646,7 +648,7 @@ gst_decklink_audio_src_unlock_stop (GstBaseSrc * bsrc)
static gboolean
gst_decklink_audio_src_open (GstDecklinkAudioSrc * self)
{
GST_DEBUG_OBJECT (self, "Starting");
GST_DEBUG_OBJECT (self, "Opening");
self->input =
gst_decklink_acquire_nth_input (self->device_number,
@ -666,18 +668,13 @@ gst_decklink_audio_src_open (GstDecklinkAudioSrc * self)
static gboolean
gst_decklink_audio_src_close (GstDecklinkAudioSrc * self)
{
GST_DEBUG_OBJECT (self, "Stopping");
GST_DEBUG_OBJECT (self, "Closing");
if (self->input) {
g_mutex_lock (&self->input->lock);
self->input->got_audio_packet = NULL;
self->input->audio_enabled = FALSE;
if (self->input->start_streams && self->input->videosrc)
self->input->start_streams (self->input->videosrc);
g_mutex_unlock (&self->input->lock);
self->input->input->DisableAudioInput ();
gst_decklink_release_nth_input (self->device_number,
GST_ELEMENT_CAST (self), TRUE);
self->input = NULL;
@ -686,6 +683,26 @@ gst_decklink_audio_src_close (GstDecklinkAudioSrc * self)
return TRUE;
}
static gboolean
gst_decklink_audio_src_stop (GstDecklinkAudioSrc * self)
{
GST_DEBUG_OBJECT (self, "Stopping");
g_queue_foreach (&self->current_packets, (GFunc) capture_packet_free,
NULL);
g_queue_clear (&self->current_packets);
if (self->input && self->input->audio_enabled) {
g_mutex_lock (&self->input->lock);
self->input->audio_enabled = FALSE;
g_mutex_unlock (&self->input->lock);
self->input->input->DisableAudioInput ();
}
return TRUE;
}
#if 0
static gboolean
in_same_pipeline (GstElement * a, GstElement * b)
@ -769,9 +786,7 @@ gst_decklink_audio_src_change_state (GstElement * element,
switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:
g_queue_foreach (&self->current_packets, (GFunc) capture_packet_free,
NULL);
g_queue_clear (&self->current_packets);
gst_decklink_audio_src_stop (self);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
gst_decklink_audio_src_close (self);

View file

@ -142,6 +142,7 @@ static GstFlowReturn gst_decklink_video_sink_render (GstBaseSink * bsink,
GstBuffer * buffer);
static gboolean gst_decklink_video_sink_open (GstBaseSink * bsink);
static gboolean gst_decklink_video_sink_close (GstBaseSink * bsink);
static gboolean gst_decklink_video_sink_stop (GstDecklinkVideoSink * self);
static gboolean gst_decklink_video_sink_propose_allocation (GstBaseSink * bsink,
GstQuery * query);
@ -539,7 +540,7 @@ gst_decklink_video_sink_open (GstBaseSink * bsink)
GstDecklinkVideoSink *self = GST_DECKLINK_VIDEO_SINK_CAST (bsink);
const GstDecklinkMode *mode;
GST_DEBUG_OBJECT (self, "Starting");
GST_DEBUG_OBJECT (self, "Stopping");
self->output =
gst_decklink_acquire_nth_output (self->device_number,
@ -569,7 +570,7 @@ gst_decklink_video_sink_close (GstBaseSink * bsink)
{
GstDecklinkVideoSink *self = GST_DECKLINK_VIDEO_SINK_CAST (bsink);
GST_DEBUG_OBJECT (self, "Stopping");
GST_DEBUG_OBJECT (self, "Closing");
if (self->output) {
g_mutex_lock (&self->output->lock);
@ -580,7 +581,6 @@ gst_decklink_video_sink_close (GstBaseSink * bsink)
g_mutex_unlock (&self->output->lock);
self->output->output->DisableVideoOutput ();
self->output->output->SetScheduledFrameCompletionCallback (NULL);
gst_decklink_release_nth_output (self->device_number,
GST_ELEMENT_CAST (self), FALSE);
self->output = NULL;
@ -589,6 +589,23 @@ gst_decklink_video_sink_close (GstBaseSink * bsink)
return TRUE;
}
static gboolean
gst_decklink_video_sink_stop (GstDecklinkVideoSink * self)
{
GST_DEBUG_OBJECT (self, "Stopping");
if (self->output && self->output->video_enabled) {
g_mutex_lock (&self->output->lock);
self->output->video_enabled = FALSE;
g_mutex_unlock (&self->output->lock);
self->output->output->DisableVideoOutput ();
self->output->output->SetScheduledFrameCompletionCallback (NULL);
}
return TRUE;
}
static void
gst_decklink_video_sink_start_scheduled_playback (GstElement * element)
{
@ -732,6 +749,7 @@ gst_decklink_video_sink_change_state (GstElement * element,
self->output->clock_last_time = 0;
self->output->clock_offset = 0;
g_mutex_unlock (&self->output->lock);
gst_decklink_video_sink_stop (self);
break;
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:{
GstClockTime start_time;

View file

@ -100,6 +100,8 @@ static GstFlowReturn gst_decklink_video_src_create (GstPushSrc * psrc,
static gboolean gst_decklink_video_src_open (GstDecklinkVideoSrc * self);
static gboolean gst_decklink_video_src_close (GstDecklinkVideoSrc * self);
static gboolean gst_decklink_video_src_stop (GstDecklinkVideoSrc * self);
static void gst_decklink_video_src_start_streams (GstElement * element);
#define parent_class gst_decklink_video_src_parent_class
@ -626,7 +628,7 @@ gst_decklink_video_src_open (GstDecklinkVideoSrc * self)
{
const GstDecklinkMode *mode;
GST_DEBUG_OBJECT (self, "Starting");
GST_DEBUG_OBJECT (self, "Opening");
self->input =
gst_decklink_acquire_nth_input (self->device_number,
@ -654,18 +656,16 @@ static gboolean
gst_decklink_video_src_close (GstDecklinkVideoSrc * self)
{
GST_DEBUG_OBJECT (self, "Stopping");
GST_DEBUG_OBJECT (self, "Closing");
if (self->input) {
g_mutex_lock (&self->input->lock);
self->input->got_video_frame = NULL;
self->input->mode = NULL;
self->input->video_enabled = FALSE;
if (self->input->start_streams)
self->input->start_streams (self->input->videosrc);
self->input->start_streams = NULL;
g_mutex_unlock (&self->input->lock);
self->input->input->DisableVideoInput ();
gst_decklink_release_nth_input (self->device_number,
GST_ELEMENT_CAST (self), FALSE);
self->input = NULL;
@ -674,6 +674,26 @@ gst_decklink_video_src_close (GstDecklinkVideoSrc * self)
return TRUE;
}
static gboolean
gst_decklink_video_src_stop (GstDecklinkVideoSrc * self)
{
GST_DEBUG_OBJECT (self, "Stopping");
g_queue_foreach (&self->current_frames, (GFunc) capture_frame_free, NULL);
g_queue_clear (&self->current_frames);
self->caps_mode = GST_DECKLINK_MODE_AUTO;
if (self->input && self->input->video_enabled) {
g_mutex_lock (&self->input->lock);
self->input->video_enabled = FALSE;
g_mutex_unlock (&self->input->lock);
self->input->input->DisableVideoInput ();
}
return TRUE;
}
static void
gst_decklink_video_src_start_streams (GstElement * element)
{
@ -774,9 +794,7 @@ gst_decklink_video_src_change_state (GstElement * element,
self->input->clock_offset = 0;
g_mutex_unlock (&self->input->lock);
g_queue_foreach (&self->current_frames, (GFunc) capture_frame_free, NULL);
g_queue_clear (&self->current_frames);
self->caps_mode = GST_DECKLINK_MODE_AUTO;
gst_decklink_video_src_stop (self);
break;
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:{
HRESULT res;