Blame tests/check/gst/typefindfunctions.c

Packit 971217
/* GStreamer unit tests for the -base typefind functions
Packit 971217
 *
Packit 971217
 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
# include <config.h>
Packit 971217
#endif
Packit 971217
Packit 971217
#include <gst/check/gstcheck.h>
Packit 971217
#include <gst/base/gsttypefindhelper.h>
Packit 971217
Packit 971217
static GstCaps *
Packit 971217
typefind_data (const guint8 * data, gsize data_size,
Packit 971217
    GstTypeFindProbability * prob)
Packit 971217
{
Packit 971217
  GstBuffer *buf;
Packit 971217
  GstCaps *caps;
Packit 971217
Packit 971217
  GST_MEMDUMP ("typefind data", data, data_size);
Packit 971217
  buf = gst_buffer_new ();
Packit 971217
  gst_buffer_append_memory (buf,
Packit 971217
      gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
Packit 971217
          (guint8 *) data, data_size, 0, data_size, NULL, NULL));
Packit 971217
  GST_BUFFER_OFFSET (buf) = 0;
Packit 971217
Packit 971217
  caps = gst_type_find_helper_for_buffer (NULL, buf, prob);
Packit 971217
  GST_INFO ("caps: %" GST_PTR_FORMAT ", probability=%u", caps, *prob);
Packit 971217
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
Packit 971217
  return caps;
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_quicktime_mpeg4video)
Packit 971217
{
Packit 971217
  /* quicktime redirect file which starts with what could also be interpreted
Packit 971217
   * as an MPEG-4 video object layer start code */
Packit 971217
  const guint8 qt_redirect_396042[] =
Packit 971217
      { 0x00, 0x00, 0x01, 0x22, 0x6d, 0x6f, 0x6f, 0x76, 0x00, 0x00, 0x01, 0x1a,
Packit 971217
    0x72, 0x6d, 0x72, 0x61, 0x00, 0x00, 0x00, 0x86, 0x72, 0x6d, 0x64, 0x61,
Packit 971217
    0x00, 0x00, 0x00, 0x54, 0x72, 0x64, 0x72, 0x66, 0x00, 0x00, 0x00, 0x00,
Packit 971217
    0x75, 0x72, 0x6c, 0x20, 0x00, 0x00, 0x00, 0x40, 0x68, 0x74, 0x74, 0x70,
Packit 971217
    0x3a, 0x2f, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x71, 0x74,
Packit 971217
    0x76, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
Packit 971217
    0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x6a, 0x61, 0x6e, 0x2f, 0x6a,
Packit 971217
    0x34, 0x37, 0x64, 0x35, 0x32, 0x6f, 0x6f, 0x2f, 0x71, 0x74, 0x37, 0x72,
Packit 971217
    0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x2e, 0x6d, 0x6f, 0x76, 0x00,
Packit 971217
    0x00, 0x00, 0x00, 0x10, 0x72, 0x6d, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00,
Packit 971217
    0x00, 0x00, 0x0a, 0xf0, 0x00, 0x00, 0x00, 0x1a, 0x72, 0x6d, 0x76, 0x63,
Packit 971217
    0x00, 0x00, 0x00, 0x00, 0x71, 0x74, 0x69, 0x6d, 0x06, 0x50, 0x00, 0x00,
Packit 971217
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x72, 0x6d,
Packit 971217
    0x64, 0x61, 0x00, 0x00, 0x00, 0x5a, 0x72, 0x64, 0x72, 0x66, 0x00, 0x00,
Packit 971217
    0x00, 0x00, 0x75, 0x72, 0x6c, 0x20, 0x00, 0x00, 0x00, 0x46, 0x68, 0x74,
Packit 971217
    0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e,
Packit 971217
    0x71, 0x74, 0x76, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
Packit 971217
    0x6d, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x6a, 0x61, 0x6e,
Packit 971217
    0x2f, 0x6a, 0x34, 0x37, 0x64, 0x35, 0x32, 0x6f, 0x6f, 0x2f, 0x38, 0x38,
Packit 971217
    0x34, 0x38, 0x31, 0x32, 0x35, 0x5f, 0x32, 0x5f, 0x33, 0x35, 0x30, 0x5f,
Packit 971217
    0x72, 0x65, 0x66, 0x2e, 0x6d, 0x6f, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10,
Packit 971217
    0x72, 0x6d, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xf0,
Packit 971217
    0x00, 0x00, 0x00, 0x1a, 0x72, 0x6d, 0x76, 0x63, 0x00, 0x00, 0x00, 0x00,
Packit 971217
    0x71, 0x74, 0x69, 0x6d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit 971217
    0x00, 0x00
Packit 971217
  };
