Merge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gstreamer.git] / tests / check / elements / audioresample.c
index 3b7432e..d8d2154 100644 (file)
  * get_peer, and then remove references in every test function */
 static GstPad *mysrcpad, *mysinkpad;
 
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define FORMATS_F  "{ F32LE, F64LE }"
+#define FORMATS_I  "{ S16LE, S32LE }"
+#else
+#define FORMATS_F  "{ F32BE, F64BE }"
+#define FORMATS_I  "{ S16BE, S32BE }"
+#endif
+
 #define RESAMPLE_CAPS_FLOAT            \
-    "audio/x-raw-float, "               \
+    "audio/x-raw, "                     \
+    "formats = (string) "FORMATS_F", "  \
     "channels = (int) [ 1, MAX ], "     \
-    "rate = (int) [ 1,  MAX ], "        \
-    "endianness = (int) BYTE_ORDER, "   \
-    "width = (int) { 32, 64 }"
+    "rate = (int) [ 1,  MAX ]"
 
 #define RESAMPLE_CAPS_INT              \
-    "audio/x-raw-int, "                 \
+    "audio/x-raw, "                     \
+    "formats = (string) "FORMATS_I", "  \
     "channels = (int) [ 1, MAX ], "     \
-    "rate = (int) [ 1,  MAX ], "        \
-    "endianness = (int) BYTE_ORDER, "   \
-    "width = (int) { 16, 32 }, "        \
-    "depth = (int) { 16, 32 }, "        \
-    "signed = (bool) TRUE"
+    "rate = (int) [ 1,  MAX ]"
 
 #define RESAMPLE_CAPS_TEMPLATE_STRING   \
     RESAMPLE_CAPS_FLOAT " ; " \
@@ -181,9 +185,8 @@ test_perfect_stream_instance (int inrate, int outrate, int samples,
   GstBuffer *inbuffer, *outbuffer;
   GstCaps *caps;
   guint64 offset = 0;
-
   int i, j;
-  gint16 *p;
+  gint16 *p, *data;
 
   audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
   caps = gst_pad_get_negotiated_caps (mysrcpad);
@@ -204,7 +207,7 @@ test_perfect_stream_instance (int inrate, int outrate, int samples,
 
     gst_buffer_set_caps (inbuffer, caps);
 
-    p = (gint16 *) GST_BUFFER_DATA (inbuffer);
+    p = data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
 
     /* create a 16 bit signed ramp */
     for (i = 0; i < samples; ++i) {
@@ -213,6 +216,7 @@ test_perfect_stream_instance (int inrate, int outrate, int samples,
       *p = -32767 + i * (65535 / samples);
       ++p;
     }
+    gst_buffer_unmap (inbuffer, data, samples * 4);
 
     /* pushing gives away my reference ... */
     fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
@@ -267,7 +271,7 @@ test_discont_stream_instance (int inrate, int outrate, int samples,
   GstClockTime ints;
 
   int i, j;
-  gint16 *p;
+  gint16 *p, *data;
 
   GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d",
       inrate, outrate, samples, numbuffers);
@@ -292,8 +296,7 @@ test_discont_stream_instance (int inrate, int outrate, int samples,
 
     gst_buffer_set_caps (inbuffer, caps);
 
-    p = (gint16 *) GST_BUFFER_DATA (inbuffer);
-
+    p = data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
     /* create a 16 bit signed ramp */
     for (i = 0; i < samples; ++i) {
       *p = -32767 + i * (65535 / samples);
@@ -301,6 +304,7 @@ test_discont_stream_instance (int inrate, int outrate, int samples,
       *p = -32767 + i * (65535 / samples);
       ++p;
     }
+    gst_buffer_unmap (inbuffer, data, samples * 4);
 
     GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%"
         G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
@@ -357,6 +361,7 @@ GST_START_TEST (test_reuse)
   GstEvent *newseg;
   GstBuffer *inbuffer;
   GstCaps *caps;
+  guint8 *data;
 
   audioresample = setup_audioresample (1, 9343, 48000, 16, FALSE);
   caps = gst_pad_get_negotiated_caps (mysrcpad);
@@ -370,7 +375,9 @@ GST_START_TEST (test_reuse)
   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
 
   inbuffer = gst_buffer_new_and_alloc (9343 * 4);
-  memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
+  data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
+  memset (data, 0, 9343 * 4);
+  gst_buffer_unmap (inbuffer, data, 9343 * 4);
   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
   GST_BUFFER_OFFSET (inbuffer) = 0;
@@ -394,7 +401,9 @@ GST_START_TEST (test_reuse)
   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
 
   inbuffer = gst_buffer_new_and_alloc (9343 * 4);
-  memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
+  data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
+  memset (data, 0, 9343 * 4);
+  gst_buffer_unmap (inbuffer, data, 9343 * 4);
   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
   GST_BUFFER_OFFSET (inbuffer) = 0;
@@ -430,13 +439,11 @@ GST_START_TEST (test_shutdown)
   g_object_set (cf2, "name", "capsfilter2", NULL);
   sink = gst_check_setup_element ("fakesink");
 
-  caps =
-      gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 11025, NULL);
+  caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT, 11025, NULL);
   g_object_set (cf1, "caps", caps, NULL);
   gst_caps_unref (caps);
 
-  caps =
-      gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 48000, NULL);
+  caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT, 48000, NULL);
   g_object_set (cf2, "caps", caps, NULL);
   gst_caps_unref (caps);
 
@@ -461,6 +468,7 @@ GST_START_TEST (test_shutdown)
 
 GST_END_TEST;
 
+#if 0
 static GstFlowReturn
 live_switch_alloc_only_48000 (GstPad * pad, guint64 offset,
     guint size, GstCaps * caps, GstBuffer ** buf)
@@ -486,6 +494,7 @@ live_switch_alloc_only_48000 (GstPad * pad, guint64 offset,
 
   return GST_FLOW_OK;
 }
+#endif
 
 static GstCaps *
 live_switch_get_sink_caps (GstPad * pad)
@@ -506,13 +515,18 @@ live_switch_push (int rate, GstCaps * caps)
   GstBuffer *inbuffer;
   GstCaps *desired;
   GList *l;
+  guint8 *data;
 
   desired = gst_caps_copy (caps);
   gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL);
   gst_pad_set_caps (mysrcpad, desired);
 
