 marshalCapsModify mkCaps (CapsM action) =
     unsafePerformIO $
         do ptr <- mkCaps
-           caps <- liftM Caps $ newForeignPtr_ ptr
-           result <- action caps
-           caps' <- takeCaps ptr
-           return (caps', result)
-
+           result <- runReaderT action ptr
+           caps <- takeCaps ptr
+           return (caps, result)
+
+-- | Create a caps and mutate it according to the given action.
 capsCreate :: CapsM a
            -> (Caps, a)
 capsCreate action =

--  available under LGPL Version 2. The documentation included with
--  this library is based on the original GStreamer documentation.
--  
-- | Maintainer  : gtk2hs-devel@lists.sourceforge.net
--   Stability   : alpha
--   Portability : portable (depends on GHC)
module Media.Streaming.GStreamer.Core.Caps (
  
  Caps,
  capsNone,
  capsAny,
  capsSize,
  capsGetStructure,
  capsIsEmpty,

        {# call caps_get_structure #} caps (fromIntegral index) >>=
            maybePeek peekStructure

-- | Returns a new 'Caps' containing only the 'Structure' at the given
--   index of the caps.
capsCopyNth :: Caps
            -> Word
            -> Maybe Caps
capsCopyNth caps index =
    unsafePerformIO $
        {# call caps_copy_nth #} caps (fromIntegral index) >>=
            maybePeek takeCaps

-- | Returns 'True' if the caps represents no media formats.
capsIsEmpty :: Caps
            -> Bool
capsIsEmpty caps =
    toBool $ unsafePerformIO $
        {# call caps_is_empty #} caps

-- | Returns 'True' if the caps is fixed.
capsIsFixed :: Caps
            -> Bool
capsIsFixed caps =
    toBool $ unsafePerformIO $
        {# call caps_is_fixed #} caps

-- | Returns 'True' if the caps represent the same set of capabilities.
capsIsEqual :: Caps
            -> Caps
            -> Bool
