pulse: more cleanups

This commit is contained in:
Wim Taymans 2011-08-04 18:41:29 +02:00
parent 9ae85cb662
commit d9750387c1

View file

@ -832,26 +832,19 @@ gst_pulsesrc_create_stream (GstPulseSrc * pulsesrc, GstCaps * caps)
memset (&spec, 0, sizeof (GstRingBufferSpec)); memset (&spec, 0, sizeof (GstRingBufferSpec));
spec.latency_time = GST_SECOND; spec.latency_time = GST_SECOND;
if (!gst_ring_buffer_parse_caps (&spec, caps)) { if (!gst_ring_buffer_parse_caps (&spec, caps))
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, SETTINGS, goto invalid_caps;
("Can't parse caps."), (NULL));
goto fail;
}
/* Keep the refcount of the caps at 1 to make them writable */ /* Keep the refcount of the caps at 1 to make them writable */
gst_caps_unref (spec.caps); gst_caps_unref (spec.caps);
if (!gst_pulse_fill_sample_spec (&spec, &pulsesrc->sample_spec)) { if (!gst_pulse_fill_sample_spec (&spec, &pulsesrc->sample_spec))
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, SETTINGS, goto invalid_spec;
("Invalid sample specification."), (NULL));
goto fail;
}
pa_threaded_mainloop_lock (pulsesrc->mainloop); pa_threaded_mainloop_lock (pulsesrc->mainloop);
if (!pulsesrc->context) { if (!pulsesrc->context)
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED, ("Bad context"), (NULL)); goto bad_context;
goto unlock_and_fail;
}
s = gst_caps_get_structure (caps, 0); s = gst_caps_get_structure (caps, 0);
if (!gst_structure_has_field (s, "channel-layout") || if (!gst_structure_has_field (s, "channel-layout") ||
@ -869,20 +862,13 @@ gst_pulsesrc_create_stream (GstPulseSrc * pulsesrc, GstCaps * caps)
if (!(pulsesrc->stream = pa_stream_new_with_proplist (pulsesrc->context, if (!(pulsesrc->stream = pa_stream_new_with_proplist (pulsesrc->context,
name, &pulsesrc->sample_spec, name, &pulsesrc->sample_spec,
(need_channel_layout) ? NULL : &channel_map, (need_channel_layout) ? NULL : &channel_map,
pulsesrc->proplist))) { pulsesrc->proplist)))
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED, goto create_failed;
("Failed to create stream: %s",
pa_strerror (pa_context_errno (pulsesrc->context))), (NULL));
goto unlock_and_fail;
}
} else if (!(pulsesrc->stream = pa_stream_new (pulsesrc->context, } else if (!(pulsesrc->stream = pa_stream_new (pulsesrc->context,
name, &pulsesrc->sample_spec, name, &pulsesrc->sample_spec,
(need_channel_layout) ? NULL : &channel_map))) { (need_channel_layout) ? NULL : &channel_map)))
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED, goto create_failed;
("Failed to create stream: %s",
pa_strerror (pa_context_errno (pulsesrc->context))), (NULL));
goto unlock_and_fail;
}
if (need_channel_layout) { if (need_channel_layout) {
const pa_channel_map *m = pa_stream_get_channel_map (pulsesrc->stream); const pa_channel_map *m = pa_stream_get_channel_map (pulsesrc->stream);
@ -908,7 +894,33 @@ gst_pulsesrc_create_stream (GstPulseSrc * pulsesrc, GstCaps * caps)
return TRUE; return TRUE;
/* ERRORS */
invalid_caps:
{
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, SETTINGS,
("Can't parse caps."), (NULL));
goto fail;
}
invalid_spec:
{
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, SETTINGS,
("Invalid sample specification."), (NULL));
goto fail;
}
bad_context:
{
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED, ("Bad context"), (NULL));
goto unlock_and_fail;
}
create_failed:
{
GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED,
("Failed to create stream: %s",
pa_strerror (pa_context_errno (pulsesrc->context))), (NULL));
goto unlock_and_fail;
}
unlock_and_fail: unlock_and_fail:
{
gst_pulsesrc_destroy_stream (pulsesrc); gst_pulsesrc_destroy_stream (pulsesrc);
pa_threaded_mainloop_unlock (pulsesrc->mainloop); pa_threaded_mainloop_unlock (pulsesrc->mainloop);
@ -916,6 +928,7 @@ unlock_and_fail:
fail: fail:
return FALSE; return FALSE;
} }
}
/* This is essentially gst_base_src_negotiate_default() but the caps /* This is essentially gst_base_src_negotiate_default() but the caps
* are guaranteed to have a channel layout for > 2 channels * are guaranteed to have a channel layout for > 2 channels