isobmff-builder-0.3.0.0: A (bytestring-) builder for the ISO-14496-12 base media file format

Safe HaskellNone
LanguageHaskell2010

Data.ByteString.IsoBaseFileFormat.Boxes.Box

Contents

Description

Definition of the most basic element in an ISOBMFF file: a box. See Chapter 4 in the standard document. A box is a container with a type, a size, some data and some nested boxes. The standard defines - among other characteristics - available box types and their semantics, the fields they contain and how they are nested into each other. This library tries to capture some of these characteristics using modern Haskell type system features, in order to provide compile time checks for (partial) standard compliance.

Synopsis

Basic Types and classes

class (IsBoxContent (BoxContent t), BoxRules t) => IsBoxType' t where Source #

Base class for all (abstractphantomnormal-) types that represent boxes

Minimal complete definition

toBoxType'

Associated Types

type BoxContent t Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

Instances

IsBoxType' * FileType Source # 

Associated Types

type BoxContent FileType (t :: FileType) :: * Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

IsBoxType' * MediaData Source # 

Associated Types

type BoxContent MediaData (t :: MediaData) :: * Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

IsBoxType' * ProgressiveDownload Source # 

Methods

toBoxType' :: proxy t -> BoxType Source #

IsBoxType' * Skip Source # 

Associated Types

type BoxContent Skip (t :: Skip) :: * Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

KnownNat version => IsBoxType' * (TrackHeader version) Source # 

Associated Types

type BoxContent (TrackHeader version) (t :: TrackHeader version) :: * Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

IsBoxType' * (Track version) Source # 

Associated Types

type BoxContent (Track version) (t :: Track version) :: * Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

KnownNat version => IsBoxType' * (MovieHeader version) Source # 

Associated Types

type BoxContent (MovieHeader version) (t :: MovieHeader version) :: * Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

IsBoxType' * (Movie version) Source # 

Associated Types

type BoxContent (Movie version) (t :: Movie version) :: * Source #

Methods

toBoxType' :: proxy t -> BoxType Source #

class BoxRules t Source #

