-
Notifications
You must be signed in to change notification settings - Fork 4
/
moov.cc
66 lines (56 loc) · 1.46 KB
/
moov.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
56
57
58
59
60
61
62
63
64
65
66
//
// Created by wlanjie on 2018/3/8.
//
#include "moov.h"
namespace mp4 {
class TrakCollector : public List<Atom>::Item::Operator {
public:
TrakCollector(List<Trak>* traks) : traks(traks) {}
Result action(Atom* atom) const {
if (atom->getType() == ATOM_TYPE_TRAK) {
Trak* trak = DYNAMIC_CAST(Trak, atom);
if (trak) {
traks->add(trak);
}
}
return SUCCESS;
}
private:
List<Trak>* traks;
};
Moov::Moov() :
Container(ATOM_TYPE_MOOV),
timeScale(0) {
timeScale = 0;
}
Moov::Moov(Size size, ByteStream &stream, AtomFactory &factory) :
Container(ATOM_TYPE_MOOV, size, false, stream, factory),
timeScale(0) {
children.apply(TrakCollector(&traks));
}
Result Moov::adjustChunkOffsets(SI64 offset) {
for (List<Trak>::Item* item = traks.firstItem(); item; item = item->getNext()) {
Trak* trak = item->getData();
trak->adjustChunkOffsets(offset);
}
return SUCCESS;
}
void Moov::onChildAdded(Atom *atom) {
if (atom->getType() == ATOM_TYPE_TRAK) {
Trak* trak = DYNAMIC_CAST(Trak, atom);
if (trak) {
traks.add(trak);
}
}
Container::onChildAdded(atom);
}
void Moov::onChildRemoved(Atom *atom) {
if (atom->getType() == ATOM_TYPE_TRAK) {
Trak* trak = DYNAMIC_CAST(Trak, atom);
if (trak) {
traks.remove(trak);
}
}
Container::onChildRemoved(atom);
}
}