Changed to the new props API

Original commit message from CVS:
Changed to the new props API
Other small tuff.
This commit is contained in:
Wim Taymans 2002-03-30 17:06:26 +00:00
parent c5e4b06ff5
commit 13d9e8d352
17 changed files with 233 additions and 389 deletions

View file

@ -432,6 +432,14 @@ GST_CHECK_FEATURE(HTTP, [http plugins], gsthttpsrc, [
AC_SUBST(GST_HTTPSRC_GET_TYPE)
])
dnl *** Jack ***
translit(dnm, m, l) AM_CONDITIONAL(USE_LCS, true)
GST_CHECK_FEATURE(LCS, Lcs, lcs, [
PKG_CHECK_MODULES(LCS, lcs, HAVE_LCS="yes", HAVE_LCS="no")
AC_SUBST(LCS_CFLAGS)
AC_SUBST(LCS_LIBS)
])
dnl *** Jack ***
translit(dnm, m, l) AM_CONDITIONAL(USE_JACK, true)
GST_CHECK_FEATURE(JACK, Jack, jack, [
@ -796,6 +804,7 @@ ext/hermes/Makefile
ext/http/Makefile
ext/jack/Makefile
ext/jpeg/Makefile
ext/lcs/Makefile
ext/ladspa/Makefile
ext/lame/Makefile
ext/mad/Makefile

View file

@ -242,8 +242,8 @@ gst_aasink_sinkconnect (GstPad *pad, GstCaps *caps)
if (!GST_CAPS_IS_FIXED (caps))
return GST_PAD_CONNECT_DELAYED;
aasink->width = gst_caps_get_int (caps, "width");
aasink->height = gst_caps_get_int (caps, "height");
gst_caps_get_int (caps, "width", &aasink->width);
gst_caps_get_int (caps, "height", &aasink->height);
print_format = GULONG_FROM_LE (aasink->format);

View file

@ -317,8 +317,12 @@ gst_dvdec_loop (GstElement *element)
/* try each format */
if (gst_pad_try_set_caps (dvdec->videosrcpad, to_try)) {
guint32 fourcc;
/* it worked, try to find what it was again */
if (gst_caps_get_fourcc_int (to_try, "format") == GST_STR_FOURCC ("RGB ")) {
gst_caps_get_fourcc_int (to_try, "format", &fourcc);
if (fourcc == GST_STR_FOURCC ("RGB ")) {
dvdec->space = e_dv_color_rgb;
dvdec->bpp = 3;
}

View file

@ -227,9 +227,9 @@ gst_esdsink_sinkconnect (GstPad *pad, GstCaps *caps)
if (!GST_CAPS_IS_FIXED (caps))
return GST_PAD_CONNECT_DELAYED;
esdsink->depth = gst_caps_get_int (caps, "depth");
esdsink->channels = gst_caps_get_int (caps, "channels");
esdsink->frequency = gst_caps_get_int (caps, "rate");
gst_caps_get_int (caps, "depth", &esdsink->depth);
gst_caps_get_int (caps, "channels", &esdsink->channels);
gst_caps_get_int (caps, "rate", &esdsink->frequency);
if (gst_esdsink_sync_parms (esdsink))
return GST_PAD_CONNECT_OK;

View file

@ -110,9 +110,9 @@ gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps)
if (!GST_CAPS_IS_FIXED (caps))
return GST_PAD_CONNECT_DELAYED;
flacenc->channels = gst_caps_get_int (caps, "channels");
flacenc->depth = gst_caps_get_int (caps, "depth");
flacenc->sample_rate = gst_caps_get_int (caps, "rate");
gst_caps_get_int (caps, "channels", &flacenc->channels);
gst_caps_get_int (caps, "depth", &flacenc->depth);
gst_caps_get_int (caps, "rate", &flacenc->sample_rate);
FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder, flacenc->depth);
FLAC__stream_encoder_set_sample_rate (flacenc->encoder, flacenc->sample_rate);

View file

@ -109,7 +109,7 @@ gst_ladspa_get_bufferpool (GstPad *pad)
{
gint i;
GstBufferPool *bp;
GstLADSPA *ladspa = gst_pad_get_parent (pad);
GstLADSPA *ladspa = (GstLADSPA *) gst_pad_get_parent (pad);
GstLADSPAClass *oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (ladspa));
if (oclass->numsrcpads > 0)
@ -394,7 +394,7 @@ gst_ladspa_init (GstLADSPA *ladspa)
}
ladspa->loopbased = TRUE;
gst_element_set_loop_function (ladspa, gst_ladspa_loop);
gst_element_set_loop_function (GST_ELEMENT (ladspa), gst_ladspa_loop);
}
gst_ladspa_instantiate(ladspa);
@ -406,13 +406,15 @@ gst_ladspa_connect (GstPad *pad, GstCaps *caps)
GstLADSPA *ladspa = (GstLADSPA *) GST_PAD_PARENT (pad);
GstLADSPAClass *oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (ladspa));
guint i;
gint rate;
g_return_val_if_fail (caps != NULL, GST_PAD_CONNECT_DELAYED);
g_return_val_if_fail (pad != NULL, GST_PAD_CONNECT_DELAYED);
gst_caps_get_int (caps, "rate", &rate);
/* have to instantiate ladspa plugin when samplerate changes (groan) */
if (ladspa->samplerate != gst_caps_get_int (caps, "rate")){
ladspa->samplerate = gst_caps_get_int (caps, "rate");
if (ladspa->samplerate != rate){
ladspa->samplerate = rate;
if (! gst_ladspa_instantiate(ladspa))
return GST_PAD_CONNECT_REFUSED;
}
@ -434,12 +436,15 @@ static GstPadConnectReturn
gst_ladspa_connect_get (GstPad *pad, GstCaps *caps)
{
GstLADSPA *ladspa = (GstLADSPA*)GST_OBJECT_PARENT (pad);
gint rate;
g_return_val_if_fail (caps != NULL, GST_PAD_CONNECT_DELAYED);
g_return_val_if_fail (pad != NULL, GST_PAD_CONNECT_DELAYED);
if (ladspa->samplerate != gst_caps_get_int (caps, "rate")) {
ladspa->samplerate = gst_caps_get_int (caps, "rate");
gst_caps_get_int (caps, "rate", &rate);
if (ladspa->samplerate != rate) {
ladspa->samplerate = rate;
if (! gst_ladspa_instantiate(ladspa))
return GST_PAD_CONNECT_REFUSED;
}
@ -674,7 +679,7 @@ gst_ladspa_deactivate(GstLADSPA *ladspa)
static void
gst_ladspa_loop (GstElement *element)
{
gint8 *raw_in, *zero_out, i, cur_buf;
gint8 *raw_in, *zero_out, i;
GstBuffer **buffers_out;
GstEvent *event = NULL;
guint32 waiting;
@ -703,7 +708,8 @@ gst_ladspa_loop (GstElement *element)
/* first get all the necessary data from the input ports */
for (i=0;i<oclass->numsinkpads;i++){
GST_DEBUG (0, "pulling %d bytes through channel %d's bytestream", i);
GST_DEBUG (0, "pulling %d bytes through channel %d'sbytestream\n",
ladspa->buffersize * sizeof (LADSPA_Data), i);
raw_in = gst_bytestream_peek_bytes (ladspa->bytestreams[i], ladspa->buffersize * sizeof (LADSPA_Data));
if (raw_in == NULL) {

View file

@ -47,7 +47,7 @@ enum {
ARG_REVERB,
ARG_SNDFXVOLUME,
ARG_VOLUME,
ARG_FIXFREQ,
ARG_MIXFREQ,
ARG_INTERP,
ARG_REVERSE,
ARG_SURROUND,
@ -226,10 +226,10 @@ gst_mikmod_class_init (GstMikModClass *klass)
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SONGNAME,
g_param_spec_string("songname","songname","songname",
"", G_PARAM_READABLE));
NULL, G_PARAM_READABLE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MODTYPE,
g_param_spec_string("modtype", "modtype", "modtype",
"", G_PARAM_READABLE ));
NULL, G_PARAM_READABLE ));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MUSICVOLUME,
g_param_spec_int("musicvolume", "musivolume", "musicvolume",
0, 128, 128, G_PARAM_READWRITE ));
@ -245,7 +245,7 @@ gst_mikmod_class_init (GstMikModClass *klass)
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VOLUME,
g_param_spec_int("volume", "volume", "volume",
0, 128, 96, G_PARAM_READWRITE ));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FIXFREQ,
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MIXFREQ,
g_param_spec_enum("mixfreq", "mixfreq", "mixfreq",
GST_TYPE_MIKMOD_MIXFREQ, 3,G_PARAM_READWRITE ));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_INTERP,
@ -305,6 +305,8 @@ gst_mikmod_init (GstMikMod *filter)
filter->musicvolume = 128;
filter->volume = 96;
filter->sndfxvolume = 128;
filter->songname = NULL;
filter->modtype = NULL;
}
@ -314,7 +316,6 @@ gst_mikmod_loop (GstElement *element)
GstMikMod *mikmod;
GstBuffer *buffer_in;
gint mode16bits;
gint first = 0;
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_MIKMOD (element));
@ -487,10 +488,12 @@ gst_mikmod_set_property (GObject *object, guint id, const GValue *value, GParamS
switch (id) {
case ARG_SONGNAME:
filter->songname = g_value_get_string (value);
g_free (filter->songname);
filter->songname = g_strdup (g_value_get_string (value));
break;
case ARG_MODTYPE:
filter->modtype = g_value_get_string (value);
g_free (filter->modtype);
filter->modtype = g_strdup (g_value_get_string (value));
break;
case ARG_MUSICVOLUME:
filter->musicvolume = g_value_get_int (value);
@ -507,7 +510,7 @@ gst_mikmod_set_property (GObject *object, guint id, const GValue *value, GParamS
case ARG_VOLUME:
filter->volume = g_value_get_int (value);
break;
case ARG_FIXFREQ:
case ARG_MIXFREQ:
filter->mixfreq = g_value_get_enum (value);
break;
case ARG_INTERP:
@ -565,8 +568,8 @@ gst_mikmod_get_property (GObject *object, guint id, GValue *value, GParamSpec *p
case ARG_VOLUME:
g_value_set_int (value, filter->volume);
break;
case ARG_FIXFREQ:
g_value_set_int (value, filter->mixfreq);
case ARG_MIXFREQ:
g_value_set_enum (value, filter->mixfreq);
break;
case ARG_INTERP:
g_value_set_boolean (value, filter->interp);

View file

@ -583,12 +583,12 @@ gst_avidemux_parse_index (GstAviDemux *avi_demux,
if (GST_BUFFER_OFFSET (buf) != filepos + offset || GST_BUFFER_SIZE (buf) != 8) {
GST_INFO (GST_CAT_PLUGIN_INFO, "avidemux: could not get index");
return;
goto end;
}
if (gst_riff_fourcc_to_id (GST_BUFFER_DATA (buf)) != GST_RIFF_TAG_idx1) {
GST_INFO (GST_CAT_PLUGIN_INFO, "avidemux: no index found");
return;
goto end;
}
index_size = GUINT32_FROM_LE(*(guint32 *)(GST_BUFFER_DATA (buf) + 4));
@ -604,6 +604,7 @@ gst_avidemux_parse_index (GstAviDemux *avi_demux,
memcpy (avi_demux->index_entries, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
gst_buffer_unref (buf);
end:
if (!gst_bytestream_seek (avi_demux->bs, GST_SEEK_BYTEOFFSET_SET, filepos)) {
GST_INFO (GST_CAT_PLUGIN_INFO, "avidemux: could not seek back to movi");
return;

View file

@ -292,57 +292,68 @@ gst_avimux_sinkconnect (GstPad *pad, GstCaps *vscaps)
if (!strcmp (mimetype, "video/avi"))
{
const gchar* format = gst_caps_get_string(caps, "format");
const gchar* format;
gst_caps_get_string (caps, "format", &format);
if (!strncmp (format, "strf_vids", 9)) {
avimux->vids.size = sizeof(gst_riff_strf_vids);
avimux->vids.width = gst_caps_get_int (caps, "width");
avimux->vids.height = gst_caps_get_int (caps, "height");
avimux->vids.planes = gst_caps_get_int (caps, "planes");
avimux->vids.bit_cnt = gst_caps_get_int (caps, "bit_cnt");
avimux->vids.compression = gst_caps_get_fourcc_int (caps, "compression");
avimux->vids.image_size = gst_caps_get_int (caps, "image_size");
avimux->vids.xpels_meter = gst_caps_get_int (caps, "xpels_meter");
avimux->vids.ypels_meter = gst_caps_get_int (caps, "ypels_meter");
avimux->vids.num_colors = gst_caps_get_int (caps, "num_colors");
avimux->vids.imp_colors = gst_caps_get_int (caps, "imp_colors");
gst_caps_get (caps,
"width", GST_PROPS_INT_TYPE, &avimux->vids.width,
"height", GST_PROPS_INT_TYPE, &avimux->vids.height,
"planes", GST_PROPS_INT_TYPE, &avimux->vids.planes,
"bit_cnt", GST_PROPS_INT_TYPE, &avimux->vids.bit_cnt,
"compression", GST_PROPS_FOURCC_TYPE, &avimux->vids.compression,
"image_size", GST_PROPS_INT_TYPE, &avimux->vids.image_size,
"xpels_meter", GST_PROPS_INT_TYPE, &avimux->vids.xpels_meter,
"ypels_meter", GST_PROPS_INT_TYPE, &avimux->vids.ypels_meter,
"num_colors", GST_PROPS_INT_TYPE, &avimux->vids.num_colors,
"imp_colors", GST_PROPS_INT_TYPE, &avimux->vids.imp_colors,
NULL);
}
else if (!strncmp (format, "strf_auds", 9)) {
avimux->auds.format = gst_caps_get_int (caps, "format");
avimux->auds.channels = gst_caps_get_int (caps, "channels");
avimux->auds.rate = gst_caps_get_int (caps, "rate");
avimux->auds.av_bps = gst_caps_get_int (caps, "av_bps");
avimux->auds.blockalign = gst_caps_get_int (caps, "blockalign");
avimux->auds.size = gst_caps_get_int (caps, "size");
gst_caps_get (caps,
"format", GST_PROPS_INT_TYPE, &avimux->auds.format,
"channels", GST_PROPS_INT_TYPE, &avimux->auds.channels,
"rate", GST_PROPS_INT_TYPE, &avimux->auds.rate,
"av_bps", GST_PROPS_INT_TYPE, &avimux->auds.av_bps,
"blockalign", GST_PROPS_INT_TYPE, &avimux->auds.blockalign,
"size", GST_PROPS_INT_TYPE, &avimux->auds.size,
NULL);
}
goto done;
}
else if (!strcmp (mimetype, "video/raw"))
{
switch (gst_caps_get_fourcc_int(caps, "format"))
guint32 format;
gst_caps_get_fourcc_int (caps, "format", &format);
switch (format)
{
case GST_MAKE_FOURCC('Y','U','Y','2'):
case GST_MAKE_FOURCC('I','4','2','0'):
case GST_MAKE_FOURCC('Y','4','1','P'):
case GST_MAKE_FOURCC('R','G','B',' '):
avimux->vids.size = sizeof(gst_riff_strf_vids);
avimux->vids.width = gst_caps_get_int (caps, "width");
avimux->vids.height = gst_caps_get_int (caps, "height");
gst_caps_get (caps,
"width", GST_PROPS_INT_TYPE, &avimux->vids.width,
"height", GST_PROPS_INT_TYPE, &avimux->vids.height,
NULL);
avimux->vids.planes = 1;
switch (gst_caps_get_fourcc_int(caps, "format"))
switch (format)
{
case GST_MAKE_FOURCC('Y','U','Y','2'):
avimux->vids.bit_cnt = 16; /* YUY2 */
break;
case GST_MAKE_FOURCC('R','G','B',' '):
avimux->vids.bit_cnt = gst_caps_get_fourcc_int(caps, "bpp"); /* RGB */
gst_caps_get_int (caps, "bpp", &avimux->vids.bit_cnt); /* RGB */
break;
case GST_MAKE_FOURCC('Y','4','1','P'):
case GST_MAKE_FOURCC('I','4','2','0'):
avimux->vids.bit_cnt = 12; /* Y41P or I420 */
break;
}
avimux->vids.compression = gst_caps_get_fourcc_int(caps, "format");
gst_caps_get_fourcc_int(caps, "format", &avimux->vids.compression);
avimux->vids.image_size = avimux->vids.height * avimux->vids.width;
goto done;
default:
@ -352,8 +363,10 @@ gst_avimux_sinkconnect (GstPad *pad, GstCaps *vscaps)
else if (!strcmp (mimetype, "video/jpeg"))
{
avimux->vids.size = sizeof(gst_riff_strf_vids);
avimux->vids.width = gst_caps_get_int (caps, "width");
avimux->vids.height = gst_caps_get_int (caps, "height");
gst_caps_get (caps,
"width", GST_PROPS_INT_TYPE, &avimux->vids.width,
"height", GST_PROPS_INT_TYPE, &avimux->vids.height,
NULL);
avimux->vids.planes = 1;
avimux->vids.bit_cnt = 24;
avimux->vids.compression = GST_MAKE_FOURCC('M','J','P','G');
@ -362,20 +375,29 @@ gst_avimux_sinkconnect (GstPad *pad, GstCaps *vscaps)
}
else if (!strcmp (mimetype, "audio/raw"))
{
gint width;
avimux->auds.format = GST_RIFF_WAVE_FORMAT_PCM;
avimux->auds.channels = gst_caps_get_int (caps, "channels");
avimux->auds.rate = gst_caps_get_int (caps, "rate");
avimux->auds.av_bps = gst_caps_get_int (caps, "width") * avimux->auds.rate *
avimux->auds.channels / 8;
avimux->auds.blockalign = gst_caps_get_int (caps, "width") * avimux->auds.channels/8;
avimux->auds.size = gst_caps_get_int (caps, "depth");
gst_caps_get (caps,
"channels", GST_PROPS_INT_TYPE, &avimux->auds.channels,
"rate", GST_PROPS_INT_TYPE, &avimux->auds.rate,
"width", GST_PROPS_INT_TYPE, &width,
"depth", GST_PROPS_INT_TYPE, &avimux->auds.size,
NULL);
avimux->auds.av_bps = width * avimux->auds.rate * avimux->auds.channels / 8;
avimux->auds.blockalign = width * avimux->auds.channels/8;
goto done;
}
else if (!strcmp (mimetype, "audio/mp3"))
{
gint layer;
gst_caps_get_int(caps, "layer", &layer);
/* we don't need to do anything here, compressed mp3 contains it all */
avimux->auds.format = gst_caps_get_int(caps, "layer")==3?
GST_RIFF_WAVE_FORMAT_MPEGL3:GST_RIFF_WAVE_FORMAT_MPEGL12;
avimux->auds.format = (layer == 3?
GST_RIFF_WAVE_FORMAT_MPEGL3 :
GST_RIFF_WAVE_FORMAT_MPEGL12);
goto done;
}
}

View file

@ -235,13 +235,13 @@ gst_cutter_chain (GstPad *pad, GstBuffer *buf)
if (filter->silent)
{
/* g_print ("DEBUG: cutter: cut to here, turning off out\n"); */
gtk_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_STOP]);
g_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_STOP], 0);
}
else
{
/* g_print ("DEBUG: cutter: start from here, turning on out\n"); */
/* first of all, flush current buffer */
gtk_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_START]);
g_signal_emit (G_OBJECT (filter), gst_cutter_signals[CUT_START], 0);
g_print ("DEBUG: cutter: flushing buffer ");
while (filter->pre_buffer)
{
@ -389,7 +389,7 @@ gst_cutter_get_caps (GstPad *pad, GstCutter* filter)
/* FIXME : Please change this to a better warning method ! */
if (caps == NULL)
printf ("WARNING: cutter: get_caps: Could not get caps of pad !\n");
filter->width = gst_caps_get_int (caps, "width");
gst_caps_get_int (caps, "width", &filter->width);
filter->max_sample = gst_audio_highest_sample_value (pad);
filter->have_caps = TRUE;
}

View file

@ -114,7 +114,7 @@ GST_PADTEMPLATE_FACTORY (sink_template,
"width", GST_PROPS_INT (16),
"depth", GST_PROPS_INT (16),
"rate", GST_PROPS_INT_RANGE (8000, 96000),
"channels", GST_PROPS_INT (1)
"channels", GST_PROPS_INT (2)
)
)

View file

@ -173,7 +173,7 @@ gst_level_chain (GstPad *pad,GstBuffer *buf)
printf ("WARNING : chain : Could not get caps of pad !\n");
}
width = gst_caps_get_int(caps, "width");
gst_caps_get_int(caps, "width", &width);
in_data = (gint16 *)GST_BUFFER_DATA(buf);
outbuf=gst_buffer_new();

View file

@ -134,8 +134,8 @@ gst_median_sinkconnect (GstPad *pad, GstCaps *caps)
if (!GST_CAPS_IS_FIXED (caps))
return GST_PAD_CONNECT_DELAYED;
filter->width = gst_caps_get_int (caps, "width");
filter->height = gst_caps_get_int (caps, "height");
gst_caps_get_int (caps, "width", &filter->width);
gst_caps_get_int (caps, "height", &filter->height);
return GST_PAD_CONNECT_OK;
}

View file

@ -22,31 +22,10 @@
#include "gstossclock.h"
static GMemChunk *_gst_clock_entries_chunk;
static GMutex *_gst_clock_entries_chunk_lock;
static GList *_gst_clock_entries_pool;
typedef struct _GstClockEntry GstClockEntry;
typedef enum {
GST_ENTRY_OK,
GST_ENTRY_RESTART,
} GstEntryStatus;
struct _GstClockEntry {
GstClockTime time;
GstEntryStatus status;
GMutex *lock;
GCond *cond;
};
static void gst_oss_clock_class_init (GstOssClockClass *klass);
static void gst_oss_clock_init (GstOssClock *clock);
static void gst_oss_clock_reset (GstClock *clock);
static void gst_oss_clock_activate (GstClock *clock, gboolean activate);
static void gst_oss_clock_set_time (GstClock *clock, GstClockTime time);
static GstClockReturn gst_oss_clock_wait (GstClock *clock, GstClockTime time);
static GstClockTime gst_oss_clock_get_internal_time (GstClock *clock);
static GstSystemClockClass *parent_class = NULL;
/* static guint gst_oss_clock_signals[LAST_SIGNAL] = { 0 }; */
@ -89,241 +68,57 @@ gst_oss_clock_class_init (GstOssClockClass *klass)
parent_class = g_type_class_ref (GST_TYPE_SYSTEM_CLOCK);
gstclock_class->reset = gst_oss_clock_reset;
gstclock_class->activate = gst_oss_clock_activate;
gstclock_class->set_time = gst_oss_clock_set_time;
gstclock_class->wait = gst_oss_clock_wait;
gstclock_class->get_internal_time = gst_oss_clock_get_internal_time;
}
static void
gst_oss_clock_init (GstOssClock *clock)
{
gst_object_set_name (GST_OBJECT (clock), "GstOssClock");
clock->is_updated = FALSE;
}
#define GST_CLOCK_ENTRY(entry) ((GstClockEntry *)(entry))
#define GST_CLOCK_ENTRY_TIME(entry) (((GstClockEntry *)(entry))->time)
#define GST_CLOCK_ENTRY_LOCK(entry) (g_mutex_lock ((entry)->lock))
#define GST_CLOCK_ENTRY_UNLOCK(entry) (g_mutex_unlock ((entry)->lock))
#define GST_CLOCK_ENTRY_SIGNAL(entry) (g_cond_signal ((entry)->cond))
#define GST_CLOCK_ENTRY_WAIT(entry) (g_cond_wait (entry->cond, entry->lock))
#define GST_CLOCK_ENTRY_TIMED_WAIT(entry, time) (g_cond_timed_wait (entry->cond, entry->lock, (time)))
static GstClockEntry*
gst_clock_entry_new (GstClockTime time)
{
GstClockEntry *entry;
g_mutex_lock (_gst_clock_entries_chunk_lock);
if (_gst_clock_entries_pool) {
entry = GST_CLOCK_ENTRY (_gst_clock_entries_pool->data);
_gst_clock_entries_pool = g_list_remove (_gst_clock_entries_pool, entry);
g_mutex_unlock (_gst_clock_entries_chunk_lock);
}
else {
entry = g_mem_chunk_alloc (_gst_clock_entries_chunk);
g_mutex_unlock (_gst_clock_entries_chunk_lock);
entry->lock = g_mutex_new ();
entry->cond = g_cond_new ();
}
entry->time = time;
return entry;
}
static void
gst_clock_entry_free (GstClockEntry *entry)
{
g_mutex_lock (_gst_clock_entries_chunk_lock);
_gst_clock_entries_pool = g_list_prepend (_gst_clock_entries_pool, entry);
g_mutex_unlock (_gst_clock_entries_chunk_lock);
clock->prev1 = 0;
clock->prev2 = 0;
}
GstOssClock*
gst_oss_clock_new (gchar *name, GstElement *owner)
gst_oss_clock_new (gchar *name, GstOssClockGetTimeFunc func, gpointer user_data)
{
GstOssClock *oss_clock = GST_OSS_CLOCK (g_object_new (GST_TYPE_OSS_CLOCK, NULL));
oss_clock->entries = NULL;
oss_clock->current_time = 0;
oss_clock->next_time = 0;
_gst_clock_entries_chunk = g_mem_chunk_new ("GstClockEntries",
sizeof (GstClockEntry), sizeof (GstClockEntry) * 32,
G_ALLOC_AND_FREE);
_gst_clock_entries_chunk_lock = g_mutex_new ();
_gst_clock_entries_pool = NULL;
oss_clock->func = func;
oss_clock->user_data = user_data;
oss_clock->adjust = 0;
return oss_clock;
}
void
gst_oss_clock_set_update (GstOssClock *clock, gboolean update)
static GstClockTime
gst_oss_clock_get_internal_time (GstClock *clock)
{
GST_LOCK (clock);
if (!update) {
GST_UNLOCK (clock);
GST_CLOCK_CLASS (parent_class)->set_time (GST_CLOCK (clock), clock->current_time);
GST_LOCK (clock);
clock->is_updated = FALSE;
/* FIXME, convert the entries to ones that wait for the system clock */
if (clock->entries) {
GList *entries = g_list_copy (clock->entries);
while (entries) {
GstClockEntry *entry = (GstClockEntry *)entries->data;
GST_CLOCK_ENTRY_LOCK (entry);
GST_CLOCK_ENTRY_SIGNAL (entry);
entry->status = GST_ENTRY_RESTART;
GST_CLOCK_ENTRY_UNLOCK (entry);
clock->entries = g_list_remove (clock->entries, entry);
entries = g_list_next (entries);
}
}
}
else {
clock->is_updated = TRUE;
}
GTimeVal timeval;
GstClockTime time1;
GstClockTime time2;
GstClockTimeDiff diff1, diff2;
GstOssClock *oss_clock = GST_OSS_CLOCK (clock);
GST_UNLOCK (clock);
g_get_current_time (&timeval);
time1 = oss_clock->func (clock, oss_clock->user_data);
time2 = GST_TIMEVAL_TO_TIME (timeval);
if (!oss_clock->prev1) {
oss_clock->prev1 = time1;
}
diff1 = time1 - oss_clock->prev1;
diff2 = time2 - oss_clock->prev2;
oss_clock->prev1 = time1;
oss_clock->prev2 = time2;
if (diff1) {
oss_clock->adjust -= diff2 - diff1;
}
//g_print ("diff %lld %lld %lld %lld %lld %lld\n", diff1, diff2, time1, time2, diff2 - diff1, oss_clock->adjust);
return time2 + oss_clock->adjust;
}
void
gst_oss_clock_set_base (GstOssClock *clock, guint64 base)
{
GstOssClock *oss_clock = GST_OSS_CLOCK (clock);
oss_clock->base_time = base;
GST_CLOCK_CLASS (parent_class)->set_time (clock, base);
}
static void
gst_oss_clock_reset (GstClock *clock)
{
GstOssClock *oss_clock = GST_OSS_CLOCK (clock);
oss_clock->next_time = 0;
oss_clock->current_time = 0;
oss_clock->base_time = 0;
GST_CLOCK_CLASS (parent_class)->reset (clock);
}
static void
gst_oss_clock_activate (GstClock *clock, gboolean activate)
{
GstOssClock *oss_clock = GST_OSS_CLOCK (clock);
if (!activate) {
oss_clock->base_time = oss_clock->current_time;
}
GST_CLOCK_CLASS (parent_class)->activate (clock, activate);
}
static void
gst_oss_clock_set_time (GstClock *clock, GstClockTime time)
{
GList *entries;
GstOssClock *oss_clock = GST_OSS_CLOCK (clock);
GST_LOCK (clock);
time += oss_clock->base_time;
/*g_print ("set time %llu\n", time); */
oss_clock->current_time = time;
if (oss_clock->next_time > time) {
GST_UNLOCK (clock);
return;
}
entries = g_list_copy (oss_clock->entries);
while (entries) {
GstClockEntry *entry = (GstClockEntry *)entries->data;
if (GST_CLOCK_ENTRY_TIME (entry) <= oss_clock->current_time) {
GST_CLOCK_ENTRY_LOCK (entry);
GST_CLOCK_ENTRY_SIGNAL (entry);
entry->status = GST_ENTRY_OK;
GST_CLOCK_ENTRY_UNLOCK (entry);
oss_clock->entries = g_list_remove (oss_clock->entries, entry);
}
else {
break;
}
entries = g_list_next (entries);
}
if (oss_clock->entries) {
oss_clock->next_time = GST_CLOCK_ENTRY_TIME (oss_clock->entries->data);
}
else {
oss_clock->next_time = 0;
}
GST_UNLOCK (oss_clock);
}
static gint
clock_compare_func (gconstpointer a,
gconstpointer b)
{
GstClockEntry *entry1 = (GstClockEntry *)a;
GstClockEntry *entry2 = (GstClockEntry *)b;
return (entry1->time - entry2->time);
}
static GstClockReturn
gst_oss_clock_wait (GstClock *clock, GstClockTime time)
{
GstClockReturn ret;
GstOssClock *oss_clock = GST_OSS_CLOCK (clock);
GST_LOCK (clock);
restart:
if (!oss_clock->is_updated) {
GST_UNLOCK (clock);
ret = GST_CLOCK_CLASS (parent_class)->wait (clock, time);
}
else if (time > oss_clock->current_time) {
GstClockEntry *entry = gst_clock_entry_new (time);
oss_clock->entries = g_list_insert_sorted (oss_clock->entries, entry, clock_compare_func);
oss_clock->next_time = GST_CLOCK_ENTRY_TIME (oss_clock->entries->data);
GST_CLOCK_ENTRY_LOCK (entry);
GST_UNLOCK (clock);
GST_CLOCK_ENTRY_WAIT (entry);
if (entry->status == GST_ENTRY_RESTART)
goto restart;
GST_CLOCK_ENTRY_UNLOCK (entry);
gst_clock_entry_free (entry);
ret = GST_CLOCK_TIMEOUT;
}
else {
GST_UNLOCK (clock);
ret = GST_CLOCK_EARLY;
}
return ret;
}

