示例#1
0
static gboolean
xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
    gboolean strict)
{
  gboolean got_xmldec;
  const guint8 *data;
  guint offset = 0;
  guint pos = 0;

  data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
  if (!data)
    return FALSE;

  /* look for the XMLDec
   * see XML spec 2.8, Prolog and Document Type Declaration
   * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
  got_xmldec = (memcmp (data, "<?xml", 5) == 0);

  if (strict && !got_xmldec)
    return FALSE;

  /* skip XMLDec in any case if we've got one */
  if (got_xmldec) {
    pos += 5;
    data += 5;
  }

  /* look for the first element, it has to be the requested element. Bail
   * out if it is not within the first 4kB. */
  while (data && (offset + pos) < 4096) {
    while (*data != '<' && (offset + pos) < 4096) {
      XML_INC_BUFFER;
    }

    XML_INC_BUFFER;
    if (!g_ascii_isalpha (*data)) {
      /* if not alphabetic, it's a PI or an element / attribute declaration
       * like <?xxx or <!xxx */
      XML_INC_BUFFER;
      continue;
    }

    /* the first normal element, check if it's the one asked for */
    data = gst_type_find_peek (tf, offset + pos, elen + 1);
    return (data && element && strncmp ((char *) data, element, elen) == 0);
  }

  return FALSE;
}
示例#2
0
static void
gst_my_typefind_function (GstTypeFind * tf, gpointer d)
{
  GstPnmInfoMngrResult r = GST_PNM_INFO_MNGR_RESULT_READING;
  GstPnmInfoMngr mngr = { 0, };
  guint i;
  guint8 *data = NULL;

  for (i = 0; r == GST_PNM_INFO_MNGR_RESULT_READING; i++) {
    data = gst_type_find_peek (tf, i, 1);
    if (!data)
      break;
    r = gst_pnm_info_mngr_scan (&mngr, data, 1);
  }
  switch (r) {
    case GST_PNM_INFO_MNGR_RESULT_READING:
    case GST_PNM_INFO_MNGR_RESULT_FAILED:
      return;
    case GST_PNM_INFO_MNGR_RESULT_FINISHED:
      switch (mngr.info.type) {
        case GST_PNM_TYPE_BITMAP_ASCII:
        case GST_PNM_TYPE_BITMAP_RAW:
          gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, BITMAP_CAPS);
          return;
        case GST_PNM_TYPE_GRAYMAP_ASCII:
        case GST_PNM_TYPE_GRAYMAP_RAW:
          gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, GRAYMAP_CAPS);
          return;
        case GST_PNM_TYPE_PIXMAP_ASCII:
        case GST_PNM_TYPE_PIXMAP_RAW:
          gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, PIXMAP_CAPS);
          return;
      }
  }
}
static void
gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore)
{
    guint8 *data;
    GdkPixbufLoader *pixbuf_loader;
    GdkPixbufFormat *format;

    data = gst_type_find_peek (tf, 0, GST_GDK_PIXBUF_TYPE_FIND_SIZE);
    if (data == NULL)
        return;

    GST_DEBUG ("creating new loader");

    pixbuf_loader = gdk_pixbuf_loader_new ();

    gdk_pixbuf_loader_write (pixbuf_loader, data, GST_GDK_PIXBUF_TYPE_FIND_SIZE,
                             NULL);

    format = gdk_pixbuf_loader_get_format (pixbuf_loader);

    if (format != NULL) {
        GstCaps *caps;
        gchar **p;
        gchar **mlist = gdk_pixbuf_format_get_mime_types (format);

        for (p = mlist; *p; ++p) {
            GST_DEBUG ("suggesting mime type %s", *p);
            caps = gst_caps_new_simple (*p, NULL);
            gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, caps);
            gst_caps_free (caps);
        }
        g_strfreev (mlist);
    }

    GST_DEBUG ("closing pixbuf loader, hope it doesn't hang ...");
    /* librsvg 2.4.x has a bug where it triggers an endless loop in trying
       to close a gzip that's not an svg; fixed upstream but no good way
       to work around it */
    gdk_pixbuf_loader_close (pixbuf_loader, NULL);
    GST_DEBUG ("closed pixbuf loader");
    g_object_unref (G_OBJECT (pixbuf_loader));
}
示例#4
0
文件: typefind.cpp 项目: shil99/study
static void
mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
    guint * found_layer, GstTypeFindProbability * found_prob)
{
    while (skipped < GST_MP3_TYPEFIND_TRY_SYNC)
    {
        // read the data to find the sync word
        size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
        data = gst_type_find_peek (tf, skipped + start_off, size);
        data_end = data + size;

        // find sync word
        if (*data == 0xFF)
        {
            // static function defined in the same file
            length = mp3_type_frame_length_from_header (head, &layer,
                    &channels, &bitrate, &samplerate, &free,last_free_framelen);

        }
    }
}