AnotherPacketSource.h revision 7c8708046117e03c0d38006bdd9685139df3ac6b
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 28namespace android { 29 30struct ABuffer; 31 32struct 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 void clear(); 45 46 // Returns true if we have any packets including discontinuities 47 bool hasBufferAvailable(status_t *finalResult); 48 49 // Returns true if we have packets that's not discontinuities 50 bool hasDataBufferAvailable(status_t *finalResult); 51 52 // Returns the difference between the last and the first queued 53 // presentation timestamps since the last discontinuity (if any). 54 int64_t getBufferedDurationUs(status_t *finalResult); 55 56 int64_t getEstimatedDurationUs(); 57 58 status_t nextBufferTime(int64_t *timeUs); 59 60 void queueAccessUnit(const sp<ABuffer> &buffer); 61 62 void queueDiscontinuity( 63 ATSParser::DiscontinuityType type, 64 const sp<AMessage> &extra, 65 bool discard); 66 67 void signalEOS(status_t result); 68 69 status_t dequeueAccessUnit(sp<ABuffer> *buffer); 70 71 bool isFinished(int64_t duration) const; 72 73 void enable(bool enable); 74 75 sp<AMessage> getLatestEnqueuedMeta(); 76 sp<AMessage> getLatestDequeuedMeta(); 77 sp<AMessage> getMetaAfterLastDequeued(int64_t delayUs); 78 79 void trimBuffersAfterTimeUs(size_t discontinuitySeq, int64_t timeUs); 80 sp<AMessage> trimBuffersBeforeTimeUs(size_t discontinuitySeq, int64_t timeUs); 81 82protected: 83 virtual ~AnotherPacketSource(); 84 85private: 86 Mutex mLock; 87 Condition mCondition; 88 89 bool mIsAudio; 90 bool mIsVideo; 91 bool mEnabled; 92 sp<MetaData> mFormat; 93 int64_t mLastQueuedTimeUs; 94 List<sp<ABuffer> > mBuffers; 95 status_t mEOSResult; 96 sp<AMessage> mLatestEnqueuedMeta; 97 sp<AMessage> mLatestDequeuedMeta; 98 99 size_t mQueuedDiscontinuityCount; 100 101 bool wasFormatChange(int32_t discontinuityType) const; 102 int64_t getBufferedDurationUs_l(status_t *finalResult); 103 104 DISALLOW_EVIL_CONSTRUCTORS(AnotherPacketSource); 105}; 106 107 108} // namespace android 109 110#endif // ANOTHER_PACKET_SOURCE_H_ 111