File: switchbin.c

package info (click to toggle)
gst-plugins-bad1.0 1.26.10-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 69,996 kB
  • sloc: ansic: 722,568; cpp: 278,154; objc: 3,556; xml: 3,351; sh: 1,095; python: 508; makefile: 175; java: 75
file content (111 lines) | stat: -rw-r--r-- 3,372 bytes parent folder | download | duplicates (10)
1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* GStreamer
 *
 * unit test for switchbin element
 * Copyright (C) 2018 Jan Schmidt <jan@centricular.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., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst.h>
#include <gst/check/gstcheck.h>
#include <gst/check/gstharness.h>

GST_START_TEST (test_switchbin_simple)
{
  GstBus *bus;
  GstElement *switchbin, *e0, *e1;
  GstCaps *c0, *c1;
  GstHarness *h;
  guint path_index;

  GstBuffer *in_buf;
  GstBuffer *out_buf;

  bus = gst_bus_new ();

  switchbin = gst_element_factory_make ("switchbin", NULL);
  fail_unless (switchbin != NULL);
  g_object_set (switchbin, "num-paths", 2, NULL);
  gst_element_set_bus (switchbin, bus);
  h = gst_harness_new_with_element (switchbin, "sink", "src");

  e0 = gst_element_factory_make ("identity", NULL);
  c0 = gst_caps_from_string ("audio/x-raw,format=S16LE,rate=48000,channels=2");
  e1 = gst_element_factory_make ("identity", NULL);
  c1 = gst_caps_from_string ("audio/x-raw,format=S16LE,rate=44100,channels=1");

  /* switchbin owns the elements after this */
  gst_child_proxy_set (GST_CHILD_PROXY (switchbin),
      "path0::element", e0, "path0::caps", c0,
      "path1::element", e1, "path1::caps", c1, NULL);

  /* Create a small buffer push it in, pull it out,
   * and check the switchbin selected the right path for these caps */
  gst_harness_set_src_caps (h, c0);
  in_buf = gst_harness_create_buffer (h, 480);
  gst_harness_push (h, in_buf);
  out_buf = gst_harness_pull (h);
  fail_unless (in_buf == out_buf);
  gst_buffer_unref (out_buf);
  g_object_get (switchbin, "current-path", &path_index, NULL);
  fail_unless (path_index == 0);

  /* Change caps, push more */
  gst_harness_set_src_caps (h, c1);
  in_buf = gst_harness_create_buffer (h, 480);
  gst_harness_push (h, in_buf);
  out_buf = gst_harness_pull (h);
  fail_unless (in_buf == out_buf);
  gst_buffer_unref (out_buf);
  g_object_get (switchbin, "current-path", &path_index, NULL);
  fail_unless (path_index == 1);

  while (TRUE) {
    GstMessage *msg = gst_bus_pop (bus);
    if (!msg)
      break;

    GST_DEBUG ("got message %s",
        gst_message_type_get_name (GST_MESSAGE_TYPE (msg)));
    fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
    gst_message_unref (msg);
  }

  gst_harness_teardown (h);
  gst_bus_set_flushing (bus, TRUE);
  gst_object_unref (bus);
  gst_object_unref (switchbin);
}

GST_END_TEST;

static Suite *
switchbin_suite (void)
{
  Suite *s = suite_create ("switchbin");
  TCase *tc_basic = tcase_create ("general");

  suite_add_tcase (s, tc_basic);
  tcase_add_test (tc_basic, test_switchbin_simple);

  return s;
}

GST_CHECK_MAIN (switchbin);