• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2020 Seungha Yang <seungha@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <gst/gst.h>
26 #include <gst/check/gstcheck.h>
27 
GST_START_TEST(test_mf_video_src_reuse)28 GST_START_TEST (test_mf_video_src_reuse)
29 {
30   GstElement *pipeline;
31   GstStateChangeReturn ret;
32   GstBus *bus;
33   GstMessage *msg;
34 
35   pipeline = gst_parse_launch ("mfvideosrc ! fakevideosink name=sink", NULL);
36   fail_unless (pipeline != NULL);
37 
38   bus = gst_element_get_bus (GST_ELEMENT (pipeline));
39   fail_unless (bus != NULL);
40 
41   GST_INFO ("Set state playing");
42   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
43   msg = gst_bus_poll (bus, GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR, -1);
44   fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ASYNC_DONE);
45   gst_message_unref (msg);
46 
47   GST_INFO ("Set state ready");
48   ret = gst_element_set_state (pipeline, GST_STATE_READY);
49   fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
50 
51   GST_INFO ("Set state playing again");
52   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
53   msg = gst_bus_poll (bus, GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR, -1);
54   fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ASYNC_DONE);
55   gst_message_unref (msg);
56 
57   ret = gst_element_set_state (pipeline, GST_STATE_NULL);
58   fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
59 
60   gst_object_unref (bus);
61   gst_object_unref (pipeline);
62 }
63 
64 GST_END_TEST;
65 
66 static gboolean
check_mf_available(void)67 check_mf_available (void)
68 {
69   gboolean ret = TRUE;
70   GstElement *mfvideosrc;
71 
72   mfvideosrc = gst_element_factory_make ("mfvideosrc", NULL);
73   if (!mfvideosrc) {
74     GST_INFO ("nvh264dec is not available");
75     return FALSE;
76   }
77 
78   /* GST_STATE_READY is meaning that camera is available */
79   if (gst_element_set_state (mfvideosrc,
80           GST_STATE_READY) != GST_STATE_CHANGE_SUCCESS) {
81     GST_INFO ("cannot open device");
82     ret = FALSE;
83   }
84 
85   gst_element_set_state (mfvideosrc, GST_STATE_NULL);
86   gst_object_unref (mfvideosrc);
87 
88   return ret;
89 }
90 
91 static Suite *
mfvideosrc_suite(void)92 mfvideosrc_suite (void)
93 {
94   Suite *s = suite_create ("mfvideosrc");
95   TCase *tc_basic = tcase_create ("general");
96   gboolean have_mf = FALSE;
97 
98   suite_add_tcase (s, tc_basic);
99 
100   have_mf = check_mf_available ();
101 
102   if (have_mf) {
103     tcase_add_test (tc_basic, test_mf_video_src_reuse);
104   } else {
105     GST_INFO ("Skipping tests, media foundation plugin is unavailable");
106   }
107 
108   return s;
109 }
110 
111 GST_CHECK_MAIN (mfvideosrc);
112