| 1 | import Data.Ratio ( Ratio, (%) ) |
|---|
| 2 | import Data.Bits ( (.|.), shiftL ) |
|---|
| 3 | import Data.Char ( ord ) |
|---|
| 4 | import Data.Word ( Word32 ) |
|---|
| 5 | import qualified Media.Streaming.GStreamer as Gst |
|---|
| 6 | |
|---|
| 7 | type FourCC = Word32 |
|---|
| 8 | type Fraction = Ratio Int |
|---|
| 9 | |
|---|
| 10 | makeFourCC :: (Char, Char, Char, Char) -> FourCC |
|---|
| 11 | makeFourCC (a,b,c,d) = a' .|. b' .|. c' .|. d' |
|---|
| 12 | where |
|---|
| 13 | a', b', c', d' :: Word32 |
|---|
| 14 | a' = ord' a |
|---|
| 15 | b' = ord' b `shiftL` 8 |
|---|
| 16 | c' = ord' c `shiftL` 16 |
|---|
| 17 | d' = ord' d `shiftL` 24 |
|---|
| 18 | |
|---|
| 19 | ord' = fromIntegral . ord |
|---|
| 20 | |
|---|
| 21 | filename :: FilePath |
|---|
| 22 | filename = "uvc_640x480.yuy2" |
|---|
| 23 | |
|---|
| 24 | buildStructure :: Gst.Structure |
|---|
| 25 | buildStructure = fst . Gst.structureCreate "video/x-raw-rgb" $ do |
|---|
| 26 | Gst.structureSetFourCCM "format" (makeFourCC ('Y', 'U', 'Y', '2')) |
|---|
| 27 | Gst.structureSetFractionM "framerate" (10 % 1) |
|---|
| 28 | Gst.structureSetIntM "width" 640 |
|---|
| 29 | Gst.structureSetIntM "height" 480 |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | buildCaps :: Gst.Caps |
|---|
| 33 | buildCaps = fst . Gst.capsCreate $ Gst.capsAppendStructure buildStructure |
|---|
| 34 | |
|---|
| 35 | main :: IO () |
|---|
| 36 | main = do |
|---|
| 37 | Gst.init |
|---|
| 38 | putStrLn $ Gst.structureToString buildStructure |
|---|
| 39 | putStrLn $ Gst.capsToString buildCaps |
|---|