4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "arraylist.h"
27 //#include "../downsample/downsampleengine.inc"
28 #include "loadbalance.h"
35 #define MOTION_FILE "/tmp/m"
37 class MotionScanPackage : public LoadPackage
42 // For multiple blocks
43 // Position of stationary block
44 int block_x1, block_y1, block_x2, block_y2;
45 // Range of positions to scan
46 int scan_x1, scan_y1, scan_x2, scan_y2;
49 int64_t max_difference;
50 int64_t min_difference;
58 // Search position to nearest pixel
61 // Subpixel of search position
69 MotionScanCache(int x, int y, int64_t difference);
74 class MotionScanUnit : public LoadClient
77 MotionScanUnit(MotionScan *server);
80 void process_package(LoadPackage *package);
81 int64_t get_cache(int x, int y);
82 void put_cache(int x, int y, int64_t difference);
86 ArrayList<MotionScanCache*> cache;
90 class MotionScan : public LoadServer
93 MotionScan(int total_clients,
97 friend class MotionScanUnit;
100 LoadClient* new_client();
101 LoadPackage* new_package();
102 // Test for identical frames before scanning
103 void set_test_match(int value);
105 // Invoke the motion engine for a search
106 // Frame before motion
107 void scan_frame(VFrame *previous_frame,
108 // Frame after motion
109 VFrame *current_frame,
126 int global_origin_y);
127 int64_t get_cache(int x, int y);
128 void put_cache(int x, int y, int64_t difference);
130 static int64_t abs_diff(unsigned char *prev_ptr,
131 unsigned char *current_ptr,
136 static int64_t abs_diff_sub(unsigned char *prev_ptr,
137 unsigned char *current_ptr,
146 static void clamp_scan(int w,
158 // Change between previous frame and current frame multiplied by
191 // Pointer to downsampled frame before motion
192 VFrame *previous_frame;
193 // Pointer to downsampled frame after motion
194 VFrame *current_frame;
195 // Frames passed from user
196 VFrame *previous_frame_arg;
197 VFrame *current_frame_arg;
198 // Downsampled frames
199 VFrame *downsampled_previous;
200 VFrame *downsampled_current;
201 // Test for identical frames before processing
202 // Faster to skip it if the frames are usually different
225 ArrayList<MotionScanCache*> cache;
227 // DownSampleServer *downsample;