Blame tests/check/elements/rawvideoparse.c

Packit 971217
/* GStreamer
Packit 971217
 *
Packit 971217
 * unit test for rawvideoparse
Packit 971217
 *
Packit 971217
 * Copyright (C) <2016> Carlos Rafael Giani <dv at pseudoterminal dot org>
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
#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/video/video.h>
Packit 971217
Packit 971217
/* The checks use as test data an 8x8 Y444 image, with 25 Hz framerate. In the
Packit 971217
 * sink caps configuration, the stride is 8 bytes, and the frames are tightly
Packit 971217
 * packed together. In the properties configuration, the stride is 10 bytes, the
Packit 971217
 * planes aren't tightly packed (there are 20 bytes between the planes), and the
Packit 971217
 * frames overall have padding between them (the overall frame size is
Packit 971217
 * stride (10) * height (8) * num-planes (3) + bytes-between-planes (20) * 2
Packit 971217
 * = 280 bytes, and the frame stride is 500 bytes, so there are 220 bytes of
Packit 971217
 * extra padding between frames).
Packit 971217
 *
Packit 971217
 * In the test 8x8 frame, the pixels are all set to #000000, except for two
Packit 971217
 * pixels: (xofs+1 yofs+0) is set to #8899AA, (xofs+0 yofs+1) is set to #112233.
Packit 971217
 * The first frame uses the offsets xofs=0 yofs=0. The second frame uses
Packit 971217
 * xofs=1 yofs=0 etc. For each configuration, there is a separate set of frames,
Packit 971217
 * each stored in the GstAdapter in the Context struct.
Packit 971217
 *
Packit 971217
 * During the tests, as part of the checks, the pixels are verified to have the
Packit 971217
 * right values. The pattern of the pixels was chosen to easily detect stride
Packit 971217
 * errors, incorrect plane offsets etc.
Packit 971217
 */
Packit 971217
Packit 971217
#define TEST_WIDTH 8
Packit 971217
#define TEST_HEIGHT 8
Packit 971217
#define TEST_FRAMERATE_N 25
Packit 971217
#define TEST_FRAMERATE_D 1
Packit 971217
#define TEST_FRAME_FORMAT GST_VIDEO_FORMAT_Y444
Packit 971217
#define NUM_TEST_PLANES 3
Packit 971217
Packit 971217
#define PROP_CTX_PLANE_STRIDE 10
Packit 971217
#define PROP_CTX_FRAME_SIZE 500
Packit 971217
#define PROP_CTX_PLANE_PADDING 20
Packit 971217
#define PROP_CTX_PLANE_SIZE (PROP_CTX_PLANE_STRIDE * TEST_HEIGHT + PROP_CTX_PLANE_PADDING)
Packit 971217
Packit 971217
GstElement *rawvideoparse;
Packit 971217
Packit 971217
/* For ease of programming we use globals to keep refs for our floating
Packit 971217
 * src and sink pads we create; otherwise we always have to do get_pad,
Packit 971217
 * get_peer, and then remove references in every test function */
Packit 971217
static GstPad *mysrcpad, *mysinkpad;
Packit 971217
Packit 971217
typedef struct
Packit 971217
{
Packit 971217
  GstAdapter *data;
Packit 971217
  guint plane_stride;
Packit 971217
  guint plane_size;
Packit 971217
}
Packit 971217
Context;
Packit 971217
Packit 971217
static Context properties_ctx, sinkcaps_ctx;
Packit 971217
Packit 971217
static void
Packit 971217
set_pixel (Context const *ctx, guint8 * pixels, guint x, guint y, guint32 color)
Packit 971217
{
Packit 971217
  guint i;
Packit 971217
  guint ofs = y * ctx->plane_stride + x;
Packit 971217
  for (i = 0; i < NUM_TEST_PLANES; ++i)
Packit 971217
    pixels[ctx->plane_size * i + ofs] =
Packit 971217
        (color >> ((NUM_TEST_PLANES - 1 - i) * 8)) & 0xFF;
Packit 971217
}
Packit 971217
Packit 971217
static guint32
Packit 971217
get_pixel (Context const *ctx, const guint8 * pixels, guint x, guint y)
Packit 971217
{
Packit 971217
  guint i;
Packit 971217
  guint ofs = y * ctx->plane_stride + x;
Packit 971217
  guint32 color = 0;
Packit 971217
  for (i = 0; i < NUM_TEST_PLANES; ++i)
Packit 971217
    color |=
Packit 971217
        ((guint32) (pixels[ctx->plane_size * i + ofs])) << ((NUM_TEST_PLANES -
Packit 971217
            1 - i) * 8);
Packit 971217
  return color;
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
fill_test_pattern (Context const *ctx, GstBuffer * buffer, guint xofs,
Packit 971217
    guint yofs)
Packit 971217
{
Packit 971217
  guint8 *pixels;
Packit 971217
  GstMapInfo map_info;
Packit 971217
Packit 971217
  gst_buffer_map (buffer, &map_info, GST_MAP_WRITE);
Packit 971217
  pixels = map_info.data;
Packit 971217
Packit 971217
  memset (pixels, 0, ctx->plane_size * NUM_TEST_PLANES);
Packit 971217
  set_pixel (ctx, pixels, 1 + xofs, 0 + yofs, 0x8899AA);
Packit 971217
  set_pixel (ctx, pixels, 0 + xofs, 1 + yofs, 0x112233);
Packit 971217
Packit 971217
  gst_buffer_unmap (buffer, &map_info);
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
check_test_pattern (Context const *ctx, GstBuffer * buffer, guint xofs,
Packit 971217
    guint yofs)
Packit 971217
{
Packit 971217
  guint x, y;
Packit 971217
  guint8 *pixels;
Packit 971217
  GstMapInfo map_info;
Packit 971217
Packit 971217
  gst_buffer_map (buffer, &map_info, GST_MAP_READ);
Packit 971217
  pixels = map_info.data;
Packit 971217
Packit 971217
  fail_unless_equals_uint64_hex (get_pixel (ctx, pixels, 1 + xofs, 0 + yofs),
Packit 971217
      0x8899AA);
Packit 971217
  fail_unless_equals_uint64_hex (get_pixel (ctx, pixels, 0 + xofs, 1 + yofs),
Packit 971217
      0x112233);
Packit 971217
Packit 971217
  for (y = 0; y < TEST_HEIGHT; ++y) {
Packit 971217
    for (x = 0; x < TEST_WIDTH; ++x) {
Packit 971217
      if ((x == (1 + xofs) && y == (0 + yofs)) || (x == (0 + xofs)
Packit 971217
              && y == (1 + yofs)))
Packit 971217
        continue;
Packit 971217
Packit 971217
      fail_unless_equals_uint64_hex (get_pixel (ctx, pixels, x, y), 0x000000);
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  gst_buffer_unmap (buffer, &map_info);
Packit 971217
}
Packit 971217
Packit 971217
Packit 971217
static void
Packit 971217
setup_rawvideoparse (gboolean use_sink_caps,
Packit 971217
    gboolean set_properties, GstCaps * incaps, GstFormat format)
Packit 971217
{
Packit 971217
  guint i;
Packit 971217
Packit 971217
Packit 971217
  /* Setup the rawvideoparse element and the pads */
Packit 971217
Packit 971217
  static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
Packit 971217
      GST_PAD_SINK,
Packit 971217
      GST_PAD_ALWAYS,
Packit 971217
      GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL))
Packit 971217
      );
Packit 971217
  static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
Packit 971217
      GST_PAD_SRC,
Packit 971217
      GST_PAD_ALWAYS,
Packit 971217
      GST_STATIC_CAPS_ANY);
Packit 971217
Packit 971217
  rawvideoparse = gst_check_setup_element ("rawvideoparse");
Packit 971217
Packit 971217
  properties_ctx.plane_stride = PROP_CTX_PLANE_STRIDE;
Packit 971217
  properties_ctx.plane_size = PROP_CTX_PLANE_SIZE;
Packit 971217
  properties_ctx.data = gst_adapter_new ();
Packit 971217
Packit 971217
  sinkcaps_ctx.plane_stride = TEST_WIDTH;
Packit 971217
  sinkcaps_ctx.plane_size = TEST_WIDTH * TEST_HEIGHT;
Packit 971217
  sinkcaps_ctx.data = gst_adapter_new ();
Packit 971217
Packit 971217
  g_object_set (G_OBJECT (rawvideoparse), "use-sink-caps", use_sink_caps, NULL);
Packit 971217
  if (set_properties) {
Packit 971217
    GValue plane_offsets = G_VALUE_INIT;
Packit 971217
    GValue plane_strides = G_VALUE_INIT;
Packit 971217
    GValue val = G_VALUE_INIT;
Packit 971217
Packit 971217
    g_value_init (&val, G_TYPE_INT);
Packit 971217
    g_value_init (&plane_offsets, GST_TYPE_ARRAY);
Packit 971217
    g_value_init (&plane_strides, GST_TYPE_ARRAY);
Packit 971217
Packit 971217
    for (i = 0; i < NUM_TEST_PLANES; ++i) {
Packit 971217
      g_value_set_int (&val, properties_ctx.plane_size * i);
Packit 971217
      gst_value_array_append_value (&plane_offsets, &val;;
Packit 971217
    }
Packit 971217
Packit 971217
    for (i = 0; i < NUM_TEST_PLANES; ++i) {
Packit 971217
      g_value_set_int (&val, properties_ctx.plane_stride);
Packit 971217
      gst_value_array_append_value (&plane_strides, &val;;
Packit 971217
    }
Packit 971217
Packit 971217
    g_value_unset (&val;;
Packit 971217
Packit 971217
    g_object_set (G_OBJECT (rawvideoparse), "width", TEST_WIDTH, "height",
Packit 971217
        TEST_HEIGHT, "frame-size", PROP_CTX_FRAME_SIZE, "framerate",
Packit 971217
        TEST_FRAMERATE_N, TEST_FRAMERATE_D, "format", TEST_FRAME_FORMAT, NULL);
Packit 971217
    g_object_set_property (G_OBJECT (rawvideoparse), "plane-offsets",
Packit 971217
        &plane_offsets);
Packit 971217
    g_object_set_property (G_OBJECT (rawvideoparse), "plane-strides",
Packit 971217
        &plane_strides);
Packit 971217
Packit 971217
    g_value_unset (&plane_offsets);
Packit 971217
    g_value_unset (&plane_strides);
Packit 971217
  }
Packit 971217
Packit 971217
  /* Check that the plane stride/offset values are correct */
Packit 971217
  {
Packit 971217
    GValue plane_offsets_array = G_VALUE_INIT;
Packit 971217
    GValue plane_strides_array = G_VALUE_INIT;
Packit 971217
Packit 971217
    /* By default, 320x240 i420 is used as format */
Packit 971217
    guint plane_offsets[3] = { 0, 76800, 96000 };
Packit 971217
    guint plane_strides[3] = { 320, 160, 160 };
Packit 971217
Packit 971217
    g_value_init (&plane_offsets_array, GST_TYPE_ARRAY);
Packit 971217
    g_value_init (&plane_strides_array, GST_TYPE_ARRAY);
Packit 971217
Packit 971217
    if (set_properties) {
Packit 971217
      /* When properties are explicitely set, we use Y444 as video format,
Packit 971217
       * so in that case, plane stride values are all the same */
Packit 971217
      plane_offsets[0] = properties_ctx.plane_size * 0;
Packit 971217
      plane_offsets[1] = properties_ctx.plane_size * 1;
Packit 971217
      plane_offsets[2] = properties_ctx.plane_size * 2;
Packit 971217
      plane_strides[0] = plane_strides[1] = plane_strides[2] =
Packit 971217
          properties_ctx.plane_stride;
Packit 971217
    }
Packit 971217
Packit 971217
    g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets",
Packit 971217
        &plane_offsets_array);
Packit 971217
    g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides",
Packit 971217
        &plane_strides_array);
Packit 971217
Packit 971217
    fail_unless (gst_value_array_get_size (&plane_offsets_array) ==
Packit 971217
        gst_value_array_get_size (&plane_strides_array));
Packit 971217
Packit 971217
    for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) {
Packit 971217
      const GValue *gvalue;
Packit 971217
Packit 971217
      gvalue = gst_value_array_get_value (&plane_offsets_array, i);
Packit 971217
      fail_unless (gvalue != NULL);
Packit 971217
      fail_unless_equals_uint64 (plane_offsets[i], g_value_get_int (gvalue));
Packit 971217
Packit 971217
      gvalue = gst_value_array_get_value (&plane_strides_array, i);
Packit 971217
      fail_unless (gvalue != NULL);
Packit 971217
      fail_unless_equals_uint64 (plane_strides[i], g_value_get_int (gvalue));
Packit 971217
    }
Packit 971217
Packit 971217
    g_value_unset (&plane_offsets_array);
Packit 971217
    g_value_unset (&plane_strides_array);
Packit 971217
  }
Packit 971217
Packit 971217
  fail_unless (gst_element_set_state (rawvideoparse,
Packit 971217
          GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
Packit 971217
      "could not set to paused");
Packit 971217
Packit 971217
  mysrcpad = gst_check_setup_src_pad (rawvideoparse, &srctemplate);
Packit 971217
  mysinkpad = gst_check_setup_sink_pad (rawvideoparse, &sinktemplate);
Packit 971217
Packit 971217
  gst_pad_set_active (mysrcpad, TRUE);
Packit 971217
  gst_pad_set_active (mysinkpad, TRUE);
Packit 971217
Packit 971217
  gst_check_setup_events (mysrcpad, rawvideoparse, incaps, format);
Packit 971217
  if (incaps)
Packit 971217
    gst_caps_unref (incaps);
Packit 971217
Packit 971217
Packit 971217
  /* Fill the adapters with test frames */
Packit 971217
Packit 971217
  for (i = 0; i < 10; ++i) {
Packit 971217
    GstBuffer *buffer =
Packit 971217
        gst_buffer_new_allocate (NULL, PROP_CTX_FRAME_SIZE, NULL);
Packit 971217
    gst_buffer_memset (buffer, 0, 0xCC, gst_buffer_get_size (buffer));
Packit 971217
    fill_test_pattern (&properties_ctx, buffer, i, 0);
Packit 971217
    gst_adapter_push (properties_ctx.data, buffer);
Packit 971217
  }
Packit 971217
Packit 971217
  for (i = 0; i < 10; ++i) {
Packit 971217
    GstBuffer *buffer =
Packit 971217
        gst_buffer_new_allocate (NULL, sinkcaps_ctx.plane_size * 3, NULL);
Packit 971217
    gst_buffer_memset (buffer, 0, 0xCC, gst_buffer_get_size (buffer));
Packit 971217
    fill_test_pattern (&sinkcaps_ctx, buffer, i, 0);
Packit 971217
    gst_adapter_push (sinkcaps_ctx.data, buffer);
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
cleanup_rawvideoparse (void)
Packit 971217
{
Packit 971217
  int num_buffers, i;
Packit 971217
Packit 971217
  gst_pad_set_active (mysrcpad, FALSE);
Packit 971217
  gst_pad_set_active (mysinkpad, FALSE);
Packit 971217
  gst_check_teardown_src_pad (rawvideoparse);
Packit 971217
  gst_check_teardown_sink_pad (rawvideoparse);
Packit 971217
  gst_check_teardown_element (rawvideoparse);
Packit 971217
Packit 971217
  g_object_unref (G_OBJECT (properties_ctx.data));
Packit 971217
  g_object_unref (G_OBJECT (sinkcaps_ctx.data));
Packit 971217
Packit 971217
  if (buffers != NULL) {
Packit 971217
    num_buffers = g_list_length (buffers);
Packit 971217
    for (i = 0; i < num_buffers; ++i) {
Packit 971217
      GstBuffer *buf = GST_BUFFER (buffers->data);
Packit 971217
      buffers = g_list_remove (buffers, buf);
Packit 971217
      gst_buffer_unref (buf);
Packit 971217
    }
Packit 971217
Packit 971217
    g_list_free (buffers);
Packit 971217
    buffers = NULL;
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
push_data_and_check_output (Context * ctx, gsize num_in_bytes,
Packit 971217
    gsize expected_num_out_bytes, gint64 expected_pts, gint64 expected_dur,
Packit 971217
    guint expected_num_buffers_in_list, guint buf_idx, guint xofs, guint yofs)
Packit 971217
{
Packit 971217
  GstBuffer *inbuf, *outbuf;
Packit 971217
  guint num_buffers;
Packit 971217
Packit 971217
  /* Simulate upstream input by taking num_in_bytes bytes from the adapter */
Packit 971217
  inbuf = gst_adapter_take_buffer (ctx->data, num_in_bytes);
Packit 971217
  fail_unless (inbuf != NULL);
Packit 971217
Packit 971217
  /* Push the input data and check that the output buffers list grew as
Packit 971217
   * expected */
Packit 971217
  fail_unless (gst_pad_push (mysrcpad, inbuf) == GST_FLOW_OK);
Packit 971217
  num_buffers = g_list_length (buffers);
Packit 971217
  fail_unless_equals_int (num_buffers, expected_num_buffers_in_list);
Packit 971217
Packit 971217
  /* Take the output buffer */
Packit 971217
  outbuf = g_list_nth_data (buffers, buf_idx);
Packit 971217
  fail_unless (outbuf != NULL);
Packit 971217
Packit 971217
  /* Verify size, PTS, duration of the output buffer */
Packit 971217
  fail_unless_equals_uint64 (expected_num_out_bytes,
Packit 971217
      gst_buffer_get_size (outbuf));
Packit 971217
  fail_unless_equals_uint64 (expected_pts, GST_BUFFER_PTS (outbuf));
Packit 971217
  fail_unless_equals_uint64 (expected_dur, GST_BUFFER_DURATION (outbuf));
Packit 971217
Packit 971217
  /* Check that the pixels have the correct values */
Packit 971217
  check_test_pattern (ctx, outbuf, xofs, yofs);
Packit 971217
}
Packit 971217
Packit 971217
Packit 971217
GST_START_TEST (test_push_unaligned_data_properties_config)
Packit 971217
{
Packit 971217
  setup_rawvideoparse (FALSE, TRUE, NULL, GST_FORMAT_BYTES);
Packit 971217
Packit 971217
  /* Send in data buffers that are not aligned to multiples of the
Packit 971217
   * frame size (= sample size * num_channels). This tests if rawvideoparse
Packit 971217
   * aligns output data properly.
Packit 971217
   *
Packit 971217
   * The second line sends a buffer with multiple frames inside.
Packit 971217
   * rawvideoparse will then parse this buffer repeatedly (and prepend
Packit 971217
   * leftover data from the earlier parse iteration), explaining why
Packit 971217
   * all of a sudden there are 4 output buffers, compared to just one
Packit 971217
   * earlier. The output data is expected to be 280 bytes large, since this
Packit 971217
   * is the size of the actual frame, without extra padding at the end.
Packit 971217
   */
Packit 971217
  push_data_and_check_output (&properties_ctx, 511, 280, GST_MSECOND * 0,
Packit 971217
      GST_MSECOND * 40, 1, 0, 0, 0);
Packit 971217
  push_data_and_check_output (&properties_ctx, 1940, 280, GST_MSECOND * 40,
Packit 971217
      GST_MSECOND * 40, 4, 1, 1, 0);
Packit 971217
  push_data_and_check_output (&properties_ctx, 10, 280, GST_MSECOND * 80,
Packit 971217
      GST_MSECOND * 40, 4, 2, 2, 0);
Packit 971217
Packit 971217
  cleanup_rawvideoparse ();
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_push_unaligned_data_sink_caps_config)
Packit 971217
{
Packit 971217
  GstVideoInfo vinfo;
Packit 971217
  GstCaps *caps;
Packit 971217
Packit 971217
  /* This test is essentially the same as test_push_unaligned_data_properties_config,
Packit 971217
   * except that rawvideoparse uses the sink caps config instead of the property config.
Packit 971217
   * Also, the input sizes are different, since the sink caps config does not use extra
Packit 971217
   * padding between planes and does use a stride that directly corresponds to the width,
Packit 971217
   * resulting in smaller frame size (192 bytes vs 280 bytes). */
Packit 971217
Packit 971217
  gst_video_info_set_format (&vinfo, TEST_FRAME_FORMAT, TEST_WIDTH,
Packit 971217
      TEST_HEIGHT);
Packit 971217
  GST_VIDEO_INFO_FPS_N (&vinfo) = 25;
Packit 971217
  GST_VIDEO_INFO_FPS_D (&vinfo) = 1;
Packit 971217
  caps = gst_video_info_to_caps (&vinfo);
Packit 971217
Packit 971217
  setup_rawvideoparse (TRUE, FALSE, caps, GST_FORMAT_BYTES);
Packit 971217
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 250, 192, GST_MSECOND * 0,
Packit 971217
      GST_MSECOND * 40, 1, 0, 0, 0);
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 811, 192, GST_MSECOND * 40,
Packit 971217
      GST_MSECOND * 40, 5, 1, 1, 0);
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 10, 192, GST_MSECOND * 80,
Packit 971217
      GST_MSECOND * 40, 5, 2, 2, 0);
Packit 971217
Packit 971217
  cleanup_rawvideoparse ();
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_config_switch)
Packit 971217
{
Packit 971217
  GstVideoInfo vinfo;
Packit 971217
  GstCaps *caps;
Packit 971217
Packit 971217
  /* Start processing with the properties config active, then mid-stream switch to
Packit 971217
   * the sink caps config. Since the sink caps config does not use padding, its
Packit 971217
   * frame size is smaller. The buffer duration stays the same (since it only depends
Packit 971217
   * on the framerate), but the expected output buffer size is different). */
Packit 971217
Packit 971217
  gst_video_info_set_format (&vinfo, TEST_FRAME_FORMAT, TEST_WIDTH,
Packit 971217
      TEST_HEIGHT);
Packit 971217
  GST_VIDEO_INFO_FPS_N (&vinfo) = 25;
Packit 971217
  GST_VIDEO_INFO_FPS_D (&vinfo) = 1;
Packit 971217
  caps = gst_video_info_to_caps (&vinfo);
Packit 971217
Packit 971217
  setup_rawvideoparse (FALSE, TRUE, caps, GST_FORMAT_BYTES);
Packit 971217
Packit 971217
  /* Push in data with properties config active */
Packit 971217
  push_data_and_check_output (&properties_ctx, 500, 280, GST_MSECOND * 0,
Packit 971217
      GST_MSECOND * 40, 1, 0, 0, 0);
Packit 971217
  push_data_and_check_output (&properties_ctx, 500, 280, GST_MSECOND * 40,
Packit 971217
      GST_MSECOND * 40, 2, 1, 1, 0);
Packit 971217
Packit 971217
  /* Perform the switch */
Packit 971217
  g_object_set (G_OBJECT (rawvideoparse), "use-sink-caps", TRUE, NULL);
Packit 971217
Packit 971217
  /* Push in data with sink caps config active, expecting a different frame size */
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 192, 192, GST_MSECOND * 80,
Packit 971217
      GST_MSECOND * 40, 3, 2, 0, 0);
Packit 971217
Packit 971217
  cleanup_rawvideoparse ();
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_push_with_no_framerate)
Packit 971217
{
Packit 971217
  /* Test the special case when no framerate is set. The parser is expected to
Packit 971217
   * still work then, but without setting duration or PTS/DTS (it cannot do that,
Packit 971217
   * because these require a nonzero framerate). The output buffers have PTS 0,
Packit 971217
   * all subsequent ones have no set PTS. */
Packit 971217
Packit 971217
  setup_rawvideoparse (FALSE, TRUE, NULL, GST_FORMAT_BYTES);
Packit 971217
  g_object_set (G_OBJECT (rawvideoparse), "framerate", 0, 1, NULL);
Packit 971217
Packit 971217
  push_data_and_check_output (&properties_ctx, 500, 280, 0, GST_CLOCK_TIME_NONE,
Packit 971217
      1, 0, 0, 0);
Packit 971217
  push_data_and_check_output (&properties_ctx, 500, 280, GST_CLOCK_TIME_NONE,
Packit 971217
      GST_CLOCK_TIME_NONE, 2, 1, 1, 0);
Packit 971217
Packit 971217
  cleanup_rawvideoparse ();
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_computed_plane_strides)
Packit 971217
{
Packit 971217
  /* Test how plane strides & offsets are (re)computed if custom offsets/strides
Packit 971217
   * are disabled, and how they are preserved if they are enabled. */
Packit 971217
Packit 971217
  GValue plane_offsets_array = G_VALUE_INIT;
Packit 971217
  GValue plane_strides_array = G_VALUE_INIT;
Packit 971217
  guint i;
Packit 971217
  guint const expected_comp_psize = TEST_WIDTH * TEST_HEIGHT;
Packit 971217
Packit 971217
  g_value_init (&plane_offsets_array, GST_TYPE_ARRAY);
Packit 971217
  g_value_init (&plane_strides_array, GST_TYPE_ARRAY);
Packit 971217
Packit 971217
  setup_rawvideoparse (FALSE, TRUE, NULL, GST_FORMAT_BYTES);
Packit 971217
Packit 971217
  /* The setup set a custom set of plane offsets and strides together with
Packit 971217
   * width=TEST_WIDTH and height=TEST_HEIGHT. Check that the offsets & strides
Packit 971217
   * are preserved even after setting new, different width & height values. */
Packit 971217
Packit 971217
  g_object_set (G_OBJECT (rawvideoparse), "width", TEST_WIDTH * 2,
Packit 971217
      "height", TEST_HEIGHT * 2, NULL);
Packit 971217
Packit 971217
  g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets",
Packit 971217
      &plane_offsets_array);
Packit 971217
  g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides",
Packit 971217
      &plane_strides_array);