+#if 0
   fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad,
           GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK);
+#endif
+  inbuffer = gst_buffer_new_and_alloc (rate * 4);
+  gst_buffer_set_caps (inbuffer, desired);
 
   /* When the basetransform hits the non-configured case it always
    * returns a buffer with exactly the same caps as we requested so the actual
@@ -522,7 +536,10 @@ live_switch_push (int rate, GstCaps * caps)
       desired, GST_BUFFER_CAPS (inbuffer));
   fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer)));
 
-  memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
+  data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
+  memset (data, 0, rate * 4);
+  gst_buffer_unmap (inbuffer, data, rate * 4);
+
   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
   GST_BUFFER_OFFSET (inbuffer) = 0;
@@ -557,7 +574,7 @@ GST_START_TEST (test_live_switch)
    * rate 48000- and can only allocate buffers for that rate, but if someone
    * tries to get a buffer with a rate higher then 48000 tries to renegotiate
    * */
-  gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000);
+  //gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000);
   gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps);
 
   gst_pad_use_fixed_caps (mysrcpad);
@@ -613,7 +630,7 @@ eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
 }
 
 static void
-test_pipeline (gint width, gboolean fp, gint inrate, gint outrate, gint quality)
+test_pipeline (const gchar * format, gint inrate, gint outrate, gint quality)
 {
   GstElement *pipeline;
   GstBus *bus;
@@ -622,9 +639,8 @@ test_pipeline (gint width, gboolean fp, gint inrate, gint outrate, gint quality)
 
   pipe_str =
       g_strdup_printf
-      ("audiotestsrc num-buffers=10 ! audioconvert ! audio/x-raw-%s,rate=%d,width=%d,channels=2 ! audioresample quality=%d ! audio/x-raw-%s,rate=%d,width=%d ! identity check-imperfect-timestamp=TRUE ! fakesink",
-      (fp) ? "float" : "int", inrate, width, quality, (fp) ? "float" : "int",
-      outrate, width);
+      ("audiotestsrc num-buffers=10 ! audioconvert ! audio/x-raw,format=%s,rate=%d,channels=2 ! audioresample quality=%d ! audio/x-raw,format=%s,rate=%d ! identity check-imperfect-timestamp=TRUE ! fakesink",
+      format, inrate, quality, format, outrate);
 
   pipeline = gst_parse_launch (pipe_str, &error);
   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
@@ -697,9 +713,8 @@ GST_START_TEST (test_preference_passthrough)
   gint rate = 0;
 
   pipeline = gst_parse_launch ("audiotestsrc num-buffers=1 name=src ! "
-      "audioresample ! audio/x-raw-int,channels=1,width=16,depth=16,"
-      "endianness=BYTE_ORDER,signed=true,rate=8000 ! "
-      "fakesink can-activate-pull=false", &error);
+      "audioresample ! audio/x-raw,format=" GST_AUDIO_NE (S16) ",channels=1,"
+      "rate=8000 ! fakesink can-activate-pull=false", &error);
   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
       error ? error->message : "(invalid error)");
 
@@ -775,7 +790,7 @@ fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad,
 
   ctx->out_buffer_count++;
   if (ctx->latency == GST_CLOCK_TIME_NONE) {
-    ctx->latency = 1000 - GST_BUFFER_SIZE (buffer) / 8;
+    ctx->latency = 1000 - gst_buffer_get_size (buffer) / 8;
   }
 
   /* Check if we have a perfectly timestamped stream */
@@ -787,10 +802,10 @@ fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad,
 
   /* Check if we have a perfectly offsetted stream */
   fail_unless (GST_BUFFER_OFFSET_END (buffer) ==
-      GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8,
+      GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer) / 8,
       "expected offset end %" G_GUINT64_FORMAT " got offset end %"
       G_GUINT64_FORMAT,
-      GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8,
+      GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer) / 8,
       GST_BUFFER_OFFSET_END (buffer));
   if (ctx->next_out_off != GST_BUFFER_OFFSET_NONE) {
     fail_unless (GST_BUFFER_OFFSET (buffer) == ctx->next_out_off,
@@ -857,7 +872,7 @@ GST_START_TEST (test_timestamp_drift)
   fail_unless (capsfilter1 != NULL);
   caps =
       gst_caps_from_string
-      ("audio/x-raw-float, channels=1, width=64, rate=16384");
+      ("audio/x-raw, format=F64LE, channels=1, rate=16384");
   g_object_set (G_OBJECT (capsfilter1), "caps", caps, NULL);
   gst_caps_unref (caps);
 
@@ -872,8 +887,7 @@ GST_START_TEST (test_timestamp_drift)
   capsfilter2 = gst_element_factory_make ("capsfilter", "capsfilter2");
   fail_unless (capsfilter2 != NULL);
   caps =
-      gst_caps_from_string
-      ("audio/x-raw-float, channels=1, width=64, rate=4096");
+      gst_caps_from_string ("audio/x-raw, format=F64LE, channels=1, rate=4096");
   g_object_set (G_OBJECT (capsfilter2), "caps", caps, NULL);
   gst_caps_unref (caps);