• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benrr101 / node-taglib-sharp / 48390938

29 Oct 2023 03:32AM UTC coverage: 92.535% (+0.09%) from 92.443%
48390938

push

appveyor

benrr101
Cleanup docs for MPEG4

3244 of 4129 branches covered (0.0%)

Branch coverage included in aggregate %.

8 of 8 new or added lines in 3 files covered. (100.0%)

26727 of 28260 relevant lines covered (94.58%)

423.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.25
/src/mpeg4/mpeg4BoxFactory.ts
1
import AppleAdditionalInfoBox from "./boxes/appleAdditionalInfoBox";
1✔
2
import AppleAnnotationBox from "./boxes/appleAnnotationBox";
1✔
3
import AppleElementaryStreamDescriptor from "./boxes/appleElementaryStreamDescriptor";
1✔
4
import AppleItemListBox from "./boxes/appleItemListBox";
1✔
5
import IsoAudioSampleEntry from "./boxes/isoAudioSampleEntry";
1✔
6
import IsoChunkLargeOffsetBox from "./boxes/isoChunkLargeOffsetBox";
1✔
7
import IsoChunkOffsetBox from "./boxes/isoChunkOffsetBox";
1✔
8
import IsoFreeSpaceBox from "./boxes/isoFreeSpaceBox";
1✔
9
import IsoHandlerBox from "./boxes/isoHandlerBox";
1✔
10
import IsoMetaBox from "./boxes/isoMetaBox";
1✔
11
import IsoMovieHeaderBox from "./boxes/isoMovieHeaderBox";
1✔
12
import IsoSampleDescriptionBox from "./boxes/isoSampleDescriptionBox";
1✔
13
import IsoSampleTableBox from "./boxes/isoSampleTableBox";
1✔
14
import IsoUnknownSampleEntry from "./boxes/isoUnknownSampleEntry";
1✔
15
import IsoUserDataBox from "./boxes/isoUserDataBox";
1✔
16
import IsoVisualSampleEntry from "./boxes/isoVisualSampleEntry";
1✔
17
import Mpeg4Box from "./boxes/mpeg4Box";
18
import Mpeg4BoxHeader from "./mpeg4BoxHeader";
1✔
19
import Mpeg4BoxType from "./mpeg4BoxType";
1✔
20
import Mpeg4HandlerType from "./mpeg4HandlerType";
1✔
21
import TextBox from "./boxes/textBox";
1✔
22
import UnknownBox from "./boxes/unknownBox";
1✔
23
import UrlBox from "./boxes/urlBox";
1✔
24
import {AppleDataBox} from "./boxes/appleDataBox";
1✔
25
import {ByteVector} from "../byteVector";
1✔
26
import {File} from "../file";
27

28
/**
29
 * This class provides support for reading boxes from a file.
30
 * @internal
31
 */
