Implement query() function implementation in sinesrc and fix up paused-ready-paused handling

Original commit message from CVS:
Implement query() function implementation in sinesrc and fix up paused-ready-paused handling
This commit is contained in:
Ronald S. Bultje 2003-12-14 16:15:49 +00:00
parent b68500c311
commit f4cc065738
2 changed files with 81 additions and 30 deletions

View file

@ -83,10 +83,8 @@ static void gst_sinesrc_get_property (GObject *object,
guint prop_id, guint prop_id,
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
/*static gboolean gst_sinesrc_change_state(GstElement *element, */ static GstElementStateReturn
/* GstElementState state); */ gst_sinesrc_change_state (GstElement *element);
/*static void gst_sinesrc_close_audio(GstSineSrc *src); */
/*static gboolean gst_sinesrc_open_audio(GstSineSrc *src); */
static void gst_sinesrc_update_freq (const GValue *value, static void gst_sinesrc_update_freq (const GValue *value,
gpointer data); gpointer data);
@ -94,6 +92,13 @@ static void gst_sinesrc_populate_sinetable (GstSineSrc *src);
static inline void gst_sinesrc_update_table_inc (GstSineSrc *src); static inline void gst_sinesrc_update_table_inc (GstSineSrc *src);
static gboolean gst_sinesrc_force_caps (GstSineSrc *src); static gboolean gst_sinesrc_force_caps (GstSineSrc *src);
static const GstQueryType *
gst_sinesrc_get_query_types (GstPad *pad);
static gboolean gst_sinesrc_src_query (GstPad *pad,
GstQueryType type,
GstFormat *format,
gint64 *value);
static GstData* gst_sinesrc_get (GstPad *pad); static GstData* gst_sinesrc_get (GstPad *pad);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -165,7 +170,7 @@ gst_sinesrc_class_init (GstSineSrcClass *klass)
gobject_class->set_property = gst_sinesrc_set_property; gobject_class->set_property = gst_sinesrc_set_property;
gobject_class->get_property = gst_sinesrc_get_property; gobject_class->get_property = gst_sinesrc_get_property;
/* gstelement_class->change_state = gst_sinesrc_change_state; */ gstelement_class->change_state = gst_sinesrc_change_state;
} }
static void static void
@ -177,6 +182,8 @@ gst_sinesrc_init (GstSineSrc *src)
gst_element_add_pad (GST_ELEMENT(src), src->srcpad); gst_element_add_pad (GST_ELEMENT(src), src->srcpad);
gst_pad_set_get_function (src->srcpad, gst_sinesrc_get); gst_pad_set_get_function (src->srcpad, gst_sinesrc_get);
gst_pad_set_query_function (src->srcpad, gst_sinesrc_src_query);
gst_pad_set_query_type_function (src->srcpad, gst_sinesrc_get_query_types);
src->width = 16; src->width = 16;
src->samplerate = 44100; src->samplerate = 44100;
@ -188,7 +195,8 @@ gst_sinesrc_init (GstSineSrc *src)
src->table_pos = 0.0; src->table_pos = 0.0;
src->table_size = 1024; src->table_size = 1024;
src->samples_per_buffer=1024; src->samples_per_buffer=1024;
src->timestamp=0LL; src->timestamp=0LLU;
src->offset=0LLU;
src->bufpool=NULL; src->bufpool=NULL;
src->seq = 0; src->seq = 0;
@ -219,6 +227,54 @@ gst_sinesrc_init (GstSineSrc *src)
} }
static const GstQueryType *
gst_sinesrc_get_query_types (GstPad *pad)
{
static const GstQueryType query_types[] = {
GST_QUERY_POSITION,
0,
};
return query_types;
}
static gboolean
gst_sinesrc_src_query (GstPad *pad,
GstQueryType type,
GstFormat *format,
gint64 *value)
{
gboolean res = FALSE;
GstSineSrc *src;
src = GST_SINESRC (gst_pad_get_parent (pad));
switch (type) {
case GST_QUERY_POSITION:
switch (*format) {
case GST_FORMAT_TIME:
*value = src->timestamp;
res = TRUE;
break;
case GST_FORMAT_DEFAULT: /* samples */
*value = src->offset / 2; /* 16bpp audio */
res = TRUE;
break;
case GST_FORMAT_BYTES:
*value = src->offset;
res = TRUE;
break;
default:
break;
}
break;
default:
break;
}
return res;
}
static GstData * static GstData *
gst_sinesrc_get (GstPad *pad) gst_sinesrc_get (GstPad *pad)
{ {
@ -237,13 +293,14 @@ gst_sinesrc_get (GstPad *pad)
buf = (GstBuffer *) gst_buffer_new_from_pool (src->bufpool, 0, 0); buf = (GstBuffer *) gst_buffer_new_from_pool (src->bufpool, 0, 0);
GST_BUFFER_TIMESTAMP(buf) = src->timestamp; GST_BUFFER_TIMESTAMP(buf) = src->timestamp;
GST_BUFFER_OFFSET (buf) = src->offset;
samples = (gint16*)GST_BUFFER_DATA(buf); samples = (gint16 *) GST_BUFFER_DATA(buf);
GST_BUFFER_DATA(buf) = (gpointer) samples;
GST_DPMAN_PREPROCESS(src->dpman, src->samples_per_buffer, src->timestamp); GST_DPMAN_PREPROCESS(src->dpman, src->samples_per_buffer, src->timestamp);
src->timestamp += (gint64)src->samples_per_buffer * GST_SECOND / (gint64)src->samplerate; src->timestamp += (gint64)src->samples_per_buffer * GST_SECOND / (gint64)src->samplerate;
src->offset += GST_BUFFER_SIZE (buf);
while(GST_DPMAN_PROCESS(src->dpman, i)) { while(GST_DPMAN_PROCESS(src->dpman, i)) {
#if 0 #if 0
@ -373,28 +430,25 @@ gst_sinesrc_get_property (GObject *object, guint prop_id,
} }
} }
/* static GstElementStateReturn
static gboolean gst_sinesrc_change_state(GstElement *element, gst_sinesrc_change_state (GstElement *element)
GstElementState state) { {
g_return_if_fail(GST_IS_SINESRC(element)); GstSineSrc *src = GST_SINESRC (element);
switch (state) { switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_RUNNING: case GST_STATE_PAUSED_TO_READY:
if (!gst_sinesrc_open_audio(GST_SINESRC(element))) src->timestamp = 0LLU;
return FALSE; src->offset = 0LLU;
break;
case ~GST_STATE_RUNNING:
gst_sinesrc_close_audio(GST_SINESRC(element));
break; break;
default: default:
break; break;
} }
if (GST_ELEMENT_CLASS(parent_class)->change_state) if (GST_ELEMENT_CLASS(parent_class)->change_state)
return GST_ELEMENT_CLASS(parent_class)->change_state(element,state); return GST_ELEMENT_CLASS(parent_class)->change_state (element);
return TRUE;
return GST_STATE_SUCCESS;
} }
*/
static void static void
gst_sinesrc_populate_sinetable (GstSineSrc *src) gst_sinesrc_populate_sinetable (GstSineSrc *src)

View file

@ -27,9 +27,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#ifdef __cplusplus G_BEGIN_DECLS
extern "C" {
#endif /* __cplusplus */
GstElementDetails gst_sinesrc_details; GstElementDetails gst_sinesrc_details;
@ -76,12 +74,13 @@ struct _GstSineSrc {
gint samples_per_buffer; gint samples_per_buffer;
gulong seq; gulong seq;
gint64 timestamp; guint64 timestamp;
guint64 offset;
GstBufferPool *bufpool; GstBufferPool *bufpool;
gboolean newcaps; gboolean newcaps;
double accumulator; gdouble accumulator;
}; };
struct _GstSineSrcClass { struct _GstSineSrcClass {
@ -91,9 +90,7 @@ struct _GstSineSrcClass {
GType gst_sinesrc_get_type(void); GType gst_sinesrc_get_type(void);
gboolean gst_sinesrc_factory_init (GstElementFactory *factory); gboolean gst_sinesrc_factory_init (GstElementFactory *factory);
#ifdef __cplusplus G_END_DECLS
}
#endif /* __cplusplus */
#endif /* __GST_SINESRC_H__ */ #endif /* __GST_SINESRC_H__ */