Packit 971217
Packit 971217
  for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) {
Packit 971217
    const GValue *gvalue;
Packit 971217
Packit 971217
    /* See setup_rawvideoparse() for how the offsets & strides are defined
Packit 971217
     * there. Offsets are set to plane_size*plane_index, and strides are
Packit 971217
     * set to the properties_ctx.plane_stride value. */
Packit 971217
Packit 971217
    gvalue = gst_value_array_get_value (&plane_offsets_array, i);
Packit 971217
    fail_unless (gvalue != NULL);
Packit 971217
    fail_unless_equals_uint64 (properties_ctx.plane_size * i,
Packit 971217
        g_value_get_int (gvalue));
Packit 971217
Packit 971217
    gvalue = gst_value_array_get_value (&plane_strides_array, i);
Packit 971217
    fail_unless (gvalue != NULL);
Packit 971217
    fail_unless_equals_uint64 (properties_ctx.plane_stride,
Packit 971217
        g_value_get_int (gvalue));
Packit 971217
  }
Packit 971217
Packit 971217
  /* Discard the custom planes&offsets, re-enabling computed values. */
Packit 971217
  g_value_reset (&plane_offsets_array);
Packit 971217
  g_value_reset (&plane_strides_array);
Packit 971217
  g_object_set_property (G_OBJECT (rawvideoparse), "plane-offsets",
Packit 971217
      &plane_offsets_array);
Packit 971217
  g_object_set_property (G_OBJECT (rawvideoparse), "plane-strides",
Packit 971217
      &plane_strides_array);
Packit 971217
Packit 971217
Packit 971217
  /* The strides & offsets should have been recomputed by now. Since the Y444
Packit 971217
   * format is used, all strides are the same, and should equal the frame width
Packit 971217
   * (which was set to TEST_WIDTH*2 earlier). Plane offsets should be
Packit 971217
   * plane_size*plane_index, with plane_size set to (TEST_WIDTH*2 * TEST_HEIGHT*2),
Packit 971217
   * or TEST_WIDTH*TEST_HEIGHT*4 (-> expected_comp_psize*4). */
Packit 971217
Packit 971217
  g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets",
Packit 971217
      &plane_offsets_array);
Packit 971217
  g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides",
Packit 971217
      &plane_strides_array);
Packit 971217
Packit 971217
  for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) {
Packit 971217
    const GValue *gvalue;
Packit 971217
Packit 971217
    gvalue = gst_value_array_get_value (&plane_offsets_array, i);
Packit 971217
    fail_unless (gvalue != NULL);
Packit 971217
    fail_unless_equals_uint64 (expected_comp_psize * 4 * i,
Packit 971217
        g_value_get_int (gvalue));
Packit 971217
Packit 971217
    gvalue = gst_value_array_get_value (&plane_strides_array, i);
Packit 971217
    fail_unless (gvalue != NULL);
Packit 971217
    fail_unless_equals_uint64 (TEST_WIDTH * 2, g_value_get_int (gvalue));
Packit 971217
  }
