| Andreas Huber | 8406678 | 2011-08-16 09:34:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef TRACK_FRAGMENT_H_ |
| 18 | |
| 19 | #define TRACK_FRAGMENT_H_ |
| 20 | |
| 21 | #include "Parser.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | struct Parser::TrackFragment : public RefBase { |
| 26 | TrackFragment() {} |
| 27 | |
| 28 | virtual status_t getSample(SampleInfo *info) = 0; |
| 29 | virtual void advance() = 0; |
| 30 | |
| 31 | virtual status_t signalCompletion() = 0; |
| 32 | virtual bool complete() const = 0; |
| 33 | |
| 34 | protected: |
| 35 | virtual ~TrackFragment() {} |
| 36 | |
| 37 | private: |
| 38 | DISALLOW_EVIL_CONSTRUCTORS(TrackFragment); |
| 39 | }; |
| 40 | |
| 41 | struct Parser::DynamicTrackFragment : public Parser::TrackFragment { |
| 42 | DynamicTrackFragment(); |
| 43 | |
| 44 | virtual status_t getSample(SampleInfo *info); |
| 45 | virtual void advance(); |
| 46 | |
| 47 | void addSample( |
| 48 | off64_t dataOffset, size_t sampleSize, |
| 49 | uint32_t presentationTime, |
| 50 | size_t sampleDescIndex, |
| 51 | uint32_t flags); |
| 52 | |
| 53 | // No more samples will be added to this fragment. |
| 54 | virtual status_t signalCompletion(); |
| 55 | |
| 56 | virtual bool complete() const; |
| 57 | |
| 58 | protected: |
| 59 | virtual ~DynamicTrackFragment(); |
| 60 | |
| 61 | private: |
| 62 | bool mComplete; |
| 63 | size_t mSampleIndex; |
| 64 | Vector<SampleInfo> mSamples; |
| 65 | |
| 66 | DISALLOW_EVIL_CONSTRUCTORS(DynamicTrackFragment); |
| 67 | }; |
| 68 | |
| 69 | struct Parser::StaticTrackFragment : public Parser::TrackFragment { |
| 70 | StaticTrackFragment(); |
| 71 | |
| 72 | virtual status_t getSample(SampleInfo *info); |
| 73 | virtual void advance(); |
| 74 | |
| 75 | virtual status_t signalCompletion(); |
| 76 | virtual bool complete() const; |
| 77 | |
| 78 | status_t parseSampleSizes( |
| 79 | Parser *parser, uint32_t type, size_t offset, uint64_t size); |
| 80 | |
| 81 | status_t parseCompactSampleSizes( |
| 82 | Parser *parser, uint32_t type, size_t offset, uint64_t size); |
| 83 | |
| 84 | status_t parseSampleToChunk( |
| 85 | Parser *parser, uint32_t type, size_t offset, uint64_t size); |
| 86 | |
| 87 | status_t parseChunkOffsets( |
| 88 | Parser *parser, uint32_t type, size_t offset, uint64_t size); |
| 89 | |
| 90 | status_t parseChunkOffsets64( |
| 91 | Parser *parser, uint32_t type, size_t offset, uint64_t size); |
| 92 | |
| 93 | protected: |
| 94 | virtual ~StaticTrackFragment(); |
| 95 | |
| 96 | private: |
| 97 | size_t mSampleIndex; |
| 98 | size_t mSampleCount; |
| 99 | |
| 100 | SampleInfo mSampleInfo; |
| 101 | |
| 102 | sp<ABuffer> mSampleSizes; |
| 103 | sp<ABuffer> mCompactSampleSizes; |
| 104 | |
| 105 | sp<ABuffer> mSampleToChunk; |
| 106 | ssize_t mSampleToChunkIndex; |
| 107 | size_t mSampleToChunkRemaining; |
| 108 | |
| 109 | sp<ABuffer> mChunkOffsets; |
| 110 | sp<ABuffer> mChunkOffsets64; |
| 111 | uint32_t mPrevChunkIndex; |
| 112 | uint64_t mNextSampleOffset; |
| 113 | |
| 114 | void updateSampleInfo(); |
| 115 | void fixSampleToChunkTableIfNecessary(); |
| 116 | |
| 117 | DISALLOW_EVIL_CONSTRUCTORS(StaticTrackFragment); |
| 118 | }; |
| 119 | |
| 120 | } // namespace android |
| 121 | |
| 122 | #endif // TRACK_FRAGMENT_H_ |