Packit 971217
  GstTypeFindProbability prob;
Packit 971217
  const gchar *type;
Packit 971217
  GstBuffer *buf;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
Packit 971217
  buf = gst_buffer_new ();
Packit 971217
  gst_buffer_append_memory (buf,
Packit 971217
      gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
Packit 971217
          (gpointer) qt_redirect_396042,
Packit 971217
          sizeof (qt_redirect_396042), 0, sizeof (qt_redirect_396042), NULL,
Packit 971217
          NULL));
Packit 971217
Packit 971217
  GST_BUFFER_OFFSET (buf) = 0;
Packit 971217
Packit 971217
  caps = gst_type_find_helper_for_buffer (NULL, buf, &prob;;
Packit 971217
  fail_unless (caps != NULL);
Packit 971217
  GST_LOG ("Found type: %" GST_PTR_FORMAT, caps);
Packit 971217
Packit 971217
  type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
  fail_unless_equals_string (type, "video/quicktime");
Packit 971217
  fail_unless (prob > GST_TYPE_FIND_MINIMUM && prob <= GST_TYPE_FIND_MAXIMUM);
Packit 971217
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_broken_flac_in_ogg)
Packit 971217
{
Packit 971217
  const guint8 flac_id_packet[4] = { 'f', 'L', 'a', 'C' };
Packit 971217
  GstTypeFindProbability prob;
Packit 971217
  const gchar *type;
Packit 971217
  GstBuffer *buf;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
Packit 971217
  buf = gst_buffer_new ();
Packit 971217
  gst_buffer_append_memory (buf,
Packit 971217
      gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
Packit 971217
          (gpointer) flac_id_packet,
Packit 971217
          sizeof (flac_id_packet), 0, sizeof (flac_id_packet), NULL, NULL));
Packit 971217
Packit 971217
  GST_BUFFER_OFFSET (buf) = 0;
