rtp-payloading.c 23 KB
Newer Older
1
/* GStreamer RTP payloader unit tests
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 * Copyright (C) 2008 Nokia Corporation and its subsidary(-ies)
 *               contact: <stefan.kost@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * 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.
 */
#include <gst/check/gstcheck.h>
#include <stdlib.h>
#include <unistd.h>

#define RELEASE_ELEMENT(x) if(x) {gst_object_unref(x); x = NULL;}

#define LOOP_COUNT 1

/*
 * RTP pipeline structure to store the required elements.
 */
typedef struct
{
  GstElement *pipeline;
34
  GstElement *appsrc;
35 36 37
  GstElement *rtppay;
  GstElement *rtpdepay;
  GstElement *fakesink;
38
  const guint8 *frame_data;
39 40 41 42
  int frame_data_size;
  int frame_count;
} rtp_pipeline;

43 44 45 46 47 48 49 50 51
/*
 * Number of bytes received in the chain list function when using buffer lists
 */
static guint chain_list_bytes_received;

/*
 * Chain list function for testing buffer lists
 */
static GstFlowReturn
Wim Taymans's avatar
Wim Taymans committed
52
rtp_pipeline_chain_list (GstPad * pad, GstObject * parent, GstBufferList * list)
53
{
Wim Taymans's avatar
Wim Taymans committed
54
  guint i, len;
55 56 57 58 59

  fail_if (!list);
  /*
   * Count the size of the payload in the buffer list.
   */
Wim Taymans's avatar
Wim Taymans committed
60
  len = gst_buffer_list_length (list);
61 62

  /* Loop through all groups */
Wim Taymans's avatar
Wim Taymans committed
63
  for (i = 0; i < len; i++) {
64 65
    GstBuffer *paybuf;

Wim Taymans's avatar
Wim Taymans committed
66 67
    /* FIXME need to discard RTP header */
    paybuf = gst_buffer_list_get (list, i);
68
    /* Loop through all payload buffers in the current group */
Wim Taymans's avatar
Wim Taymans committed
69
    chain_list_bytes_received += gst_buffer_get_size (paybuf);
70 71 72 73 74 75
  }
  gst_buffer_list_unref (list);

  return GST_FLOW_OK;
}

76 77 78
/*
 * RTP bus callback.
 */
79
static gboolean
80 81 82 83 84 85 86 87
rtp_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
{
  GMainLoop *mainloop = (GMainLoop *) data;

  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_ERROR:
    {
      GError *err;
88

89
      gchar *debug;
90

91
      gchar *element_name;
92

93
      element_name = (message->src) ? gst_object_get_name (message->src) : NULL;
94
      gst_message_parse_error (message, &err, &debug);
95 96 97
      /* FIXME: should we fail the test here? */
      g_print ("\nError from element %s: %s\n%s\n\n",
          GST_STR_NULL (element_name), err->message, (debug) ? debug : "");
98 99
      g_error_free (err);
      g_free (debug);
100
      g_free (element_name);
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

      g_main_loop_quit (mainloop);
    }
      break;

    case GST_MESSAGE_EOS:
    {
      g_main_loop_quit (mainloop);
    }
      break;
      break;

    default:
    {
    }
      break;
  }

  return TRUE;
}

/*
 * Creates a RTP pipeline for one test.
 * @param frame_data Pointer to the frame data which is used to pass thru pay/depayloaders.
 * @param frame_data_size Frame data size in bytes.
 * @param frame_count Frame count.
 * @param filtercaps Caps filters.
 * @param pay Payloader name.
 * @param depay Depayloader name.
 * @return
 * Returns pointer to the RTP pipeline.
 * The user must free the RTP pipeline when it's not used anymore.
 */