32
export default class Mpeg4BoxFactory {
1✔
33
    /**
34
     * Creates a box by reading it from a file given its header, parent header, handler, and index in its parent.
35
     * @param file A {@link File} object containing the file to read from.
36
     * @param header A {@link Mpeg4BoxHeader} object containing the header of the box to create.
37
     * @param handlerType Type of the handler box containing the handler that applies to the new box.
38
     * @param parentHeader Header of the parent of this box. Optional.
39
     * @returns Mpeg4Box {@link Mpeg4Box} box created from the position in the file
40
     */
41
    public static createBox(
42
        file: File,
43
        header: Mpeg4BoxHeader,
44
        handlerType?: ByteVector,
45
        parentHeader?: Mpeg4BoxHeader,
46
    ): Mpeg4Box {
47
        // Standard items...
48
        const type = header.boxType;
×
49

50
        if (ByteVector.equals(type, Mpeg4BoxType.MVHD)) {
×
51
            return IsoMovieHeaderBox.fromFile(header, file, handlerType);
×
52
        }
53
        else if (ByteVector.equals(type, Mpeg4BoxType.STBL))
×
54
        {
55
            const box = IsoSampleTableBox.fromHeader(header, handlerType);
×
56
            this.loadChildren(file, box);
×
57
            return box;
×
58
        }
59
        else if (ByteVector.equals(type, Mpeg4BoxType.STSD))
×
60
        {
61
            const box = IsoSampleDescriptionBox.fromFile(file, header, handlerType);
×
62
            this.loadSampleDescriptors(file, box);
×
63
            return box;
×
64
        }
65
        else if (ByteVector.equals(type, Mpeg4BoxType.STCO))
×
66
        {
67
            return IsoChunkOffsetBox.fromFile(header, file, handlerType);
×
68
        }
69
        else if (ByteVector.equals(type, Mpeg4BoxType.CO64))
×
70
        {
71
            return IsoChunkLargeOffsetBox.fromFile(header, file, handlerType);
×
72
        }
73
        else if (ByteVector.equals(type, Mpeg4BoxType.HDLR))
×
74
        {
75
            return IsoHandlerBox.fromFile(header, file, handlerType);
×
76
        }
77
        else if (ByteVector.equals(type, Mpeg4BoxType.UDTA))
×
78
        {
79
            const box = IsoUserDataBox.fromHeader(header, handlerType);
×
80
            this.loadChildren(file, box);
×
81
            return box;
×
82
        }
83
        else if (ByteVector.equals(type, Mpeg4BoxType.META))
×
84
        {
85
            const box = IsoMetaBox.fromFile(file, header, handlerType);
×
86
            this.loadChildren(file, box);
×
87
            return box;
×
88
        }
89
        else if (ByteVector.equals(type, Mpeg4BoxType.ILST))
×
90
        {
91
            const box = AppleItemListBox.fromHeader(header, handlerType);
×
92
            this.loadChildren(file, box);
×
93
            return box;
×
94
        }
95
        else if (ByteVector.equals(type, Mpeg4BoxType.DATA))
×
96
        {
97
            return AppleDataBox.fromFile(header, file, handlerType);
×
98
        }
99
        else if (ByteVector.equals(type, Mpeg4BoxType.ESDS))
×
100
        {
101
            return AppleElementaryStreamDescriptor.fromFile(header, file, handlerType);
×
102
        }
103
        else if (ByteVector.equals(type, Mpeg4BoxType.FREE) || ByteVector.equals(type, Mpeg4BoxType.SKIP))
×
104
        {
105
            return IsoFreeSpaceBox.fromHeader(header, handlerType);
×
106
        }
107
        else if (ByteVector.equals(type, Mpeg4BoxType.MEAN) || ByteVector.equals(type, Mpeg4BoxType.NAME))
×
108
        {
109
            return AppleAdditionalInfoBox.fromFile(header, file, handlerType);
×
110
        }
111

112
        // If we still don't have a tag, and we're inside an ItemListBox, load the box as an
113
        // AnnotationBox (Apple tag item).
114
        if (ByteVector.equals(parentHeader.boxType, Mpeg4BoxType.ILST)) {
×
115
            const box = AppleAnnotationBox.fromHeader(header, handlerType);
×
116
            this.loadChildren(file, box);
×
117
            return box;
×
118
        }
119

120
        // Nothing good. Go generic.
121
        return UnknownBox.fromFile(header, file, handlerType);
×
122
    }
123

124
    private static loadSampleDescriptors(file: File, box: IsoSampleDescriptionBox): void {
125
        let position = box.dataPosition
×
126
        for (let i = 0; i < box.entryCount; i++) {
×
127
            const header = Mpeg4BoxHeader.fromFileAndPosition(file, position);
×
128
            let child: Mpeg4Box;
129

130
            // I know this isn't the right formatting, but it is damn near unreadable without some spacing
131
            if (ByteVector.equals(box.handlerType, Mpeg4HandlerType.SOUN))
×
132
            {
133
                child = IsoAudioSampleEntry.fromFile(file, header, box.handlerType);
×
134
                this.loadChildren(file, child);
×
135
            }
136
            else if (ByteVector.equals(box.handlerType, Mpeg4HandlerType.VIDE))
×
137
            {
138
                child = IsoVisualSampleEntry.fromFile(header, file, box.handlerType);
×
139
            }
140
            else if (ByteVector.equals(box.handlerType, Mpeg4HandlerType.ALIS))
×
141
            {
142
                if (ByteVector.equals(header.boxType, Mpeg4BoxType.TEXT))
×
143
                {
144
                    child = TextBox.fromFile(header, file, box.handlerType);
×
145
                }
146
                else if (ByteVector.equals(header.boxType, Mpeg4BoxType.URL))
×
147
                {
148
                    child = UrlBox.fromFile(header, file, box.handlerType);
×
149
                }
150
                else
151
                {
152
                    // This could be anything, so just parse it.
153
                    child = UnknownBox.fromFile(header, file, box.handlerType);
×
154
                }
155
            }
156
            else
157
            {
158
                child = IsoUnknownSampleEntry.fromFile(header, file, box.handlerType);
×
159
            }
160

161
            box.addChild(child);
×
162
            position += child.size;
×
163
        }
164
    }
165

166
    private static loadChildren(file: File, box: Mpeg4Box): void {
167
        let position = box.dataPosition;
×
168
        const end = position + box.dataSize;
×
169

170
        while (position < end) {
×
171
            const header = Mpeg4BoxHeader.fromFileAndPosition(file, position);
×
172
            const child = this.createBox(file, header, box.handlerType, box.header);
×
173

174
            if (child.size === 0) {
×
175
                break;
×
176
            }
177

178
            box.addChild(child);
×
179
            position += child.size;
×
180
        }
181
    }
182
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc