{- | Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte License : LGPL-2.1 Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc) 'GI.GstAudio.Objects.AudioClock.AudioClock' makes it easy for elements to implement a 'GI.Gst.Objects.Clock.Clock', they simply need to provide a function that returns the current clock time. This object is internally used to implement the clock in 'GI.GstAudio.Objects.AudioBaseSink.AudioBaseSink'. -} #define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \ && !defined(__HADDOCK_VERSION__)) module GI.GstAudio.Objects.AudioClock ( -- * Exported types AudioClock(..) , IsAudioClock , toAudioClock , noAudioClock , -- * Methods -- ** adjust #method:adjust# #if ENABLE_OVERLOADING AudioClockAdjustMethodInfo , #endif audioClockAdjust , -- ** getTime #method:getTime# #if ENABLE_OVERLOADING AudioClockGetTimeMethodInfo , #endif audioClockGetTime , -- ** invalidate #method:invalidate# #if ENABLE_OVERLOADING AudioClockInvalidateMethodInfo , #endif audioClockInvalidate , -- ** new #method:new# audioClockNew , -- ** reset #method:reset# #if ENABLE_OVERLOADING AudioClockResetMethodInfo , #endif audioClockReset , ) 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.Callbacks as GLib.Callbacks import qualified GI.GObject.Objects.Object as GObject.Object import qualified GI.Gst.Objects.Clock as Gst.Clock import qualified GI.Gst.Objects.Object as Gst.Object import qualified GI.Gst.Objects.SystemClock as Gst.SystemClock import qualified GI.GstAudio.Callbacks as GstAudio.Callbacks -- | Memory-managed wrapper type. newtype AudioClock = AudioClock (ManagedPtr AudioClock) foreign import ccall "gst_audio_clock_get_type" c_gst_audio_clock_get_type :: IO GType instance GObject AudioClock where gobjectType = c_gst_audio_clock_get_type -- | Type class for types which can be safely cast to `AudioClock`, for instance with `toAudioClock`. class (GObject o, O.IsDescendantOf AudioClock o) => IsAudioClock o instance (GObject o, O.IsDescendantOf AudioClock o) => IsAudioClock o instance O.HasParentTypes AudioClock type instance O.ParentTypes AudioClock = '[Gst.SystemClock.SystemClock, Gst.Clock.Clock, Gst.Object.Object, GObject.Object.Object] -- | Cast to `AudioClock`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`. toAudioClock :: (MonadIO m, IsAudioClock o) => o -> m AudioClock toAudioClock = liftIO . unsafeCastTo AudioClock -- | A convenience alias for `Nothing` :: `Maybe` `AudioClock`. noAudioClock :: Maybe AudioClock noAudioClock = Nothing #if ENABLE_OVERLOADING type family ResolveAudioClockMethod (t :: Symbol) (o :: *) :: * where ResolveAudioClockMethod "addControlBinding" o = Gst.Object.ObjectAddControlBindingMethodInfo ResolveAudioClockMethod "addObservation" o = Gst.Clock.ClockAddObservationMethodInfo ResolveAudioClockMethod "addObservationUnapplied" o = Gst.Clock.ClockAddObservationUnappliedMethodInfo ResolveAudioClockMethod "adjust" o = AudioClockAdjustMethodInfo ResolveAudioClockMethod "adjustUnlocked" o = Gst.Clock.ClockAdjustUnlockedMethodInfo ResolveAudioClockMethod "adjustWithCalibration" o = Gst.Clock.ClockAdjustWithCalibrationMethodInfo ResolveAudioClockMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo ResolveAudioClockMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo ResolveAudioClockMethod "defaultError" o = Gst.Object.ObjectDefaultErrorMethodInfo ResolveAudioClockMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo ResolveAudioClockMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo ResolveAudioClockMethod "getv" o = GObject.Object.ObjectGetvMethodInfo ResolveAudioClockMethod "hasActiveControlBindings" o = Gst.Object.ObjectHasActiveControlBindingsMethodInfo ResolveAudioClockMethod "hasAncestor" o = Gst.Object.ObjectHasAncestorMethodInfo ResolveAudioClockMethod "hasAsAncestor" o = Gst.Object.ObjectHasAsAncestorMethodInfo ResolveAudioClockMethod "hasAsParent" o = Gst.Object.ObjectHasAsParentMethodInfo ResolveAudioClockMethod "invalidate" o = AudioClockInvalidateMethodInfo ResolveAudioClockMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo ResolveAudioClockMethod "isSynced" o = Gst.Clock.ClockIsSyncedMethodInfo ResolveAudioClockMethod "newPeriodicId" o = Gst.Clock.ClockNewPeriodicIdMethodInfo ResolveAudioClockMethod "newSingleShotId" o = Gst.Clock.ClockNewSingleShotIdMethodInfo ResolveAudioClockMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo ResolveAudioClockMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo ResolveAudioClockMethod "periodicIdReinit" o = Gst.Clock.ClockPeriodicIdReinitMethodInfo ResolveAudioClockMethod "ref" o = Gst.Object.ObjectRefMethodInfo ResolveAudioClockMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo ResolveAudioClockMethod "removeControlBinding" o = Gst.Object.ObjectRemoveControlBindingMethodInfo ResolveAudioClockMethod "reset" o = AudioClockResetMethodInfo ResolveAudioClockMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo ResolveAudioClockMethod "singleShotIdReinit" o = Gst.Clock.ClockSingleShotIdReinitMethodInfo ResolveAudioClockMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo ResolveAudioClockMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo ResolveAudioClockMethod "suggestNextSync" o = Gst.Object.ObjectSuggestNextSyncMethodInfo ResolveAudioClockMethod "syncValues" o = Gst.Object.ObjectSyncValuesMethodInfo ResolveAudioClockMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo ResolveAudioClockMethod "unadjustUnlocked" o = Gst.Clock.ClockUnadjustUnlockedMethodInfo ResolveAudioClockMethod "unadjustWithCalibration" o = Gst.Clock.ClockUnadjustWithCalibrationMethodInfo ResolveAudioClockMethod "unparent" o = Gst.Object.ObjectUnparentMethodInfo ResolveAudioClockMethod "unref" o = Gst.Object.ObjectUnrefMethodInfo ResolveAudioClockMethod "waitForSync" o = Gst.Clock.ClockWaitForSyncMethodInfo ResolveAudioClockMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo ResolveAudioClockMethod "getCalibration" o = Gst.Clock.ClockGetCalibrationMethodInfo ResolveAudioClockMethod "getControlBinding" o = Gst.Object.ObjectGetControlBindingMethodInfo ResolveAudioClockMethod "getControlRate" o = Gst.Object.ObjectGetControlRateMethodInfo ResolveAudioClockMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo ResolveAudioClockMethod "getGValueArray" o = Gst.Object.ObjectGetGValueArrayMethodInfo ResolveAudioClockMethod "getInternalTime" o = Gst.Clock.ClockGetInternalTimeMethodInfo ResolveAudioClockMethod "getMaster" o = Gst.Clock.ClockGetMasterMethodInfo ResolveAudioClockMethod "getName" o = Gst.Object.ObjectGetNameMethodInfo ResolveAudioClockMethod "getParent" o = Gst.Object.ObjectGetParentMethodInfo ResolveAudioClockMethod "getPathString" o = Gst.Object.ObjectGetPathStringMethodInfo ResolveAudioClockMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo ResolveAudioClockMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo ResolveAudioClockMethod "getResolution" o = Gst.Clock.ClockGetResolutionMethodInfo ResolveAudioClockMethod "getTime" o = AudioClockGetTimeMethodInfo ResolveAudioClockMethod "getTimeout" o = Gst.Clock.ClockGetTimeoutMethodInfo ResolveAudioClockMethod "getValue" o = Gst.Object.ObjectGetValueMethodInfo ResolveAudioClockMethod "setCalibration" o = Gst.Clock.ClockSetCalibrationMethodInfo ResolveAudioClockMethod "setControlBindingDisabled" o = Gst.Object.ObjectSetControlBindingDisabledMethodInfo ResolveAudioClockMethod "setControlBindingsDisabled" o = Gst.Object.ObjectSetControlBindingsDisabledMethodInfo ResolveAudioClockMethod "setControlRate" o = Gst.Object.ObjectSetControlRateMethodInfo ResolveAudioClockMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo ResolveAudioClockMethod "setMaster" o = Gst.Clock.ClockSetMasterMethodInfo ResolveAudioClockMethod "setName" o = Gst.Object.ObjectSetNameMethodInfo ResolveAudioClockMethod "setParent" o = Gst.Object.ObjectSetParentMethodInfo ResolveAudioClockMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo ResolveAudioClockMethod "setResolution" o = Gst.Clock.ClockSetResolutionMethodInfo ResolveAudioClockMethod "setSynced" o = Gst.Clock.ClockSetSyncedMethodInfo ResolveAudioClockMethod "setTimeout" o = Gst.Clock.ClockSetTimeoutMethodInfo ResolveAudioClockMethod l o = O.MethodResolutionFailed l o instance (info ~ ResolveAudioClockMethod t AudioClock, O.MethodInfo info AudioClock p) => OL.IsLabel t (AudioClock -> 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 AudioClock type instance O.AttributeList AudioClock = AudioClockAttributeList type AudioClockAttributeList = ('[ '("clockType", Gst.SystemClock.SystemClockClockTypePropertyInfo), '("name", Gst.Object.ObjectNamePropertyInfo), '("parent", Gst.Object.ObjectParentPropertyInfo), '("timeout", Gst.Clock.ClockTimeoutPropertyInfo), '("windowSize", Gst.Clock.ClockWindowSizePropertyInfo), '("windowThreshold", Gst.Clock.ClockWindowThresholdPropertyInfo)] :: [(Symbol, *)]) #endif #if ENABLE_OVERLOADING #endif #if ENABLE_OVERLOADING type instance O.SignalList AudioClock = AudioClockSignalList type AudioClockSignalList = ('[ '("deepNotify", Gst.Object.ObjectDeepNotifySignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo), '("synced", Gst.Clock.ClockSyncedSignalInfo)] :: [(Symbol, *)]) #endif -- method AudioClock::new -- method type : Constructor -- Args : [Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the clock", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "func", argType = TInterface (Name {namespace = "GstAudio", name = "AudioClockGetTimeFunc"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a function", sinceVersion = Nothing}, argScope = ScopeTypeNotified, argClosure = 2, argDestroy = 3, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "destroy_notify", argType = TInterface (Name {namespace = "GLib", name = "DestroyNotify"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "#GDestroyNotify for @user_data", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Just (TInterface (Name {namespace = "GstAudio", name = "AudioClock"})) -- throws : False -- Skip return : False foreign import ccall "gst_audio_clock_new" gst_audio_clock_new :: CString -> -- name : TBasicType TUTF8 FunPtr GstAudio.Callbacks.C_AudioClockGetTimeFunc -> -- func : TInterface (Name {namespace = "GstAudio", name = "AudioClockGetTimeFunc"}) Ptr () -> -- user_data : TBasicType TPtr FunPtr GLib.Callbacks.C_DestroyNotify -> -- destroy_notify : TInterface (Name {namespace = "GLib", name = "DestroyNotify"}) IO (Ptr AudioClock) {- | Create a new 'GI.GstAudio.Objects.AudioClock.AudioClock' instance. Whenever the clock time should be calculated it will call /@func@/ with /@userData@/. When /@func@/ returns 'GI.Gst.Constants.CLOCK_TIME_NONE', the clock will return the last reported time. -} audioClockNew :: (B.CallStack.HasCallStack, MonadIO m) => T.Text {- ^ /@name@/: the name of the clock -} -> GstAudio.Callbacks.AudioClockGetTimeFunc {- ^ /@func@/: a function -} -> m AudioClock {- ^ __Returns:__ a new 'GI.GstAudio.Objects.AudioClock.AudioClock' casted to a 'GI.Gst.Objects.Clock.Clock'. -} audioClockNew name func = liftIO $ do name' <- textToCString name func' <- GstAudio.Callbacks.mk_AudioClockGetTimeFunc (GstAudio.Callbacks.wrap_AudioClockGetTimeFunc Nothing (GstAudio.Callbacks.drop_closures_AudioClockGetTimeFunc func)) let userData = castFunPtrToPtr func' let destroyNotify = safeFreeFunPtrPtr result <- gst_audio_clock_new name' func' userData destroyNotify checkUnexpectedReturnNULL "audioClockNew" result result' <- (wrapObject AudioClock) result freeMem name' return result' #if ENABLE_OVERLOADING #endif -- method AudioClock::adjust -- method type : OrdinaryMethod -- Args : [Arg {argCName = "clock", argType = TInterface (Name {namespace = "GstAudio", name = "AudioClock"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioClock", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "time", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstClockTime", 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_audio_clock_adjust" gst_audio_clock_adjust :: Ptr AudioClock -> -- clock : TInterface (Name {namespace = "GstAudio", name = "AudioClock"}) Word64 -> -- time : TBasicType TUInt64 IO Word64 {- | Adjust /@time@/ with the internal offset of the audio clock. -} audioClockAdjust :: (B.CallStack.HasCallStack, MonadIO m, IsAudioClock a) => a {- ^ /@clock@/: a 'GI.GstAudio.Objects.AudioClock.AudioClock' -} -> Word64 {- ^ /@time@/: a @/GstClockTime/@ -} -> m Word64 {- ^ __Returns:__ /@time@/ adjusted with the internal offset. -} audioClockAdjust clock time = liftIO $ do clock' <- unsafeManagedPtrCastPtr clock result <- gst_audio_clock_adjust clock' time touchManagedPtr clock return result #if ENABLE_OVERLOADING data AudioClockAdjustMethodInfo instance (signature ~ (Word64 -> m Word64), MonadIO m, IsAudioClock a) => O.MethodInfo AudioClockAdjustMethodInfo a signature where overloadedMethod _ = audioClockAdjust #endif -- method AudioClock::get_time -- method type : OrdinaryMethod -- Args : [Arg {argCName = "clock", argType = TInterface (Name {namespace = "GstAudio", name = "AudioClock"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioClock", 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_audio_clock_get_time" gst_audio_clock_get_time :: Ptr AudioClock -> -- clock : TInterface (Name {namespace = "GstAudio", name = "AudioClock"}) IO Word64 {- | Report the time as returned by the 'GI.GstAudio.Callbacks.AudioClockGetTimeFunc' without applying any offsets. -} audioClockGetTime :: (B.CallStack.HasCallStack, MonadIO m, IsAudioClock a) => a {- ^ /@clock@/: a 'GI.GstAudio.Objects.AudioClock.AudioClock' -} -> m Word64 {- ^ __Returns:__ the time as reported by the time function of the audio clock -} audioClockGetTime clock = liftIO $ do clock' <- unsafeManagedPtrCastPtr clock result <- gst_audio_clock_get_time clock' touchManagedPtr clock return result #if ENABLE_OVERLOADING data AudioClockGetTimeMethodInfo instance (signature ~ (m Word64), MonadIO m, IsAudioClock a) => O.MethodInfo AudioClockGetTimeMethodInfo a signature where overloadedMethod _ = audioClockGetTime #endif -- method AudioClock::invalidate -- method type : OrdinaryMethod -- Args : [Arg {argCName = "clock", argType = TInterface (Name {namespace = "GstAudio", name = "AudioClock"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioClock", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "gst_audio_clock_invalidate" gst_audio_clock_invalidate :: Ptr AudioClock -> -- clock : TInterface (Name {namespace = "GstAudio", name = "AudioClock"}) IO () {- | Invalidate the clock function. Call this function when the provided 'GI.GstAudio.Callbacks.AudioClockGetTimeFunc' cannot be called anymore, for example, when the user_data becomes invalid. After calling this function, /@clock@/ will return the last returned time for the rest of its lifetime. -} audioClockInvalidate :: (B.CallStack.HasCallStack, MonadIO m, IsAudioClock a) => a {- ^ /@clock@/: a 'GI.GstAudio.Objects.AudioClock.AudioClock' -} -> m () audioClockInvalidate clock = liftIO $ do clock' <- unsafeManagedPtrCastPtr clock gst_audio_clock_invalidate clock' touchManagedPtr clock return () #if ENABLE_OVERLOADING data AudioClockInvalidateMethodInfo instance (signature ~ (m ()), MonadIO m, IsAudioClock a) => O.MethodInfo AudioClockInvalidateMethodInfo a signature where overloadedMethod _ = audioClockInvalidate #endif -- method AudioClock::reset -- method type : OrdinaryMethod -- Args : [Arg {argCName = "clock", argType = TInterface (Name {namespace = "GstAudio", name = "AudioClock"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioClock", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "time", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstClockTime", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "gst_audio_clock_reset" gst_audio_clock_reset :: Ptr AudioClock -> -- clock : TInterface (Name {namespace = "GstAudio", name = "AudioClock"}) Word64 -> -- time : TBasicType TUInt64 IO () {- | Inform /@clock@/ that future calls to 'GI.GstAudio.Callbacks.AudioClockGetTimeFunc' will return values starting from /@time@/. The clock will update an internal offset to make sure that future calls to internal_time will return an increasing result as required by the 'GI.Gst.Objects.Clock.Clock' object. -} audioClockReset :: (B.CallStack.HasCallStack, MonadIO m, IsAudioClock a) => a {- ^ /@clock@/: a 'GI.GstAudio.Objects.AudioClock.AudioClock' -} -> Word64 {- ^ /@time@/: a @/GstClockTime/@ -} -> m () audioClockReset clock time = liftIO $ do clock' <- unsafeManagedPtrCastPtr clock gst_audio_clock_reset clock' time touchManagedPtr clock return () #if ENABLE_OVERLOADING data AudioClockResetMethodInfo instance (signature ~ (Word64 -> m ()), MonadIO m, IsAudioClock a) => O.MethodInfo AudioClockResetMethodInfo a signature where overloadedMethod _ = audioClockReset #endif