summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/mp4/TrackFragment.h
blob: e1ad46e2175a6cf5b40c79ac8063d7f9c4136b3c (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TRACK_FRAGMENT_H_

#define TRACK_FRAGMENT_H_

#include "include/FragmentedMP4Parser.h"

namespace android {

struct FragmentedMP4Parser::TrackFragment : public RefBase {
    TrackFragment() {}

    virtual status_t getSample(SampleInfo *info) = 0;
    virtual void advance() = 0;

    virtual status_t signalCompletion() = 0;
    virtual bool complete() const = 0;

protected:
    virtual ~TrackFragment() {}

private:
    DISALLOW_EVIL_CONSTRUCTORS(TrackFragment);
};

struct FragmentedMP4Parser::DynamicTrackFragment : public FragmentedMP4Parser::TrackFragment {
    DynamicTrackFragment();

    virtual status_t getSample(SampleInfo *info);
    virtual void advance();

    void addSample(
            off64_t dataOffset, size_t sampleSize,
            uint32_t presentationTime,
            size_t sampleDescIndex,
            uint32_t flags);

    // No more samples will be added to this fragment.
    virtual status_t signalCompletion();

    virtual bool complete() const;

protected:
    virtual ~DynamicTrackFragment();

private:
    bool mComplete;
    size_t mSampleIndex;
    Vector<SampleInfo> mSamples;

    DISALLOW_EVIL_CONSTRUCTORS(DynamicTrackFragment);
};

struct FragmentedMP4Parser::StaticTrackFragment : public FragmentedMP4Parser::TrackFragment {
    StaticTrackFragment();

    virtual status_t getSample(SampleInfo *info);
    virtual void advance();

    virtual status_t signalCompletion();
    virtual bool complete() const;

    status_t parseSampleSizes(
            FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size);

    status_t parseCompactSampleSizes(
            FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size);

    status_t parseSampleToChunk(
            FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size);

    status_t parseChunkOffsets(
            FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size);

    status_t parseChunkOffsets64(
            FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size);

protected:
    virtual ~StaticTrackFragment();

private:
    size_t mSampleIndex;
    size_t mSampleCount;
    uint32_t mChunkIndex;

    SampleInfo mSampleInfo;

    sp<ABuffer> mSampleSizes;
    sp<ABuffer> mCompactSampleSizes;

    sp<ABuffer> mSampleToChunk;
    ssize_t mSampleToChunkIndex;
    size_t mSampleToChunkRemaining;

    sp<ABuffer> mChunkOffsets;
    sp<ABuffer> mChunkOffsets64;
    uint32_t mPrevChunkIndex;
    uint64_t mNextSampleOffset;

    void updateSampleInfo();

    DISALLOW_EVIL_CONSTRUCTORS(StaticTrackFragment);
};

}  // namespace android

#endif  // TRACK_FRAGMENT_H_