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

benrr101 / node-taglib-sharp / 47556045

pending completion
47556045

push

appveyor

Ben Russell
fixing-missing-settings

3255 of 4223 branches covered (77.08%)

Branch coverage included in aggregate %.

26553 of 28216 relevant lines covered (94.11%)

412.85 hits per line

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

4.72
/src/mpeg4/mpeg4BoxFactory.ts
1
import { ByteVector } from "../byteVector";
1✔
2
import { File } from "../file";
3
import AppleAnnotationBox, {
1✔
4
    AppleAdditionalInfoBox,
5
    AppleDataBox,
6
    AppleElementaryStreamDescriptor,
7
    AppleItemListBox,
8
    IsoAudioSampleEntry,
9
    IsoChunkLargeOffsetBox,
10
    IsoChunkOffsetBox,
11
    IsoFreeSpaceBox,
12
    IsoHandlerBox,
13
    IsoMetaBox,
14
    IsoMovieHeaderBox,
15
    IsoSampleDescriptionBox,
16
    IsoSampleEntry,
17
    IsoSampleTableBox,
18
    IsoUserDataBox,
19
    IsoVisualSampleEntry,
20
    Mpeg4Box,
21
    TextBox,
22
    UnknownBox,
23
    UrlBox,
24
} from "./mpeg4Boxes";
25
import Mpeg4BoxHeader from "./mpeg4BoxHeader";
1✔
26
import Mpeg4BoxType from "./mpeg4BoxType";
1✔
27

28
/**
29
 * This class provides support for reading boxes from a file.
30
 */
31
export default class Mpeg4BoxFactory {
1✔
32
    /**
33
     * Creates a box by reading it from a file given its header, parent header, handler, and index in its parent.
34
     * @param file A @see File object containing the file to read from.
35
     * @param header A @see Mpeg4BoxHeader object containing the header of the box to create.
36
     * @param parent A @see Mpeg4BoxHeader object containing the header of the parent box.
37
     * @param handler A @see IsoHandlerBox object containing the handler that applies to the new box.
38
     * @param index  A value containing the index of the new box in its parent.
39
     * @returns A newly created @see Mpeg4Box object.
40
     */
41
    public static createBoxFromFileHeaderParentHandlerAndIndex(
42
        file: File,
43
        header: Mpeg4BoxHeader,
44
        parent: Mpeg4BoxHeader,
45
        handler: IsoHandlerBox,
46
        index: number
47
    ): Mpeg4Box {
48
        // The first few children of an "stsd" are sample entries.
49
        if (
×
50
            ByteVector.equals(parent.boxType, Mpeg4BoxType.Stsd) &&
×
51
            parent.box instanceof IsoSampleDescriptionBox &&
52
            index < (parent.box as IsoSampleDescriptionBox).entryCount
53
        ) {
54
            if (handler && ByteVector.equals(handler.handlerType, Mpeg4BoxType.Soun)) {
×
55
                return IsoAudioSampleEntry.fromHeaderFileAndHandler(header, file, handler);
×
56
            }
57

58
            if (handler && ByteVector.equals(handler.handlerType, Mpeg4BoxType.Vide)) {
×
59
                return IsoVisualSampleEntry.fromHeaderFileAndHandler(header, file, handler);
×
60
            }
61

62
            if (handler && ByteVector.equals(handler.handlerType, Mpeg4BoxType.Alis)) {
×
63
                if (ByteVector.equals(header.boxType, Mpeg4BoxType.Text)) {
×
64
                    return TextBox.fromHeaderFileAndHandler(header, file, handler);
×
65
                }
66

67
                if (ByteVector.equals(header.boxType, Mpeg4BoxType.Url)) {
×
68
                    return UrlBox.fromHeaderFileAndHandler(header, file, handler);
×
69
                }
70

71
                // This could be anything, so just parse it.
72
                return UnknownBox.fromHeaderFileAndHandler(header, file, handler);
×
73
            }
74

75
            return IsoSampleEntry.fromHeaderFileAndHandler(header, file, handler);
×
76
        }
77

78
        // Standard items...
79
        const type: ByteVector = header.boxType;
×
80

81
        if (ByteVector.equals(type, Mpeg4BoxType.Mvhd)) {
×
82
            return IsoMovieHeaderBox.fromHeaderFileAndHandler(header, file, handler);
×
83
        } else if (ByteVector.equals(type, Mpeg4BoxType.Stbl)) {
×
84
            return IsoSampleTableBox.fromHeaderFileAndHandler(header, file, handler);
×
85
        } else if (ByteVector.equals(type, Mpeg4BoxType.Stsd)) {
×
86
            return IsoSampleDescriptionBox.fromHeaderFileAndHandler(header, file, handler);
×
87
        } else if (ByteVector.equals(type, Mpeg4BoxType.Stco)) {
×
88
            return IsoChunkOffsetBox.fromHeaderFileAndHandler(header, file, handler);
×
89
        } else if (ByteVector.equals(type, Mpeg4BoxType.Co64)) {
×
90
            return IsoChunkLargeOffsetBox.fromHeaderFileAndHandler(header, file, handler);
×
91
        } else if (ByteVector.equals(type, Mpeg4BoxType.Hdlr)) {
×
92
            return IsoHandlerBox.fromHeaderFileAndHandler(header, file, handler);
×
93
        } else if (ByteVector.equals(type, Mpeg4BoxType.Udta)) {
×
94
            return IsoUserDataBox.fromHeaderFileAndHandler(header, file, handler);
×
95
        } else if (ByteVector.equals(type, Mpeg4BoxType.Meta)) {
×
96
            return IsoMetaBox.fromHeaderFileAndHandler(header, file, handler);
×
97
        } else if (ByteVector.equals(type, Mpeg4BoxType.Ilst)) {
×
98
            return AppleItemListBox.fromHeaderFileAndHandler(header, file, handler);
×
99
        } else if (ByteVector.equals(type, Mpeg4BoxType.Data)) {
×
100
            return AppleDataBox.fromHeaderFileAndHandler(header, file, handler);
×
101
        } else if (ByteVector.equals(type, Mpeg4BoxType.Esds)) {
×
102
            return AppleElementaryStreamDescriptor.fromHeaderFileAndHandler(header, file, handler);
×
103
        } else if (ByteVector.equals(type, Mpeg4BoxType.Free) || ByteVector.equals(type, Mpeg4BoxType.Skip)) {
×
104
            return IsoFreeSpaceBox.fromHeaderFileAndHandler(header, file, handler);
×
105
        } else if (ByteVector.equals(type, Mpeg4BoxType.Mean) || ByteVector.equals(type, Mpeg4BoxType.Name)) {
×
106
            return AppleAdditionalInfoBox.fromHeaderFileAndHandler(header, file, handler);
×
107
        }
108

109
        // If we still don't have a tag, and we're inside an ItemListBox, load the box as an AnnotationBox (Apple tag item).
110
        if (ByteVector.equals(parent.boxType, Mpeg4BoxType.Ilst)) {
×
111
            return AppleAnnotationBox.fromHeaderFileAndHandler(header, file, handler);
×
112
        }
113

114
        // Nothing good. Go generic.
115
        return UnknownBox.fromHeaderFileAndHandler(header, file, handler);
×
116
    }
117

118
    /**
119
     * Creates a box by reading it from a file given its position in the file, parent header, handler, and index in its parent.
120
     * @param file A @see File object containing the file to read from.
121
     * @param position  A value specifying at what seek position in file to start reading.
122
     * @param parent A @see Mpeg4BoxHeader object containing the header of the parent box.
123
     * @param handler A @see IsoHandlerBox object containing the handler that applies to the new box.
124
     * @param index A value containing the index of the new box in its parent.
125
     * @returns A newly created @see Mpeg4Box object.
126
     */
127
    public static createBoxFromFilePositionParentHandlerAndIndex(
128
        file: File,
129
        position: number,
130
        parent: Mpeg4BoxHeader,
131
        handler: IsoHandlerBox,
132
        index: number
133
    ): Mpeg4Box {
134
        const header: Mpeg4BoxHeader = Mpeg4BoxHeader.fromFileAndPosition(file, position);
×
135

136
        return Mpeg4BoxFactory.createBoxFromFileHeaderParentHandlerAndIndex(file, header, parent, handler, index);
×
137
    }
138

139
    /**
140
     * Creates a box by reading it from a file given its position in the file and handler.
141
     * @param file A @see File object containing the file to read from.
142
     * @param position A value specifying at what seek position in file to start reading.
143
     * @param handler A @see IsoHandlerBox object containing the handler that applies to the new box.
144
     * @returns A newly created @see Mpeg4Box object.
145
     */
146
    public static createBoxFromFilePositionAndHandler(file: File, position: number, handler: IsoHandlerBox): Mpeg4Box {
147
        return Mpeg4BoxFactory.createBoxFromFilePositionAndHandler(file, position, handler);
×
148
    }
149

150
    /**
151
     *  Creates a box by reading it from a file given its position in the file.
152
     * @param file A @see File object containing the file to read from.
153
     * @param position A value specifying at what seek position in file to start reading.
154
     * @returns A newly created @see Mpeg4Box object.
155
     */
156
    public static createBoxFromFileAndPosition(file: File, position: number): Mpeg4Box {
157
        return Mpeg4BoxFactory.createBoxFromFilePositionAndHandler(file, position, undefined);
×
158
    }
159

160
    /**
161
     * Creates a box by reading it from a file given its header and handler.
162
     * @param file A @see File object containing the file to read from.
163
     * @param header A @see Mpeg4BoxHeader object containing the header of the box to create.
164
     * @param handler A @see IsoHandlerBox object containing the handler that applies to the new box.
165
     * @returns A newly created @see Mpeg4Box object.
166
     */
167
    public static createBoxFromFileHeaderAndHandler(file: File, header: Mpeg4BoxHeader, handler: IsoHandlerBox): Mpeg4Box {
168
        return Mpeg4BoxFactory.createBoxFromFileHeaderParentHandlerAndIndex(file, header, Mpeg4BoxHeader.fromEmpty(), handler, -1);
×
169
    }
170

171
    /**
172
     * Creates a box by reading it from a file given its header and handler.
173
     * @param file A @see File object containing the file to read from.
174
     * @param header A @see Mpeg4BoxHeader object containing the header of the box to create.
175
     * @returns A newly created @see Mpeg4Box object.
176
     */
177
    public static createBoxFromFileAndHeader(file: File, header: Mpeg4BoxHeader): Mpeg4Box {
178
        return Mpeg4BoxFactory.createBoxFromFileHeaderAndHandler(file, header, undefined);
×
179
    }
180
}
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