#include <gst/check/gstharness.h>
#include <gst/video/video.h>
+/* enable this define to see color conversion result with videosink */
+#define RUN_VISUAL_TEST 0
+
typedef struct _TestFrame
{
gint width;
GST_END_TEST;
+#if RUN_VISUAL_TEST
+static gboolean
+bus_cb (GstBus * bus, GstMessage * message, gpointer data)
+{
+ GMainLoop *loop = (GMainLoop *) data;
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:{
+ GError *err = NULL;
+ gchar *debug = NULL;
+
+ gst_message_parse_error (message, &err, &debug);
+
+ GST_ERROR ("Error: %s : %s", err->message, debug);
+ g_error_free (err);
+ g_free (debug);
+
+ fail_if (TRUE, "failed");
+ g_main_loop_quit (loop);
+ }
+ break;
+ case GST_MESSAGE_EOS:
+ g_main_loop_quit (loop);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+static void
+run_convert_pipelne (const gchar * in_format, const gchar * out_format)
+{
+ GstBus *bus;
+ GMainLoop *loop = g_main_loop_new (NULL, FALSE);
+ gchar *pipeline_str =
+ g_strdup_printf ("videotestsrc num-buffers=1 is-live=true ! "
+ "video/x-raw,format=%s,framerate=3/1 ! d3d11upload ! "
+ "d3d11colorconvert ! d3d11download ! video/x-raw,format=%s ! "
+ "videoconvert ! d3d11videosink", in_format, out_format);
+ GstElement *pipeline;
+
+ pipeline = gst_parse_launch (pipeline_str, NULL);
+ fail_unless (pipeline != NULL);
+ g_free (pipeline_str);
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+ gst_bus_add_watch (bus, (GstBusFunc) bus_cb, loop);
+
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ g_main_loop_run (loop);
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+
+ gst_bus_remove_watch (bus);
+ gst_object_unref (bus);
+ gst_object_unref (pipeline);
+ g_main_loop_unref (loop);
+}
+
+GST_START_TEST (test_d3d11_color_convert_yuv_yuv)
+{
+ const gchar *format_list[] = {
+ "VUYA", "NV12", "P010_10LE", "P016_LE", "I420", "I420_10LE"
+ };
+
+ gint i, j;
+
+ for (i = 0; i < G_N_ELEMENTS (format_list); i++) {
+ for (j = 0; j < G_N_ELEMENTS (format_list); j++) {
+ if (i == j)
+ continue;
+
+ GST_DEBUG ("run conversion %s to %s", format_list[i], format_list[j]);
+ run_convert_pipelne (format_list[i], format_list[j]);
+ }
+ }
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_d3d11_color_convert_yuv_rgb)
+{
+ const gchar *in_format_list[] = {
+ "VUYA", "NV12", "P010_10LE", "P016_LE", "I420", "I420_10LE"
+ };
+ const gchar *out_format_list[] = {
+ "BGRA", "RGBA", "RGB10A2_LE",
+ };
+
+
+ gint i, j;
+
+ for (i = 0; i < G_N_ELEMENTS (in_format_list); i++) {
+ for (j = 0; j < G_N_ELEMENTS (out_format_list); j++) {
+ if (i == j)
+ continue;
+
+ GST_DEBUG ("run conversion %s to %s", in_format_list[i],
+ out_format_list[j]);
+ run_convert_pipelne (in_format_list[i], out_format_list[j]);
+ }
+ }
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_d3d11_color_convert_rgb_yuv)
+{
+ const gchar *in_format_list[] = {
+ "BGRA", "RGBA", "RGB10A2_LE",
+ };
+ const gchar *out_format_list[] = {
+ "VUYA", "NV12", "P010_10LE", "P016_LE", "I420", "I420_10LE"
+ };
+
+ gint i, j;
+
+ for (i = 0; i < G_N_ELEMENTS (in_format_list); i++) {
+ for (j = 0; j < G_N_ELEMENTS (out_format_list); j++) {
+ GST_DEBUG ("run conversion %s to %s", in_format_list[i],
+ out_format_list[j]);
+ run_convert_pipelne (in_format_list[i], out_format_list[j]);
+ }
+ }
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_d3d11_color_convert_rgb_rgb)
+{
+ const gchar *format_list[] = {
+ "BGRA", "RGBA", "RGB10A2_LE",
+ };
+
+ gint i, j;
+
+ for (i = 0; i < G_N_ELEMENTS (format_list); i++) {
+ for (j = 0; j < G_N_ELEMENTS (format_list); j++) {
+ if (i == j)
+ continue;
+
+ GST_DEBUG ("run conversion %s to %s", format_list[i], format_list[j]);
+ run_convert_pipelne (format_list[i], format_list[j]);
+ }
+ }
+}
+
+GST_END_TEST;
+#endif /* RUN_VISUAL_TEST */
+
static Suite *
d3d11colorconvert_suite (void)
{
suite_add_tcase (s, tc_basic);
tcase_add_test (tc_basic, test_d3d11_color_convert_rgba_reorder);
+#if RUN_VISUAL_TEST
+ tcase_add_test (tc_basic, test_d3d11_color_convert_yuv_yuv);
+ tcase_add_test (tc_basic, test_d3d11_color_convert_yuv_rgb);
+ tcase_add_test (tc_basic, test_d3d11_color_convert_rgb_yuv);
+ tcase_add_test (tc_basic, test_d3d11_color_convert_rgb_rgb);
+#endif
return s;
}