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

A 'GI.Gst.Structs.Sample.Sample' is a small object containing data, a type, timing and
extra arbitrary information.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Gst.Structs.Sample
    (

-- * Exported types
    Sample(..)                              ,
    noSample                                ,


 -- * Methods
-- ** getBuffer #method:getBuffer#

#if ENABLE_OVERLOADING
    SampleGetBufferMethodInfo               ,
#endif
    sampleGetBuffer                         ,


-- ** getBufferList #method:getBufferList#

#if ENABLE_OVERLOADING
    SampleGetBufferListMethodInfo           ,
#endif
    sampleGetBufferList                     ,


-- ** getCaps #method:getCaps#

#if ENABLE_OVERLOADING
    SampleGetCapsMethodInfo                 ,
#endif
    sampleGetCaps                           ,


-- ** getInfo #method:getInfo#

#if ENABLE_OVERLOADING
    SampleGetInfoMethodInfo                 ,
#endif
    sampleGetInfo                           ,


-- ** getSegment #method:getSegment#

#if ENABLE_OVERLOADING
    SampleGetSegmentMethodInfo              ,
#endif
    sampleGetSegment                        ,


-- ** new #method:new#

    sampleNew                               ,


-- ** setBufferList #method:setBufferList#

#if ENABLE_OVERLOADING
    SampleSetBufferListMethodInfo           ,
#endif
    sampleSetBufferList                     ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import {-# SOURCE #-} qualified GI.Gst.Structs.Buffer as Gst.Buffer
import {-# SOURCE #-} qualified GI.Gst.Structs.BufferList as Gst.BufferList
import {-# SOURCE #-} qualified GI.Gst.Structs.Caps as Gst.Caps
import {-# SOURCE #-} qualified GI.Gst.Structs.Segment as Gst.Segment
import {-# SOURCE #-} qualified GI.Gst.Structs.Structure as Gst.Structure

-- | Memory-managed wrapper type.
newtype Sample = Sample (ManagedPtr Sample)
foreign import ccall "gst_sample_get_type" c_gst_sample_get_type ::
    IO GType

instance BoxedObject Sample where
    boxedType _ = c_gst_sample_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `Sample`.
noSample :: Maybe Sample
noSample = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList Sample
type instance O.AttributeList Sample = SampleAttributeList
type SampleAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method Sample::new
-- method type : Constructor
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gst", name = "Buffer"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GstBuffer, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "caps", argType = TInterface (Name {namespace = "Gst", name = "Caps"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GstCaps, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "segment", argType = TInterface (Name {namespace = "Gst", name = "Segment"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GstSegment, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "info", argType = TInterface (Name {namespace = "Gst", name = "Structure"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GstStructure, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Sample"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_sample_new" gst_sample_new ::
    Ptr Gst.Buffer.Buffer ->                -- buffer : TInterface (Name {namespace = "Gst", name = "Buffer"})
    Ptr Gst.Caps.Caps ->                    -- caps : TInterface (Name {namespace = "Gst", name = "Caps"})
    Ptr Gst.Segment.Segment ->              -- segment : TInterface (Name {namespace = "Gst", name = "Segment"})
    Ptr Gst.Structure.Structure ->          -- info : TInterface (Name {namespace = "Gst", name = "Structure"})
    IO (Ptr Sample)

{- |
Create a new 'GI.Gst.Structs.Sample.Sample' with the provided details.

Free-function: gst_sample_unref
-}
sampleNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Maybe (Gst.Buffer.Buffer)
    {- ^ /@buffer@/: a 'GI.Gst.Structs.Buffer.Buffer', or 'Nothing' -}
    -> Maybe (Gst.Caps.Caps)
    {- ^ /@caps@/: a 'GI.Gst.Structs.Caps.Caps', or 'Nothing' -}
    -> Maybe (Gst.Segment.Segment)
    {- ^ /@segment@/: a 'GI.Gst.Structs.Segment.Segment', or 'Nothing' -}
    -> Maybe (Gst.Structure.Structure)
    {- ^ /@info@/: a 'GI.Gst.Structs.Structure.Structure', or 'Nothing' -}
    -> m Sample
    {- ^ __Returns:__ the new 'GI.Gst.Structs.Sample.Sample'. @/gst_sample_unref()/@
    after usage. -}
sampleNew buffer caps segment info = liftIO $ do
    maybeBuffer <- case buffer of
        Nothing -> return nullPtr
        Just jBuffer -> do
            jBuffer' <- unsafeManagedPtrGetPtr jBuffer
            return jBuffer'
    maybeCaps <- case caps of
        Nothing -> return nullPtr
        Just jCaps -> do
            jCaps' <- unsafeManagedPtrGetPtr jCaps
            return jCaps'
    maybeSegment <- case segment of
        Nothing -> return nullPtr
        Just jSegment -> do
            jSegment' <- unsafeManagedPtrGetPtr jSegment
            return jSegment'
    maybeInfo <- case info of
        Nothing -> return nullPtr
        Just jInfo -> do
            jInfo' <- B.ManagedPtr.disownBoxed jInfo
            return jInfo'
    result <- gst_sample_new maybeBuffer maybeCaps maybeSegment maybeInfo
    checkUnexpectedReturnNULL "sampleNew" result
    result' <- (wrapBoxed Sample) result
    whenJust buffer touchManagedPtr
    whenJust caps touchManagedPtr
    whenJust segment touchManagedPtr
    whenJust info touchManagedPtr
    return result'

#if ENABLE_OVERLOADING
#endif

-- method Sample::get_buffer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sample", argType = TInterface (Name {namespace = "Gst", name = "Sample"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstSample", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Buffer"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_sample_get_buffer" gst_sample_get_buffer ::
    Ptr Sample ->                           -- sample : TInterface (Name {namespace = "Gst", name = "Sample"})
    IO (Ptr Gst.Buffer.Buffer)

{- |
Get the buffer associated with /@sample@/
-}
sampleGetBuffer ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Sample
    {- ^ /@sample@/: a 'GI.Gst.Structs.Sample.Sample' -}
    -> m (Maybe Gst.Buffer.Buffer)
    {- ^ __Returns:__ the buffer of /@sample@/ or 'Nothing'
 when there is no buffer. The buffer remains valid as long as
 /@sample@/ is valid.  If you need to hold on to it for longer than
 that, take a ref to the buffer with @/gst_buffer_ref()/@. -}
sampleGetBuffer sample = liftIO $ do
    sample' <- unsafeManagedPtrGetPtr sample
    result <- gst_sample_get_buffer sample'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed Gst.Buffer.Buffer) result'
        return result''
    touchManagedPtr sample
    return maybeResult

#if ENABLE_OVERLOADING
data SampleGetBufferMethodInfo
instance (signature ~ (m (Maybe Gst.Buffer.Buffer)), MonadIO m) => O.MethodInfo SampleGetBufferMethodInfo Sample signature where
    overloadedMethod _ = sampleGetBuffer

#endif

-- method Sample::get_buffer_list
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sample", argType = TInterface (Name {namespace = "Gst", name = "Sample"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstSample", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "BufferList"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_sample_get_buffer_list" gst_sample_get_buffer_list ::
    Ptr Sample ->                           -- sample : TInterface (Name {namespace = "Gst", name = "Sample"})
    IO (Ptr Gst.BufferList.BufferList)

{- |
Get the buffer list associated with /@sample@/

/Since: 1.6/
-}
sampleGetBufferList ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Sample
    {- ^ /@sample@/: a 'GI.Gst.Structs.Sample.Sample' -}
    -> m (Maybe Gst.BufferList.BufferList)
    {- ^ __Returns:__ the buffer list of /@sample@/ or 'Nothing'
 when there is no buffer list. The buffer list remains valid as long as
 /@sample@/ is valid.  If you need to hold on to it for longer than
 that, take a ref to the buffer list with gst_mini_object_ref (). -}
sampleGetBufferList sample = liftIO $ do
    sample' <- unsafeManagedPtrGetPtr sample
    result <- gst_sample_get_buffer_list sample'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed Gst.BufferList.BufferList) result'
        return result''
    touchManagedPtr sample
    return maybeResult

#if ENABLE_OVERLOADING
data SampleGetBufferListMethodInfo
instance (signature ~ (m (Maybe Gst.BufferList.BufferList)), MonadIO m) => O.MethodInfo SampleGetBufferListMethodInfo Sample signature where
    overloadedMethod _ = sampleGetBufferList

#endif

-- method Sample::get_caps
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sample", argType = TInterface (Name {namespace = "Gst", name = "Sample"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstSample", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Caps"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_sample_get_caps" gst_sample_get_caps ::
    Ptr Sample ->                           -- sample : TInterface (Name {namespace = "Gst", name = "Sample"})
    IO (Ptr Gst.Caps.Caps)

{- |
Get the caps associated with /@sample@/
-}
sampleGetCaps ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Sample
    {- ^ /@sample@/: a 'GI.Gst.Structs.Sample.Sample' -}
    -> m (Maybe Gst.Caps.Caps)
    {- ^ __Returns:__ the caps of /@sample@/ or 'Nothing'
 when there is no caps. The caps remain valid as long as /@sample@/ is
 valid.  If you need to hold on to the caps for longer than that,
 take a ref to the caps with @/gst_caps_ref()/@. -}
sampleGetCaps sample = liftIO $ do
    sample' <- unsafeManagedPtrGetPtr sample
    result <- gst_sample_get_caps sample'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed Gst.Caps.Caps) result'
        return result''
    touchManagedPtr sample
    return maybeResult

#if ENABLE_OVERLOADING
data SampleGetCapsMethodInfo
instance (signature ~ (m (Maybe Gst.Caps.Caps)), MonadIO m) => O.MethodInfo SampleGetCapsMethodInfo Sample signature where
    overloadedMethod _ = sampleGetCaps

#endif

-- method Sample::get_info
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sample", argType = TInterface (Name {namespace = "Gst", name = "Sample"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstSample", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Structure"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_sample_get_info" gst_sample_get_info ::
    Ptr Sample ->                           -- sample : TInterface (Name {namespace = "Gst", name = "Sample"})
    IO (Ptr Gst.Structure.Structure)

{- |
Get extra information associated with /@sample@/.
-}
sampleGetInfo ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Sample
    {- ^ /@sample@/: a 'GI.Gst.Structs.Sample.Sample' -}
    -> m (Maybe Gst.Structure.Structure)
    {- ^ __Returns:__ the extra info of /@sample@/.
 The info remains valid as long as /@sample@/ is valid. -}
sampleGetInfo sample = liftIO $ do
    sample' <- unsafeManagedPtrGetPtr sample
    result <- gst_sample_get_info sample'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed Gst.Structure.Structure) result'
        return result''
    touchManagedPtr sample
    return maybeResult

#if ENABLE_OVERLOADING
data SampleGetInfoMethodInfo
instance (signature ~ (m (Maybe Gst.Structure.Structure)), MonadIO m) => O.MethodInfo SampleGetInfoMethodInfo Sample signature where
    overloadedMethod _ = sampleGetInfo

#endif

-- method Sample::get_segment
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sample", argType = TInterface (Name {namespace = "Gst", name = "Sample"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstSample", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Segment"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_sample_get_segment" gst_sample_get_segment ::
    Ptr Sample ->                           -- sample : TInterface (Name {namespace = "Gst", name = "Sample"})
    IO (Ptr Gst.Segment.Segment)

{- |
Get the segment associated with /@sample@/
-}
sampleGetSegment ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Sample
    {- ^ /@sample@/: a 'GI.Gst.Structs.Sample.Sample' -}
    -> m Gst.Segment.Segment
    {- ^ __Returns:__ the segment of /@sample@/.
 The segment remains valid as long as /@sample@/ is valid. -}
sampleGetSegment sample = liftIO $ do
    sample' <- unsafeManagedPtrGetPtr sample
    result <- gst_sample_get_segment sample'
    checkUnexpectedReturnNULL "sampleGetSegment" result
    result' <- (newBoxed Gst.Segment.Segment) result
    touchManagedPtr sample
    return result'

#if ENABLE_OVERLOADING
data SampleGetSegmentMethodInfo
instance (signature ~ (m Gst.Segment.Segment), MonadIO m) => O.MethodInfo SampleGetSegmentMethodInfo Sample signature where
    overloadedMethod _ = sampleGetSegment

#endif

-- method Sample::set_buffer_list
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sample", argType = TInterface (Name {namespace = "Gst", name = "Sample"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstSample", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "buffer_list", argType = TInterface (Name {namespace = "Gst", name = "BufferList"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBufferList", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_sample_set_buffer_list" gst_sample_set_buffer_list ::
    Ptr Sample ->                           -- sample : TInterface (Name {namespace = "Gst", name = "Sample"})
    Ptr Gst.BufferList.BufferList ->        -- buffer_list : TInterface (Name {namespace = "Gst", name = "BufferList"})
    IO ()

{- |
Set the buffer list associated with /@sample@/

/Since: 1.6/
-}
sampleSetBufferList ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Sample
    {- ^ /@sample@/: a 'GI.Gst.Structs.Sample.Sample' -}
    -> Gst.BufferList.BufferList
    {- ^ /@bufferList@/: a 'GI.Gst.Structs.BufferList.BufferList' -}
    -> m ()
sampleSetBufferList sample bufferList = liftIO $ do
    sample' <- unsafeManagedPtrGetPtr sample
    bufferList' <- unsafeManagedPtrGetPtr bufferList
    gst_sample_set_buffer_list sample' bufferList'
    touchManagedPtr sample
    touchManagedPtr bufferList
    return ()

#if ENABLE_OVERLOADING
data SampleSetBufferListMethodInfo
instance (signature ~ (Gst.BufferList.BufferList -> m ()), MonadIO m) => O.MethodInfo SampleSetBufferListMethodInfo Sample signature where
    overloadedMethod _ = sampleSetBufferList

#endif

#if ENABLE_OVERLOADING
type family ResolveSampleMethod (t :: Symbol) (o :: *) :: * where
    ResolveSampleMethod "getBuffer" o = SampleGetBufferMethodInfo
    ResolveSampleMethod "getBufferList" o = SampleGetBufferListMethodInfo
    ResolveSampleMethod "getCaps" o = SampleGetCapsMethodInfo
    ResolveSampleMethod "getInfo" o = SampleGetInfoMethodInfo
    ResolveSampleMethod "getSegment" o = SampleGetSegmentMethodInfo
    ResolveSampleMethod "setBufferList" o = SampleSetBufferListMethodInfo
    ResolveSampleMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveSampleMethod t Sample, O.MethodInfo info Sample p) => O.IsLabelProxy t (Sample -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveSampleMethod t Sample, O.MethodInfo info Sample p) => O.IsLabel t (Sample -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif

#endif