mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-09-28 23:02:22 +00:00
latest set of fixed (mostly stupid bugs in the typefind element and the bufferstore)
Original commit message from CVS: latest set of fixed (mostly stupid bugs in the typefind element and the bufferstore) WARNING: includes fix that changes gst_pad_push behaviour to allow pushing on unconnected pads (which just unrefs the buffer
This commit is contained in:
parent
367dc2f36a
commit
59c9a1133d
10 changed files with 219 additions and 112 deletions
|
@ -135,9 +135,13 @@ gst_buffer_store_add_buffer_func (GstBufferStore *store, GstBuffer *buffer)
|
||||||
store->buffers &&
|
store->buffers &&
|
||||||
GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
||||||
/* we assumed valid offsets, but suddenly they are not anymore */
|
/* we assumed valid offsets, but suddenly they are not anymore */
|
||||||
|
GST_DEBUG_OBJECT (store, "attempting to add buffer %p with invalid offset to store with valid offset, abort",
|
||||||
|
buffer);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (store->buffers && !GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
} else if (store->buffers && !GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
||||||
/* the starting buffer had an invalid offset, in that case we assume continuous buffers */
|
/* the starting buffer had an invalid offset, in that case we assume continuous buffers */
|
||||||
|
GST_LOG_OBJECT (store, "adding buffer %p with invalid offset and size %u",
|
||||||
|
buffer, GST_BUFFER_SIZE (buffer));
|
||||||
gst_data_ref (GST_DATA (buffer));
|
gst_data_ref (GST_DATA (buffer));
|
||||||
g_list_append (store->buffers, buffer);
|
g_list_append (store->buffers, buffer);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -147,6 +151,8 @@ gst_buffer_store_add_buffer_func (GstBufferStore *store, GstBuffer *buffer)
|
||||||
GstBuffer *current;
|
GstBuffer *current;
|
||||||
|
|
||||||
g_assert (GST_BUFFER_OFFSET_IS_VALID (buffer));
|
g_assert (GST_BUFFER_OFFSET_IS_VALID (buffer));
|
||||||
|
GST_LOG_OBJECT (store, "attempting to add buffer %p with offset %"G_GUINT64_FORMAT" and size %u",
|
||||||
|
buffer, GST_BUFFER_OFFSET (buffer), GST_BUFFER_SIZE (buffer));
|
||||||
/* we keep a sorted list of non-overlapping buffers */
|
/* we keep a sorted list of non-overlapping buffers */
|
||||||
walk = store->buffers;
|
walk = store->buffers;
|
||||||
while (walk) {
|
while (walk) {
|
||||||
|
@ -163,8 +169,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore *store, GstBuffer *buffer)
|
||||||
} else {
|
} else {
|
||||||
needed_size = GST_BUFFER_SIZE (buffer);
|
needed_size = GST_BUFFER_SIZE (buffer);
|
||||||
}
|
}
|
||||||
if (needed_size <= GST_BUFFER_OFFSET (current)) {
|
if (needed_size <= GST_BUFFER_SIZE (current)) {
|
||||||
g_assert (needed_size == GST_BUFFER_OFFSET (current)); /* we have no overlapping data */
|
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
} else {
|
} else {
|
||||||
if (needed_size < GST_BUFFER_SIZE (buffer)) {
|
if (needed_size < GST_BUFFER_SIZE (buffer)) {
|
||||||
|
@ -323,7 +328,7 @@ gst_buffer_store_get_buffer (GstBufferStore *store, guint64 offset, guint size)
|
||||||
gst_data_ref (GST_DATA (ret));
|
gst_data_ref (GST_DATA (ret));
|
||||||
break;
|
break;
|
||||||
} else if (cur_offset + GST_BUFFER_SIZE (current) > offset) {
|
} else if (cur_offset + GST_BUFFER_SIZE (current) > offset) {
|
||||||
if (cur_offset + GST_BUFFER_SIZE (current) <= offset + size) {
|
if (cur_offset + GST_BUFFER_SIZE (current) >= offset + size) {
|
||||||
ret = gst_buffer_create_sub (current, offset - cur_offset, size);
|
ret = gst_buffer_create_sub (current, offset - cur_offset, size);
|
||||||
GST_LOG_OBJECT (store, "created subbuffer %p from buffer %p for offset %llu and size %u",
|
GST_LOG_OBJECT (store, "created subbuffer %p from buffer %p for offset %llu and size %u",
|
||||||
ret, current, offset, size);
|
ret, current, offset, size);
|
||||||
|
@ -396,11 +401,11 @@ gst_buffer_store_get_size (GstBufferStore *store, guint64 offset)
|
||||||
cur_offset = 0;
|
cur_offset = 0;
|
||||||
}
|
}
|
||||||
while (walk) {
|
while (walk) {
|
||||||
if (have_offset &&
|
current = GST_BUFFER (walk->data);
|
||||||
|
if (have_offset && counting &&
|
||||||
cur_offset + GST_BUFFER_SIZE (current) != GST_BUFFER_OFFSET (walk->data)) {
|
cur_offset + GST_BUFFER_SIZE (current) != GST_BUFFER_OFFSET (walk->data)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current = GST_BUFFER (walk->data);
|
|
||||||
if (have_offset) {
|
if (have_offset) {
|
||||||
cur_offset = GST_BUFFER_OFFSET (current);
|
cur_offset = GST_BUFFER_OFFSET (current);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ plugin_init (GModule *module, GstPlugin *plugin)
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_shaper_debug, "shaper", 0, "shaper element");
|
GST_DEBUG_CATEGORY_INIT (gst_shaper_debug, "shaper", 0, "shaper element");
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_statistics_debug, "statistics", 0, "statistics element");
|
GST_DEBUG_CATEGORY_INIT (gst_statistics_debug, "statistics", 0, "statistics element");
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_tee_debug, "tee", 0, "tee element");
|
GST_DEBUG_CATEGORY_INIT (gst_tee_debug, "tee", 0, "tee element");
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_type_find_element_debug, "typefind", 0, "typefind element");
|
GST_DEBUG_CATEGORY_INIT (gst_type_find_element_debug, "typefind", GST_DEBUG_BG_YELLOW | GST_DEBUG_FG_GREEN, "typefind element");
|
||||||
|
|
||||||
while (_elements[i].name) {
|
while (_elements[i].name) {
|
||||||
factory = gst_element_factory_new (_elements[i].name,
|
factory = gst_element_factory_new (_elements[i].name,
|
||||||
|
|
|
@ -142,7 +142,7 @@ gst_type_find_element_have_type (GstTypeFindElement *typefind, guint probability
|
||||||
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
||||||
g_free (caps_str);
|
g_free (caps_str);
|
||||||
gst_caps_replace (&typefind->caps, caps);
|
gst_caps_replace (&typefind->caps, caps);
|
||||||
if (!gst_pad_try_set_caps (typefind->src, caps)) {
|
if (gst_pad_try_set_caps (typefind->src, caps) < GST_PAD_LINK_OK) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,8 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
||||||
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
||||||
|
|
||||||
|
typefind_class->have_type = gst_type_find_element_have_type;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_CAPS,
|
g_object_class_install_property (gobject_class, ARG_CAPS,
|
||||||
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
||||||
GST_TYPE_CAPS, G_PARAM_READABLE));
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
||||||
|
@ -180,8 +182,6 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
G_TYPE_UINT, GST_TYPE_CAPS);
|
G_TYPE_UINT, GST_TYPE_CAPS);
|
||||||
|
|
||||||
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
||||||
|
|
||||||
typefind_class->have_type = gst_type_find_element_have_type;
|
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
||||||
|
@ -216,6 +216,8 @@ gst_type_find_element_dispose (GObject *object)
|
||||||
g_object_unref (typefind->store);
|
g_object_unref (typefind->store);
|
||||||
typefind->store = NULL;
|
typefind->store = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
||||||
|
@ -271,21 +273,27 @@ start_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
g_assert (typefind->caps == NULL);
|
g_assert (typefind->caps == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "starting typefinding");
|
||||||
typefind->mode = MODE_TYPEFIND;
|
typefind->mode = MODE_TYPEFIND;
|
||||||
|
typefind->stream_length_available = TRUE;
|
||||||
|
typefind->stream_length = 0;
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
stop_typefinding (GstTypeFindElement *typefind, gboolean push_cached_buffers)
|
stop_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
/* stop all typefinding and set mode back to normal */
|
/* stop all typefinding and set mode back to normal */
|
||||||
|
gboolean push_cached_buffers = gst_element_get_state (GST_ELEMENT (typefind)) == GST_STATE_PLAYING;
|
||||||
|
|
||||||
g_assert (typefind->possibilities == NULL);
|
g_assert (typefind->possibilities == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "stopping typefinding%s", push_cached_buffers ? " and pushing cached buffers" : "");
|
||||||
typefind->mode = MODE_NORMAL;
|
typefind->mode = MODE_NORMAL;
|
||||||
|
|
||||||
if (push_cached_buffers) {
|
if (push_cached_buffers) {
|
||||||
|
GstBuffer *buffer;
|
||||||
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
||||||
GstBuffer *buffer = gst_buffer_store_get_buffer (typefind->store, 0, size);
|
if (size && (buffer = gst_buffer_store_get_buffer (typefind->store, 0, size))) {
|
||||||
if (buffer) {
|
gst_pad_push (typefind->src, GST_DATA (buffer));
|
||||||
gst_pad_push (typefind->sink, GST_DATA (buffer));
|
|
||||||
} else {
|
} else {
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
@ -332,17 +340,24 @@ find_element_get_length (gpointer data)
|
||||||
GstTypeFindElement *typefind = entry->self;
|
GstTypeFindElement *typefind = entry->self;
|
||||||
GstFormat format = GST_FORMAT_BYTES;
|
GstFormat format = GST_FORMAT_BYTES;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length ()",
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but we know it's not available",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
if (!typefind->stream_length_available)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (entry->self->stream_length == 0) {
|
if (entry->self->stream_length == 0) {
|
||||||
typefind->stream_length_available = gst_pad_query (entry->self->sink, GST_QUERY_TOTAL,
|
typefind->stream_length_available = gst_pad_query (GST_PAD_PEER (entry->self->sink), GST_QUERY_TOTAL,
|
||||||
&format, &entry->self->stream_length);
|
&format, &entry->self->stream_length);
|
||||||
if (format != GST_FORMAT_BYTES)
|
if (format != GST_FORMAT_BYTES)
|
||||||
typefind->stream_length_available = FALSE;
|
typefind->stream_length_available = FALSE;
|
||||||
if (!typefind->stream_length_available)
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but it's not available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () and it's %"G_GUINT64_FORMAT" bytes",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->self->stream_length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry->self->stream_length;
|
return entry->self->stream_length;
|
||||||
|
@ -364,7 +379,7 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
} else {
|
} else {
|
||||||
buf = gst_buffer_store_get_buffer (entry->self->store, length - offset, size);
|
buf = gst_buffer_store_get_buffer (entry->self->store, length + offset, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +388,8 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
return GST_BUFFER_DATA (buf);
|
return GST_BUFFER_DATA (buf);
|
||||||
} else {
|
} else {
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "setting requested peek (%"G_GINT64_FORMAT", %u) on '%s'",
|
||||||
|
offset, size, GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
entry->requested_offset = offset;
|
entry->requested_offset = offset;
|
||||||
entry->requested_size = size;
|
entry->requested_size = size;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +456,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
|
|
||||||
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
||||||
entry->self = typefind;
|
entry->self = typefind;
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
all_factories = g_list_next (all_factories);
|
all_factories = g_list_next (all_factories);
|
||||||
}
|
}
|
||||||
|
@ -451,12 +468,14 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
while (walk) {
|
while (walk) {
|
||||||
find.data = entry = (TypeFindEntry *) walk->data;
|
find.data = entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
gst_type_find_factory_call_function (entry->factory, &find);
|
gst_type_find_factory_call_function (entry->factory, &find);
|
||||||
free_entry_buffers (entry);
|
free_entry_buffers (entry);
|
||||||
if (entry->probability == -1) {
|
if (entry->probability == 0 && entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - no chance of being the right plugin",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
} else if (entry->probability >= typefind->max_probability) {
|
} else if (entry->probability >= typefind->max_probability) {
|
||||||
/* wooha, got caps */
|
/* wooha, got caps */
|
||||||
|
@ -464,7 +483,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
guint probability = entry->probability;
|
guint probability = entry->probability;
|
||||||
|
|
||||||
gst_caps_ref (found_caps);
|
gst_caps_ref (found_caps);
|
||||||
GST_LOG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
GST_DEBUG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
||||||
while (walk) {
|
while (walk) {
|
||||||
free_entry ((TypeFindEntry *) walk->data);
|
free_entry ((TypeFindEntry *) walk->data);
|
||||||
|
@ -477,7 +496,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
}
|
}
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], probability, found_caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, probability, found_caps);
|
||||||
gst_caps_unref (found_caps);
|
gst_caps_unref (found_caps);
|
||||||
} else {
|
} else {
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
|
@ -486,7 +505,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
g_list_free (entries);
|
g_list_free (entries);
|
||||||
/* we may now already have caps or we might be left without functions to try */
|
/* we may now already have caps or we might be left without functions to try */
|
||||||
if (typefind->caps) {
|
if (typefind->caps) {
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
} else if (typefind->possibilities == NULL) {
|
} else if (typefind->possibilities == NULL) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
||||||
} else {
|
} else {
|
||||||
|
@ -499,13 +518,15 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size > 0) {
|
if (entry->requested_size > 0) {
|
||||||
/* FIXME: need heuristic to find out if we should seek */
|
/* FIXME: need heuristic to find out if we should seek */
|
||||||
GstEvent *event = gst_event_new_seek (entry->requested_offset < 0 ?
|
GstEvent *event = gst_event_new_seek (GST_FORMAT_BYTES | (entry->requested_offset > 0 ?
|
||||||
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END, entry->requested_offset);
|
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END), entry->requested_offset);
|
||||||
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
||||||
/* done seeking */
|
/* done seeking */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* impossible to seek */
|
/* impossible to seek */
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was reset - couldn't seek to %"G_GINT64_FORMAT,
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->requested_offset);
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
}
|
}
|
||||||
|
@ -518,6 +539,8 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) walk->data;
|
entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - higher possibilities available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
||||||
}
|
}
|
||||||
|
@ -526,11 +549,11 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) typefind->possibilities->data;
|
entry = (TypeFindEntry *) typefind->possibilities->data;
|
||||||
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], entry->probability, entry->caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, entry->probability, entry->caps);
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -552,7 +575,7 @@ gst_type_find_element_change_state (GstElement *element)
|
||||||
start_typefinding (typefind);
|
start_typefinding (typefind);
|
||||||
break;
|
break;
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
stop_typefinding (typefind, FALSE);
|
stop_typefinding (typefind);
|
||||||
gst_caps_replace (&typefind->caps, NULL);
|
gst_caps_replace (&typefind->caps, NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -142,7 +142,7 @@ gst_type_find_element_have_type (GstTypeFindElement *typefind, guint probability
|
||||||
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
||||||
g_free (caps_str);
|
g_free (caps_str);
|
||||||
gst_caps_replace (&typefind->caps, caps);
|
gst_caps_replace (&typefind->caps, caps);
|
||||||
if (!gst_pad_try_set_caps (typefind->src, caps)) {
|
if (gst_pad_try_set_caps (typefind->src, caps) < GST_PAD_LINK_OK) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,8 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
||||||
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
||||||
|
|
||||||
|
typefind_class->have_type = gst_type_find_element_have_type;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_CAPS,
|
g_object_class_install_property (gobject_class, ARG_CAPS,
|
||||||
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
||||||
GST_TYPE_CAPS, G_PARAM_READABLE));
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
||||||
|
@ -180,8 +182,6 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
G_TYPE_UINT, GST_TYPE_CAPS);
|
G_TYPE_UINT, GST_TYPE_CAPS);
|
||||||
|
|
||||||
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
||||||
|
|
||||||
typefind_class->have_type = gst_type_find_element_have_type;
|
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
||||||
|
@ -216,6 +216,8 @@ gst_type_find_element_dispose (GObject *object)
|
||||||
g_object_unref (typefind->store);
|
g_object_unref (typefind->store);
|
||||||
typefind->store = NULL;
|
typefind->store = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
||||||
|
@ -271,21 +273,27 @@ start_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
g_assert (typefind->caps == NULL);
|
g_assert (typefind->caps == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "starting typefinding");
|
||||||
typefind->mode = MODE_TYPEFIND;
|
typefind->mode = MODE_TYPEFIND;
|
||||||
|
typefind->stream_length_available = TRUE;
|
||||||
|
typefind->stream_length = 0;
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
stop_typefinding (GstTypeFindElement *typefind, gboolean push_cached_buffers)
|
stop_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
/* stop all typefinding and set mode back to normal */
|
/* stop all typefinding and set mode back to normal */
|
||||||
|
gboolean push_cached_buffers = gst_element_get_state (GST_ELEMENT (typefind)) == GST_STATE_PLAYING;
|
||||||
|
|
||||||
g_assert (typefind->possibilities == NULL);
|
g_assert (typefind->possibilities == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "stopping typefinding%s", push_cached_buffers ? " and pushing cached buffers" : "");
|
||||||
typefind->mode = MODE_NORMAL;
|
typefind->mode = MODE_NORMAL;
|
||||||
|
|
||||||
if (push_cached_buffers) {
|
if (push_cached_buffers) {
|
||||||
|
GstBuffer *buffer;
|
||||||
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
||||||
GstBuffer *buffer = gst_buffer_store_get_buffer (typefind->store, 0, size);
|
if (size && (buffer = gst_buffer_store_get_buffer (typefind->store, 0, size))) {
|
||||||
if (buffer) {
|
gst_pad_push (typefind->src, GST_DATA (buffer));
|
||||||
gst_pad_push (typefind->sink, GST_DATA (buffer));
|
|
||||||
} else {
|
} else {
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
@ -332,17 +340,24 @@ find_element_get_length (gpointer data)
|
||||||
GstTypeFindElement *typefind = entry->self;
|
GstTypeFindElement *typefind = entry->self;
|
||||||
GstFormat format = GST_FORMAT_BYTES;
|
GstFormat format = GST_FORMAT_BYTES;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length ()",
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but we know it's not available",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
if (!typefind->stream_length_available)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (entry->self->stream_length == 0) {
|
if (entry->self->stream_length == 0) {
|
||||||
typefind->stream_length_available = gst_pad_query (entry->self->sink, GST_QUERY_TOTAL,
|
typefind->stream_length_available = gst_pad_query (GST_PAD_PEER (entry->self->sink), GST_QUERY_TOTAL,
|
||||||
&format, &entry->self->stream_length);
|
&format, &entry->self->stream_length);
|
||||||
if (format != GST_FORMAT_BYTES)
|
if (format != GST_FORMAT_BYTES)
|
||||||
typefind->stream_length_available = FALSE;
|
typefind->stream_length_available = FALSE;
|
||||||
if (!typefind->stream_length_available)
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but it's not available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () and it's %"G_GUINT64_FORMAT" bytes",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->self->stream_length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry->self->stream_length;
|
return entry->self->stream_length;
|
||||||
|
@ -364,7 +379,7 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
} else {
|
} else {
|
||||||
buf = gst_buffer_store_get_buffer (entry->self->store, length - offset, size);
|
buf = gst_buffer_store_get_buffer (entry->self->store, length + offset, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +388,8 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
return GST_BUFFER_DATA (buf);
|
return GST_BUFFER_DATA (buf);
|
||||||
} else {
|
} else {
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "setting requested peek (%"G_GINT64_FORMAT", %u) on '%s'",
|
||||||
|
offset, size, GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
entry->requested_offset = offset;
|
entry->requested_offset = offset;
|
||||||
entry->requested_size = size;
|
entry->requested_size = size;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +456,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
|
|
||||||
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
||||||
entry->self = typefind;
|
entry->self = typefind;
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
all_factories = g_list_next (all_factories);
|
all_factories = g_list_next (all_factories);
|
||||||
}
|
}
|
||||||
|
@ -451,12 +468,14 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
while (walk) {
|
while (walk) {
|
||||||
find.data = entry = (TypeFindEntry *) walk->data;
|
find.data = entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
gst_type_find_factory_call_function (entry->factory, &find);
|
gst_type_find_factory_call_function (entry->factory, &find);
|
||||||
free_entry_buffers (entry);
|
free_entry_buffers (entry);
|
||||||
if (entry->probability == -1) {
|
if (entry->probability == 0 && entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - no chance of being the right plugin",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
} else if (entry->probability >= typefind->max_probability) {
|
} else if (entry->probability >= typefind->max_probability) {
|
||||||
/* wooha, got caps */
|
/* wooha, got caps */
|
||||||
|
@ -464,7 +483,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
guint probability = entry->probability;
|
guint probability = entry->probability;
|
||||||
|
|
||||||
gst_caps_ref (found_caps);
|
gst_caps_ref (found_caps);
|
||||||
GST_LOG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
GST_DEBUG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
||||||
while (walk) {
|
while (walk) {
|
||||||
free_entry ((TypeFindEntry *) walk->data);
|
free_entry ((TypeFindEntry *) walk->data);
|
||||||
|
@ -477,7 +496,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
}
|
}
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], probability, found_caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, probability, found_caps);
|
||||||
gst_caps_unref (found_caps);
|
gst_caps_unref (found_caps);
|
||||||
} else {
|
} else {
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
|
@ -486,7 +505,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
g_list_free (entries);
|
g_list_free (entries);
|
||||||
/* we may now already have caps or we might be left without functions to try */
|
/* we may now already have caps or we might be left without functions to try */
|
||||||
if (typefind->caps) {
|
if (typefind->caps) {
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
} else if (typefind->possibilities == NULL) {
|
} else if (typefind->possibilities == NULL) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
||||||
} else {
|
} else {
|
||||||
|
@ -499,13 +518,15 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size > 0) {
|
if (entry->requested_size > 0) {
|
||||||
/* FIXME: need heuristic to find out if we should seek */
|
/* FIXME: need heuristic to find out if we should seek */
|
||||||
GstEvent *event = gst_event_new_seek (entry->requested_offset < 0 ?
|
GstEvent *event = gst_event_new_seek (GST_FORMAT_BYTES | (entry->requested_offset > 0 ?
|
||||||
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END, entry->requested_offset);
|
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END), entry->requested_offset);
|
||||||
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
||||||
/* done seeking */
|
/* done seeking */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* impossible to seek */
|
/* impossible to seek */
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was reset - couldn't seek to %"G_GINT64_FORMAT,
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->requested_offset);
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
}
|
}
|
||||||
|
@ -518,6 +539,8 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) walk->data;
|
entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - higher possibilities available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
||||||
}
|
}
|
||||||
|
@ -526,11 +549,11 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) typefind->possibilities->data;
|
entry = (TypeFindEntry *) typefind->possibilities->data;
|
||||||
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], entry->probability, entry->caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, entry->probability, entry->caps);
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -552,7 +575,7 @@ gst_type_find_element_change_state (GstElement *element)
|
||||||
start_typefinding (typefind);
|
start_typefinding (typefind);
|
||||||
break;
|
break;
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
stop_typefinding (typefind, FALSE);
|
stop_typefinding (typefind);
|
||||||
gst_caps_replace (&typefind->caps, NULL);
|
gst_caps_replace (&typefind->caps, NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2545,7 +2545,7 @@ gst_element_dispose (GObject *object)
|
||||||
GList *pads;
|
GList *pads;
|
||||||
GstPad *pad;
|
GstPad *pad;
|
||||||
|
|
||||||
GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, element, "dispose");
|
GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "dispose");
|
||||||
|
|
||||||
gst_element_set_state (element, GST_STATE_NULL);
|
gst_element_set_state (element, GST_STATE_NULL);
|
||||||
|
|
||||||
|
|
11
gst/gstpad.c
11
gst/gstpad.c
|
@ -2310,14 +2310,19 @@ gst_pad_push (GstPad *pad, GstData *data)
|
||||||
{
|
{
|
||||||
GstRealPad *peer;
|
GstRealPad *peer;
|
||||||
|
|
||||||
g_assert (GST_IS_PAD (pad));
|
g_return_if_fail (GST_IS_PAD (pad));
|
||||||
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pushing");
|
|
||||||
|
|
||||||
g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
|
g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
|
||||||
|
|
||||||
if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
|
if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!GST_PAD_IS_LINKED (pad)) {
|
||||||
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "not pushing data %p as pad is unconnected", data);
|
||||||
|
gst_data_unref (data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pushing");
|
||||||
peer = GST_RPAD_PEER (pad);
|
peer = GST_RPAD_PEER (pad);
|
||||||
|
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
|
|
|
@ -135,9 +135,13 @@ gst_buffer_store_add_buffer_func (GstBufferStore *store, GstBuffer *buffer)
|
||||||
store->buffers &&
|
store->buffers &&
|
||||||
GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
||||||
/* we assumed valid offsets, but suddenly they are not anymore */
|
/* we assumed valid offsets, but suddenly they are not anymore */
|
||||||
|
GST_DEBUG_OBJECT (store, "attempting to add buffer %p with invalid offset to store with valid offset, abort",
|
||||||
|
buffer);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (store->buffers && !GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
} else if (store->buffers && !GST_BUFFER_OFFSET_IS_VALID (store->buffers->data)) {
|
||||||
/* the starting buffer had an invalid offset, in that case we assume continuous buffers */
|
/* the starting buffer had an invalid offset, in that case we assume continuous buffers */
|
||||||
|
GST_LOG_OBJECT (store, "adding buffer %p with invalid offset and size %u",
|
||||||
|
buffer, GST_BUFFER_SIZE (buffer));
|
||||||
gst_data_ref (GST_DATA (buffer));
|
gst_data_ref (GST_DATA (buffer));
|
||||||
g_list_append (store->buffers, buffer);
|
g_list_append (store->buffers, buffer);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -147,6 +151,8 @@ gst_buffer_store_add_buffer_func (GstBufferStore *store, GstBuffer *buffer)
|
||||||
GstBuffer *current;
|
GstBuffer *current;
|
||||||
|
|
||||||
g_assert (GST_BUFFER_OFFSET_IS_VALID (buffer));
|
g_assert (GST_BUFFER_OFFSET_IS_VALID (buffer));
|
||||||
|
GST_LOG_OBJECT (store, "attempting to add buffer %p with offset %"G_GUINT64_FORMAT" and size %u",
|
||||||
|
buffer, GST_BUFFER_OFFSET (buffer), GST_BUFFER_SIZE (buffer));
|
||||||
/* we keep a sorted list of non-overlapping buffers */
|
/* we keep a sorted list of non-overlapping buffers */
|
||||||
walk = store->buffers;
|
walk = store->buffers;
|
||||||
while (walk) {
|
while (walk) {
|
||||||
|
@ -163,8 +169,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore *store, GstBuffer *buffer)
|
||||||
} else {
|
} else {
|
||||||
needed_size = GST_BUFFER_SIZE (buffer);
|
needed_size = GST_BUFFER_SIZE (buffer);
|
||||||
}
|
}
|
||||||
if (needed_size <= GST_BUFFER_OFFSET (current)) {
|
if (needed_size <= GST_BUFFER_SIZE (current)) {
|
||||||
g_assert (needed_size == GST_BUFFER_OFFSET (current)); /* we have no overlapping data */
|
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
} else {
|
} else {
|
||||||
if (needed_size < GST_BUFFER_SIZE (buffer)) {
|
if (needed_size < GST_BUFFER_SIZE (buffer)) {
|
||||||
|
@ -323,7 +328,7 @@ gst_buffer_store_get_buffer (GstBufferStore *store, guint64 offset, guint size)
|
||||||
gst_data_ref (GST_DATA (ret));
|
gst_data_ref (GST_DATA (ret));
|
||||||
break;
|
break;
|
||||||
} else if (cur_offset + GST_BUFFER_SIZE (current) > offset) {
|
} else if (cur_offset + GST_BUFFER_SIZE (current) > offset) {
|
||||||
if (cur_offset + GST_BUFFER_SIZE (current) <= offset + size) {
|
if (cur_offset + GST_BUFFER_SIZE (current) >= offset + size) {
|
||||||
ret = gst_buffer_create_sub (current, offset - cur_offset, size);
|
ret = gst_buffer_create_sub (current, offset - cur_offset, size);
|
||||||
GST_LOG_OBJECT (store, "created subbuffer %p from buffer %p for offset %llu and size %u",
|
GST_LOG_OBJECT (store, "created subbuffer %p from buffer %p for offset %llu and size %u",
|
||||||
ret, current, offset, size);
|
ret, current, offset, size);
|
||||||
|
@ -396,11 +401,11 @@ gst_buffer_store_get_size (GstBufferStore *store, guint64 offset)
|
||||||
cur_offset = 0;
|
cur_offset = 0;
|
||||||
}
|
}
|
||||||
while (walk) {
|
while (walk) {
|
||||||
if (have_offset &&
|
current = GST_BUFFER (walk->data);
|
||||||
|
if (have_offset && counting &&
|
||||||
cur_offset + GST_BUFFER_SIZE (current) != GST_BUFFER_OFFSET (walk->data)) {
|
cur_offset + GST_BUFFER_SIZE (current) != GST_BUFFER_OFFSET (walk->data)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current = GST_BUFFER (walk->data);
|
|
||||||
if (have_offset) {
|
if (have_offset) {
|
||||||
cur_offset = GST_BUFFER_OFFSET (current);
|
cur_offset = GST_BUFFER_OFFSET (current);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ plugin_init (GModule *module, GstPlugin *plugin)
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_shaper_debug, "shaper", 0, "shaper element");
|
GST_DEBUG_CATEGORY_INIT (gst_shaper_debug, "shaper", 0, "shaper element");
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_statistics_debug, "statistics", 0, "statistics element");
|
GST_DEBUG_CATEGORY_INIT (gst_statistics_debug, "statistics", 0, "statistics element");
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_tee_debug, "tee", 0, "tee element");
|
GST_DEBUG_CATEGORY_INIT (gst_tee_debug, "tee", 0, "tee element");
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_type_find_element_debug, "typefind", 0, "typefind element");
|
GST_DEBUG_CATEGORY_INIT (gst_type_find_element_debug, "typefind", GST_DEBUG_BG_YELLOW | GST_DEBUG_FG_GREEN, "typefind element");
|
||||||
|
|
||||||
while (_elements[i].name) {
|
while (_elements[i].name) {
|
||||||
factory = gst_element_factory_new (_elements[i].name,
|
factory = gst_element_factory_new (_elements[i].name,
|
||||||
|
|
|
@ -142,7 +142,7 @@ gst_type_find_element_have_type (GstTypeFindElement *typefind, guint probability
|
||||||
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
||||||
g_free (caps_str);
|
g_free (caps_str);
|
||||||
gst_caps_replace (&typefind->caps, caps);
|
gst_caps_replace (&typefind->caps, caps);
|
||||||
if (!gst_pad_try_set_caps (typefind->src, caps)) {
|
if (gst_pad_try_set_caps (typefind->src, caps) < GST_PAD_LINK_OK) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,8 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
||||||
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
||||||
|
|
||||||
|
typefind_class->have_type = gst_type_find_element_have_type;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_CAPS,
|
g_object_class_install_property (gobject_class, ARG_CAPS,
|
||||||
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
||||||
GST_TYPE_CAPS, G_PARAM_READABLE));
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
||||||
|
@ -180,8 +182,6 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
G_TYPE_UINT, GST_TYPE_CAPS);
|
G_TYPE_UINT, GST_TYPE_CAPS);
|
||||||
|
|
||||||
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
||||||
|
|
||||||
typefind_class->have_type = gst_type_find_element_have_type;
|
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
||||||
|
@ -216,6 +216,8 @@ gst_type_find_element_dispose (GObject *object)
|
||||||
g_object_unref (typefind->store);
|
g_object_unref (typefind->store);
|
||||||
typefind->store = NULL;
|
typefind->store = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
||||||
|
@ -271,21 +273,27 @@ start_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
g_assert (typefind->caps == NULL);
|
g_assert (typefind->caps == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "starting typefinding");
|
||||||
typefind->mode = MODE_TYPEFIND;
|
typefind->mode = MODE_TYPEFIND;
|
||||||
|
typefind->stream_length_available = TRUE;
|
||||||
|
typefind->stream_length = 0;
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
stop_typefinding (GstTypeFindElement *typefind, gboolean push_cached_buffers)
|
stop_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
/* stop all typefinding and set mode back to normal */
|
/* stop all typefinding and set mode back to normal */
|
||||||
|
gboolean push_cached_buffers = gst_element_get_state (GST_ELEMENT (typefind)) == GST_STATE_PLAYING;
|
||||||
|
|
||||||
g_assert (typefind->possibilities == NULL);
|
g_assert (typefind->possibilities == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "stopping typefinding%s", push_cached_buffers ? " and pushing cached buffers" : "");
|
||||||
typefind->mode = MODE_NORMAL;
|
typefind->mode = MODE_NORMAL;
|
||||||
|
|
||||||
if (push_cached_buffers) {
|
if (push_cached_buffers) {
|
||||||
|
GstBuffer *buffer;
|
||||||
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
||||||
GstBuffer *buffer = gst_buffer_store_get_buffer (typefind->store, 0, size);
|
if (size && (buffer = gst_buffer_store_get_buffer (typefind->store, 0, size))) {
|
||||||
if (buffer) {
|
gst_pad_push (typefind->src, GST_DATA (buffer));
|
||||||
gst_pad_push (typefind->sink, GST_DATA (buffer));
|
|
||||||
} else {
|
} else {
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
@ -332,17 +340,24 @@ find_element_get_length (gpointer data)
|
||||||
GstTypeFindElement *typefind = entry->self;
|
GstTypeFindElement *typefind = entry->self;
|
||||||
GstFormat format = GST_FORMAT_BYTES;
|
GstFormat format = GST_FORMAT_BYTES;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length ()",
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but we know it's not available",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
if (!typefind->stream_length_available)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (entry->self->stream_length == 0) {
|
if (entry->self->stream_length == 0) {
|
||||||
typefind->stream_length_available = gst_pad_query (entry->self->sink, GST_QUERY_TOTAL,
|
typefind->stream_length_available = gst_pad_query (GST_PAD_PEER (entry->self->sink), GST_QUERY_TOTAL,
|
||||||
&format, &entry->self->stream_length);
|
&format, &entry->self->stream_length);
|
||||||
if (format != GST_FORMAT_BYTES)
|
if (format != GST_FORMAT_BYTES)
|
||||||
typefind->stream_length_available = FALSE;
|
typefind->stream_length_available = FALSE;
|
||||||
if (!typefind->stream_length_available)
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but it's not available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () and it's %"G_GUINT64_FORMAT" bytes",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->self->stream_length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry->self->stream_length;
|
return entry->self->stream_length;
|
||||||
|
@ -364,7 +379,7 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
} else {
|
} else {
|
||||||
buf = gst_buffer_store_get_buffer (entry->self->store, length - offset, size);
|
buf = gst_buffer_store_get_buffer (entry->self->store, length + offset, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +388,8 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
return GST_BUFFER_DATA (buf);
|
return GST_BUFFER_DATA (buf);
|
||||||
} else {
|
} else {
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "setting requested peek (%"G_GINT64_FORMAT", %u) on '%s'",
|
||||||
|
offset, size, GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
entry->requested_offset = offset;
|
entry->requested_offset = offset;
|
||||||
entry->requested_size = size;
|
entry->requested_size = size;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +456,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
|
|
||||||
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
||||||
entry->self = typefind;
|
entry->self = typefind;
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
all_factories = g_list_next (all_factories);
|
all_factories = g_list_next (all_factories);
|
||||||
}
|
}
|
||||||
|
@ -451,12 +468,14 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
while (walk) {
|
while (walk) {
|
||||||
find.data = entry = (TypeFindEntry *) walk->data;
|
find.data = entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
gst_type_find_factory_call_function (entry->factory, &find);
|
gst_type_find_factory_call_function (entry->factory, &find);
|
||||||
free_entry_buffers (entry);
|
free_entry_buffers (entry);
|
||||||
if (entry->probability == -1) {
|
if (entry->probability == 0 && entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - no chance of being the right plugin",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
} else if (entry->probability >= typefind->max_probability) {
|
} else if (entry->probability >= typefind->max_probability) {
|
||||||
/* wooha, got caps */
|
/* wooha, got caps */
|
||||||
|
@ -464,7 +483,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
guint probability = entry->probability;
|
guint probability = entry->probability;
|
||||||
|
|
||||||
gst_caps_ref (found_caps);
|
gst_caps_ref (found_caps);
|
||||||
GST_LOG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
GST_DEBUG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
||||||
while (walk) {
|
while (walk) {
|
||||||
free_entry ((TypeFindEntry *) walk->data);
|
free_entry ((TypeFindEntry *) walk->data);
|
||||||
|
@ -477,7 +496,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
}
|
}
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], probability, found_caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, probability, found_caps);
|
||||||
gst_caps_unref (found_caps);
|
gst_caps_unref (found_caps);
|
||||||
} else {
|
} else {
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
|
@ -486,7 +505,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
g_list_free (entries);
|
g_list_free (entries);
|
||||||
/* we may now already have caps or we might be left without functions to try */
|
/* we may now already have caps or we might be left without functions to try */
|
||||||
if (typefind->caps) {
|
if (typefind->caps) {
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
} else if (typefind->possibilities == NULL) {
|
} else if (typefind->possibilities == NULL) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
||||||
} else {
|
} else {
|
||||||
|
@ -499,13 +518,15 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size > 0) {
|
if (entry->requested_size > 0) {
|
||||||
/* FIXME: need heuristic to find out if we should seek */
|
/* FIXME: need heuristic to find out if we should seek */
|
||||||
GstEvent *event = gst_event_new_seek (entry->requested_offset < 0 ?
|
GstEvent *event = gst_event_new_seek (GST_FORMAT_BYTES | (entry->requested_offset > 0 ?
|
||||||
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END, entry->requested_offset);
|
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END), entry->requested_offset);
|
||||||
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
||||||
/* done seeking */
|
/* done seeking */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* impossible to seek */
|
/* impossible to seek */
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was reset - couldn't seek to %"G_GINT64_FORMAT,
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->requested_offset);
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
}
|
}
|
||||||
|
@ -518,6 +539,8 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) walk->data;
|
entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - higher possibilities available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
||||||
}
|
}
|
||||||
|
@ -526,11 +549,11 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) typefind->possibilities->data;
|
entry = (TypeFindEntry *) typefind->possibilities->data;
|
||||||
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], entry->probability, entry->caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, entry->probability, entry->caps);
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -552,7 +575,7 @@ gst_type_find_element_change_state (GstElement *element)
|
||||||
start_typefinding (typefind);
|
start_typefinding (typefind);
|
||||||
break;
|
break;
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
stop_typefinding (typefind, FALSE);
|
stop_typefinding (typefind);
|
||||||
gst_caps_replace (&typefind->caps, NULL);
|
gst_caps_replace (&typefind->caps, NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -142,7 +142,7 @@ gst_type_find_element_have_type (GstTypeFindElement *typefind, guint probability
|
||||||
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
GST_INFO_OBJECT (typefind, "found caps %s", caps_str);
|
||||||
g_free (caps_str);
|
g_free (caps_str);
|
||||||
gst_caps_replace (&typefind->caps, caps);
|
gst_caps_replace (&typefind->caps, caps);
|
||||||
if (!gst_pad_try_set_caps (typefind->src, caps)) {
|
if (gst_pad_try_set_caps (typefind->src, caps) < GST_PAD_LINK_OK) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
gst_element_error (GST_ELEMENT (typefind), "could not set caps on source pad");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,8 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_element_get_property);
|
||||||
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_type_find_element_dispose);
|
||||||
|
|
||||||
|
typefind_class->have_type = gst_type_find_element_have_type;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_CAPS,
|
g_object_class_install_property (gobject_class, ARG_CAPS,
|
||||||
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
g_param_spec_boxed ("caps", _("caps"), _("detected capabilities in stream"),
|
||||||
GST_TYPE_CAPS, G_PARAM_READABLE));
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
||||||
|
@ -180,8 +182,6 @@ gst_type_find_element_class_init (gpointer g_class, gpointer class_data)
|
||||||
G_TYPE_UINT, GST_TYPE_CAPS);
|
G_TYPE_UINT, GST_TYPE_CAPS);
|
||||||
|
|
||||||
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_element_change_state);
|
||||||
|
|
||||||
typefind_class->have_type = gst_type_find_element_have_type;
|
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
gst_type_find_element_init (GTypeInstance *instance, gpointer g_class)
|
||||||
|
@ -216,6 +216,8 @@ gst_type_find_element_dispose (GObject *object)
|
||||||
g_object_unref (typefind->store);
|
g_object_unref (typefind->store);
|
||||||
typefind->store = NULL;
|
typefind->store = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
gst_type_find_element_set_property (GObject *object, guint prop_id,
|
||||||
|
@ -271,21 +273,27 @@ start_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
g_assert (typefind->caps == NULL);
|
g_assert (typefind->caps == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "starting typefinding");
|
||||||
typefind->mode = MODE_TYPEFIND;
|
typefind->mode = MODE_TYPEFIND;
|
||||||
|
typefind->stream_length_available = TRUE;
|
||||||
|
typefind->stream_length = 0;
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
stop_typefinding (GstTypeFindElement *typefind, gboolean push_cached_buffers)
|
stop_typefinding (GstTypeFindElement *typefind)
|
||||||
{
|
{
|
||||||
/* stop all typefinding and set mode back to normal */
|
/* stop all typefinding and set mode back to normal */
|
||||||
|
gboolean push_cached_buffers = gst_element_get_state (GST_ELEMENT (typefind)) == GST_STATE_PLAYING;
|
||||||
|
|
||||||
g_assert (typefind->possibilities == NULL);
|
g_assert (typefind->possibilities == NULL);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (typefind, "stopping typefinding%s", push_cached_buffers ? " and pushing cached buffers" : "");
|
||||||
typefind->mode = MODE_NORMAL;
|
typefind->mode = MODE_NORMAL;
|
||||||
|
|
||||||
if (push_cached_buffers) {
|
if (push_cached_buffers) {
|
||||||
|
GstBuffer *buffer;
|
||||||
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
guint size = gst_buffer_store_get_size (typefind->store, 0);
|
||||||
GstBuffer *buffer = gst_buffer_store_get_buffer (typefind->store, 0, size);
|
if (size && (buffer = gst_buffer_store_get_buffer (typefind->store, 0, size))) {
|
||||||
if (buffer) {
|
gst_pad_push (typefind->src, GST_DATA (buffer));
|
||||||
gst_pad_push (typefind->sink, GST_DATA (buffer));
|
|
||||||
} else {
|
} else {
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
@ -332,17 +340,24 @@ find_element_get_length (gpointer data)
|
||||||
GstTypeFindElement *typefind = entry->self;
|
GstTypeFindElement *typefind = entry->self;
|
||||||
GstFormat format = GST_FORMAT_BYTES;
|
GstFormat format = GST_FORMAT_BYTES;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length ()",
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but we know it's not available",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
if (!typefind->stream_length_available)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (entry->self->stream_length == 0) {
|
if (entry->self->stream_length == 0) {
|
||||||
typefind->stream_length_available = gst_pad_query (entry->self->sink, GST_QUERY_TOTAL,
|
typefind->stream_length_available = gst_pad_query (GST_PAD_PEER (entry->self->sink), GST_QUERY_TOTAL,
|
||||||
&format, &entry->self->stream_length);
|
&format, &entry->self->stream_length);
|
||||||
if (format != GST_FORMAT_BYTES)
|
if (format != GST_FORMAT_BYTES)
|
||||||
typefind->stream_length_available = FALSE;
|
typefind->stream_length_available = FALSE;
|
||||||
if (!typefind->stream_length_available)
|
if (!typefind->stream_length_available) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () but it's not available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "'%s' called get_length () and it's %"G_GUINT64_FORMAT" bytes",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->self->stream_length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry->self->stream_length;
|
return entry->self->stream_length;
|
||||||
|
@ -364,7 +379,7 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
} else {
|
} else {
|
||||||
buf = gst_buffer_store_get_buffer (entry->self->store, length - offset, size);
|
buf = gst_buffer_store_get_buffer (entry->self->store, length + offset, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +388,8 @@ find_peek (gpointer data, gint64 offset, guint size)
|
||||||
return GST_BUFFER_DATA (buf);
|
return GST_BUFFER_DATA (buf);
|
||||||
} else {
|
} else {
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_DEBUG_OBJECT (entry->self, "setting requested peek (%"G_GINT64_FORMAT", %u) on '%s'",
|
||||||
|
offset, size, GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
entry->requested_offset = offset;
|
entry->requested_offset = offset;
|
||||||
entry->requested_size = size;
|
entry->requested_size = size;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +456,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
|
|
||||||
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
entry->factory = GST_TYPE_FIND_FACTORY (all_factories->data);
|
||||||
entry->self = typefind;
|
entry->self = typefind;
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
all_factories = g_list_next (all_factories);
|
all_factories = g_list_next (all_factories);
|
||||||
}
|
}
|
||||||
|
@ -451,12 +468,14 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
while (walk) {
|
while (walk) {
|
||||||
find.data = entry = (TypeFindEntry *) walk->data;
|
find.data = entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
entry->probability = -1;
|
entry->probability = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
gst_type_find_factory_call_function (entry->factory, &find);
|
gst_type_find_factory_call_function (entry->factory, &find);
|
||||||
free_entry_buffers (entry);
|
free_entry_buffers (entry);
|
||||||
if (entry->probability == -1) {
|
if (entry->probability == 0 && entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - no chance of being the right plugin",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
} else if (entry->probability >= typefind->max_probability) {
|
} else if (entry->probability >= typefind->max_probability) {
|
||||||
/* wooha, got caps */
|
/* wooha, got caps */
|
||||||
|
@ -464,7 +483,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
guint probability = entry->probability;
|
guint probability = entry->probability;
|
||||||
|
|
||||||
gst_caps_ref (found_caps);
|
gst_caps_ref (found_caps);
|
||||||
GST_LOG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
GST_DEBUG_OBJECT (typefind, "'%s' returned %u/%u probability, using it NOW",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), probability, typefind->max_probability);
|
||||||
while (walk) {
|
while (walk) {
|
||||||
free_entry ((TypeFindEntry *) walk->data);
|
free_entry ((TypeFindEntry *) walk->data);
|
||||||
|
@ -477,7 +496,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
}
|
}
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], probability, found_caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, probability, found_caps);
|
||||||
gst_caps_unref (found_caps);
|
gst_caps_unref (found_caps);
|
||||||
} else {
|
} else {
|
||||||
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
typefind->possibilities = g_list_prepend (typefind->possibilities, entry);
|
||||||
|
@ -486,7 +505,7 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
g_list_free (entries);
|
g_list_free (entries);
|
||||||
/* we may now already have caps or we might be left without functions to try */
|
/* we may now already have caps or we might be left without functions to try */
|
||||||
if (typefind->caps) {
|
if (typefind->caps) {
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
} else if (typefind->possibilities == NULL) {
|
} else if (typefind->possibilities == NULL) {
|
||||||
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
|
||||||
} else {
|
} else {
|
||||||
|
@ -499,13 +518,15 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size > 0) {
|
if (entry->requested_size > 0) {
|
||||||
/* FIXME: need heuristic to find out if we should seek */
|
/* FIXME: need heuristic to find out if we should seek */
|
||||||
GstEvent *event = gst_event_new_seek (entry->requested_offset < 0 ?
|
GstEvent *event = gst_event_new_seek (GST_FORMAT_BYTES | (entry->requested_offset > 0 ?
|
||||||
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END, entry->requested_offset);
|
GST_SEEK_METHOD_SET : GST_SEEK_METHOD_END), entry->requested_offset);
|
||||||
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
if (gst_pad_send_event (GST_PAD_PEER (typefind->sink), event)) {
|
||||||
/* done seeking */
|
/* done seeking */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* impossible to seek */
|
/* impossible to seek */
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was reset - couldn't seek to %"G_GINT64_FORMAT,
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->requested_offset);
|
||||||
entry->requested_size = 0;
|
entry->requested_size = 0;
|
||||||
entry->requested_offset = 0;
|
entry->requested_offset = 0;
|
||||||
}
|
}
|
||||||
|
@ -518,6 +539,8 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) walk->data;
|
entry = (TypeFindEntry *) walk->data;
|
||||||
walk = g_list_next (walk);
|
walk = g_list_next (walk);
|
||||||
if (entry->requested_size == 0) {
|
if (entry->requested_size == 0) {
|
||||||
|
GST_LOG_OBJECT (typefind, "'%s' was removed - higher possibilities available",
|
||||||
|
GST_PLUGIN_FEATURE_NAME (entry->factory));
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
typefind->possibilities = g_list_delete_link (typefind->possibilities, cur);
|
||||||
}
|
}
|
||||||
|
@ -526,11 +549,11 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
|
||||||
entry = (TypeFindEntry *) typefind->possibilities->data;
|
entry = (TypeFindEntry *) typefind->possibilities->data;
|
||||||
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
GST_LOG_OBJECT (typefind, "'%s' is the only typefind left, using it now (probability %u)",
|
||||||
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->probability);
|
||||||
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], entry->probability, entry->caps);
|
g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, entry->probability, entry->caps);
|
||||||
free_entry (entry);
|
free_entry (entry);
|
||||||
g_list_free (typefind->possibilities);
|
g_list_free (typefind->possibilities);
|
||||||
typefind->possibilities = NULL;
|
typefind->possibilities = NULL;
|
||||||
stop_typefinding (typefind, TRUE);
|
stop_typefinding (typefind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -552,7 +575,7 @@ gst_type_find_element_change_state (GstElement *element)
|
||||||
start_typefinding (typefind);
|
start_typefinding (typefind);
|
||||||
break;
|
break;
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
stop_typefinding (typefind, FALSE);
|
stop_typefinding (typefind);
|
||||||
gst_caps_replace (&typefind->caps, NULL);
|
gst_caps_replace (&typefind->caps, NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue