• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * unit test for VA allocators
4  *
5  * Copyright (C) 2021 Igalia, S.L.
6  *     Author: Víctor Jáquez <vjaquez@igalia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27 
28 #include <gst/gst.h>
29 #include <gst/check/gstcheck.h>
30 #include <gst/check/gstharness.h>
31 #include <gst/video/video.h>
32 
GST_START_TEST(raw_copy)33 GST_START_TEST (raw_copy)
34 {
35   GstHarness *h;
36   GstBuffer *buf, *buf_copy;
37   gboolean ret;
38 
39   h = gst_harness_new_parse ("videotestsrc num-buffers=1 ! "
40       "video/x-raw, width=(int)1024, height=(int)768 ! vapostproc");
41   ck_assert (h);
42 
43   gst_harness_set_sink_caps_str (h,
44       "video/x-raw, format=(string)NV12, width=(int)3840, height=(int)2160");
45 
46   gst_harness_add_propose_allocation_meta (h, GST_VIDEO_META_API_TYPE, NULL);
47   gst_harness_play (h);
48 
49   buf = gst_harness_pull (h);
50   ck_assert (buf);
51 
52   buf_copy = gst_buffer_new ();
53   ret = gst_buffer_copy_into (buf_copy, buf,
54       GST_BUFFER_COPY_MEMORY | GST_BUFFER_COPY_DEEP, 0, -1);
55   ck_assert (ret);
56 
57   gst_clear_buffer (&buf);
58   gst_clear_buffer (&buf_copy);
59 
60   gst_harness_teardown (h);
61 }
62 
63 GST_END_TEST;
64 
GST_START_TEST(dmabuf_copy)65 GST_START_TEST (dmabuf_copy)
66 {
67   GstHarness *h;
68   GstBuffer *buf, *buf_copy;
69   gboolean ret;
70 
71   h = gst_harness_new_parse ("videotestsrc num-buffers=1 ! "
72       "video/x-raw, width=(int)1024, height=(int)768 ! vapostproc");
73   ck_assert (h);
74 
75   gst_harness_set_sink_caps_str (h,
76       "video/x-raw(memory:DMABuf), format=(string)NV12, width=(int)3840, height=(int)2160");
77 
78   gst_harness_add_propose_allocation_meta (h, GST_VIDEO_META_API_TYPE, NULL);
79   gst_harness_play (h);
80 
81   buf = gst_harness_pull (h);
82   ck_assert (buf);
83 
84   buf_copy = gst_buffer_new ();
85   ret = gst_buffer_copy_into (buf_copy, buf,
86       GST_BUFFER_COPY_MEMORY | GST_BUFFER_COPY_DEEP, 0, -1);
87 
88   if (gst_buffer_n_memory (buf_copy) == 1)
89     ck_assert (ret == TRUE);
90   /* else it will depend on the drm modifier */
91 
92   gst_clear_buffer (&buf);
93   gst_clear_buffer (&buf_copy);
94 
95   gst_harness_teardown (h);
96 }
97 
98 GST_END_TEST;
99 
100 int
main(int argc,char ** argv)101 main (int argc, char **argv)
102 {
103   GstElement *vpp;
104   Suite *s;
105   TCase *tc_chain;
106 
107   gst_check_init (&argc, &argv);
108 
109   vpp = gst_element_factory_make ("vapostproc", NULL);
110   if (!vpp)
111     return EXIT_SUCCESS;        /* not available vapostproc */
112   gst_object_unref (vpp);
113 
114   s = suite_create ("va");
115   tc_chain = tcase_create ("copy");
116 
117   suite_add_tcase (s, tc_chain);
118 
119   tcase_add_test (tc_chain, raw_copy);
120   tcase_add_test (tc_chain, dmabuf_copy);
121 
122   return gst_check_run_suite (s, "va", __FILE__);
123 }
124