View file

@ -45,18 +45,17 @@ extern "C" {
typedef struct _GstOssClock GstOssClock;
typedef struct _GstOssClockClass GstOssClockClass;
typedef GstClockTime (*GstOssClockGetTimeFunc) (GstClock *clock, gpointer user_data);
struct _GstOssClock {
GstSystemClock clock;
GList *entries;
GstClockTime current_time;
GstClockTime next_time;
GstClockTime base_time;
gboolean is_updated;
GstClockTime start_time;
GstClockTime origin;
GstElement *owner;
GstOssClockGetTimeFunc func;
gpointer user_data;
GstClockTime prev1, prev2;
GstClockTimeDiff adjust;
};
struct _GstOssClockClass {
@ -64,10 +63,8 @@ struct _GstOssClockClass {
};
GType gst_oss_clock_get_type (void);
GstOssClock* gst_oss_clock_new (gchar *name, GstElement *owner);
void gst_oss_clock_set_update (GstOssClock *clock, gboolean update);
void gst_oss_clock_set_base (GstOssClock *clock, guint64 base);
GstOssClock* gst_oss_clock_new (gchar *name, GstOssClockGetTimeFunc func,
gpointer user_data);
#ifdef __cplusplus
}

View file

@ -50,7 +50,8 @@ static void gst_osssink_close_audio (GstOssSink *sink);
static gboolean gst_osssink_sync_parms (GstOssSink *osssink);
static GstElementStateReturn gst_osssink_change_state (GstElement *element);
static void gst_osssink_set_clock (GstElement *element, GstClock *clock);
static GstClock* gst_osssink_get_clock (GstElement *element);
static GstClock* gst_osssink_get_clock (GstElement *element);
static GstPadConnectReturn gst_osssink_sinkconnect (GstPad *pad, GstCaps *caps);
static void gst_osssink_set_property (GObject *object, guint prop_id, const GValue *value,
@ -213,7 +214,21 @@ gst_osssink_class_init (GstOssSinkClass *klass)
gobject_class->get_property = gst_osssink_get_property;
gobject_class->finalize = gst_osssink_finalize;
gstelement_class->change_state = gst_osssink_change_state;
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_osssink_change_state);
}
static GstClockTime
gst_osssink_get_time (GstClock *clock, gpointer data)
{
GstOssSink *osssink = GST_OSSSINK (data);
gint delay;
if (!osssink->bps)
return 0;
ioctl (osssink->fd, SNDCTL_DSP_GETODELAY, &delay);
return osssink->offset + (osssink->handled - delay) * 1000000LL / osssink->bps;
}
static void
@ -240,16 +255,19 @@ gst_osssink_init (GstOssSink *osssink)
#endif /* WORDS_BIGENDIAN */
/* gst_clock_register (osssink->clock, GST_OBJECT (osssink)); */
osssink->bufsize = 4096;
osssink->offset = 0LL;
osssink->offset = -1LL;
osssink->handled = 0LL;
/* 6 buffers per chunk by default */
osssink->sinkpool = gst_buffer_pool_get_default (osssink->bufsize, 6);
osssink->provided_clock = GST_CLOCK (gst_oss_clock_new ("OssClock", GST_ELEMENT (osssink)));
osssink->provided_clock = NULL;
osssink->provided_clock = GST_CLOCK (gst_oss_clock_new ("ossclock", gst_osssink_get_time, osssink));
GST_ELEMENT (osssink)->setclockfunc = gst_osssink_set_clock;
GST_ELEMENT (osssink)->getclockfunc = gst_osssink_get_clock;
GST_FLAG_SET (osssink, GST_ELEMENT_THREAD_SUGGESTED);
GST_FLAG_SET (osssink, GST_ELEMENT_EVENT_AWARE);
}
static GstPadConnectReturn
@ -263,8 +281,8 @@ gst_osssink_sinkconnect (GstPad *pad, GstCaps *caps)
if (!GST_CAPS_IS_FIXED (caps))
return GST_PAD_CONNECT_DELAYED;
width = gst_caps_get_int (caps, "width");
depth = gst_caps_get_int (caps, "depth");
gst_caps_get_int (caps, "width", &width);
gst_caps_get_int (caps, "depth", &depth);
if (width != depth)
return GST_PAD_CONNECT_REFUSED;
@ -272,9 +290,9 @@ gst_osssink_sinkconnect (GstPad *pad, GstCaps *caps)
/* laws 1 and 2 are 1 bps anyway */
osssink->bps = 1;
law = gst_caps_get_int (caps, "law");
endianness = gst_caps_get_int (caps, "endianness");
sign = gst_caps_get_boolean (caps, "signed");
gst_caps_get_int (caps, "law", &law);
gst_caps_get_int (caps, "endianness", &endianness);
gst_caps_get_boolean (caps, "signed", &sign);
if (law == 0) {
if (width == 16) {
@ -314,8 +332,8 @@ gst_osssink_sinkconnect (GstPad *pad, GstCaps *caps)
return GST_PAD_CONNECT_REFUSED;
osssink->format = format;
osssink->channels = gst_caps_get_int (caps, "channels");
osssink->frequency = gst_caps_get_int (caps, "rate");
gst_caps_get_int (caps, "channels", &osssink->channels);
gst_caps_get_int (caps, "rate", &osssink->frequency);
osssink->bps *= osssink->channels;
osssink->bps *= osssink->frequency;
@ -344,9 +362,9 @@ gst_osssink_sync_parms (GstOssSink *osssink)
return FALSE;
if (osssink->fragment >> 16)
frag = osssink->fragment;
frag = osssink->fragment;
else
frag = 0x7FFF0000 | osssink->fragment;
frag = 0x7FFF0000 | osssink->fragment;
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: trying to set sound card to %dHz %d bit %s (%08x fragment)",
osssink->frequency, osssink->format,
@ -393,6 +411,16 @@ gst_osssink_sync_parms (GstOssSink *osssink)
return TRUE;
}
static GstClock*
gst_osssink_get_clock (GstElement *element)
{
GstOssSink *osssink;
osssink = GST_OSSSINK (element);
return GST_CLOCK (osssink->provided_clock);
}
static void
gst_osssink_set_clock (GstElement *element, GstClock *clock)
{
@ -403,16 +431,6 @@ gst_osssink_set_clock (GstElement *element, GstClock *clock)
osssink->clock = clock;
}
static GstClock*
gst_osssink_get_clock (GstElement *element)
{
GstOssSink *osssink;
osssink = GST_OSSSINK (element);
return osssink->provided_clock;
}
static void
gst_osssink_chain (GstPad *pad, GstBuffer *buf)
{
@ -422,6 +440,17 @@ gst_osssink_chain (GstPad *pad, GstBuffer *buf)
/* this has to be an audio buffer */
osssink = GST_OSSSINK (gst_pad_get_parent (pad));
if (GST_IS_EVENT (buf)) {
switch (GST_EVENT_TYPE (buf)) {
case GST_EVENT_EOS:
ioctl (osssink->fd, SNDCTL_DSP_SYNC);
gst_pad_event_default (pad, GST_EVENT (buf));
return;
default:
return;
}
}
buftime = GST_BUFFER_TIMESTAMP (buf);
if (!osssink->bps) {
@ -433,47 +462,26 @@ gst_osssink_chain (GstPad *pad, GstBuffer *buf)
if (!osssink->mute) {
guchar *data = GST_BUFFER_DATA (buf);
gint size = GST_BUFFER_SIZE (buf);
gint frag = osssink->fragment;
if (osssink->clock) {
if (osssink->clock == osssink->provided_clock) {
guint64 time;
gint granularity, granularity_time;
count_info optr;
audio_buf_info ospace;
gint queued;
/* FIXME, NEW_MEDIA/DISCONT?. Try to get our start point */
if (osssink->offset == 0LL && buftime != -1LL) {
/* gst_oss_clock_set_base (GST_OSS_CLOCK (osssink->clock), buftime); */
osssink->offset = buftime;
}
ioctl (osssink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
ioctl (osssink->fd, SNDCTL_DSP_GETOPTR, &optr);
queued = (ospace.fragstotal * ospace.fragsize) - ospace.bytes;
time = osssink->offset + (optr.bytes) * 1000000LL / osssink->bps;
GST_DEBUG (GST_CAT_PLUGIN_INFO, "sync %llu %llu %d", buftime, time, queued);
granularity = ospace.fragsize;
/* granularity = size; */
granularity_time = granularity * osssink->fragment_time / ospace.fragsize;
while (size > 0) {
write (osssink->fd, data, MIN (size, granularity));
data += granularity;
size -= granularity;
time += granularity_time;
gst_clock_set_time (osssink->provided_clock, time);
}
}
else {
/* FIXME, NEW_MEDIA/DISCONT?. Try to get our start point */
if (osssink->offset == -1LL && buftime != -1LL) {
//g_print ("%lld %lld %lld\n", osssink->offset, buftime, gst_clock_get_time (osssink->clock));
osssink->offset = buftime;
osssink->handled = 0;
gst_element_clock_wait (GST_ELEMENT (osssink), osssink->clock, buftime);
write (osssink->fd, data, size);
}
while (size) {
gint tosend = MIN (size, frag);
write (osssink->fd, data, tosend);
data += frag;
size -= frag;
osssink->handled += tosend;
}
}
/* no clock, try to be as fast as possible */
else {
audio_buf_info ospace;
@ -482,6 +490,7 @@ gst_osssink_chain (GstPad *pad, GstBuffer *buf)
if (ospace.bytes >= size) {
write (osssink->fd, data, size);
}
osssink->handled += size;
}
}
}
@ -675,9 +684,10 @@ gst_osssink_change_state (GstElement *element)
}
break;
case GST_STATE_READY_TO_PAUSED:
osssink->offset = -1LL;
break;
case GST_STATE_PAUSED_TO_PLAYING:
gst_oss_clock_set_update (GST_OSS_CLOCK (osssink->provided_clock), TRUE);
//gst_clock_adjust (osssink->clock, osssink->offset - gst_clock_get_time (osssink->clock));
break;
case GST_STATE_PLAYING_TO_PAUSED:
{
@ -685,22 +695,18 @@ gst_osssink_change_state (GstElement *element)
if (osssink->bps) {
GstClockTime time;
audio_buf_info ospace;
count_info optr;
gint queued;
ioctl (osssink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
ioctl (osssink->fd, SNDCTL_DSP_GETOPTR, &optr);
queued = (ospace.fragstotal * ospace.fragsize) - ospace.bytes;
time = (optr.bytes + queued) * 1000000LL / osssink->bps;
ioctl (osssink->fd, SNDCTL_DSP_RESET, 0);
gst_oss_clock_set_update (GST_OSS_CLOCK (osssink->provided_clock), FALSE);
gst_clock_set_time (osssink->provided_clock, time);
queued = (ospace.fragstotal * ospace.fragsize) - ospace.bytes;
time = osssink->offset + (osssink->handled - queued) * 1000000LL / osssink->bps;
//gst_clock_adjust (osssink->clock, time - gst_clock_get_time (osssink->clock));
}
else {
ioctl (osssink->fd, SNDCTL_DSP_RESET, 0);
gst_oss_clock_set_update (GST_OSS_CLOCK (osssink->provided_clock), FALSE);
}
}

View file

@ -78,6 +78,7 @@ struct _GstOssSink {
guint bufsize;
guint bps;
guint64 offset;
guint64 handled;
guint64 fragment_time;
};