packages feed

gi-gstvideo-0.1.6.13: GI/GstVideo/Structs/VideoMeta.hs


{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

Extra buffer metadata describing image properties
-}

module GI.GstVideo.Structs.VideoMeta
    ( 

-- * Exported types
    VideoMeta(..)                           ,
    newZeroVideoMeta                        ,
    noVideoMeta                             ,


 -- * Methods
-- ** videoMetaGetInfo
    videoMetaGetInfo                        ,


-- ** videoMetaMap
    VideoMetaMapMethodInfo                  ,
    videoMetaMap                            ,


-- ** videoMetaUnmap
    VideoMetaUnmapMethodInfo                ,
    videoMetaUnmap                          ,




 -- * Properties
-- ** Buffer
    videoMetaReadBuffer                     ,


-- ** Flags
    videoMetaReadFlags                      ,


-- ** Format
    videoMetaReadFormat                     ,


-- ** Height
    videoMetaReadHeight                     ,


-- ** Id
    videoMetaReadId                         ,


-- ** Meta
    videoMetaReadMeta                       ,


-- ** NPlanes
    videoMetaReadNPlanes                    ,


-- ** Width
    videoMetaReadWidth                      ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.GstVideo.Types
import GI.GstVideo.Callbacks
import qualified GI.Gst as Gst

newtype VideoMeta = VideoMeta (ForeignPtr VideoMeta)
-- | Construct a `VideoMeta` struct initialized to zero.
newZeroVideoMeta :: MonadIO m => m VideoMeta
newZeroVideoMeta = liftIO $ callocBytes 112 >>= wrapPtr VideoMeta

noVideoMeta :: Maybe VideoMeta
noVideoMeta = Nothing

videoMetaReadMeta :: VideoMeta -> IO Gst.Meta
videoMetaReadMeta s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO (Ptr Gst.Meta)
    val' <- (newPtr 16 Gst.Meta) val
    return val'

videoMetaReadBuffer :: VideoMeta -> IO Gst.Buffer
videoMetaReadBuffer s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO (Ptr Gst.Buffer)
    val' <- (newBoxed Gst.Buffer) val
    return val'

videoMetaReadFlags :: VideoMeta -> IO [VideoFrameFlags]
videoMetaReadFlags s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO CUInt
    let val' = wordToGFlags val
    return val'

videoMetaReadFormat :: VideoMeta -> IO VideoFormat
videoMetaReadFormat s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 28) :: IO CUInt
    let val' = (toEnum . fromIntegral) val
    return val'

videoMetaReadId :: VideoMeta -> IO Int32
videoMetaReadId s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 32) :: IO Int32
    return val

videoMetaReadWidth :: VideoMeta -> IO Word32
videoMetaReadWidth s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 36) :: IO Word32
    return val

videoMetaReadHeight :: VideoMeta -> IO Word32
videoMetaReadHeight s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 40) :: IO Word32
    return val

videoMetaReadNPlanes :: VideoMeta -> IO Word32
videoMetaReadNPlanes s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 44) :: IO Word32
    return val

-- XXX Skipped getter for "VideoMeta:offset" :: Not implemented: "Don't know how to unpack C array of type TCArray False 4 (-1) (TBasicType TUInt64)"

-- XXX Skipped getter for "VideoMeta:stride" :: Not implemented: "Don't know how to unpack C array of type TCArray False 4 (-1) (TBasicType TInt32)"

-- XXX Skipped getter for "VideoMeta:map" :: Not implemented: "Wrapping foreign callbacks is not supported yet"

-- XXX Skipped getter for "VideoMeta:unmap" :: Not implemented: "Wrapping foreign callbacks is not supported yet"

-- method VideoMeta::map
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "GstVideo" "VideoMeta", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "plane", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "info", argType = TInterface "Gst" "MapInfo", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stride", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TInterface "Gst" "MapFlags", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "gst_video_meta_map" gst_video_meta_map :: 
    Ptr VideoMeta ->                        -- _obj : TInterface "GstVideo" "VideoMeta"
    Word32 ->                               -- plane : TBasicType TUInt32
    Ptr Gst.MapInfo ->                      -- info : TInterface "Gst" "MapInfo"
    Ptr () ->                               -- data : TBasicType TVoid
    Int32 ->                                -- stride : TBasicType TInt32
    CUInt ->                                -- flags : TInterface "Gst" "MapFlags"
    IO CInt


videoMetaMap ::
    (MonadIO m) =>
    VideoMeta                               -- _obj
    -> Word32                               -- plane
    -> Gst.MapInfo                          -- info
    -> Ptr ()                               -- data_
    -> Int32                                -- stride
    -> [Gst.MapFlags]                       -- flags
    -> m Bool                               -- result
videoMetaMap _obj plane info data_ stride flags = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let info' = unsafeManagedPtrGetPtr info
    let flags' = gflagsToWord flags
    result <- gst_video_meta_map _obj' plane info' data_ stride flags'
    let result' = (/= 0) result
    touchManagedPtr _obj
    touchManagedPtr info
    return result'

data VideoMetaMapMethodInfo
instance (signature ~ (Word32 -> Gst.MapInfo -> Ptr () -> Int32 -> [Gst.MapFlags] -> m Bool), MonadIO m) => MethodInfo VideoMetaMapMethodInfo VideoMeta signature where
    overloadedMethod _ = videoMetaMap

-- method VideoMeta::unmap
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "GstVideo" "VideoMeta", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "plane", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "info", argType = TInterface "Gst" "MapInfo", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "gst_video_meta_unmap" gst_video_meta_unmap :: 
    Ptr VideoMeta ->                        -- _obj : TInterface "GstVideo" "VideoMeta"
    Word32 ->                               -- plane : TBasicType TUInt32
    Ptr Gst.MapInfo ->                      -- info : TInterface "Gst" "MapInfo"
    IO CInt


videoMetaUnmap ::
    (MonadIO m) =>
    VideoMeta                               -- _obj
    -> Word32                               -- plane
    -> Gst.MapInfo                          -- info
    -> m Bool                               -- result
videoMetaUnmap _obj plane info = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let info' = unsafeManagedPtrGetPtr info
    result <- gst_video_meta_unmap _obj' plane info'
    let result' = (/= 0) result
    touchManagedPtr _obj
    touchManagedPtr info
    return result'

data VideoMetaUnmapMethodInfo
instance (signature ~ (Word32 -> Gst.MapInfo -> m Bool), MonadIO m) => MethodInfo VideoMetaUnmapMethodInfo VideoMeta signature where
    overloadedMethod _ = videoMetaUnmap

-- method VideoMeta::get_info
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : TInterface "Gst" "MetaInfo"
-- throws : False
-- Skip return : False

foreign import ccall "gst_video_meta_get_info" gst_video_meta_get_info :: 
    IO (Ptr Gst.MetaInfo)


videoMetaGetInfo ::
    (MonadIO m) =>
    m Gst.MetaInfo                          -- result
videoMetaGetInfo  = liftIO $ do
    result <- gst_video_meta_get_info
    checkUnexpectedReturnNULL "gst_video_meta_get_info" result
    result' <- (newPtr 80 Gst.MetaInfo) result
    return result'

type family ResolveVideoMetaMethod (t :: Symbol) (o :: *) :: * where
    ResolveVideoMetaMethod "map" o = VideoMetaMapMethodInfo
    ResolveVideoMetaMethod "unmap" o = VideoMetaUnmapMethodInfo
    ResolveVideoMetaMethod l o = MethodResolutionFailed l o

instance (info ~ ResolveVideoMetaMethod t VideoMeta, MethodInfo info VideoMeta p) => IsLabelProxy t (VideoMeta -> p) where
    fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveVideoMetaMethod t VideoMeta, MethodInfo info VideoMeta p) => IsLabel t (VideoMeta -> p) where
    fromLabel _ = overloadedMethod (MethodProxy :: MethodProxy info)
#endif