mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 19:20:35 +00:00
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:
parent
b68500c311
commit
f4cc065738
2 changed files with 81 additions and 30 deletions
|
@ -83,10 +83,8 @@ static void gst_sinesrc_get_property (GObject *object,
|
|||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
/*static gboolean gst_sinesrc_change_state(GstElement *element, */
|
||||
/* GstElementState state); */
|
||||
/*static void gst_sinesrc_close_audio(GstSineSrc *src); */
|
||||
/*static gboolean gst_sinesrc_open_audio(GstSineSrc *src); */
|
||||
static GstElementStateReturn
|
||||
gst_sinesrc_change_state (GstElement *element);
|
||||
|
||||
static void gst_sinesrc_update_freq (const GValue *value,
|
||||
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 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 GstElementClass *parent_class = NULL;
|
||||
|
@ -165,7 +170,7 @@ gst_sinesrc_class_init (GstSineSrcClass *klass)
|
|||
gobject_class->set_property = gst_sinesrc_set_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
|
||||
|
@ -177,6 +182,8 @@ gst_sinesrc_init (GstSineSrc *src)
|
|||
gst_element_add_pad (GST_ELEMENT(src), src->srcpad);
|
||||
|
||||
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->samplerate = 44100;
|
||||
|
@ -188,7 +195,8 @@ gst_sinesrc_init (GstSineSrc *src)
|
|||
src->table_pos = 0.0;
|
||||
src->table_size = 1024;
|
||||
src->samples_per_buffer=1024;
|
||||
src->timestamp=0LL;
|
||||
src->timestamp=0LLU;
|
||||
src->offset=0LLU;
|
||||
src->bufpool=NULL;
|
||||
|
||||
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 *
|
||||
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);
|
||||
GST_BUFFER_TIMESTAMP(buf) = src->timestamp;
|
||||
GST_BUFFER_OFFSET (buf) = src->offset;
|
||||
|
||||
samples = (gint16*)GST_BUFFER_DATA(buf);
|
||||
GST_BUFFER_DATA(buf) = (gpointer) samples;
|
||||
samples = (gint16 *) GST_BUFFER_DATA(buf);
|
||||
|
||||
GST_DPMAN_PREPROCESS(src->dpman, src->samples_per_buffer, src->timestamp);
|
||||
|
||||
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)) {
|
||||
#if 0
|
||||
|
@ -373,28 +430,25 @@ gst_sinesrc_get_property (GObject *object, guint prop_id,
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
static gboolean gst_sinesrc_change_state(GstElement *element,
|
||||
GstElementState state) {
|
||||
g_return_if_fail(GST_IS_SINESRC(element));
|
||||
static GstElementStateReturn
|
||||
gst_sinesrc_change_state (GstElement *element)
|
||||
{
|
||||
GstSineSrc *src = GST_SINESRC (element);
|
||||
|
||||
switch (state) {
|
||||
case GST_STATE_RUNNING:
|
||||
if (!gst_sinesrc_open_audio(GST_SINESRC(element)))
|
||||
return FALSE;
|
||||
break;
|
||||
case ~GST_STATE_RUNNING:
|
||||
gst_sinesrc_close_audio(GST_SINESRC(element));
|
||||
switch (GST_STATE_TRANSITION (element)) {
|
||||
case GST_STATE_PAUSED_TO_READY:
|
||||
src->timestamp = 0LLU;
|
||||
src->offset = 0LLU;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (GST_ELEMENT_CLASS(parent_class)->change_state)
|
||||
return GST_ELEMENT_CLASS(parent_class)->change_state(element,state);
|
||||
return TRUE;
|
||||
return GST_ELEMENT_CLASS(parent_class)->change_state (element);
|
||||
|
||||
return GST_STATE_SUCCESS;
|
||||
}
|
||||
*/
|
||||
|
||||
static void
|
||||
gst_sinesrc_populate_sinetable (GstSineSrc *src)
|
||||
|
|
|
@ -27,9 +27,7 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
GstElementDetails gst_sinesrc_details;
|
||||
|
@ -76,12 +74,13 @@ struct _GstSineSrc {
|
|||
gint samples_per_buffer;
|
||||
gulong seq;
|
||||
|
||||
gint64 timestamp;
|
||||
guint64 timestamp;
|
||||
guint64 offset;
|
||||
GstBufferPool *bufpool;
|
||||
|
||||
gboolean newcaps;
|
||||
|
||||
double accumulator;
|
||||
gdouble accumulator;
|
||||
};
|
||||
|
||||
struct _GstSineSrcClass {
|
||||
|
@ -91,9 +90,7 @@ struct _GstSineSrcClass {
|
|||
GType gst_sinesrc_get_type(void);
|
||||
gboolean gst_sinesrc_factory_init (GstElementFactory *factory);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
#endif /* __GST_SINESRC_H__ */
|
||||
|
|
Loading…
Reference in a new issue