A class that describes (on the type level) how a box can be nested into other boxes (see 'Boxes).

Associated Types

type RestrictedTo t :: Maybe [k] Source #

List of boxes that this box can be nested into.

type IsTopLevelBox t :: Bool Source #

If the box is also allowed 'top-level' i.e. in the file directly, not nested in an other box.

type RequiredNestedBoxes t :: [k] Source #

Describes which nested boxes MUST be present in a box using boxes.

type GetCardinality t (c :: k) :: Cardinality Source #

Describes how many times a box should be present in a container (-box).

Instances

BoxRules * FileType Source #

File Type Box

BoxRules * MediaData Source # 
BoxRules * ProgressiveDownload Source # 
BoxRules * Skip Source # 

Associated Types

type RestrictedTo Skip (t :: Skip) :: Maybe [k] Source #

type IsTopLevelBox Skip (t :: Skip) :: Bool Source #

type RequiredNestedBoxes Skip (t :: Skip) :: [k] Source #

type GetCardinality Skip (t :: Skip) (c :: Skip) :: Cardinality Source #

BoxRules * (TrackHeader version) Source # 

Associated Types

type RestrictedTo (TrackHeader version) (t :: TrackHeader version) :: Maybe [k] Source #

type IsTopLevelBox (TrackHeader version) (t :: TrackHeader version) :: Bool Source #

type RequiredNestedBoxes (TrackHeader version) (t :: TrackHeader version) :: [k] Source #

type GetCardinality (TrackHeader version) (t :: TrackHeader version) (c :: TrackHeader version) :: Cardinality Source #

BoxRules * (Track version) Source # 

Associated Types

type RestrictedTo (Track version) (t :: Track version) :: Maybe [k] Source #

type IsTopLevelBox (Track version) (t :: Track version) :: Bool Source #

type RequiredNestedBoxes (Track version) (t :: Track version) :: [k] Source #

type GetCardinality (Track version) (t :: Track version) (c :: Track version) :: Cardinality Source #

BoxRules * (MovieHeader version) Source # 

Associated Types

type RestrictedTo (MovieHeader version) (t :: MovieHeader version) :: Maybe [k] Source #

type IsTopLevelBox (MovieHeader version) (t :: MovieHeader version) :: Bool Source #

type RequiredNestedBoxes (MovieHeader version) (t :: MovieHeader version) :: [k] Source #

type GetCardinality (MovieHeader version) (t :: MovieHeader version) (c :: MovieHeader version) :: Cardinality Source #

BoxRules * (Movie version) Source # 

Associated Types

type RestrictedTo (Movie version) (t :: Movie version) :: Maybe [k] Source #

type IsTopLevelBox (Movie version) (t :: Movie version) :: Bool Source #

type RequiredNestedBoxes (Movie version) (t :: Movie version) :: [k] Source #

type GetCardinality (Movie version) (t :: Movie version) (c :: Movie version) :: Cardinality Source #

data Cardinality Source #

Describes how many times a box should be present in a container.

class IsBoxContent a where Source #

Types that go into a box. A box content is a piece of data that can be reused in different instances of IsBox. It has no BoxType and hence defines no box.

Minimal complete definition

boxSize, boxBuilder

Instances

IsBoxContent () Source #

An empty box content can by represented by () (i.e. unit).

Methods

boxSize :: () -> BoxSize Source #

boxBuilder :: () -> Builder Source #

IsBoxContent ByteString Source #

Trivial instance for ByteString

IsBoxContent BoxTypeExtension Source # 
IsBoxContent FourCc Source # 
IsBoxContent BoxType Source # 
IsBoxContent BoxSizeExtension Source # 
IsBoxContent BoxSize Source # 
IsBoxContent FileType Source # 
IsBoxContent Skip Source # 
IsBoxContent (TrackHeader version) Source # 
IsBoxContent (MovieHeader version) Source # 
IsBoxContent (Boxes k bs) Source # 

Methods

boxSize :: Boxes k bs -> BoxSize Source #

boxBuilder :: Boxes k bs -> Builder Source #

IsBoxContent (Box' k cnt) Source # 

Methods

boxSize :: Box' k cnt -> BoxSize Source #

boxBuilder :: Box' k cnt -> Builder Source #

(IsBoxContent p, IsBoxContent c) => IsBoxContent (Extend p c) Source # 
KnownNat bits => IsBoxContent (BoxFlags Nat bits) Source #

Get the number of bytes required to store a number of bits.

(IsBoxContent o, FromTypeLit k o v) => IsBoxContent (Template k o v) Source # 
IsBoxContent (Scalar k Int64 label) Source # 

Methods

boxSize :: Scalar k Int64 label -> BoxSize Source #

boxBuilder :: Scalar k Int64 label -> Builder Source #

IsBoxContent (Scalar k Int32 label) Source # 

Methods

boxSize :: Scalar k Int32 label -> BoxSize Source #

boxBuilder :: Scalar k Int32 label -> Builder Source #

IsBoxContent (Scalar k Int16 label) Source # 

Methods

boxSize :: Scalar k Int16 label -> BoxSize Source #

boxBuilder :: Scalar k Int16 label -> Builder Source #

IsBoxContent (Scalar k Int8 label) Source # 

Methods

boxSize :: Scalar k Int8 label -> BoxSize Source #

boxBuilder :: Scalar k Int8 label -> Builder Source #

IsBoxContent (Scalar k Word64 label) Source # 
IsBoxContent (Scalar k Word32 label) Source # 
IsBoxContent (Scalar k Word16 label) Source # 
IsBoxContent (Scalar k Word8 label) Source # 

Methods

boxSize :: Scalar k Word8 label -> BoxSize Source #

boxBuilder :: Scalar k Word8 label -> Builder Source #

IsBoxContent (Versioned v0 v1 version) Source # 

Methods

boxSize :: Versioned v0 v1 version -> BoxSize Source #

boxBuilder :: Versioned v0 v1 version -> Builder Source #

(KnownNat version, IsBoxContent t) => IsBoxContent (FullBox Nat version t) Source # 

Methods

boxSize :: FullBox Nat version t -> BoxSize Source #

boxBuilder :: FullBox Nat version t -> Builder Source #

(IsBoxContent o, FromTypeLit k o v) => IsBoxContent (Constant k * o v) Source # 
(Num o, IsBoxContent (Scalar k o label), KnownNat len) => IsBoxContent (ScalarArray k label len o) Source # 

Methods

boxSize :: ScalarArray k label len o -> BoxSize Source #

boxBuilder :: ScalarArray k label len o -> Builder Source #

Data types

data Box' b where Source #

A type that wraps the contents of a box and the box type.

Constructors

Box' :: (IsBoxType' b, ValidBoxes b ts) => BoxContent b -> Boxes ts -> Box' b 

Instances

IsBoxContent (Box' k cnt) Source # 

Methods

boxSize :: Box' k cnt -> BoxSize Source #

boxBuilder :: Box' k cnt -> Builder Source #

data Boxes boxTypes where Source #

A heterogenous collection of boxes.

Constructors

Nested :: Boxes '[] 
(:.) :: Boxes ts -> Box' t -> Boxes (t ': ts) infixl 2 

Instances

closedBox :: (IsBoxType' t, ValidBoxes t '[]) => BoxContent t -> Box' t Source #

A box that contains no nested boxes.

containerBox :: (IsBoxType' t, ValidBoxes t ts, BoxContent t ~ ()) => Boxes ts -> Box' t Source #

A box that contains no fields, but nested boxes.

mediaFile :: Boxes ts -> Builder Source #

A complete media file, consisting of top-level boxes.

Box Size and Type

data BoxSize Source #

The size of the box. If the size is limited to a (fixed) value, it can be provided as a Word64 which will be represented as either a 32bit compact size or as 64 bit largesize. If UnlimitedSize is used, the box extends to the end of the file.

data BoxSizeExtension Source #

The BoxSize can be > 2^32 in which case an BoxSizeExtension must be added after the type field.

data BoxType Source #

A box has a type, this is the value level representation for the box type.

Constructors

StdType FourCc

FourCc can be used as boxType in Box, standard four letter character code, e.g. ftyp

CustomBoxType String

CustomBoxType defines custom boxTypes in Boxes.

newtype FourCc Source #

A type containin a printable four letter character code.

Constructors

FourCc (Char, Char, Char, Char) 

data BoxTypeExtension Source #

When using custom types extra data must be written after the extra size information. Since the box type and the optional custom box type are not guaranteed to be consequtive, this type handles the second part seperately.

Type-safe box composition

Type level consistency checks

type ValidBoxes t ts = (AllAllowedIn t ts ~ True, HasAllRequiredBoxes t (RequiredNestedBoxes t) ts ~ True) Source #

A type-level check that uses BoxRules to check that the contained boxes are standard conform.

type family AllAllowedIn (container :: k) (boxes :: [k]) :: Bool where ... Source #

A type function to check that all nested boxes are allowed in the container.

Equations

AllAllowedIn c '[] = True 
AllAllowedIn c (t ': ts) = If (CheckAllowedIn c t (RestrictedTo t)) (AllAllowedIn c ts) (TypeError (NotAllowedMsg c t)) 

type family CheckAllowedIn (c :: k) (t :: k) (a :: Maybe [k]) :: Bool where ... Source #

Equations

CheckAllowedIn c t Nothing = True 
CheckAllowedIn c t (Just rs) = Find c rs 

type NotAllowedMsg c t = (((((Text "Boxes of type: " :<>: ShowType c) :<>: Text " may not contain boxes of type ") :<>: ShowType t) :$$: ((Text "Valid containers for " :<>: ShowType t) :<>: Text " boxes are: ")) :$$: ShowType (RestrictedTo t)) :$$: (ShowType t :<>: If (IsTopLevelBox c) (Text " boxes may appear top-level in a file.") (Text " boxes must be nested.")) Source #

The custom (type-) error message for AllAllowedIn.

type family HasAllRequiredBoxes (c :: k) (req :: [k]) (nested :: [k]) :: Bool where ... Source #

Check that all required boxes have been nested.

Equations

HasAllRequiredBoxes c '[] nested = True 
HasAllRequiredBoxes c (r ': restReq) nested = If (Find r nested) (HasAllRequiredBoxes c restReq nested) (TypeError (MissingRequired c r nested)) 

type IsSubSet base sub = Intersection base sub == sub Source #

type MissingRequired c r nested = ((((Text "Boxes of type: " :<>: ShowType c) :<>: Text " require these nested boxes: ") :<>: ShowType (RequiredNestedBoxes c)) :$$: (Text "but only these box types were nested: " :<>: ShowType nested)) :$$: (Text "e.g. this type is missing: " :<>: ShowType r) Source #

The custom (type-) error message for 'HasAllRequiredBoxes.

type family CheckAllTopLevelOk (ts :: [k]) :: Bool where ... Source #

Check that all boxes may appear top-level.

type family CheckTopLevelOk (t :: k) :: Bool where ... Source #

Check that the box may appear top-level.

type NotTopLevenError c = ((Text "Boxes of type " :<>: ShowType c) :<>: Text " MUST be nested inside boxes of these types: ") :$$: ShowType (RestrictedTo c) Source #

The custom (type-) error message indicating that a box may not appear top-level.

IsBoxContent instances