| 302 | |
| 303 | |
| 304 | class Compressor : public Runnable |
| 305 | { |
| 306 | public: |
| 307 | |
| 308 | Compressor(Decompressor *decompressor_, Blitter *blitter_) : findex(0), |
| 309 | deadYet(false), thread(NULL), decompressor(decompressor_) |
| 310 | #ifdef USEXV |
| 311 | , blitter(blitter_) |
| 312 | #endif |
| 313 | { |
| 314 | thread = new Thread(this); |
| 315 | thread->start(); |
| 316 | #ifdef USEHELGRIND |
| 317 | ANNOTATE_BENIGN_RACE_SIZED(&deadYet, sizeof(bool), ); |
| 318 | #endif |
| 319 | } |
| 320 | |
| 321 | virtual ~Compressor(void) |
| 322 | { |
| 323 | if(thread) thread->stop(); |
| 324 | } |
| 325 | |
| 326 | Frame &get(int width, int height, int pixelFormat) |
| 327 | { |
| 328 | Frame &frame = frames[findex]; |
| 329 | findex = (findex + 1) % NFRAMES; |
| 330 | if(thread) thread->checkError(); |
| 331 | if(!deadYet) frame.waitUntilComplete(); |
| 332 | if(thread) thread->checkError(); |
| 333 | rrframeheader hdr; |
| 334 | memset(&hdr, 0, sizeof(rrframeheader)); |
| 335 | hdr.framew = hdr.width = width + BORDER; |
| 336 | hdr.frameh = hdr.height = height + BORDER; |
| 337 | hdr.x = hdr.y = BORDER; |
| 338 | hdr.qual = 80; |
| 339 | hdr.subsamp = 2; |
| 340 | hdr.compress = useRGB ? RRCOMP_RGB : RRCOMP_JPEG; |
| 341 | if(useXV) hdr.compress = RRCOMP_YUV; |
| 342 | frame.init(hdr, pixelFormat, 0); |
| 343 | return frame; |
| 344 | } |
| 345 | |
| 346 | void put(Frame &frame) |
| 347 | { |
| 348 | if(thread) thread->checkError(); |
| 349 | frame.signalReady(); |
| 350 | } |
| 351 | |
| 352 | void shutdown(void) |
| 353 | { |
| 354 | deadYet = true; |
| 355 | int i; |
| 356 | for(i = 0; i < NFRAMES; i++) |
| 357 | frames[i].signalReady(); // Release my thread |
| 358 | if(thread) |
| 359 | { |
| 360 | thread->stop(); delete thread; thread = NULL; |
| 361 | } |
nothing calls this directly
no test coverage detected