134
static rtp_pipeline *
135
rtp_pipeline_create (const guint8 * frame_data, int frame_data_size,
136 137
    int frame_count, const char *filtercaps, const char *pay, const char *depay)
{
138
  gchar *pipeline_name;
139 140 141
  rtp_pipeline *p;
  GstCaps *caps;

142 143 144 145 146 147
  /* Check parameters. */
  if (!frame_data || !pay || !depay) {
    return NULL;
  }

  /* Allocate memory for the RTP pipeline. */
148
  p = (rtp_pipeline *) malloc (sizeof (rtp_pipeline));
149 150 151 152 153 154

  p->frame_data = frame_data;
  p->frame_data_size = frame_data_size;
  p->frame_count = frame_count;

  /* Create elements. */
155 156 157
  pipeline_name = g_strdup_printf ("%s-%s-pipeline", pay, depay);
  p->pipeline = gst_pipeline_new (pipeline_name);
  g_free (pipeline_name);
158
  p->appsrc = gst_element_factory_make ("appsrc", NULL);
159 160 161 162 163
  p->rtppay = gst_element_factory_make (pay, NULL);
  p->rtpdepay = gst_element_factory_make (depay, NULL);
  p->fakesink = gst_element_factory_make ("fakesink", NULL);

  /* One or more elements are not created successfully or failed to create p? */
164
  if (!p->pipeline || !p->appsrc || !p->rtppay || !p->rtpdepay || !p->fakesink) {
165 166
    /* Release created elements. */
    RELEASE_ELEMENT (p->pipeline);
167
    RELEASE_ELEMENT (p->appsrc);
168 169 170 171 172 173 174 175 176 177
    RELEASE_ELEMENT (p->rtppay);
    RELEASE_ELEMENT (p->rtpdepay);
    RELEASE_ELEMENT (p->fakesink);

    /* Release allocated memory. */
    free (p);

    return NULL;
  }

178
  /* Set src properties. */
179
  caps = gst_caps_from_string (filtercaps);
180 181
  g_object_set (p->appsrc, "do-timestamp", TRUE, "caps", caps,
      "format", GST_FORMAT_TIME, NULL);
182 183 184
  gst_caps_unref (caps);

  /* Add elements to the pipeline. */
185
  gst_bin_add (GST_BIN (p->pipeline), p->appsrc);
186 187 188 189 190
  gst_bin_add (GST_BIN (p->pipeline), p->rtppay);
  gst_bin_add (GST_BIN (p->pipeline), p->rtpdepay);
  gst_bin_add (GST_BIN (p->pipeline), p->fakesink);

  /* Link elements. */
191
  gst_element_link (p->appsrc, p->rtppay);
192 193 194 195 196 197 198 199 200 201
  gst_element_link (p->rtppay, p->rtpdepay);
  gst_element_link (p->rtpdepay, p->fakesink);

  return p;
}

/*
 * Destroys the RTP pipeline.
 * @param p Pointer to the RTP pipeline.
 */
202
static void
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
rtp_pipeline_destroy (rtp_pipeline * p)
{
  /* Check parameters. */
  if (p == NULL) {
    return;
  }

  /* Release pipeline. */
  RELEASE_ELEMENT (p->pipeline);

  /* Release allocated memory. */
  free (p);
}

/*
 * Runs the RTP pipeline.
 * @param p Pointer to the RTP pipeline.
 */
221
static void
222 223
rtp_pipeline_run (rtp_pipeline * p)
{
224
  GstFlowReturn flow_ret;
225
  GMainLoop *mainloop = NULL;
226
  GstBus *bus;
227
  gint i, j;
228

229 230 231 232 233 234 235 236 237 238 239 240
  /* Check parameters. */
  if (p == NULL) {
    return;
  }

  /* Create mainloop. */
  mainloop = g_main_loop_new (NULL, FALSE);
  if (!mainloop) {
    return;
  }

  /* Add bus callback. */
241
  bus = gst_pipeline_get_bus (GST_PIPELINE (p->pipeline));
242 243 244 245 246 247 248

  gst_bus_add_watch (bus, rtp_bus_callback, (gpointer) mainloop);
  gst_object_unref (bus);

  /* Set pipeline to PLAYING. */
  gst_element_set_state (p->pipeline, GST_STATE_PLAYING);

249
  /* Push data into the pipeline */
250
  for (i = 0; i < LOOP_COUNT; i++) {
251 252 253 254 255
    const guint8 *data = p->frame_data;

    for (j = 0; j < p->frame_count; j++) {
      GstBuffer *buf;

Wim Taymans's avatar
Wim Taymans committed
256
      buf =
257 258 259
          gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
          (guint8 *) data, p->frame_data_size, 0, p->frame_data_size, NULL,
          NULL);
260 261 262 263 264 265

      g_signal_emit_by_name (p->appsrc, "push-buffer", buf, &flow_ret);
      fail_unless_equals_int (flow_ret, GST_FLOW_OK);
      data += p->frame_data_size;

      gst_buffer_unref (buf);
266 267 268
    }
  }

269 270
  g_signal_emit_by_name (p->appsrc, "end-of-stream", &flow_ret);

271 272 273 274 275 276 277 278 279 280
  /* Run mainloop. */
  g_main_loop_run (mainloop);

  /* Set pipeline to NULL. */
  gst_element_set_state (p->pipeline, GST_STATE_NULL);

  /* Release mainloop. */
  g_main_loop_unref (mainloop);
}

281 282 283 284 285 286 287 288
/*
 * Enables buffer lists. Sets the buffer-list property of the payloader
 * and adds a chain_list_function to the depayloader.
 * @param p Pointer to the RTP pipeline.
 */
static void
rtp_pipeline_enable_lists (rtp_pipeline * p, guint mtu_size)
{
289 290
  GstPad *pad;

291 292 293 294 295 296 297 298 299
  /* use buffer lists */
  g_object_set (p->rtppay, "buffer-list", TRUE, NULL);

  /* set mtu size if needed */
  if (mtu_size) {
    g_object_set (p->rtppay, "mtu", mtu_size, NULL);
  }

  /* Add chain list function for the buffer list tests */
300 301 302 303
  pad = gst_element_get_static_pad (p->rtpdepay, "sink");
  gst_pad_set_chain_list_function (pad,
      GST_DEBUG_FUNCPTR (rtp_pipeline_chain_list));
  gst_object_unref (pad);
304 305
}

306 307 308 309 310 311 312 313
/*
 * Creates the RTP pipeline and runs the test using the pipeline.
 * @param frame_data Pointer to the frame data which is used to pass thru pay/depayloaders.
 * @param frame_data_size Frame data size in bytes.
 * @param frame_count Frame count.
 * @param filtercaps Caps filters.
 * @param pay Payloader name.
 * @param depay Depayloader name.
314 315 316
 * @bytes_sent bytes that will be sent, used when testing buffer lists
 * @mtu_size set mtu size when testing lists
 * @use_lists enable buffer lists
317
 */
318
static void
319 320
rtp_pipeline_test (const guint8 * frame_data, int frame_data_size,
    int frame_count, const char *filtercaps, const char *pay, const char *depay,
321
    guint bytes_sent, guint mtu_size, gboolean use_lists)
322 323 324 325 326
{
  /* Create RTP pipeline. */
  rtp_pipeline *p =
      rtp_pipeline_create (frame_data, frame_data_size, frame_count, filtercaps,
      pay, depay);
327

328 329 330 331
  if (p == NULL) {
    return;
  }

332 333 334 335 336
  if (use_lists) {
    rtp_pipeline_enable_lists (p, mtu_size);
    chain_list_bytes_received = 0;
  }

337 338 339 340 341
  /* Run RTP pipeline. */
  rtp_pipeline_run (p);

  /* Destroy RTP pipeline. */
  rtp_pipeline_destroy (p);
342 343 344 345 346

  if (use_lists) {
    /* 'next NAL' indicator is 4 bytes */
    fail_if (chain_list_bytes_received != bytes_sent * LOOP_COUNT);
  }
347 348
}

349
static const guint8 rtp_ilbc_frame_data[] =
350
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
351 352
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
353

354
static int rtp_ilbc_frame_data_size = 20;
355

356 357 358 359 360 361
static int rtp_ilbc_frame_count = 1;

GST_START_TEST (rtp_ilbc)
{
  rtp_pipeline_test (rtp_ilbc_frame_data, rtp_ilbc_frame_data_size,
      rtp_ilbc_frame_count, "audio/x-iLBC,mode=20", "rtpilbcpay",
362
      "rtpilbcdepay", 0, 0, FALSE);
363
}
364 365

GST_END_TEST;
366
static const guint8 rtp_gsm_frame_data[] =
367
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
368 369
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
370

371
static int rtp_gsm_frame_data_size = 20;
372

373 374 375 376 377 378
static int rtp_gsm_frame_count = 1;

GST_START_TEST (rtp_gsm)
{
  rtp_pipeline_test (rtp_gsm_frame_data, rtp_gsm_frame_data_size,
      rtp_gsm_frame_count, "audio/x-gsm,rate=8000,channels=1", "rtpgsmpay",
379
      "rtpgsmdepay", 0, 0, FALSE);
380
}
381 382

