-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsample_source.cpp
55 lines (45 loc) · 1.3 KB
/
sample_source.cpp
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/31.
//
#include "sample_source.h"
namespace mp4 {
TrackSampleSource::TrackSampleSource(Track *track) :
track(track),
sampleIndex(0) {
}
UI32 TrackSampleSource::getTimeScale() {
return track->getMediaTimeScale();
}
UI32 TrackSampleSource::getDurationMs() {
return track->getDurationMs();
}
Result TrackSampleSource::readNextSample(Sample &sample, DataBuffer &buffer, UI32 &trackId) {
auto result = track->readSample(sampleIndex, sample, buffer);
if (SUCCEEDED(result)) {
++sampleIndex;
trackId = track->getId();
} else {
trackId = 0;
}
return result;
}
Result TrackSampleSource::seekToTime(UI32 timeMs, bool before) {
Ordinal sampleIndex = 0;
auto result = track->getSampleIndexForTimeStampMs(timeMs, sampleIndex);
if (FAILED(result)) {
return result;
}
if (sampleIndex >= track->getSampleCount()) {
return ERROR_OUT_OF_RANGE;
}
sampleIndex = track->getNearestSyncSampleIndex(sampleIndex, before);
if (sampleIndex >= track->getSampleCount()) {
return ERROR_OUT_OF_RANGE;
}
this->sampleIndex = sampleIndex;
return result;
}
SampleDescription *TrackSampleSource::getSampleDescription(Ordinal index) {
return track->getSampleDescription(index);
}
}