1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #include "oscl_types.h" 19 #include "impeg4file.h" 20 #include "pv_gau.h" 21 #include "oscl_mem.h" 22 23 typedef enum 24 { 25 MP4_PARSE_ERROR = 1, 26 SCALABILITY_CHECK_FAILED, 27 PRASE_PVTI_AND_GEN_SDP_FAILED, 28 GENERIC_SDP_FAILED, 29 PEEK_N_FAILED, 30 GET_N_FAILED, 31 SAMPLE_COUNT_MISMATCH, 32 RANDOM_POSITION_FAILED, 33 BAD_ARGUMENTS, 34 GET_TRACK_DECODER_SPECIFIC_INFO_FAILED 35 } ERROR_CODES; 36 37 38 struct BSInfo 39 { 40 uint8 *buffPtr; 41 uint32 timestamp; 42 uint32 frame_size; 43 uint32 buff_pos; 44 45 // constructor BSInfoBSInfo46 OSCL_IMPORT_REF BSInfo() 47 { 48 oscl_memset(this, 0, sizeof(BSInfo)); 49 } 50 51 // two copy functions copyBSInfo52 OSCL_IMPORT_REF void copy(BSInfo& X) 53 { 54 this->buffPtr = X.buffPtr; 55 this->timestamp = X.timestamp; 56 this->frame_size = X.frame_size; 57 this->buff_pos = X.buff_pos; 58 } 59 copyBSInfo60 OSCL_IMPORT_REF void copy(BSInfo* pX) 61 { 62 if (pX) 63 { 64 this->buffPtr = pX->buffPtr; 65 this->timestamp = pX->timestamp; 66 this->frame_size = pX->frame_size; 67 this->buff_pos = pX->buff_pos; 68 } 69 } 70 71 }; 72 73 class GauObject 74 { 75 76 private: 77 GAU mGau; 78 uint32 mCount; 79 uint32 mNumSamples; 80 uint8 *mpBuffer; 81 BSInfo mBSInfo; 82 83 // for getPrevSample() 84 BSInfo mBSInfo_prev; 85 bool bGetNew; 86 87 //! Any GauObject object should be bundled with a track in a mp4 bitstream 88 uint32 mTrackID; 89 IMpeg4File *mp4Bitstream; 90 91 92 //! low-level getting data function 93 int32 updateGauPtr(); 94 /** 95 * @brief Purposely make this function private to prevent the mis-use of this function 96 * Note this function should not be called twice consecutively 97 * @return the pointer of the sample we need, NULL for error 98 */ 99 BSInfo *getPrevSample(); 100 reset()101 void reset() 102 { 103 if (mp4Bitstream) 104 { 105 mp4Bitstream->resetPlayback(); 106 oscl_memset(&mBSInfo, 0, sizeof(BSInfo)); 107 oscl_memset(&mBSInfo_prev, 0, sizeof(BSInfo)); 108 mCount = 0; 109 bGetNew = true; 110 mNumSamples = 10; 111 } 112 } 113 114 public: 115 116 //! default constructor 117 OSCL_IMPORT_REF GauObject(IMpeg4File *mp4In = NULL, uint32 trackID = 0); 118 119 //! destructor 120 OSCL_IMPORT_REF ~GauObject(); 121 122 OSCL_IMPORT_REF IMpeg4File *getBitstream(); 123 OSCL_IMPORT_REF uint32 getTrackID(); 124 125 /** 126 * @brief Hide all the GAU operation to get the next sample from the current bitstream 127 * @return the pointer of the sample we need, NULL for error 128 */ 129 OSCL_IMPORT_REF BSInfo *getNextSample(); 130 /** 131 * @brief Hide all the GAU operation to get the sample immediately before a certain timestamp 132 * from the current bitstream 133 * @param tsIn is the requested point refering to the sample 134 * @return the pointer of the sample we need, NULL for error 135 */ 136 OSCL_IMPORT_REF BSInfo *getPreviousSampleAt(uint32 tsIn); 137 /** 138 * @brief Hide all the GAU operation to get the sample at or immediately after a certain timestamp 139 * from the current bitstream 140 * @param tsIn is the requested point refering to the sample 141 * @return the pointer of the sample we need, NULL for error 142 */ 143 OSCL_IMPORT_REF BSInfo *getNextSampleAt(uint32 tsIn = 0); 144 /** 145 * @brief Hide all the GAU operation to get the next I frame from the current bitstream, whose timestamp >= tsIn 146 * @param tsIn is the requested point refering to the sample 147 * @param bH263Stream is flag showing whether the input bitstream is H263 bitstream 148 * @return the pointer of the sample we need, NULL for error 149 */ 150 OSCL_IMPORT_REF BSInfo *GauObject::getNextIFrame(uint32 tsIn = 0, bool bH263Stream = false); 151 152 }; 153 154