<commit_before>{-# LANGUAGE UndecidableInstances #-}
-- | @mp4a@ Audio sample entry according to ISO 14496-14
module Data.ByteString.Mp4.Boxes.Mp4AudioSampleEntry where

import           Data.ByteString.IsoBaseFileFormat.Box
import           Data.ByteString.IsoBaseFileFormat.Boxes
import           Data.ByteString.IsoBaseFileFormat.Util.BoxFields
import           Data.ByteString.IsoBaseFileFormat.ReExports
import           Data.ByteString.Mp4.Boxes.BaseDescriptor
import           Data.ByteString.Mp4.Boxes.ElementaryStreamDescriptor
import           Data.ByteString.Mp4.Boxes.DecoderSpecificInfo
import           Data.ByteString.Mp4.Boxes.DecoderConfigDescriptor
import           Data.ByteString.Mp4.Boxes.AudioSpecificConfig

-- | A /body/ for 'AudioSampleEntry'. This 'IsBoxContent' with an
-- 'ElementaryStreamDescriptor' for ISO-14496-3 audio, with audio decoder
-- specific info.

-- | Create an 'AudioSampleEntry' with an 'AudioEsd'
--
-- TODO generalize this, allow all parameters,e.g. also for SBR though the
audioSampleEntry
  :: AudioSampleEntry ()
  -> AudioEsd
  -> AudioSampleEntry (Box AudioEsd)
audioSampleEntry ase eds = const (Box eds) <$> ase

-- | Create an mp4 audio elementary stream descriptor full box
-- audioEsd
--  :: Tagged "esId" Word16 -> Tagged "streamPriority" Word64 -> AudioEsd
-- audioEsd = runHoley $ hoistR AudioEsd $ bitBoxHoley $ Proxy @ESDescriptorSimple

-- | Consists of an 'ElementaryStreamDescriptor' derived from a 'DecoderSpecificInfo'.
newtype AudioEsd =
  AudioEsd (EsdBox (Mp4AudioEsDescriptor Mp4AacLcAudioDecoderConfigDescriptor))
  deriving (IsBoxContent)

instance IsBox AudioEsd
type instance BoxTypeSymbol AudioEsd = "mp4a"

type Mp4AudioEsDescriptor di =
  (ESDescriptorMp4File
    (DecoderConfigDescriptor
     'AudioIso14496_3
     'AudioStream
     '[Eval di]
     '[]))

type Mp4AacLcAudioDecoderConfigDescriptor =
  DecoderConfigDescriptor
   'AudioIso14496_3
   'AudioStream
  '[Eval (NonSbrAudioConfig
          (GASpecificConfig 'AacLc 'False 'Nothing 'Nothing)
          (SetEnum SamplingFreq 'SF88200)
          (SetEnum ChannelConfig 'GasChannelConfig))]
  '[]

-- ** EsdBox

newtype EsdBox (d :: Descriptor 'ES_Descr) where
  EsdBox :: BitBox d -> EsdBox d

deriving instance KnownNat (BitRecordSize (ToBitRecord d))
  => IsBoxContent (EsdBox d)


-- -- TODO rename project

-- -- TODO seperate this and other modules so theres the same seperation as in between
-- -- the parts of the standard.
-- esDescriptorBitBox
--   :: forall (di :: IsA (Descriptor 'DecoderConfigDescr)) .
--     (BitStringBuilderHoley (Proxy (ESDescriptorMp4File di)) (BitBox (ESDescriptorMp4File di)))
--   => Proxy di
--   -> ToBitStringBuilder (Proxy (ESDescriptorMp4File di)) (BitBox (ESDescriptorMp4File di))
-- esDescriptorBitBox _ =
--   bitBoxWithArgs (Proxy @(ESDescriptorMp4File di))


{-
 :kind! (Eval (NonSbrAudioConfig<commit_msg>WIP Esdbox<commit_after>{-# LANGUAGE UndecidableInstances #-}
-- | @mp4a@ Audio sample entry according to ISO 14496-14
module Data.ByteString.Mp4.Boxes.Mp4AudioSampleEntry where

import           Data.ByteString.IsoBaseFileFormat.Box
import           Data.ByteString.IsoBaseFileFormat.Boxes
import           Data.ByteString.IsoBaseFileFormat.Util.BoxFields
import           Data.ByteString.IsoBaseFileFormat.ReExports
import           Data.ByteString.Mp4.Boxes.BaseDescriptor
import           Data.ByteString.Mp4.Boxes.ElementaryStreamDescriptor
import           Data.ByteString.Mp4.Boxes.DecoderSpecificInfo
import           Data.ByteString.Mp4.Boxes.DecoderConfigDescriptor
import           Data.ByteString.Mp4.Boxes.AudioSpecificConfig

-- | A /body/ for 'AudioSampleEntry'. This 'IsBoxContent' with an
-- 'ElementaryStreamDescriptor' for ISO-14496-3 audio, with audio decoder
-- specific info.

-- | Create an 'AudioSampleEntry' with an 'AudioEsd'
--
-- TODO generalize this, allow all parameters,e.g. also for SBR though the
audioSampleEntry
  :: AudioSampleEntry ()
  -> AudioEsd
  -> AudioSampleEntry (Box AudioEsd)
audioSampleEntry ase eds = const (Box eds) <$> ase

-- | Create an mp4 audio elementary stream descriptor full box
-- audioEsd
--  :: Tagged "esId" Word16 -> Tagged "streamPriority" Word64 -> AudioEsd
-- audioEsd = runHoley $ hoistR AudioEsd $ bitBoxHoley $ Proxy @ESDescriptorSimple

-- | Consists of an 'ElementaryStreamDescriptor' derived from a 'DecoderSpecificInfo'.
newtype AudioEsd =
  AudioEsd (EsdBox Mp4AudioEsDescriptor)
  deriving (IsBoxContent)

instance IsBox AudioEsd
type instance BoxTypeSymbol AudioEsd = "mp4a"

type Mp4AudioEsDescriptor = (ESDescriptorMp4File Mp4AacLcAudioDecoderConfigDescriptor)

type Mp4AacLcAudioDecoderConfigDescriptor =
  DecoderConfigDescriptor
   'AudioIso14496_3
   'AudioStream
  '[Eval (NonSbrAudioConfig
          (GASpecificConfig 'AacLc 'False 'Nothing 'Nothing)
          (SetEnum SamplingFreq 'SF88200)
          (SetEnum ChannelConfig 'GasChannelConfig))]
  '[]

-- ** EsdBox

newtype EsdBox (d :: IsA (Descriptor 'ES_Descr)) where
  EsdBox :: BitBox d -> EsdBox d

deriving instance KnownNat (BitRecordSize (ToBitRecord d))
  => IsBoxContent (EsdBox d)


-- -- TODO rename project

-- -- TODO seperate this and other modules so theres the same seperation as in between
-- -- the parts of the standard.
-- esDescriptorBitBox
--   :: forall (di :: IsA (Descriptor 'DecoderConfigDescr)) .
--     (BitStringBuilderHoley (Proxy (ESDescriptorMp4File di)) (BitBox (ESDescriptorMp4File di)))
--   => Proxy di
--   -> ToBitStringBuilder (Proxy (ESDescriptorMp4File di)) (BitBox (ESDescriptorMp4File di))
-- esDescriptorBitBox _ =
--   bitBoxWithArgs (Proxy @(ESDescriptorMp4File di))


{-
 :kind! (Eval (NonSbrAudioConfig
{'fraction_non_alphanumeric': 0.09441606482296988, 'fraction_numerical': 0.01796723621631143, 'mean_word_length': 3.836456558773424, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6197491', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1784, 'n_words': 449}