]> git.sesse.net Git - nageru/blob - theme.cpp
Move WIDTH/HEIGHT #defines into defs.h.
[nageru] / theme.cpp
1 #include "theme.h"
2
3 #include <assert.h>
4 #include <lauxlib.h>
5 #include <lua.h>
6 #include <lualib.h>
7 #include <movit/effect.h>
8 #include <movit/effect_chain.h>
9 #include <movit/image_format.h>
10 #include <movit/mix_effect.h>
11 #include <movit/overlay_effect.h>
12 #include <movit/padding_effect.h>
13 #include <movit/resample_effect.h>
14 #include <movit/resize_effect.h>
15 #include <movit/white_balance_effect.h>
16 #include <movit/ycbcr.h>
17 #include <movit/ycbcr_input.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <cstddef>
21 #include <new>
22 #include <utility>
23 #include <memory>
24
25 #include "defs.h"
26 #include "image_input.h"
27
28 namespace movit {
29 class ResourcePool;
30 }  // namespace movit
31
32 using namespace std;
33 using namespace movit;
34
35 namespace {
36
37 vector<LiveInputWrapper *> live_inputs;
38
39 class LuaRefWithDeleter {
40 public:
41         LuaRefWithDeleter(mutex *m, lua_State *L, int ref) : m(m), L(L), ref(ref) {}
42         ~LuaRefWithDeleter() {
43                 unique_lock<mutex> lock(*m);
44                 luaL_unref(L, LUA_REGISTRYINDEX, ref);
45         }
46         int get() const { return ref; }
47
48 private:
49         LuaRefWithDeleter(const LuaRefWithDeleter &) = delete;
50
51         mutex *m;
52         lua_State *L;
53         int ref;
54 };
55
56 template<class T, class... Args>
57 int wrap_lua_object(lua_State* L, const char *class_name, Args&&... args)
58 {
59         // Construct the C++ object and put it on the stack.
60         void *mem = lua_newuserdata(L, sizeof(T));
61         new(mem) T(std::forward<Args>(args)...);
62
63         // Look up the metatable named <class_name>, and set it on the new object.
64         luaL_getmetatable(L, class_name);
65         lua_setmetatable(L, -2);
66
67         return 1;
68 }
69
70 Theme *get_theme_updata(lua_State* L)
71 {       
72         luaL_checktype(L, lua_upvalueindex(1), LUA_TLIGHTUSERDATA);
73         return (Theme *)lua_touserdata(L, lua_upvalueindex(1));
74 }
75
76 Effect *get_effect(lua_State *L, int idx)
77 {
78         if (luaL_testudata(L, idx, "WhiteBalanceEffect") ||
79             luaL_testudata(L, idx, "ResampleEffect") ||
80             luaL_testudata(L, idx, "PaddingEffect") ||
81             luaL_testudata(L, idx, "IntegralPaddingEffect") ||
82             luaL_testudata(L, idx, "OverlayEffect") ||
83             luaL_testudata(L, idx, "ResizeEffect") ||
84             luaL_testudata(L, idx, "MixEffect") ||
85             luaL_testudata(L, idx, "ImageInput")) {
86                 return (Effect *)lua_touserdata(L, idx);
87         }
88         luaL_error(L, "Error: Index #%d was not an Effect type\n", idx);
89         return nullptr;
90 }
91
92 bool checkbool(lua_State* L, int idx)
93 {
94         luaL_checktype(L, idx, LUA_TBOOLEAN);
95         return lua_toboolean(L, idx);
96 }
97
98 std::string checkstdstring(lua_State *L, int index)
99 {
100         size_t len;
101         const char* cstr = lua_tolstring(L, index, &len);
102         return std::string(cstr, len);
103 }
104
105 int EffectChain_new(lua_State* L)
106 {
107         assert(lua_gettop(L) == 2);
108         int aspect_w = luaL_checknumber(L, 1);
109         int aspect_h = luaL_checknumber(L, 2);
110
111         return wrap_lua_object<EffectChain>(L, "EffectChain", aspect_w, aspect_h);
112 }
113
114 int EffectChain_add_live_input(lua_State* L)
115 {
116         assert(lua_gettop(L) == 2);
117         Theme *theme = get_theme_updata(L);
118         EffectChain *chain = (EffectChain *)luaL_checkudata(L, 1, "EffectChain");
119         bool override_bounce = checkbool(L, 2);
120         return wrap_lua_object<LiveInputWrapper>(L, "LiveInputWrapper", theme, chain, override_bounce);
121 }
122
123 int EffectChain_add_effect(lua_State* L)
124 {
125         assert(lua_gettop(L) >= 2);
126         EffectChain *chain = (EffectChain *)luaL_checkudata(L, 1, "EffectChain");
127
128         // TODO: Better error reporting.
129         Effect *effect = get_effect(L, 2);
130         if (lua_gettop(L) == 2) {
131                 if (effect->num_inputs() == 0) {
132                         chain->add_input((Input *)effect);
133                 } else {
134                         chain->add_effect(effect);
135                 }
136         } else {
137                 vector<Effect *> inputs;
138                 for (int idx = 3; idx <= lua_gettop(L); ++idx) {
139                         if (luaL_testudata(L, idx, "LiveInputWrapper")) {
140                                 LiveInputWrapper *input = (LiveInputWrapper *)lua_touserdata(L, idx);
141                                 inputs.push_back(input->get_input());
142                         } else {
143                                 inputs.push_back(get_effect(L, idx));
144                         }
145                 }
146                 chain->add_effect(effect, inputs);
147         }
148
149         lua_settop(L, 2);  // Return the effect itself.
150
151         // Make sure Lua doesn't garbage-collect it away.
152         lua_pushvalue(L, -1);
153         luaL_ref(L, LUA_REGISTRYINDEX);  // TODO: leak?
154
155         return 1;
156 }
157
158 int EffectChain_finalize(lua_State* L)
159 {
160         assert(lua_gettop(L) == 2);
161         EffectChain *chain = (EffectChain *)luaL_checkudata(L, 1, "EffectChain");
162         bool is_main_chain = checkbool(L, 2);
163
164         // Add outputs as needed.
165         // NOTE: If you change any details about the output format, you will need to
166         // also update what's given to the muxer (HTTPD::Mux constructor) and
167         // what's put in the H.264 stream (sps_rbsp()).
168         ImageFormat inout_format;
169         inout_format.color_space = COLORSPACE_REC_709;
170
171         // Output gamma is tricky. We should output Rec. 709 for TV, except that
172         // we expect to run with web players and others that don't really care and
173         // just output with no conversion. So that means we'll need to output sRGB,
174         // even though H.264 has no setting for that (we use “unspecified”).
175         inout_format.gamma_curve = GAMMA_sRGB;
176
177         if (is_main_chain) {
178                 YCbCrFormat output_ycbcr_format;
179                 // We actually output 4:2:0 in the end, but chroma subsampling
180                 // happens in a pass not run by Movit (see Mixer::subsample_chroma()).
181                 output_ycbcr_format.chroma_subsampling_x = 1;
182                 output_ycbcr_format.chroma_subsampling_y = 1;
183
184                 // Rec. 709 would be the sane thing to do, but it seems many players
185                 // (e.g. MPlayer and VLC) just default to BT.601 coefficients no matter
186                 // what (see discussions in e.g. https://trac.ffmpeg.org/ticket/4978).
187                 // We _do_ set the right flags, though, so that a player that works
188                 // properly doesn't have to guess.
189                 output_ycbcr_format.luma_coefficients = YCBCR_REC_601;
190                 output_ycbcr_format.full_range = false;
191                 output_ycbcr_format.num_levels = 256;
192
193                 chain->add_ycbcr_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED, output_ycbcr_format, YCBCR_OUTPUT_SPLIT_Y_AND_CBCR);
194                 chain->set_dither_bits(8);
195                 chain->set_output_origin(OUTPUT_ORIGIN_TOP_LEFT);
196         }
197         chain->add_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
198
199         chain->finalize();
200         return 0;
201 }
202
203 int LiveInputWrapper_connect_signal(lua_State* L)
204 {
205         assert(lua_gettop(L) == 2);
206         LiveInputWrapper *input = (LiveInputWrapper *)luaL_checkudata(L, 1, "LiveInputWrapper");
207         int signal_num = luaL_checknumber(L, 2);
208         input->connect_signal(signal_num);
209         return 0;
210 }
211
212 int ImageInput_new(lua_State* L)
213 {
214         assert(lua_gettop(L) == 1);
215         std::string filename = checkstdstring(L, 1);
216         return wrap_lua_object<ImageInput>(L, "ImageInput", filename);
217 }
218
219 int WhiteBalanceEffect_new(lua_State* L)
220 {
221         assert(lua_gettop(L) == 0);
222         return wrap_lua_object<WhiteBalanceEffect>(L, "WhiteBalanceEffect");
223 }
224
225 int ResampleEffect_new(lua_State* L)
226 {
227         assert(lua_gettop(L) == 0);
228         return wrap_lua_object<ResampleEffect>(L, "ResampleEffect");
229 }
230
231 int PaddingEffect_new(lua_State* L)
232 {
233         assert(lua_gettop(L) == 0);
234         return wrap_lua_object<PaddingEffect>(L, "PaddingEffect");
235 }
236
237 int IntegralPaddingEffect_new(lua_State* L)
238 {
239         assert(lua_gettop(L) == 0);
240         return wrap_lua_object<IntegralPaddingEffect>(L, "IntegralPaddingEffect");
241 }
242
243 int OverlayEffect_new(lua_State* L)
244 {
245         assert(lua_gettop(L) == 0);
246         return wrap_lua_object<OverlayEffect>(L, "OverlayEffect");
247 }
248
249 int ResizeEffect_new(lua_State* L)
250 {
251         assert(lua_gettop(L) == 0);
252         return wrap_lua_object<ResizeEffect>(L, "ResizeEffect");
253 }
254
255 int MixEffect_new(lua_State* L)
256 {
257         assert(lua_gettop(L) == 0);
258         return wrap_lua_object<MixEffect>(L, "MixEffect");
259 }
260
261 int Effect_set_float(lua_State *L)
262 {
263         assert(lua_gettop(L) == 3);
264         Effect *effect = (Effect *)get_effect(L, 1);
265         std::string key = checkstdstring(L, 2);
266         float value = luaL_checknumber(L, 3);
267         if (!effect->set_float(key, value)) {
268                 luaL_error(L, "Effect refused set_float(\"%s\", %d) (invalid key?)", key.c_str(), int(value));
269         }
270         return 0;
271 }
272
273 int Effect_set_int(lua_State *L)
274 {
275         assert(lua_gettop(L) == 3);
276         Effect *effect = (Effect *)get_effect(L, 1);
277         std::string key = checkstdstring(L, 2);
278         float value = luaL_checknumber(L, 3);
279         if (!effect->set_int(key, value)) {
280                 luaL_error(L, "Effect refused set_int(\"%s\", %d) (invalid key?)", key.c_str(), int(value));
281         }
282         return 0;
283 }
284
285 int Effect_set_vec3(lua_State *L)
286 {
287         assert(lua_gettop(L) == 5);
288         Effect *effect = (Effect *)get_effect(L, 1);
289         std::string key = checkstdstring(L, 2);
290         float v[3];
291         v[0] = luaL_checknumber(L, 3);
292         v[1] = luaL_checknumber(L, 4);
293         v[2] = luaL_checknumber(L, 5);
294         if (!effect->set_vec3(key, v)) {
295                 luaL_error(L, "Effect refused set_vec3(\"%s\", %f, %f, %f) (invalid key?)", key.c_str(),
296                         v[0], v[1], v[2]);
297         }
298         return 0;
299 }
300
301 int Effect_set_vec4(lua_State *L)
302 {
303         assert(lua_gettop(L) == 6);
304         Effect *effect = (Effect *)get_effect(L, 1);
305         std::string key = checkstdstring(L, 2);
306         float v[4];
307         v[0] = luaL_checknumber(L, 3);
308         v[1] = luaL_checknumber(L, 4);
309         v[2] = luaL_checknumber(L, 5);
310         v[3] = luaL_checknumber(L, 6);
311         if (!effect->set_vec4(key, v)) {
312                 luaL_error(L, "Effect refused set_vec4(\"%s\", %f, %f, %f, %f) (invalid key?)", key.c_str(),
313                         v[0], v[1], v[2], v[3]);
314         }
315         return 0;
316 }
317
318 const luaL_Reg EffectChain_funcs[] = {
319         { "new", EffectChain_new },
320         { "add_live_input", EffectChain_add_live_input },
321         { "add_effect", EffectChain_add_effect },
322         { "finalize", EffectChain_finalize },
323         { NULL, NULL }
324 };
325
326 const luaL_Reg LiveInputWrapper_funcs[] = {
327         { "connect_signal", LiveInputWrapper_connect_signal },
328         { NULL, NULL }
329 };
330
331 const luaL_Reg ImageInput_funcs[] = {
332         { "new", ImageInput_new },
333         { "set_float", Effect_set_float },
334         { "set_int", Effect_set_int },
335         { "set_vec3", Effect_set_vec3 },
336         { "set_vec4", Effect_set_vec4 },
337         { NULL, NULL }
338 };
339
340 const luaL_Reg WhiteBalanceEffect_funcs[] = {
341         { "new", WhiteBalanceEffect_new },
342         { "set_float", Effect_set_float },
343         { "set_int", Effect_set_int },
344         { "set_vec3", Effect_set_vec3 },
345         { "set_vec4", Effect_set_vec4 },
346         { NULL, NULL }
347 };
348
349 const luaL_Reg ResampleEffect_funcs[] = {
350         { "new", ResampleEffect_new },
351         { "set_float", Effect_set_float },
352         { "set_int", Effect_set_int },
353         { "set_vec3", Effect_set_vec3 },
354         { "set_vec4", Effect_set_vec4 },
355         { NULL, NULL }
356 };
357
358 const luaL_Reg PaddingEffect_funcs[] = {
359         { "new", PaddingEffect_new },
360         { "set_float", Effect_set_float },
361         { "set_int", Effect_set_int },
362         { "set_vec3", Effect_set_vec3 },
363         { "set_vec4", Effect_set_vec4 },
364         { NULL, NULL }
365 };
366
367 const luaL_Reg IntegralPaddingEffect_funcs[] = {
368         { "new", IntegralPaddingEffect_new },
369         { "set_float", Effect_set_float },
370         { "set_int", Effect_set_int },
371         { "set_vec3", Effect_set_vec3 },
372         { "set_vec4", Effect_set_vec4 },
373         { NULL, NULL }
374 };
375
376 const luaL_Reg OverlayEffect_funcs[] = {
377         { "new", OverlayEffect_new },
378         { "set_float", Effect_set_float },
379         { "set_int", Effect_set_int },
380         { "set_vec3", Effect_set_vec3 },
381         { "set_vec4", Effect_set_vec4 },
382         { NULL, NULL }
383 };
384
385 const luaL_Reg ResizeEffect_funcs[] = {
386         { "new", ResizeEffect_new },
387         { "set_float", Effect_set_float },
388         { "set_int", Effect_set_int },
389         { "set_vec3", Effect_set_vec3 },
390         { "set_vec4", Effect_set_vec4 },
391         { NULL, NULL }
392 };
393
394 const luaL_Reg MixEffect_funcs[] = {
395         { "new", MixEffect_new },
396         { "set_float", Effect_set_float },
397         { "set_int", Effect_set_int },
398         { "set_vec3", Effect_set_vec3 },
399         { "set_vec4", Effect_set_vec4 },
400         { NULL, NULL }
401 };
402
403 }  // namespace
404
405 LiveInputWrapper::LiveInputWrapper(Theme *theme, EffectChain *chain, bool override_bounce)
406         : theme(theme)
407 {
408         ImageFormat inout_format;
409         inout_format.color_space = COLORSPACE_sRGB;
410
411         // Gamma curve depends on the input signal, and we don't really get any
412         // indications. A camera would be expected to do Rec. 709, but
413         // I haven't checked if any do in practice. However, computers _do_ output
414         // in sRGB gamma (ie., they don't convert from sRGB to Rec. 709), and
415         // I wouldn't really be surprised if most non-professional cameras do, too.
416         // So we pick sRGB as the least evil here.
417         inout_format.gamma_curve = GAMMA_sRGB;
418
419         // The Blackmagic driver docs claim that the device outputs Y'CbCr
420         // according to Rec. 601, but practical testing indicates it definitely
421         // is Rec. 709 (at least up to errors attributable to rounding errors).
422         // Perhaps 601 was only to indicate the subsampling positions, not the
423         // colorspace itself? Tested with a Lenovo X1 gen 3 as input.
424         YCbCrFormat input_ycbcr_format;
425         input_ycbcr_format.chroma_subsampling_x = 2;
426         input_ycbcr_format.chroma_subsampling_y = 1;
427         input_ycbcr_format.cb_x_position = 0.0;
428         input_ycbcr_format.cr_x_position = 0.0;
429         input_ycbcr_format.cb_y_position = 0.5;
430         input_ycbcr_format.cr_y_position = 0.5;
431         input_ycbcr_format.luma_coefficients = YCBCR_REC_709;
432         input_ycbcr_format.full_range = false;
433
434         if (override_bounce) {
435                 input = new NonBouncingYCbCrInput(inout_format, input_ycbcr_format, WIDTH, HEIGHT, YCBCR_INPUT_SPLIT_Y_AND_CBCR);
436         } else {
437                 input = new YCbCrInput(inout_format, input_ycbcr_format, WIDTH, HEIGHT, YCBCR_INPUT_SPLIT_Y_AND_CBCR);
438         }
439         chain->add_input(input);
440 }
441
442 void LiveInputWrapper::connect_signal(int signal_num)
443 {
444         theme->connect_signal(input, signal_num);
445 }
446
447 Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_cards)
448         : resource_pool(resource_pool), num_cards(num_cards)
449 {
450         L = luaL_newstate();
451         luaL_openlibs(L);
452
453         register_class("EffectChain", EffectChain_funcs); 
454         register_class("LiveInputWrapper", LiveInputWrapper_funcs); 
455         register_class("ImageInput", ImageInput_funcs);
456         register_class("WhiteBalanceEffect", WhiteBalanceEffect_funcs);
457         register_class("ResampleEffect", ResampleEffect_funcs);
458         register_class("PaddingEffect", PaddingEffect_funcs);
459         register_class("IntegralPaddingEffect", IntegralPaddingEffect_funcs);
460         register_class("OverlayEffect", OverlayEffect_funcs);
461         register_class("ResizeEffect", ResizeEffect_funcs);
462         register_class("MixEffect", MixEffect_funcs);
463
464         // Run script.
465         lua_settop(L, 0);
466         if (luaL_dofile(L, filename)) {
467                 fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
468                 lua_pop(L, 1);
469                 exit(1);
470         }
471         assert(lua_gettop(L) == 0);
472
473         // Ask it for the number of channels.
474         lua_getglobal(L, "num_channels");
475
476         if (lua_pcall(L, 0, 1, 0) != 0) {
477                 fprintf(stderr, "error running function `num_channels': %s\n", lua_tostring(L, -1));
478                 exit(1);
479         }
480
481         num_channels = luaL_checknumber(L, 1);
482         lua_pop(L, 1);
483         assert(lua_gettop(L) == 0);
484 }
485
486 void Theme::register_class(const char *class_name, const luaL_Reg *funcs)
487 {
488         assert(lua_gettop(L) == 0);
489         luaL_newmetatable(L, class_name);
490         lua_pushlightuserdata(L, this);
491         luaL_setfuncs(L, funcs, 1);
492         lua_pushvalue(L, -1);
493         lua_setfield(L, -2, "__index");
494         lua_setglobal(L, class_name);
495         assert(lua_gettop(L) == 0);
496 }
497
498 pair<EffectChain *, function<void()>>
499 Theme::get_chain(unsigned num, float t, unsigned width, unsigned height)
500 {
501         unique_lock<mutex> lock(m);
502         assert(lua_gettop(L) == 0);
503         lua_getglobal(L, "get_chain");  /* function to be called */
504         lua_pushnumber(L, num);
505         lua_pushnumber(L, t);
506         lua_pushnumber(L, width);
507         lua_pushnumber(L, height);
508
509         if (lua_pcall(L, 4, 2, 0) != 0) {
510                 fprintf(stderr, "error running function `get_chain': %s\n", lua_tostring(L, -1));
511                 exit(1);
512         }
513
514         EffectChain *chain = (EffectChain *)luaL_checkudata(L, -2, "EffectChain");
515         if (!lua_isfunction(L, -1)) {
516                 fprintf(stderr, "Argument #-1 should be a function\n");
517                 exit(1);
518         }
519         lua_pushvalue(L, -1);
520         shared_ptr<LuaRefWithDeleter> funcref(new LuaRefWithDeleter(&m, L, luaL_ref(L, LUA_REGISTRYINDEX)));
521         lua_pop(L, 2);
522         assert(lua_gettop(L) == 0);
523         return make_pair(chain, [this, funcref]{
524                 unique_lock<mutex> lock(m);
525
526                 // Set up state, including connecting signals.
527                 lua_rawgeti(L, LUA_REGISTRYINDEX, funcref->get());
528                 if (lua_pcall(L, 0, 0, 0) != 0) {
529                         fprintf(stderr, "error running chain setup callback: %s\n", lua_tostring(L, -1));
530                         exit(1);
531                 }
532                 assert(lua_gettop(L) == 0);
533         });
534 }
535
536 std::string Theme::get_channel_name(unsigned channel)
537 {
538         unique_lock<mutex> lock(m);
539         lua_getglobal(L, "channel_name");
540         lua_pushnumber(L, channel);
541         if (lua_pcall(L, 1, 1, 0) != 0) {
542                 fprintf(stderr, "error running function `channel_nam': %s\n", lua_tostring(L, -1));
543                 exit(1);
544         }
545
546         std::string ret = lua_tostring(L, -1);
547         lua_pop(L, 1);
548         assert(lua_gettop(L) == 0);
549         return ret;
550 }
551
552 bool Theme::get_supports_set_wb(unsigned channel)
553 {
554         unique_lock<mutex> lock(m);
555         lua_getglobal(L, "supports_set_wb");
556         lua_pushnumber(L, channel);
557         if (lua_pcall(L, 1, 1, 0) != 0) {
558                 fprintf(stderr, "error running function `supports_set_wb': %s\n", lua_tostring(L, -1));
559                 exit(1);
560         }
561
562         bool ret = checkbool(L, -1);
563         lua_pop(L, 1);
564         assert(lua_gettop(L) == 0);
565         return ret;
566 }
567
568 void Theme::set_wb(unsigned channel, double r, double g, double b)
569 {
570         unique_lock<mutex> lock(m);
571         lua_getglobal(L, "set_wb");
572         lua_pushnumber(L, channel);
573         lua_pushnumber(L, r);
574         lua_pushnumber(L, g);
575         lua_pushnumber(L, b);
576         if (lua_pcall(L, 4, 0, 0) != 0) {
577                 fprintf(stderr, "error running function `set_wb': %s\n", lua_tostring(L, -1));
578                 exit(1);
579         }
580
581         assert(lua_gettop(L) == 0);
582 }
583
584 std::vector<std::string> Theme::get_transition_names(float t)
585 {
586         unique_lock<mutex> lock(m);
587         lua_getglobal(L, "get_transitions");
588         lua_pushnumber(L, t);
589         if (lua_pcall(L, 1, 1, 0) != 0) {
590                 fprintf(stderr, "error running function `get_transitions': %s\n", lua_tostring(L, -1));
591                 exit(1);
592         }
593
594         std::vector<std::string> ret;
595         lua_pushnil(L);
596         while (lua_next(L, -2) != 0) {
597                 ret.push_back(lua_tostring(L, -1));
598                 lua_pop(L, 1);
599         }
600         lua_pop(L, 1);
601         assert(lua_gettop(L) == 0);
602         return ret;
603 }       
604
605 void Theme::connect_signal(YCbCrInput *input, int signal_num)
606 {
607         if (signal_num >= int(num_cards)) {
608                 if (signals_warned_about.insert(signal_num).second) {
609                         fprintf(stderr, "WARNING: Theme asked for input %d, but we only have %u card(s).\n", signal_num, num_cards);
610                         fprintf(stderr, "Mapping to card %d instead.\n", signal_num % num_cards);
611                 }
612                 signal_num %= num_cards;
613         }
614         input->set_texture_num(0, input_textures[signal_num].tex_y);
615         input->set_texture_num(1, input_textures[signal_num].tex_cbcr);
616 }
617
618 void Theme::transition_clicked(int transition_num, float t)
619 {
620         unique_lock<mutex> lock(m);
621         lua_getglobal(L, "transition_clicked");
622         lua_pushnumber(L, transition_num);
623         lua_pushnumber(L, t);
624
625         if (lua_pcall(L, 2, 0, 0) != 0) {
626                 fprintf(stderr, "error running function `transition_clicked': %s\n", lua_tostring(L, -1));
627                 exit(1);
628         }
629         assert(lua_gettop(L) == 0);
630 }
631
632 void Theme::channel_clicked(int preview_num)
633 {
634         unique_lock<mutex> lock(m);
635         lua_getglobal(L, "channel_clicked");
636         lua_pushnumber(L, preview_num);
637
638         if (lua_pcall(L, 1, 0, 0) != 0) {
639                 fprintf(stderr, "error running function `channel_clicked': %s\n", lua_tostring(L, -1));
640                 exit(1);
641         }
642         assert(lua_gettop(L) == 0);
643 }