gstreamer test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Prelude hiding (init)
import Control.Monad
import Media.Streaming.GStreamer
import System.Glib.Properties
import System.Glib.MainLoop

connect a b = do
	res <- elementLink a b
	unless res $ do
		na <- objectGetPropertyString "name" a
		nb <- objectGetPropertyString "name" b
		error ("cannot connect " ++ na ++ " to " ++ nb)

player = do
	init

	bin <- pipelineNew "video-stream"
	Just src      <- elementFactoryMake "videotestsrc"     (Just "videotestsrc")
	Just mdspproc <- elementFactoryMake "videoscale"       (Just "videoscale"  )
	Just color1   <- elementFactoryMake "ffmpegcolorspace" (Just "color1"      )
	Just color2   <- elementFactoryMake "ffmpegcolorspace" (Just "color2"      )
	Just sink     <- elementFactoryMake "ximagesink"       (Just "sink1"       )

	putStrLn "made elems"

	binAdd (castToBin bin) src
	binAdd (castToBin bin) mdspproc
	binAdd (castToBin bin) color1
	binAdd (castToBin bin) sink
	binAdd (castToBin bin) color2

	connect src color1
	connect color1 mdspproc
	connect mdspproc color2
	connect color2 sink

	elementSetState bin StatePlaying >>= print
	return bin

main = do
	player
	loop <- mainLoopNew Nothing False
	mainLoopRun loop