(bind-func xtm_decode 5000000
(let ((dat:i8* (alloc (* 1200 800 3))))
(lambda (playz:GstElement* sink:GstElement* time rate preroll:i1)
(if (<> (gst_app_sink_is_eos (cast sink GstAppSink*)) 0)
(begin
(printf "Finished Streaming! Try another video!\n")
(gst_element_set_state playz GST_STATE_NULL)
(gst_object_unref (cast playz gpointer))
(set! vplay #f)
void)
(let ((sample (gst_app_sink_pull_sample (cast sink i8*)))
(caps (gst_sample_get_caps sample))
(buffer (gst_sample_get_buffer sample))
(xsize:gsize 0))
(if preroll
(let ((st (gst_caps_get_structure caps 0))
(gv (gst_structure_get_value st "framerate"))
(num (gst_value_get_fraction_numerator gv))
(denom (gst_value_get_fraction_denominator gv)))
(set! vplay #t)
(set! rate (ftoi64 (/ 44100.0 (/ (i32tof num) (i32tof denom)))))
(printf "Play format: %s\n" (gst_caps_to_string caps))))
(set! xsize (gst_buffer_extract buffer 0 dat (* 3 1200 800)))
;; load texture into 11
(if (= xsize (* 3 1200 800))
(set! movietexid (gl_load_tex 1200 800 3 GL_UNSIGNED_BYTE dat movietexid)))
(if (or preroll
(and (> rate 0)
(> xsize 0)))
(callback (+ time (/ rate 2)) xtm_decode playz sink (+ time rate) rate 0)
(begin (set! vplay #f)
(printf "Are we here :(\n")
void)))))))