Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 1 | /* Copyright 2015 Pierre Ossman <ossman@cendio.se> for Cendio AB |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 2 | * Copyright (C) 2015 D. R. Commander. All Rights Reserved. |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 3 | * |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 4 | * This is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 8 | * |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 9 | * This software is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 13 | * |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | * USA. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * This program reads files produced by TightVNC's/TurboVNC's |
| 22 | * fbs-dump, which in turn takes files from rfbproxy. It is |
| 23 | * basically a dump of the RFB protocol from the server side after |
| 24 | * the ServerInit message. Mostly this consists of FramebufferUpdate |
| 25 | * message using the HexTile encoding. Screen size and pixel format |
| 26 | * are not encoded in the file and must be specified by the user. |
| 27 | */ |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <math.h> |
| 32 | |
| 33 | #include <rdr/Exception.h> |
| 34 | #include <rdr/OutStream.h> |
| 35 | #include <rdr/FileInStream.h> |
| 36 | |
| 37 | #include <rfb/PixelFormat.h> |
| 38 | |
| 39 | #include <rfb/CConnection.h> |
| 40 | #include <rfb/CMsgReader.h> |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 41 | #include <rfb/UpdateTracker.h> |
| 42 | |
| 43 | #include <rfb/EncodeManager.h> |
| 44 | #include <rfb/SConnection.h> |
| 45 | #include <rfb/SMsgWriter.h> |
| 46 | |
| 47 | #include "util.h" |
| 48 | |
| 49 | static rfb::IntParameter width("width", "Frame buffer width", 0); |
| 50 | static rfb::IntParameter height("height", "Frame buffer height", 0); |
DRC | 4631a76 | 2015-02-21 11:57:27 -0600 | [diff] [blame] | 51 | static rfb::IntParameter count("count", "Number of benchmark iterations", 9); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 52 | |
| 53 | static rfb::StringParameter format("format", "Pixel format (e.g. bgr888)", ""); |
| 54 | |
DRC | 2a172c9 | 2015-02-25 14:18:07 -0600 | [diff] [blame] | 55 | static rfb::BoolParameter translate("translate", |
| 56 | "Translate 8-bit and 16-bit datasets into 24-bit", |
| 57 | true); |
| 58 | |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 59 | // The frame buffer (and output) is always this format |
| 60 | static const rfb::PixelFormat fbPF(32, 24, false, true, 255, 255, 255, 0, 8, 16); |
| 61 | |
| 62 | // Encodings to use |
| 63 | static const rdr::S32 encodings[] = { |
| 64 | rfb::encodingTight, rfb::encodingCopyRect, rfb::encodingRRE, |
| 65 | rfb::encodingHextile, rfb::encodingZRLE, rfb::pseudoEncodingLastRect, |
DRC | 562eb71 | 2015-02-21 12:01:47 -0600 | [diff] [blame] | 66 | rfb::pseudoEncodingQualityLevel0 + 8, |
| 67 | rfb::pseudoEncodingCompressLevel0 + 2}; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 68 | |
| 69 | class DummyOutStream : public rdr::OutStream { |
| 70 | public: |
| 71 | DummyOutStream(); |
| 72 | |
| 73 | virtual int length(); |
| 74 | virtual void flush(); |
| 75 | |
| 76 | private: |
| 77 | virtual int overrun(int itemSize, int nItems); |
| 78 | |
| 79 | int offset; |
| 80 | rdr::U8 buf[131072]; |
| 81 | }; |
| 82 | |
| 83 | class CConn : public rfb::CConnection { |
| 84 | public: |
| 85 | CConn(const char *filename); |
| 86 | ~CConn(); |
| 87 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 88 | void getStats(double& ratio, unsigned long long& bytes, |
| 89 | unsigned long long& rawEquivalent); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 90 | |
| 91 | virtual void setDesktopSize(int w, int h); |
| 92 | virtual void setCursor(int, int, const rfb::Point&, void*, void*); |
| 93 | virtual void framebufferUpdateStart(); |
| 94 | virtual void framebufferUpdateEnd(); |
| 95 | virtual void dataRect(const rfb::Rect&, int); |
| 96 | virtual void setColourMapEntries(int, int, rdr::U16*); |
| 97 | virtual void bell(); |
| 98 | virtual void serverCutText(const char*, rdr::U32); |
| 99 | |
| 100 | public: |
| 101 | double decodeTime; |
| 102 | double encodeTime; |
| 103 | |
| 104 | protected: |
| 105 | rdr::FileInStream *in; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 106 | rfb::SimpleUpdateTracker updates; |
| 107 | class SConn *sc; |
| 108 | }; |
| 109 | |
| 110 | class Manager : public rfb::EncodeManager { |
| 111 | public: |
| 112 | Manager(class rfb::SConnection *conn); |
| 113 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 114 | void getStats(double&, unsigned long long&, unsigned long long&); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | class SConn : public rfb::SConnection { |
| 118 | public: |
| 119 | SConn(); |
| 120 | ~SConn(); |
| 121 | |
| 122 | void writeUpdate(const rfb::UpdateInfo& ui, const rfb::PixelBuffer* pb); |
| 123 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 124 | void getStats(double&, unsigned long long&, unsigned long long&); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 125 | |
| 126 | virtual void setAccessRights(AccessRights ar); |
| 127 | |
| 128 | virtual void setDesktopSize(int fb_width, int fb_height, |
| 129 | const rfb::ScreenSet& layout); |
| 130 | |
| 131 | protected: |
| 132 | DummyOutStream *out; |
| 133 | Manager *manager; |
| 134 | }; |
| 135 | |
| 136 | DummyOutStream::DummyOutStream() |
| 137 | { |
| 138 | offset = 0; |
| 139 | ptr = buf; |
| 140 | end = buf + sizeof(buf); |
| 141 | } |
| 142 | |
| 143 | int DummyOutStream::length() |
| 144 | { |
| 145 | flush(); |
| 146 | return offset; |
| 147 | } |
| 148 | |
| 149 | void DummyOutStream::flush() |
| 150 | { |
| 151 | offset += ptr - buf; |
| 152 | ptr = buf; |
| 153 | } |
| 154 | |
| 155 | int DummyOutStream::overrun(int itemSize, int nItems) |
| 156 | { |
| 157 | flush(); |
Pierre Ossman | fc331e6 | 2015-03-03 16:42:45 +0100 | [diff] [blame] | 158 | if (itemSize * nItems > end - ptr) |
| 159 | nItems = (end - ptr) / itemSize; |
| 160 | return nItems; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | CConn::CConn(const char *filename) |
| 164 | { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 165 | decodeTime = 0.0; |
| 166 | encodeTime = 0.0; |
| 167 | |
| 168 | in = new rdr::FileInStream(filename); |
| 169 | setStreams(in, NULL); |
| 170 | |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 171 | // Need to skip the initial handshake and ServerInit |
| 172 | setState(RFBSTATE_NORMAL); |
| 173 | // That also means that the reader and writer weren't setup |
| 174 | setReader(new rfb::CMsgReader(this, in)); |
| 175 | // Nor the frame buffer size and format |
| 176 | setDesktopSize(width, height); |
| 177 | rfb::PixelFormat pf; |
| 178 | pf.parse(format); |
| 179 | setPixelFormat(pf); |
| 180 | |
| 181 | sc = new SConn(); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 182 | sc->cp.setPF((bool)translate ? fbPF : pf); |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 183 | sc->setEncodings(sizeof(encodings) / sizeof(*encodings), encodings); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | CConn::~CConn() |
| 187 | { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 188 | delete sc; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 189 | delete in; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 190 | } |
| 191 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 192 | void CConn::getStats(double& ratio, unsigned long long& bytes, |
| 193 | unsigned long long& rawEquivalent) |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 194 | { |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 195 | sc->getStats(ratio, bytes, rawEquivalent); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void CConn::setDesktopSize(int w, int h) |
| 199 | { |
| 200 | CConnection::setDesktopSize(w, h); |
| 201 | |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 202 | setFramebuffer(new rfb::ManagedPixelBuffer(sc->cp.pf(), cp.width, cp.height)); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void CConn::setCursor(int, int, const rfb::Point&, void*, void*) |
| 206 | { |
| 207 | } |
| 208 | |
| 209 | void CConn::framebufferUpdateStart() |
| 210 | { |
Pierre Ossman | 3da238d | 2015-11-12 12:20:05 +0100 | [diff] [blame] | 211 | CConnection::framebufferUpdateStart(); |
| 212 | |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 213 | updates.clear(); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 214 | startCpuCounter(); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void CConn::framebufferUpdateEnd() |
| 218 | { |
| 219 | rfb::UpdateInfo ui; |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 220 | rfb::PixelBuffer* pb = getFramebuffer(); |
| 221 | rfb::Region clip(pb->getRect()); |
| 222 | |
Pierre Ossman | 3da238d | 2015-11-12 12:20:05 +0100 | [diff] [blame] | 223 | CConnection::framebufferUpdateEnd(); |
| 224 | |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 225 | endCpuCounter(); |
| 226 | |
| 227 | decodeTime += getCpuCounter(); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 228 | |
| 229 | updates.getUpdateInfo(&ui, clip); |
| 230 | |
| 231 | startCpuCounter(); |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 232 | sc->writeUpdate(ui, pb); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 233 | endCpuCounter(); |
| 234 | |
| 235 | encodeTime += getCpuCounter(); |
| 236 | } |
| 237 | |
| 238 | void CConn::dataRect(const rfb::Rect &r, int encoding) |
| 239 | { |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 240 | CConnection::dataRect(r, encoding); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 241 | |
| 242 | if (encoding != rfb::encodingCopyRect) // FIXME |
| 243 | updates.add_changed(rfb::Region(r)); |
| 244 | } |
| 245 | |
| 246 | void CConn::setColourMapEntries(int, int, rdr::U16*) |
| 247 | { |
| 248 | } |
| 249 | |
| 250 | void CConn::bell() |
| 251 | { |
| 252 | } |
| 253 | |
| 254 | void CConn::serverCutText(const char*, rdr::U32) |
| 255 | { |
| 256 | } |
| 257 | |
| 258 | Manager::Manager(class rfb::SConnection *conn) : |
| 259 | EncodeManager(conn) |
| 260 | { |
| 261 | } |
| 262 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 263 | void Manager::getStats(double& ratio, unsigned long long& encodedBytes, |
| 264 | unsigned long long& rawEquivalent) |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 265 | { |
| 266 | StatsVector::iterator iter; |
| 267 | unsigned long long bytes, equivalent; |
| 268 | |
| 269 | bytes = equivalent = 0; |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 270 | for (iter = stats.begin(); iter != stats.end(); ++iter) { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 271 | StatsVector::value_type::iterator iter2; |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 272 | for (iter2 = iter->begin(); iter2 != iter->end(); ++iter2) { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 273 | bytes += iter2->bytes; |
| 274 | equivalent += iter2->equivalent; |
| 275 | } |
| 276 | } |
| 277 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 278 | ratio = (double)equivalent / bytes; |
| 279 | encodedBytes = bytes; |
| 280 | rawEquivalent = equivalent; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | SConn::SConn() |
| 284 | { |
| 285 | out = new DummyOutStream; |
| 286 | setStreams(NULL, out); |
| 287 | |
| 288 | setWriter(new rfb::SMsgWriter(&cp, out)); |
| 289 | |
| 290 | manager = new Manager(this); |
| 291 | } |
| 292 | |
| 293 | SConn::~SConn() |
| 294 | { |
| 295 | delete manager; |
| 296 | delete out; |
| 297 | } |
| 298 | |
| 299 | void SConn::writeUpdate(const rfb::UpdateInfo& ui, const rfb::PixelBuffer* pb) |
| 300 | { |
| 301 | manager->writeUpdate(ui, pb, NULL); |
| 302 | } |
| 303 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 304 | void SConn::getStats(double& ratio, unsigned long long& bytes, |
| 305 | unsigned long long& rawEquivalent) |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 306 | { |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 307 | manager->getStats(ratio, bytes, rawEquivalent); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void SConn::setAccessRights(AccessRights ar) |
| 311 | { |
| 312 | } |
| 313 | |
| 314 | void SConn::setDesktopSize(int fb_width, int fb_height, |
| 315 | const rfb::ScreenSet& layout) |
| 316 | { |
| 317 | } |
| 318 | |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 319 | static double runTest(const char *fn, double& ratio, unsigned long long& bytes, |
| 320 | unsigned long long& rawEquivalent) |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 321 | { |
| 322 | CConn *cc; |
| 323 | double time; |
| 324 | |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 325 | try { |
DRC | 13cfb51 | 2015-02-26 12:24:03 -0600 | [diff] [blame] | 326 | cc = new CConn(fn); |
Pierre Ossman | 86475a6 | 2015-03-03 16:42:15 +0100 | [diff] [blame] | 327 | } catch (rdr::Exception e) { |
| 328 | fprintf(stderr, "Failed to open rfb file: %s\n", e.str()); |
| 329 | exit(1); |
| 330 | } |
DRC | 13cfb51 | 2015-02-26 12:24:03 -0600 | [diff] [blame] | 331 | |
Pierre Ossman | 86475a6 | 2015-03-03 16:42:15 +0100 | [diff] [blame] | 332 | try { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 333 | while (true) |
| 334 | cc->processMsg(); |
| 335 | } catch (rdr::EndOfStream e) { |
| 336 | } catch (rdr::Exception e) { |
| 337 | fprintf(stderr, "Failed to run rfb file: %s\n", e.str()); |
| 338 | exit(1); |
| 339 | } |
| 340 | |
| 341 | time = cc->encodeTime; |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 342 | cc->getStats(ratio, bytes, rawEquivalent); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 343 | |
| 344 | delete cc; |
| 345 | |
| 346 | return time; |
| 347 | } |
| 348 | |
| 349 | static void sort(double *array, int count) |
| 350 | { |
| 351 | bool sorted; |
| 352 | int i; |
| 353 | do { |
| 354 | sorted = true; |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 355 | for (i = 1; i < count; i++) { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 356 | if (array[i-1] > array[i]) { |
| 357 | double d; |
| 358 | d = array[i]; |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 359 | array[i] = array[i - 1]; |
| 360 | array[i - 1] = d; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 361 | sorted = false; |
| 362 | } |
| 363 | } |
| 364 | } while (!sorted); |
| 365 | } |
| 366 | |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 367 | static void usage(const char *argv0) |
| 368 | { |
| 369 | fprintf(stderr, "Syntax: %s [options] <rfb file>\n", argv0); |
| 370 | fprintf(stderr, "Options:\n"); |
| 371 | rfb::Configuration::listParams(79, 14); |
| 372 | exit(1); |
| 373 | } |
| 374 | |
| 375 | int main(int argc, char **argv) |
| 376 | { |
| 377 | int i; |
| 378 | |
| 379 | const char *fn; |
| 380 | |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 381 | fn = NULL; |
| 382 | for (i = 1; i < argc; i++) { |
| 383 | if (rfb::Configuration::setParam(argv[i])) |
| 384 | continue; |
| 385 | |
| 386 | if (argv[i][0] == '-') { |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 387 | if (i + 1 < argc) { |
| 388 | if (rfb::Configuration::setParam(&argv[i][1], argv[i + 1])) { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 389 | i++; |
| 390 | continue; |
| 391 | } |
| 392 | } |
| 393 | usage(argv[0]); |
| 394 | } |
| 395 | |
| 396 | if (fn != NULL) |
| 397 | usage(argv[0]); |
| 398 | |
| 399 | fn = argv[i]; |
| 400 | } |
| 401 | |
DRC | 4631a76 | 2015-02-21 11:57:27 -0600 | [diff] [blame] | 402 | int runCount = count; |
| 403 | double times[runCount], dev[runCount]; |
| 404 | double median, meddev, ratio; |
| 405 | unsigned long long bytes, equivalent; |
| 406 | |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 407 | if (fn == NULL) { |
| 408 | fprintf(stderr, "No file specified!\n\n"); |
| 409 | usage(argv[0]); |
| 410 | } |
| 411 | |
Pierre Ossman | 135906e | 2015-04-27 12:48:47 +0200 | [diff] [blame] | 412 | if (strcmp(format, "") == 0) { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 413 | fprintf(stderr, "Pixel format not specified!\n\n"); |
| 414 | usage(argv[0]); |
| 415 | } |
| 416 | |
Pierre Ossman | 135906e | 2015-04-27 12:48:47 +0200 | [diff] [blame] | 417 | if (width == 0 || height == 0) { |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 418 | fprintf(stderr, "Frame buffer size not specified!\n\n"); |
| 419 | usage(argv[0]); |
| 420 | } |
| 421 | |
| 422 | // Warmup |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 423 | runTest(fn, ratio, bytes, equivalent); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 424 | |
| 425 | // Multiple runs to get a good average |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 426 | for (i = 0; i < runCount; i++) |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 427 | times[i] = runTest(fn, ratio, bytes, equivalent); |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 428 | |
| 429 | // Calculate median and median deviation |
| 430 | sort(times, runCount); |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 431 | median = times[runCount / 2]; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 432 | |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 433 | for (i = 0; i < runCount; i++) |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 434 | dev[i] = fabs((times[i] - median) / median) * 100; |
| 435 | |
| 436 | sort(dev, runCount); |
DRC | b4c4a38 | 2015-02-21 11:28:37 -0600 | [diff] [blame] | 437 | meddev = dev[runCount / 2]; |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 438 | |
DRC | e46dda6 | 2015-02-25 14:08:34 -0600 | [diff] [blame] | 439 | printf("CPU time: %g s (+/- %g %%)\n", median, meddev); |
Pierre Ossman | 7d218b0 | 2015-03-03 16:43:05 +0100 | [diff] [blame] | 440 | #ifdef WIN32 |
| 441 | printf("Encoded bytes: %I64d\n", bytes); |
| 442 | printf("Raw equivalent bytes: %I64d\n", equivalent); |
| 443 | #else |
DRC | 77be929 | 2015-02-21 11:44:26 -0600 | [diff] [blame] | 444 | printf("Encoded bytes: %lld\n", bytes); |
| 445 | printf("Raw equivalent bytes: %lld\n", equivalent); |
Pierre Ossman | 7d218b0 | 2015-03-03 16:43:05 +0100 | [diff] [blame] | 446 | #endif |
Pierre Ossman | 8738e8a | 2015-02-11 13:49:04 +0100 | [diff] [blame] | 447 | printf("Ratio: %g\n", ratio); |
| 448 | |
| 449 | return 0; |
| 450 | } |