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

This class is for elements that receive buffers in an undesired size.
While for example raw video contains one image per buffer, the same is not
true for a lot of other formats, especially those that come directly from
a file. So if you have undefined buffer sizes and require a specific size,
this object is for you.

An adapter is created with 'GI.GstBase.Objects.Adapter.adapterNew'. It can be freed again with
'GI.GObject.Objects.Object.objectUnref'.

The theory of operation is like this: All buffers received are put
into the adapter using 'GI.GstBase.Objects.Adapter.adapterPush' and the data is then read back
in chunks of the desired size using 'GI.GstBase.Objects.Adapter.adapterMap'\/'GI.GstBase.Objects.Adapter.adapterUnmap'
and\/or @/gst_adapter_copy()/@. After the data has been processed, it is freed
using 'GI.GstBase.Objects.Adapter.adapterUnmap'.

Other methods such as 'GI.GstBase.Objects.Adapter.adapterTake' and 'GI.GstBase.Objects.Adapter.adapterTakeBuffer'
combine 'GI.GstBase.Objects.Adapter.adapterMap' and 'GI.GstBase.Objects.Adapter.adapterUnmap' in one method and are
potentially more convenient for some use cases.

For example, a sink pad\'s chain function that needs to pass data to a library
in 512-byte chunks could be implemented like this:

=== /C code/
>
>static GstFlowReturn
>sink_pad_chain (GstPad *pad, GstObject *parent, GstBuffer *buffer)
>{
>  MyElement *this;
>  GstAdapter *adapter;
>  GstFlowReturn ret = GST_FLOW_OK;
>
>  this = MY_ELEMENT (parent);
>
>  adapter = this->adapter;
>
>  // put buffer into adapter
>  gst_adapter_push (adapter, buffer);
>
>  // while we can read out 512 bytes, process them
>  while (gst_adapter_available (adapter) >= 512 && ret == GST_FLOW_OK) {
>    const guint8 *data = gst_adapter_map (adapter, 512);
>    // use flowreturn as an error value
>    ret = my_library_foo (data);
>    gst_adapter_unmap (adapter);
>    gst_adapter_flush (adapter, 512);
>  }
>  return ret;
>}


For another example, a simple element inside GStreamer that uses 'GI.GstBase.Objects.Adapter.Adapter'
is the libvisual element.

An element using 'GI.GstBase.Objects.Adapter.Adapter' in its sink pad chain function should ensure that
when the FLUSH_STOP event is received, that any queued data is cleared using
'GI.GstBase.Objects.Adapter.adapterClear'. Data should also be cleared or processed on EOS and
when changing state from 'GI.Gst.Enums.StatePaused' to 'GI.Gst.Enums.StateReady'.

Also check the GST_BUFFER_FLAG_DISCONT flag on the buffer. Some elements might
need to clear the adapter after a discontinuity.

The adapter will keep track of the timestamps of the buffers
that were pushed. The last seen timestamp before the current position
can be queried with 'GI.GstBase.Objects.Adapter.adapterPrevPts'. This function can
optionally return the number of bytes between the start of the buffer that
carried the timestamp and the current adapter position. The distance is
useful when dealing with, for example, raw audio samples because it allows
you to calculate the timestamp of the current adapter position by using the
last seen timestamp and the amount of bytes since.  Additionally, the
'GI.GstBase.Objects.Adapter.adapterPrevPtsAtOffset' can be used to determine the last
seen timestamp at a particular offset in the adapter.

The adapter will also keep track of the offset of the buffers
(@/GST_BUFFER_OFFSET/@) that were pushed. The last seen offset before the
current position can be queried with 'GI.GstBase.Objects.Adapter.adapterPrevOffset'. This function
can optionally return the number of bytes between the start of the buffer
that carried the offset and the current adapter position.

Additionally the adapter also keeps track of the PTS, DTS and buffer offset
at the last discontinuity, which can be retrieved with
'GI.GstBase.Objects.Adapter.adapterPtsAtDiscont', 'GI.GstBase.Objects.Adapter.adapterDtsAtDiscont' and
'GI.GstBase.Objects.Adapter.adapterOffsetAtDiscont'. The number of bytes that were consumed
since then can be queried with 'GI.GstBase.Objects.Adapter.adapterDistanceFromDiscont'.

A last thing to note is that while 'GI.GstBase.Objects.Adapter.Adapter' is pretty optimized,
merging buffers still might be an operation that requires a @/malloc()/@ and
@/memcpy()/@ operation, and these operations are not the fastest. Because of
this, some functions like 'GI.GstBase.Objects.Adapter.adapterAvailableFast' are provided to help
speed up such cases should you want to. To avoid repeated memory allocations,
@/gst_adapter_copy()/@ can be used to copy data into a (statically allocated)
user provided buffer.

'GI.GstBase.Objects.Adapter.Adapter' is not MT safe. All operations on an adapter must be serialized by
the caller. This is not normally a problem, however, as the normal use case
of 'GI.GstBase.Objects.Adapter.Adapter' is inside one pad\'s chain function, in which case access is
serialized via the pad\'s STREAM_LOCK.

Note that 'GI.GstBase.Objects.Adapter.adapterPush' takes ownership of the buffer passed. Use
@/gst_buffer_ref()/@ before pushing it into the adapter if you still want to
access the buffer later. The adapter will never modify the data in the
buffer pushed in it.
-}

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

module GI.GstBase.Objects.Adapter
    (

-- * Exported types
    Adapter(..)                             ,
    IsAdapter                               ,
    toAdapter                               ,
    noAdapter                               ,


 -- * Methods
-- ** available #method:available#

#if ENABLE_OVERLOADING
    AdapterAvailableMethodInfo              ,
#endif
    adapterAvailable                        ,


-- ** availableFast #method:availableFast#

#if ENABLE_OVERLOADING
    AdapterAvailableFastMethodInfo          ,
#endif
    adapterAvailableFast                    ,


-- ** clear #method:clear#

#if ENABLE_OVERLOADING
    AdapterClearMethodInfo                  ,
#endif
    adapterClear                            ,


-- ** copy #method:copy#

#if ENABLE_OVERLOADING
    AdapterCopyMethodInfo                   ,
#endif
    adapterCopy                             ,


-- ** distanceFromDiscont #method:distanceFromDiscont#

#if ENABLE_OVERLOADING
    AdapterDistanceFromDiscontMethodInfo    ,
#endif
    adapterDistanceFromDiscont              ,


-- ** dtsAtDiscont #method:dtsAtDiscont#

#if ENABLE_OVERLOADING
    AdapterDtsAtDiscontMethodInfo           ,
#endif
    adapterDtsAtDiscont                     ,


-- ** flush #method:flush#

#if ENABLE_OVERLOADING
    AdapterFlushMethodInfo                  ,
#endif
    adapterFlush                            ,


-- ** getBuffer #method:getBuffer#

#if ENABLE_OVERLOADING
    AdapterGetBufferMethodInfo              ,
#endif
    adapterGetBuffer                        ,


-- ** getBufferFast #method:getBufferFast#

#if ENABLE_OVERLOADING
    AdapterGetBufferFastMethodInfo          ,
#endif
    adapterGetBufferFast                    ,


-- ** getBufferList #method:getBufferList#

#if ENABLE_OVERLOADING
    AdapterGetBufferListMethodInfo          ,
#endif
    adapterGetBufferList                    ,


-- ** getList #method:getList#

#if ENABLE_OVERLOADING
    AdapterGetListMethodInfo                ,
#endif
    adapterGetList                          ,


-- ** map #method:map#

#if ENABLE_OVERLOADING
    AdapterMapMethodInfo                    ,
#endif
    adapterMap                              ,


-- ** maskedScanUint32 #method:maskedScanUint32#

#if ENABLE_OVERLOADING
    AdapterMaskedScanUint32MethodInfo       ,
#endif
    adapterMaskedScanUint32                 ,


-- ** maskedScanUint32Peek #method:maskedScanUint32Peek#

#if ENABLE_OVERLOADING
    AdapterMaskedScanUint32PeekMethodInfo   ,
#endif
    adapterMaskedScanUint32Peek             ,


-- ** new #method:new#

    adapterNew                              ,


-- ** offsetAtDiscont #method:offsetAtDiscont#

#if ENABLE_OVERLOADING
    AdapterOffsetAtDiscontMethodInfo        ,
#endif
    adapterOffsetAtDiscont                  ,


-- ** prevDts #method:prevDts#

#if ENABLE_OVERLOADING
    AdapterPrevDtsMethodInfo                ,
#endif
    adapterPrevDts                          ,


-- ** prevDtsAtOffset #method:prevDtsAtOffset#

#if ENABLE_OVERLOADING
    AdapterPrevDtsAtOffsetMethodInfo        ,
#endif
    adapterPrevDtsAtOffset                  ,


-- ** prevOffset #method:prevOffset#

#if ENABLE_OVERLOADING
    AdapterPrevOffsetMethodInfo             ,
#endif
    adapterPrevOffset                       ,


-- ** prevPts #method:prevPts#

#if ENABLE_OVERLOADING
    AdapterPrevPtsMethodInfo                ,
#endif
    adapterPrevPts                          ,


-- ** prevPtsAtOffset #method:prevPtsAtOffset#

#if ENABLE_OVERLOADING
    AdapterPrevPtsAtOffsetMethodInfo        ,
#endif
    adapterPrevPtsAtOffset                  ,


-- ** ptsAtDiscont #method:ptsAtDiscont#

#if ENABLE_OVERLOADING
    AdapterPtsAtDiscontMethodInfo           ,
#endif
    adapterPtsAtDiscont                     ,


-- ** push #method:push#

#if ENABLE_OVERLOADING
    AdapterPushMethodInfo                   ,
#endif
    adapterPush                             ,


-- ** take #method:take#

#if ENABLE_OVERLOADING
    AdapterTakeMethodInfo                   ,
#endif
    adapterTake                             ,


-- ** takeBuffer #method:takeBuffer#

#if ENABLE_OVERLOADING
    AdapterTakeBufferMethodInfo             ,
#endif
    adapterTakeBuffer                       ,


-- ** takeBufferFast #method:takeBufferFast#

#if ENABLE_OVERLOADING
    AdapterTakeBufferFastMethodInfo         ,
#endif
    adapterTakeBufferFast                   ,


-- ** takeBufferList #method:takeBufferList#

#if ENABLE_OVERLOADING
    AdapterTakeBufferListMethodInfo         ,
#endif
    adapterTakeBufferList                   ,


-- ** takeList #method:takeList#

#if ENABLE_OVERLOADING
    AdapterTakeListMethodInfo               ,
#endif
    adapterTakeList                         ,


-- ** unmap #method:unmap#

#if ENABLE_OVERLOADING
    AdapterUnmapMethodInfo                  ,
#endif
    adapterUnmap                            ,




    ) 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.GClosure as B.GClosure
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.GI.Base.Properties as B.Properties
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 qualified GHC.OverloadedLabels as OL

import qualified GI.GLib.Structs.Bytes as GLib.Bytes
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gst.Structs.Buffer as Gst.Buffer
import qualified GI.Gst.Structs.BufferList as Gst.BufferList

-- | Memory-managed wrapper type.
newtype Adapter = Adapter (ManagedPtr Adapter)
foreign import ccall "gst_adapter_get_type"
    c_gst_adapter_get_type :: IO GType

instance GObject Adapter where
    gobjectType = c_gst_adapter_get_type


-- | Type class for types which can be safely cast to `Adapter`, for instance with `toAdapter`.
class (GObject o, O.IsDescendantOf Adapter o) => IsAdapter o
instance (GObject o, O.IsDescendantOf Adapter o) => IsAdapter o

instance O.HasParentTypes Adapter
type instance O.ParentTypes Adapter = '[GObject.Object.Object]

-- | Cast to `Adapter`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toAdapter :: (MonadIO m, IsAdapter o) => o -> m Adapter
toAdapter = liftIO . unsafeCastTo Adapter

-- | A convenience alias for `Nothing` :: `Maybe` `Adapter`.
noAdapter :: Maybe Adapter
noAdapter = Nothing

#if ENABLE_OVERLOADING
type family ResolveAdapterMethod (t :: Symbol) (o :: *) :: * where
    ResolveAdapterMethod "available" o = AdapterAvailableMethodInfo
    ResolveAdapterMethod "availableFast" o = AdapterAvailableFastMethodInfo
    ResolveAdapterMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveAdapterMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveAdapterMethod "clear" o = AdapterClearMethodInfo
    ResolveAdapterMethod "copy" o = AdapterCopyMethodInfo
    ResolveAdapterMethod "distanceFromDiscont" o = AdapterDistanceFromDiscontMethodInfo
    ResolveAdapterMethod "dtsAtDiscont" o = AdapterDtsAtDiscontMethodInfo
    ResolveAdapterMethod "flush" o = AdapterFlushMethodInfo
    ResolveAdapterMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveAdapterMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveAdapterMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveAdapterMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveAdapterMethod "map" o = AdapterMapMethodInfo
    ResolveAdapterMethod "maskedScanUint32" o = AdapterMaskedScanUint32MethodInfo
    ResolveAdapterMethod "maskedScanUint32Peek" o = AdapterMaskedScanUint32PeekMethodInfo
    ResolveAdapterMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveAdapterMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveAdapterMethod "offsetAtDiscont" o = AdapterOffsetAtDiscontMethodInfo
    ResolveAdapterMethod "prevDts" o = AdapterPrevDtsMethodInfo
    ResolveAdapterMethod "prevDtsAtOffset" o = AdapterPrevDtsAtOffsetMethodInfo
    ResolveAdapterMethod "prevOffset" o = AdapterPrevOffsetMethodInfo
    ResolveAdapterMethod "prevPts" o = AdapterPrevPtsMethodInfo
    ResolveAdapterMethod "prevPtsAtOffset" o = AdapterPrevPtsAtOffsetMethodInfo
    ResolveAdapterMethod "ptsAtDiscont" o = AdapterPtsAtDiscontMethodInfo
    ResolveAdapterMethod "push" o = AdapterPushMethodInfo
    ResolveAdapterMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveAdapterMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveAdapterMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveAdapterMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveAdapterMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveAdapterMethod "take" o = AdapterTakeMethodInfo
    ResolveAdapterMethod "takeBuffer" o = AdapterTakeBufferMethodInfo
    ResolveAdapterMethod "takeBufferFast" o = AdapterTakeBufferFastMethodInfo
    ResolveAdapterMethod "takeBufferList" o = AdapterTakeBufferListMethodInfo
    ResolveAdapterMethod "takeList" o = AdapterTakeListMethodInfo
    ResolveAdapterMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveAdapterMethod "unmap" o = AdapterUnmapMethodInfo
    ResolveAdapterMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveAdapterMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveAdapterMethod "getBuffer" o = AdapterGetBufferMethodInfo
    ResolveAdapterMethod "getBufferFast" o = AdapterGetBufferFastMethodInfo
    ResolveAdapterMethod "getBufferList" o = AdapterGetBufferListMethodInfo
    ResolveAdapterMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveAdapterMethod "getList" o = AdapterGetListMethodInfo
    ResolveAdapterMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveAdapterMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveAdapterMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveAdapterMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveAdapterMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveAdapterMethod t Adapter, O.MethodInfo info Adapter p) => OL.IsLabel t (Adapter -> 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

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

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Adapter = AdapterSignalList
type AdapterSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Adapter::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GstBase", name = "Adapter"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_new" gst_adapter_new ::
    IO (Ptr Adapter)

{- |
Creates a new 'GI.GstBase.Objects.Adapter.Adapter'. Free with 'GI.GObject.Objects.Object.objectUnref'.
-}
adapterNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Adapter
    {- ^ __Returns:__ a new 'GI.GstBase.Objects.Adapter.Adapter' -}
adapterNew  = liftIO $ do
    result <- gst_adapter_new
    checkUnexpectedReturnNULL "adapterNew" result
    result' <- (wrapObject Adapter) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method Adapter::available
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_available" gst_adapter_available ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO Word64

{- |
Gets the maximum amount of bytes available, that is it returns the maximum
value that can be supplied to 'GI.GstBase.Objects.Adapter.adapterMap' without that function
returning 'Nothing'.
-}
adapterAvailable ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m Word64
    {- ^ __Returns:__ number of bytes available in /@adapter@/ -}
adapterAvailable adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_available adapter'
    touchManagedPtr adapter
    return result

#if ENABLE_OVERLOADING
data AdapterAvailableMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsAdapter a) => O.MethodInfo AdapterAvailableMethodInfo a signature where
    overloadedMethod _ = adapterAvailable

#endif

-- method Adapter::available_fast
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_available_fast" gst_adapter_available_fast ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO Word64

{- |
Gets the maximum number of bytes that are immediately available without
requiring any expensive operations (like copying the data into a
temporary buffer).
-}
adapterAvailableFast ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m Word64
    {- ^ __Returns:__ number of bytes that are available in /@adapter@/ without expensive
operations -}
adapterAvailableFast adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_available_fast adapter'
    touchManagedPtr adapter
    return result

#if ENABLE_OVERLOADING
data AdapterAvailableFastMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsAdapter a) => O.MethodInfo AdapterAvailableFastMethodInfo a signature where
    overloadedMethod _ = adapterAvailableFast

#endif

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

foreign import ccall "gst_adapter_clear" gst_adapter_clear ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO ()

{- |
Removes all buffers from /@adapter@/.
-}
adapterClear ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m ()
adapterClear adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    gst_adapter_clear adapter'
    touchManagedPtr adapter
    return ()

#if ENABLE_OVERLOADING
data AdapterClearMethodInfo
instance (signature ~ (m ()), MonadIO m, IsAdapter a) => O.MethodInfo AdapterClearMethodInfo a signature where
    overloadedMethod _ = adapterClear

#endif

-- method Adapter::copy
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "offset", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the bytes offset in the adapter to start from", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "size", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to copy", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GLib", name = "Bytes"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_copy_bytes" gst_adapter_copy_bytes ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- offset : TBasicType TUInt64
    Word64 ->                               -- size : TBasicType TUInt64
    IO (Ptr GLib.Bytes.Bytes)

{- |
Similar to gst_adapter_copy, but more suitable for language bindings. /@size@/
bytes of data starting at /@offset@/ will be copied out of the buffers contained
in /@adapter@/ and into a new 'GI.GLib.Structs.Bytes.Bytes' structure which is returned. Depending on
the value of the /@size@/ argument an empty 'GI.GLib.Structs.Bytes.Bytes' structure may be returned.

/Since: 1.4/
-}
adapterCopy ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@offset@/: the bytes offset in the adapter to start from -}
    -> Word64
    {- ^ /@size@/: the number of bytes to copy -}
    -> m GLib.Bytes.Bytes
    {- ^ __Returns:__ A new 'GI.GLib.Structs.Bytes.Bytes' structure containing the copied data. -}
adapterCopy adapter offset size = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_copy_bytes adapter' offset size
    checkUnexpectedReturnNULL "adapterCopy" result
    result' <- (wrapBoxed GLib.Bytes.Bytes) result
    touchManagedPtr adapter
    return result'

#if ENABLE_OVERLOADING
data AdapterCopyMethodInfo
instance (signature ~ (Word64 -> Word64 -> m GLib.Bytes.Bytes), MonadIO m, IsAdapter a) => O.MethodInfo AdapterCopyMethodInfo a signature where
    overloadedMethod _ = adapterCopy

#endif

-- method Adapter::distance_from_discont
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_distance_from_discont" gst_adapter_distance_from_discont ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO Word64

{- |
/No description available in the introspection data./
-}
adapterDistanceFromDiscont ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    -> m Word64
adapterDistanceFromDiscont adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_distance_from_discont adapter'
    touchManagedPtr adapter
    return result

#if ENABLE_OVERLOADING
data AdapterDistanceFromDiscontMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsAdapter a) => O.MethodInfo AdapterDistanceFromDiscontMethodInfo a signature where
    overloadedMethod _ = adapterDistanceFromDiscont

#endif

-- method Adapter::dts_at_discont
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_dts_at_discont" gst_adapter_dts_at_discont ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO Word64

{- |
Get the DTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
flag, or GST_CLOCK_TIME_NONE.

/Since: 1.10/
-}
adapterDtsAtDiscont ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m Word64
    {- ^ __Returns:__ The DTS at the last discont or GST_CLOCK_TIME_NONE. -}
adapterDtsAtDiscont adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_dts_at_discont adapter'
    touchManagedPtr adapter
    return result

#if ENABLE_OVERLOADING
data AdapterDtsAtDiscontMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsAdapter a) => O.MethodInfo AdapterDtsAtDiscontMethodInfo a signature where
    overloadedMethod _ = adapterDtsAtDiscont

#endif

-- method Adapter::flush
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flush", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to flush", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_flush" gst_adapter_flush ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- flush : TBasicType TUInt64
    IO ()

{- |
Flushes the first /@flush@/ bytes in the /@adapter@/. The caller must ensure that
at least this many bytes are available.

See also: 'GI.GstBase.Objects.Adapter.adapterMap', 'GI.GstBase.Objects.Adapter.adapterUnmap'
-}
adapterFlush ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@flush@/: the number of bytes to flush -}
    -> m ()
adapterFlush adapter flush = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    gst_adapter_flush adapter' flush
    touchManagedPtr adapter
    return ()

#if ENABLE_OVERLOADING
data AdapterFlushMethodInfo
instance (signature ~ (Word64 -> m ()), MonadIO m, IsAdapter a) => O.MethodInfo AdapterFlushMethodInfo a signature where
    overloadedMethod _ = adapterFlush

#endif

-- method Adapter::get_buffer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to get", 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_adapter_get_buffer" gst_adapter_get_buffer ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr Gst.Buffer.Buffer)

{- |
Returns a 'GI.Gst.Structs.Buffer.Buffer' containing the first /@nbytes@/ of the /@adapter@/, but
does not flush them from the adapter. See 'GI.GstBase.Objects.Adapter.adapterTakeBuffer'
for details.

Caller owns a reference to the returned buffer. @/gst_buffer_unref()/@ after
usage.

Free-function: gst_buffer_unref

/Since: 1.6/
-}
adapterGetBuffer ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to get -}
    -> m (Maybe Gst.Buffer.Buffer)
    {- ^ __Returns:__ a 'GI.Gst.Structs.Buffer.Buffer' containing the first
    /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/ bytes are not available.
    @/gst_buffer_unref()/@ when no longer needed. -}
adapterGetBuffer adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_get_buffer adapter' nbytes
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Gst.Buffer.Buffer) result'
        return result''
    touchManagedPtr adapter
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterGetBufferMethodInfo
instance (signature ~ (Word64 -> m (Maybe Gst.Buffer.Buffer)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterGetBufferMethodInfo a signature where
    overloadedMethod _ = adapterGetBuffer

#endif

-- method Adapter::get_buffer_fast
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to get", 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_adapter_get_buffer_fast" gst_adapter_get_buffer_fast ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr Gst.Buffer.Buffer)

{- |
Returns a 'GI.Gst.Structs.Buffer.Buffer' containing the first /@nbytes@/ of the /@adapter@/, but
does not flush them from the adapter. See 'GI.GstBase.Objects.Adapter.adapterTakeBufferFast'
for details.

Caller owns a reference to the returned buffer. @/gst_buffer_unref()/@ after
usage.

Free-function: gst_buffer_unref

/Since: 1.6/
-}
adapterGetBufferFast ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to get -}
    -> m (Maybe Gst.Buffer.Buffer)
    {- ^ __Returns:__ a 'GI.Gst.Structs.Buffer.Buffer' containing the first
    /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/ bytes are not available.
    @/gst_buffer_unref()/@ when no longer needed. -}
adapterGetBufferFast adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_get_buffer_fast adapter' nbytes
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Gst.Buffer.Buffer) result'
        return result''
    touchManagedPtr adapter
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterGetBufferFastMethodInfo
instance (signature ~ (Word64 -> m (Maybe Gst.Buffer.Buffer)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterGetBufferFastMethodInfo a signature where
    overloadedMethod _ = adapterGetBufferFast

#endif

-- method Adapter::get_buffer_list
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to get", 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_adapter_get_buffer_list" gst_adapter_get_buffer_list ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr Gst.BufferList.BufferList)

{- |
Returns a 'GI.Gst.Structs.BufferList.BufferList' of buffers containing the first /@nbytes@/ bytes of
the /@adapter@/ but does not flush them from the adapter. See
'GI.GstBase.Objects.Adapter.adapterTakeBufferList' for details.

Caller owns the returned list. Call @/gst_buffer_list_unref()/@ to free
the list after usage.

/Since: 1.6/
-}
adapterGetBufferList ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to get -}
    -> m (Maybe Gst.BufferList.BufferList)
    {- ^ __Returns:__ a 'GI.Gst.Structs.BufferList.BufferList' of buffers containing
    the first /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/ bytes are not
    available -}
adapterGetBufferList adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_get_buffer_list adapter' nbytes
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Gst.BufferList.BufferList) result'
        return result''
    touchManagedPtr adapter
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterGetBufferListMethodInfo
instance (signature ~ (Word64 -> m (Maybe Gst.BufferList.BufferList)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterGetBufferListMethodInfo a signature where
    overloadedMethod _ = adapterGetBufferList

#endif

-- method Adapter::get_list
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to get", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TGList (TInterface (Name {namespace = "Gst", name = "Buffer"})))
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_get_list" gst_adapter_get_list ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr (GList (Ptr Gst.Buffer.Buffer)))

{- |
Returns a 'GI.GLib.Structs.List.List' of buffers containing the first /@nbytes@/ bytes of the
/@adapter@/, but does not flush them from the adapter. See
'GI.GstBase.Objects.Adapter.adapterTakeList' for details.

Caller owns returned list and contained buffers. @/gst_buffer_unref()/@ each
buffer in the list before freeing the list after usage.

/Since: 1.6/
-}
adapterGetList ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to get -}
    -> m [Gst.Buffer.Buffer]
    {- ^ __Returns:__ a 'GI.GLib.Structs.List.List' of
    buffers containing the first /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/
    bytes are not available -}
adapterGetList adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_get_list adapter' nbytes
    result' <- unpackGList result
    result'' <- mapM (wrapBoxed Gst.Buffer.Buffer) result'
    g_list_free result
    touchManagedPtr adapter
    return result''

#if ENABLE_OVERLOADING
data AdapterGetListMethodInfo
instance (signature ~ (Word64 -> m [Gst.Buffer.Buffer]), MonadIO m, IsAdapter a) => O.MethodInfo AdapterGetListMethodInfo a signature where
    overloadedMethod _ = adapterGetList

#endif

-- method Adapter::map
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "size", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to map/peek", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : [Arg {argCName = "size", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to map/peek", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- returnType : Just (TCArray False (-1) 1 (TBasicType TUInt8))
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_map" gst_adapter_map ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Ptr Word64 ->                           -- size : TBasicType TUInt64
    IO (Ptr Word8)

{- |
Gets the first /@size@/ bytes stored in the /@adapter@/. The returned pointer is
valid until the next function is called on the adapter.

Note that setting the returned pointer as the data of a 'GI.Gst.Structs.Buffer.Buffer' is
incorrect for general-purpose plugins. The reason is that if a downstream
element stores the buffer so that it has access to it outside of the bounds
of its chain function, the buffer will have an invalid data pointer after
your element flushes the bytes. In that case you should use
'GI.GstBase.Objects.Adapter.adapterTake', which returns a freshly-allocated buffer that you can set
as 'GI.Gst.Structs.Buffer.Buffer' memory or the potentially more performant
'GI.GstBase.Objects.Adapter.adapterTakeBuffer'.

Returns 'Nothing' if /@size@/ bytes are not available.
-}
adapterMap ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m (Maybe ByteString)
    {- ^ __Returns:__ 
    a pointer to the first /@size@/ bytes of data, or 'Nothing' -}
adapterMap adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    size <- allocMem :: IO (Ptr Word64)
    result <- gst_adapter_map adapter' size
    size' <- peek size
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (unpackByteStringWithLength size') result'
        return result''
    touchManagedPtr adapter
    freeMem size
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterMapMethodInfo
instance (signature ~ (m (Maybe ByteString)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterMapMethodInfo a signature where
    overloadedMethod _ = adapterMap

#endif

-- method Adapter::masked_scan_uint32
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "mask", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "mask to apply to data before matching against @pattern", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "pattern", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pattern to match (after mask is applied)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "offset", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "offset into the adapter data from which to start scanning, returns\n         the last scanned position.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "size", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes to scan from offset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_masked_scan_uint32" gst_adapter_masked_scan_uint32 ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word32 ->                               -- mask : TBasicType TUInt32
    Word32 ->                               -- pattern : TBasicType TUInt32
    Word64 ->                               -- offset : TBasicType TUInt64
    Word64 ->                               -- size : TBasicType TUInt64
    IO Int64

{- |
Scan for pattern /@pattern@/ with applied mask /@mask@/ in the adapter data,
starting from offset /@offset@/.

The bytes in /@pattern@/ and /@mask@/ are interpreted left-to-right, regardless
of endianness.  All four bytes of the pattern must be present in the
adapter for it to match, even if the first or last bytes are masked out.

It is an error to call this function without making sure that there is
enough data (offset+size bytes) in the adapter.

This function calls 'GI.GstBase.Objects.Adapter.adapterMaskedScanUint32Peek' passing 'Nothing'
for value.
-}
adapterMaskedScanUint32 ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word32
    {- ^ /@mask@/: mask to apply to data before matching against /@pattern@/ -}
    -> Word32
    {- ^ /@pattern@/: pattern to match (after mask is applied) -}
    -> Word64
    {- ^ /@offset@/: offset into the adapter data from which to start scanning, returns
         the last scanned position. -}
    -> Word64
    {- ^ /@size@/: number of bytes to scan from offset -}
    -> m Int64
    {- ^ __Returns:__ offset of the first match, or -1 if no match was found.

Example:
>
>// Assume the adapter contains 0x00 0x01 0x02 ... 0xfe 0xff
>
>gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 0, 256);
>// -> returns 0
>gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 1, 255);
>// -> returns -1
>gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x01020304, 1, 255);
>// -> returns 1
>gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0001, 0, 256);
>// -> returns -1
>gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0203, 0, 256);
>// -> returns 0
>gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 256);
>// -> returns 2
>gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 4);
>// -> returns -1
 -}
adapterMaskedScanUint32 adapter mask pattern offset size = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_masked_scan_uint32 adapter' mask pattern offset size
    touchManagedPtr adapter
    return result

#if ENABLE_OVERLOADING
data AdapterMaskedScanUint32MethodInfo
instance (signature ~ (Word32 -> Word32 -> Word64 -> Word64 -> m Int64), MonadIO m, IsAdapter a) => O.MethodInfo AdapterMaskedScanUint32MethodInfo a signature where
    overloadedMethod _ = adapterMaskedScanUint32

#endif

-- method Adapter::masked_scan_uint32_peek
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "mask", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "mask to apply to data before matching against @pattern", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "pattern", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pattern to match (after mask is applied)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "offset", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "offset into the adapter data from which to start scanning, returns\n         the last scanned position.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "size", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of bytes to scan from offset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUInt32, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to uint32 to return matching data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_masked_scan_uint32_peek" gst_adapter_masked_scan_uint32_peek ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word32 ->                               -- mask : TBasicType TUInt32
    Word32 ->                               -- pattern : TBasicType TUInt32
    Word64 ->                               -- offset : TBasicType TUInt64
    Word64 ->                               -- size : TBasicType TUInt64
    Ptr Word32 ->                           -- value : TBasicType TUInt32
    IO Int64

{- |
Scan for pattern /@pattern@/ with applied mask /@mask@/ in the adapter data,
starting from offset /@offset@/.  If a match is found, the value that matched
is returned through /@value@/, otherwise /@value@/ is left untouched.

The bytes in /@pattern@/ and /@mask@/ are interpreted left-to-right, regardless
of endianness.  All four bytes of the pattern must be present in the
adapter for it to match, even if the first or last bytes are masked out.

It is an error to call this function without making sure that there is
enough data (offset+size bytes) in the adapter.
-}
adapterMaskedScanUint32Peek ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word32
    {- ^ /@mask@/: mask to apply to data before matching against /@pattern@/ -}
    -> Word32
    {- ^ /@pattern@/: pattern to match (after mask is applied) -}
    -> Word64
    {- ^ /@offset@/: offset into the adapter data from which to start scanning, returns
         the last scanned position. -}
    -> Word64
    {- ^ /@size@/: number of bytes to scan from offset -}
    -> m ((Int64, Word32))
    {- ^ __Returns:__ offset of the first match, or -1 if no match was found. -}
adapterMaskedScanUint32Peek adapter mask pattern offset size = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    value <- allocMem :: IO (Ptr Word32)
    result <- gst_adapter_masked_scan_uint32_peek adapter' mask pattern offset size value
    value' <- peek value
    touchManagedPtr adapter
    freeMem value
    return (result, value')

#if ENABLE_OVERLOADING
data AdapterMaskedScanUint32PeekMethodInfo
instance (signature ~ (Word32 -> Word32 -> Word64 -> Word64 -> m ((Int64, Word32))), MonadIO m, IsAdapter a) => O.MethodInfo AdapterMaskedScanUint32PeekMethodInfo a signature where
    overloadedMethod _ = adapterMaskedScanUint32Peek

#endif

-- method Adapter::offset_at_discont
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_offset_at_discont" gst_adapter_offset_at_discont ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO Word64

{- |
Get the offset that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
flag, or GST_BUFFER_OFFSET_NONE.

/Since: 1.10/
-}
adapterOffsetAtDiscont ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m Word64
    {- ^ __Returns:__ The offset at the last discont or GST_BUFFER_OFFSET_NONE. -}
adapterOffsetAtDiscont adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_offset_at_discont adapter'
    touchManagedPtr adapter
    return result

#if ENABLE_OVERLOADING
data AdapterOffsetAtDiscontMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsAdapter a) => O.MethodInfo AdapterOffsetAtDiscontMethodInfo a signature where
    overloadedMethod _ = adapterOffsetAtDiscont

#endif

-- method Adapter::prev_dts
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "distance", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to location for distance, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_prev_dts" gst_adapter_prev_dts ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Ptr Word64 ->                           -- distance : TBasicType TUInt64
    IO Word64

{- |
Get the dts that was before the current byte in the adapter. When
/@distance@/ is given, the amount of bytes between the dts and the current
position is returned.

The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
the adapter is first created or when it is cleared. This also means that before
the first byte with a dts is removed from the adapter, the dts
and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
-}
adapterPrevDts ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m ((Word64, Word64))
    {- ^ __Returns:__ The previously seen dts. -}
adapterPrevDts adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    distance <- allocMem :: IO (Ptr Word64)
    result <- gst_adapter_prev_dts adapter' distance
    distance' <- peek distance
    touchManagedPtr adapter
    freeMem distance
    return (result, distance')

#if ENABLE_OVERLOADING
data AdapterPrevDtsMethodInfo
instance (signature ~ (m ((Word64, Word64))), MonadIO m, IsAdapter a) => O.MethodInfo AdapterPrevDtsMethodInfo a signature where
    overloadedMethod _ = adapterPrevDts

#endif

-- method Adapter::prev_dts_at_offset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "offset", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the offset in the adapter at which to get timestamp", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "distance", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to location for distance, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_prev_dts_at_offset" gst_adapter_prev_dts_at_offset ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- offset : TBasicType TUInt64
    Ptr Word64 ->                           -- distance : TBasicType TUInt64
    IO Word64

{- |
Get the dts that was before the byte at offset /@offset@/ in the adapter. When
/@distance@/ is given, the amount of bytes between the dts and the current
position is returned.

The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
the adapter is first created or when it is cleared. This also means that before
the first byte with a dts is removed from the adapter, the dts
and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.

/Since: 1.2/
-}
adapterPrevDtsAtOffset ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@offset@/: the offset in the adapter at which to get timestamp -}
    -> m ((Word64, Word64))
    {- ^ __Returns:__ The previously seen dts at given offset. -}
adapterPrevDtsAtOffset adapter offset = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    distance <- allocMem :: IO (Ptr Word64)
    result <- gst_adapter_prev_dts_at_offset adapter' offset distance
    distance' <- peek distance
    touchManagedPtr adapter
    freeMem distance
    return (result, distance')

#if ENABLE_OVERLOADING
data AdapterPrevDtsAtOffsetMethodInfo
instance (signature ~ (Word64 -> m ((Word64, Word64))), MonadIO m, IsAdapter a) => O.MethodInfo AdapterPrevDtsAtOffsetMethodInfo a signature where
    overloadedMethod _ = adapterPrevDtsAtOffset

#endif

-- method Adapter::prev_offset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "distance", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to a location for distance, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_prev_offset" gst_adapter_prev_offset ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Ptr Word64 ->                           -- distance : TBasicType TUInt64
    IO Word64

{- |
Get the offset that was before the current byte in the adapter. When
/@distance@/ is given, the amount of bytes between the offset and the current
position is returned.

The offset is reset to GST_BUFFER_OFFSET_NONE and the distance is set to 0
when the adapter is first created or when it is cleared. This also means that
before the first byte with an offset is removed from the adapter, the offset
and distance returned are GST_BUFFER_OFFSET_NONE and 0 respectively.

/Since: 1.10/
-}
adapterPrevOffset ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m ((Word64, Word64))
    {- ^ __Returns:__ The previous seen offset. -}
adapterPrevOffset adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    distance <- allocMem :: IO (Ptr Word64)
    result <- gst_adapter_prev_offset adapter' distance
    distance' <- peek distance
    touchManagedPtr adapter
    freeMem distance
    return (result, distance')

#if ENABLE_OVERLOADING
data AdapterPrevOffsetMethodInfo
instance (signature ~ (m ((Word64, Word64))), MonadIO m, IsAdapter a) => O.MethodInfo AdapterPrevOffsetMethodInfo a signature where
    overloadedMethod _ = adapterPrevOffset

#endif

-- method Adapter::prev_pts
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "distance", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to location for distance, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_prev_pts" gst_adapter_prev_pts ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Ptr Word64 ->                           -- distance : TBasicType TUInt64
    IO Word64

{- |
Get the pts that was before the current byte in the adapter. When
/@distance@/ is given, the amount of bytes between the pts and the current
position is returned.

The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
the adapter is first created or when it is cleared. This also means that before
the first byte with a pts is removed from the adapter, the pts
and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
-}
adapterPrevPts ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m ((Word64, Word64))
    {- ^ __Returns:__ The previously seen pts. -}
adapterPrevPts adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    distance <- allocMem :: IO (Ptr Word64)
    result <- gst_adapter_prev_pts adapter' distance
    distance' <- peek distance
    touchManagedPtr adapter
    freeMem distance
    return (result, distance')

#if ENABLE_OVERLOADING
data AdapterPrevPtsMethodInfo
instance (signature ~ (m ((Word64, Word64))), MonadIO m, IsAdapter a) => O.MethodInfo AdapterPrevPtsMethodInfo a signature where
    overloadedMethod _ = adapterPrevPts

#endif

-- method Adapter::prev_pts_at_offset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "offset", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the offset in the adapter at which to get timestamp", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "distance", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to location for distance, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_prev_pts_at_offset" gst_adapter_prev_pts_at_offset ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- offset : TBasicType TUInt64
    Ptr Word64 ->                           -- distance : TBasicType TUInt64
    IO Word64

{- |
Get the pts that was before the byte at offset /@offset@/ in the adapter. When
/@distance@/ is given, the amount of bytes between the pts and the current
position is returned.

The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
the adapter is first created or when it is cleared. This also means that before
the first byte with a pts is removed from the adapter, the pts
and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.

/Since: 1.2/
-}
adapterPrevPtsAtOffset ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@offset@/: the offset in the adapter at which to get timestamp -}
    -> m ((Word64, Word64))
    {- ^ __Returns:__ The previously seen pts at given offset. -}
adapterPrevPtsAtOffset adapter offset = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    distance <- allocMem :: IO (Ptr Word64)
    result <- gst_adapter_prev_pts_at_offset adapter' offset distance
    distance' <- peek distance
    touchManagedPtr adapter
    freeMem distance
    return (result, distance')

#if ENABLE_OVERLOADING
data AdapterPrevPtsAtOffsetMethodInfo
instance (signature ~ (Word64 -> m ((Word64, Word64))), MonadIO m, IsAdapter a) => O.MethodInfo AdapterPrevPtsAtOffsetMethodInfo a signature where
    overloadedMethod _ = adapterPrevPtsAtOffset

#endif

-- method Adapter::pts_at_discont
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_pts_at_discont" gst_adapter_pts_at_discont ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO Word64

{- |
Get the PTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
flag, or GST_CLOCK_TIME_NONE.

/Since: 1.10/
-}
adapterPtsAtDiscont ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m Word64
    {- ^ __Returns:__ The PTS at the last discont or GST_CLOCK_TIME_NONE. -}
adapterPtsAtDiscont adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_pts_at_discont adapter'
    touchManagedPtr adapter
    return result

#if ENABLE_OVERLOADING
data AdapterPtsAtDiscontMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsAdapter a) => O.MethodInfo AdapterPtsAtDiscontMethodInfo a signature where
    overloadedMethod _ = adapterPtsAtDiscont

#endif

-- method Adapter::push
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "buf", argType = TInterface (Name {namespace = "Gst", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBuffer to add to queue in the adapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_push" gst_adapter_push ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Ptr Gst.Buffer.Buffer ->                -- buf : TInterface (Name {namespace = "Gst", name = "Buffer"})
    IO ()

{- |
Adds the data from /@buf@/ to the data stored inside /@adapter@/ and takes
ownership of the buffer.
-}
adapterPush ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Gst.Buffer.Buffer
    {- ^ /@buf@/: a 'GI.Gst.Structs.Buffer.Buffer' to add to queue in the adapter -}
    -> m ()
adapterPush adapter buf = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    buf' <- B.ManagedPtr.disownBoxed buf
    gst_adapter_push adapter' buf'
    touchManagedPtr adapter
    touchManagedPtr buf
    return ()

#if ENABLE_OVERLOADING
data AdapterPushMethodInfo
instance (signature ~ (Gst.Buffer.Buffer -> m ()), MonadIO m, IsAdapter a) => O.MethodInfo AdapterPushMethodInfo a signature where
    overloadedMethod _ = adapterPush

#endif

-- method Adapter::take
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to take", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : [Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to take", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- returnType : Just (TCArray False (-1) 1 (TBasicType TUInt8))
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_take" gst_adapter_take ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Ptr Word64 ->                           -- nbytes : TBasicType TUInt64
    IO (Ptr Word8)

{- |
Returns a freshly allocated buffer containing the first /@nbytes@/ bytes of the
/@adapter@/. The returned bytes will be flushed from the adapter.

Caller owns returned value. g_free after usage.

Free-function: g_free
-}
adapterTake ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m (Maybe ByteString)
    {- ^ __Returns:__ 
    oven-fresh hot data, or 'Nothing' if /@nbytes@/ bytes are not available -}
adapterTake adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    nbytes <- allocMem :: IO (Ptr Word64)
    result <- gst_adapter_take adapter' nbytes
    nbytes' <- peek nbytes
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (unpackByteStringWithLength nbytes') result'
        freeMem result'
        return result''
    touchManagedPtr adapter
    freeMem nbytes
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterTakeMethodInfo
instance (signature ~ (m (Maybe ByteString)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterTakeMethodInfo a signature where
    overloadedMethod _ = adapterTake

#endif

-- method Adapter::take_buffer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to take", 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_adapter_take_buffer" gst_adapter_take_buffer ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr Gst.Buffer.Buffer)

{- |
Returns a 'GI.Gst.Structs.Buffer.Buffer' containing the first /@nbytes@/ bytes of the
/@adapter@/. The returned bytes will be flushed from the adapter.
This function is potentially more performant than
'GI.GstBase.Objects.Adapter.adapterTake' since it can reuse the memory in pushed buffers
by subbuffering or merging. This function will always return a
buffer with a single memory region.

Note that no assumptions should be made as to whether certain buffer
flags such as the DISCONT flag are set on the returned buffer, or not.
The caller needs to explicitly set or unset flags that should be set or
unset.

Since 1.6 this will also copy over all GstMeta of the input buffers except
for meta with the 'GI.Gst.Flags.MetaFlagsPooled' flag or with the \"memory\" tag.

Caller owns a reference to the returned buffer. @/gst_buffer_unref()/@ after
usage.

Free-function: gst_buffer_unref
-}
adapterTakeBuffer ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to take -}
    -> m (Maybe Gst.Buffer.Buffer)
    {- ^ __Returns:__ a 'GI.Gst.Structs.Buffer.Buffer' containing the first
    /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/ bytes are not available.
    @/gst_buffer_unref()/@ when no longer needed. -}
adapterTakeBuffer adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_take_buffer adapter' nbytes
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Gst.Buffer.Buffer) result'
        return result''
    touchManagedPtr adapter
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterTakeBufferMethodInfo
instance (signature ~ (Word64 -> m (Maybe Gst.Buffer.Buffer)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterTakeBufferMethodInfo a signature where
    overloadedMethod _ = adapterTakeBuffer

#endif

-- method Adapter::take_buffer_fast
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to take", 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_adapter_take_buffer_fast" gst_adapter_take_buffer_fast ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr Gst.Buffer.Buffer)

{- |
Returns a 'GI.Gst.Structs.Buffer.Buffer' containing the first /@nbytes@/ of the /@adapter@/.
The returned bytes will be flushed from the adapter.  This function
is potentially more performant than 'GI.GstBase.Objects.Adapter.adapterTakeBuffer' since
it can reuse the memory in pushed buffers by subbuffering or
merging. Unlike 'GI.GstBase.Objects.Adapter.adapterTakeBuffer', the returned buffer may
be composed of multiple non-contiguous 'GI.Gst.Structs.Memory.Memory' objects, no
copies are made.

Note that no assumptions should be made as to whether certain buffer
flags such as the DISCONT flag are set on the returned buffer, or not.
The caller needs to explicitly set or unset flags that should be set or
unset.

This will also copy over all GstMeta of the input buffers except
for meta with the 'GI.Gst.Flags.MetaFlagsPooled' flag or with the \"memory\" tag.

This function can return buffer up to the return value of
'GI.GstBase.Objects.Adapter.adapterAvailable' without making copies if possible.

Caller owns a reference to the returned buffer. @/gst_buffer_unref()/@ after
usage.

Free-function: gst_buffer_unref

/Since: 1.2/
-}
adapterTakeBufferFast ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to take -}
    -> m (Maybe Gst.Buffer.Buffer)
    {- ^ __Returns:__ a 'GI.Gst.Structs.Buffer.Buffer' containing the first
    /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/ bytes are not available.
    @/gst_buffer_unref()/@ when no longer needed. -}
adapterTakeBufferFast adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_take_buffer_fast adapter' nbytes
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Gst.Buffer.Buffer) result'
        return result''
    touchManagedPtr adapter
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterTakeBufferFastMethodInfo
instance (signature ~ (Word64 -> m (Maybe Gst.Buffer.Buffer)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterTakeBufferFastMethodInfo a signature where
    overloadedMethod _ = adapterTakeBufferFast

#endif

-- method Adapter::take_buffer_list
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to take", 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_adapter_take_buffer_list" gst_adapter_take_buffer_list ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr Gst.BufferList.BufferList)

{- |
Returns a 'GI.Gst.Structs.BufferList.BufferList' of buffers containing the first /@nbytes@/ bytes of
the /@adapter@/. The returned bytes will be flushed from the adapter.
When the caller can deal with individual buffers, this function is more
performant because no memory should be copied.

Caller owns the returned list. Call @/gst_buffer_list_unref()/@ to free
the list after usage.

/Since: 1.6/
-}
adapterTakeBufferList ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to take -}
    -> m (Maybe Gst.BufferList.BufferList)
    {- ^ __Returns:__ a 'GI.Gst.Structs.BufferList.BufferList' of buffers containing
    the first /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/ bytes are not
    available -}
adapterTakeBufferList adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_take_buffer_list adapter' nbytes
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Gst.BufferList.BufferList) result'
        return result''
    touchManagedPtr adapter
    return maybeResult

#if ENABLE_OVERLOADING
data AdapterTakeBufferListMethodInfo
instance (signature ~ (Word64 -> m (Maybe Gst.BufferList.BufferList)), MonadIO m, IsAdapter a) => O.MethodInfo AdapterTakeBufferListMethodInfo a signature where
    overloadedMethod _ = adapterTakeBufferList

#endif

-- method Adapter::take_list
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "adapter", argType = TInterface (Name {namespace = "GstBase", name = "Adapter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAdapter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nbytes", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of bytes to take", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TGList (TInterface (Name {namespace = "Gst", name = "Buffer"})))
-- throws : False
-- Skip return : False

foreign import ccall "gst_adapter_take_list" gst_adapter_take_list ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    Word64 ->                               -- nbytes : TBasicType TUInt64
    IO (Ptr (GList (Ptr Gst.Buffer.Buffer)))

{- |
Returns a 'GI.GLib.Structs.List.List' of buffers containing the first /@nbytes@/ bytes of the
/@adapter@/. The returned bytes will be flushed from the adapter.
When the caller can deal with individual buffers, this function is more
performant because no memory should be copied.

Caller owns returned list and contained buffers. @/gst_buffer_unref()/@ each
buffer in the list before freeing the list after usage.
-}
adapterTakeList ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> Word64
    {- ^ /@nbytes@/: the number of bytes to take -}
    -> m [Gst.Buffer.Buffer]
    {- ^ __Returns:__ a 'GI.GLib.Structs.List.List' of
    buffers containing the first /@nbytes@/ of the adapter, or 'Nothing' if /@nbytes@/
    bytes are not available -}
adapterTakeList adapter nbytes = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    result <- gst_adapter_take_list adapter' nbytes
    result' <- unpackGList result
    result'' <- mapM (wrapBoxed Gst.Buffer.Buffer) result'
    g_list_free result
    touchManagedPtr adapter
    return result''

#if ENABLE_OVERLOADING
data AdapterTakeListMethodInfo
instance (signature ~ (Word64 -> m [Gst.Buffer.Buffer]), MonadIO m, IsAdapter a) => O.MethodInfo AdapterTakeListMethodInfo a signature where
    overloadedMethod _ = adapterTakeList

#endif

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

foreign import ccall "gst_adapter_unmap" gst_adapter_unmap ::
    Ptr Adapter ->                          -- adapter : TInterface (Name {namespace = "GstBase", name = "Adapter"})
    IO ()

{- |
Releases the memory obtained with the last 'GI.GstBase.Objects.Adapter.adapterMap'.
-}
adapterUnmap ::
    (B.CallStack.HasCallStack, MonadIO m, IsAdapter a) =>
    a
    {- ^ /@adapter@/: a 'GI.GstBase.Objects.Adapter.Adapter' -}
    -> m ()
adapterUnmap adapter = liftIO $ do
    adapter' <- unsafeManagedPtrCastPtr adapter
    gst_adapter_unmap adapter'
    touchManagedPtr adapter
    return ()

#if ENABLE_OVERLOADING
data AdapterUnmapMethodInfo
instance (signature ~ (m ()), MonadIO m, IsAdapter a) => O.MethodInfo AdapterUnmapMethodInfo a signature where
    overloadedMethod _ = adapterUnmap

#endif