Packit 971217
Packit 971217
  caps = gst_type_find_helper_for_buffer (NULL, buf, &prob;;
Packit 971217
  fail_unless (caps != NULL);
Packit 971217
  GST_LOG ("Found type: %" GST_PTR_FORMAT, caps);
Packit 971217
Packit 971217
  type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
  fail_unless_equals_string (type, "audio/x-flac");
Packit 971217
  fail_unless (prob > GST_TYPE_FIND_MINIMUM && prob <= GST_TYPE_FIND_MAXIMUM);
Packit 971217
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static GstCaps *
Packit 971217
typefind_test_file (const gchar * filename)
Packit 971217
{
Packit 971217
  GstBuffer *buf;
Packit 971217
  GError *err = NULL;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
  gchar *path, *data = NULL;
Packit 971217
  gsize data_len;
Packit 971217
Packit 971217
  path = g_build_filename (GST_TEST_FILES_PATH, filename, NULL);
Packit 971217
  GST_LOG ("reading file '%s'", path);
Packit 971217
  if (!g_file_get_contents (path, &data, &data_len, &err)) {
Packit 971217
    g_error ("error loading test file: %s", err->message);
Packit 971217
    g_clear_error (&err;;
Packit 971217
  }
Packit 971217
Packit 971217
  buf = gst_buffer_new ();
Packit 971217
  gst_buffer_append_memory (buf,
Packit 971217
      gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
Packit 971217
          (gpointer) data, data_len, 0, data_len, NULL, NULL));
Packit 971217
Packit 971217
  GST_BUFFER_OFFSET (buf) = 0;
Packit 971217
Packit 971217
  caps = gst_type_find_helper_for_buffer (NULL, buf, NULL);
Packit 971217
  fail_unless (caps != NULL);
Packit 971217
  GST_LOG ("Found type: %" GST_PTR_FORMAT, caps);
Packit 971217
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
  g_free (data);
Packit 971217
  g_free (path);
Packit 971217
Packit 971217
  return caps;
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_jpeg_not_ac3)
Packit 971217
{
Packit 971217
  const gchar *type;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
Packit 971217
  caps = typefind_test_file ("partialframe.mjpeg");
Packit 971217
  type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
  fail_unless_equals_string (type, "image/jpeg");
Packit 971217
Packit 971217
  gst_caps_unref (caps);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_mpegts)
Packit 971217
{
Packit 971217
  GstStructure *s;
Packit 971217
  gboolean systemstream = FALSE;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
  gint packetsize = -1;
Packit 971217
Packit 971217
  caps = typefind_test_file ("623663.mts");
Packit 971217
  s = gst_caps_get_structure (caps, 0);
Packit 971217
  fail_unless (gst_structure_has_name (s, "video/mpegts"));
Packit 971217
  fail_unless (gst_structure_has_field (s, "systemstream"));
Packit 971217
  fail_unless (gst_structure_get_boolean (s, "systemstream", &systemstream));
Packit 971217
  fail_unless_equals_int (systemstream, TRUE);
Packit 971217
  fail_unless (gst_structure_has_field (s, "packetsize"));
Packit 971217
  fail_unless (gst_structure_get_int (s, "packetsize", &packetsize));
Packit 971217
  fail_unless_equals_int (packetsize, 192);
Packit 971217
Packit 971217
  gst_caps_unref (caps);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
struct ac3_frmsize
Packit 971217
{
Packit 971217
  unsigned frmsizecod;
Packit 971217
  unsigned frmsize;
Packit 971217
};
Packit 971217
Packit 971217
static void
Packit 971217
make_ac3_packet (guint8 * data, guint bytesize, guint bsid)
Packit 971217
{
Packit 971217
  /* Actually not a fully valid packet; if the typefinder starts to
Packit 971217
   * check e.g. the CRCs, this test needs to be improved as well. */
Packit 971217
  const guint8 ac3_header[] = {
Packit 971217
    0x0b, 0x77,                 /* syncword */
Packit 971217
    0x00, 0x00,                 /* crc1 */
Packit 971217
    0x00,                       /* fscod 0xc0, frmsizecod 0x3f */
Packit 971217
    0x00                        /* bsid 0xf8, bsmod 0x07 */
Packit 971217
  };
Packit 971217
  const struct ac3_frmsize frmsize[] = {
Packit 971217
    {17, 256}, {26, 640}        /* small subset of supported sizes */
Packit 971217
  };
Packit 971217
  guint wordsize = bytesize >> 1, frmsizecod = 0;
Packit 971217
  int i;
Packit 971217
Packit 971217
  fail_unless ((bytesize & 0x01) == 0);
Packit 971217
  fail_unless (bytesize >= sizeof (ac3_header));
Packit 971217
Packit 971217
  for (i = 0; i < G_N_ELEMENTS (frmsize); i++) {
Packit 971217
    if (frmsize[i].frmsize == wordsize) {
Packit 971217
      frmsizecod = frmsize[i].frmsizecod;
Packit 971217
      break;
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  fail_unless (frmsizecod);
Packit 971217
Packit 971217
  memcpy (data, ac3_header, sizeof (ac3_header));
Packit 971217
  data[4] = (data[4] & ~0x3f) | (frmsizecod & 0x3f);
Packit 971217
  data[5] = (bsid & 0x1f) << 3;
Packit 971217
  memset (data + 6, 0, bytesize - 6);
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_ac3)
Packit 971217
{
Packit 971217
  GstTypeFindProbability prob;
Packit 971217
  const gchar *type;
Packit 971217
  GstBuffer *buf;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
  guint bsid;
Packit 971217
Packit 971217
  for (bsid = 0; bsid < 32; bsid++) {
Packit 971217
    GstMapInfo map;
Packit 971217
Packit 971217
    buf = gst_buffer_new_and_alloc ((256 + 640) * 2);
Packit 971217
    gst_buffer_map (buf, &map, GST_MAP_WRITE);
Packit 971217
    make_ac3_packet (map.data, 256 * 2, bsid);
Packit 971217
    make_ac3_packet (map.data + 256 * 2, 640 * 2, bsid);
Packit 971217
    gst_buffer_unmap (buf, &map);
Packit 971217
Packit 971217
    caps = gst_type_find_helper_for_buffer (NULL, buf, &prob;;
Packit 971217
    if (bsid <= 8) {
Packit 971217
      fail_unless (caps != NULL);
Packit 971217
      GST_LOG ("Found type for BSID %u: %" GST_PTR_FORMAT, bsid, caps);
Packit 971217
Packit 971217
      type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
      fail_unless_equals_string (type, "audio/x-ac3");
Packit 971217
      fail_unless (prob > GST_TYPE_FIND_MINIMUM
Packit 971217
          && prob <= GST_TYPE_FIND_MAXIMUM);
Packit 971217
      gst_caps_unref (caps);
Packit 971217
    } else {
Packit 971217
      fail_unless (caps == NULL);
Packit 971217
    }
Packit 971217
Packit 971217
    gst_buffer_unref (buf);
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static void
Packit 971217
make_eac3_packet (guint8 * data, guint bytesize, guint bsid)
Packit 971217
{
Packit 971217
  /* Actually not a fully valid packet; if the typefinder starts to
Packit 971217
   * check e.g. the CRCs, this test needs to be improved as well. */
Packit 971217
  const guint8 eac3_header[] = {
Packit 971217
    0x0b, 0x77,                 /* syncword */
Packit 971217
    0x00,                       /* strmtyp 0xc0, substreamid 0x38,
Packit 971217
                                 * frmsize 0x07 (3 high bits) */
Packit 971217
    0x00,                       /* frmsize (low bits -> 11 total) */
Packit 971217
    0x00,                       /* fscod 0xc0, fscod2/numblocks 0x30,
Packit 971217
                                 * acmod 0x0e, lfeon 0x01 */
Packit 971217
    0x00                        /* bsid 0xf8, dialnorm 0x07 (3 high bits) */
Packit 971217
  };
Packit 971217
  guint wordsize = bytesize >> 1;
Packit 971217
Packit 971217
  fail_unless ((bytesize & 0x01) == 0);
Packit 971217
  fail_unless (bytesize >= sizeof (eac3_header));
Packit 971217
Packit 971217
  memcpy (data, eac3_header, sizeof (eac3_header));
Packit 971217
  data[2] = (data[2] & ~0x07) | ((((wordsize - 1) & 0x700) >> 8) & 0xff);
Packit 971217
  data[3] = (wordsize - 1) & 0xff;
Packit 971217
  data[5] = (bsid & 0x1f) << 3;
Packit 971217
  memset (data + 6, 0, bytesize - 6);
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_eac3)
Packit 971217
{
Packit 971217
  GstTypeFindProbability prob;
Packit 971217
  const gchar *type;
Packit 971217
  GstBuffer *buf;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
  guint bsid;
Packit 971217
Packit 971217
  for (bsid = 0; bsid <= 32; bsid++) {
Packit 971217
    GstMapInfo map;
Packit 971217
Packit 971217
    buf = gst_buffer_new_and_alloc (558 + 384);
Packit 971217
    gst_buffer_map (buf, &map, GST_MAP_WRITE);
Packit 971217
    make_eac3_packet (map.data, 558, bsid);
Packit 971217
    make_eac3_packet (map.data + 558, 384, bsid);
Packit 971217
    gst_buffer_unmap (buf, &map);
Packit 971217
Packit 971217
    caps = gst_type_find_helper_for_buffer (NULL, buf, &prob;;
Packit 971217
    if (bsid > 10 && bsid <= 16) {
Packit 971217
      /* Only BSIs 11..16 are valid for Annex E */
Packit 971217
      fail_unless (caps != NULL);
Packit 971217
      GST_LOG ("Found type for BSID %u: %" GST_PTR_FORMAT, bsid, caps);
Packit 971217
Packit 971217
      type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
      fail_unless_equals_string (type, "audio/x-eac3");
Packit 971217
      fail_unless (prob > GST_TYPE_FIND_MINIMUM
Packit 971217
          && prob <= GST_TYPE_FIND_MAXIMUM);
Packit 971217
      gst_caps_unref (caps);
Packit 971217
    } else {
Packit 971217
      /* Invalid E-AC-3 BSID, must not be detected as anything: */
Packit 971217
      fail_unless (caps == NULL);
Packit 971217
    }
Packit 971217
Packit 971217
    gst_buffer_unref (buf);
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
#define TEST_RANDOM_DATA_SIZE (4*1024)
Packit 971217
Packit 971217
/* typefind random data, to make sure all typefinders are called */
Packit 971217
GST_START_TEST (test_random_data)
Packit 971217
{
Packit 971217
  GstTypeFindProbability prob;
Packit 971217
  const gchar *seed_env;
Packit 971217
  GstBuffer *buf;
Packit 971217
  GstCaps *caps;
Packit 971217
  guint32 seed;
Packit 971217
  guint8 *data;
Packit 971217
  gint i;
Packit 971217
Packit 971217
  seed_env = g_getenv ("GST_TYPEFIND_TEST_SEED");
Packit 971217
  if (seed_env != NULL)
Packit 971217
    seed = atoi (seed_env);
Packit 971217
  else
Packit 971217
    seed = (guint32) time (NULL);
Packit 971217
Packit 971217
  g_random_set_seed (seed);
Packit 971217
Packit 971217
  data = g_malloc (TEST_RANDOM_DATA_SIZE);
Packit 971217
  for (i = 0; i < TEST_RANDOM_DATA_SIZE; ++i)
Packit 971217
    data[i] = g_random_int () & 0xff;
Packit 971217
Packit 971217
  buf = gst_buffer_new ();
Packit 971217
  gst_buffer_append_memory (buf,
Packit 971217
      gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
Packit 971217
          data, TEST_RANDOM_DATA_SIZE, 0, TEST_RANDOM_DATA_SIZE, NULL, NULL));
Packit 971217
Packit 971217
  GST_BUFFER_OFFSET (buf) = 0;
Packit 971217
Packit 971217
  caps = gst_type_find_helper_for_buffer (NULL, buf, &prob;;
Packit 971217
  GST_INFO ("caps: %" GST_PTR_FORMAT ", probability=%u", caps, prob);
Packit 971217
  /* for now we just print an error log message */
Packit 971217
  if (caps != NULL /* && prob >= GST_TYPE_FIND_LIKELY */ ) {
Packit 971217
    GST_ERROR ("typefinder thinks random data is %" GST_PTR_FORMAT ", with a "
Packit 971217
        "probability of %u (seed was %u)", caps, prob, seed);
Packit 971217
    gst_caps_unref (caps);
Packit 971217
  }
Packit 971217
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
  g_free (data);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_hls_m3u8)
Packit 971217
{
Packit 971217
  const gchar *type;
Packit 971217
  GstCaps *caps = NULL;
Packit 971217
Packit 971217
  caps = typefind_test_file ("hls.m3u8");
Packit 971217
  type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
  fail_unless_equals_string (type, "application/x-hls");
Packit 971217
Packit 971217
  gst_caps_unref (caps);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static const gchar MANIFEST[] =
Packit 971217
    "\n"
Packit 971217
    "\n"
Packit 971217
    "
Packit 971217
    "  MajorVersion=\"1\"\n"
Packit 971217
    "  MinorVersion=\"0\"\n"
Packit 971217
    "  Duration=\"5965419999\">\n"
Packit 971217
    "  
Packit 971217
    "    Type=\"video\"\n"
Packit 971217
    "    Subtype=\"WVC1\"\n"
Packit 971217
    "    Chunks=\"299\"\n"
Packit 971217
    "    Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n"
Packit 971217
    "    
Packit 971217
    "      Bitrate=\"2750000\"\n"
Packit 971217
    "      FourCC=\"WVC1\"\n" "      Width=\"1280\"\n" "      Height=\"720\"\n";
Packit 971217
Packit 971217
static guint8 *
Packit 971217
generate_utf16 (guint off_lo, guint off_hi)
Packit 971217
{
Packit 971217
  guint8 *utf16;
Packit 971217
  gsize len, i;
Packit 971217
Packit 971217
  len = strlen (MANIFEST);
Packit 971217
  /* BOM + UTF-16 string */
Packit 971217
  utf16 = g_malloc (2 + len * 2);
Packit 971217
  utf16[off_lo] = 0xff;
Packit 971217
  utf16[off_hi] = 0xfe;
Packit 971217
  for (i = 0; i < len; ++i) {
Packit 971217
    utf16[2 + (2 * i) + off_lo] = MANIFEST[i];
Packit 971217
    utf16[2 + (2 * i) + off_hi] = 0x00;
Packit 971217
  }
Packit 971217
Packit 971217
  return utf16;
Packit 971217
}
Packit 971217
Packit 971217
/* Test that we can typefind UTF16-LE and UTF16-BE variants
Packit 971217
 * of smooth streaming manifests (even without iconv) */
Packit 971217
GST_START_TEST (test_manifest_typefinding)
Packit 971217
{
Packit 971217
  GstTypeFindProbability prob;
Packit 971217
  const gchar *media_type;
Packit 971217
  GstCaps *caps;
Packit 971217
  guint8 *utf16;
Packit 971217
Packit 971217
  utf16 = generate_utf16 (0, 1);
Packit 971217
  prob = 0;
Packit 971217
  caps = typefind_data (utf16, 2 + strlen (MANIFEST) * 2, &prob;;
Packit 971217
  fail_unless (caps != NULL);
Packit 971217
  media_type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
  fail_unless_equals_string (media_type, "application/vnd.ms-sstr+xml");
Packit 971217
  fail_unless_equals_int (prob, GST_TYPE_FIND_MAXIMUM);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
  g_free (utf16);
Packit 971217
Packit 971217
  utf16 = generate_utf16 (1, 0);
Packit 971217
  prob = 0;
Packit 971217
  caps = typefind_data (utf16, 2 + strlen (MANIFEST) * 2, &prob;;
Packit 971217
  fail_unless (caps != NULL);
Packit 971217
  media_type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
Packit 971217
  fail_unless_equals_string (media_type, "application/vnd.ms-sstr+xml");
Packit 971217
  fail_unless_equals_int (prob, GST_TYPE_FIND_MAXIMUM);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
  g_free (utf16);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static Suite *
Packit 971217
typefindfunctions_suite (void)
Packit 971217
{
Packit 971217
  Suite *s = suite_create ("typefindfunctions");
Packit 971217
  TCase *tc_chain = tcase_create ("general");
Packit 971217
Packit 971217
  suite_add_tcase (s, tc_chain);
Packit 971217
Packit 971217
  tcase_add_test (tc_chain, test_quicktime_mpeg4video);
Packit 971217
  tcase_add_test (tc_chain, test_broken_flac_in_ogg);
Packit 971217
  tcase_add_test (tc_chain, test_jpeg_not_ac3);
Packit 971217
  tcase_add_test (tc_chain, test_mpegts);
Packit 971217
  tcase_add_test (tc_chain, test_ac3);
Packit 971217
  tcase_add_test (tc_chain, test_eac3);
Packit 971217
  tcase_add_test (tc_chain, test_random_data);
Packit 971217
  tcase_add_test (tc_chain, test_hls_m3u8);
Packit 971217
  tcase_add_test (tc_chain, test_manifest_typefinding);
Packit 971217
Packit 971217
  return s;
Packit 971217
}
Packit 971217
Packit 971217
GST_CHECK_MAIN (typefindfunctions);