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
44
45
46
47
48
49
50
51
52
53
54
55
56
import Prelude hiding (init)

import Media.Streaming.GStreamer

import System.Posix.Unistd
import Control.Applicative

import System.Glib as Glib
import System.Glib.Properties as Glib
import System.Glib.MainLoop as Glib
import System.Glib.Signals as Glib



connect a b = do res <- a `elementLink` b
		 case res of
			True  -> return b
			False -> do str <- (\na nb -> "cannot connect " ++ na ++ " to " ++ nb) <$> objectGetPropertyString "name" a <*> objectGetPropertyString "name" b
				    error str

player =do 
	   init
	   bin	         <- pipelineNew "video-stream"
  	   Just src  	 <- elementFactoryMake  "videotestsrc"    	(Just "videotestsrc")
	   Just mdspproc <- elementFactoryMake  "mdspproc" 		(Just "mdspproc")
	   Just color1   <- elementFactoryMake  "ffmpegcolorspace" 	(Just "color1")
	   Just color2   <- elementFactoryMake  "ffmpegcolorspace" 	(Just "color2")
	   Just color3   <- elementFactoryMake  "ffmpegcolorspace" 	(Just "color3")

	   Just mix <- elementFactoryMake "videomixer" Nothing
	   Just tee <- elementFactoryMake "tee" (Just "tee")

	   Just sink <- elementFactoryMake "ximagesink" (Just "sink")
           putStrLn "made elems"

	   mapM_ (binAdd (castToBin bin)) [src, mdspproc, color1, sink, color2, color3, mix, tee]


	   src      `connect` tee
	   tee	    `connect` mdspproc
	   mdspproc `connect` color1
	   color1   `connect` mix
	   mix      `connect` color3
	   color3   `connect` sink

	   tee	    `connect` color2
	   color2   `connect` mix


	   elementSetState bin StatePlaying >>= print
	   return bin


main = do loop <- Glib.mainLoopNew Nothing False
	  bin <- player
	  Glib.mainLoopRun loop
16:18: Warning: Use if
Found:
case res of
True -> return b
False -> do str <- (\ na nb ->
"cannot connect " ++ na ++ " to " ++ nb)
<$> objectGetPropertyString "name" a
<*> objectGetPropertyString "name" b
error str
Why not:
if res then return b else
(do str <- (\ na nb -> "cannot connect " ++ na ++ " to " ++ nb) <$>
objectGetPropertyString "name" a
<*> objectGetPropertyString "name" b
error str)