shithub: mcfs

ref: aad9511a85b15ced2fde315c693ce12a05f1f315
dir: /elem.c/

View raw version
#include <u.h>
#include <libc.h>
#include "elem.h"

static Element els[] = {
	{EChapterDisplay, "ChapterDisplay", Emaster},
	{ETrackType, "TrackType", Eunsigned},
	{EChapString, "ChapString", Eunicode},
	{ECodecID, "CodecID", Esigned},
	{EFlagDefault, "FlagDefault", Eunsigned},
	{EChapterTrackUID, "ChapterTrackUID", Eunsigned},
	{ESlices, "Slices", Emaster},
	{EChapterTrack, "ChapterTrack", Emaster},
	{EChapterTimeStart, "ChapterTimeStart", Eunsigned},
	{EChapterTimeEnd, "ChapterTimeEnd", Eunsigned},
	{ECueRefTime, "CueRefTime", Eunsigned},
	{ECueRefCluster, "CueRefCluster", Eunsigned},
	{EChapterFlagHidden, "ChapterFlagHidden", Eunsigned},
	{EFlagInterlaced, "FlagInterlaced", Eunsigned},
	{EBlockDuration, "BlockDuration", Eunsigned},
	{EFlagLacing, "FlagLacing", Eunsigned},
	{EFieldOrder, "FieldOrder", Eunsigned},
	{EChannels, "Channels", Eunsigned},
	{EBlockGroup, "BlockGroup", Emaster},
	{EBlock, "Block", Ebinary},
	{EBlockVirtual, "BlockVirtual", Ebinary},
	{ESimpleBlock, "SimpleBlock", Ebinary},
	{ECodecState, "CodecState", Ebinary},
	{EBlockAdditional, "BlockAdditional", Ebinary},
	{EBlockMore, "BlockMore", Emaster},
	{EPosition, "Position", Eunsigned},
	{ECodecDecodeAll, "CodecDecodeAll", Eunsigned},
	{EPrevSize, "PrevSize", Eunsigned},
	{ETrackEntry, "TrackEntry", Emaster},
	{EEncryptedBlock, "EncryptedBlock", Ebinary},
	{EPixelWidth, "PixelWidth", Eunsigned},
	{ECueDuration, "CueDuration", Eunsigned},
	{ECueTime, "CueTime", Eunsigned},
	{ESamplingFrequency, "SamplingFrequency", Efloat},
	{EChapterAtom, "ChapterAtom", Emaster},
	{ECueTrackPositions, "CueTrackPositions", Emaster},
	{EFlagEnabled, "FlagEnabled", Eunsigned},
	{EPixelHeight, "PixelHeight", Eunsigned},
	{ECuePoint, "CuePoint", Emaster},
	{ECRC32, "CRC-32", Ebinary},
	{EReferenceFrame, "ReferenceFrame", Emaster},
	{EReferenceOffset, "ReferenceOffset", Eunsigned},
	{EReferenceTimestamp, "ReferenceTimestamp", Eunsigned},
	{EBlockAdditionID, "BlockAdditionID", Eunsigned},
	{ELaceNumber, "LaceNumber", Eunsigned},
	{EFrameNumber, "FrameNumber", Eunsigned},
	{EDelay, "Delay", Eunsigned},
	{ESliceDuration, "SliceDuration", Eunsigned},
	{ETrackNumber, "TrackNumber", Eunsigned},
	{ECueReference, "CueReference", Emaster},
	{EVideo, "Video", Emaster},
	{EAudio, "Audio", Emaster},
	{ETrackOperation, "TrackOperation", Emaster},
	{ETrackCombinePlanes, "TrackCombinePlanes", Emaster},
	{ETrackPlane, "TrackPlane", Emaster},
	{ETrackPlaneUID, "TrackPlaneUID", Eunsigned},
	{ETrackPlaneType, "TrackPlaneType", Eunsigned},
	{ETimestamp, "Timestamp", Eunsigned},
	{ETimeSlice, "TimeSlice", Emaster},
	{ETrackJoinBlocks, "TrackJoinBlocks", Emaster},
	{ECueCodecState, "CueCodecState", Eunsigned},
	{ECueRefCodecState, "CueRefCodecState", Eunsigned},
	{EVoid, "Void", Ebinary},
	{ETrackJoinUID, "TrackJoinUID", Eunsigned},
	{EBlockAddID, "BlockAddID", Eunsigned},
	{ECueRelativePosition, "CueRelativePosition", Eunsigned},
	{ECueClusterPosition, "CueClusterPosition", Eunsigned},
	{ECueTrack, "CueTrack", Eunsigned},
	{EReferencePriority, "ReferencePriority", Eunsigned},
	{EReferenceBlock, "ReferenceBlock", Esigned},
	{EReferenceVirtual, "ReferenceVirtual", Esigned},
	{EBlockAddIDName, "BlockAddIDName", Eascii},
	{EBlockAdditionMapping, "BlockAdditionMapping", Emaster},
	{EBlockAddIDType, "BlockAddIDType", Eunsigned},
	{EBlockAddIDExtraData, "BlockAddIDExtraData", Ebinary},
	{EBlockAddIDValue, "BlockAddIDValue", Eunsigned},
	{EContentCompAlgo, "ContentCompAlgo", Eunsigned},
	{EContentCompSettings, "ContentCompSettings", Ebinary},
	{EDocTypeExtension, "DocTypeExtension", Emaster},
	{EDocType, "DocType", Eascii},
	{EDocTypeExtensionName, "DocTypeExtensionName", Eascii},
	{EDocTypeExtensionVersion, "DocTypeExtensionVersion", Eunsigned},
	{EDocTypeReadVersion, "DocTypeReadVersion", Eunsigned},
	{EEBMLVersion, "EBMLVersion", Eunsigned},
	{EDocTypeVersion, "DocTypeVersion", Eunsigned},
	{EEBMLMaxIDLength, "EBMLMaxIDLength", Eunsigned},
	{EEBMLMaxSizeLength, "EBMLMaxSizeLength", Eunsigned},
	{EEBMLReadVersion, "EBMLReadVersion", Eunsigned},
	{EChapLanguage, "ChapLanguage", Eascii},
	{EChapLanguageIETF, "ChapLanguageIETF", Eascii},
	{EChapCountry, "ChapCountry", Eascii},
	{ESegmentFamily, "SegmentFamily", Ebinary},
	{EDateUTC, "DateUTC", Etimestamp},
	{ETagLanguage, "TagLanguage", Eascii},
	{ETagLanguageIETF, "TagLanguageIETF", Eascii},
	{ETagDefault, "TagDefault", Eunsigned},
	{ETagBinary, "TagBinary", Ebinary},
	{ETagString, "TagString", Eunicode},
	{EDuration, "Duration", Efloat},
	{EChapProcessPrivate, "ChapProcessPrivate", Ebinary},
	{EChapterFlagEnabled, "ChapterFlagEnabled", Eunsigned},
	{ETagName, "TagName", Eunicode},
	{EEditionEntry, "EditionEntry", Emaster},
	{EEditionUID, "EditionUID", Eunsigned},
	{EEditionFlagHidden, "EditionFlagHidden", Eunsigned},
	{EEditionFlagDefault, "EditionFlagDefault", Eunsigned},
	{EEditionFlagOrdered, "EditionFlagOrdered", Eunsigned},
	{EFileData, "FileData", Ebinary},
	{EFileMimeType, "FileMimeType", Eascii},
	{EFileUsedStartTime, "FileUsedStartTime", Eunsigned},
	{EFileUsedEndTime, "FileUsedEndTime", Eunsigned},
	{EFileName, "FileName", Eunicode},
	{EFileReferral, "FileReferral", Ebinary},
	{EFileDescription, "FileDescription", Eunicode},
	{EFileUID, "FileUID", Eunsigned},
	{EContentEncAlgo, "ContentEncAlgo", Eunsigned},
	{EContentEncKeyID, "ContentEncKeyID", Ebinary},
	{EContentSignature, "ContentSignature", Ebinary},
	{EContentSigKeyID, "ContentSigKeyID", Ebinary},
	{EContentSigAlgo, "ContentSigAlgo", Eunsigned},
	{EContentSigHashAlgo, "ContentSigHashAlgo", Eunsigned},
	{EContentAESSettings, "ContentAESSettings", Emaster},
	{EAESSettingsCipherMode, "AESSettingsCipherMode", Eunsigned},
	{EMuxingApp, "MuxingApp", Eunicode},
	{ESeek, "Seek", Emaster},
	{EContentEncodingOrder, "ContentEncodingOrder", Eunsigned},
	{EContentEncodingScope, "ContentEncodingScope", Eunsigned},
	{EContentEncodingType, "ContentEncodingType", Eunsigned},
	{EContentCompression, "ContentCompression", Emaster},
	{EContentEncryption, "ContentEncryption", Emaster},
	{ECueRefNumber, "CueRefNumber", Eunsigned},
	{EName, "Name", Eunicode},
	{ECueBlockNumber, "CueBlockNumber", Eunsigned},
	{ETrackOffset, "TrackOffset", Esigned},
	{ESeekID, "SeekID", Ebinary},
	{ESeekPosition, "SeekPosition", Eunsigned},
	{EStereoMode, "StereoMode", Eunsigned},
	{EOldStereoMode, "OldStereoMode", Eunsigned},
	{EAlphaMode, "AlphaMode", Eunsigned},
	{EPixelCropBottom, "PixelCropBottom", Eunsigned},
	{EDisplayWidth, "DisplayWidth", Eunsigned},
	{EDisplayUnit, "DisplayUnit", Eunsigned},
	{EAspectRatioType, "AspectRatioType", Eunsigned},
	{EDisplayHeight, "DisplayHeight", Eunsigned},
	{EPixelCropTop, "PixelCropTop", Eunsigned},
	{EPixelCropLeft, "PixelCropLeft", Eunsigned},
	{EPixelCropRight, "PixelCropRight", Eunsigned},
	{EFlagForced, "FlagForced", Eunsigned},
	{EColour, "Colour", Emaster},
	{EMatrixCoefficients, "MatrixCoefficients", Eunsigned},
	{EBitsPerChannel, "BitsPerChannel", Eunsigned},
	{EChromaSubsamplingHorz, "ChromaSubsamplingHorz", Eunsigned},
	{EChromaSubsamplingVert, "ChromaSubsamplingVert", Eunsigned},
	{ECbSubSamplingHorz, "CbSubSamplingHorz", Eunsigned},
	{ECbSubSamplingVert, "CbSubSamplingVert", Eunsigned},
	{EChromaSitingHorz, "ChromaSitingHorz", Eunsigned},
	{EChromaSitingVert, "ChromaSitingVert", Eunsigned},
	{ERange, "Range", Eunsigned},
	{ETransferCharacteristics, "TransferCharacteristics", Eunsigned},
	{EPrimaries, "Primaries", Eunsigned},
	{EMaxCLL, "MaxCLL", Eunsigned},
	{EMaxFALL, "MaxFALL", Eunsigned},
	{EMasteringMetadata, "MasteringMetadata", Emaster},
	{EPrimaryRChromaticityX, "PrimaryRChromaticityX", Efloat},
	{EPrimaryRChromaticityY, "PrimaryRChromaticityY", Efloat},
	{EPrimaryGChromaticityX, "PrimaryGChromaticityX", Efloat},
	{EPrimaryGChromaticityY, "PrimaryGChromaticityY", Efloat},
	{EPrimaryBChromaticityX, "PrimaryBChromaticityX", Efloat},
	{EPrimaryBChromaticityY, "PrimaryBChromaticityY", Efloat},
	{EWhitePointChromaticityX, "WhitePointChromaticityX", Efloat},
	{EWhitePointChromaticityY, "WhitePointChromaticityY", Efloat},
	{ELuminanceMax, "LuminanceMax", Efloat},
	{ELuminanceMin, "LuminanceMin", Efloat},
	{EMaxBlockAdditionID, "MaxBlockAdditionID", Eunsigned},
	{EChapterStringUID, "ChapterStringUID", Eunicode},
	{ECodecDelay, "CodecDelay", Eunsigned},
	{ESeekPreRoll, "SeekPreRoll", Eunsigned},
	{EWritingApp, "WritingApp", Eunicode},
	{ESilentTracks, "SilentTracks", Emaster},
	{ESilentTrackNumber, "SilentTrackNumber", Eunsigned},
	{EAttachedFile, "AttachedFile", Emaster},
	{EContentEncoding, "ContentEncoding", Emaster},
	{EBitDepth, "BitDepth", Eunsigned},
	{ECodecPrivate, "CodecPrivate", Ebinary},
	{ETargets, "Targets", Emaster},
	{EChapterPhysicalEquiv, "ChapterPhysicalEquiv", Eunsigned},
	{ETagChapterUID, "TagChapterUID", Eunsigned},
	{ETagTrackUID, "TagTrackUID", Eunsigned},
	{ETagAttachmentUID, "TagAttachmentUID", Eunsigned},
	{ETagEditionUID, "TagEditionUID", Eunsigned},
	{ETargetType, "TargetType", Eascii},
	{ETrackTranslate, "TrackTranslate", Emaster},
	{ETrackTranslateTrackID, "TrackTranslateTrackID", Ebinary},
	{ETrackTranslateCodec, "TrackTranslateCodec", Eunsigned},
	{ETrackTranslateEditionUID, "TrackTranslateEditionUID", Eunsigned},
	{ESimpleTag, "SimpleTag", Emaster},
	{ETargetTypeValue, "TargetTypeValue", Eunsigned},
	{EChapProcessCommand, "ChapProcessCommand", Emaster},
	{EChapProcessTime, "ChapProcessTime", Eunsigned},
	{EChapterTranslate, "ChapterTranslate", Emaster},
	{EChapProcessData, "ChapProcessData", Ebinary},
	{EChapProcess, "ChapProcess", Emaster},
	{EChapProcessCodecID, "ChapProcessCodecID", Eunsigned},
	{EChapterTranslateID, "ChapterTranslateID", Ebinary},
	{EChapterTranslateCodec, "ChapterTranslateCodec", Eunsigned},
	{EChapterTranslateEditionUID, "ChapterTranslateEditionUID", Eunsigned},
	{EContentEncodings, "ContentEncodings", Emaster},
	{EMinCache, "MinCache", Eunsigned},
	{EMaxCache, "MaxCache", Eunsigned},
	{EChapterSegmentUID, "ChapterSegmentUID", Ebinary},
	{EChapterSegmentEditionUID, "ChapterSegmentEditionUID", Eunsigned},
	{ETrackOverlay, "TrackOverlay", Eunsigned},
	{ETag, "Tag", Emaster},
	{ESegmentFilename, "SegmentFilename", Eunicode},
	{ESegmentUID, "SegmentUID", Ebinary},
	{EChapterUID, "ChapterUID", Eunsigned},
	{ETrackUID, "TrackUID", Eunsigned},
	{EAttachmentLink, "AttachmentLink", Eunsigned},
	{EBlockAdditions, "BlockAdditions", Emaster},
	{EDiscardPadding, "DiscardPadding", Esigned},
	{EProjection, "Projection", Emaster},
	{EProjectionType, "ProjectionType", Eunsigned},
	{EProjectionPrivate, "ProjectionPrivate", Ebinary},
	{EProjectionPoseYaw, "ProjectionPoseYaw", Efloat},
	{EProjectionPosePitch, "ProjectionPosePitch", Efloat},
	{EProjectionPoseRoll, "ProjectionPoseRoll", Efloat},
	{EOutputSamplingFrequency, "OutputSamplingFrequency", Efloat},
	{ETitle, "Title", Eunicode},
	{EChannelPositions, "ChannelPositions", Ebinary},
	{ELanguage, "Language", Eascii},
	{ELanguageIETF, "LanguageIETF", Esigned},
	{ETrackTimestampScale, "TrackTimestampScale", Efloat},
	{EDefaultDecodedFieldDuration, "DefaultDecodedFieldDuration", Eunsigned},
	{EFrameRate, "FrameRate", Efloat},
	{EDefaultDuration, "DefaultDuration", Eunsigned},
	{ECodecName, "CodecName", Eunicode},
	{ECodecDownloadURL, "CodecDownloadURL", Eascii},
	{ETimestampScale, "TimestampScale", Eunsigned},
	{EColourSpace, "ColourSpace", Ebinary},
	{EGammaValue, "GammaValue", Efloat},
	{ECodecSettings, "CodecSettings", Eunicode},
	{ECodecInfoURL, "CodecInfoURL", Eascii},
	{EPrevFilename, "PrevFilename", Eunicode},
	{EPrevUID, "PrevUID", Ebinary},
	{ENextFilename, "NextFilename", Eunicode},
	{ENextUID, "NextUID", Ebinary},
	{EChapters, "Chapters", Emaster},
	{ESeekHead, "SeekHead", Emaster},
	{ETags, "Tags", Emaster},
	{EInfo, "Info", Emaster},
	{ETracks, "Tracks", Emaster},
	{ESegment, "Segment", Emaster},
	{EAttachments, "Attachments", Emaster},
	{EEBML, "EBML", Emaster},
	{ECues, "Cues", Emaster},
	{ECluster, "Cluster", Emaster},
};

Element *
ebmlid2elem(vlong id)
{
	Element *p, *t;
	int m, n;

	n = nelem(els);
	t = els;
	while(n > 1){
		m = n/2;
		p = t + m;
		if(id >= p->id) {
			t = p;
			n = n-m;
		} else
			n = m;
	}

	return id == t->id ? t : nil;
}