GST_END_TEST;
383
static const guint8 rtp_amr_frame_data[] =
Wim Taymans's avatar
Wim Taymans committed
384 385 386
    { 0x3c, 0x24, 0x03, 0xb3, 0x48, 0x10, 0x68, 0x46, 0x6c, 0xec, 0x03,
  0x7a, 0x37, 0x16, 0x41, 0x41, 0xc0, 0x00, 0x0d, 0xcd, 0x12, 0xed,
  0xad, 0x80, 0x00, 0x00, 0x11, 0x31, 0x00, 0x00, 0x0d, 0xa0
387
};
388

Wim Taymans's avatar
Wim Taymans committed
389
static int rtp_amr_frame_data_size = 32;
390

391 392 393 394 395 396
static int rtp_amr_frame_count = 1;

GST_START_TEST (rtp_amr)
{
  rtp_pipeline_test (rtp_amr_frame_data, rtp_amr_frame_data_size,
      rtp_amr_frame_count, "audio/AMR,channels=1,rate=8000", "rtpamrpay",
397
      "rtpamrdepay", 0, 0, FALSE);
398
}
399 400

GST_END_TEST;
401
static const guint8 rtp_pcma_frame_data[] =
402
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403 404
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
405

406
static int rtp_pcma_frame_data_size = 20;
407

408 409 410 411 412 413
static int rtp_pcma_frame_count = 1;

GST_START_TEST (rtp_pcma)
{
  rtp_pipeline_test (rtp_pcma_frame_data, rtp_pcma_frame_data_size,
      rtp_pcma_frame_count, "audio/x-alaw,channels=1,rate=8000", "rtppcmapay",
414
      "rtppcmadepay", 0, 0, FALSE);
415
}
416 417

GST_END_TEST;
418
static const guint8 rtp_pcmu_frame_data[] =
419
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
420 421
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
422

423
static int rtp_pcmu_frame_data_size = 20;
424

425 426 427 428 429 430
static int rtp_pcmu_frame_count = 1;

GST_START_TEST (rtp_pcmu)
{
  rtp_pipeline_test (rtp_pcmu_frame_data, rtp_pcmu_frame_data_size,
      rtp_pcmu_frame_count, "audio/x-mulaw,channels=1,rate=8000", "rtppcmupay",
431
      "rtppcmudepay", 0, 0, FALSE);
432
}
433 434

GST_END_TEST;
435
static const guint8 rtp_mpa_frame_data[] =
436
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
437 438
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
439

440
static int rtp_mpa_frame_data_size = 20;
441

442 443 444 445 446
static int rtp_mpa_frame_count = 1;

GST_START_TEST (rtp_mpa)
{
  rtp_pipeline_test (rtp_mpa_frame_data, rtp_mpa_frame_data_size,
447 448
      rtp_mpa_frame_count, "audio/mpeg,mpegversion=1", "rtpmpapay",
      "rtpmpadepay", 0, 0, FALSE);
449
}
450 451

GST_END_TEST;
452
static const guint8 rtp_h263_frame_data[] =
453
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
454 455
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
456

457
static int rtp_h263_frame_data_size = 20;
458

459 460 461 462 463
static int rtp_h263_frame_count = 1;

GST_START_TEST (rtp_h263)
{
  rtp_pipeline_test (rtp_h263_frame_data, rtp_h263_frame_data_size,
464
      rtp_h263_frame_count, "video/x-h263,variant=(string)itu,h263version=h263",
465
      "rtph263pay", "rtph263depay", 0, 0, FALSE);
466
}
467 468

GST_END_TEST;
469
static const guint8 rtp_h263p_frame_data[] =
470
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
471 472
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
473

474
static int rtp_h263p_frame_data_size = 20;
475

476 477 478 479 480
static int rtp_h263p_frame_count = 1;

GST_START_TEST (rtp_h263p)
{
  rtp_pipeline_test (rtp_h263p_frame_data, rtp_h263p_frame_data_size,
481
      rtp_h263p_frame_count, "video/x-h263,variant=(string)itu", "rtph263ppay",
482
      "rtph263pdepay", 0, 0, FALSE);
483
}
484 485

GST_END_TEST;
486
static const guint8 rtp_h264_frame_data[] =
487
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488 489
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
490

491
static int rtp_h264_frame_data_size = 20;
492

493 494 495 496
static int rtp_h264_frame_count = 1;

GST_START_TEST (rtp_h264)
{
497
  /* FIXME 0.11: fully specify h264 caps (and make payloader check) */
498
  rtp_pipeline_test (rtp_h264_frame_data, rtp_h264_frame_data_size,
499 500 501
      rtp_h264_frame_count,
      "video/x-h264,stream-format=(string)byte-stream,alignment=(string)nal",
      "rtph264pay", "rtph264depay", 0, 0, FALSE);
502 503 504
}

GST_END_TEST;
505
static const guint8 rtp_h264_list_lt_mtu_frame_data[] =
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
    /* not packetized, next NAL starts with 0001 */
{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  0xad, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00
};

static int rtp_h264_list_lt_mtu_frame_data_size = 16;

static int rtp_h264_list_lt_mtu_frame_count = 2;

/* NAL = 4 bytes */
static int rtp_h264_list_lt_mtu_bytes_sent = 2 * (16 - 4);

static int rtp_h264_list_lt_mtu_mtu_size = 1024;

GST_START_TEST (rtp_h264_list_lt_mtu)
{
523
  /* FIXME 0.11: fully specify h264 caps (and make payloader check) */
524 525
  rtp_pipeline_test (rtp_h264_list_lt_mtu_frame_data,
      rtp_h264_list_lt_mtu_frame_data_size, rtp_h264_list_lt_mtu_frame_count,
526 527
      "video/x-h264,stream-format=(string)byte-stream,alignment=(string)nal",
      "rtph264pay", "rtph264depay",
528 529 530 531
      rtp_h264_list_lt_mtu_bytes_sent, rtp_h264_list_lt_mtu_mtu_size, TRUE);
}

GST_END_TEST;
532
static const guint8 rtp_h264_list_gt_mtu_frame_data[] =
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    /* not packetized, next NAL starts with 0001 */
{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static int rtp_h264_list_gt_mtu_frame_data_size = 64;

static int rtp_h264_list_gt_mtu_frame_count = 1;

/* NAL = 4 bytes. When data does not fit into 1 mtu, 1 byte will be skipped */
static int rtp_h264_list_gt_mtu_bytes_sent = 1 * (64 - 4) - 1;

static int rtp_h264_list_gt_mtu_mty_size = 28;

GST_START_TEST (rtp_h264_list_gt_mtu)
{
553
  /* FIXME 0.11: fully specify h264 caps (and make payloader check) */
554 555
  rtp_pipeline_test (rtp_h264_list_gt_mtu_frame_data,
      rtp_h264_list_gt_mtu_frame_data_size, rtp_h264_list_gt_mtu_frame_count,
556 557
      "video/x-h264,stream-format=(string)byte-stream,alignment=(string)nal",
      "rtph264pay", "rtph264depay",
558
      rtp_h264_list_gt_mtu_bytes_sent, rtp_h264_list_gt_mtu_mty_size, TRUE);
559
}
560 561

GST_END_TEST;
562
static const guint8 rtp_L16_frame_data[] =
563
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
564 565
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
566

567
static int rtp_L16_frame_data_size = 20;
568

569 570 571 572 573 574
static int rtp_L16_frame_count = 1;

GST_START_TEST (rtp_L16)
{
  rtp_pipeline_test (rtp_L16_frame_data, rtp_L16_frame_data_size,
      rtp_L16_frame_count,
575
      "audio/x-raw,format=S16BE,rate=1,channels=1,layout=(string)interleaved",
576
      "rtpL16pay", "rtpL16depay", 0, 0, FALSE);
577
}
578 579

GST_END_TEST;
580
static const guint8 rtp_mp2t_frame_data[] =
581
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
582 583
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
584

585
static int rtp_mp2t_frame_data_size = 20;
586

587 588 589 590 591 592
static int rtp_mp2t_frame_count = 1;

GST_START_TEST (rtp_mp2t)
{
  rtp_pipeline_test (rtp_mp2t_frame_data, rtp_mp2t_frame_data_size,
      rtp_mp2t_frame_count, "video/mpegts,packetsize=188,systemstream=true",
593
      "rtpmp2tpay", "rtpmp2tdepay", 0, 0, FALSE);
594
}
595 596

GST_END_TEST;
597
static const guint8 rtp_mp4v_frame_data[] =
598
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
599 600
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
601

602
static int rtp_mp4v_frame_data_size = 20;
603

604 605 606 607 608 609
static int rtp_mp4v_frame_count = 1;

GST_START_TEST (rtp_mp4v)
{
  rtp_pipeline_test (rtp_mp4v_frame_data, rtp_mp4v_frame_data_size,
      rtp_mp4v_frame_count, "video/mpeg,mpegversion=4,systemstream=false",
610 611 612 613
      "rtpmp4vpay", "rtpmp4vdepay", 0, 0, FALSE);
}

GST_END_TEST;
614
static const guint8 rtp_mp4v_list_frame_data[] =
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static int rtp_mp4v_list_frame_data_size = 20;

static int rtp_mp4v_list_frame_count = 1;

static int rtp_mp4v_list_bytes_sent = 1 * 20;

GST_START_TEST (rtp_mp4v_list)
{
  rtp_pipeline_test (rtp_mp4v_list_frame_data, rtp_mp4v_list_frame_data_size,
      rtp_mp4v_list_frame_count,
      "video/mpeg,mpegversion=4,codec_data=(buffer)000001b001",
      "rtpmp4vpay", "rtpmp4vdepay", rtp_mp4v_list_bytes_sent, 0, TRUE);
631
}
632 633

GST_END_TEST;
634
static const guint8 rtp_mp4g_frame_data[] =
635
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
636 637
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
638

639
static int rtp_mp4g_frame_data_size = 20;
640

641 642 643 644 645
static int rtp_mp4g_frame_count = 1;

GST_START_TEST (rtp_mp4g)
{
  rtp_pipeline_test (rtp_mp4g_frame_data, rtp_mp4g_frame_data_size,
Wim Taymans's avatar
Wim Taymans committed
646 647
      rtp_mp4g_frame_count,
      "video/mpeg,mpegversion=4,codec_data=(buffer)000001b001", "rtpmp4gpay",
648
      "rtpmp4gdepay", 0, 0, FALSE);
649
}
650 651

GST_END_TEST;
652
static const guint8 rtp_theora_frame_data[] =
653
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
654 655
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
656

657
static int rtp_theora_frame_data_size = 20;
658

659 660 661 662 663 664
static int rtp_theora_frame_count = 1;

GST_START_TEST (rtp_theora)
{
  rtp_pipeline_test (rtp_theora_frame_data, rtp_theora_frame_data_size,
      rtp_theora_frame_count, "video/x-theora", "rtptheorapay",
665
      "rtptheoradepay", 0, 0, FALSE);
666
}
667 668

GST_END_TEST;
669
static const guint8 rtp_vorbis_frame_data[] =
670
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
671 672
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
673

674
static int rtp_vorbis_frame_data_size = 20;
675

676 677 678 679 680 681
static int rtp_vorbis_frame_count = 1;

GST_START_TEST (rtp_vorbis)
{
  rtp_pipeline_test (rtp_vorbis_frame_data, rtp_vorbis_frame_data_size,
      rtp_vorbis_frame_count, "audio/x-vorbis", "rtpvorbispay",
682 683 684 685
      "rtpvorbisdepay", 0, 0, FALSE);
}

GST_END_TEST;
686
static const guint8 rtp_jpeg_frame_data[] =
687
    { /* SOF */ 0xFF, 0xC0, 0x00, 0x11, 0x08, 0x00, 0x08, 0x00, 0x08,
Wim Taymans's avatar
Wim Taymans committed
688 689 690 691 692 693 694 695 696 697
  0x03, 0x00, 0x21, 0x08, 0x01, 0x11, 0x08, 0x02, 0x11, 0x08,
  /* DQT */ 0xFF, 0xDB, 0x00, 0x43, 0x08,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
698 699 700
  /* DATA */ 0x00, 0x00, 0x00, 0x00, 0x00
};

Wim Taymans's avatar
Wim Taymans committed
701
static int rtp_jpeg_frame_data_size = sizeof (rtp_jpeg_frame_data);
702 703 704 705 706 707 708 709 710 711 712

static int rtp_jpeg_frame_count = 1;

GST_START_TEST (rtp_jpeg)
{
  rtp_pipeline_test (rtp_jpeg_frame_data, rtp_jpeg_frame_data_size,
      rtp_jpeg_frame_count, "video/x-jpeg,height=640,width=480", "rtpjpegpay",
      "rtpjpegdepay", 0, 0, FALSE);
}

GST_END_TEST;
713
static const guint8 rtp_jpeg_list_frame_data[] =
714
    { /* SOF */ 0xFF, 0xC0, 0x00, 0x11, 0x08, 0x00, 0x08, 0x00, 0x08,
Wim Taymans's avatar
Wim Taymans committed
715 716 717 718 719 720 721 722 723 724
  0x03, 0x00, 0x21, 0x08, 0x01, 0x11, 0x08, 0x02, 0x11, 0x08,
  /* DQT */ 0xFF, 0xDB, 0x00, 0x43, 0x08,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
725 726 727
  /* DATA */ 0x00, 0x00, 0x00, 0x00, 0x00
};

Wim Taymans's avatar
Wim Taymans committed
728
static int rtp_jpeg_list_frame_data_size = sizeof (rtp_jpeg_list_frame_data);
729 730 731

static int rtp_jpeg_list_frame_count = 1;

Wim Taymans's avatar
Wim Taymans committed
732
static int rtp_jpeg_list_bytes_sent = 1 * sizeof (rtp_jpeg_list_frame_data);
733 734 735 736 737 738

GST_START_TEST (rtp_jpeg_list)
{
  rtp_pipeline_test (rtp_jpeg_list_frame_data, rtp_jpeg_list_frame_data_size,
      rtp_jpeg_list_frame_count, "video/x-jpeg,height=640,width=480",
      "rtpjpegpay", "rtpjpegdepay", rtp_jpeg_list_bytes_sent, 0, TRUE);
739 740
}

741
GST_END_TEST;
742
static const guint8 rtp_g729_frame_data[] =
743 744 745 746 747 748 749 750 751 752 753
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static int rtp_g729_frame_data_size = 22;

static int rtp_g729_frame_count = 1;

GST_START_TEST (rtp_g729)
{
  rtp_pipeline_test (rtp_g729_frame_data, rtp_g729_frame_data_size,
754
      rtp_g729_frame_count, "audio/G729,rate=8000,channels=1", "rtpg729pay",
755 756 757 758 759
      "rtpg729depay", 0, 0, FALSE);
}

GST_END_TEST;

760 761 762 763 764
/*
 * Creates the test suite.
 *
 * Returns: pointer to the test suite.
 */
765
static Suite *
766
rtp_payloading_suite (void)
767 768
{
  Suite *s = suite_create ("rtp_data_test");
769

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
  TCase *tc_chain = tcase_create ("linear");

  /* Set timeout to 60 seconds. */
  tcase_set_timeout (tc_chain, 60);

  suite_add_tcase (s, tc_chain);
  tcase_add_test (tc_chain, rtp_ilbc);
  tcase_add_test (tc_chain, rtp_gsm);
  tcase_add_test (tc_chain, rtp_amr);
  tcase_add_test (tc_chain, rtp_pcma);
  tcase_add_test (tc_chain, rtp_pcmu);
  tcase_add_test (tc_chain, rtp_mpa);
  tcase_add_test (tc_chain, rtp_h263);
  tcase_add_test (tc_chain, rtp_h263p);
  tcase_add_test (tc_chain, rtp_h264);
785 786
  tcase_add_test (tc_chain, rtp_h264_list_lt_mtu);
  tcase_add_test (tc_chain, rtp_h264_list_gt_mtu);
787 788 789
  tcase_add_test (tc_chain, rtp_L16);
  tcase_add_test (tc_chain, rtp_mp2t);
  tcase_add_test (tc_chain, rtp_mp4v);
790
  tcase_add_test (tc_chain, rtp_mp4v_list);
791 792 793
  tcase_add_test (tc_chain, rtp_mp4g);
  tcase_add_test (tc_chain, rtp_theora);
  tcase_add_test (tc_chain, rtp_vorbis);
794 795
  tcase_add_test (tc_chain, rtp_jpeg);
  tcase_add_test (tc_chain, rtp_jpeg_list);
796
  tcase_add_test (tc_chain, rtp_g729);
797 798 799
  return s;
}

800
GST_CHECK_MAIN (rtp_payloading)