1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
18// EBML numbers (ids and sizes)
19// Implementation
20
21#include "EBMLNumber.hh"
22
23EBMLNumber::EBMLNumber(Boolean stripLeading1)
24 : stripLeading1(stripLeading1), len(0) {
25}
26
27EBMLNumber::~EBMLNumber() {
28}
29
30char* EBMLNumber::hexString() const {
31 static char printBuf[2*EBML_NUMBER_MAX_LEN + 1];
32
33 char* to = printBuf;
34 for (unsigned i = 0; i < len; ++i) {
35 sprintf(to, "%02X", data[i]);
36 to += 2;
37 }
38
39 return printBuf;
40}
41
42u_int64_t EBMLNumber::val() const {
43 u_int64_t result = 0;
44
45 for (unsigned i = 0; i < len; ++i) {
46 result = result*256 + data[i];
47 }
48
49 return result;
50}
51
52EBMLId::EBMLId()
53 : EBMLNumber(False) {
54}
55
56EBMLId::~EBMLId() {
57}
58
59char const* EBMLId::stringName() const {
60 switch (val()) {
61 case MATROSKA_ID_EBML: { return "EBML"; }
62 case MATROSKA_ID_VOID: { return "Void"; }
63 case MATROSKA_ID_CRC_32: { return "CRC-32"; }
64 case MATROSKA_ID_SEGMENT: { return "Segment"; }
65 case MATROSKA_ID_SEEK_HEAD: { return "Seek Head"; }
66 case MATROSKA_ID_SEEK: { return "Seek"; }
67 case MATROSKA_ID_SEEK_ID: { return "Seek ID"; }
68 case MATROSKA_ID_SEEK_POSITION: { return "Seek Position"; }
69 case MATROSKA_ID_INFO: { return "Segment Info"; }
70 case MATROSKA_ID_SEGMENT_UID: { return "Segment UID"; }
71 case MATROSKA_ID_DURATION: { return "Segment Duration"; }
72 case MATROSKA_ID_TIMECODE_SCALE: { return "Timecode Scale"; }
73 case MATROSKA_ID_DATE_UTC: { return "Date (UTC)"; }
74 case MATROSKA_ID_TITLE: { return "Title"; }
75 case MATROSKA_ID_MUXING_APP: { return "Muxing App"; }
76 case MATROSKA_ID_WRITING_APP: { return "Writing App"; }
77 case MATROSKA_ID_CLUSTER: { return "Cluster"; }
78 case MATROSKA_ID_TIMECODE: { return "TimeCode"; }
79 case MATROSKA_ID_POSITION: { return "Position"; }
80 case MATROSKA_ID_PREV_SIZE: { return "Prev. Size"; }
81 case MATROSKA_ID_SIMPLEBLOCK: { return "SimpleBlock"; }
82 case MATROSKA_ID_BLOCK_GROUP: { return "Block Group"; }
83 case MATROSKA_ID_BLOCK: { return "Block"; }
84 case MATROSKA_ID_BLOCK_DURATION: { return "Block Duration"; }
85 case MATROSKA_ID_REFERENCE_BLOCK: { return "Reference Block"; }
86 case MATROSKA_ID_TRACKS: { return "Tracks"; }
87 case MATROSKA_ID_TRACK_ENTRY: { return "Track Entry"; }
88 case MATROSKA_ID_TRACK_NUMBER: { return "Track Number"; }
89 case MATROSKA_ID_TRACK_UID: { return "Track UID"; }
90 case MATROSKA_ID_TRACK_TYPE: { return "Track Type"; }
91 case MATROSKA_ID_FLAG_ENABLED: { return "Flag Enabled"; }
92 case MATROSKA_ID_FLAG_DEFAULT: { return "Flag Default"; }
93 case MATROSKA_ID_FLAG_FORCED: { return "Flag Forced"; }
94 case MATROSKA_ID_FLAG_LACING: { return "Flag Lacing"; }
95 case MATROSKA_ID_MIN_CACHE: { return "Min Cache"; }
96 case MATROSKA_ID_DEFAULT_DURATION: { return "Default Duration"; }
97 case MATROSKA_ID_TRACK_TIMECODE_SCALE: { return "Track Timecode Scale"; }
98 case MATROSKA_ID_MAX_BLOCK_ADDITION_ID: { return "Max Block Addition ID"; }
99 case MATROSKA_ID_NAME: { return "Name"; }
100 case MATROSKA_ID_LANGUAGE: { return "Language"; }
101 case MATROSKA_ID_CODEC: { return "Codec ID"; }
102 case MATROSKA_ID_CODEC_PRIVATE: { return "Codec Private"; }
103 case MATROSKA_ID_CODEC_NAME: { return "Codec Name"; }
104 case MATROSKA_ID_CODEC_DECODE_ALL: { return "Codec Decode All"; }
105 case MATROSKA_ID_VIDEO: { return "Video Settings"; }
106 case MATROSKA_ID_FLAG_INTERLACED: { return "Flag Interlaced"; }
107 case MATROSKA_ID_PIXEL_WIDTH: { return "Pixel Width"; }
108 case MATROSKA_ID_PIXEL_HEIGHT: { return "Pixel Height"; }
109 case MATROSKA_ID_DISPLAY_WIDTH: { return "Display Width"; }
110 case MATROSKA_ID_DISPLAY_HEIGHT: { return "Display Height"; }
111 case MATROSKA_ID_DISPLAY_UNIT: { return "Display Unit"; }
112 case MATROSKA_ID_AUDIO: { return "Audio Settings"; }
113 case MATROSKA_ID_SAMPLING_FREQUENCY: { return "Sampling Frequency"; }
114 case MATROSKA_ID_OUTPUT_SAMPLING_FREQUENCY: { return "Output Sampling Frequency"; }
115 case MATROSKA_ID_CHANNELS: { return "Channels"; }
116 case MATROSKA_ID_BIT_DEPTH: { return "Bit Depth"; }
117 case MATROSKA_ID_CONTENT_ENCODINGS: { return "Content Encodings"; }
118 case MATROSKA_ID_CONTENT_ENCODING: { return "Content Encoding"; }
119 case MATROSKA_ID_CONTENT_COMPRESSION: { return "Content Compression"; }
120 case MATROSKA_ID_CONTENT_COMP_ALGO: { return "Content Compression Algorithm"; }
121 case MATROSKA_ID_CONTENT_COMP_SETTINGS: { return "Content Compression Settings"; }
122 case MATROSKA_ID_CONTENT_ENCRYPTION: { return "Content Encryption"; }
123 case MATROSKA_ID_ATTACHMENTS: { return "Attachments"; }
124 case MATROSKA_ID_ATTACHED_FILE: { return "Attached File"; }
125 case MATROSKA_ID_FILE_DESCRIPTION: { return "File Description"; }
126 case MATROSKA_ID_FILE_NAME: { return "File Name"; }
127 case MATROSKA_ID_FILE_MIME_TYPE: { return "File MIME Type"; }
128 case MATROSKA_ID_FILE_DATA: { return "File Data"; }
129 case MATROSKA_ID_FILE_UID: { return "File UID"; }
130 case MATROSKA_ID_CUES: { return "Cues"; }
131 case MATROSKA_ID_CUE_POINT: { return "Cue Point"; }
132 case MATROSKA_ID_CUE_TIME: { return "Cue Time"; }
133 case MATROSKA_ID_CUE_TRACK_POSITIONS: { return "Cue Track Positions"; }
134 case MATROSKA_ID_CUE_TRACK: { return "Cue Track"; }
135 case MATROSKA_ID_CUE_CLUSTER_POSITION: { return "Cue Cluster Position"; }
136 case MATROSKA_ID_CUE_BLOCK_NUMBER: { return "Cue Block Number"; }
137 case MATROSKA_ID_TAGS: { return "Tags"; }
138 case MATROSKA_ID_SEEK_PRE_ROLL: { return "SeekPreRoll"; }
139 case MATROSKA_ID_CODEC_DELAY: { return "CodecDelay"; }
140 case MATROSKA_ID_DISCARD_PADDING: { return "DiscardPadding"; }
141 default: { return "*****unknown*****"; }
142 }
143}
144
145EBMLDataSize::EBMLDataSize()
146 : EBMLNumber(True) {
147}
148
149EBMLDataSize::~EBMLDataSize() {
150}
151