gstreamer_core/gst/gsttypefind.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer
       
     2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
       
     3  *
       
     4  * gsttypefind.c: typefinding subsystem
       
     5  *
       
     6  * This library is free software; you can redistribute it and/or
       
     7  * modify it under the terms of the GNU Library General Public
       
     8  * License as published by the Free Software Foundation; either
       
     9  * version 2 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This library is distributed in the hope that it will be useful,
       
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    14  * Library General Public License for more details.
       
    15  *
       
    16  * You should have received a copy of the GNU Library General Public
       
    17  * License along with this library; if not, write to the
       
    18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    19  * Boston, MA 02111-1307, USA.
       
    20  */
       
    21 
       
    22 /**
       
    23  * SECTION:gsttypefind
       
    24  * @short_description: Stream type detection
       
    25  *
       
    26  * The following functions allow you to detect the media type of an unknown
       
    27  * stream.
       
    28  *
       
    29  * Last reviewed on 2005-11-09 (0.9.4)
       
    30  */
       
    31 
       
    32 #include "gst_private.h"
       
    33 #include "gstinfo.h"
       
    34 #include "gsttypefind.h"
       
    35 #include "gstregistry.h"
       
    36 #include "gsttypefindfactory.h"
       
    37 
       
    38 GST_DEBUG_CATEGORY_EXTERN (type_find_debug);
       
    39 #define GST_CAT_DEFAULT type_find_debug
       
    40 
       
    41 #ifdef __SYMBIAN32__
       
    42 EXPORT_C
       
    43 #endif
       
    44 GType
       
    45 gst_type_find_get_type (void)
       
    46 {
       
    47   static GType typefind_type = 0;
       
    48 
       
    49   if (G_UNLIKELY (typefind_type == 0)) {
       
    50     typefind_type = g_pointer_type_register_static ("GstTypeFind");
       
    51   }
       
    52   return typefind_type;
       
    53 }
       
    54 
       
    55 /**
       
    56  * gst_type_find_register:
       
    57  * @plugin: A #GstPlugin, or NULL for a static typefind function (note that
       
    58  *    passing NULL only works in GStreamer 0.10.16 and later)
       
    59  * @name: The name for registering
       
    60  * @rank: The rank (or importance) of this typefind function
       
    61  * @func: The #GstTypeFindFunction to use
       
    62  * @extensions: Optional extensions that could belong to this type
       
    63  * @possible_caps: Optionally the caps that could be returned when typefinding
       
    64  *                 succeeds
       
    65  * @data: Optional user data. This user data must be available until the plugin
       
    66  *        is unloaded.
       
    67  * @data_notify: a #GDestroyNotify that will be called on @data when the plugin
       
    68  *        is unloaded.
       
    69  *
       
    70  * Registers a new typefind function to be used for typefinding. After
       
    71  * registering this function will be available for typefinding.
       
    72  * This function is typically called during an element's plugin initialization.
       
    73  *
       
    74  * Returns: TRUE on success, FALSE otherwise
       
    75  */
       
    76 #ifdef __SYMBIAN32__
       
    77 EXPORT_C
       
    78 #endif
       
    79 
       
    80 gboolean
       
    81 gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
       
    82     GstTypeFindFunction func, gchar ** extensions,
       
    83     const GstCaps * possible_caps, gpointer data, GDestroyNotify data_notify)
       
    84 {
       
    85   GstTypeFindFactory *factory;
       
    86 
       
    87   g_return_val_if_fail (name != NULL, FALSE);
       
    88   g_return_val_if_fail (func != NULL, FALSE);
       
    89 
       
    90   GST_INFO ("registering typefind function for %s", name);
       
    91 
       
    92   factory = g_object_new (GST_TYPE_TYPE_FIND_FACTORY, NULL);
       
    93   GST_DEBUG_OBJECT (factory, "using new typefind factory for %s", name);
       
    94   g_assert (GST_IS_TYPE_FIND_FACTORY (factory));
       
    95   gst_plugin_feature_set_name (GST_PLUGIN_FEATURE (factory), name);
       
    96 
       
    97   gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory), rank);
       
    98   if (factory->extensions)
       
    99     g_strfreev (factory->extensions);
       
   100 
       
   101   factory->extensions = g_strdupv (extensions);
       
   102   gst_caps_replace (&factory->caps, (GstCaps *) possible_caps);
       
   103   factory->function = func;
       
   104   factory->user_data = data;
       
   105   factory->user_data_notify = data_notify;
       
   106   if (plugin && plugin->desc.name) {
       
   107     GST_PLUGIN_FEATURE (factory)->plugin_name = plugin->desc.name;      /* interned string */
       
   108   } else {
       
   109     GST_PLUGIN_FEATURE (factory)->plugin_name = "NULL";
       
   110   }
       
   111   GST_PLUGIN_FEATURE (factory)->loaded = TRUE;
       
   112 
       
   113   gst_registry_add_feature (gst_registry_get_default (),
       
   114       GST_PLUGIN_FEATURE (factory));
       
   115 
       
   116   return TRUE;
       
   117 }
       
   118 
       
   119 /*** typefind function interface **********************************************/
       
   120 
       
   121 /**
       
   122  * gst_type_find_peek:
       
   123  * @find: The #GstTypeFind object the function was called with
       
   124  * @offset: The offset
       
   125  * @size: The number of bytes to return
       
   126  *
       
   127  * Returns the @size bytes of the stream to identify beginning at offset. If
       
   128  * offset is a positive number, the offset is relative to the beginning of the
       
   129  * stream, if offset is a negative number the offset is relative to the end of
       
   130  * the stream. The returned memory is valid until the typefinding function
       
   131  * returns and must not be freed.
       
   132  *
       
   133  * Returns: the requested data, or NULL if that data is not available.
       
   134  */
       
   135 #ifdef __SYMBIAN32__
       
   136 EXPORT_C
       
   137 #endif
       
   138 
       
   139 guint8 *
       
   140 gst_type_find_peek (GstTypeFind * find, gint64 offset, guint size)
       
   141 {
       
   142   g_return_val_if_fail (find->peek != NULL, NULL);
       
   143 
       
   144   return find->peek (find->data, offset, size);
       
   145 }
       
   146 
       
   147 /**
       
   148  * gst_type_find_suggest:
       
   149  * @find: The #GstTypeFind object the function was called with
       
   150  * @probability: The probability in percent that the suggestion is right
       
   151  * @caps: The fixed #GstCaps to suggest
       
   152  *
       
   153  * If a #GstTypeFindFunction calls this function it suggests the caps with the
       
   154  * given probability. A #GstTypeFindFunction may supply different suggestions
       
   155  * in one call.
       
   156  * It is up to the caller of the #GstTypeFindFunction to interpret these values.
       
   157  */
       
   158 #ifdef __SYMBIAN32__
       
   159 EXPORT_C
       
   160 #endif
       
   161 
       
   162 void
       
   163 gst_type_find_suggest (GstTypeFind * find, guint probability,
       
   164     const GstCaps * caps)
       
   165 {
       
   166   g_return_if_fail (find->suggest != NULL);
       
   167   g_return_if_fail (probability <= 100);
       
   168   g_return_if_fail (caps != NULL);
       
   169   g_return_if_fail (gst_caps_is_fixed (caps));
       
   170 
       
   171   find->suggest (find->data, probability, caps);
       
   172 }
       
   173 
       
   174 /**
       
   175  * gst_type_find_get_length:
       
   176  * @find: The #GstTypeFind the function was called with
       
   177  *
       
   178  * Get the length of the data stream.
       
   179  *
       
   180  * Returns: The length of the data stream, or 0 if it is not available.
       
   181  */
       
   182 #ifdef __SYMBIAN32__
       
   183 EXPORT_C
       
   184 #endif
       
   185 
       
   186 guint64
       
   187 gst_type_find_get_length (GstTypeFind * find)
       
   188 {
       
   189   if (find->get_length == NULL)
       
   190     return 0;
       
   191 
       
   192   return find->get_length (find->data);
       
   193 }