Added timestamps

Original commit message from CVS:
Added timestamps
Added typefind
check if pad is connected before pushing
This commit is contained in:
Wim Taymans 2002-06-15 14:32:35 +00:00
parent 0d8175508d
commit 7f38fbbf15
2 changed files with 136 additions and 44 deletions

View File

@ -119,11 +119,41 @@ GST_PAD_TEMPLATE_FACTORY ( audio_src_temp,
) )
) )
/* typefind stuff */
static GstCaps*
dv_type_find (GstBuffer *buf, gpointer private)
{
gulong head = GULONG_FROM_BE(*((gulong *)GST_BUFFER_DATA(buf)));
GstCaps *new = NULL;
/* check for DIF and DV flag */
if ((head & 0xffffff00) == 0x1f070000 && !(GST_BUFFER_DATA(buf)[4] & 0x01)) {
gchar *format;
if ((head & 0x000000ff) & 0x80)
format = "PAL";
else
format = "NTSC";
new = GST_CAPS_NEW ("dv_type_find",
"video/dv",
"format", GST_PROPS_STRING (format)
);
}
return new;
}
static GstTypeDefinition dv_definition = {
"dv_video/dv", "video/dv", ".dv", dv_type_find
};
/* A number of functon prototypes are given so we can refer to them later. */ /* A number of functon prototypes are given so we can refer to them later. */
static void gst_dvdec_class_init (GstDVDecClass *klass); static void gst_dvdec_class_init (GstDVDecClass *klass);
static void gst_dvdec_init (GstDVDec *dvdec); static void gst_dvdec_init (GstDVDec *dvdec);
static gboolean gst_dvdec_src_query (GstPad *pad, GstPadQueryType type,
GstFormat *format, gint64 *value);
static void gst_dvdec_loop (GstElement *element); static void gst_dvdec_loop (GstElement *element);
static GstElementStateReturn static GstElementStateReturn
@ -212,12 +242,15 @@ gst_dvdec_init(GstDVDec *dvdec)
dvdec->sinkpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (sink_temp), "sink"); dvdec->sinkpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (sink_temp), "sink");
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad); gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
gst_pad_set_query_function (dvdec->sinkpad, NULL);
dvdec->videosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (video_src_temp), "video"); dvdec->videosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (video_src_temp), "video");
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->videosrcpad); gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->videosrcpad);
gst_pad_set_query_function (dvdec->videosrcpad, gst_dvdec_src_query);
dvdec->audiosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET(audio_src_temp), "audio"); dvdec->audiosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET(audio_src_temp), "audio");
gst_element_add_pad(GST_ELEMENT(dvdec),dvdec->audiosrcpad); gst_element_add_pad(GST_ELEMENT(dvdec),dvdec->audiosrcpad);
gst_pad_set_query_function (dvdec->audiosrcpad, gst_dvdec_src_query);
gst_element_set_loop_function (GST_ELEMENT (dvdec), gst_dvdec_loop); gst_element_set_loop_function (GST_ELEMENT (dvdec), gst_dvdec_loop);
@ -225,12 +258,51 @@ gst_dvdec_init(GstDVDec *dvdec)
dvdec->decoder->quality = DV_QUALITY_BEST; dvdec->decoder->quality = DV_QUALITY_BEST;
dvdec->pool = NULL; dvdec->pool = NULL;
dvdec->length = 0; dvdec->length = 0;
dvdec->next_ts = 0LL;
for (i = 0; i <4; i++) { for (i = 0; i <4; i++) {
dvdec->audio_buffers[i] = (gint16 *)g_malloc (DV_AUDIO_MAX_SAMPLES * sizeof (gint16)); dvdec->audio_buffers[i] = (gint16 *)g_malloc (DV_AUDIO_MAX_SAMPLES * sizeof (gint16));
} }
} }
static gboolean
gst_dvdec_src_query (GstPad *pad, GstPadQueryType type,
GstFormat *format, gint64 *value)
{
gboolean res = TRUE;
GstDVDec *dvdec;
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
switch (type) {
case GST_PAD_QUERY_TOTAL:
switch (*format) {
case GST_FORMAT_DEFAULT:
*format = GST_FORMAT_TIME;
case GST_FORMAT_TIME:
*value = 0;
break;
default:
res = FALSE;
break;
}
break;
case GST_PAD_QUERY_POSITION:
switch (*format) {
case GST_FORMAT_DEFAULT:
*format = GST_FORMAT_TIME;
default:
*value = dvdec->next_ts;
break;
}
break;
default:
res = FALSE;
break;
}
return res;
}
static gboolean static gboolean
gst_dvdec_handle_event (GstDVDec *dvdec) gst_dvdec_handle_event (GstDVDec *dvdec)
{ {
@ -273,14 +345,11 @@ gst_dvdec_loop (GstElement *element)
GstDVDec *dvdec; GstDVDec *dvdec;
GstBuffer *buf, *outbuf; GstBuffer *buf, *outbuf;
guint8 *inframe; guint8 *inframe;
guint8 *outframe;
guint8 *outframe_ptrs[3];
gint outframe_pitches[3];
gboolean PAL; gboolean PAL;
gint height; gint height;
guint32 length, got_bytes; guint32 length, got_bytes;
gint16 *a_ptr; GstFormat format;
gint i, j; guint64 ts;
dvdec = GST_DVDEC (element); dvdec = GST_DVDEC (element);
@ -374,6 +443,13 @@ gst_dvdec_loop (GstElement *element)
)); ));
} }
format = GST_FORMAT_TIME;
gst_pad_query (dvdec->videosrcpad, GST_PAD_QUERY_POSITION, &format, &ts);
if (GST_PAD_IS_CONNECTED (dvdec->audiosrcpad)) {
gint16 *a_ptr;
gint i, j;
dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf), dvdec->audio_buffers); dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf), dvdec->audio_buffers);
outbuf = gst_buffer_new (); outbuf = gst_buffer_new ();
@ -387,7 +463,15 @@ gst_dvdec_loop (GstElement *element)
*(a_ptr++) = dvdec->audio_buffers[j][i]; *(a_ptr++) = dvdec->audio_buffers[j][i];
} }
} }
GST_BUFFER_TIMESTAMP (outbuf) = ts;
gst_pad_push (dvdec->audiosrcpad, outbuf); gst_pad_push (dvdec->audiosrcpad, outbuf);
}
if (GST_PAD_IS_CONNECTED (dvdec->videosrcpad)) {
guint8 *outframe;
guint8 *outframe_ptrs[3];
gint outframe_pitches[3];
/* try to grab a pool */ /* try to grab a pool */
if (!dvdec->pool) { if (!dvdec->pool) {
@ -407,7 +491,6 @@ gst_dvdec_loop (GstElement *element)
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf)); GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
} }
outframe = GST_BUFFER_DATA (outbuf); outframe = GST_BUFFER_DATA (outbuf);
outframe_ptrs[0] = outframe; outframe_ptrs[0] = outframe;
@ -421,11 +504,17 @@ gst_dvdec_loop (GstElement *element)
dv_decode_full_frame (dvdec->decoder, GST_BUFFER_DATA (buf), dv_decode_full_frame (dvdec->decoder, GST_BUFFER_DATA (buf),
dvdec->space, outframe_ptrs, outframe_pitches); dvdec->space, outframe_ptrs, outframe_pitches);
gst_buffer_unref (buf); GST_BUFFER_TIMESTAMP (outbuf) = ts;
gst_pad_push (dvdec->videosrcpad, outbuf); gst_pad_push (dvdec->videosrcpad, outbuf);
} }
/* FIXME this is inaccurate for NTSC */
dvdec->next_ts += GST_SECOND / (PAL ? 25 : 30);
gst_buffer_unref (buf);
}
static GstElementStateReturn static GstElementStateReturn
gst_dvdec_change_state (GstElement *element) gst_dvdec_change_state (GstElement *element)
{ {
@ -456,8 +545,6 @@ gst_dvdec_change_state (GstElement *element)
return GST_STATE_SUCCESS; return GST_STATE_SUCCESS;
} }
/* Arguments are part of the Gtk+ object system, and these functions /* Arguments are part of the Gtk+ object system, and these functions
* enable the element to respond to various arguments. * enable the element to respond to various arguments.
*/ */
@ -503,6 +590,7 @@ static gboolean
plugin_init (GModule *module, GstPlugin *plugin) plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstElementFactory *factory; GstElementFactory *factory;
GstTypeFactory *type;
if (!gst_library_load ("gstbytestream")) { if (!gst_library_load ("gstbytestream")) {
gst_info("dvdec: could not load support library: 'gstbytestream'\n"); gst_info("dvdec: could not load support library: 'gstbytestream'\n");
@ -529,6 +617,9 @@ plugin_init (GModule *module, GstPlugin *plugin)
/* The very last thing is to register the elementfactory with the plugin. */ /* The very last thing is to register the elementfactory with the plugin. */
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
type = gst_type_factory_new (&dv_definition);
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
return TRUE; return TRUE;
} }

View File

@ -54,6 +54,7 @@ struct _GstDVDec {
dv_color_space_t space; dv_color_space_t space;
gint bpp; gint bpp;
gint length; gint length;
guint64 next_ts;
gint16 *audio_buffers[4]; gint16 *audio_buffers[4];
}; };