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 "include/FragmentedMP4Parser.h" 22 23 namespace android { 24 25 struct FragmentedMP4Parser::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 FragmentedMP4Parser::DynamicTrackFragment : public FragmentedMP4Parser::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 FragmentedMP4Parser::StaticTrackFragment : public FragmentedMP4Parser::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 FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size); 80 81 status_t parseCompactSampleSizes( 82 FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size); 83 84 status_t parseSampleToChunk( 85 FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size); 86 87 status_t parseChunkOffsets( 88 FragmentedMP4Parser *parser, uint32_t type, size_t offset, uint64_t size); 89 90 status_t parseChunkOffsets64( 91 FragmentedMP4Parser *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 uint32_t mChunkIndex; 100 101 SampleInfo mSampleInfo; 102 103 sp<ABuffer> mSampleSizes; 104 sp<ABuffer> mCompactSampleSizes; 105 106 sp<ABuffer> mSampleToChunk; 107 ssize_t mSampleToChunkIndex; 108 size_t mSampleToChunkRemaining; 109 110 sp<ABuffer> mChunkOffsets; 111 sp<ABuffer> mChunkOffsets64; 112 uint32_t mPrevChunkIndex; 113 uint64_t mNextSampleOffset; 114 115 void updateSampleInfo(); 116 117 DISALLOW_EVIL_CONSTRUCTORS(StaticTrackFragment); 118 }; 119 120 } // namespace android 121 122 #endif // TRACK_FRAGMENT_H_ 123