1 /* 2 * Copyright © 2016 Red Hat Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 * 23 * Authors: Lyude Paul <lyude@redhat.com> 24 */ 25 26 #ifndef IGT_CHAMELIUM_H 27 #define IGT_CHAMELIUM_H 28 29 #include "config.h" 30 31 #include <stdbool.h> 32 #include <xf86drmMode.h> 33 34 #include "igt_debugfs.h" 35 36 struct igt_fb; 37 struct edid; 38 39 struct chamelium; 40 struct chamelium_port; 41 struct chamelium_frame_dump; 42 struct chamelium_fb_crc_async_data; 43 44 /** 45 * chamelium_check: 46 * @CHAMELIUM_CHECK_ANALOG: Fuzzy checking method for analog interfaces 47 * @CHAMELIUM_CHECK_CRC: CRC-based checking method for pixel-perfect interfaces 48 * 49 * Checking method for comparing between reference and captured frames. 50 */ 51 enum chamelium_check { 52 CHAMELIUM_CHECK_ANALOG, 53 CHAMELIUM_CHECK_CHECKERBOARD, 54 CHAMELIUM_CHECK_CRC, 55 }; 56 57 struct chamelium_video_params { 58 double clock; 59 int htotal, hactive, hsync_offset, hsync_width, hsync_polarity; 60 int vtotal, vactive, vsync_offset, vsync_width, vsync_polarity; 61 }; 62 63 struct chamelium_audio_file { 64 char *path; 65 int rate; /* Hz */ 66 int channels; 67 }; 68 69 enum chamelium_infoframe_type { 70 CHAMELIUM_INFOFRAME_AVI, 71 CHAMELIUM_INFOFRAME_AUDIO, 72 CHAMELIUM_INFOFRAME_MPEG, 73 CHAMELIUM_INFOFRAME_VENDOR, 74 }; 75 76 struct chamelium_infoframe { 77 int version; 78 size_t payload_size; 79 uint8_t *payload; 80 }; 81 82 struct chamelium_edid; 83 84 /** 85 * CHAMELIUM_MAX_PORTS: the maximum number of ports supported by igt_chamelium. 86 * 87 * For now, we have 1 VGA, 1 HDMI and 2 DisplayPort ports. 88 */ 89 #define CHAMELIUM_MAX_PORTS 4 90 91 /** 92 * CHAMELIUM_DEFAULT_EDID: provide this ID to #chamelium_port_set_edid to use 93 * the default EDID. 94 */ 95 #define CHAMELIUM_DEFAULT_EDID 0 96 97 /** 98 * CHAMELIUM_MAX_AUDIO_CHANNELS: the maximum number of audio capture channels 99 * supported by Chamelium. 100 */ 101 #define CHAMELIUM_MAX_AUDIO_CHANNELS 8 102 103 struct chamelium *chamelium_init(int drm_fd); 104 void chamelium_deinit(struct chamelium *chamelium); 105 void chamelium_reset(struct chamelium *chamelium); 106 107 struct chamelium_port **chamelium_get_ports(struct chamelium *chamelium, 108 int *count); 109 unsigned int chamelium_port_get_type(const struct chamelium_port *port); 110 drmModeConnector *chamelium_port_get_connector(struct chamelium *chamelium, 111 struct chamelium_port *port, 112 bool reprobe); 113 const char *chamelium_port_get_name(struct chamelium_port *port); 114 115 void chamelium_wait_reachable(struct chamelium *chamelium, int timeout); 116 void chamelium_plug(struct chamelium *chamelium, struct chamelium_port *port); 117 void chamelium_unplug(struct chamelium *chamelium, struct chamelium_port *port); 118 bool chamelium_is_plugged(struct chamelium *chamelium, 119 struct chamelium_port *port); 120 bool chamelium_port_wait_video_input_stable(struct chamelium *chamelium, 121 struct chamelium_port *port, 122 int timeout_secs); 123 void chamelium_fire_mixed_hpd_pulses(struct chamelium *chamelium, 124 struct chamelium_port *port, ...); 125 void chamelium_fire_hpd_pulses(struct chamelium *chamelium, 126 struct chamelium_port *port, 127 int width_msec, int count); 128 void chamelium_schedule_hpd_toggle(struct chamelium *chamelium, 129 struct chamelium_port *port, int delay_ms, 130 bool rising_edge); 131 struct chamelium_edid *chamelium_new_edid(struct chamelium *chamelium, 132 const struct edid *edid); 133 const struct edid *chamelium_edid_get_raw(struct chamelium_edid *edid, 134 struct chamelium_port *port); 135 void chamelium_port_set_edid(struct chamelium *chamelium, 136 struct chamelium_port *port, 137 struct chamelium_edid *edid); 138 bool chamelium_port_get_ddc_state(struct chamelium *chamelium, 139 struct chamelium_port *port); 140 void chamelium_port_set_ddc_state(struct chamelium *chamelium, 141 struct chamelium_port *port, 142 bool enabled); 143 void chamelium_port_get_resolution(struct chamelium *chamelium, 144 struct chamelium_port *port, 145 int *x, int *y); 146 bool chamelium_supports_get_video_params(struct chamelium *chamelium); 147 void chamelium_port_get_video_params(struct chamelium *chamelium, 148 struct chamelium_port *port, 149 struct chamelium_video_params *params); 150 igt_crc_t *chamelium_get_crc_for_area(struct chamelium *chamelium, 151 struct chamelium_port *port, 152 int x, int y, int w, int h); 153 void chamelium_start_capture(struct chamelium *chamelium, 154 struct chamelium_port *port, 155 int x, int y, int w, int h); 156 void chamelium_stop_capture(struct chamelium *chamelium, int frame_count); 157 void chamelium_capture(struct chamelium *chamelium, struct chamelium_port *port, 158 int x, int y, int w, int h, int frame_count); 159 bool chamelium_supports_get_last_infoframe(struct chamelium *chamelium); 160 struct chamelium_infoframe * 161 chamelium_get_last_infoframe(struct chamelium *chamelium, 162 struct chamelium_port *port, 163 enum chamelium_infoframe_type type); 164 bool chamelium_supports_trigger_link_failure(struct chamelium *chamelium); 165 void chamelium_trigger_link_failure(struct chamelium *chamelium, 166 struct chamelium_port *port); 167 bool chamelium_has_audio_support(struct chamelium *chamelium, 168 struct chamelium_port *port); 169 void chamelium_get_audio_channel_mapping(struct chamelium *chamelium, 170 struct chamelium_port *port, 171 int mapping[static CHAMELIUM_MAX_AUDIO_CHANNELS]); 172 void chamelium_get_audio_format(struct chamelium *chamelium, 173 struct chamelium_port *port, 174 int *rate, int *channels); 175 void chamelium_start_capturing_audio(struct chamelium *chamelium, 176 struct chamelium_port *port, bool save_to_file); 177 struct chamelium_audio_file *chamelium_stop_capturing_audio(struct chamelium *chamelium, 178 struct chamelium_port *port); 179 igt_crc_t *chamelium_read_captured_crcs(struct chamelium *chamelium, 180 int *frame_count); 181 struct chamelium_frame_dump *chamelium_read_captured_frame(struct chamelium *chamelium, 182 unsigned int index); 183 struct chamelium_frame_dump *chamelium_port_dump_pixels(struct chamelium *chamelium, 184 struct chamelium_port *port, 185 int x, int y, 186 int w, int h); 187 igt_crc_t *chamelium_calculate_fb_crc(int fd, struct igt_fb *fb); 188 struct chamelium_fb_crc_async_data *chamelium_calculate_fb_crc_async_start(int fd, 189 struct igt_fb *fb); 190 igt_crc_t *chamelium_calculate_fb_crc_async_finish(struct chamelium_fb_crc_async_data *fb_crc); 191 int chamelium_get_captured_frame_count(struct chamelium *chamelium); 192 int chamelium_get_frame_limit(struct chamelium *chamelium, 193 struct chamelium_port *port, 194 int w, int h); 195 void chamelium_assert_frame_eq(const struct chamelium *chamelium, 196 const struct chamelium_frame_dump *dump, 197 struct igt_fb *fb); 198 void chamelium_assert_crc_eq_or_dump(struct chamelium *chamelium, 199 igt_crc_t *reference_crc, 200 igt_crc_t *capture_crc, struct igt_fb *fb, 201 int index); 202 void chamelium_assert_frame_match_or_dump(struct chamelium *chamelium, 203 struct chamelium_port *port, 204 const struct chamelium_frame_dump *frame, 205 struct igt_fb *fb, 206 enum chamelium_check check); 207 void chamelium_crop_analog_frame(struct chamelium_frame_dump *dump, int width, 208 int height); 209 void chamelium_destroy_frame_dump(struct chamelium_frame_dump *dump); 210 void chamelium_destroy_audio_file(struct chamelium_audio_file *audio_file); 211 void chamelium_infoframe_destroy(struct chamelium_infoframe *infoframe); 212 213 #endif /* IGT_CHAMELIUM_H */ 214