@@ -2,6 +2,9 @@ local Thumbnailer = {
2
2
cache_directory = thumbnailer_options .cache_directory ,
3
3
4
4
state = {
5
+ -- Used to make sure updates sent to us by workers correspond to the
6
+ -- current state (the video hasn't changed)
7
+ id = 0 ,
5
8
ready = false ,
6
9
available = false ,
7
10
enabled = false ,
@@ -33,7 +36,10 @@ local Thumbnailer = {
33
36
}
34
37
35
38
function Thumbnailer :clear_state ()
39
+ local prev_state_id = self .state .id
40
+
36
41
clear_table (self .state )
42
+ self .state .id = prev_state_id + 1
37
43
self .state .ready = false
38
44
self .state .available = false
39
45
self .state .finished_thumbnails = 0
@@ -46,7 +52,11 @@ function Thumbnailer:on_file_loaded()
46
52
self :clear_state ()
47
53
end
48
54
49
- function Thumbnailer :on_thumb_ready (index )
55
+ function Thumbnailer :on_thumb_ready (state_id , index )
56
+ if self .state .id ~= state_id then
57
+ return
58
+ end
59
+
50
60
self .state .thumbnails [index ] = 1
51
61
52
62
-- Full recount instead of a naive increment (let's be safe!)
@@ -58,7 +68,11 @@ function Thumbnailer:on_thumb_ready(index)
58
68
end
59
69
end
60
70
61
- function Thumbnailer :on_thumb_progress (index )
71
+ function Thumbnailer :on_thumb_progress (state_id , index )
72
+ if self .state .id ~= state_id then
73
+ return
74
+ end
75
+
62
76
self .state .thumbnails [index ] = math.max (self .state .thumbnails [index ], 0 )
63
77
end
64
78
@@ -259,11 +273,11 @@ end
259
273
function Thumbnailer :register_client ()
260
274
self .worker_register_timeout = mp .get_time () + 2
261
275
262
- mp .register_script_message (" mpv_thumbnail_script-ready" , function (index , path )
263
- self :on_thumb_ready (tonumber (index ), path )
276
+ mp .register_script_message (" mpv_thumbnail_script-ready" , function (state_id , index , path )
277
+ self :on_thumb_ready (tonumber (state_id ), tonumber ( index ), path )
264
278
end )
265
- mp .register_script_message (" mpv_thumbnail_script-progress" , function (index , path )
266
- self :on_thumb_progress (tonumber (index ), path )
279
+ mp .register_script_message (" mpv_thumbnail_script-progress" , function (state_id , index , path )
280
+ self :on_thumb_progress (tonumber (state_id ), tonumber ( index ), path )
267
281
end )
268
282
269
283
mp .register_script_message (" mpv_thumbnail_script-worker" , function (worker_name )
@@ -371,7 +385,7 @@ function Thumbnailer:start_worker_jobs()
371
385
return
372
386
end
373
387
374
- local worker_list = {}
388
+ local worker_list = { state_id = self . state . id }
375
389
for worker_name in pairs (self .workers ) do table.insert (worker_list , worker_name ) end
376
390
377
391
local worker_count = # worker_list
0 commit comments