Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Seungha Yang
gst-plugins-bad
Commits
b1455894
Commit
b1455894
authored
Dec 20, 2018
by
Seungha Yang
🐑
Browse files
tests: Add nvdec unit test
parent
5c44c84a
Changes
3
Hide whitespace changes
Inline
Side-by-side
tests/check/Makefile.am
View file @
b1455894
...
...
@@ -229,6 +229,12 @@ else
check_nvenc
=
endif
if
USE_NVDEC
check_nvdec
=
elements/nvdec
else
check_nvdec
=
endif
VALGRIND_TO_FIX
=
\
elements/mpeg2enc
\
elements/mplex
\
...
...
@@ -313,6 +319,7 @@ check_PROGRAMS = \
$(check_webrtc)
\
$(check_msdk)
\
$(check_nvenc)
\
$(check_nvdec)
\
$(EXPERIMENTAL_CHECKS)
noinst_HEADERS
=
elements/mxfdemux.h libs/isoff.h
...
...
tests/check/elements/nvdec.c
0 → 100644
View file @
b1455894
/* GStreamer
*
* Copyright (c) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) 2018 Seungha Yang <seungha.yang@navercorp.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.
*/
#include
<gst/check/gstcheck.h>
static
GstStaticPadTemplate
sinktemplate
=
GST_STATIC_PAD_TEMPLATE
(
"sink"
,
GST_PAD_SINK
,
GST_PAD_ALWAYS
,
GST_STATIC_CAPS
(
"video/x-raw, "
"format = (string) NV12, "
"width = (int) [1, MAX], "
"height = (int) [1, MAX], "
"framerate = (fraction) [0, MAX]"
));
static
GstStaticPadTemplate
srctemplate
=
GST_STATIC_PAD_TEMPLATE
(
"src"
,
GST_PAD_SRC
,
GST_PAD_ALWAYS
,
GST_STATIC_CAPS
(
"video/x-raw, "
"format = (string) NV12, "
"width = (int) [1, MAX], "
"height = (int) [1, MAX], "
"framerate = (fraction) [0, MAX]"
));
static
GstPad
*
sinkpad
,
*
srcpad
;
static
GstElement
*
setup_nvdec
(
const
gchar
*
src_caps_str
)
{
GstElement
*
bin
;
GstElement
*
nvenc
,
*
nvdec
;
GstCaps
*
srccaps
=
NULL
;
GstBus
*
bus
;
GstPad
*
ghostpad
,
*
targetpad
;
if
(
src_caps_str
)
{
srccaps
=
gst_caps_from_string
(
src_caps_str
);
fail_unless
(
srccaps
!=
NULL
);
}
bin
=
gst_bin_new
(
"bin"
);
nvenc
=
gst_check_setup_element
(
"nvh264enc"
);
fail_unless
(
nvenc
!=
NULL
);
nvdec
=
gst_check_setup_element
(
"nvdec"
);
fail_unless
(
nvdec
!=
NULL
);
g_object_set
(
nvenc
,
"name"
,
"encoder"
,
NULL
);
g_object_set
(
nvdec
,
"name"
,
"decoder"
,
NULL
);
gst_bin_add_many
(
GST_BIN
(
bin
),
nvenc
,
nvdec
,
NULL
);
fail_unless
(
gst_element_link_pads
(
nvenc
,
"src"
,
nvdec
,
"sink"
));
targetpad
=
gst_element_get_static_pad
(
nvenc
,
"sink"
);
fail_unless
(
targetpad
!=
NULL
);
ghostpad
=
gst_ghost_pad_new
(
"sink"
,
targetpad
);
fail_unless
(
ghostpad
!=
NULL
);
gst_element_add_pad
(
bin
,
ghostpad
);
gst_object_unref
(
targetpad
);
targetpad
=
gst_element_get_static_pad
(
nvdec
,
"src"
);
fail_unless
(
targetpad
!=
NULL
);
ghostpad
=
gst_ghost_pad_new
(
"src"
,
targetpad
);
fail_unless
(
ghostpad
!=
NULL
);
gst_element_add_pad
(
bin
,
ghostpad
);
gst_object_unref
(
targetpad
);
srcpad
=
gst_check_setup_src_pad
(
bin
,
&
srctemplate
);
sinkpad
=
gst_check_setup_sink_pad
(
bin
,
&
sinktemplate
);
gst_pad_set_active
(
srcpad
,
TRUE
);
gst_pad_set_active
(
sinkpad
,
TRUE
);
gst_check_setup_events
(
srcpad
,
bin
,
srccaps
,
GST_FORMAT_TIME
);
bus
=
gst_bus_new
();
gst_element_set_bus
(
bin
,
bus
);
fail_unless
(
gst_element_set_state
(
bin
,
GST_STATE_PLAYING
)
!=
GST_STATE_CHANGE_FAILURE
,
"could not set to playing"
);
if
(
srccaps
)
gst_caps_unref
(
srccaps
);
buffers
=
NULL
;
return
bin
;
}
static
void
cleanup_nvdec
(
GstElement
*
bin
)
{
GstBus
*
bus
;
/* Free parsed buffers */
gst_check_drop_buffers
();
bus
=
GST_ELEMENT_BUS
(
bin
);
gst_bus_set_flushing
(
bus
,
TRUE
);
gst_object_unref
(
bus
);
gst_pad_set_active
(
srcpad
,
FALSE
);
gst_pad_set_active
(
sinkpad
,
FALSE
);
gst_check_teardown_src_pad
(
bin
);
gst_check_teardown_sink_pad
(
bin
);
gst_check_teardown_element
(
bin
);
}
GST_START_TEST
(
test_decode_simple
)
{
GstElement
*
bin
;
GstBuffer
*
buffer
;
gint
i
;
GList
*
l
;
GstSegment
seg
;
bin
=
setup_nvdec
(
"video/x-raw,format=(string)NV12,width=(int)320,height=(int)240,framerate=(fraction)25/1"
);
gst_segment_init
(
&
seg
,
GST_FORMAT_TIME
);
seg
.
stop
=
gst_util_uint64_scale
(
20
,
GST_SECOND
,
25
);
fail_unless
(
gst_pad_push_event
(
srcpad
,
gst_event_new_segment
(
&
seg
)));
buffer
=
gst_buffer_new_and_alloc
(
320
*
240
+
2
*
160
*
120
);
gst_buffer_memset
(
buffer
,
0
,
0
,
-
1
);
for
(
i
=
0
;
i
<
20
;
i
++
)
{
GST_BUFFER_TIMESTAMP
(
buffer
)
=
gst_util_uint64_scale
(
i
,
GST_SECOND
,
25
);
GST_BUFFER_DURATION
(
buffer
)
=
gst_util_uint64_scale
(
1
,
GST_SECOND
,
25
);
fail_unless
(
gst_pad_push
(
srcpad
,
gst_buffer_ref
(
buffer
))
==
GST_FLOW_OK
);
}
gst_buffer_unref
(
buffer
);
fail_unless
(
gst_pad_push_event
(
srcpad
,
gst_event_new_eos
()));
/* All buffers must be there now */
fail_unless_equals_int
(
g_list_length
(
buffers
),
20
);
for
(
l
=
buffers
,
i
=
0
;
l
;
l
=
l
->
next
,
i
++
)
{
buffer
=
l
->
data
;
fail_unless_equals_uint64
(
GST_BUFFER_TIMESTAMP
(
buffer
),
gst_util_uint64_scale
(
i
,
GST_SECOND
,
25
));
fail_unless_equals_uint64
(
GST_BUFFER_DURATION
(
buffer
),
gst_util_uint64_scale
(
1
,
GST_SECOND
,
25
));
}
cleanup_nvdec
(
bin
);
}
GST_END_TEST
;
static
gboolean
check_nvdec_available
(
void
)
{
gboolean
ret
=
TRUE
;
GstElement
*
nvdec
;
nvdec
=
gst_element_factory_make
(
"nvdec"
,
NULL
);
if
(
!
nvdec
)
{
GST_WARNING
(
"nvdec is not available, possibly driver load failure"
);
return
FALSE
;
}
/* GST_STATE_READY is meaning that driver could be loaded */
if
(
gst_element_set_state
(
nvdec
,
GST_STATE_PAUSED
)
!=
GST_STATE_CHANGE_SUCCESS
)
{
GST_WARNING
(
"cannot open device"
);
ret
=
FALSE
;
}
gst_element_set_state
(
nvdec
,
GST_STATE_NULL
);
gst_object_unref
(
nvdec
);
return
ret
;
}
static
Suite
*
nvdec_suite
(
void
)
{
Suite
*
s
;
TCase
*
tc_chain
;
/* HACK: cuda device init/deinit with fork seems to problematic */
g_setenv
(
"CK_FORK"
,
"no"
,
TRUE
);
s
=
suite_create
(
"nvdec"
);
tc_chain
=
tcase_create
(
"general"
);
suite_add_tcase
(
s
,
tc_chain
);
if
(
!
check_nvdec_available
())
{
GST_DEBUG
(
"Skip nvdec test since cannot open device"
);
goto
end
;
}
tcase_add_test
(
tc_chain
,
test_decode_simple
);
end:
return
s
;
}
GST_CHECK_MAIN
(
nvdec
);
tests/check/meson.build
View file @
b1455894
...
...
@@ -39,6 +39,7 @@ base_tests = [
[['elements/msdkh264enc.c'], not have_msdk, [msdk_dep]],
[['elements/mxfdemux.c']],
[['elements/mxfmux.c']],
[['elements/nvdec.c'], not cuda_header_dep.found(), nvenc_test_deps],
[['elements/nvenc.c'], not cuda_header_dep.found(), nvenc_test_deps],
[['elements/pcapparse.c'], false, [libparser_dep]],
[['elements/pnm.c']],
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment