-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdescriptor_factory.cc
55 lines (47 loc) · 1.42 KB
/
descriptor_factory.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Created by wlanjie on 2018/3/15.
//
#include "descriptor_factory.h"
#include "decoder_specificinfo_descriptor.h"
#include "decoder_config_descriptor.h"
#include "es_descriptor.h"
namespace mp4 {
Result DescriptorFactory::createDescriptionFromStream(ByteStream &stream, Descriptor *&descriptor) {
Result result;
descriptor = nullptr;
Position offset;
stream.tell(offset);
unsigned char tag;
result = stream.readUI08(tag);
if (FAILED(result)) {
stream.seek(offset);
return result;
}
UI32 payloadSize = 0;
unsigned int headerSize = 1;
unsigned int max = 4;
unsigned char ext = 0;
do {
headerSize++;
result = stream.readUI08(ext);
if (FAILED(result)) {
stream.seek(offset);
return result;
}
payloadSize = (payloadSize << 7) + (ext & 0x7F);
} while (--max && (ext & 0x80));
switch (tag) {
case DESCRIPTOR_TAG_ES:
descriptor = new EsDescriptor(stream, headerSize, payloadSize);
break;
case DESCRIPTOR_TAG_DECODER_CONFIG:
descriptor = new DecoderConfigDescriptor(stream, headerSize, payloadSize);
break;
case DESCRIPTOR_TAG_DECODER_SPECIFIC_INFO:
descriptor = new DecoderSpecificInfoDescriptor(stream, headerSize, payloadSize);
break;
}
stream.seek(offset + headerSize + payloadSize);
return 0;
}
}