1 /* 2 * Copyright (C) 2010 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 ANOTHER_PACKET_SOURCE_H_ 18 19 #define ANOTHER_PACKET_SOURCE_H_ 20 21 #include <media/stagefright/foundation/ABase.h> 22 #include <media/stagefright/MediaSource.h> 23 #include <utils/threads.h> 24 #include <utils/List.h> 25 26 #include "ATSParser.h" 27 28 namespace android { 29 30 struct ABuffer; 31 32 struct AnotherPacketSource : public MediaSource { 33 AnotherPacketSource(const sp<MetaData> &meta); 34 35 void setFormat(const sp<MetaData> &meta); 36 37 virtual status_t start(MetaData *params = NULL); 38 virtual status_t stop(); 39 virtual sp<MetaData> getFormat(); 40 41 virtual status_t read( 42 MediaBuffer **buffer, const ReadOptions *options = NULL); 43 44 bool hasBufferAvailable(status_t *finalResult); 45 46 // Returns the difference between the last and the first queued 47 // presentation timestamps since the last discontinuity (if any). 48 int64_t getBufferedDurationUs(status_t *finalResult); 49 50 status_t nextBufferTime(int64_t *timeUs); 51 52 void queueAccessUnit(const sp<ABuffer> &buffer); 53 54 void queueDiscontinuity( 55 ATSParser::DiscontinuityType type, const sp<AMessage> &extra); 56 57 void signalEOS(status_t result); 58 59 status_t dequeueAccessUnit(sp<ABuffer> *buffer); 60 61 protected: 62 virtual ~AnotherPacketSource(); 63 64 private: 65 Mutex mLock; 66 Condition mCondition; 67 68 bool mIsAudio; 69 sp<MetaData> mFormat; 70 List<sp<ABuffer> > mBuffers; 71 status_t mEOSResult; 72 73 bool wasFormatChange(int32_t discontinuityType) const; 74 75 DISALLOW_EVIL_CONSTRUCTORS(AnotherPacketSource); 76 }; 77 78 79 } // namespace android 80 81 #endif // ANOTHER_PACKET_SOURCE_H_ 82