1 
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5 #include <schroedinger/schro.h>
6 #include <schroedinger/opengl/schroopengl.h>
7 #include <schroedinger/opengl/schroopenglcanvas.h>
8 #include <schroedinger/opengl/schroopenglframe.h>
9 #include <string.h>
10 #include "../common.h"
11 #include "opengl_util.h"
12 
13 void
opengl_test_push_pull(SchroFrameFormat format,int width,int height,int todo,int custom_pattern)14 opengl_test_push_pull (SchroFrameFormat format, int width, int height,
15     int todo, int custom_pattern)
16 {
17   char format_name[64];
18   SchroFrame *cpu_ref_frame;
19   SchroFrame *cpu_test_frame;
20   SchroFrame *opengl_frame;
21   char pattern_name[TEST_PATTERN_NAME_SIZE];
22   int i;
23   int ok;
24   int frames = 0;
25   int total_length;
26   double start_push;
27   double start_pull;
28   double elapsed_push = 0;
29   double elapsed_pull = 0;
30 
31   printf ("==========================================================\n");
32 
33   if (!opengl_format_name(format, format_name, 64)) {
34     printf ("opengl_test_push_pull: %ix%i\n", width, height);
35     printf ("  unhandled format 0x%x", format);
36     printf ("==========================================================\n");
37     return;
38   }
39 
40   printf ("opengl_test_push_pull: %ix%i %s\n", width, height, format_name);
41 
42   if (_benchmark) {
43     schro_opengl_canvas_print_flags ("  ");
44   }
45 
46   cpu_ref_frame = schro_frame_new_and_alloc (_cpu_domain, format, width,
47       height);
48   cpu_test_frame = schro_frame_new_and_alloc (_cpu_domain, format, width,
49       height);
50   opengl_frame = schro_opengl_frame_new (_opengl, _opengl_domain, format, width,
51       height);
52 
53   printf ("  patterns\n");
54 
55   for (i = 0; i < todo; ++i) {
56     opengl_custom_pattern_generate (cpu_ref_frame, custom_pattern, i,
57         pattern_name);
58 
59     schro_opengl_lock (_opengl);
60 
61     start_push = schro_utils_get_time ();
62 
63     schro_opengl_frame_push (opengl_frame, cpu_ref_frame);
64 
65     start_pull = schro_utils_get_time ();
66     elapsed_push += start_pull - start_push;
67 
68     schro_opengl_frame_pull (cpu_test_frame, opengl_frame);
69 
70     elapsed_pull += schro_utils_get_time () - start_pull;
71 
72     schro_opengl_unlock (_opengl);
73 
74     ++frames;
75 
76     ok = frame_compare (cpu_ref_frame, cpu_test_frame);
77 
78     printf ("    %s: %s\n", pattern_name, ok ? "OK" : "broken");
79 
80     if (!ok) {
81       if (width <= 32 && height <= 32) {
82         frame_dump (cpu_ref_frame, cpu_ref_frame);
83         frame_dump (cpu_test_frame, cpu_ref_frame);
84       }
85 
86       opengl_test_failed ();
87     }
88   }
89 
90   if (_benchmark) {
91     total_length = (cpu_ref_frame->components[0].length
92         + cpu_ref_frame->components[1].length
93         + cpu_ref_frame->components[2].length) * frames;
94 
95     printf ("  results\n");
96     printf ("    %i frames pushed/pulled: %.2f mbyte each\n", frames,
97         (float)total_length / (1024 * 1024));
98     printf ("    total %f/%f sec, %.2f/%.2f mbyte/sec\n", elapsed_push,
99         elapsed_pull, total_length / elapsed_push / (1024 * 1024),
100         total_length / elapsed_pull / (1024 * 1024));
101     printf ("    avg   %f/%f sec, %f sec\n", elapsed_push / frames,
102         elapsed_pull / frames, elapsed_push / frames + elapsed_pull / frames);
103   }
104 
105   schro_frame_unref (cpu_ref_frame);
106   schro_frame_unref (cpu_test_frame);
107   schro_frame_unref (opengl_frame);
108 
109   printf ("==========================================================\n");
110 }
111 
112 struct PushPullTest {
113   SchroFrameFormat format;
114   int width, height;
115   int todo;
116   int custom_pattern;
117 };
118 
119 static struct PushPullTest opengl_test_push_pull_list[] = {
120   { SCHRO_FRAME_FORMAT_U8_444, 1920, 1080, 1, OPENGL_CUSTOM_PATTERN_RANDOM },
121   { SCHRO_FRAME_FORMAT_U8_444, 16, 16, -1, OPENGL_CUSTOM_PATTERN_NONE },
122   { SCHRO_FRAME_FORMAT_S16_444, 1920, 1080, 1, OPENGL_CUSTOM_PATTERN_RANDOM },
123   { SCHRO_FRAME_FORMAT_S16_444, 16, 16, -1, OPENGL_CUSTOM_PATTERN_NONE  },
124   { SCHRO_FRAME_FORMAT_U8_444, 1920, 1080, 1, OPENGL_CUSTOM_PATTERN_RANDOM },
125   { SCHRO_FRAME_FORMAT_U8_444, 23, 16, -1, OPENGL_CUSTOM_PATTERN_NONE  },
126   { SCHRO_FRAME_FORMAT_S16_444, 1920, 1080, 1, OPENGL_CUSTOM_PATTERN_RANDOM },
127   { SCHRO_FRAME_FORMAT_S16_444, 16, 23, -1, OPENGL_CUSTOM_PATTERN_NONE  },
128   { SCHRO_FRAME_FORMAT_YUYV, 1920, 1080, 1, OPENGL_CUSTOM_PATTERN_RANDOM },
129   { SCHRO_FRAME_FORMAT_YUYV, 16, 16, -1, OPENGL_CUSTOM_PATTERN_NONE  },
130   { SCHRO_FRAME_FORMAT_UYVY, 1920, 1080, 1, OPENGL_CUSTOM_PATTERN_RANDOM },
131   { SCHRO_FRAME_FORMAT_UYVY, 16, 16, -1, OPENGL_CUSTOM_PATTERN_NONE  },
132   { SCHRO_FRAME_FORMAT_AYUV, 1920, 1080, 1, OPENGL_CUSTOM_PATTERN_RANDOM },
133   { SCHRO_FRAME_FORMAT_AYUV, 16, 16, -1, OPENGL_CUSTOM_PATTERN_NONE  }
134 };
135 
opengl_test_push_pull_run()136 void opengl_test_push_pull_run ()
137 {
138   int i;
139 
140   for (i = 0; i < ARRAY_SIZE (opengl_test_push_pull_list); ++i) {
141     opengl_test_push_pull (opengl_test_push_pull_list[i].format,
142         opengl_test_push_pull_list[i].width,
143         opengl_test_push_pull_list[i].height,
144         opengl_test_push_pull_list[i].todo < 1 ? _generators
145         : opengl_test_push_pull_list[i].todo,
146         opengl_test_push_pull_list[i].custom_pattern);
147   }
148 }
149