Packit 971217
Packit 971217
  g_value_reset (&plane_offsets_array);
Packit 971217
  g_value_reset (&plane_strides_array);
Packit 971217
Packit 971217
Packit 971217
  /* Again change the width & height values. width=TEST_WIDTH, height=TEST_HEIGHT.
Packit 971217
   * However, this time, offsets&strides are computed; the current values should
Packit 971217
   * not be preserved. Expected plane stride and offset values are similar to
Packit 971217
   * above, expect that no multiplications by 2 are present (since the TEST_WIDTH
Packit 971217
   * and TEST_HEIGHT values were passed without multiplying them). */
Packit 971217
Packit 971217
  g_object_set (G_OBJECT (rawvideoparse), "width", TEST_WIDTH,
Packit 971217
      "height", TEST_HEIGHT, NULL);
Packit 971217
Packit 971217
Packit 971217
  g_object_get_property (G_OBJECT (rawvideoparse), "plane-offsets",
Packit 971217
      &plane_offsets_array);
Packit 971217
  g_object_get_property (G_OBJECT (rawvideoparse), "plane-strides",
Packit 971217
      &plane_strides_array);
Packit 971217
Packit 971217
  for (i = 0; i < gst_value_array_get_size (&plane_offsets_array); ++i) {
Packit 971217
    const GValue *gvalue;
Packit 971217
Packit 971217
    gvalue = gst_value_array_get_value (&plane_offsets_array, i);
Packit 971217
    fail_unless (gvalue != NULL);
Packit 971217
    fail_unless_equals_uint64 (expected_comp_psize * i,
Packit 971217
        g_value_get_int (gvalue));
Packit 971217
Packit 971217
    gvalue = gst_value_array_get_value (&plane_strides_array, i);
Packit 971217
    fail_unless (gvalue != NULL);
Packit 971217
    fail_unless_equals_uint64 (TEST_WIDTH, g_value_get_int (gvalue));
Packit 971217
  }
Packit 971217
Packit 971217
  g_value_unset (&plane_offsets_array);
Packit 971217
  g_value_unset (&plane_strides_array);
Packit 971217
Packit 971217
  cleanup_rawvideoparse ();
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_change_caps)
Packit 971217
{
Packit 971217
  GstVideoInfo vinfo;
Packit 971217
  GstCaps *caps;
Packit 971217
Packit 971217
  /* Start processing with the sink caps config active, using the
Packit 971217
   * default width/height/format and 25 Hz frame rate for the caps.
Packit 971217
   * Push some data, then change caps (25 Hz -> 50 Hz).
Packit 971217
   * Check that the changed caps are handled properly. */
Packit 971217
Packit 971217
  gst_video_info_set_format (&vinfo, TEST_FRAME_FORMAT, TEST_WIDTH,
Packit 971217
      TEST_HEIGHT);
Packit 971217
  GST_VIDEO_INFO_FPS_N (&vinfo) = 25;
Packit 971217
  GST_VIDEO_INFO_FPS_D (&vinfo) = 1;
Packit 971217
  caps = gst_video_info_to_caps (&vinfo);
Packit 971217
Packit 971217
  setup_rawvideoparse (TRUE, FALSE, caps, GST_FORMAT_BYTES);
Packit 971217
Packit 971217
  /* Push in data with sink config active, expecting duration calculations
Packit 971217
   * to be based on the 25 Hz frame rate */
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 192, 192, GST_MSECOND * 0,
Packit 971217
      GST_MSECOND * 40, 1, 0, 0, 0);
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 192, 192, GST_MSECOND * 40,
Packit 971217
      GST_MSECOND * 40, 2, 1, 1, 0);
Packit 971217
Packit 971217
  /* Change caps */
Packit 971217
  GST_VIDEO_INFO_FPS_N (&vinfo) = 50;
Packit 971217
  GST_VIDEO_INFO_FPS_D (&vinfo) = 1;
Packit 971217
  caps = gst_video_info_to_caps (&vinfo);
Packit 971217
  fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_caps (caps)));
Packit 971217
  gst_caps_unref (caps);
Packit 971217
Packit 971217
  /* Push in data with sink config active, expecting duration calculations
Packit 971217
   * to be based on the 50 Hz frame rate */
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 192, 192, GST_MSECOND * 80,
Packit 971217
      GST_MSECOND * 20, 3, 2, 2, 0);
Packit 971217
Packit 971217
  cleanup_rawvideoparse ();
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_incomplete_last_buffer)
Packit 971217
{
Packit 971217
  GstVideoInfo vinfo;
Packit 971217
  GstCaps *caps;
Packit 971217
Packit 971217
  /* Start processing with the sink caps config active, using the
Packit 971217
   * default width/height/format and 25 Hz frame rate for the caps.
Packit 971217
   * Push some data, then change caps (25 Hz -> 50 Hz).
Packit 971217
   * Check that the changed caps are handled properly. */
Packit 971217
Packit 971217
  gst_video_info_set_format (&vinfo, TEST_FRAME_FORMAT, TEST_WIDTH,
Packit 971217
      TEST_HEIGHT);
Packit 971217
  GST_VIDEO_INFO_FPS_N (&vinfo) = 25;
Packit 971217
  GST_VIDEO_INFO_FPS_D (&vinfo) = 1;
Packit 971217
  caps = gst_video_info_to_caps (&vinfo);
Packit 971217
Packit 971217
  setup_rawvideoparse (TRUE, FALSE, caps, GST_FORMAT_BYTES);
Packit 971217
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 192, 192, GST_MSECOND * 0,
Packit 971217
      GST_MSECOND * 40, 1, 0, 0, 0);
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 192, 192, GST_MSECOND * 40,
Packit 971217
      GST_MSECOND * 40, 2, 1, 1, 0);
Packit 971217
  push_data_and_check_output (&sinkcaps_ctx, 100, 192, GST_MSECOND * 40,
Packit 971217
      GST_MSECOND * 40, 2, 1, 1, 0);
Packit 971217
  gst_pad_push_event (mysrcpad, gst_event_new_eos ());
Packit 971217
  fail_unless_equals_int (g_list_length (buffers), 2);
Packit 971217
Packit 971217
  cleanup_rawvideoparse ();
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static Suite *
Packit 971217
rawvideoparse_suite (void)
Packit 971217
{
Packit 971217
  Suite *s = suite_create ("rawvideoparse");
Packit 971217
  TCase *tc_chain = tcase_create ("general");
Packit 971217
Packit 971217
  suite_add_tcase (s, tc_chain);
Packit 971217
  tcase_add_test (tc_chain, test_push_unaligned_data_properties_config);
Packit 971217
  tcase_add_test (tc_chain, test_push_unaligned_data_sink_caps_config);
Packit 971217
  tcase_add_test (tc_chain, test_config_switch);
Packit 971217
  tcase_add_test (tc_chain, test_push_with_no_framerate);
Packit 971217
  tcase_add_test (tc_chain, test_computed_plane_strides);
Packit 971217
  tcase_add_test (tc_chain, test_change_caps);
Packit 971217
  tcase_add_test (tc_chain, test_incomplete_last_buffer);
Packit 971217
Packit 971217
  return s;
Packit 971217
}
Packit 971217
Packit 971217
GST_CHECK_MAIN (rawvideoparse);