v4l2: UVC driver is named uvcvideo these days
[platform/upstream/gst-plugins-good.git] / tests / check / pipelines / flacdec.c
index 2f1890a..651d77f 100644 (file)
  *
  * 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #include <gst/check/gstcheck.h>
+#include <gst/audio/audio.h>
 #include <glib/gstdio.h>
 
 static guint16
-buffer_get_first_sample (GstBuffer * buf)
+_get_first_sample (GstSample * sample)
 {
-  GstStructure *s;
-  gint w, d, c, r, e;
+  GstAudioInfo info;
+  GstCaps *caps;
+  GstBuffer *buf;
+  GstMapInfo map;
+  guint16 res;
 
-  fail_unless (buf != NULL, "NULL buffer");
-  fail_unless (GST_BUFFER_CAPS (buf) != NULL, "buffer without caps");
+  fail_unless (sample != NULL, "NULL sample");
 
+  caps = gst_sample_get_caps (sample);
+  fail_unless (caps != NULL, "sample without caps");
+
+  buf = gst_sample_get_buffer (sample);
+  GST_DEBUG ("buffer with size=%" G_GSIZE_FORMAT ", caps=%" GST_PTR_FORMAT,
+      gst_buffer_get_size (buf), caps);
+
+  gst_buffer_map (buf, &map, GST_MAP_READ);
   /* log buffer details */
-  GST_DEBUG ("buffer with size=%u, caps=%" GST_PTR_FORMAT,
-      GST_BUFFER_SIZE (buf), GST_BUFFER_CAPS (buf));
-  GST_MEMDUMP ("buffer data from decoder", GST_BUFFER_DATA (buf),
-      GST_BUFFER_SIZE (buf));
+  GST_MEMDUMP ("buffer data from decoder", map.data, map.size);
 
   /* make sure it's the format we expect */
-  s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
-  fail_unless_equals_string (gst_structure_get_name (s), "audio/x-raw-int");
-  fail_unless (gst_structure_get_int (s, "width", &w));
-  fail_unless_equals_int (w, 16);
-  fail_unless (gst_structure_get_int (s, "depth", &d));
-  fail_unless_equals_int (d, 16);
-  fail_unless (gst_structure_get_int (s, "rate", &r));
-  fail_unless_equals_int (r, 44100);
-  fail_unless (gst_structure_get_int (s, "channels", &c));
-  fail_unless_equals_int (c, 1);
-  fail_unless (gst_structure_get_int (s, "endianness", &e));
-  if (e == G_BIG_ENDIAN)
-    return GST_READ_UINT16_BE (GST_BUFFER_DATA (buf));
+  fail_unless (gst_audio_info_from_caps (&info, caps));
+
+  fail_unless_equals_int (GST_AUDIO_INFO_WIDTH (&info), 16);
+  fail_unless_equals_int (GST_AUDIO_INFO_DEPTH (&info), 16);
+  fail_unless_equals_int (GST_AUDIO_INFO_RATE (&info), 44100);
+  fail_unless_equals_int (GST_AUDIO_INFO_CHANNELS (&info), 1);
+
+  if (GST_AUDIO_INFO_IS_LITTLE_ENDIAN (&info))
+    res = GST_READ_UINT16_LE (map.data);
   else
-    return GST_READ_UINT16_LE (GST_BUFFER_DATA (buf));
+    res = GST_READ_UINT16_BE (map.data);
+
+  gst_buffer_unmap (buf, &map);
+
+  return res;
 }
 
 GST_START_TEST (test_decode)
 {
   GstElement *pipeline;
   GstElement *appsink;
-  GstBuffer *buffer = NULL;
+  GstSample *sample = NULL;
   guint16 first_sample = 0;
   guint size = 0;
   gchar *path =
       g_build_filename (GST_TEST_FILES_PATH, "audiotestsrc.flac", NULL);
   gchar *pipe_desc =
-      g_strdup_printf ("filesrc location=\"%s\" ! flacdec ! appsink name=sink",
+      g_strdup_printf
+      ("filesrc location=\"%s\" ! flacparse ! flacdec ! appsink name=sink",
       path);
 
   pipeline = gst_parse_launch (pipe_desc, NULL);
@@ -78,17 +87,16 @@ GST_START_TEST (test_decode)
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
   do {
-    g_signal_emit_by_name (appsink, "pull-buffer", &buffer);
-    if (buffer == NULL)
+    g_signal_emit_by_name (appsink, "pull-sample", &sample);
+    if (sample == NULL)
       break;
     if (first_sample == 0)
-      first_sample = buffer_get_first_sample (buffer);
-    g_print ("buffer: %d\n", buffer->size);
-    g_print ("buffer: %04x\n", buffer_get_first_sample (buffer));
-    size += buffer->size;
+      first_sample = _get_first_sample (sample);
 
-    gst_buffer_unref (buffer);
-    buffer = NULL;
+    size += gst_buffer_get_size (gst_sample_get_buffer (sample));
+
+    gst_sample_unref (sample);
+    sample = NULL;
   }
   while (TRUE);
 
@@ -108,14 +116,14 @@ GST_START_TEST (test_decode_seek_full)
   GstElement *pipeline;
   GstElement *appsink;
   GstEvent *event;
-  GstBuffer *buffer = NULL;
+  GstSample *sample = NULL;
   guint16 first_sample = 0;
-  gboolean result;
   guint size = 0;
   gchar *path =
       g_build_filename (GST_TEST_FILES_PATH, "audiotestsrc.flac", NULL);
   gchar *pipe_desc =
-      g_strdup_printf ("filesrc location=\"%s\" ! flacdec ! appsink name=sink",
+      g_strdup_printf
+      ("filesrc location=\"%s\" ! flacparse ! flacdec ! appsink name=sink",
       path);
 
   pipeline = gst_parse_launch (pipe_desc, NULL);
@@ -133,20 +141,20 @@ GST_START_TEST (test_decode_seek_full)
   /* do a seek that should give us the complete output */
   event = gst_event_new_seek (1.0, GST_FORMAT_DEFAULT, GST_SEEK_FLAG_FLUSH,
       GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 20480);
-  result = gst_element_send_event (appsink, event);
+  fail_unless (gst_element_send_event (appsink, event));
 
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
   do {
-    g_signal_emit_by_name (appsink, "pull-buffer", &buffer);
-    if (buffer == NULL)
+    g_signal_emit_by_name (appsink, "pull-sample", &sample);
+    if (sample == NULL)
       break;
     if (first_sample == 0)
-      first_sample = buffer_get_first_sample (buffer);
-    size += buffer->size;
+      first_sample = _get_first_sample (sample);
+    size += gst_buffer_get_size (gst_sample_get_buffer (sample));
 
-    gst_buffer_unref (buffer);
-    buffer = NULL;
+    gst_sample_unref (sample);
+    sample = NULL;
   }
   while (TRUE);
 
@@ -168,14 +176,14 @@ GST_START_TEST (test_decode_seek_partial)
   GstElement *pipeline;
   GstElement *appsink;
   GstEvent *event;
-  GstBuffer *buffer = NULL;
-  gboolean result;
+  GstSample *sample = NULL;
   guint size = 0;
   guint16 first_sample = 0;
   gchar *path =
       g_build_filename (GST_TEST_FILES_PATH, "audiotestsrc.flac", NULL);
   gchar *pipe_desc =
-      g_strdup_printf ("filesrc location=\"%s\" ! flacdec ! appsink name=sink",
+      g_strdup_printf
+      ("filesrc location=\"%s\" ! flacparse ! flacdec ! appsink name=sink",
       path);
 
   pipeline = gst_parse_launch (pipe_desc, NULL);
@@ -194,29 +202,29 @@ GST_START_TEST (test_decode_seek_partial)
   event = gst_event_new_seek (1.0, GST_FORMAT_DEFAULT, GST_SEEK_FLAG_FLUSH,
       GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 1024);
   GST_DEBUG ("seeking");
-  result = gst_element_send_event (appsink, event);
+  fail_unless (gst_element_send_event (appsink, event));
   GST_DEBUG ("seeked");
 
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
   do {
-    GST_DEBUG ("pulling buffer");
-    g_signal_emit_by_name (appsink, "pull-buffer", &buffer);
-    GST_DEBUG ("pulled buffer %x", buffer);
-    if (buffer == NULL)
+    GST_DEBUG ("pulling sample");
+    g_signal_emit_by_name (appsink, "pull-sample", &sample);
+    GST_DEBUG ("pulled sample %p", sample);
+    if (sample == NULL)
       break;
     if (first_sample == 0) {
-      fail_unless_equals_int (GST_BUFFER_OFFSET (buffer), 0L);
-      first_sample = buffer_get_first_sample (buffer);
+      first_sample = _get_first_sample (sample);
     }
-    size += buffer->size;
+    size += gst_buffer_get_size (gst_sample_get_buffer (sample));
 
-    gst_buffer_unref (buffer);
-    buffer = NULL;
+    gst_sample_unref (sample);
+    sample = NULL;
   }
   while (TRUE);
 
-  fail_unless_equals_int (size, 2048);
+  /* allow for sample round-up clipping effect */
+  fail_unless (size == 2048 || size == 2050);
   fail_unless_equals_int (first_sample, 0x066a);
 
   gst_element_set_state (pipeline, GST_STATE_NULL);
@@ -227,7 +235,6 @@ GST_START_TEST (test_decode_seek_partial)
 
 GST_END_TEST;
 
-
 static Suite *
 flacdec_suite (void)
 {