+2005-07-15 Andy Wingo <wingo@pobox.com>
+
+ * tools/gst-typefind.c: Update, add copyright block.
+
+ * gst/base/gstbasesrc.c (gst_base_src_default_negotiate):
+ Normalize and truncate caps before fixation.
+
+ * gst/gstcaps.h:
+ * gst/gstcaps.c (gst_caps_truncate): New function, destructively
+ discards all but the first structure from its argument.
+
2005-07-15 Wim Taymans <wim@fluendo.com>
* gst/base/gstbasetransform.c: (gst_base_transform_init),
pipeline</ulink> and Microsoft's DirectShow for some background.
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### FUNCTION gst_init ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstBaseSink ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstBaseSrc ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstBaseTransform ##### -->
<para>
@parent_class:
@transform_caps:
@set_caps:
+@get_size:
@start:
@stop:
@event:
@transform:
+@transform_ip:
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstBin ##### -->
<para>
#GstPad, #GstMiniObject
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstBuffer ##### -->
<para>
The basic structure of a buffer.
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstCaps ##### -->
<para>
#GstSystemClock
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstClock ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### MACRO GST_DISABLE_LOADSAVE_REGISTRY ##### -->
<para>
<!-- basic object functions -->
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstElement ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstElementDetails ##### -->
<para>
This struct is used to define public information about the element. It
#GstElement, #GstPlugin, #GstPluginFeature, #GstPadTemplate.
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstElementFactory ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### ENUM GstCoreError ##### -->
<para>
@GST_STREAM_ERROR_DEMUX:
@GST_STREAM_ERROR_MUX:
@GST_STREAM_ERROR_FORMAT:
+@GST_STREAM_ERROR_STOPPED:
@GST_STREAM_ERROR_NUM_ERRORS:
<!-- ##### MACRO GST_CORE_ERROR ##### -->
#GstPad, #GstElement
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstEvent ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstFakeSink ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstFakeSrc ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstFileSink ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstFileSrc ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### USER_FUNCTION GstFilterFunc ##### -->
<para>
#GstPad, #GstElement
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### ENUM GstFormat ##### -->
<para>
Standard predefined formats
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstGhostPad ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstImplementsInterface ##### -->
<para>
#GstIndexFactory
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstIndex ##### -->
<para>
#GstIndex
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstIndexFactory ##### -->
<para>
The GstIndexFactory object
and environment variables that affect the debugging output.
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### ENUM GstDebugLevel ##### -->
<para>
The level defines the importance of a debugging message. The more important a
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstIterator ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
#GstBuffer, #GstEvent, #GstData
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstMemChunk ##### -->
<para>
The memchunk structure
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstMiniObject ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstObject ##### -->
<para>
#GstPadTemplate, #GstElement, #GstEvent
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstPad ##### -->
<para>
#GstPad, #GstElementFactory
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstPadTemplate ##### -->
<para>
The padtemplate object.
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### FUNCTION gst_parse_error_quark ##### -->
<para>
#GstBin
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstPipeline ##### -->
<para>
#GstPluginFeature, #GstType, #GstAutoplug, #GstElementFactory
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### FUNCTION gst_plugin_error_quark ##### -->
<para>
Get the error quark
#GstPlugin
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstPluginFeature ##### -->
<para>
#GstPad, #GstElement
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### ENUM GstQueryType ##### -->
<para>
Standard predefined Query types
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstQueue ##### -->
<para>
#GstPlugin, #GstPluginFeature
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
GstRegistry
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### FUNCTION gst_registry_pool_list ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstScheduler ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstSchedulerFactory ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstStructure ##### -->
<para>
#GstClock
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstSystemClock ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### TYPEDEF GstTagList ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstTagSetter ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstTrace ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstTrashStack ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstTypeFind ##### -->
<para>
<link linkend="gstreamer-Writing-typefind-functions">Writing typefind functions</link>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstTypeFindFactory ##### -->
<para>
Object that stores information about a typefind function
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### ENUM GstElementState ##### -->
<para>
These contants describe the state a #GstElement is in and transition scheduled for the #GstElement (the pending state).
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstURIHandler ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### ENUM GstURIType ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### FUNCTION gst_util_set_value_from_string ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### MACRO GST_MAKE_FOURCC ##### -->
<para>
will transform four characters into a host-endiannness guint32 fourcc:
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### MACRO GST_VERSION_MAJOR ##### -->
<para>
The major version of GStreamer at compile time
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstXML ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### FUNCTION gst_control_init ##### -->
<para>
#GstBuffer, #GstCaps, #GstEvent
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### ENUM GstDPHeaderFlag ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstDParam ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstDParamLinInterp ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstDParamManager ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstDParamSmooth ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT gst_getbits_t ##### -->
<para>
</para>
+<!-- ##### SECTION Stability_Level ##### -->
+
+
<!-- ##### STRUCT GstUnitConvert ##### -->
<para>
caps = thiscaps;
}
if (caps) {
- caps = gst_caps_make_writable (caps);
+ GstCaps *normalized;
+
+ normalized = gst_caps_make_writable (caps);
+ gst_caps_unref (caps);
+ caps = normalized;
+ gst_caps_truncate (caps);
+
gst_pad_fixate_caps (GST_BASE_SRC_PAD (basesrc), caps);
GST_DEBUG ("fixated to: %" GST_PTR_FORMAT, caps);
return newcaps;
}
+/**
+ * gst_caps_truncate:
+ * @caps: the @GstCaps to truncate
+ *
+ * Destructively discard all but the first structure from @caps. Useful when
+ * fixating. @caps must be writable.
+ */
+void
+gst_caps_truncate (GstCaps * caps)
+{
+ gint i;
+
+ g_return_if_fail (GST_IS_CAPS (caps));
+ g_return_if_fail (IS_WRITABLE (caps));
+
+ i = caps->structs->len - 1;
+
+ while (i > 0)
+ gst_caps_remove_structure (caps, i--);
+}
+
/**
* gst_caps_set_simple:
* @caps: the @GstCaps to set
GstStructure * gst_caps_get_structure (const GstCaps *caps,
int index);
GstCaps * gst_caps_copy_nth (const GstCaps * caps, gint nth);
+void gst_caps_truncate (GstCaps * caps);
void gst_caps_set_simple (GstCaps *caps,
char *field, ...);
void gst_caps_set_simple_valist (GstCaps *caps,
caps = thiscaps;
}
if (caps) {
- caps = gst_caps_make_writable (caps);
+ GstCaps *normalized;
+
+ normalized = gst_caps_make_writable (caps);
+ gst_caps_unref (caps);
+ caps = normalized;
+ gst_caps_truncate (caps);
+
gst_pad_fixate_caps (GST_BASE_SRC_PAD (basesrc), caps);
GST_DEBUG ("fixated to: %" GST_PTR_FORMAT, caps);
+/* GStreamer
+ * Copyright (C) 2003 Thomas Vander Stichele <thomas@apestaart.org>
+ * 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
+ * 2005 Andy Wingo <wingo@pobox.com>
+ *
+ * gst-typefind.c: Use GStreamer to find the type of a file
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <locale.h>
#include <gst/gst.h>
-/*
- * find the type of a media file and display it's properties
- **/
-
-gboolean FOUND = FALSE;
-gchar *filename = NULL;
-void
-gst_caps_print (const char *filename, const GstCaps * caps)
-{
- gchar *caps_str = gst_caps_to_string (caps);
+char *filename = NULL;
- g_print ("%s - %s\n", filename, caps_str);
- g_free (caps_str);
-}
void
have_type_handler (GstElement * typefind, guint probability,
const GstCaps * caps, gpointer unused)
{
- gst_caps_print (filename, caps);
- FOUND = TRUE;
+ gchar *caps_str;
+
+ caps_str = gst_caps_to_string (caps);
+ g_print ("%s - %s\n", filename, caps_str);
+ g_free (caps_str);
}
int
{
guint i = 1;
GstElement *pipeline;
- GstElement *source, *typefind;
+ GstElement *source, *typefind, *fakesink;
setlocale (LC_ALL, "");
}
pipeline = gst_pipeline_new (NULL);
+
+ /* don't hang too long trying to preroll */
+ g_object_set (pipeline, "play-timeout", (gint64) 0.25 * GST_SECOND, NULL);
+
source = gst_element_factory_make ("filesrc", "source");
g_assert (GST_IS_ELEMENT (source));
typefind = gst_element_factory_make ("typefind", "typefind");
g_assert (GST_IS_ELEMENT (typefind));
- gst_bin_add (GST_BIN (pipeline), source);
- gst_bin_add (GST_BIN (pipeline), typefind);
- gst_pad_link (gst_element_get_pad (source, "src"),
- gst_element_get_pad (typefind, "sink"));
+ fakesink = gst_element_factory_make ("fakesink", "fakesink");
+ g_assert (GST_IS_ELEMENT (typefind));
+
+ gst_bin_add_many (GST_BIN (pipeline), source, typefind, fakesink, NULL);
+ gst_element_link_many (source, typefind, fakesink, NULL);
+
g_signal_connect (G_OBJECT (typefind), "have-type",
G_CALLBACK (have_type_handler), NULL);
while (i < argc) {
- FOUND = FALSE;
- gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
+ GstElementStateReturn sret;
+
filename = argv[i];
g_object_set (source, "location", filename, NULL);
- /* set to play */
- gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
- while (!FOUND) {
- }
- if (!FOUND) {
+ /* typefind will only commit to PAUSED if it actually finds a type;
+ * otherwise the state change fails */
+ sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
+
+ if (sret != GST_STATE_SUCCESS)
g_print ("%s - No type found\n", argv[i]);
- }
+
+ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
+
i++;
}
- g_object_unref (pipeline);
+
+ gst_object_unref (pipeline);
return 0;
}