// Copyright 2024 Martin Riedl // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package gomp4 import "encoding/binary" const ( boxSizeLength uint32 = 4 boxTypeLength uint32 = 4 // BoxTypeFileType File Type Box BoxTypeFileType = "ftyp" // BoxTypeMediaData Media Data Box BoxTypeMediaData = "mdat" // BoxTypeMovie Movie Box BoxTypeMovie = "moov" // BoxTypeMovieHeader Movie Header Box BoxTypeMovieHeader = "mvhd" // BoxTypeTrack Track Box BoxTypeTrack = "trak" // BoxTypeTrackHeader Track Header Box BoxTypeTrackHeader = "tkhd" // BoxTypeMedia Media Box BoxTypeMedia = "mdia" // BoxTypeMediaHeader Media Header Box BoxTypeMediaHeader = "mdhd" // BoxTypeHandlerReference Handler Reference Box BoxTypeHandlerReference = "hdlr" // BoxTypeMediaInformation Media Information Box BoxTypeMediaInformation = "minf" // BoxTypeDataInformation Data Information Box BoxTypeDataInformation = "dinf" // BoxTypeDataReferenceBox Data Reference Box BoxTypeDataReferenceBox = "dref" // BoxTypeDataEntryUrlBox Data Entry URL Box BoxTypeDataEntryUrlBox = "url " // BoxTypeDataEntryUrnBox Data Entry URN Box BoxTypeDataEntryUrnBox = "urn " // BoxTypeMovieFragment Movie Fragment Box BoxTypeMovieFragment = "moof" // BoxTypeMovieFragmentHeader Movie Fragment Header Box BoxTypeMovieFragmentHeader = "mfhd" // BoxTypeTrackFragment Track Fragment Box BoxTypeTrackFragment = "traf" // BoxTypeTrackFragmentHeader Track Fragment Header BoxTypeTrackFragmentHeader = "tfhd" // BoxTypeTrackFragmentRun Track Fragment Run Box BoxTypeTrackFragmentRun = "trun" // BoxTypeVideoMediaHeader Video Media Header Box BoxTypeVideoMediaHeader = "vmhd" ) // Box is an abstract box struct type Box struct { FilePosition uint64 HeaderSize uint32 } // FullBox is an abstract box type extending base box type FullBox struct { *Box Version uint8 Flag []byte flagUInt32 uint32 } // newFullBox parses based on 4 bytes data the version number (first byte) and the flags (bytes 2 - 4) func newFullBox(box *Box, data []byte) *FullBox { fullBox := &FullBox{Box: box, Version: data[0], Flag: data[1:4]} // build uint32 for flags (used for easier matching) flag4Bytes := append(make([]byte, 1), fullBox.Flag...) fullBox.flagUInt32 = binary.BigEndian.Uint32(flag4Bytes) // extend header size fullBox.HeaderSize = fullBox.HeaderSize + 4 return fullBox }