#include <gst/pbutils/pbutils.h> /* only used for GST_PLUGINS_BASE_VERSION_* */
#include <gst/glib-compat-private.h>
-
+#if defined(__TIZEN__) && defined(PCM_DUMP_ENABLE)
+#include <vconf.h>
+#endif /* __TIZEN__ && PCM_DUMP_ENABLE */
#include "pulsesink.h"
#include "pulseutil.h"
#define DEFAULT_SERVER NULL
#define DEFAULT_DEVICE NULL
+#define DEFAULT_CURRENT_DEVICE NULL
#define DEFAULT_DEVICE_NAME NULL
#define DEFAULT_VOLUME 1.0
#define DEFAULT_MUTE FALSE
#define MAX_VOLUME 10.0
+#ifdef __TIZEN__
+#define DEFAULT_AUDIO_LATENCY "mid"
+#define DEFAULT_AUTO_RENDER_DELAY FALSE
+#endif /* __TIZEN__ */
enum
{
PROP_0,
PROP_SERVER,
PROP_DEVICE,
+ PROP_CURRENT_DEVICE,
PROP_DEVICE_NAME,
PROP_VOLUME,
PROP_MUTE,
PROP_CLIENT_NAME,
PROP_STREAM_PROPERTIES,
+#ifdef __TIZEN__
+ PROP_AUDIO_LATENCY,
+ PROP_AUTO_RENDER_DELAY,
+#endif /* __TIZEN__ */
PROP_LAST
};
+#if defined(__TIZEN__) && defined(PCM_DUMP_ENABLE)
+#define GST_PULSESINK_DUMP_VCONF_KEY "memory/private/sound/pcm_dump"
+#define GST_PULSESINK_DUMP_INPUT_PATH_PREFIX "/tmp/dump_pulsesink_in_"
+#define GST_PULSESINK_DUMP_OUTPUT_PATH_PREFIX "/tmp/dump_pulsesink_out_"
+#define GST_PULSESINK_DUMP_INPUT_FLAG 0x00000400
+#define GST_PULSESINK_DUMP_OUTPUT_FLAG 0x00000800
+#endif /* __TIZEN__ && PCM_DUMP_ENABLE */
+
#define GST_TYPE_PULSERING_BUFFER \
(gst_pulseringbuffer_get_type())
#define GST_PULSERING_BUFFER(obj) \
typedef struct _GstPulseContext GstPulseContext;
+/* A note on threading.
+ *
+ * We use a pa_threaded_mainloop to interact with the PulseAudio server. This
+ * starts up a separate thread that runs a mainloop to carry back events,
+ * messages and timing updates from the PulseAudio server.
+ *
+ * In most cases, the PulseAudio API we use communicates with the server and
+ * processes replies asynchronously. Operations on PA objects that result in
+ * such communication are protected with a pa_threaded_mainloop_lock() and
+ * pa_threaded_mainloop_unlock(). These guarantee mutual exclusion with the
+ * mainloop thread -- when an iteration of the mainloop thread begins, it first
+ * tries to acquire this lock, and cannot do so if our code also holds that
+ * lock.
+ *
+ * When we need to complete an operation synchronously, we use
+ * pa_threaded_mainloop_wait() and pa_threaded_mainloop_signal(). These work
+ * much as pthread conditionals do. pa_threaded_mainloop_wait() is called with
+ * the mainloop lock held. It releases the lock (thereby allowing the mainloop
+ * to execute), and waits till one of our callbacks to be executed by the
+ * mainloop thread calls pa_threaded_mainloop_signal(). At the end of the
+ * mainloop iteration, the pa_threaded_mainloop_wait() will reacquire the
+ * mainloop lock and return control to the caller.
+ */
+
/* Store the PA contexts in a hash table to allow easy sharing among
* multiple instances of the sink. Keys are $context_name@$server_name
* (strings) and values should be GstPulseContext pointers.
static guint gst_pulseringbuffer_commit (GstAudioRingBuffer * buf,
guint64 * sample, guchar * data, gint in_samples, gint out_samples,
gint * accum);
+#ifdef __TIZEN__
+static gboolean gst_pulsering_set_corked (GstPulseRingBuffer * pbuf, gboolean corked,
+ gboolean wait);
+#endif
G_DEFINE_TYPE (GstPulseRingBuffer, gst_pulseringbuffer,
GST_TYPE_AUDIO_RING_BUFFER);
gst_pulsering_destroy_context (pbuf);
pa_threaded_mainloop_unlock (mainloop);
+#if defined(__TIZEN__) && defined(PCM_DUMP_ENABLE)
+ if (psink->dump_fd_input) {
+ fclose(psink->dump_fd_input);
+ psink->dump_fd_input = NULL;
+ }
+#endif /* __TIZEN__ && PCM_DUMP_ENABLE */
+
GST_LOG_OBJECT (psink, "closed device");
return TRUE;
GST_TIMEVAL_TO_TIME (info->timestamp), info->write_index_corrupt,
info->write_index, info->read_index_corrupt, info->read_index,
info->sink_usec, sink_usec);
+#ifdef __TIZEN__
+ if (!psink->auto_render_delay)
+ return;
+
+ if (sink_usec < info->sink_usec)
+ gst_base_sink_set_render_delay (GST_BASE_SINK(psink),
+ (info->sink_usec - sink_usec) * G_GINT64_CONSTANT (1000));
+ else
+ gst_base_sink_set_render_delay (GST_BASE_SINK(psink), 0);
+
+ GST_DEBUG_OBJECT (psink,
+ "Current render delay is %llu", gst_base_sink_get_render_delay (GST_BASE_SINK(psink)));
+#endif
}
static void
GST_ELEMENT_ERROR (psink, STREAM, FORMAT, ("Sink format changed"),
("Sink format changed"));
}
+#ifdef __TIZEN__
+ } else if (!strcmp (name, PA_STREAM_EVENT_POP_TIMEOUT)) {
+ GST_WARNING_OBJECT (psink, "got event [%s], cork stream now!!!!", name);
+ gst_pulsering_set_corked (pbuf, TRUE, FALSE);
+#endif
} else {
GST_DEBUG_OBJECT (psink, "got unknown event %s", name);
}
const pa_buffer_attr *actual;
pa_channel_map channel_map;
pa_operation *o = NULL;
+#ifndef __TIZEN__
pa_cvolume v;
+#endif
pa_cvolume *pv = NULL;
pa_stream_flags_t flags;
const gchar *name;
else
name = "Playback Stream";
+#if defined(__TIZEN__) && defined(PCM_DUMP_ENABLE)
+ if (psink->need_dump_input == TRUE && psink->dump_fd_input == NULL) {
+ char *suffix , *dump_path;
+ GDateTime *time = g_date_time_new_now_local();
+
+ suffix = g_date_time_format(time, "%m%d_%H%M%S");
+ dump_path = g_strdup_printf("%s%dch_%dhz_%s.pcm", GST_PULSESINK_DUMP_INPUT_PATH_PREFIX, pbuf->channels, spec->info.rate, suffix);
+ GST_WARNING_OBJECT(psink, "pulse-sink dumping enabled: dump path [%s]", dump_path);
+ psink->dump_fd_input = fopen(dump_path, "w+");
+
+ g_free(suffix);
+ g_free(dump_path);
+ g_date_time_unref(time);
+ }
+#endif /* __TIZEN__ && PCM_DUMP_ENABLE */
+
/* create a stream */
formats[0] = pbuf->format;
if (!(pbuf->stream = pa_stream_new_extended (pbuf->context, name, formats, 1,
GST_INFO_OBJECT (psink, "prebuf: %d", wanted.prebuf);
GST_INFO_OBJECT (psink, "minreq: %d", wanted.minreq);
+#ifndef __TIZEN__
/* configure volume when we changed it, else we leave the default */
if (psink->volume_set) {
GST_LOG_OBJECT (psink, "have volume of %f", psink->volume);
} else {
pv = NULL;
}
+#endif
/* construct the flags */
flags = PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE |
PA_STREAM_ADJUST_LATENCY | PA_STREAM_START_CORKED;
+#ifndef __TIZEN__
if (psink->mute_set) {
if (psink->mute)
flags |= PA_STREAM_START_MUTED;
else
flags |= PA_STREAM_START_UNMUTED;
}
+#endif
/* we always start corked (see flags above) */
pbuf->corked = TRUE;
GST_INFO_OBJECT (psink, "negotiated to: %s", print_buf);
#endif
+#ifdef __TIZEN__
+ {
+ uint32_t idx;
+ if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX)
+ goto no_index;
+ if (psink->volume_set)
+ gst_pulse_set_volume_ratio (idx, "out", psink->volume);
+ if (psink->mute_set)
+ if (psink->mute)
+ gst_pulse_set_volume_ratio (idx, "out", 0);
+ }
+#endif
/* After we passed the volume off of to PA we never want to set it
again, since it is PA's job to save/restore volumes. */
psink->volume_set = psink->mute_set = FALSE;
pa_strerror (pa_context_errno (pbuf->context))), (NULL));
goto unlock_and_fail;
}
+#ifdef __TIZEN__
+no_index:
+ {
+ GST_ELEMENT_ERROR (psink, RESOURCE, FAILED,
+ ("Failed to get stream index: %s",
+ pa_strerror (pa_context_errno (pbuf->context))), (NULL));
+ goto unlock_and_fail;
+ }
+#endif
}
/* free the stream that we acquired before */
pa_threaded_mainloop_unlock (mainloop);
}
-/* called from pulse with the mainloop lock */
+#if 0
+/* called from pulse thread with the mainloop lock */
static void
mainloop_enter_defer_cb (pa_mainloop_api * api, void *userdata)
{
pulsesink->defer_pending--;
pa_threaded_mainloop_signal (mainloop, 0);
}
+#endif
/* start/resume playback ASAP, we don't uncork here but in the commit method */
static gboolean
pa_threaded_mainloop_lock (mainloop);
- GST_DEBUG_OBJECT (psink, "scheduling stream status");
- psink->defer_pending++;
- pa_mainloop_api_once (pa_threaded_mainloop_get_api (mainloop),
- mainloop_enter_defer_cb, psink);
-
GST_DEBUG_OBJECT (psink, "starting");
pbuf->paused = FALSE;
g_atomic_int_get (&GST_AUDIO_BASE_SINK (psink)->eos_rendering))
gst_pulsering_set_corked (pbuf, FALSE, FALSE);
+#if 0
+ GST_DEBUG_OBJECT (psink, "scheduling stream status");
+ psink->defer_pending++;
+ pa_mainloop_api_once (pa_threaded_mainloop_get_api (mainloop),
+ mainloop_enter_defer_cb, psink);
+
+ /* Wait for the stream status message to be posted. This needs to be done
+ * synchronously because the callback will take the mainloop lock
+ * (implicitly) and then take the GST_OBJECT_LOCK. Everywhere else, we take
+ * the locks in the reverse order, so not doing this synchronously could
+ * cause a deadlock. */
+ GST_DEBUG_OBJECT (psink, "waiting for stream status (ENTER) to be posted");
+ pa_threaded_mainloop_wait (mainloop);
+#endif
+
pa_threaded_mainloop_unlock (mainloop);
return TRUE;
return res;
}
-/* called from pulse with the mainloop lock */
+#if 0
+/* called from pulse thread with the mainloop lock */
static void
mainloop_leave_defer_cb (pa_mainloop_api * api, void *userdata)
{
pulsesink->defer_pending--;
pa_threaded_mainloop_signal (mainloop, 0);
}
+#endif
/* stop playback, we flush everything. */
static gboolean
pa_operation_cancel (o);
pa_operation_unref (o);
}
-
+#if 0
GST_DEBUG_OBJECT (psink, "scheduling stream status");
psink->defer_pending++;
pa_mainloop_api_once (pa_threaded_mainloop_get_api (mainloop),
mainloop_leave_defer_cb, psink);
+ /* Wait for the stream status message to be posted. This needs to be done
+ * synchronously because the callback will take the mainloop lock
+ * (implicitly) and then take the GST_OBJECT_LOCK. Everywhere else, we take
+ * the locks in the reverse order, so not doing this synchronously could
+ * cause a deadlock. */
+ GST_DEBUG_OBJECT (psink, "waiting for stream status (LEAVE) to be posted");
+ pa_threaded_mainloop_wait (mainloop);
+#endif
+
pa_threaded_mainloop_unlock (mainloop);
return res;
if (g_atomic_int_compare_and_exchange (&psink->notify, 1, 0)) {
g_object_notify (G_OBJECT (psink), "volume");
g_object_notify (G_OBJECT (psink), "mute");
+ g_object_notify (G_OBJECT (psink), "current-device");
}
/* make sure the ringbuffer is started */
if (pbuf->paused)
goto was_paused;
+#ifdef __TIZEN__
+ /* ensure running clock for whatever out there */
+ if (pbuf->corked) {
+ if (!gst_pulsering_set_corked (pbuf, FALSE, FALSE))
+ goto uncork_failed;
+ }
+#endif
/* offset is in bytes */
offset = *sample * bpf;
static GstStateChangeReturn gst_pulsesink_change_state (GstElement * element,
GstStateChange transition);
-static GstStaticPadTemplate pad_template = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (PULSE_SINK_TEMPLATE_CAPS));
-
#define gst_pulsesink_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstPulseSink, gst_pulsesink, GST_TYPE_AUDIO_BASE_SINK,
gst_pulsesink_init_contexts ();
case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_EAC3:
case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_DTS:
case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_MPEG:
+ case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_MPEG2_AAC:
+ case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_MPEG4_AAC:
{
/* FIXME: alloc memory from PA if possible */
gint framesize = gst_audio_iec61937_frame_size (&sink->ringbuffer->spec);
}
}
+#if defined(__TIZEN__) && defined(PCM_DUMP_ENABLE)
+static GstPadProbeReturn
+gst_pulsesink_pad_dump_probe (GstPad * pad, GstPadProbeInfo * info, gpointer data)
+{
+ GstPulseSink *psink = GST_PULSESINK_CAST (data);
+ size_t written = 0;
+ GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
+ GstMapInfo in_map;
+ if (psink->dump_fd_input) {
+ gst_buffer_map(buffer, &in_map, GST_MAP_READ);
+ written = fwrite(in_map.data, 1, in_map.size, psink->dump_fd_input);
+ if (written != in_map.size)
+ GST_WARNING("failed to write!!! ferror=%d", ferror(psink->dump_fd_input));
+ gst_buffer_unmap(buffer, &in_map);
+ }
+ return GST_PAD_PROBE_OK;
+}
+#endif /* __TIZEN__ && PCM_DUMP_ENABLE */
+
static void
gst_pulsesink_class_init (GstPulseSinkClass * klass)
{
GstBaseSinkClass *bc;
GstAudioBaseSinkClass *gstaudiosink_class = GST_AUDIO_BASE_SINK_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
+ GstCaps *caps;
gchar *clientname;
gobject_class->finalize = gst_pulsesink_finalize;
"The PulseAudio sink device to connect to", DEFAULT_DEVICE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_CURRENT_DEVICE,
+ g_param_spec_string ("current-device", "Current Device",
+ "The current PulseAudio sink device", DEFAULT_CURRENT_DEVICE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (gobject_class,
PROP_DEVICE_NAME,
g_param_spec_string ("device-name", "Device name",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstPulseSink:client-name
+ * GstPulseSink:client-name:
*
* The PulseAudio client name to use.
*/
g_free (clientname);
/**
- * GstPulseSink:stream-properties
+ * GstPulseSink:stream-properties:
*
* List of pulseaudio stream properties. A list of defined properties can be
* found in the <ulink url="http://0pointer.de/lennart/projects/pulseaudio/doxygen/proplist_8h.html">pulseaudio api docs</ulink>.
* g_object_set (pulse, "stream-properties", props, NULL);
* gst_structure_free
* ]|
- *
- * Since: 0.10.26
*/
g_object_class_install_property (gobject_class,
PROP_STREAM_PROPERTIES,
"list of pulseaudio stream properties",
GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+#ifdef __TIZEN__
+ g_object_class_install_property (gobject_class,
+ PROP_AUDIO_LATENCY,
+ g_param_spec_string ("latency", "Audio Backend Latency",
+ "Audio Backend Latency (\"low\": Low Latency, \"mid\": Mid Latency, \"high\": High Latency)",
+ DEFAULT_AUDIO_LATENCY,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class,
+ PROP_AUTO_RENDER_DELAY,
+ g_param_spec_boolean ("auto-render-delay", "Auto Render Delay",
+ "Apply render delay automatically", DEFAULT_AUTO_RENDER_DELAY,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+#endif /* __TIZEN__ */
+
gst_element_class_set_static_metadata (gstelement_class,
"PulseAudio Audio Sink",
"Sink/Audio", "Plays audio to a PulseAudio server", "Lennart Poettering");
+
+ caps =
+ gst_pulse_fix_pcm_caps (gst_caps_from_string (PULSE_SINK_TEMPLATE_CAPS));
gst_element_class_add_pad_template (gstelement_class,
- gst_static_pad_template_get (&pad_template));
+ gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps));
+ gst_caps_unref (caps);
}
static void
pa_threaded_mainloop_signal (mainloop, 0);
}
-#ifdef HAVE_PULSE_2_0
-static gboolean
-gst_pulse_format_info_int_prop_to_value (pa_format_info * format,
- const char *key, GValue * value)
-{
- GValue v = { 0, };
- int i;
- int *a, n;
- int min, max;
-
- if (pa_format_info_get_prop_int (format, key, &i) == 0) {
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, i);
-
- } else if (pa_format_info_get_prop_int_array (format, key, &a, &n) == 0) {
- g_value_init (value, GST_TYPE_LIST);
- g_value_init (&v, G_TYPE_INT);
-
- for (i = 0; i < n; i++) {
- g_value_set_int (&v, a[i]);
- gst_value_list_append_value (value, &v);
- }
-
- pa_xfree (a);
-
- } else if (pa_format_info_get_prop_int_range (format, key, &min, &max) == 0) {
- g_value_init (value, GST_TYPE_INT_RANGE);
- gst_value_set_int_range (value, min, max);
-
- } else {
- /* Property not available or is not an int type */
- return FALSE;
- }
-
- return TRUE;
-}
-
-static GstCaps *
-gst_pulse_format_info_to_caps (pa_format_info * format)
-{
- GstCaps *ret = NULL;
- GValue v = { 0, };
- pa_sample_spec ss;
-
- switch (format->encoding) {
- case PA_ENCODING_PCM:{
- char *tmp = NULL;
-
- pa_format_info_to_sample_spec (format, &ss, NULL);
-
- if (pa_format_info_get_prop_string (format,
- PA_PROP_FORMAT_SAMPLE_FORMAT, &tmp)) {
- /* No specific sample format means any sample format */
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_PCM);
- goto out;
-
- } else if (ss.format == PA_SAMPLE_ALAW) {
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_ALAW);
-
- } else if (ss.format == PA_SAMPLE_ULAW) {
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_MP3);
-
- } else {
- /* Linear PCM format */
- const char *sformat =
- gst_pulse_sample_format_to_caps_format (ss.format);
-
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_LINEAR);
-
- if (sformat)
- gst_caps_set_simple (ret, "format", G_TYPE_STRING, NULL);
- }
-
- pa_xfree (tmp);
- break;
- }
-
- case PA_ENCODING_AC3_IEC61937:
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_AC3);
- break;
-
- case PA_ENCODING_EAC3_IEC61937:
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_EAC3);
- break;
-
- case PA_ENCODING_DTS_IEC61937:
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_DTS);
- break;
-
- case PA_ENCODING_MPEG_IEC61937:
- ret = gst_caps_from_string (_PULSE_SINK_CAPS_MP3);
- break;
-
- default:
- GST_WARNING ("Found a PA format that we don't support yet");
- goto out;
- }
-
- if (gst_pulse_format_info_int_prop_to_value (format, PA_PROP_FORMAT_RATE, &v))
- gst_caps_set_value (ret, "rate", &v);
-
- g_value_unset (&v);
-
- if (gst_pulse_format_info_int_prop_to_value (format, PA_PROP_FORMAT_CHANNELS,
- &v))
- gst_caps_set_value (ret, "channels", &v);
-
-out:
- return ret;
-}
-#endif
-
/* Call with mainloop lock held */
static pa_stream *
gst_pulsesink_create_probe_stream (GstPulseSink * psink,
return NULL;
}
-#ifdef HAVE_PULSE_2_0
static GstCaps *
gst_pulsesink_query_getcaps (GstPulseSink * psink, GstCaps * filter)
{
goto unlock;
}
+ ret = gst_caps_new_empty ();
+
if (pbuf->stream) {
/* We're in PAUSED or higher */
stream = pbuf->stream;
pbuf->probe_stream = gst_pulsesink_create_probe_stream (psink, pbuf,
format);
+
+ pa_format_info_free (format);
+
if (!pbuf->probe_stream) {
GST_WARNING_OBJECT (psink, "Could not create probe stream");
goto unlock;
}
- pa_format_info_free (format);
-
stream = pbuf->probe_stream;
}
- ret = gst_caps_new_empty ();
-
if (!(o = pa_context_get_sink_info_by_name (pbuf->context,
pa_stream_get_device_name (stream), gst_pulsesink_sink_info_cb,
&device_info)))
}
for (i = g_list_first (device_info.formats); i; i = g_list_next (i)) {
- gst_caps_append (ret,
- gst_pulse_format_info_to_caps ((pa_format_info *) i->data));
+ GstCaps *caps = gst_pulse_format_info_to_caps ((pa_format_info *) i->data);
+ if (caps)
+ gst_caps_append (ret, caps);
}
+unlock:
+ pa_threaded_mainloop_unlock (mainloop);
+ /* FIXME: this could be freed after device_name is got */
+ GST_OBJECT_UNLOCK (pbuf);
+
if (filter) {
GstCaps *tmp = gst_caps_intersect_full (filter, ret,
GST_CAPS_INTERSECT_FIRST);
ret = tmp;
}
-unlock:
- pa_threaded_mainloop_unlock (mainloop);
- /* FIXME: this could be freed after device_name is got */
- GST_OBJECT_UNLOCK (pbuf);
-
out:
free_device_info (&device_info);
goto unlock;
}
}
-#endif
static gboolean
gst_pulsesink_query_acceptcaps (GstPulseSink * psink, GstCaps * caps)
if (format)
pa_format_info_free (format);
+ free_device_info (&device_info);
+
if (o)
pa_operation_unref (o);
static void
gst_pulsesink_init (GstPulseSink * pulsesink)
{
+#if defined(__TIZEN__) && defined(PCM_DUMP_ENABLE)
+ GstPad *sinkpad = NULL;
+ int vconf_dump = 0;
+#endif /* __TIZEN__ && PCM_DUMP_ENABLE */
+
pulsesink->server = NULL;
pulsesink->device = NULL;
pulsesink->device_info.description = NULL;
pulsesink->properties = NULL;
pulsesink->proplist = NULL;
+#ifdef __TIZEN__
+ pulsesink->latency = g_strdup (DEFAULT_AUDIO_LATENCY);
+ pulsesink->auto_render_delay = DEFAULT_AUTO_RENDER_DELAY;
+ pulsesink->proplist = pa_proplist_new();
+ pa_proplist_sets(pulsesink->proplist, PA_PROP_MEDIA_TIZEN_AUDIO_LATENCY, pulsesink->latency);
+#ifdef PCM_DUMP_ENABLE
+ if (vconf_get_int(GST_PULSESINK_DUMP_VCONF_KEY, &vconf_dump)) {
+ GST_WARNING("vconf_get_int %s failed", GST_PULSESINK_DUMP_VCONF_KEY);
+ }
+ pulsesink->need_dump_input = vconf_dump & GST_PULSESINK_DUMP_INPUT_FLAG ? TRUE : FALSE;
+ pulsesink->dump_fd_input = NULL;
+ if (pulsesink->need_dump_input) {
+ sinkpad = gst_element_get_static_pad((GstElement *)pulsesink, "sink");
+ if (sinkpad) {
+ gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BUFFER, gst_pulsesink_pad_dump_probe, pulsesink, NULL);
+ gst_object_unref (GST_OBJECT(sinkpad));
+ }
+ }
+#endif
+#endif /* __TIZEN__ */
/* override with a custom clock */
if (GST_AUDIO_BASE_SINK (pulsesink)->provided_clock)
GST_AUDIO_BASE_SINK (pulsesink)->provided_clock =
gst_audio_clock_new ("GstPulseSinkClock",
(GstAudioClockGetTimeFunc) gst_pulsesink_get_time, pulsesink, NULL);
-
- /* TRUE for sinks, FALSE for sources */
- pulsesink->probe = gst_pulseprobe_new (G_OBJECT (pulsesink),
- G_OBJECT_GET_CLASS (pulsesink), PROP_DEVICE, pulsesink->device,
- TRUE, FALSE);
}
static void
g_free (pulsesink->server);
g_free (pulsesink->device);
g_free (pulsesink->client_name);
+ g_free (pulsesink->current_sink_name);
free_device_info (&pulsesink->device_info);
if (pulsesink->proplist)
pa_proplist_free (pulsesink->proplist);
- if (pulsesink->probe) {
- gst_pulseprobe_free (pulsesink->probe);
- pulsesink->probe = NULL;
- }
+#ifdef __TIZEN__
+ g_free (pulsesink->latency);
+#endif /* __TIZEN__ */
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_pulsesink_set_volume (GstPulseSink * psink, gdouble volume)
{
+#ifndef __TIZEN__
pa_cvolume v;
pa_operation *o = NULL;
+#endif
GstPulseRingBuffer *pbuf;
uint32_t idx;
+#ifndef __TIZEN__
if (!mainloop)
goto no_mainloop;
pa_threaded_mainloop_lock (mainloop);
+#endif
GST_DEBUG_OBJECT (psink, "setting volume to %f", volume);
if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX)
goto no_index;
+#ifndef __TIZEN__
if (pbuf->is_pcm)
gst_pulse_cvolume_from_linear (&v, pbuf->channels, volume);
else
&v, NULL, NULL)))
goto volume_failed;
+#else
+ if (!psink->mute)
+ gst_pulse_set_volume_ratio (idx, "out", volume);
+ psink->volume = volume;
+#endif
+
/* We don't really care about the result of this call */
unlock:
+#ifndef __TIZEN__
if (o)
pa_operation_unref (o);
pa_threaded_mainloop_unlock (mainloop);
+#endif
return;
/* ERRORS */
+#ifndef __TIZEN__
no_mainloop:
{
psink->volume = volume;
GST_DEBUG_OBJECT (psink, "we have no mainloop");
return;
}
+#endif
no_buffer:
{
psink->volume = volume;
GST_DEBUG_OBJECT (psink, "we don't have a stream index");
goto unlock;
}
+#ifndef __TIZEN__
volume_failed:
{
GST_ELEMENT_ERROR (psink, RESOURCE, FAILED,
pa_strerror (pa_context_errno (pbuf->context))), (NULL));
goto unlock;
}
+#endif
}
static void
gst_pulsesink_set_mute (GstPulseSink * psink, gboolean mute)
{
+#ifndef __TIZEN__
pa_operation *o = NULL;
+#endif
GstPulseRingBuffer *pbuf;
uint32_t idx;
+#ifndef __TIZEN__
if (!mainloop)
goto no_mainloop;
pa_threaded_mainloop_lock (mainloop);
+#endif
GST_DEBUG_OBJECT (psink, "setting mute state to %d", mute);
if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX)
goto no_index;
+#ifndef __TIZEN__
if (!(o = pa_context_set_sink_input_mute (pbuf->context, idx,
mute, NULL, NULL)))
goto mute_failed;
+#else
+ gst_pulse_set_volume_ratio (idx, "out", mute ? 0 : psink->volume);
+ psink->mute = mute;
+#endif
/* We don't really care about the result of this call */
unlock:
+#ifndef __TIZEN__
if (o)
pa_operation_unref (o);
pa_threaded_mainloop_unlock (mainloop);
+#endif
return;
/* ERRORS */
+#ifndef __TIZEN__
no_mainloop:
{
psink->mute = mute;
GST_DEBUG_OBJECT (psink, "we have no mainloop");
return;
}
+#endif
no_buffer:
{
psink->mute = mute;
GST_DEBUG_OBJECT (psink, "we don't have a stream index");
goto unlock;
}
+#ifndef __TIZEN__
mute_failed:
{
GST_ELEMENT_ERROR (psink, RESOURCE, FAILED,
pa_strerror (pa_context_errno (pbuf->context))), (NULL));
goto unlock;
}
+#endif
}
static void
if (i->index == pa_stream_get_index (pbuf->stream)) {
psink->volume = pa_sw_volume_to_linear (pa_cvolume_max (&i->volume));
psink->mute = i->mute;
+ psink->current_sink_idx = i->sink;
+
+ if (psink->volume > MAX_VOLUME) {
+ GST_WARNING_OBJECT (psink, "Clipped volume from %f to %f", psink->volume,
+ MAX_VOLUME);
+ psink->volume = MAX_VOLUME;
+ }
}
done:
pa_threaded_mainloop_signal (mainloop, 0);
}
-static gdouble
-gst_pulsesink_get_volume (GstPulseSink * psink)
+static void
+gst_pulsesink_get_sink_input_info (GstPulseSink * psink, gdouble * volume,
+ gboolean * mute)
{
GstPulseRingBuffer *pbuf;
pa_operation *o = NULL;
- gdouble v = DEFAULT_VOLUME;
uint32_t idx;
if (!mainloop)
}
unlock:
- v = psink->volume;
+ if (volume)
+ *volume = psink->volume;
+ if (mute)
+ *mute = psink->mute;
if (o)
pa_operation_unref (o);
pa_threaded_mainloop_unlock (mainloop);
- if (v > MAX_VOLUME) {
- GST_WARNING_OBJECT (psink, "Clipped volume from %f to %f", v, MAX_VOLUME);
- v = MAX_VOLUME;
- }
-
- return v;
+ return;
/* ERRORS */
no_mainloop:
{
- v = psink->volume;
+ if (volume)
+ *volume = psink->volume;
+ if (mute)
+ *mute = psink->mute;
+
GST_DEBUG_OBJECT (psink, "we have no mainloop");
- return v;
+ return;
}
no_buffer:
{
}
}
-static gboolean
-gst_pulsesink_get_mute (GstPulseSink * psink)
+static void
+gst_pulsesink_current_sink_info_cb (pa_context * c, const pa_sink_info * i,
+ int eol, void *userdata)
+{
+ GstPulseSink *psink;
+
+ psink = GST_PULSESINK_CAST (userdata);
+
+ if (!i)
+ goto done;
+
+ /* If the index doesn't match our current stream,
+ * it implies we just recreated the stream (caps change)
+ */
+ if (i->index == psink->current_sink_idx) {
+ g_free (psink->current_sink_name);
+ psink->current_sink_name = g_strdup (i->name);
+ }
+
+done:
+ pa_threaded_mainloop_signal (mainloop, 0);
+}
+
+static gchar *
+gst_pulsesink_get_current_device (GstPulseSink * pulsesink)
{
- GstPulseRingBuffer *pbuf;
pa_operation *o = NULL;
- uint32_t idx;
- gboolean mute = FALSE;
+ GstPulseRingBuffer *pbuf;
+ gchar *current_sink;
if (!mainloop)
goto no_mainloop;
- pa_threaded_mainloop_lock (mainloop);
- mute = psink->mute;
-
- pbuf = GST_PULSERING_BUFFER_CAST (GST_AUDIO_BASE_SINK (psink)->ringbuffer);
+ pbuf =
+ GST_PULSERING_BUFFER_CAST (GST_AUDIO_BASE_SINK (pulsesink)->ringbuffer);
if (pbuf == NULL || pbuf->stream == NULL)
goto no_buffer;
- if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX)
- goto no_index;
+ gst_pulsesink_get_sink_input_info (pulsesink, NULL, NULL);
- if (!(o = pa_context_get_sink_input_info (pbuf->context, idx,
- gst_pulsesink_sink_input_info_cb, pbuf)))
+ pa_threaded_mainloop_lock (mainloop);
+
+ if (!(o = pa_context_get_sink_info_by_index (pbuf->context,
+ pulsesink->current_sink_idx, gst_pulsesink_current_sink_info_cb,
+ pulsesink)))
goto info_failed;
while (pa_operation_get_state (o) == PA_OPERATION_RUNNING) {
pa_threaded_mainloop_wait (mainloop);
- if (gst_pulsering_is_dead (psink, pbuf, TRUE))
+ if (gst_pulsering_is_dead (pulsesink, pbuf, TRUE))
goto unlock;
}
unlock:
+
+ current_sink = g_strdup (pulsesink->current_sink_name);
+
if (o)
pa_operation_unref (o);
pa_threaded_mainloop_unlock (mainloop);
- return mute;
+ return current_sink;
/* ERRORS */
no_mainloop:
{
- mute = psink->mute;
- GST_DEBUG_OBJECT (psink, "we have no mainloop");
- return mute;
+ GST_DEBUG_OBJECT (pulsesink, "we have no mainloop");
+ return NULL;
}
no_buffer:
{
- GST_DEBUG_OBJECT (psink, "we have no ringbuffer");
- goto unlock;
- }
-no_index:
- {
- GST_DEBUG_OBJECT (psink, "we don't have a stream index");
- goto unlock;
+ GST_DEBUG_OBJECT (pulsesink, "we have no ringbuffer");
+ return NULL;
}
info_failed:
{
- GST_ELEMENT_ERROR (psink, RESOURCE, FAILED,
+ GST_ELEMENT_ERROR (pulsesink, RESOURCE, FAILED,
("pa_context_get_sink_input_info() failed: %s",
pa_strerror (pa_context_errno (pbuf->context))), (NULL));
goto unlock;
}
static void
+gst_pulsesink_set_stream_device (GstPulseSink * psink, const gchar * device)
+{
+ pa_operation *o = NULL;
+ GstPulseRingBuffer *pbuf;
+ uint32_t idx;
+
+ if (!mainloop)
+ goto no_mainloop;
+
+ pa_threaded_mainloop_lock (mainloop);
+
+ pbuf = GST_PULSERING_BUFFER_CAST (GST_AUDIO_BASE_SINK (psink)->ringbuffer);
+ if (pbuf == NULL || pbuf->stream == NULL)
+ goto no_buffer;
+
+ if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX)
+ goto no_index;
+
+
+ GST_DEBUG_OBJECT (psink, "setting stream device to %s", device);
+
+ if (!(o = pa_context_move_sink_input_by_name (pbuf->context, idx, device,
+ NULL, NULL)))
+ goto move_failed;
+
+unlock:
+
+ if (o)
+ pa_operation_unref (o);
+
+ pa_threaded_mainloop_unlock (mainloop);
+
+ return;
+
+ /* ERRORS */
+no_mainloop:
+ {
+ GST_DEBUG_OBJECT (psink, "we have no mainloop");
+ return;
+ }
+no_buffer:
+ {
+ GST_DEBUG_OBJECT (psink, "we have no ringbuffer");
+ goto unlock;
+ }
+no_index:
+ {
+ GST_DEBUG_OBJECT (psink, "we don't have a stream index");
+ return;
+ }
+move_failed:
+ {
+ GST_ELEMENT_ERROR (psink, RESOURCE, FAILED,
+ ("pa_context_move_sink_input_by_name(%s) failed: %s", device,
+ pa_strerror (pa_context_errno (pbuf->context))), (NULL));
+ goto unlock;
+ }
+}
+
+
+static void
gst_pulsesink_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec)
{
case PROP_SERVER:
g_free (pulsesink->server);
pulsesink->server = g_value_dup_string (value);
- if (pulsesink->probe)
- gst_pulseprobe_set_server (pulsesink->probe, pulsesink->server);
break;
case PROP_DEVICE:
g_free (pulsesink->device);
pulsesink->device = g_value_dup_string (value);
+ gst_pulsesink_set_stream_device (pulsesink, pulsesink->device);
break;
case PROP_VOLUME:
gst_pulsesink_set_volume (pulsesink, g_value_get_double (value));
pa_proplist_free (pulsesink->proplist);
pulsesink->proplist = gst_pulse_make_proplist (pulsesink->properties);
break;
+#ifdef __TIZEN__
+ case PROP_AUDIO_LATENCY:
+ g_free (pulsesink->latency);
+ pulsesink->latency = g_value_dup_string (value);
+ /* setting NULL restores the default latency */
+ if (pulsesink->latency == NULL) {
+ pulsesink->latency = g_strdup (DEFAULT_AUDIO_LATENCY);
+ }
+ if (!pulsesink->proplist) {
+ pulsesink->proplist = pa_proplist_new();
+ }
+ pa_proplist_sets(pulsesink->proplist, PA_PROP_MEDIA_TIZEN_AUDIO_LATENCY, pulsesink->latency);
+ GST_DEBUG_OBJECT(pulsesink, "latency(%s)", pulsesink->latency);
+ break;
+ case PROP_AUTO_RENDER_DELAY:
+ pulsesink->auto_render_delay = g_value_get_boolean (value);
+ GST_DEBUG_OBJECT (pulsesink, "setting auto-render-delay to %d", g_value_get_boolean (value));
+ break;
+#endif /* __TIZEN__ */
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_DEVICE:
g_value_set_string (value, pulsesink->device);
break;
+ case PROP_CURRENT_DEVICE:
+ {
+ gchar *current_device = gst_pulsesink_get_current_device (pulsesink);
+ if (current_device)
+ g_value_take_string (value, current_device);
+ else
+ g_value_set_string (value, "");
+ break;
+ }
case PROP_DEVICE_NAME:
g_value_take_string (value, gst_pulsesink_device_description (pulsesink));
break;
case PROP_VOLUME:
- g_value_set_double (value, gst_pulsesink_get_volume (pulsesink));
+ {
+#ifndef __TIZEN__
+ gdouble volume;
+
+ gst_pulsesink_get_sink_input_info (pulsesink, &volume, NULL);
+ g_value_set_double (value, volume);
+#else
+ g_value_set_double (value, pulsesink->volume);
+#endif
break;
+ }
case PROP_MUTE:
- g_value_set_boolean (value, gst_pulsesink_get_mute (pulsesink));
+ {
+#ifndef __TIZEN__
+ gboolean mute;
+
+ gst_pulsesink_get_sink_input_info (pulsesink, NULL, &mute);
+ g_value_set_boolean (value, mute);
+#else
+ g_value_set_boolean (value, pulsesink->mute);
+#endif
break;
+ }
case PROP_CLIENT_NAME:
g_value_set_string (value, pulsesink->client_name);
break;
case PROP_STREAM_PROPERTIES:
gst_value_set_structure (value, pulsesink->properties);
break;
+#ifdef __TIZEN__
+ case PROP_AUDIO_LATENCY:
+ g_value_set_string (value, pulsesink->latency);
+ break;
+ case PROP_AUTO_RENDER_DELAY:
+ g_value_set_boolean (value, pulsesink->auto_render_delay);
+ break;
+#endif /* __TIZEN__ */
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
gst_pulsesink_query (GstBaseSink * sink, GstQuery * query)
{
GstPulseSink *pulsesink = GST_PULSESINK_CAST (sink);
- gboolean ret;
+ gboolean ret = FALSE;
switch (GST_QUERY_TYPE (query)) {
-#ifdef HAVE_PULSE_2_0
case GST_QUERY_CAPS:
{
GstCaps *caps, *filter;
if (caps) {
gst_query_set_caps_result (query, caps);
gst_caps_unref (caps);
- return TRUE;
- } else {
- return FALSE;
+ ret = TRUE;
}
+ break;
}
-#endif
case GST_QUERY_ACCEPT_CAPS:
{
GstCaps *caps;