2014-11-05 35 views
0

我試圖從Android相機捕獲原始視頻數據。 我正在使用Timer + TimerTask模式。計時器和TimerTask期間錯誤

long lastT = System.currentTimeMillis(); 
long curT = System.currentTimeMillis(); 
    timertask = new TimerTask() { 
       @Override 
       public void run() { 


        curT = System.currentTimeMillis(); 
        Log.d(TAG_VIDEO,">>\t" + (curT - lastT) + "\t::\t");// + data.length); 
        lastT = curT; 
} 
}; 
timer.scheduleAtFixedRate(timertask, 0L, 1000L/15L); 

但LogCat說內胎面每3-170毫秒發射一次。 Omg爲什麼?如何解決它? 其他方法(Handler,Thread)給出了相同的結果。 日誌:

11-05 17:54:27.550: >> 67 :: 
11-05 17:54:27.620: >> 65 :: 
11-05 17:54:27.685: >> 66 :: 
11-05 17:54:27.750: >> 66 :: 
11-05 17:54:27.815: >> 66 :: 
11-05 17:54:27.880: >> 67 :: 
11-05 17:54:27.945: >> 65 :: 
11-05 17:54:28.015: >> 66 :: 
11-05 17:54:28.080: >> 66 :: 
11-05 17:54:28.145: >> 66 :: 
11-05 17:54:28.250: >> 66 :: 
11-05 17:54:28.280: >> 68 :: 
11-05 17:54:28.450: >> 168 :: 
11-05 17:54:28.450: >> 3 :: 
11-05 17:54:28.475: >> 25 :: 
11-05 17:54:28.550: >> 77 :: 
11-05 17:54:28.650: >> 95 :: 
11-05 17:54:28.675: >> 26 :: 
11-05 17:54:28.740: >> 66 :: 
11-05 17:54:28.805: >> 66 :: 
11-05 17:54:28.930: >> 76 :: 
11-05 17:54:28.940: >> 57 :: 
11-05 17:54:29.125: >> 95 :: 
11-05 17:54:29.130: >> 95 :: 
11-05 17:54:29.160: >> 30 :: 
11-05 17:54:29.280: >> 69 :: 
11-05 17:54:29.280: >> 51 :: 
11-05 17:54:29.380: >> 103 :: 
11-05 17:54:29.470: >> 48 :: 
11-05 17:54:29.470: >> 41 :: 
11-05 17:54:29.575: >> 105 :: 
11-05 17:54:29.670: >> 44 :: 
11-05 17:54:29.670: >> 50 :: 
11-05 17:54:29.765: >> 91 :: 
11-05 17:54:29.855: >> 49 :: 
11-05 17:54:29.865: >> 54 :: 
11-05 17:54:29.950: >> 87 :: 
11-05 17:54:30.005: >> 52 :: 
11-05 17:54:30.085: >> 79 :: 
11-05 17:54:30.130: >> 46 :: 
11-05 17:54:30.280: >> 153 :: 
11-05 17:54:30.280: >> 2 :: 
11-05 17:54:30.435: >> 66 :: 
11-05 17:54:30.525: >> 88 :: 
11-05 17:54:30.525: >> 89 :: 
11-05 17:54:30.525: >> 0 :: 
11-05 17:54:30.600: >> 63 :: 
11-05 17:54:30.730: >> 79 :: 
11-05 17:54:30.730: >> 63 :: 
11-05 17:54:30.835: >> 56 :: 
11-05 17:54:30.940: >> 106 :: 
11-05 17:54:30.940: >> 48 :: 
11-05 17:54:31.055: >> 67 :: 
11-05 17:54:31.055: >> 47 :: 
11-05 17:54:31.210: >> 148 :: 
11-05 17:54:31.210: >> 6 :: 
11-05 17:54:31.335: >> 65 :: 
11-05 17:54:31.335: >> 62 :: 
11-05 17:54:31.450: >> 61 :: 
11-05 17:54:31.450: >> 55 :: 
11-05 17:54:31.535: >> 84 :: 
11-05 17:54:31.605: >> 70 :: 
11-05 17:54:31.675: >> 69 :: 
11-05 17:54:31.755: >> 35 :: 
11-05 17:54:31.855: >> 99 :: 
11-05 17:54:31.860: >> 49 :: 
11-05 17:54:31.950: >> 94 :: 
11-05 17:54:32.045: >> 54 :: 
11-05 17:54:32.045: >> 41 :: 
11-05 17:54:32.200: >> 102 :: 
11-05 17:54:32.200: >> 50 :: 
11-05 17:54:32.335: >> 66 :: 
11-05 17:54:32.335: >> 69 :: 
11-05 17:54:32.440: >> 52 :: 
11-05 17:54:32.440: >> 55 :: 
11-05 17:54:32.550: >> 106 :: 
11-05 17:54:32.640: >> 53 :: 
11-05 17:54:32.645: >> 42 :: 
11-05 17:54:32.760: >> 64 :: 
11-05 17:54:32.765: >> 61 :: 
11-05 17:54:32.865: >> 91 :: 
11-05 17:54:32.980: >> 58 :: 
11-05 17:54:32.980: >> 66 :: 
11-05 17:54:33.100: >> 60 :: 
11-05 17:54:33.100: >> 59 :: 
11-05 17:54:33.235: >> 127 :: 
11-05 17:54:33.235: >> 6 :: 
11-05 17:54:33.340: >> 106 :: 
11-05 17:54:33.430: >> 52 :: 
11-05 17:54:33.440: >> 40 :: 
11-05 17:54:33.535: >> 103 :: 
11-05 17:54:33.650: >> 48 :: 
11-05 17:54:33.650: >> 68 :: 
11-05 17:54:33.760: >> 52 :: 
11-05 17:54:33.760: >> 59 :: 
11-05 17:54:33.860: >> 91 :: 
11-05 17:54:34.065: >> 42 :: 
11-05 17:54:34.100: >> 172 :: 
11-05 17:54:34.100: >> 36 :: 
11-05 17:54:34.105: >> 2 :: 
11-05 17:54:34.220: >> 76 :: 
11-05 17:54:34.230: >> 40 :: 
11-05 17:54:34.370: >> 112 :: 
11-05 17:54:34.370: >> 38 :: 
11-05 17:54:34.505: >> 84 :: 
11-05 17:54:34.505: >> 52 :: 
11-05 17:54:34.590: >> 41 :: 
11-05 17:54:34.670: >> 82 :: 
11-05 17:54:34.750: >> 80 :: 
11-05 17:54:34.750: >> 42 :: 
11-05 17:54:34.830: >> 77 :: 
11-05 17:54:34.905: >> 74 :: 
11-05 17:54:35.005: >> 41 :: 
11-05 17:54:35.010: >> 67 :: 
11-05 17:54:35.105: >> 92 :: 
11-05 17:54:35.235: >> 61 :: 
11-05 17:54:35.235: >> 74 :: 
11-05 17:54:35.370: >> 68 :: 
11-05 17:54:35.370: >> 66 :: 
11-05 17:54:35.475: >> 53 :: 
11-05 17:54:35.475: >> 50 :: 
11-05 17:54:35.580: >> 106 :: 
11-05 17:54:35.670: >> 50 :: 
11-05 17:54:35.675: >> 43 :: 
11-05 17:54:35.735: >> 62 :: 
11-05 17:54:35.800: >> 67 :: 
11-05 17:54:35.865: >> 65 :: 
11-05 17:54:35.935: >> 66 :: 
11-05 17:54:36.000: >> 66 :: 
11-05 17:54:36.065: >> 66 :: 
11-05 17:54:36.130: >> 67 :: 
11-05 17:54:36.195: >> 65 :: 
11-05 17:54:36.265: >> 66 :: 
11-05 17:54:36.415: >> 105 :: 
11-05 17:54:36.415: >> 46 :: 
11-05 17:54:36.460: >> 47 :: 
11-05 17:54:36.525: >> 66 :: 
11-05 17:54:36.595: >> 66 :: 
11-05 17:54:36.660: >> 68 :: 
11-05 17:54:36.725: >> 64 :: 
11-05 17:54:36.790: >> 66 :: 
11-05 17:54:36.860: >> 67 :: 
11-05 17:54:36.925: >> 66 :: 
11-05 17:54:37.130: >> 202 :: 
11-05 17:54:37.135: >> 3 :: 
11-05 17:54:37.140: >> 8 :: 
11-05 17:54:37.200: >> 57 :: 
11-05 17:54:37.255: >> 59 :: 
11-05 17:54:37.320: >> 67 :: 
11-05 17:54:37.385: >> 66 :: 
11-05 17:54:37.465: >> 77 :: 
11-05 17:54:37.850: >> 140 :: 
11-05 17:54:37.855: >> 250 :: 
11-05 17:54:37.855: >> 2 :: 
11-05 17:54:37.855: >> 1 :: 
11-05 17:54:37.855: >> 1 :: 
11-05 17:54:37.860: >> 0 :: 
11-05 17:54:37.915: >> 58 :: 
11-05 17:54:37.985: >> 68 :: 
11-05 17:54:38.165: >> 93 :: 
11-05 17:54:38.165: >> 90 :: 
11-05 17:54:38.180: >> 13 :: 
11-05 17:54:38.600: >> 82 :: 
11-05 17:54:38.610: >> 337 :: 
11-05 17:54:38.610: >> 10 :: 
11-05 17:54:38.610: >> 2 :: 
11-05 17:54:38.610: >> 1 :: 
11-05 17:54:38.610: >> 0 :: 
11-05 17:54:38.650: >> 37 :: 
11-05 17:54:38.850: >> 131 :: 
11-05 17:54:39.130: >> 137 :: 
11-05 17:54:39.130: >> 212 :: 
11-05 17:54:39.130: >> 0 :: 
11-05 17:54:39.130: >> 0 :: 
11-05 17:54:39.130: >> 0 :: 
11-05 17:54:39.130: >> 0 :: 
11-05 17:54:39.265: >> 69 :: 
11-05 17:54:39.270: >> 70 :: 
11-05 17:54:39.420: >> 62 :: 
11-05 17:54:39.420: >> 90 :: 
11-05 17:54:39.640: >> 63 :: 
11-05 17:54:39.640: >> 157 :: 
11-05 17:54:39.640: >> 1 :: 
11-05 17:54:39.640: >> 1 :: 
11-05 17:54:39.745: >> 55 :: 
11-05 17:54:39.765: >> 67 :: 
11-05 17:54:39.895: >> 133 :: 
11-05 17:54:39.895: >> 1 :: 
11-05 17:54:40.035: >> 63 :: 
11-05 17:54:40.035: >> 73 :: 
11-05 17:54:40.200: >> 72 :: 
11-05 17:54:40.205: >> 99 :: 
11-05 17:54:40.405: >> 63 :: 
11-05 17:54:40.405: >> 136 :: 
11-05 17:54:40.405: >> 0 :: 
11-05 17:54:40.425: >> 20 :: 
11-05 17:54:40.575: >> 68 :: 
11-05 17:54:40.575: >> 82 :: 
11-05 17:54:40.840: >> 90 :: 
11-05 17:54:40.900: >> 233 :: 
11-05 17:54:40.900: >> 3 :: 
11-05 17:54:40.910: >> 9 :: 
11-05 17:54:40.910: >> 3 :: 
11-05 17:54:41.010: >> 47 :: 
11-05 17:54:41.015: >> 57 :: 
11-05 17:54:41.110: >> 95 :: 
11-05 17:54:41.265: >> 58 :: 
11-05 17:54:41.270: >> 100 :: 
11-05 17:54:41.425: >> 73 :: 
11-05 17:54:41.425: >> 82 :: 
11-05 17:54:41.425: >> 0 :: 
11-05 17:54:41.510: >> 86 :: 
11-05 17:54:41.595: >> 46 :: 
11-05 17:54:41.700: >> 76 :: 
11-05 17:54:41.700: >> 68 :: 
11-05 17:54:41.815: >> 61 :: 
11-05 17:54:41.815: >> 56 :: 
11-05 17:54:42.010: >> 75 :: 
11-05 17:54:42.080: >> 119 :: 
11-05 17:54:42.080: >> 71 :: 
11-05 17:54:42.080: >> 1 :: 
11-05 17:54:42.340: >> 137 :: 
11-05 17:54:42.340: >> 121 :: 
11-05 17:54:42.340: >> 0 :: 
11-05 17:54:42.340: >> 0 :: 
11-05 17:54:42.485: >> 79 :: 
11-05 17:54:42.485: >> 64 :: 
11-05 17:54:42.535: >> 53 :: 
11-05 17:54:42.645: >> 106 :: 
11-05 17:54:42.850: >> 56 :: 
11-05 17:54:42.850: >> 151 :: 
11-05 17:54:42.850: >> 1 :: 
11-05 17:54:42.895: >> 41 :: 
11-05 17:54:43.030: >> 74 :: 
11-05 17:54:43.035: >> 68 :: 
11-05 17:54:43.200: >> 62 :: 
11-05 17:54:43.200: >> 104 :: 
11-05 17:54:43.200: >> 0 :: 
11-05 17:54:43.365: >> 70 :: 
11-05 17:54:43.365: >> 95 :: 
11-05 17:54:43.495: >> 70 :: 
11-05 17:54:43.495: >> 60 :: 
11-05 17:54:43.695: >> 101 :: 
11-05 17:54:43.695: >> 98 :: 
11-05 17:54:43.695: >> 0 :: 
11-05 17:54:43.790: >> 46 :: 
11-05 17:54:43.790: >> 53 :: 
11-05 17:54:43.900: >> 101 :: 
11-05 17:54:44.000: >> 48 :: 
11-05 17:54:44.000: >> 58 :: 
11-05 17:54:44.155: >> 70 :: 
11-05 17:54:44.155: >> 88 :: 
11-05 17:54:44.380: >> 98 :: 
11-05 17:54:44.385: >> 126 :: 
11-05 17:54:44.385: >> 2 :: 
11-05 17:54:44.385: >> 3 :: 
11-05 17:54:44.535: >> 149 :: 
11-05 17:54:44.535: >> 0 :: 
11-05 17:54:44.945: >> 91 :: 
11-05 17:54:44.945: >> 316 :: 
11-05 17:54:44.945: >> 1 :: 
11-05 17:54:44.945: >> 0 :: 
11-05 17:54:44.945: >> 0 :: 
11-05 17:54:44.945: >> 0 :: 
11-05 17:54:44.995: >> 48 :: 
11-05 17:54:45.115: >> 70 :: 
11-05 17:54:45.115: >> 53 :: 
11-05 17:54:45.260: >> 65 :: 
11-05 17:54:45.260: >> 82 :: 
11-05 17:54:45.365: >> 64 :: 
11-05 17:54:45.370: >> 46 :: 
11-05 17:54:45.475: >> 101 :: 
11-05 17:54:45.590: >> 58 :: 
11-05 17:54:45.590: >> 58 :: 
11-05 17:54:45.700: >> 57 :: 
11-05 17:54:45.700: >> 56 :: 
11-05 17:54:45.825: >> 121 :: 
11-05 17:54:45.915: >> 47 :: 
11-05 17:54:45.915: >> 44 :: 
11-05 17:54:46.015: >> 99 :: 
11-05 17:54:46.130: >> 61 :: 
11-05 17:54:46.130: >> 58 :: 
11-05 17:54:46.265: >> 134 :: 
11-05 17:54:46.270: >> 3 :: 
11-05 17:54:46.500: >> 71 :: 
11-05 17:54:46.500: >> 160 :: 
11-05 17:54:46.500: >> 0 :: 
11-05 17:54:46.500: >> 0 :: 
11-05 17:54:46.560: >> 60 :: 
11-05 17:54:46.645: >> 85 :: 
11-05 17:54:46.765: >> 52 :: 
11-05 17:54:46.765: >> 68 :: 
11-05 17:54:46.855: >> 90 :: 
11-05 17:54:46.940: >> 44 :: 
11-05 17:54:47.025: >> 78 :: 
11-05 17:54:47.025: >> 51 :: 
11-05 17:54:47.125: >> 97 :: 
11-05 17:54:47.240: >> 45 :: 
11-05 17:54:47.240: >> 70 :: 
11-05 17:54:47.360: >> 47 :: 
11-05 17:54:47.450: >> 115 :: 
11-05 17:54:47.455: >> 52 :: 
11-05 17:54:47.540: >> 47 :: 
11-05 17:54:47.550: >> 49 :: 
11-05 17:54:47.625: >> 77 :: 
11-05 17:54:47.710: >> 84 :: 
11-05 17:54:47.800: >> 42 :: 
11-05 17:54:47.815: >> 61 :: 
11-05 17:54:47.895: >> 78 :: 
11-05 17:54:47.970: >> 78 :: 
11-05 17:54:48.070: >> 44 :: 
11-05 17:54:48.155: >> 91 :: 
11-05 17:54:48.155: >> 49 :: 
11-05 17:54:48.260: >> 60 :: 
11-05 17:54:48.470: >> 85 :: 
11-05 17:54:48.470: >> 170 :: 
11-05 17:54:48.470: >> 0 :: 
11-05 17:54:48.570: >> 45 :: 
11-05 17:54:48.570: >> 59 :: 
11-05 17:54:48.605: >> 33 :: 
11-05 17:54:48.735: >> 69 :: 
11-05 17:54:48.740: >> 64 :: 

回答

0

我認爲問題是,你正在試圖做的實時圖像處理與Java和Android。 Java Runtime具有垃圾收集機制,可在收集內存中未引用的對象時暫停應用程序線程。所以你看到的變化(抖動)是由於垃圾收集線程正在運行。

+0

即使我試圖直接使用我之前編寫的代碼,循環也有這種滯後。沒有其他圖像使用methods.just簡單timertask – Vyacheslav 2014-11-05 14:39:49

+0

所以也許嘗試改變計時器的優先級。 http://stackoverflow.com/q/18739748/588532 – 2014-11-05 14:44:02